polaris

package
v0.0.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 21, 2021 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package polaris contains code to interact with the Polaris platform on a high level. Relies on the graphql package for low level queries.

Index

Constants

View Source
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

View Source
var (
	// ErrNotFound signals that the specified entity could not be found.
	ErrNotFound = errors.New("not found")

	// ErrNotUnique signals that a request did not result in a unique entity.
	ErrNotUnique = errors.New("not unique")
)

Functions

func FromAwsConfig

func FromAwsConfig(config aws.Config) *awsConfigOption

FromAwsConfig passes the specified AWS configuration as an option to a function accepting AwsConfigOption, IDOption or QueryOption as argument. When given multiple times to a variadic function the last configuration given will be used.

func FromAwsDefault

func FromAwsDefault() *awsConfigOption

FromAwsDefault passes the default AWS configuration as an option to a function accepting AwsConfigOption, IDOption or QueryOption as argument. When given multiple times to a variadic function the last configuration given will be used.

func FromAwsProfile

func FromAwsProfile(profile string) *awsConfigOption

FromAwsProfile passes the AWS configuration identified by the given profile as an option to a function accepting AwsConfigOption, IDOption or QueryOption as argument. When given multiple times to a variadic function the last profile given will be used.

func FromGcpDefault

func FromGcpDefault() *gcpConfigOption

FromGcpDefault passes the default GCP configuration as an option to a function accepting GcpConfigOption or QueryOption as argument. When given multiple times to a variadic function the last key file given will be used.

func FromGcpKeyFile

func FromGcpKeyFile(keyFile string) *gcpConfigOption

FromGcpKeyFile passes the GCP configuration identified by the given key file as an option to a function accepting GcpConfigOption or QueryOption as argument. When given multiple times to a variadic function the last key file given will be used.

func FromGcpKeyFileWithProjectID

func FromGcpKeyFileWithProjectID(keyFile, projectID string) *gcpConfigOption

FromGcpKeyFileWithProjectID passes the GCP configuration identified by the given key file and project id as an option to a function accepting GcpConfigOption or QueryOption as argument. When given multiple times to a variadic function the last key file given will be used.

func FromGcpProject

func FromGcpProject(projectID, projectName string, projectNumber int64, orgName string) *gcpConfigOption

FromGcpProject passes the GCP project details as an option to a function accepting GcpConfigOption or QueryOption as argument. When given multiple times to a variadic function the details given will be used.

func WithAwsID

func WithAwsID(id string) *queryAndIDOption

WithAwsID passes the specified AWS id as an option to a function accepting IDOption or QueryOption as argument. When given multiple times to a variadic function only the first id will be used. Note that cloud service provider specific options that also specifies an id, directly or indirectly, takes priority.

func WithAzureSubscriptionID added in v0.0.13

func WithAzureSubscriptionID(subscriptionID string) *azureSubscriptionID

WithAzureSubscriptionID -

func WithGcpProjectID

func WithGcpProjectID(projectID string) *queryOption

WithGcpProjectID passes the specified GCP project id as an option to a function accepting QueryOption as argument. When given multiple times to a variadic function only the first project id will be used. Note that cloud service provider specific options that also specifies a project id, directly or indirectly, takes priority.

func WithGcpProjectNumber

func WithGcpProjectNumber(projectNumber int64) *queryOption

WithGcpProjectNumber passes the specified GCP project number as an option to a function accepting QueryOption as argument. When given multiple times to a variadic function only the first project number will be used. Note that cloud service provider specific options that also specifies a project number, directly or indirectly, takes priority.

func WithName

func WithName(name string) *addAndQueryOption

WithName passes the specified name as an option to a function accepting AddOption or QueryOption as argument. When given multiple times to a variadic function the last name given will be used.

func WithPolarisSubscriptionID added in v0.0.13

func WithPolarisSubscriptionID(subscriptionID string) *polarisSubscriptionID

WithPolarisSubscriptionID -

func WithPrefix added in v0.0.13

func WithPrefix(prefix string) *azureSubscriptionQuery

WithPrefix returns an Azure subscription query for a specific prefix. The prefix is matched against the Azure subscription id, the Polaris subscription id and the subscription name.

func WithRegion

func WithRegion(region string) *addOption

WithAddOption passes the specified region as an option to a function accepting AddOption as argument. When given multiple times to a variadic function all regions will be used.

func WithRegions

func WithRegions(regions ...string) *addOption

WithRegions passes the specified set of regions as an option to a function accepting AddOption as argument. When given multiple times to a variadic function all regions will be used.

func WithStatus added in v0.0.13

func WithStatus(status graphql.CloudAccountStatus) *azureSubscriptionQuery

WithStatus returns an Azure subscription query for a specific status.

func WithUUID

func WithUUID(id string) *idOption

WithUUID passes the specified uuid as an option to a function accepting IDOption as an argument. When given multiple times to a variadic function the last uuid given will be used.

Types

type Account

type Account struct {
	// Polaris account name.
	Name string

	// Polaris account username.
	Username string

	// Polaris account password.
	Password string

	// Optional Polaris API endpoint. Useful for running the SDK against a test
	// service. Defaults to https://{Account}.my.rubrik.com/api.
	URL string
}

Account holds the Polaris account configuration.

func AccountFromEnv

func AccountFromEnv() (Account, error)

AccountFromEnv returns a new Accoount from the user's environment variables. Environment variables must have the same name as the Account fields but be all upper case and prepended with RUBRIK_POLARIS_ACCOUNT, e.g. RUBRIK_POLARIS_ACCOUNT_USERNAME.

func AccountFromFile

func AccountFromFile(file, name string) (Account, error)

AccountFromFile returns a new Account read from the specified file. Files must be in JSON format and the attributes must have the same name as the Account fields but be all lower case. Note that the Name field is used as a key for the JSON object. E.g:

{
  "account-name-1": {
    "username": "username-1",
    "password": "password-1"
  },
  "account-name-2": {
    "username": "username-2",
    "password": "password-2",
    "url": "https://polaris-url/api"
  }
}

func DefaultAccount

func DefaultAccount(name string) (Account, error)

DefaultAccount returns a new Account read from the default account file. Environment variables can be used to override user information in the file. See AccountFromEnv 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.

type AddOption

type AddOption interface {
	// contains filtered or unexported methods
}

AddOption accept options valid for an add operation.

type AwsAccountFeature

type AwsAccountFeature struct {
	Feature    string
	AwsRegions []string
	RoleArn    string
	StackArn   string
	Status     string
}

AwsAccountFeature AWS account features.

type AwsCloudAccount

type AwsCloudAccount struct {
	ID       string
	NativeID string
	Name     string
	Message  string
	Features []AwsAccountFeature
}

AwsCloudAccount AWS cloud account.

type AwsConfigOption

type AwsConfigOption interface {
	// contains filtered or unexported methods
}

AwsConfigOption accepts AWS configuration options.

type AwsProtectionFeature

type AwsProtectionFeature string

AwsProtectionFeature represents the protection features of an AWS cloud account.

const (
	// AwsEC2 AWS EC2.
	AwsEC2 AwsProtectionFeature = "EC2"

	// AwsRDS AWS RDS.
	AwsRDS AwsProtectionFeature = "RDS"
)

type AzureFeature added in v0.0.13

type AzureFeature struct {
	Name    graphql.CloudAccountFeature
	Status  graphql.CloudAccountStatus
	Regions []graphql.AzureRegion
}

AzureFeature Azure feature.

type AzureServicePrincipal added in v0.0.13

type AzureServicePrincipal struct {
	Cloud        graphql.AzureCloud
	AppID        uuid.UUID
	AppName      string
	AppSecret    string
	TenantID     uuid.UUID
	TenantDomain string
}

AzureServicePrincipal Azure service principal used by Polaris to access one or more Azure subscriptions.

func AzureDefaultServicePrincipal added in v0.0.13

func AzureDefaultServicePrincipal() (AzureServicePrincipal, error)

AzureDefaultServicePrincipal -

func AzureServicePrincipalFromFile added in v0.0.13

func AzureServicePrincipalFromFile(file string) (AzureServicePrincipal, error)

AzureServicePrincipalFromFile -

type AzureServicePrincipalConfig added in v0.0.13

type AzureServicePrincipalConfig struct {
	AppID        string `json:"app_id"`
	AppName      string `json:"app_name"`
	AppSecret    string `json:"app_secret"`
	TenantID     string `json:"tenant_id"`
	TenantDomain string `json:"tenant_domain"`
}

AzureServicePrincipalConfig -

type AzureSubscription added in v0.0.13

type AzureSubscription struct {
	ID           uuid.UUID
	NativeID     uuid.UUID
	Name         string
	TenantDomain string
	Feature      AzureFeature
}

AzureSubscription Azure subscription. Note that ID is the Polaris subscription id and NativeID the actual Azure subscription id.

type AzureSubscriptionConfig added in v0.0.13

type AzureSubscriptionConfig struct {
	ID           string   `json:"id"`
	Name         string   `json:"name"`
	TenantDomain string   `json:"tenant_domain"`
	Regions      []string `json:"regions"`
}

AzureSubscriptionConfig -

type AzureSubscriptionID added in v0.0.13

type AzureSubscriptionID interface {
	// contains filtered or unexported methods
}

AzureSubscriptionID -

type AzureSubscriptionIn added in v0.0.13

type AzureSubscriptionIn struct {
	Cloud        graphql.AzureCloud
	ID           uuid.UUID
	Name         string
	TenantDomain string
	Regions      []graphql.AzureRegion
}

AzureSubscriptionIn -

func AzureDefaultSubscription added in v0.0.13

func AzureDefaultSubscription() (AzureSubscriptionIn, error)

AzureDefaultSubscription -

func AzureSubscriptionFromFile added in v0.0.13

func AzureSubscriptionFromFile(file string) (AzureSubscriptionIn, error)

AzureSubscriptionFromFile -

type AzureSubscriptionOut added in v0.0.13

type AzureSubscriptionOut struct {
	TenantID uuid.UUID
	ID       uuid.UUID
	NativeID uuid.UUID
}

AzureSubscriptionOut -

type AzureSubscriptionQuery added in v0.0.13

type AzureSubscriptionQuery interface {
	// contains filtered or unexported methods
}

AzureSubscriptionQuery -

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is used to make calls to the Polaris platform.

func NewClient

func NewClient(account Account, logger log.Logger) (*Client, error)

NewClient returns a new Client from the specified Account. The log level of the given logger can be changed at runtime using the environment variable RUBRIK_POLARIS_LOGLEVEL.

func NewClientFromServiceAccount

func NewClientFromServiceAccount(account ServiceAccount, logger log.Logger) (*Client, error)

NewClientFromServiceAccount returns a new Client from the specified ServiceAccount. The log level of the given logger can be changed at runtime using the environment variable RUBRIK_POLARIS_LOGLEVEL.

func (*Client) AwsAccount

func (c *Client) AwsAccount(ctx context.Context, queryOpt QueryOption) (AwsCloudAccount, error)

AwsAccount returns cloud accounts the same way as AwsAccounts but expects to return only a single account, otherwise it returns an error.

func (*Client) AwsAccountAdd

func (c *Client) AwsAccountAdd(ctx context.Context, awsOpt AwsConfigOption, addOpts ...AddOption) error

AwsAccountAdd adds the AWS account identified by the AwsConfigOption to Polaris. The optional AddOptions can be used to specify name and regions. If name isn't explicitly given AWS Organizations will be used to lookup the AWS account name. If that fails the name will be derived from the AWS account id and, if available, the profile name. If no regions are given the default region for the AWS configuration will be used.

func (*Client) AwsAccountRemove

func (c *Client) AwsAccountRemove(ctx context.Context, awsOpt AwsConfigOption, deleteSnapshots bool) error

AwsAccountRemove removes the AWS account identified by the AwsConfigOption from Polaris. If deleteSnapshots are true the snapshots are deleted otherwise they are kept.

func (*Client) AwsAccountSetRegions

func (c *Client) AwsAccountSetRegions(ctx context.Context, idOpts IDOption, regions ...string) error

AwsAccountSetRegions updates the AWS regions for the AWS account identified by the ID option.

func (*Client) AwsAccounts

func (c *Client) AwsAccounts(ctx context.Context, queryOpt QueryOption) ([]AwsCloudAccount, error)

AwsAccounts returns all cloud accounts with cloud native protection matching the given query option.

func (*Client) AzureServicePrincipalSet added in v0.0.13

func (c *Client) AzureServicePrincipalSet(ctx context.Context, principal AzureServicePrincipal) error

AzureServicePrincipalSet sets the service princiapl to use by subscriptions in the same tenant domain.

func (*Client) AzureSubscription added in v0.0.13

func (c *Client) AzureSubscription(ctx context.Context, id AzureSubscriptionID) (AzureSubscription, error)

AzureSubscriptions returns the Azure subscription identified by the specified subscription id.

func (*Client) AzureSubscriptionAdd added in v0.0.13

func (c *Client) AzureSubscriptionAdd(ctx context.Context, subscription AzureSubscriptionIn) error

AzureSubscriptionAdd -

func (*Client) AzureSubscriptionRemove added in v0.0.13

func (c *Client) AzureSubscriptionRemove(ctx context.Context, id AzureSubscriptionID, deleteSnapshots bool) error

AzureSubscriptionRemove removes the Azure subscription identified by the specified subscription id.

func (*Client) AzureSubscriptionSetName added in v0.0.13

func (c *Client) AzureSubscriptionSetName(ctx context.Context, id AzureSubscriptionID, name string) error

AzureSubscriptionSetName -

func (*Client) AzureSubscriptionSetRegions added in v0.0.13

func (c *Client) AzureSubscriptionSetRegions(ctx context.Context, id AzureSubscriptionID, regions ...graphql.AzureRegion) error

AzureSubscriptionSetRegions -

func (*Client) AzureSubscriptions added in v0.0.13

func (c *Client) AzureSubscriptions(ctx context.Context, query ...AzureSubscriptionQuery) ([]AzureSubscription, error)

AzureSubscriptions returns a collection of Azure subscriptions matching the specified query. WithPrefix can be used to search for a prefix on the Azure subscription id, the Polaris subscription id or the subscription name. If both WithPrefix and WithStatus is given only subscription having both conditions are included in the collection. If multiple WithPrefix are given subscriptions have any of the prefixes are included in the collection.

func (*Client) GQLClient

func (c *Client) GQLClient() *graphql.Client

GQLClient returns the underlaying GraphQL client. Can be used to execute low level and raw GraphQL queries against the Polaris platform.

func (*Client) GcpProject

func (c *Client) GcpProject(ctx context.Context, opt QueryOption) (GcpProject, error)

GcpProject returns a single GCP project matching the query option or an error. At the moment only projects with Cloud Native Protection are returned.

func (*Client) GcpProjectAdd

func (c *Client) GcpProjectAdd(ctx context.Context, opt GcpConfigOption) error

GcpProjectAdd adds the GCP project identified by the GcpConfigOption to Polaris. Note that passing a FromGcpProject as the GcpConfigOption requires that a GCP service account has been set.

func (*Client) GcpProjectRemove

func (c *Client) GcpProjectRemove(ctx context.Context, opt QueryOption, deleteSnapshots bool) error

GcpProjectRemove removes the GCP project identified by the GcpConfigOption from Polaris. If deleteSnapshots are true the snapshots are deleted otherwise they are kept.

func (*Client) GcpProjects

func (c *Client) GcpProjects(ctx context.Context, opt QueryOption) ([]GcpProject, error)

GcpProjects returns all GCP projects matching the given query option. At the moment only projects with Cloud Native Protection are returned.

func (*Client) GcpServiceAccount

func (c *Client) GcpServiceAccount(ctx context.Context) (string, error)

GcpServiceAccount gets the default GCP service account name. If no default GCP service account has been set an empty string is returned.

func (*Client) GcpServiceAccountSet

func (c *Client) GcpServiceAccountSet(ctx context.Context, gcpOpt GcpConfigOption, addOpts ...AddOption) error

GcpSetServiceAccount sets the default GCP service account. The set service account will be used for GCP projects added without a service account key file. The optional AddOption can be used to specify a name for the service account, otherwise the service account's project name will be used. Note that it's not possible to remove a service account once it has been set.

type GcpConfigOption

type GcpConfigOption interface {
	// contains filtered or unexported methods
}

GcpConfigOption accepts GCP configuration options.

type GcpProject

type GcpProject struct {
	ID       string
	Name     string
	Features []GcpProjectFeature

	// GCP
	ProjectName      string
	ProjectID        string
	ProjectNumber    int64
	OrganizationName string
}

GcpProject GCP project.

type GcpProjectFeature

type GcpProjectFeature struct {
	Feature string
	Status  string
}

GcpProjectFeature GCP project feature.

type IDOption

type IDOption interface {
	// contains filtered or unexported methods
}

IDOption accept options valid as id for an operation.

type QueryOption

type QueryOption interface {
	// contains filtered or unexported methods
}

QueryOption accepts options valid for a query operation.

type ServiceAccount

type ServiceAccount struct {
	ClientID       string `json:"client_id"`
	ClientSecret   string `json:"client_secret"`
	Name           string `json:"name"`
	AccessTokenURI string `json:"access_token_uri"`
}

ServiceAccount holds the Polaris ServiceAccount configuration.

func DefaultServiceAccount

func DefaultServiceAccount() (ServiceAccount, error)

DefaultServiceAccount returns a new ServiceAccount read from the default service account file. 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 user's environment variables. Environment variables must have the same name as the 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) (ServiceAccount, error)

ServiceAccountFromFile returns a new ServiceAccount read from the specified file. Files must be in JSON format and the attributes must have the same name as the ServiceAccount fields but be all lower case and have words separated by underscores.

Directories

Path Synopsis
Package graphql contains code to interact directly with the Polaris GraphQL API.
Package graphql contains code to interact directly with the Polaris GraphQL API.
Package log contains the Logger interface used by the Polaris SDK.
Package log contains the Logger interface used by the Polaris SDK.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL