@@ -2,7 +2,6 @@ package ecs
22
33import (
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
1514var (
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 (
3433var 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'
4544var AddToECSCmd = & cobra.Command {
4645 Use : "add" ,
4746 Short : Cmd .Short ,
@@ -53,7 +52,7 @@ var AddToECSCmd = &cobra.Command{
5352var 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
6463func 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
9291func 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
128111func 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