diff --git a/.github/workflows/deploy-demo.yml b/.github/workflows/deploy-demo.yml index 64e5649190..10b298eba5 100644 --- a/.github/workflows/deploy-demo.yml +++ b/.github/workflows/deploy-demo.yml @@ -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' diff --git a/.github/workflows/deploy-main.yml b/.github/workflows/deploy-main.yml index a5b3f27acc..ceab47f3a5 100644 --- a/.github/workflows/deploy-main.yml +++ b/.github/workflows/deploy-main.yml @@ -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: @@ -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' diff --git a/.github/workflows/release-candidate.yml b/.github/workflows/release-candidate.yml index 3ea37ff9a6..6f1dd07ac2 100644 --- a/.github/workflows/release-candidate.yml +++ b/.github/workflows/release-candidate.yml @@ -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 }} diff --git a/.github/workflows/release-version.yml b/.github/workflows/release-version.yml index e37c5f9b33..2670fd819b 100644 --- a/.github/workflows/release-version.yml +++ b/.github/workflows/release-version.yml @@ -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: diff --git a/.goreleaser.demo.yaml b/.goreleaser.demo.yaml index fc16bb8408..9c0226551d 100644 --- a/.goreleaser.demo.yaml +++ b/.goreleaser.demo.yaml @@ -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 @@ -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: diff --git a/.goreleaser.dev.yaml b/.goreleaser.dev.yaml index da558bfcce..59bbd55156 100644 --- a/.goreleaser.dev.yaml +++ b/.goreleaser.dev.yaml @@ -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 @@ -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: diff --git a/.goreleaser.rc.yaml b/.goreleaser.rc.yaml index 3f8c7a15dd..256105484c 100644 --- a/.goreleaser.rc.yaml +++ b/.goreleaser.rc.yaml @@ -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 @@ -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: diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 546dfb0ff4..a75013612c 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -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 @@ -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: diff --git a/cli/cmd/resource_select_cmd.go b/cli/cmd/resource_select_cmd.go index 376ed04453..585797f4f2 100644 --- a/cli/cmd/resource_select_cmd.go +++ b/cli/cmd/resource_select_cmd.go @@ -59,4 +59,5 @@ type selectParameters struct { organizationID string environmentID string endpoint string + agentApiKey string } diff --git a/cli/cmd/start_agent_cmd.go b/cli/cmd/start_agent_cmd.go deleted file mode 100644 index 63a6e5ed7a..0000000000 --- a/cli/cmd/start_agent_cmd.go +++ /dev/null @@ -1,58 +0,0 @@ -package cmd - -import ( - "context" - - "github.com/spf13/cobra" -) - -var ( - startAgentParams = &startAgentParameters{} -) - -var startAgentCmd = &cobra.Command{ - Use: "agent", - Short: "Start an Agent", - Long: "Start an Environment Agent", - PreRun: setupCommand(), - Run: WithResultHandler(WithParamsHandler(startAgentParams)(func(_ *cobra.Command, _ []string) (string, error) { - ctx := context.Background() - - endpoint := cliConfig.AgentEndpoint - if startAgentParams.endpoint != "" { - endpoint = startAgentParams.endpoint - } - - err := start.StartAgent(ctx, endpoint, startAgentParams.name, startAgentParams.apiKey, cliConfig.UIEndpoint) - return "", err - })), - PostRun: teardownCommand, -} - -func init() { - if isCloudEnabled { - startAgentCmd.Flags().StringVarP(&startAgentParams.apiKey, "api-key", "", "", "set the agent api key") - startAgentCmd.Flags().StringVarP(&startAgentParams.endpoint, "endpoint", "", "", "set a custom server endpoint") - startAgentCmd.Flags().StringVarP(&startAgentParams.name, "name", "", "default", "set the agent name") - startCmd.AddCommand(startAgentCmd) - } -} - -type startAgentParameters struct { - apiKey string - endpoint string - name string -} - -func (p startAgentParameters) Validate(cmd *cobra.Command, args []string) []error { - var errors []error - - if p.apiKey == "" { - errors = append(errors, paramError{ - Parameter: "api-key", - Message: "The Agent API Key is required.", - }) - } - - return errors -} diff --git a/cli/cmd/start_cmd.go b/cli/cmd/start_cmd.go index 34c720ebc2..c9e92985d8 100644 --- a/cli/cmd/start_cmd.go +++ b/cli/cmd/start_cmd.go @@ -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) @@ -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) } } diff --git a/cli/config/config.go b/cli/config/config.go index b6bafd1e76..dff84005f6 100644 --- a/cli/config/config.go +++ b/cli/config/config.go @@ -14,11 +14,11 @@ 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 { @@ -26,6 +26,7 @@ type ConfigFlags struct { OrganizationID string EnvironmentID string CI bool + AgentApiKey string } type Config struct { @@ -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:"-"` @@ -82,7 +84,7 @@ func LoadConfig(configFile string) (Config, error) { } if config.CloudAPIEndpoint == "" { - config.CloudAPIEndpoint = DefaultCloudAPIEndpoint + config.CloudAPIEndpoint = DefaultCloudEndpoint } homePath, err := os.UserHomeDir() diff --git a/cli/config/configurator.go b/cli/config/configurator.go index 14341155fd..5ec26efe23 100644 --- a/cli/config/configurator.go +++ b/cli/config/configurator.go @@ -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). @@ -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()) @@ -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()) diff --git a/cli/pkg/starter/starter.go b/cli/pkg/starter/starter.go index 3fb94540d2..a3e7caf6ff 100644 --- a/cli/pkg/starter/starter.go +++ b/cli/pkg/starter/starter.go @@ -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())