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
- Variables
- func IsDisabled(dir string) (bool, error)
- func SetConfigForTest(configFile string)
- type Alias
- type Api
- type AuthConfig
- type AuthInfo
- type CacheConfig
- type Config
- type DNSAPI
- func (a *DNSAPI) CreateAlias(ctx context.Context, zoneID, name, target string) (alias *Alias, err error)
- func (a *DNSAPI) DeleteAlias(ctx context.Context, zoneID, aliasUUID string) error
- func (a *DNSAPI) GetAliases(ctx context.Context, zoneID, name, uuid string) (method, url string, code int, data []byte, err error)
- func (a *DNSAPI) GetScopes(scopeType string) []string
- func (a *DNSAPI) UpdateAlias(ctx context.Context, zoneID, aliasUUID, name, target string) (alias *Alias, err error)
- type DNSConfig
- type FilesAPI
- func (a *FilesAPI) DeleteNFSClients(ctx context.Context, fsUUID, clientUUID string) (method, url string, code int, data []byte, err error)
- func (a *FilesAPI) GetConsistencyGroup(ctx context.Context, uuid string) (method, url string, code int, data []byte, err error)
- func (a *FilesAPI) GetConsistencyGroupURL(uuid string) string
- func (a *FilesAPI) GetFilesystem(ctx context.Context, uuid string) (method, url string, code int, data []byte, err error)
- func (a *FilesAPI) GetScopes(scopeType string) []string
- func (a *FilesAPI) PatchConsistencyGroup(ctx context.Context, uuid string, payload any) (method, url string, code int, data []byte, err error)
- func (a *FilesAPI) PostNFSClients(ctx context.Context, uuid string, client *NfsClient) (method, url string, code int, data []byte, err error)
- type FilesConfig
- type NfsClient
- type Token
- type TokenFactory
Constants ¶
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 ¶
var (
DefaultConfigPath = "/etc/om3/sgcp.yaml"
)
SGCPConfig is the global configuration instance
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 ¶
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 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) GetDefaultSecret ¶
GetDefaultSecret returns the default secret name
func (*Config) WithAuthSecret ¶
func (*Config) WithDNSBaseURL ¶
func (*Config) WithFileURL ¶
type DNSAPI ¶
type DNSAPI struct {
Api
// contains filtered or unexported fields
}
DNSAPI provides methods for DNS alias management.
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 ¶
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.
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 ¶
NewFilesAPI creates a new FilesAPI instance
func (*FilesAPI) DeleteNFSClients ¶
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 ¶
GetConsistencyGroupURL constructs the URL for a specific consistency group
func (*FilesAPI) GetFilesystem ¶
func (*FilesAPI) PatchConsistencyGroup ¶
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.