Skip to main content
Version: v46

Automation with Golang SDK

Use the PrivX Go SDK to configure PrivX programmatically through the PrivX REST API. The SDK has three layers:

  • restapi provides the HTTPS transport for API requests.
  • oauth obtains access tokens using OAuth 2.0.
  • api/... provides type-safe clients for individual PrivX services, such as Role Store.

Here is a typical workflow required to setup the client:

// 1. Create Authorizer and Access Token Provider
auth := oauth.WithClientID(
restapi.New(/* use restapi options to config http */),

// Use oauth2 options to config authorizer
oauth.Access(/* ... */),
oauth.Secret(/* ... */),
)

// 2. Create HTTP transport for PrivX API
curl := restapi.New(
restapi.Auth(provider),

// Use other transport options
)

// 3. Create API client of rolestore feature
client := rolestore.New(curl)

Configuring API Client Permissions​

The roles you assign to an API client determine which operations it can perform in PrivX.

  1. In the PrivX GUI, go to Deployment → API Clients, and select Add API Client.

    • Enter a name for the API client. Under Roles, select the roles required for the operations you want to automate. Save the changes.
  2. Expand Client Credentials for the API client you created. You need these values to configure the SDK.

SDK Configuration Providers​

You can use configuration files to configure the PrivX SDK.
PrivX SDK UseConfigFile supports the following configuration file format:

[api]

# restapi.BaseURL(...)
base_url="https://your-instance.privx.io"

# restapi.X509(...)
api_ca_crt="""Place the TLS Trust Anchor here"""

[auth]

# oauth.Access(...)
api_client_id="00000000-0000-0000-0000-000000000000"

# oauth.Secret(...)
api_client_secret="some-random-base64"

# oauth.Digest(...)
oauth_client_id="privx-external"
oauth_client_secret="another-random-base64"

The required TLS Trust Anchor can be found at the bottom of the page Deployment → API Clients.

Choosing Authentication Method​

Choose the SDK function that matches how your application authenticates to PrivX:

To authenticateUseHow it works
As an API clientoauth.WithClientIDUses the API client credentials and OAuth client credentials with the OAuth 2.0 resource owner password credentials grant.
On behalf of an existing PrivX useroauth.WithCredentialUses the user's credentials with the OAuth 2.0 authorization code grant.
Based on the credentials available at runtimeoauth.WithSelects an authentication method based on the credentials you provide.

PrivX CLI​

PrivX CLI is a command line application that uses the Go SDK to interact with the PrivX REST API.

PrivX CLI is no longer actively maintained. Use it only in test environments. For automation in production, use the PrivX REST API directly or through the Go SDK described in this article.

For examples of how to use the SDK, see the PrivX CLI source code.