Documentation
¶
Overview ¶
Package polaris contains code to interact with the RSC platform on a high level. Relies on the graphql package for low level queries.
Index ¶
- Constants
- Variables
- func SetLogLevelFromEnv(logger log.Logger) error
- type Account
- type CacheParams
- type Client
- func NewClient(account Account) (*Client, error)
- func NewClientWithCacheParams(account Account, cacheParams CacheParams) (*Client, error)
- func NewClientWithLogger(account Account, logger log.Logger) (*Client, error)
- func NewClientWithLoggerAndCacheParams(account Account, cacheParams CacheParams, logger log.Logger) (*Client, error)
- type ServiceAccount
- func DefaultServiceAccount(allowEnvOverride bool) (*ServiceAccount, error)
- func ServiceAccountFromEnv() (*ServiceAccount, error)
- func ServiceAccountFromFile(file string, allowEnvOverride bool) (*ServiceAccount, error)
- func ServiceAccountFromText(text string, allowEnvOverride bool) (*ServiceAccount, error)
- type UserAccount
Constants ¶
const ( // DefaultLocalUserFile path to the default local users file. DefaultLocalUserFile = "~/.rubrik/polaris-accounts.json" // DefaultServiceAccountFile path to the default service account file. DefaultServiceAccountFile = "~/.rubrik/polaris-service-account.json" )
Variables ¶
var ( // ErrAccountNotFound signals that the account could not be found. // Note that this is different from the account data being invalid or // malformed. ErrAccountNotFound = errors.New("account not found") )
Functions ¶
func SetLogLevelFromEnv ¶ added in v0.7.0
SetLogLevelFromEnv sets the log level of the logger to the log level specified in the RUBRIK_POLARIS_LOGLEVEL environment variable.
Types ¶
type Account ¶
type Account interface { // AccountName returns the RSC account name. AccountName() string // AccountFQDN returns the fully qualified domain name of the RSC account. AccountFQDN() string // APIURL returns the RSC account API URL. APIURL() string // TokenURL returns the RSC account token URL. TokenURL() string // contains filtered or unexported methods }
Account represents a Polaris account. Implemented by UserAccount and ServiceAccount.
func FindAccount ¶ added in v0.11.0
FindAccount looks for a valid Account using the passed in credentials string with the following algorithm:
When credentials string contains a value:
Try and read the service account by interpreting the credentials string as a service account.
Try and read the service account by interpreting the credentials string as a path to a file holding the service account.
If the default user account file exist, try and read the user account from the file by interpreting the credentials string as the user account name.
When the credentials string is empty:
If the default service account file exist, try and read the service account from the file.
If env contains a service account, try and read the service account from env.
Note, when reading an account from file, environment variables can be used to override account information.
type CacheParams ¶ added in v0.11.0
type CacheParams struct { Enable bool // Enable the token cache. Dir string // Directory to store the cached tokens in. Secret string // Secret to encrypt the cached tokens with. }
CacheParams is used to configure the token cache.
Note, if the user account or service account has environment variable override enabled, the cache param values can be overridden.
type Client ¶
Client is used to make calls to the RSC platform.
func NewClient ¶
NewClient returns a new Client for the specified Account.
The client will cache authentication tokens by default, this behavior can be overridden by setting the environment variable RUBRIK_POLARIS_TOKEN_CACHE to false, given that the account specified allows environment variable overrides.
func NewClientWithCacheParams ¶ added in v0.11.0
func NewClientWithCacheParams(account Account, cacheParams CacheParams) (*Client, error)
NewClientWithCacheParams returns a new Client for the specified Account.
Note, the cache parameters specified can be overridden by environmental variables if the specified account allows environment variable overrides.
func NewClientWithLogger ¶ added in v0.7.0
NewClientWithLogger returns a new Client for the specified Account.
The client will cache authentication tokens by default, this behavior can be overridden by setting the environment variable RUBRIK_POLARIS_TOKEN_CACHE to false, given that the account specified allows environment variable overrides.
func NewClientWithLoggerAndCacheParams ¶ added in v0.11.0
func NewClientWithLoggerAndCacheParams(account Account, cacheParams CacheParams, logger log.Logger) (*Client, error)
NewClientWithLoggerAndCacheParams returns a new Client for the specified Account.
Note, the cache parameters specified can be overridden by environmental variables if the specified account allows environment variable overrides.
type ServiceAccount ¶
type ServiceAccount struct { ClientID string `json:"client_id"` // Client ID. ClientSecret string `json:"client_secret"` // Client secret. Name string `json:"name"` // Service account name. AccessTokenURI string `json:"access_token_uri"` // Access token URI. // contains filtered or unexported fields }
ServiceAccount holds an RSC ServiceAccount configuration. The Name field holds the name of the service account and not the name of the RSC account.
func DefaultServiceAccount ¶
func DefaultServiceAccount(allowEnvOverride bool) (*ServiceAccount, error)
DefaultServiceAccount returns a new ServiceAccount read from the RSC service account file at the default service account location.
If allowEnvOverride is true, environment variables can be used to override account information in the file. See ServiceAccountFromEnv for details. In addition, the environment variable RUBRIK_POLARIS_SERVICEACCOUNT_FILE can be used to override the file that the service account is read from.
func ServiceAccountFromEnv ¶
func ServiceAccountFromEnv() (*ServiceAccount, error)
ServiceAccountFromEnv returns a new ServiceAccount from the current environment. The account can be stored as a single environment variable (RUBRIK_POLARIS_SERVICEACCOUNT_CREDENTIALS) or as multiple environment variables. When using a single environment variable, the content should be the RSC service account file downloaded from RSC when creating the service account. When using multiple environment variables, they must have the same name as the public ServiceAccount fields but be all upper case and prepended with RUBRIK_POLARIS_SERVICEACCOUNT, e.g. RUBRIK_POLARIS_SERVICEACCOUNT_NAME.
func ServiceAccountFromFile ¶
func ServiceAccountFromFile(file string, allowEnvOverride bool) (*ServiceAccount, error)
ServiceAccountFromFile returns a new ServiceAccount read from the specified RSC service account file.
If allowEnvOverride is true environment variables can be used to override account information in the file. See ServiceAccountFromEnv for details. In addition, the environment variable RUBRIK_POLARIS_SERVICEACCOUNT_FILE can be used to override the file that the service account is read from.
func ServiceAccountFromText ¶ added in v0.11.0
func ServiceAccountFromText(text string, allowEnvOverride bool) (*ServiceAccount, error)
ServiceAccountFromText returns a new ServiceAccount read from the specified text containing an RSC service account.
If allowEnvOverride is true environment variables can be used to override account information in the file. See ServiceAccountFromEnv for details. In addition, the environment variable RUBRIK_POLARIS_SERVICEACCOUNT_FILE can be used to override the file that the service account is read from.
func (*ServiceAccount) APIURL ¶ added in v0.10.0
func (a *ServiceAccount) APIURL() string
APIURL returns the RSC account API URL.
func (*ServiceAccount) AccountFQDN ¶ added in v0.10.0
func (a *ServiceAccount) AccountFQDN() string
AccountFQDN returns the fully qualified domain name of the RSC account.
func (*ServiceAccount) AccountName ¶ added in v0.10.0
func (a *ServiceAccount) AccountName() string
AccountName returns the RSC account name. Note, this might not be the same as the name of the ServiceAccount.
func (*ServiceAccount) TokenURL ¶ added in v0.10.0
func (a *ServiceAccount) TokenURL() string
TokenURL returns the RSC account token URL.
type UserAccount ¶ added in v0.3.0
type UserAccount struct { Name string // User account name. Username string // RSC account username. Password string // RSC account password. // Optional RSC API endpoint. Useful for running the SDK against a test // service. When omitted, it defaults to https://{Name}.my.rubrik.com/api. URL string // contains filtered or unexported fields }
UserAccount holds an RSC local user account configuration. Depending on how the local user account is stored, the Name field might hold the RSC account name.
Note, RSC user accounts with MFA enabled cannot be used.
func DefaultUserAccount ¶ added in v0.3.0
func DefaultUserAccount(name string, allowEnvOverride bool) (*UserAccount, error)
DefaultUserAccount returns a new UserAccount read from the default account file.
If allowEnvOverride is true environment variables can be used to override user information in the file. See UserAccountFromEnv for details. In addition, the environment variable RUBRIK_POLARIS_ACCOUNT_FILE can be used to override the file that the user information is read from.
Note that RSC user accounts with MFA enabled cannot be used.
func UserAccountFromEnv ¶ added in v0.3.0
func UserAccountFromEnv() (*UserAccount, error)
UserAccountFromEnv returns a new UserAccount from the current environment. The account can be stored as a single JSON encoded environment variable (RUBRIK_POLARIS_ACCOUNT_CREDENTIALS) or as multiple plain text environment variables (e.g. name, username, etc.). When using a single environment variable, the JSON content should have the following structure:
{ "<account-name>": { "username": "<username>", "password": "<password>" } }
Or:
{ "<name-1>": { "username": "<username-1>", "password": "<password-1>", "url": "https://<account-name>.my.rubrik.com/api" }, "<name-2>": { "username": "<username-2>", "password": "<password-2>", "url": "https://<account-name>.my.rubrik.com/api" } }
The later format is used to hold multiple accounts. The environment variable RUBRIK_POLARIS_ACCOUNT_NAME specifies which account to use.
When using multiple environment variables, they must have the same name as the public UserAccount fields but be all upper case and prepended with RUBRIK_POLARIS_ACCOUNT, e.g. RUBRIK_POLARIS_ACCOUNT_NAME.
Note that RSC user accounts with MFA enabled cannot be used.
func UserAccountFromFile ¶ added in v0.3.0
func UserAccountFromFile(file, name string, allowEnvOverride bool) (*UserAccount, error)
UserAccountFromFile returns a new UserAccount read from the specified file. The file must be in the JSON format and the attributes must have the same name as the public UserAccount fields but be all lower case. Note that the name field is used as a key for the JSON object. E.g:
{ "<account-name>": { "username": "<username>", "password": "<password>" } }
Or:
{ "<name-1>": { "username": "<username-1>", "password": "<password-1>", "url": "https://<account-name>.my.rubrik.com/api" }, "<name-2>": { "username": "<username-2>", "password": "<password-2>", "url": "https://<account-name>.my.rubrik.com/api" } }
The later format is used to hold multiple accounts. The URL field is optional, if it is skipped the URL is constructed from the account name.
If allowEnvOverride is true, environment variables can be used to override user information in the file. See UserAccountFromEnv for details. In addition, the environment variable RUBRIK_POLARIS_ACCOUNT_FILE can be used to override the file that the user information is read from.
Note that RSC user accounts with MFA enabled cannot be used.
func (*UserAccount) APIURL ¶ added in v0.10.0
func (a *UserAccount) APIURL() string
APIURL returns the RSC account API URL.
func (*UserAccount) AccountFQDN ¶ added in v0.10.0
func (a *UserAccount) AccountFQDN() string
AccountFQDN returns the fully qualified domain name of the RSC account.
func (*UserAccount) AccountName ¶ added in v0.10.0
func (a *UserAccount) AccountName() string
AccountName returns the RSC account name. Note, this might not be the same as the name of the UserAccount.
func (*UserAccount) TokenURL ¶ added in v0.10.0
func (a *UserAccount) TokenURL() string
TokenURL returns the RSC account token URL.
Directories
¶
Path | Synopsis |
---|---|
Package access provides a high level interface to the users, groups and roles management part of the RSC platform.
|
Package access provides a high level interface to the users, groups and roles management part of the RSC platform. |
Package aws provides a high level interface to the AWS part of the RSC platform.
|
Package aws provides a high level interface to the AWS part of the RSC platform. |
Package azure provides a high-level interface to the Azure part of the RSC platform.
|
Package azure provides a high-level interface to the Azure part of the RSC platform. |
Package gcp provides a high level interface to the GCP part of the RSC platform.
|
Package gcp provides a high level interface to the GCP part of the RSC platform. |
Package graphql provides direct access to the RSC GraphQL API.
|
Package graphql provides direct access to the RSC GraphQL API. |
access
Package access provides a low level interface to the users, groups and roles management GraphQL queries provided by the RSC platform.
|
Package access provides a low level interface to the users, groups and roles management GraphQL queries provided by the RSC platform. |
aws
Package aws provides a low-level interface to the AWS GraphQL queries provided by the Polaris platform.
|
Package aws provides a low-level interface to the AWS GraphQL queries provided by the Polaris platform. |
azure
Package azure provides a low-level interface to the Azure GraphQL queries provided by the Polaris platform.
|
Package azure provides a low-level interface to the Azure GraphQL queries provided by the Polaris platform. |
core
Package core provides a low-level interface to core GraphQL queries provided by the Polaris platform.
|
Package core provides a low-level interface to core GraphQL queries provided by the Polaris platform. |
event
Package event provides a low-level interface to the events GraphQL queries provided by the Polaris platform.
|
Package event provides a low-level interface to the events GraphQL queries provided by the Polaris platform. |
gcp
Package gcp provides a low level interface to the GCP GraphQL queries provided by the RSC platform.
|
Package gcp provides a low level interface to the GCP GraphQL queries provided by the RSC platform. |
Package log contains the Logger interface used by the Polaris SDK.
|
Package log contains the Logger interface used by the Polaris SDK. |
Package token contains functions to request a token from the RSC platform.
|
Package token contains functions to request a token from the RSC platform. |