mirror of
https://github.com/LukeHagar/developer.sailpoint.com.git
synced 2025-12-09 12:27:47 +00:00
Refactor docusaurus site for Identity Security Cloud
This commit is contained in:
89
docs/tools/sdk/go/creating-resources.md
Normal file
89
docs/tools/sdk/go/creating-resources.md
Normal file
@@ -0,0 +1,89 @@
|
||||
---
|
||||
id: go-sdk-create
|
||||
title: Creating resources with the Go SDK
|
||||
pagination_label: Go SDK
|
||||
sidebar_label: Create a resource
|
||||
sidebar_position: 2
|
||||
sidebar_class_name: gosdk
|
||||
keywords: ['go', 'golang', 'sdk', 'create']
|
||||
description: Learn how to create new resources the Golang SDK in this guide.
|
||||
slug: /tools/sdk/go/create
|
||||
tags: ['SDK', 'Software Development Kit']
|
||||
---
|
||||
|
||||
Here is an example create workgroup script from the beta APIs you can copy into your "sdk.go" instance to try it out:
|
||||
|
||||
```go showLineNumbers
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
sailpoint "github.com/sailpoint-oss/golang-sdk"
|
||||
"github.com/sailpoint-oss/golang-sdk/beta"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
ctx := context.TODO()
|
||||
configuration := sailpoint.NewDefaultConfiguration()
|
||||
apiClient := sailpoint.NewAPIClient(configuration)
|
||||
|
||||
resp, _, err := apiClient.V3.PublicIdentitiesApi.GetPublicIdentities(ctx).Limit(1).Execute()
|
||||
|
||||
identity := "IDENTITY"
|
||||
workgroupName := "DB Access Governance Group"
|
||||
workgroupDescription := "Description of the Governance Group"
|
||||
|
||||
workgroup := beta.WorkgroupDto{
|
||||
Name: &workgroupName,
|
||||
Description: &workgroupDescription,
|
||||
Owner: &beta.OwnerDto{
|
||||
Id: resp[0].Id,
|
||||
Name: resp[0].Name,
|
||||
Type: &identity,
|
||||
},
|
||||
}
|
||||
|
||||
newWorkgroup, request, errMessage := apiClient.Beta.GovernanceGroupsApi.CreateWorkgroup(ctx).WorkgroupDto(workgroup).Execute()
|
||||
|
||||
if errMessage != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error when calling `GovernanceGroupsApi.CreateWorkgroup``: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", request)
|
||||
}
|
||||
|
||||
b, _ := json.MarshalIndent(newWorkgroup, "", " ")
|
||||
fmt.Fprint(os.Stdout, string(b))
|
||||
}
|
||||
```
|
||||
|
||||
The example uses the `GetPublicIdentities` method from the `PublicIdentitiesApi` to pull an identity needed to be the owner of the Workgroup.
|
||||
|
||||
On lines 20-32 the new workgroup object is initialized and sent to the `CreateWorkgroup` method on line 34.
|
||||
|
||||
To run the code, run this command:
|
||||
|
||||
```go
|
||||
go run sdk.go
|
||||
```
|
||||
|
||||
The WorkGroup is assigned to the `newWorkgroup` variable and the details are printed out:
|
||||
|
||||
```json
|
||||
{
|
||||
"created": null,
|
||||
"description": "Description of the Governance Group",
|
||||
"modified": null,
|
||||
"name": "DB Access Governance Group",
|
||||
"owner": {
|
||||
"displayName": "Brian Mendoza",
|
||||
"emailAddress": null,
|
||||
"id": "0003c25c365e492381d4e557b6159f9b",
|
||||
"name": "Brian Mendoza",
|
||||
"type": "IDENTITY"
|
||||
}
|
||||
}
|
||||
```
|
||||
58
docs/tools/sdk/go/deleting-resources.md
Normal file
58
docs/tools/sdk/go/deleting-resources.md
Normal file
@@ -0,0 +1,58 @@
|
||||
---
|
||||
id: go-sdk-delete
|
||||
title: Delete resources with the Go SDK
|
||||
pagination_label: Go SDK
|
||||
sidebar_label: Delete a resource
|
||||
sidebar_position: 4
|
||||
sidebar_class_name: gosdk
|
||||
keywords: ['go', 'golang', 'sdk', 'delete']
|
||||
description: Learn how to delete resources with the Golang SDK in this guide.
|
||||
slug: /tools/sdk/go/delete
|
||||
tags: ['SDK', 'Software Development Kit']
|
||||
---
|
||||
|
||||
Here is an example script that searches for the Workgroup created in [Create a resource](./creating-resources.md) by name and calls the delete method to remove it from your environment.
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
sailpoint "github.com/sailpoint-oss/golang-sdk"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
ctx := context.TODO()
|
||||
configuration := sailpoint.NewDefaultConfiguration()
|
||||
apiClient := sailpoint.NewAPIClient(configuration)
|
||||
|
||||
workgroup, r, err := apiClient.Beta.GovernanceGroupsApi.ListWorkgroups(ctx).Filters(`name eq "DB Access Governance Group"`).Execute()
|
||||
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error when retrieving workgroup`: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
|
||||
}
|
||||
|
||||
response, errorMessage := apiClient.Beta.GovernanceGroupsApi.DeleteWorkgroup(ctx, *workgroup[0].Id).Execute()
|
||||
|
||||
if errorMessage != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error when updating workgroup`: %v\n", errorMessage)
|
||||
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", response)
|
||||
}
|
||||
|
||||
fmt.Fprintf(os.Stdout, "Resource Deleted: %v\n", response.StatusCode)
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
To run the code, run this command:
|
||||
|
||||
```go
|
||||
go run sdk.go
|
||||
```
|
||||
|
||||
The deletionStatus is returned by the SDK with a value of 204.
|
||||
35
docs/tools/sdk/go/error-handling.md
Normal file
35
docs/tools/sdk/go/error-handling.md
Normal file
@@ -0,0 +1,35 @@
|
||||
---
|
||||
id: go-sdk-error-handling
|
||||
title: Error handling with the Go SDK
|
||||
pagination_label: Go SDK
|
||||
sidebar_label: Error Handling
|
||||
sidebar_position: 8
|
||||
sidebar_class_name: gosdk
|
||||
keywords: ['go', 'golang', 'sdk', 'error']
|
||||
description: Learn how to handle errors with the Golang SDK in this guide.
|
||||
slug: /tools/sdk/go/error-handling
|
||||
tags: ['SDK', 'Software Development Kit']
|
||||
---
|
||||
|
||||
The SDK returns the response object, request and error object for each method. The error object will be defined for any response status that falls out of the range of 2xx.
|
||||
|
||||
You can use an `if` statement to check whether there are any errors with the request and take actions on the results, such as logging the message or performing additional actions before exiting the program:
|
||||
|
||||
```go
|
||||
resp, r, err := apiClient.V3.TransformsApi.ListTransforms(ctx).Filters("This is an incorrect string").Execute()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error when calling `TransformsApi.ListTransforms``: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
|
||||
}
|
||||
```
|
||||
|
||||
The program will continue running unless you specify to end it. Use `os.Exit(0)` within the error check to stop execution after an error is found.
|
||||
|
||||
```go
|
||||
resp, r, err := apiClient.V3.TransformsApi.ListTransforms(ctx).Filters("This is an incorrect string").Execute()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error when calling `TransformsApi.ListTransforms``: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
|
||||
os.Exit(0)
|
||||
}
|
||||
```
|
||||
61
docs/tools/sdk/go/getting-started.md
Normal file
61
docs/tools/sdk/go/getting-started.md
Normal file
@@ -0,0 +1,61 @@
|
||||
---
|
||||
id: go-sdk-getting-started
|
||||
title: Getting started with the Go SDK
|
||||
pagination_label: Go SDK
|
||||
sidebar_label: Getting Started
|
||||
sidebar_position: 1
|
||||
sidebar_class_name: gosdk
|
||||
keywords: ['go', 'golang', 'sdk', 'start']
|
||||
description: Learn how to use the Golang SDK in this guide.
|
||||
slug: /tools/sdk/go/getting-started
|
||||
tags: ['SDK', 'Software Development Kit']
|
||||
---
|
||||
|
||||
Once your SDK is installed and configured, you can start accessing the SDK's different functionalities. This guide will walk through some examples of this functionality. To learn how to install and configure the Golang SDK, refer to [Installation and Configuration](./index.mdx).
|
||||
|
||||
### List Transforms
|
||||
|
||||
Create a file in your project called `sdk.go` with the following content:
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
sailpoint "github.com/sailpoint-oss/golang-sdk"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
ctx := context.TODO()
|
||||
configuration := sailpoint.NewDefaultConfiguration()
|
||||
apiClient := sailpoint.NewAPIClient(configuration)
|
||||
|
||||
resp, r, err := apiClient.V3.TransformsApi.ListTransforms(ctx).Execute()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error when calling `TransformsApi.ListTransforms``: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
|
||||
}
|
||||
fmt.Fprintf(os.Stdout, "All Transforms from `TransformsApi.ListTransforms`: %v\n", resp)
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
To run the code, run this command:
|
||||
|
||||
```go
|
||||
go run sdk.go
|
||||
```
|
||||
|
||||
You can make changes to the API you are calling by changing this line:
|
||||
|
||||
```go
|
||||
resp, r, err := apiClient.V3.TransformsApi.ListTransforms(ctx).Execute()
|
||||
```
|
||||
|
||||
- To call a different version of the APIs, change `V3` to `Beta`, `V2`, or `CC`.
|
||||
- To call a different API collection, change `TransformsApi` to another collection, like `SourcesApi`, for example.
|
||||
- To call a different endpoint, change `ListTransforms` to another endpoint, like `GetTransform`, for example.
|
||||
196
docs/tools/sdk/go/index.mdx
Normal file
196
docs/tools/sdk/go/index.mdx
Normal file
@@ -0,0 +1,196 @@
|
||||
---
|
||||
id: go-sdk
|
||||
title: Go SDK
|
||||
pagination_label: Go SDK
|
||||
sidebar_label: Golang
|
||||
sidebar_position: 2
|
||||
sidebar_class_name: gosdk
|
||||
keywords: ['go', 'golang', 'sdk']
|
||||
description: Learn how to use the Golang SDK in this guide.
|
||||
slug: /tools/sdk/go
|
||||
tags: ['SDK', 'Software Development Kit']
|
||||
---
|
||||
|
||||
Read this guide to learn how to use the Go SDK. The Go SDK has some pre-built code examples you can use to learn how to build tools that can interact with IdentityNow.
|
||||
|
||||
## Requirements
|
||||
|
||||
You need the following to use the Go SDK:
|
||||
|
||||
- Golang version 1.18 or above. You can download it [here](https://go.dev/dl/). You can use `go version` to check your version.
|
||||
|
||||
- Your tenant name in IdentityNow. To learn how to find it, refer to [Getting Started](/idn/api/getting-started#find-your-tenant-name). The SDK will use this tenant name to connect to your IdentityNow instance.
|
||||
|
||||
- A PAT with a client secret and ID. To learn how to create one in IDN, refer to [Personal Access Tokens](https://documentation.sailpoint.com/saas/help/common/api_keys.html#generating-a-personal-access-token). The SDK will use this PAT to authenticate with the SailPoint APIs.
|
||||
|
||||
|
||||
## Setup
|
||||
|
||||
<details>
|
||||
<summary>CLI Assisted <em>(Recommended)</em></summary>
|
||||
|
||||
The SailPoint CLI offers a few commands that will allow you to quickly get started with the Go SDK. To learn how to install and use the SailPoint CLI, refer to [SailPoint CLI](https://developer.sailpoint.com/idn/tools/cli#get-the-cli).
|
||||
|
||||
Once the CLI is installed and configured, run this command to create a new Go project with the Go SDK:
|
||||
|
||||
```bash
|
||||
sail sdk init golang go-example
|
||||
```
|
||||
|
||||
Running the command will create the structure for your project:
|
||||
|
||||
```text
|
||||
|-- go-example
|
||||
| |-- go.mod
|
||||
| |-- go.sum
|
||||
| |-- sdk.go
|
||||
```
|
||||
|
||||
Navigate into your project folder and run this command to install the required dependencies:
|
||||
|
||||
```bash
|
||||
go mod tidy
|
||||
```
|
||||
|
||||
The SDK is now installed. To learn how to configure the SDK, refer to the [Configure section](#configure).
|
||||
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Manual Installation</summary>
|
||||
|
||||
To begin your go project, you will need to create a directory for your project.
|
||||
|
||||
To create a project directory, run this command:
|
||||
|
||||
```bash
|
||||
mkdir golang-example
|
||||
```
|
||||
|
||||
Then run this command to change into your project directory:
|
||||
|
||||
```bash
|
||||
cd golang-example
|
||||
```
|
||||
|
||||
To initialize your project and create the `go.mod` file, run this command in your project directory:
|
||||
|
||||
```go
|
||||
go mod init github.com/github-repo-name/golang-example
|
||||
```
|
||||
|
||||
You will edit this file to add the SailPoint SDK to your project.
|
||||
|
||||
To install the SailPoint SDK, run this command:
|
||||
|
||||
```go
|
||||
go get github.com/sailpoint-oss/golang-sdk
|
||||
```
|
||||
|
||||
The SDK is now installed. To learn how to configure the SDK, refer to the [Configure section](#configure).
|
||||
|
||||
</details>
|
||||
|
||||
## Configure
|
||||
|
||||
You must provide configuration to the SDK so that it can authenticate to your SailPoint tenant and make API calls. To do so, you can use a configuration file, "config.json", or environment variables.
|
||||
|
||||
### Configuration File
|
||||
|
||||
The SDK requires a configuration file to be named "config.json". Within the file, provide these key/value pairs: `ClientID`, `ClientSecret`, `BaseUrl`.
|
||||
|
||||
<details>
|
||||
<summary>CLI Assisted <em>(Recommended)</em></summary>
|
||||
The SailPoint CLI offers a command to generate the "config.json" file with your currently configured CLI credentials.
|
||||
|
||||
```bash
|
||||
sail sdk init config
|
||||
```
|
||||
|
||||
If you have multiple environments configured with the CLI, you can pass an additional parameter to state the environment you wish to create a "config.json" for.
|
||||
|
||||
To pass an additional parameter that states the environment you want to configure, run this command:
|
||||
|
||||
```bash
|
||||
sail sdk init config --env devrel
|
||||
```
|
||||
|
||||
#### Example "config.json"
|
||||
|
||||
```json
|
||||
{
|
||||
"ClientID": "g0567b766b413b22c05c66e75d532f1b",
|
||||
"ClientSecret": "cabd0e950a7230b63c1ff45be33fb22065b382b6251a73c61177a8bb5482fcc7",
|
||||
"BaseUrl": "https://[tenant].api.identitynow.com"
|
||||
}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Manual Configuration</summary>
|
||||
|
||||
Create a file named "config.json", and provide these key/value pairs: `ClientID`, `ClientSecret`, `BaseUrl`.
|
||||
|
||||
#### Example "config.json"
|
||||
|
||||
```json
|
||||
{
|
||||
"ClientID": "g0567b766b413b22c05c66e75d532f1b",
|
||||
"ClientSecret": "cabd0e950a7230b63c1ff45be33fb22065b382b6251a73c61177a8bb5482fcc7",
|
||||
"BaseUrl": "https://[tenant].api.identitynow.com"
|
||||
}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
:::warning
|
||||
Please ensure this file is ignored in your version control system (ex. .gitignore for git)
|
||||
:::
|
||||
|
||||
### Environment variable configuration
|
||||
|
||||
You can also store your configuration in environment variables.
|
||||
|
||||
To get your environment variables to persist across terminal sessions, add these exports to your shell profile, something like `~/.bash_profile`.
|
||||
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
|
||||
<Tabs>
|
||||
<TabItem value="linux_mac" label="Linux/Mac" default>
|
||||
|
||||
```bash
|
||||
export SAIL_BASE_URL=https://[tenant].api.identitynow.com
|
||||
export SAIL_CLIENT_ID=[clientID]
|
||||
export SAIL_CLIENT_SECRET=[clientSecret]
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="windows" label="Windows PowerShell">
|
||||
|
||||
```bash
|
||||
$env:SAIL_BASE_URL=https://[tenant].api.identitynow.com
|
||||
$env:SAIL_CLIENT_ID=[clientID]
|
||||
$env:SAIL_CLIENT_SECRET=[clientSecret]
|
||||
```
|
||||
|
||||
To get your environment variables to persist across PowerShell sessions, run these commands instead:
|
||||
|
||||
```powershell
|
||||
[System.Environment]::SetEnvironmentVariable('SAIL_BASE_URL','https://[tenant].api.identitynow.com')
|
||||
[System.Environment]::SetEnvironmentVariable('SAIL_CLIENT_ID','[clientID]')
|
||||
[System.Environment]::SetEnvironmentVariable('SAIL_CLIENT_SECRET','[clientSecret]')
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
## Discuss
|
||||
|
||||
You can use this SDK to build new tools that extend your IDN platform and improve experiences across your organization. Use this guide to get started, and if you have questions, don't hesitate to reach out on the SailPoint Developer Community forum at https://developer.sailpoint.com/discuss!
|
||||
|
||||
## Getting Started
|
||||
|
||||
To get started using the SDK, refer to the [Getting Started Guide](./getting-started.md).
|
||||
78
docs/tools/sdk/go/pagination.md
Normal file
78
docs/tools/sdk/go/pagination.md
Normal file
@@ -0,0 +1,78 @@
|
||||
---
|
||||
id: go-sdk-paginate
|
||||
title: Paginate results with the Go SDK
|
||||
pagination_label: Go SDK
|
||||
sidebar_label: Paginate Results
|
||||
sidebar_position: 5
|
||||
sidebar_class_name: gosdk
|
||||
keywords: ['go', 'golang', 'sdk', 'paginate']
|
||||
description: Learn how to paginate results with the Golang SDK in this guide.
|
||||
slug: /tools/sdk/go/paginate
|
||||
tags: ['SDK', 'Software Development Kit']
|
||||
---
|
||||
|
||||
By default, your requests will return a maximum of 250 records. To return more, you must implement pagination. To learn more about pagination, refer to [Paginating Results](/idn/api/standard-collection-parameters/#paginating-results).
|
||||
|
||||
Pagination is implemented with the SDK in the following code block on line 18:
|
||||
|
||||
```go showLineNumbers
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
sailpoint "github.com/sailpoint-oss/golang-sdk"
|
||||
v3 "github.com/sailpoint-oss/golang-sdk/v3"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
ctx := context.TODO()
|
||||
configuration := sailpoint.NewDefaultConfiguration()
|
||||
apiClient := sailpoint.NewAPIClient(configuration)
|
||||
|
||||
resp, r, err := sailpoint.PaginateWithDefaults[v3.Account](apiClient.V3.AccountsApi.ListAccounts(ctx))
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error when calling `PaginateWithDefaults[v3.Account]``: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
|
||||
}
|
||||
// response from `ListAccounts`: []Account
|
||||
fmt.Fprintf(os.Stdout, "First response from `PaginateWithDefaults[v3.Account]`: %v\n", resp[0].Name)
|
||||
}
|
||||
```
|
||||
|
||||
The `PaginateWithDefaults` function takes a return type, `v3.Account`, and the list method to invoke, in this case `ListAccounts` from the AccountsApi. By default, the `PaginateWithDefaults` method gets 10000 results at an increment of 250.
|
||||
|
||||
To change the limit and increment, you can use the available 'Paginate' function:
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
sailpoint "github.com/sailpoint-oss/golang-sdk"
|
||||
v3 "github.com/sailpoint-oss/golang-sdk/v3"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
ctx := context.TODO()
|
||||
configuration := sailpoint.NewDefaultConfiguration()
|
||||
apiClient := sailpoint.NewAPIClient(configuration)
|
||||
|
||||
resp, r, err := sailpoint.Paginate[v3.Account](apiClient.V3.AccountsApi.ListAccounts(ctx), 0, 250, 150000)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error when calling `Paginate[v3.Account]``: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
|
||||
}
|
||||
// response from `ListAccounts`: []Account
|
||||
fmt.Fprintf(os.Stdout, "First response from `Paginate[v3.Account]`: %v\n", resp[0].Name)
|
||||
}
|
||||
```
|
||||
|
||||
You must provide the `Paginate` function with the following: the return type, `v3.Account`, the list endpoint, `ListAccounts`, the initial offset, `0`, the increment, `250`, and the limit, `150000`.
|
||||
47
docs/tools/sdk/go/retries.md
Normal file
47
docs/tools/sdk/go/retries.md
Normal file
@@ -0,0 +1,47 @@
|
||||
---
|
||||
id: go-sdk-retries
|
||||
title: Retries with the Go SDK
|
||||
pagination_label: Go SDK
|
||||
sidebar_label: Retries
|
||||
sidebar_position: 7
|
||||
sidebar_class_name: gosdk
|
||||
keywords: ['go', 'golang', 'sdk', 'retry']
|
||||
description: Learn how to paginate results with the Golang SDK in this guide.
|
||||
slug: /tools/sdk/go/retries
|
||||
tags: ['SDK', 'Software Development Kit']
|
||||
---
|
||||
|
||||
The SDK uses the [go-retryablehttp](https://github.com/hashicorp/go-retryablehttp) module to support retry logic.
|
||||
|
||||
On line 17-18 of the following example, the SDK is set to retry if there is an unexpected error up to 10 times and wait 2 seconds between each retry:
|
||||
|
||||
```go showLineNumbers
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
sailpoint "github.com/sailpoint-oss/golang-sdk"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
ctx := context.TODO()
|
||||
configuration := sailpoint.NewDefaultConfiguration()
|
||||
apiClient := sailpoint.NewAPIClient(configuration)
|
||||
|
||||
configuration.HTTPClient.RetryMax = 10
|
||||
configuration.HTTPClient.RetryWaitMax = time.Second * 2
|
||||
|
||||
resp, r, err := apiClient.V3.TransformsApi.ListTransforms(ctx).Filters("This is an incorrect string").Execute()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error when calling `TransformsApi.ListTransforms``: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
|
||||
}
|
||||
// response from `ListAccounts`: []Account
|
||||
fmt.Fprintf(os.Stdout, "First response from `TransformsApi.ListTransforms`: %v\n", resp)
|
||||
|
||||
}
|
||||
```
|
||||
88
docs/tools/sdk/go/search.md
Normal file
88
docs/tools/sdk/go/search.md
Normal file
@@ -0,0 +1,88 @@
|
||||
---
|
||||
id: go-sdk-search
|
||||
title: Search with the Go SDK
|
||||
pagination_label: Go SDK
|
||||
sidebar_label: Search
|
||||
sidebar_position: 5
|
||||
sidebar_class_name: gosdk
|
||||
keywords: ['go', 'golang', 'sdk', 'search']
|
||||
description: Learn how to search with the Golang SDK in this guide.
|
||||
slug: /tools/sdk/go/search
|
||||
tags: ['SDK', 'Software Development Kit']
|
||||
---
|
||||
|
||||
To try using the IDN [search functionality](/idn/api/v3/search-post) along with pagination, copy this code into your "sdk.go" file, following the main code:
|
||||
|
||||
```go
|
||||
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 `PaginateSearchApi``: %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"])
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
To run the search, run this command: `go run sdk.go` This example lists all the identities it finds in your tenant.
|
||||
|
||||
There are two ways to configure the search:
|
||||
|
||||
1. You can edit the `searchString` JSON:
|
||||
|
||||
```go showLineNumbers
|
||||
searchString := []byte(`
|
||||
{
|
||||
"indices": [
|
||||
"identities"
|
||||
],
|
||||
"query": {
|
||||
"query": "*"
|
||||
},
|
||||
"sort": [
|
||||
"-name"
|
||||
]
|
||||
}
|
||||
`)
|
||||
```
|
||||
|
||||
In this example, changing the `"indices"` on line 3 from `"identities"` to `"access profiles"` makes the search return access profiles instead of identities.
|
||||
|
||||
2. You can edit the string at the end of this `search.Indices` line to do the same thing as a shortcut:
|
||||
|
||||
```go
|
||||
search.Indices = append(search.Indices, "identities")
|
||||
```
|
||||
|
||||
In this example, the `"identities"` string represents an unmarshalled JSON. Changing `append(search.Indices, "identities")` to `append(search.Indices, "access profiles")` does the same thing that editing the `searchString` JSON does.
|
||||
|
||||
### Paginate search results
|
||||
|
||||
The search example includes the syntax you can use to paginate search results. Edit this line to configure the search result pagination:
|
||||
|
||||
```go
|
||||
resp, r, err := sailpoint.PaginateSearchApi(ctx, apiClient, *search, 0, 10, 10000)
|
||||
```
|
||||
|
||||
The first value refers to the `initialOffset`, the starting number for the results, the second refers to the `increment`, the number of records per page, and the third refers to the `limit`, the last record that can be returned.
|
||||
|
||||
For example, changing the first number to `21`, the second to `20`, and the third to `40` would configure the search to return records 21 to 40 and then stop.
|
||||
82
docs/tools/sdk/go/updating-resources.md
Normal file
82
docs/tools/sdk/go/updating-resources.md
Normal file
@@ -0,0 +1,82 @@
|
||||
---
|
||||
id: go-sdk-patch
|
||||
title: Updating resources with the Go SDK
|
||||
pagination_label: Go SDK
|
||||
sidebar_label: Update a resource
|
||||
sidebar_position: 3
|
||||
sidebar_class_name: gosdk
|
||||
keywords: ['go', 'golang', 'sdk', 'update']
|
||||
description: Learn how to update resources with the Golang SDK.
|
||||
slug: /tools/sdk/go/update
|
||||
tags: ['SDK', 'Software Development Kit']
|
||||
---
|
||||
|
||||
Here is an example update WorkGroup script which will update the description for the previously created Workgroup from [Create a Resource](./creating-resources.md):
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
sailpoint "github.com/sailpoint-oss/golang-sdk"
|
||||
"github.com/sailpoint-oss/golang-sdk/beta"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
ctx := context.TODO()
|
||||
configuration := sailpoint.NewDefaultConfiguration()
|
||||
apiClient := sailpoint.NewAPIClient(configuration)
|
||||
|
||||
workgroup, r, err := apiClient.Beta.GovernanceGroupsApi.ListWorkgroups(ctx).Filters(`name eq "DB Access Governance Group"`).Execute()
|
||||
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error when retrieving workgroup`: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
|
||||
}
|
||||
|
||||
updatedDescription := `This is an updated description for the workgroup.`
|
||||
newDescriptionValue := beta.JsonPatchOperationValue{String: &updatedDescription}
|
||||
patchArray := []beta.JsonPatchOperation{{Op: "replace", Path: "/description", Value: &newDescriptionValue}}
|
||||
|
||||
updatedWorkgroup, request, errorMessage := apiClient.Beta.GovernanceGroupsApi.PatchWorkgroup(ctx, *workgroup[0].Id).JsonPatchOperation(patchArray).Execute()
|
||||
|
||||
if errorMessage != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error when updating workgroup`: %v\n", errorMessage)
|
||||
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", request)
|
||||
}
|
||||
|
||||
b, _ := json.MarshalIndent(updatedWorkgroup, "", " ")
|
||||
fmt.Fprint(os.Stdout, string(b))
|
||||
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
To run the code, run this command:
|
||||
|
||||
```go
|
||||
go run sdk.go
|
||||
```
|
||||
|
||||
The updated WorkGroup will be returned by the SDK:
|
||||
|
||||
```json
|
||||
{
|
||||
"created": "2023-12-04T19:37:28Z",
|
||||
"description": "This is an updated description for the workgroup.",
|
||||
"modified": "2023-12-04T19:37:28Z",
|
||||
"name": "DB Access Governance Group",
|
||||
"owner": {
|
||||
"displayName": "Brian Mendoza",
|
||||
"emailAddress": null,
|
||||
"id": "0003c25c365e492381d4e557b6159f9b",
|
||||
"name": "Brian Mendoza",
|
||||
"type": "IDENTITY"
|
||||
}
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user