-
Notifications
You must be signed in to change notification settings - Fork 1
/
identity.go
70 lines (59 loc) · 2.09 KB
/
identity.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package c8y
import (
"context"
"fmt"
"github.com/tidwall/gjson"
)
// IdentityService does something
type IdentityService service
// IdentityOptions Identity parameters required when creating a new externalid
type IdentityOptions struct {
ExternalID string `json:"externalId"`
Type string `json:"type"`
}
// Identity Cumulocity Identity object holding the information about the external id and link to the managed object
type Identity struct {
ExternalID string `json:"externalId"`
Type string `json:"type"`
Self string `json:"self"`
ManagedObject IdentityReference `json:"managedObject"`
Item gjson.Result `json:"-"`
}
// IdentityReference contains the id and self link to the identify resource
type IdentityReference struct {
ID string `json:"id"`
Self string `json:"self"`
}
// Create adds a new external id for the given managed object id
func (s *IdentityService) Create(ctx context.Context, ID string, identityType string, externalID string) (*Identity, *Response, error) {
data := new(Identity)
body := IdentityOptions{
Type: identityType,
ExternalID: externalID,
}
resp, err := s.client.SendRequest(ctx, RequestOptions{
Method: "POST",
Path: fmt.Sprintf("identity/globalIds/%s/externalIds", ID),
Body: body,
ResponseData: data,
})
return data, resp, err
}
/* External ID */
// GetExternalID Get a managed object by an external ID
func (s *IdentityService) GetExternalID(ctx context.Context, identityType string, externalID string) (*Identity, *Response, error) {
data := new(Identity)
resp, err := s.client.SendRequest(ctx, RequestOptions{
Method: "GET",
Path: fmt.Sprintf("identity/externalIds/%s/%s", identityType, externalID),
ResponseData: data,
})
return data, resp, err
}
// Delete removes an existing external id
func (s *IdentityService) Delete(ctx context.Context, identityType, externalID string) (*Response, error) {
return s.client.SendRequest(ctx, RequestOptions{
Method: "DELETE",
Path: fmt.Sprintf("identity/externalIds/%s/%s", identityType, externalID),
})
}