-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloud.go
46 lines (36 loc) · 1 KB
/
cloud.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package mycscloud
import (
"context"
"github.com/hasura/go-graphql-client"
"github.com/appbricks/cloud-builder/config"
"github.com/mevansam/goutils/logger"
)
type CloudAPI struct {
apiClient *graphql.Client
}
func NewCloudAPI(apiClient *graphql.Client) *CloudAPI {
return &CloudAPI{
apiClient: apiClient,
}
}
func (c *CloudAPI) UpdateProperties(
config config.Config,
) error {
var query struct {
MyCSCloudProps struct {
PublicKeyID graphql.String `graphql:"publicKeyID"`
PublicKey graphql.String
} `graphql:"mycsCloudProps"`
}
if err := c.apiClient.Query(context.Background(), &query, nil); err != nil {
logger.ErrorMessage("CloudAPI.UpdateProperties(): mycsCloudProps query returned an error: %s", err.Error())
return err
}
logger.DebugMessage("CloudAPI.UpdateProperties(): mycsCloudProps query returned response: %# v", query)
ac := config.AuthContext()
ac.SetPublicKey(
string(query.MyCSCloudProps.PublicKeyID),
string(query.MyCSCloudProps.PublicKey),
)
return nil
}