Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pure Storage Unified Go SDK

Overview

The go-pure-client Go module provides clients for the FlashArray 2.x API and the FlashBlade 2.x API (preview).

Requirements

The module requires Go 1.24 or higher.

Installation

Each REST version is its own Go module. Add the import for the REST version you target:

import gopureclient "github.com/PureStorage-OpenConnect/go-pure-client/flasharray/FA_2_26"

Install it pinned to an SDK release:

go get github.com/PureStorage-OpenConnect/go-pure-client/flasharray/FA_2_26@v0.25.0

or track the latest:

go get github.com/PureStorage-OpenConnect/go-pure-client/flasharray/FA_2_26@latest

Please note: Specific package might be different depending on the REST version used.

Releases are tagged per module with directory-prefixed tags, as Go's multi-module repository rules require (e.g. flasharray/FA_2_26/v0.25.0); go get <module>@vX.Y.Z resolves them automatically.

Configuration

To build client's configuration use configuration builder.

OAuth

An example for OAuth authentication where user is pureuser, issuer is go-test, key id is 123e4567-e89b-12d3-a456-426614174000, client id is 123e4567-e89b-12d3-a456-426614174000, privateKeyBytes contains RSA private key protected by password pwd123:

configuration, err := openapiclient.NewConfigurationBuilder("[ARRAY_URL]").
	OAuth("pureuser", "go-test", "123e4567-e89b-12d3-a456-426614174000", "123e4567-e89b-12d3-a456-426614174000", "pwd123", privateKeyBytes).
	DisableSSLVerification().
	Build()

OAuth configuration for FA can be found here.

API Token

An example for API token authentication:

configuration, err := openapiclient.NewConfigurationBuilder("[ARRAY_URL]").
	APIToken(apiToken).
	DisableSSLVerification().
	Build()

API token can be retrieved via running the following command on the target array:

# pureadmin list --api-token --expose
username  local  123e4567-e89b-12d3-a456-426614174000  2099-12-12 00:00:01 PST  -

Anonymous

An example for anonymous authentication:

configuration, err := openapiclient.NewConfigurationBuilder("[ARRAY_URL]").
	DisableSSLVerification().
	Build()

Builder methods:

Method Description
UserAgent Sets custom user agent
DisableSSLVerification Disables verification of certificate chain
DebugMode Enables debug mode
HTTPClient Sets custom HTTPClient
Timeout Sets request timeout of the default HTTP client
OAuthWithRawTokenID Sets OAuth authentication with raw ID token
OAuth Sets OAuth authentication with private key
APIToken Sets API token authentication
RateLimitRetries Sets maximum number of retries in case of rate limit 429 response

By default requests time out after 90 seconds, including reading the response body. Use Timeout to change this, or Timeout(0) to disable it. When you bring your own client via HTTPClient, set the timeout on that client instead; combining it with Timeout is rejected by Build, as is DisableSSLVerification.

Rate limiting

Arrays rate limit the REST API and answer HTTP 429 (Too Many Requests) when a client sends too much. The client handles this for you: it waits for the time the array asks for in the Retry-After header (or RateLimit-Reset when absent, or a short exponential backoff when neither is sent), adds up to half a second of random jitter, and sends the request again up to max retries limit (default is 5).

The client never waits past the deadline of the context.Context you pass to the API call. Use context.WithTimeout to cap the total time a call, including retries, may take. RateLimitRetries caps how many times the client retries, and Timeout caps each HTTP round trip. Neither caps the wait between retries: that is whatever the array asks for. With context.Background() the total call time is unbounded, so pass a context with a deadline when that matters.

ctx, cancel := context.WithTimeout(context.Background(), 300*time.Second)
defer cancel()

resp, httpResp, err := client.VolumesApi.VolumesGet(ctx).Execute()

Example

package main

import (
	"context"
	"fmt"
	"os"

	openapiclient "github.com/PureStorage-OpenConnect/go-pure-client/flasharray/FA_2_34"
)

func main() {
	url := "10.0.0.1"
	apiToken := "123e4567-e89b-12d3-a456-426614174000"
	configuration, err := openapiclient.NewConfigurationBuilder(url).
		APIToken(apiToken).
		DisableSSLVerification().
		Build()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to create configuration: %v\n", err)
		return
	}

	client, err := openapiclient.NewClient(configuration)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to create client: %v\n", err)
		return
	}
	defer client.Close()

	req := client.VolumesApi.VolumesGet(context.Background())
	resp, httpResp, err := req.Execute()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error when calling `VolumesApi.VolumesGet`: %v\n", err)
		fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", httpResp)
		return
	}
	fmt.Fprintf(os.Stdout, "Response from `VolumesApi.VolumesGet`: %v\n", resp)
}

Packages info

Flash Array

Flash Blade - ⚠️ preview

About

Pure Storage Unified APIs GoLang Client

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors