@@ -2,9 +2,7 @@ package client
22
33import (
44 "fmt"
5- "io/ioutil"
65 kubernetes "litmus-helm-agent/pkg/k8s"
7- "net/http"
86 "os"
97 "reflect"
108 "strconv"
@@ -92,7 +90,7 @@ func GetProjectID(credentials types.Credentials) string {
9290 }
9391 }
9492 if result == "" {
95- utils .Red .Println ("\n ❌ No project found with owner or editor access to current user" + " \n " )
93+ utils .Red .Println ("\n ❌ No project found with owner or editor access to current user" )
9694 os .Exit (1 )
9795 }
9896 return result
@@ -137,11 +135,11 @@ func CreateInfra(credentials types.Credentials) {
137135 }
138136
139137 if connectionData .Data .RegisterInfraDetails .Token == "" {
140- utils .Red .Println ("\n ❌ failed to get the infrastructure registration token: " + " \n " )
138+ utils .Red .Println ("\n ❌ failed to get the infrastructure registration token: " )
141139 os .Exit (1 )
142140 }
143141
144- accessKey , err := validateInfra (connectionData .Data .RegisterInfraDetails .Token , credentials . Endpoint )
142+ accessKey , err := validateInfra (connectionData .Data .RegisterInfraDetails .Manifest )
145143
146144 if err != nil {
147145 utils .Red .Println ("❌ Error validate infrastructure: " , err )
@@ -160,52 +158,38 @@ func CreateInfra(credentials types.Credentials) {
160158
161159 fmt .Printf ("Infra Successfully declared, starting...\n " )
162160 } else {
163- fmt .Printf ("Infra already exist, starting... \n " )
161+ fmt .Printf ("Infra already exist\n " )
164162 }
165163}
166164
167- func validateInfra (token string , endpoint string ) (string , error ) {
168- var accessKey string
165+ func validateInfra (manifest string ) (string , error ) {
169166
170- path := fmt .Sprintf ("%s/%s/%s.yaml" , endpoint , utils .ChaosYamlPath , token )
171- req , err := http .NewRequest ("GET" , path , nil )
172- if err != nil {
173- return accessKey , err
174- }
175- resp , err := http .DefaultClient .Do (req )
176- if err != nil {
177- return accessKey , err
178- }
179- defer resp .Body .Close ()
180- resp_body , err := ioutil .ReadAll (resp .Body )
181- if err != nil {
182- return accessKey , err
183- }
184- manifests := strings .Split (string (resp_body ), "---" )
167+ manifests := strings .Split (manifest , "---" )
185168 for _ , manifest := range manifests {
186169 if len (strings .TrimSpace (manifest )) > 0 {
187170 jsonValue , err := ymlToJson .YAMLToJSON ([]byte (manifest ))
188171 if err != nil {
189- return accessKey , err
172+ return "" , err
190173 }
191174 fieldName , _ , _ , err := jsonparser .Get ([]byte (jsonValue ), "metadata" , "name" )
192175 if err != nil {
193- return accessKey , err
176+ return "" , err
194177 }
195178 fieldKind , _ , _ , err := jsonparser .Get ([]byte (jsonValue ), "kind" )
196179 if err != nil {
197- return accessKey , err
180+ return "" , err
198181 }
199182 if string (fieldName ) == "subscriber-secret" && string (fieldKind ) == "Secret" {
200183 if fieldData , _ , _ , err := jsonparser .Get ([]byte (jsonValue ), "stringData" , "ACCESS_KEY" ); err != nil {
201- return accessKey , err
184+ return "" , err
202185 } else {
203- accessKey = string (fieldData )
186+ return string (fieldData ), nil
204187 }
205188 }
206189 }
207190 }
208- return accessKey , err
191+
192+ return "" , fmt .Errorf ("Subscriber Secret not found" )
209193}
210194
211195func Login (LITMUS_FRONTEND_URL string , LITMUS_USERNAME string , LITMUS_PASSWORD string ) types.Credentials {
0 commit comments