-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsdk.go
94 lines (80 loc) · 2.89 KB
/
sdk.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"context"
"encoding/json"
"fmt"
"os"
sailpoint "github.com/sailpoint-oss/golang-sdk/v2"
v3 "github.com/sailpoint-oss/golang-sdk/v2/api_v3"
)
func main() {
ctx := context.TODO()
configuration := sailpoint.NewDefaultConfiguration()
apiClient := sailpoint.NewAPIClient(configuration)
configuration.HTTPClient.RetryMax = 10
getBeta(ctx, apiClient)
//getAllPaginatedResults(ctx, apiClient)
}
func getResults(ctx context.Context, apiClient *sailpoint.APIClient) {
resp, r, err := apiClient.V3.AccountsAPI.ListAccounts(ctx).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `AccountsApi.ListAccount``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
// response from `ListAccounts`: []Account
fmt.Fprintf(os.Stdout, "First response from `AccountsApi.ListAccount`: %v\n", resp[0].Name)
}
func getSearchResults(ctx context.Context, apiClient *sailpoint.APIClient) {
search := v3.NewSearchWithDefaults()
search.Indices = append(search.Indices, "identities")
searchString := []byte(`
{
"indices": [
"identities"
],
"query": {
"query": "*"
},
"sort": [
"-name"
]
}
`)
search.UnmarshalJSON(searchString)
resp, r, err := sailpoint.PaginateSearchApi(ctx, apiClient, *search, 0, 10, 10000)
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `AccountsApi.ListAccount``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
// response from `search`
for i := 0; i < len(resp); i++ {
fmt.Println(resp[i]["name"])
}
}
func getTransformResults(ctx context.Context, apiClient *sailpoint.APIClient) {
resp, r, err := apiClient.V3.TransformsAPI.ListTransforms(ctx).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `TransformsApi.GetTransformsList``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
b, _ := json.Marshal(resp[0].Attributes)
fmt.Fprintf(os.Stdout, "First response from `TransformsApi.GetTransformsList`: %v\n", string(b))
}
func getAllPaginatedResults(ctx context.Context, apiClient *sailpoint.APIClient) {
resp, r, err := sailpoint.PaginateWithDefaults[v3.Account](apiClient.V3.AccountsAPI.ListAccounts(ctx))
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `AccountsApi.ListAccount``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
// response from `ListAccounts`: []Account
fmt.Fprintf(os.Stdout, "First response from `AccountsApi.ListAccount`: %v\n", resp[0].Name)
}
func getBeta(ctx context.Context, apiClient *sailpoint.APIClient) {
resp, _, err := apiClient.Beta.AccountsAPI.ListAccounts(context.TODO()).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `AccountsApi.ListAccount``: %v\n", err)
//fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
// response from `ListAccounts`: []Account
fmt.Fprintf(os.Stdout, "First response from `AccountsApi.ListAccount`: %v\n", resp)
}