Skip to content

Commit

Permalink
Uses config api key
Browse files Browse the repository at this point in the history
  • Loading branch information
cveticm committed Dec 20, 2024
1 parent c668bf2 commit 7c7e163
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 60 deletions.
4 changes: 4 additions & 0 deletions internal/cli/kubernetes/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package config

import (
"github.com/mongodb/atlas-cli-core/config"
"github.com/spf13/cobra"
)

Expand All @@ -24,6 +25,9 @@ func Builder() *cobra.Command {
Use: use,
Short: "Manage Kubernetes configuration resources.",
Long: `This command provides your Kubernetes configuration access to Atlas.`,
PersistentPreRun: func(_ *cobra.Command, _ []string) {
config.LoadAtlasCLIConfig()
},
}

cmd.AddCommand(GenerateBuilder())
Expand Down
35 changes: 0 additions & 35 deletions internal/cli/kubernetes/kubernetes.go

This file was deleted.

8 changes: 7 additions & 1 deletion internal/cli/kubernetes/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,20 @@

package operator

import "github.com/spf13/cobra"
import (
"github.com/mongodb/atlas-cli-core/config"
"github.com/spf13/cobra"
)

func Builder() *cobra.Command {
const use = "operator"
cmd := &cobra.Command{
Use: use,
Short: "Manage Atlas Kubernetes Operator.",
Long: `This command manages the Atlas Kubernetes Operator.`,
PersistentPreRun: func(_ *cobra.Command, _ []string) {
config.LoadAtlasCLIConfig()
},
}

cmd.AddCommand(InstallBuilder())
Expand Down
30 changes: 11 additions & 19 deletions internal/kubernetes/operator/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,11 @@ func (i *Install) WithAtlasGov(flag bool) *Install {
}

func (i *Install) Run(ctx context.Context, orgID string) error {
keys, err := i.generateKeys(orgID)
if err != nil {
if err := i.installResources.InstallCRDs(ctx, i.version, len(i.watch) > 0); err != nil {
return err
}

if err = i.installResources.InstallCRDs(ctx, i.version, len(i.watch) > 0); err != nil {
return err
}

if err = i.installResources.InstallConfiguration(ctx, &InstallConfig{
if err := i.installResources.InstallConfiguration(ctx, &InstallConfig{
Version: i.version,
Namespace: i.namespace,
Watch: i.watch,
Expand All @@ -117,25 +112,22 @@ func (i *Install) Run(ctx context.Context, orgID string) error {
return err
}

if err = i.installResources.InstallCredentials(
if err := i.installResources.InstallCredentials(
ctx,
i.namespace,
orgID,
keys.GetPublicKey(),
keys.GetPrivateKey(),
i.projectName); err != nil {
return err
}

if i.importResources {
if err = i.importAtlasResources(orgID, keys.GetId()); err != nil {
return err
}
// if i.importResources {
// if err := i.importAtlasResources(config.OrgID(), keys.id); err != nil {
// return err
// }

if err = i.ensureCredentialsAssignment(ctx); err != nil {
return err
}
}
// if err := i.ensureCredentialsAssignment(ctx); err != nil {
// return err
// }
// }

return nil
}
Expand Down
11 changes: 6 additions & 5 deletions internal/kubernetes/operator/install_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"atlas-cli-plugin-test/internal/kubernetes/operator/resources"
"atlas-cli-plugin-test/internal/kubernetes/operator/version"

"github.com/mongodb/atlas-cli-core/config"
"gopkg.in/yaml.v3"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -56,7 +57,7 @@ type InstallConfig struct {
type Installer interface {
InstallCRDs(ctx context.Context, v string, namespaced bool) error
InstallConfiguration(ctx context.Context, installConfig *InstallConfig) error
InstallCredentials(ctx context.Context, namespace, orgID, publicKey, privateKey string, projectName string) error
InstallCredentials(ctx context.Context, namespace string, projectName string) error
}

type InstallResources struct {
Expand Down Expand Up @@ -149,7 +150,7 @@ func (ir *InstallResources) handleKind(ctx context.Context, installConfig *Insta
return nil
}

func (ir *InstallResources) InstallCredentials(ctx context.Context, namespace, orgID, publicKey, privateKey string, projectName string) error {
func (ir *InstallResources) InstallCredentials(ctx context.Context, namespace string, projectName string) error {
name := credentialsGlobalName

if projectName != "" {
Expand All @@ -165,9 +166,9 @@ func (ir *InstallResources) InstallCredentials(ctx context.Context, namespace, o
},
},
StringData: map[string]string{
"orgId": orgID,
"publicApiKey": publicKey,
"privateApiKey": privateKey,
"orgId": config.OrgID(),
"publicApiKey": config.PublicAPIKey(),
"privateApiKey": config.PrivateAPIKey(),
},
}

Expand Down

0 comments on commit 7c7e163

Please sign in to comment.