feat(client): implemented ListInstances
Some checks failed
Go Tests / go-tests (push) Failing after 1m30s
Some checks failed
Go Tests / go-tests (push) Failing after 1m30s
This commit is contained in:
parent
cf88522e57
commit
90ceb69a18
2 changed files with 99 additions and 1 deletions
|
|
@ -250,6 +250,64 @@ func (e *EdgeConnect) ShowAppInstance(ctx context.Context, appinstkey AppInstanc
|
|||
return response.Data, nil
|
||||
}
|
||||
|
||||
func (e *EdgeConnect) ShowAppInstances(ctx context.Context, appinstkey AppInstanceKey, region string) ([]AppInstance, error) {
|
||||
token, err := e.RetrieveToken(ctx)
|
||||
if err != nil {
|
||||
return []AppInstance{}, err
|
||||
}
|
||||
|
||||
input := struct {
|
||||
App struct {
|
||||
AppInstKey AppInstanceKey `json:"key"`
|
||||
} `json:"appinst"`
|
||||
Region string `json:"Region"`
|
||||
}{
|
||||
App: struct {
|
||||
AppInstKey AppInstanceKey `json:"key"`
|
||||
}{
|
||||
AppInstKey: appinstkey,
|
||||
},
|
||||
Region: region,
|
||||
}
|
||||
|
||||
json_data, err := json.Marshal(input)
|
||||
if err != nil {
|
||||
return []AppInstance{}, err
|
||||
}
|
||||
|
||||
request, err := http.NewRequestWithContext(ctx, "POST", e.BaseURL+"/api/v1/auth/ctrl/ShowAppInst", bytes.NewBuffer(json_data))
|
||||
if err != nil {
|
||||
return []AppInstance{}, err
|
||||
}
|
||||
request.Header.Set("Content-Type", "application/json")
|
||||
request.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
|
||||
|
||||
resp, err := e.HttpClient.Do(request)
|
||||
if err != nil {
|
||||
return []AppInstance{}, err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
type response struct {
|
||||
Data AppInstance `json:"data"`
|
||||
}
|
||||
|
||||
appinstances := []AppInstance{}
|
||||
decoder := json.NewDecoder(resp.Body)
|
||||
for {
|
||||
var d response
|
||||
if err := decoder.Decode(&d); err != nil {
|
||||
if err.Error() == "EOF" {
|
||||
break
|
||||
}
|
||||
log.Fatal(err)
|
||||
}
|
||||
appinstances = append(appinstances, d.Data)
|
||||
}
|
||||
|
||||
return appinstances, nil
|
||||
}
|
||||
|
||||
func (e *EdgeConnect) RetrieveToken(ctx context.Context) (string, error) {
|
||||
json_data, err := json.Marshal(map[string]string{
|
||||
"username": e.Credentials.Username,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue