-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexternal_identity.go
More file actions
43 lines (37 loc) · 1.25 KB
/
external_identity.go
File metadata and controls
43 lines (37 loc) · 1.25 KB
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
package ccloud
import (
"fmt"
"net/http"
"github.com/dghubble/sling"
)
var ErrFailedToCreateExternalIdentity = fmt.Errorf("failed to create external identity")
type ExternalIdentityService struct {
base *http.Client
client *http.Client
sling *sling.Sling
apiSling *sling.Sling
logger Logger
}
func NewExternalIdentityService(client *Client) *ExternalIdentityService {
return &ExternalIdentityService{
base: client.BaseClient,
client: client.HttpClient,
sling: client.sling.New().Add("Content-Type", "application/json"),
apiSling: GetSlingWithNewClient(client.sling, client.BaseClient, client.Logger).ResponseDecoder(JsonDecoder{}),
logger: client.Logger,
}
}
func (s *ExternalIdentityService) CreateExternalIdentity(cloud, accountID string) (string, error) {
responseBody := new(CreateExternalIdentityResponse)
response, err := s.sling.New().Post("/api/external_identities").BodyJSON(&CreateExternalIdentityRequest{
Cloud: cloud,
AccountId: accountID,
}).Receive(responseBody, nil)
if err != nil {
return "", E(ErrFailedToCreateExternalIdentity.Error())
}
if response.StatusCode >= 400 {
return "", E(response.StatusCode, ErrFailedToCreateExternalIdentity.Error())
}
return responseBody.IdentityName, nil
}