sgcp

package
v3.0.0-rc67 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sgcp provides utility functions for SGCP API interactions. It uses a YAML configuration file to avoid hardcoding API paths in the code.

Index

Constants

View Source
const (
	FsDefaultPermission = "read-write"
	FsDefaultProtocol   = "nfs4.1"

	// FsDefaultExclusive documents the files.fs.exclusive default. The
	// setting is a bool, so its zero value already is that default: no
	// code needs to apply it.
	FsDefaultExclusive = "false"

	// CGDefaultTimeout is the consistency group operations timeout used
	// when files.cg.timeout is unset or is not a parsable duration.
	CGDefaultTimeout = 30 * time.Minute
)

Defaults for the files.fs settings. A driver keyword left unset falls back to the sgcp.yaml value, which itself falls back to these.

Variables

View Source
var (
	DefaultConfigPath = "/etc/om3/sgcp.yaml"
)

SGCPConfig is the global configuration instance

View Source
var FsIgnoredClients = []string{}

FsIgnoredClients is the files.fs.ignored_clients default. It can not be a const, as a slice is not a constant expression.

Functions

func IsDisabled

func IsDisabled(dir string) (bool, error)

IsDisabled returns true when the sgcp support is administratively disabled, which an operator declares by creating the disabled_flag file named by the configuration. A relative flag path is resolved against dir.

A flag that can be neither confirmed present nor absent, because of a permission error on a parent directory or an io error, is reported as an error and not as a disable. The callers act on that error, where reading it as "disabled" would have them quietly skip the work they were asked to do.

func SetConfigForTest

func SetConfigForTest(configFile string)

SetConfigForTest sets the global configuration for testing, loading it from the specified file, or resetting it if null configFile is passed.

Types

type Alias

type Alias struct {
	UUID   string `json:"id,omitempty"`
	Name   string `json:"name,omitempty"`
	Target string `json:"target,omitempty"`
	FQDN   string `json:"fqdn,omitempty"`
	ZoneID string `json:"zoneId,omitempty"`
}

Alias represents a DNS alias.

type Api

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

func (*Api) CheckStatusCode

func (a *Api) CheckStatusCode(method, url string, got int, wanted ...int) error

type AuthConfig

type AuthConfig struct {
	BaseURL       string              `yaml:"base_url" json:"base_url"`
	DefaultSecret string              `yaml:"default_secret"`
	Scopes        map[string][]string `yaml:"scopes"`
	TTLSeconds    int                 `yaml:"ttl_seconds"`
	Timeout       int                 `yaml:"timeout"`
}

AuthConfig contains authentication configuration

type AuthInfo

type AuthInfo struct {
	AccountID    string
	ClientID     string
	ClientSecret string

	// Signature identifies auth info
	Signature string
}

AuthInfo represents authentication details required for API access.

type CacheConfig

type CacheConfig struct {
	TTLSeconds int `yaml:"ttl_seconds"`
}

CacheConfig contains caching configuration. A zero ttl_seconds disables the caching.

type Config

type Config struct {
	Files        FilesConfig `yaml:"files"`
	DNS          DNSConfig   `yaml:"dns"`
	Auth         AuthConfig  `yaml:"auth"`
	Cache        CacheConfig `yaml:"cache"`
	DisabledFlag string      `yaml:"disabled_flag"`
}

Config represents the SGCP configuration structure

func GetConfig

func GetConfig() *Config

GetConfig returns the global SGCP configuration, loading it once

func (*Config) Clone

func (c *Config) Clone() *Config

func (*Config) GetDefaultSecret

func (c *Config) GetDefaultSecret() string

GetDefaultSecret returns the default secret name

func (*Config) GetScopes

func (c *Config) GetScopes(scopeType string) []string

GetScopes returns the auth scopes for a given scope type

func (*Config) WithAuthSecret

func (c *Config) WithAuthSecret(s string) *Config

func (*Config) WithDNSBaseURL

func (c *Config) WithDNSBaseURL(s string) *Config

func (*Config) WithFileURL

func (c *Config) WithFileURL(s string) *Config

type DNSAPI

type DNSAPI struct {
	Api
	// contains filtered or unexported fields
}

DNSAPI provides methods for DNS alias management.

func NewDNSAPI

func NewDNSAPI(config *Config, client *http.Client, l *plog.Logger, tk tokenGetter) *DNSAPI

NewDNSAPI creates a new DNSAPI instance.

func (*DNSAPI) CreateAlias

func (a *DNSAPI) CreateAlias(ctx context.Context, zoneID, name, target string) (alias *Alias, err error)

CreateAlias creates a new DNS alias.

func (*DNSAPI) DeleteAlias

func (a *DNSAPI) DeleteAlias(ctx context.Context, zoneID, aliasUUID string) error

DeleteAlias deletes a DNS alias.

func (*DNSAPI) GetAliases

func (a *DNSAPI) GetAliases(ctx context.Context, zoneID, name, uuid string) (method, url string, code int, data []byte, err error)

GetAliases retrieves aliases matching the given criteria.

func (*DNSAPI) GetScopes

func (a *DNSAPI) GetScopes(scopeType string) []string

GetScopes returns the scopes for a given scope type.

func (*DNSAPI) UpdateAlias

func (a *DNSAPI) UpdateAlias(ctx context.Context, zoneID, aliasUUID, name, target string) (alias *Alias, err error)

UpdateAlias updates an existing DNS alias (PATCH, target only).

type DNSConfig

type DNSConfig struct {
	BaseURL    string `yaml:"base_url"`
	NoneTarget string `yaml:"none_target"`
	Path       struct {
		CName string `yaml:"cname"`
		Zone  string `yaml:"zone"`
	} `yaml:"path"`
}

DNSConfig contains DNS-related API configuration

type FilesAPI

type FilesAPI struct {
	Api
	// contains filtered or unexported fields
}

FilesAPI provides methods for file-related API operations

func NewFilesAPI

func NewFilesAPI(config *Config, client *http.Client, l *plog.Logger, tk tokenGetter) *FilesAPI

NewFilesAPI creates a new FilesAPI instance

func (*FilesAPI) DeleteNFSClients

func (a *FilesAPI) DeleteNFSClients(ctx context.Context, fsUUID, clientUUID string) (method, url string, code int, data []byte, err error)

func (*FilesAPI) GetConsistencyGroup

func (a *FilesAPI) GetConsistencyGroup(ctx context.Context, uuid string) (method, url string, code int, data []byte, err error)

GetConsistencyGroup fetches a consistency group by uuid.

func (*FilesAPI) GetConsistencyGroupURL

func (a *FilesAPI) GetConsistencyGroupURL(uuid string) string

GetConsistencyGroupURL constructs the URL for a specific consistency group

func (*FilesAPI) GetFilesystem

func (a *FilesAPI) GetFilesystem(ctx context.Context, uuid string) (method, url string, code int, data []byte, err error)

func (*FilesAPI) GetScopes

func (a *FilesAPI) GetScopes(scopeType string) []string

func (*FilesAPI) PatchConsistencyGroup

func (a *FilesAPI) PatchConsistencyGroup(ctx context.Context, uuid string, payload any) (method, url string, code int, data []byte, err error)

func (*FilesAPI) PostNFSClients

func (a *FilesAPI) PostNFSClients(ctx context.Context, uuid string, client *NfsClient) (method, url string, code int, data []byte, err error)

type FilesConfig

type FilesConfig struct {
	BaseURL string `yaml:"base_url"`
	Path    struct {
		FS     string `yaml:"fs"`
		Client string `yaml:"client"`
		CG     string `yaml:"cg"`
	} `yaml:"path"`
	FS struct {
		Permission     string   `yaml:"permission"`
		Protocol       string   `yaml:"protocol"`
		Exclusive      bool     `yaml:"exclusive"`
		IgnoredClients []string `yaml:"ignored_clients"`
	} `yaml:"fs"`
	Client struct{}
	CG     struct {
		Timeout string `yaml:"timeout"`
	} `yaml:"cg"`
}

FilesConfig contains file-related API configuration

func (FilesConfig) CGTimeout

func (c FilesConfig) CGTimeout() time.Duration

CGTimeout returns the consistency group operations timeout parsed from files.cg.timeout. A unset or unparsable value yields CGDefaultTimeout. The duration default unit is the second, so a bare "300" means 5 minutes.

type NfsClient

type NfsClient struct {
	UUID               string `json:"uuid,omitempty"`
	Host               string `json:"host"`
	Permission         string `json:"permission"`
	Protocol           string `json:"protocol"`
	ConsistencyGroupID string `json:"consistencyGroupId,omitempty"`
}

NfsClient represents an NFS client with associated metadata and permissions for a specific filesystem.

type Token

type Token struct {
	AccessToken string `json:"access_token"`
	Scope       string `json:"scope,omitempty"`
	TokenType   string `json:"token_type,omitempty"`
	ExpiresIn   int    `json:"expires_in,omitempty"`
}

Token represents an authentication token used for API access.

type TokenFactory

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

TokenFactory is responsible for generating and caching authentication tokens for API access.

func NewTokenFactory

func NewTokenFactory(log *plog.Logger, client *http.Client, authCfg *AuthConfig, authInfo *AuthInfo) *TokenFactory

NewTokenFactory initializes a new instance of TokenFactory with the provided logger, authentication config, and auth info.

func (*TokenFactory) Clear

func (t *TokenFactory) Clear(scope ...string) error

Clear removes the cached authentication token associated with the provided scope(s). Returns an error if the operation fails.

func (*TokenFactory) Get

func (t *TokenFactory) Get(ctx context.Context, scope ...string) (string, error)

Get retrieves an authentication token for the given context and scopes, utilizing caching for performance optimization. Returns the token as a string or an error if retrieval fails.

Jump to

Keyboard shortcuts

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