Skip to content

Commit

Permalink
chore(cli): Updating start command (#3174)
Browse files Browse the repository at this point in the history
* chore(cli): Updating start command

* fixing missing secrets
  • Loading branch information
xoscar authored Sep 21, 2023
1 parent 7e15169 commit 3d54ed1
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 67 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy-demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ jobs:
TRACETEST_ENV: demo
ANALYTICS_FE_KEY: ${{ secrets.ANALYTICS_FE_KEY }}
ANALYTICS_BE_KEY: ${{ secrets.ANALYTICS_BE_KEY }}
TRACETEST_DEFAULT_CLOUD_ENDPOINT: ${{ secrets.TRACETEST_DEFAULT_CLOUD_ENDPOINT }}

demo-deploy:
if: github.event_name == 'push'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/deploy-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ jobs:
TRACETEST_ENV: main
ANALYTICS_FE_KEY: ${{ secrets.ANALYTICS_FE_KEY }}
ANALYTICS_BE_KEY: ${{ secrets.ANALYTICS_BE_KEY }}
TRACETEST_DEFAULT_CLOUD_ENDPOINT: ${{ secrets.TRACETEST_DEFAULT_CLOUD_ENDPOINT }}
- name: Upload assets
uses: actions/upload-artifact@v3
with:
Expand Down Expand Up @@ -196,6 +197,7 @@ jobs:
TRACETEST_ENV: main
ANALYTICS_FE_KEY: ${{ secrets.ANALYTICS_FE_KEY }}
ANALYTICS_BE_KEY: ${{ secrets.ANALYTICS_BE_KEY }}
TRACETEST_DEFAULT_CLOUD_ENDPOINT: ${{ secrets.TRACETEST_DEFAULT_CLOUD_ENDPOINT }}

deploy-beta:
if: github.event_name == 'push'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release-candidate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,4 @@ jobs:
TRACETEST_ENV: main
ANALYTICS_FE_KEY: ${{ secrets.ANALYTICS_FE_KEY }}
ANALYTICS_BE_KEY: ${{ secrets.ANALYTICS_BE_KEY }}
TRACETEST_DEFAULT_CLOUD_ENDPOINT: ${{ secrets.TRACETEST_DEFAULT_CLOUD_ENDPOINT }}
1 change: 1 addition & 0 deletions .github/workflows/release-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ jobs:
TRACETEST_ENV: main
ANALYTICS_FE_KEY: ${{ secrets.ANALYTICS_FE_KEY }}
ANALYTICS_BE_KEY: ${{ secrets.ANALYTICS_BE_KEY }}
TRACETEST_DEFAULT_CLOUD_ENDPOINT: ${{ secrets.TRACETEST_DEFAULT_CLOUD_ENDPOINT }}


helm_chart_version_bump:
Expand Down
2 changes: 2 additions & 0 deletions .goreleaser.demo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ env:
- TRACETEST_ENV={{ if index .Env "TRACETEST_ENV" }}{{ .Env.TRACETEST_ENV }}{{ else }}dev{{ end }}
- ANALYTICS_BE_KEY={{ if index .Env "ANALYTICS_BE_KEY" }}{{ .Env.ANALYTICS_BE_KEY }}{{ else }}{{ end }}
- ANALYTICS_FE_KEY={{ if index .Env "ANALYTICS_FE_KEY" }}{{ .Env.ANALYTICS_FE_KEY }}{{ else }}{{ end }}
- TRACETEST_DEFAULT_CLOUD_ENDPOINT={{ if index .Env "TRACETEST_DEFAULT_CLOUD_ENDPOINT" }}{{ .Env.TRACETEST_DEFAULT_CLOUD_ENDPOINT }}{{ else }}{{ end }}
builds:
- id: server
binary: tracetest-server
Expand All @@ -39,6 +40,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
2 changes: 2 additions & 0 deletions .goreleaser.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ env:
- TRACETEST_ENV={{ if index .Env "TRACETEST_ENV" }}{{ .Env.TRACETEST_ENV }}{{ else }}dev{{ end }}
- ANALYTICS_BE_KEY={{ if index .Env "ANALYTICS_BE_KEY" }}{{ .Env.ANALYTICS_BE_KEY }}{{ else }}{{ end }}
- ANALYTICS_FE_KEY={{ if index .Env "ANALYTICS_FE_KEY" }}{{ .Env.ANALYTICS_FE_KEY }}{{ else }}{{ end }}
- TRACETEST_DEFAULT_CLOUD_ENDPOINT={{ if index .Env "TRACETEST_DEFAULT_CLOUD_ENDPOINT" }}{{ .Env.TRACETEST_DEFAULT_CLOUD_ENDPOINT }}{{ else }}{{ end }}

builds:
- id: server
Expand All @@ -42,6 +43,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
2 changes: 2 additions & 0 deletions .goreleaser.rc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ env:
- TRACETEST_ENV={{ if index .Env "TRACETEST_ENV" }}{{ .Env.TRACETEST_ENV }}{{ else }}dev{{ end }}
- ANALYTICS_BE_KEY={{ if index .Env "ANALYTICS_BE_KEY" }}{{ .Env.ANALYTICS_BE_KEY }}{{ else }}{{ end }}
- ANALYTICS_FE_KEY={{ if index .Env "ANALYTICS_FE_KEY" }}{{ .Env.ANALYTICS_FE_KEY }}{{ else }}{{ end }}
- TRACETEST_DEFAULT_CLOUD_ENDPOINT={{ if index .Env "TRACETEST_DEFAULT_CLOUD_ENDPOINT" }}{{ .Env.TRACETEST_DEFAULT_CLOUD_ENDPOINT }}{{ else }}{{ end }}
builds:
- id: server
binary: tracetest-server
Expand Down Expand Up @@ -49,6 +50,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
2 changes: 2 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ env:
- TRACETEST_ENV={{ if index .Env "TRACETEST_ENV" }}{{ .Env.TRACETEST_ENV }}{{ else }}dev{{ end }}
- ANALYTICS_BE_KEY={{ if index .Env "ANALYTICS_BE_KEY" }}{{ .Env.ANALYTICS_BE_KEY }}{{ else }}{{ end }}
- ANALYTICS_FE_KEY={{ if index .Env "ANALYTICS_FE_KEY" }}{{ .Env.ANALYTICS_FE_KEY }}{{ else }}{{ end }}
- TRACETEST_DEFAULT_CLOUD_ENDPOINT={{ if index .Env "TRACETEST_DEFAULT_CLOUD_ENDPOINT" }}{{ .Env.TRACETEST_DEFAULT_CLOUD_ENDPOINT }}{{ else }}{{ end }}
builds:
- id: server
binary: tracetest-server
Expand Down Expand Up @@ -51,6 +52,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

0 comments on commit 3d54ed1

Please sign in to comment.