Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cli): Updating start command #3174

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .goreleaser.demo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ builds:
main: ./cli/main.go
ldflags:
- -X github.com/kubeshop/tracetest/cli/config.Version={{ .Env.VERSION }}
- -X github.com/kubeshop/tracetest/cli/config.DefaultCloudEndpoint={{ .Env.TRACETEST_DEFAULT_CLOUD_ENDPOINT }}
- -X github.com/kubeshop/tracetest/cli/config.Env={{ .Env.TRACETEST_ENV }}
- -X github.com/kubeshop/tracetest/cli/analytics.SecretKey={{ .Env.ANALYTICS_BE_KEY }}
env:
Expand Down
1 change: 1 addition & 0 deletions .goreleaser.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ builds:
main: ./cli/main.go
ldflags:
- -X github.com/kubeshop/tracetest/cli/config.Version={{ .Env.VERSION }}
- -X github.com/kubeshop/tracetest/cli/config.DefaultCloudEndpoint={{ .Env.TRACETEST_DEFAULT_CLOUD_ENDPOINT }}
- -X github.com/kubeshop/tracetest/cli/config.Env={{ .Env.TRACETEST_ENV }}
- -X github.com/kubeshop/tracetest/cli/analytics.SecretKey={{ .Env.ANALYTICS_BE_KEY }}
env:
Expand Down
1 change: 1 addition & 0 deletions .goreleaser.rc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ builds:
main: ./cli/main.go
ldflags:
- -X github.com/kubeshop/tracetest/cli/config.Version={{ .Env.VERSION }}
- -X github.com/kubeshop/tracetest/cli/config.DefaultCloudEndpoint={{ .Env.TRACETEST_DEFAULT_CLOUD_ENDPOINT }}
- -X github.com/kubeshop/tracetest/cli/config.Env={{ .Env.TRACETEST_ENV }}
- -X github.com/kubeshop/tracetest/cli/analytics.SecretKey={{ .Env.ANALYTICS_BE_KEY }}
env:
Expand Down
1 change: 1 addition & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ builds:
main: ./cli/main.go
ldflags:
- -X github.com/kubeshop/tracetest/cli/config.Version={{ .Env.VERSION }}
- -X github.com/kubeshop/tracetest/cli/config.DefaultCloudEndpoint={{ .Env.TRACETEST_DEFAULT_CLOUD_ENDPOINT }}
- -X github.com/kubeshop/tracetest/cli/config.Env={{ .Env.TRACETEST_ENV }}
- -X github.com/kubeshop/tracetest/cli/analytics.SecretKey={{ .Env.ANALYTICS_BE_KEY }}
env:
Expand Down
1 change: 1 addition & 0 deletions cli/cmd/resource_select_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ type selectParameters struct {
organizationID string
environmentID string
endpoint string
agentApiKey string
}
58 changes: 0 additions & 58 deletions cli/cmd/start_agent_cmd.go

This file was deleted.

4 changes: 3 additions & 1 deletion cli/cmd/start_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var startCmd = &cobra.Command{
OrganizationID: selectParams.organizationID,
EnvironmentID: selectParams.environmentID,
Endpoint: selectParams.endpoint,
AgentApiKey: selectParams.agentApiKey,
}

err := start.Run(ctx, cliConfig, flags)
Expand All @@ -37,7 +38,8 @@ func init() {
if isCloudEnabled {
startCmd.Flags().StringVarP(&selectParams.organizationID, "organization", "", "", "organization id")
startCmd.Flags().StringVarP(&selectParams.environmentID, "environment", "", "", "environment id")
startCmd.Flags().StringVarP(&selectParams.endpoint, "endpoint", "e", "", "set the value for the endpoint, so the CLI won't ask for this value")
startCmd.Flags().StringVarP(&selectParams.agentApiKey, "api-key", "", "", "agent api key")
startCmd.Flags().StringVarP(&selectParams.endpoint, "endpoint", "e", config.DefaultCloudEndpoint, "set the value for the endpoint, so the CLI won't ask for this value")
rootCmd.AddCommand(startCmd)
}
}
14 changes: 8 additions & 6 deletions cli/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@ import (
)

var (
Version = "dev"
Env = "dev"
DefaultCloudAPIEndpoint = "http://localhost:8090"
DefaultCloudDomain = "tracetest.io"
DefaultCloudPath = "/"
Version = "dev"
Env = "dev"
DefaultCloudEndpoint = "http://localhost:3000/"
DefaultCloudDomain = "tracetest.io"
DefaultCloudPath = "/"
)

type ConfigFlags struct {
Endpoint string
OrganizationID string
EnvironmentID string
CI bool
AgentApiKey string
}

type Config struct {
Expand All @@ -36,6 +37,7 @@ type Config struct {
EnvironmentID string `yaml:"environmentID,omitempty"`
Token string `yaml:"token,omitempty"`
Jwt string `yaml:"jwt,omitempty"`
AgentApiKey string `yaml:"-"`

// cloud config
CloudAPIEndpoint string `yaml:"-"`
Expand Down Expand Up @@ -82,7 +84,7 @@ func LoadConfig(configFile string) (Config, error) {
}

if config.CloudAPIEndpoint == "" {
config.CloudAPIEndpoint = DefaultCloudAPIEndpoint
config.CloudAPIEndpoint = DefaultCloudEndpoint
}

homePath, err := os.UserHomeDir()
Expand Down
10 changes: 8 additions & 2 deletions cli/config/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ func (c Configurator) Start(ctx context.Context, prev Config, flags ConfigFlags)
return nil
}

if flags.AgentApiKey != "" {
cfg.AgentApiKey = flags.AgentApiKey
c.ShowOrganizationSelector(ctx, cfg, flags)
return nil
}

oauthServer := oauth.NewOAuthServer(fmt.Sprintf("%s%s", cfg.URL(), cfg.Path()), cfg.UIEndpoint)
err = oauthServer.WithOnSuccess(c.onOAuthSuccess(ctx, cfg)).
WithOnFailure(c.onOAuthFailure).
Expand All @@ -130,7 +136,7 @@ func (c Configurator) onOAuthFailure(err error) {

func (c Configurator) ShowOrganizationSelector(ctx context.Context, cfg Config, flags ConfigFlags) {
cfg.OrganizationID = flags.OrganizationID
if cfg.OrganizationID == "" {
if cfg.OrganizationID == "" && flags.AgentApiKey == "" {
orgID, err := c.organizationSelector(ctx, cfg)
if err != nil {
c.ui.Exit(err.Error())
Expand All @@ -141,7 +147,7 @@ func (c Configurator) ShowOrganizationSelector(ctx context.Context, cfg Config,
}

cfg.EnvironmentID = flags.EnvironmentID
if cfg.EnvironmentID == "" {
if cfg.EnvironmentID == "" && flags.AgentApiKey == "" {
envID, err := c.environmentSelector(ctx, cfg)
if err != nil {
c.ui.Exit(err.Error())
Expand Down
9 changes: 9 additions & 0 deletions cli/pkg/starter/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ func (s *Starter) Run(ctx context.Context, cfg config.Config, flags config.Confi
}

func (s *Starter) onStartAgent(ctx context.Context, cfg config.Config) {
if cfg.AgentApiKey != "" {
err := s.StartAgent(ctx, cfg.AgentEndpoint, "local", cfg.AgentApiKey, cfg.UIEndpoint)
if err != nil {
s.ui.Error(err.Error())
}

return
}

env, err := s.getEnvironment(ctx, cfg)
if err != nil {
s.ui.Error(err.Error())
Expand Down