Skip to content

Commit b54c18c

Browse files
authored
Add collection flag for postman ECS agent (#234)
- Adds collection flag
1 parent e4b857e commit b54c18c

File tree

2 files changed

+31
-44
lines changed

2 files changed

+31
-44
lines changed

cmd/internal/ecs/add.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ type AddWorkflow struct {
8585

8686
const (
8787
// Tag to use for objects created by the Akita CLI
88-
akitaCreationTagKey = "akita.software:created_by"
89-
akitaCreationTagValue = "Akita Software ECS integration"
90-
akitaModificationTagKey = "akita.software:modified_by"
91-
akitaModificationTagValue = "Akita Software ECS integration"
88+
akitaCreationTagKey = "postman:created_by"
89+
akitaCreationTagValue = "Postman Live Insights ECS integration"
90+
akitaModificationTagKey = "postman:modified_by"
91+
akitaModificationTagValue = "Postman Live Insights ECS integration"
9292

9393
// Separate AWS secrets for the key ID and key secret
9494
// TODO: make these configurable
95-
akitaSecretPrefix = "akita.software/"
95+
akitaSecretPrefix = "postman/"
9696
defaultKeyIDName = akitaSecretPrefix + "api_key_id"
9797
defaultKeySecretName = akitaSecretPrefix + "api_key_secret"
9898

@@ -840,21 +840,25 @@ func modifyTaskState(wf *AddWorkflow) (nextState optionals.Optional[AddWorkflowS
840840
Value: aws.String(akitaCreationTagValue),
841841
})
842842

843-
apiKey, apiSecret := cfg.GetAPIKeyAndSecret()
843+
pKey, pEnv := cfg.GetPostmanAPIKeyAndEnvironment()
844+
envs := []types.KeyValuePair{}
845+
if pEnv != "" {
846+
envs = append(envs, []types.KeyValuePair{
847+
{Name: aws.String("POSTMAN_ENV"), Value: &pEnv},
848+
}...)
849+
}
844850
input.ContainerDefinitions = append(input.ContainerDefinitions, types.ContainerDefinition{
845-
Name: aws.String("akita-agent"),
851+
Name: aws.String("postman-lc-agent"),
846852
// TODO: Cpu and Memory should be omitted for Fargate; they take their default values for EC2 if omitted.
847853
// For now we can leave the defaults in place, but they might be a bit large for EC2.
848-
EntryPoint: []string{"/akita", "apidump", "--project", projectFlag},
849-
Environment: []types.KeyValuePair{
850-
{Name: aws.String("AKITA_API_KEY_ID"), Value: &apiKey},
851-
{Name: aws.String("AKITA_API_KEY_SECRET"), Value: &apiSecret},
852-
854+
EntryPoint: []string{"/postman-lc-agent", "apidump", "--collection", collectionId},
855+
Environment: append(envs, []types.KeyValuePair{
856+
{Name: aws.String("POSTMAN_API_KEY"), Value: &pKey},
853857
// Setting these environment variables will cause the traces to be tagged.
854858
{Name: aws.String("AKITA_AWS_REGION"), Value: &wf.awsRegion},
855859
{Name: aws.String("AKITA_ECS_SERVICE"), Value: &wf.ecsService},
856860
{Name: aws.String("AKITA_ECS_TASK"), Value: &wf.ecsTaskDefinitionFamily},
857-
},
861+
}...),
858862
Essential: aws.Bool(false),
859863
Image: aws.String(postmanECRImage),
860864
})
@@ -998,6 +1002,6 @@ func waitForRestartState(wf *AddWorkflow) (nextState optionals.Optional[AddWorkf
9981002
}
9991003

10001004
reportStep("ECS Service Updated")
1001-
printer.Infof("Deployment successful! Please return to the Akita web console.\n")
1005+
printer.Infof("Deployment successful! Please return to the Postman Live collection you created.\n")
10021006
return awf_done()
10031007
}

cmd/internal/ecs/ecs.go

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package ecs
22

33
import (
44
"fmt"
5-
"strings"
65

76
"github.com/akitasoftware/akita-cli/cmd/internal/cmderr"
87
"github.com/akitasoftware/akita-cli/rest"
@@ -13,8 +12,8 @@ import (
1312
)
1413

1514
var (
16-
// Mandatory flag: Akita project name
17-
projectFlag string
15+
// Mandatory flag: Postman collection id
16+
collectionId string
1817

1918
// Any of these will be interactively prompted if not given on the command line.
2019
// On the other hand, to run non-interactively then all of them *must* be given.
@@ -34,14 +33,14 @@ var (
3433
var Cmd = &cobra.Command{
3534
Use: "ecs",
3635
Short: "Add the Postman Live Collections Agent to AWS ECS.",
37-
Long: "The CLI will collect information from you and add the Akita container to an ECS Task.",
36+
Long: "The CLI will collect information from you and add the Postman Live Collections Agent container to an ECS Task.",
3837
// N.B.: this is useless because the root command makes its own determination,
3938
// need to return AkitaErr to not show the usage.
4039
SilenceUsage: true,
4140
RunE: addAgentToECS,
4241
}
4342

44-
// 'akita ecs' should default to 'akita ecs add'
43+
// 'postman-lc-agent ecs' should default to 'postman-lc-agent ecs add'
4544
var AddToECSCmd = &cobra.Command{
4645
Use: "add",
4746
Short: Cmd.Short,
@@ -53,7 +52,7 @@ var AddToECSCmd = &cobra.Command{
5352
var RemoveFromECSCmd = &cobra.Command{
5453
Use: "remove",
5554
Short: "Remove the Postman Live Collections Agent from AWS ECS.",
56-
Long: "Remove a previously installed Akita container from an ECS Task.",
55+
Long: "Remove a previously installed Postman container from an ECS Task.",
5756
SilenceUsage: true,
5857
RunE: removeAgentFromECS,
5958

@@ -63,7 +62,7 @@ var RemoveFromECSCmd = &cobra.Command{
6362

6463
func init() {
6564
// TODO: add the ability to specify the credentials directly instead of via an AWS profile?
66-
Cmd.PersistentFlags().StringVar(&projectFlag, "project", "", "Your Akita project.")
65+
Cmd.PersistentFlags().StringVar(&collectionId, "collection", "", "Your Postman collection ID")
6766
Cmd.PersistentFlags().StringVar(&awsProfileFlag, "profile", "", "Which of your AWS profiles to use to access ECS.")
6867
Cmd.PersistentFlags().StringVar(&awsRegionFlag, "region", "", "The AWS region in which your ECS cluster resides.")
6968
Cmd.PersistentFlags().StringVar(&ecsClusterFlag, "cluster", "", "The name or ARN of your ECS cluster.")
@@ -91,40 +90,24 @@ func init() {
9190

9291
func addAgentToECS(cmd *cobra.Command, args []string) error {
9392
// Check for API key
94-
_, _, err := cmderr.RequireAkitaAPICredentials("The Postman Live Collections Agent must have an API key in order to capture traces.")
93+
_, err := cmderr.RequirePostmanAPICredentials("The Postman Live Collections Agent must have an API key in order to capture traces.")
9594
if err != nil {
9695
return err
9796
}
9897

99-
// Check project's existence
100-
if projectFlag == "" {
101-
return errors.New("Must specify the name of your Akita project with the --project flag.")
98+
// Check collecton Id's existence
99+
if collectionId == "" {
100+
return errors.New("Must specify the ID of your collection with the --collection flag.")
102101
}
103102
frontClient := rest.NewFrontClient(rest.Domain, telemetry.GetClientID())
104-
_, err = util.GetServiceIDByName(frontClient, projectFlag)
103+
_, err = util.GetOrCreateServiceIDByPostmanCollectionID(frontClient, collectionId)
105104
if err != nil {
106-
// TODO: we _could_ offer to create it, instead.
107-
if strings.Contains(err.Error(), "cannot determine project ID") {
108-
return cmderr.AkitaErr{
109-
Err: fmt.Errorf(
110-
"Could not find the project %q in the Akita cloud. Please create it from the Akita web console before proceeding.",
111-
projectFlag,
112-
),
113-
}
114-
} else {
115-
return cmderr.AkitaErr{
116-
Err: errors.Wrapf(
117-
err,
118-
"Could not look up the project %q in the Akita cloud",
119-
projectFlag,
120-
),
121-
}
122-
}
105+
return err
123106
}
124107

125108
return RunAddWorkflow()
126109
}
127110

128111
func removeAgentFromECS(cmd *cobra.Command, args []string) error {
129-
return fmt.Errorf("This command is not yet implemented")
112+
return fmt.Errorf("this command is not yet implemented")
130113
}

0 commit comments

Comments
 (0)