common

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2025 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ArkBasicKeyringOverrideEnvVar      = "ARK_BASIC_KEYRING"
	DBusSessionEnvVar                  = "DBUS_SESSION_BUS_ADDRESS"
	DefaultExpirationGraceDeltaSeconds = 60
	MaxKeyringRecordTimeHours          = 12
)

Env vars and definitions

View Source
const (
	Debug    = 4
	Info     = 3
	Warning  = 2
	Error    = 1
	Critical = 0
	Unknown  = -1
)

Log Levels for ArkLogger

View Source
const (
	LoggerStyle        = "LOGGER_STYLE"
	LogLevel           = "LOG_LEVEL"
	LoggerStyleDefault = "default"
)

Logger Environment Variables

View Source
const (
	ArkDisableCertificateVerificationEnvVar = "ARK_DISABLE_CERTIFICATE_VERIFICATION"
)

ArkDisableCertificateVerificationEnvVar Environment variable for disabling certificate validation

Variables

View Source
var GlobalLogger = GetLogger("ark-sdk", -1)

GlobalLogger is the global logger instance for the Ark SDK.

Functions

func AllowOutput

func AllowOutput()

AllowOutput allows output to be displayed.

func DeserializeJSONSnake

func DeserializeJSONSnake(response io.ReadCloser) (interface{}, error)

DeserializeJSONSnake takes an io.ReadCloser response and deserializes it into a map with snake_case keys.

func DisableCertificateVerification

func DisableCertificateVerification()

DisableCertificateVerification disables certificate verification.

func DisableColor

func DisableColor()

DisableColor disables colored output in the console.

func DisableInteractive

func DisableInteractive()

DisableInteractive disables interactive mode.

func DisableVerboseLogging

func DisableVerboseLogging()

DisableVerboseLogging disables verbose logging.

func DisallowOutput

func DisallowOutput()

DisallowOutput disallows output to be displayed.

func EnableCertificateVerification

func EnableCertificateVerification()

EnableCertificateVerification enables certificate verification.

func EnableColor

func EnableColor()

EnableColor enables colored output in the console.

func EnableInteractive

func EnableInteractive()

EnableInteractive enables interactive mode.

func EnableVerboseLogging

func EnableVerboseLogging(logLevel string)

EnableVerboseLogging enables verbose logging with the specified log level.

func ExpandFolder

func ExpandFolder(folder string) string

ExpandFolder expands the given folder path by replacing environment variables and user home directory.

func IsAllowingOutput

func IsAllowingOutput() bool

IsAllowingOutput checks if output is allowed to be displayed.

func IsColoring

func IsColoring() bool

IsColoring checks if colored output is enabled.

func IsConnectionRefused

func IsConnectionRefused(err error) bool

IsConnectionRefused checks if the error is a connection refused error.

func IsInteractive

func IsInteractive() bool

IsInteractive checks if interactive mode is enabled.

func IsVerifyingCertificates

func IsVerifyingCertificates() bool

IsVerifyingCertificates checks if certificate verification is enabled.

func LogLevelFromEnv

func LogLevelFromEnv() int

LogLevelFromEnv retrieves the log level from the environment variable.

func MarshalCookies

func MarshalCookies(cookieJar *cookiejar.Jar) ([]byte, error)

MarshalCookies marshals the cookies into a JSON byte array.

func RandomIPAddress

func RandomIPAddress() string

RandomIPAddress generates a random IPv4 address.

func RandomNumberString

func RandomNumberString(n int) string

RandomNumberString generates a random string of digits of length n.

func RandomPassword

func RandomPassword(n int) string

RandomPassword generates a random password of length n.

func RandomString

func RandomString(n int) string

RandomString generates a random string of length n.

func RetryCall

func RetryCall(
	fn func() error,
	tries int,
	delay int,
	maxDelay *int,
	backoff int,
	jitter interface{},
	logger func(error, int),
) error

RetryCall retries a function call based on the provided parameters.

func SerializeJSONCamel

func SerializeJSONCamel(item interface{}) (map[string]interface{}, error)

SerializeJSONCamel takes an interface and serializes it into a map with camelCase keys.

func SerializeResponseToJSON

func SerializeResponseToJSON(response io.ReadCloser) string

SerializeResponseToJSON takes an io.ReadCloser response and serializes it to a JSON string.

func SetLoggerStyle

func SetLoggerStyle(loggerStyle string)

SetLoggerStyle sets the logger style based on the provided string.

func SetTrustedCertificate

func SetTrustedCertificate(cert string)

SetTrustedCertificate sets the trusted certificate for verification.

func StrToLogLevel

func StrToLogLevel(logLevelStr string) int

StrToLogLevel converts a string representation of a log level to its integer value.

func TrustedCertificate

func TrustedCertificate() string

TrustedCertificate returns the trusted certificate for verification.

func UnmarshalCookies

func UnmarshalCookies(cookies []byte, cookieJar *cookiejar.Jar) error

UnmarshalCookies unmarshals the JSON byte array into the cookies map.

Types

type ArkClient

type ArkClient struct {
	BaseURL string
	// contains filtered or unexported fields
}

ArkClient is a struct that represents a client for the Ark service.

func NewArkClient

func NewArkClient(baseURL string, token string, tokenType string, authHeaderName string, cookieJar *cookiejar.Jar, refreshCallback func(*ArkClient) error) *ArkClient

NewArkClient creates a new instance of ArkClient with the specified parameters.

func NewSimpleArkClient

func NewSimpleArkClient(baseURL string) *ArkClient

NewSimpleArkClient creates a new instance of ArkClient with the specified base URL.

func (*ArkClient) Delete

func (ac *ArkClient) Delete(ctx context.Context, route string, body interface{}) (*http.Response, error)

Delete performs a DELETE request to the specified route.

func (*ArkClient) Get

func (ac *ArkClient) Get(ctx context.Context, route string, params map[string]string) (*http.Response, error)

Get performs a GET request to the specified route with the provided parameters.

func (*ArkClient) GetCookieJar

func (ac *ArkClient) GetCookieJar() *cookiejar.Jar

GetCookieJar returns the cookie jar for the ArkClient.

func (*ArkClient) GetCookies

func (ac *ArkClient) GetCookies() map[string]string

GetCookies returns the cookies for the ArkClient.

func (*ArkClient) GetHeaders

func (ac *ArkClient) GetHeaders() map[string]string

GetHeaders returns the headers for the ArkClient.

func (*ArkClient) GetToken

func (ac *ArkClient) GetToken() string

GetToken returns the token for the ArkClient.

func (*ArkClient) GetTokenType

func (ac *ArkClient) GetTokenType() string

GetTokenType returns the token type for the ArkClient.

func (*ArkClient) Options

func (ac *ArkClient) Options(ctx context.Context, route string) (*http.Response, error)

Options performs an OPTIONS request to the specified route.

func (*ArkClient) Patch

func (ac *ArkClient) Patch(ctx context.Context, route string, body interface{}) (*http.Response, error)

Patch performs a PATCH request to the specified route with the provided body.

func (*ArkClient) Post

func (ac *ArkClient) Post(ctx context.Context, route string, body interface{}) (*http.Response, error)

Post performs a POST request to the specified route with the provided body.

func (*ArkClient) Put

func (ac *ArkClient) Put(ctx context.Context, route string, body interface{}) (*http.Response, error)

Put performs a PUT request to the specified route with the provided body.

func (*ArkClient) SetCookie

func (ac *ArkClient) SetCookie(key string, value string)

SetCookie sets a single cookie for the ArkClient.

func (*ArkClient) SetCookies

func (ac *ArkClient) SetCookies(cookies map[string]string)

SetCookies sets multiple cookies for the ArkClient.

func (*ArkClient) SetHeader

func (ac *ArkClient) SetHeader(key string, value string)

SetHeader sets a single header for the ArkClient.

func (*ArkClient) SetHeaders

func (ac *ArkClient) SetHeaders(headers map[string]string)

SetHeaders sets multiple headers for the ArkClient.

func (*ArkClient) UpdateCookies

func (ac *ArkClient) UpdateCookies(cookies map[string]string)

UpdateCookies updates the cookies for the ArkClient with the provided cookies.

func (*ArkClient) UpdateHeaders

func (ac *ArkClient) UpdateHeaders(headers map[string]string)

UpdateHeaders updates the headers for the ArkClient with the provided headers.

func (*ArkClient) UpdateToken

func (ac *ArkClient) UpdateToken(token string, tokenType string)

UpdateToken updates the token and token type for the ArkClient.

type ArkKeyring

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

ArkKeyring is a struct that represents a keyring for storing and retrieving tokens.

func NewArkKeyring

func NewArkKeyring(serviceName string) *ArkKeyring

NewArkKeyring creates a new instance of ArkKeyring.

func (*ArkKeyring) GetKeyring

func (a *ArkKeyring) GetKeyring(enforceBasicKeyring bool) (*common.BasicKeyring, error)

GetKeyring returns a keyring instance based on the operating system and environment.

func (*ArkKeyring) LoadToken

func (a *ArkKeyring) LoadToken(profile *models.ArkProfile, postfix string, enforceBasicKeyring bool) (*auth.ArkToken, error)

LoadToken loads the token from the keyring for the specified profile and postfix.

func (*ArkKeyring) SaveToken

func (a *ArkKeyring) SaveToken(profile *models.ArkProfile, token *auth.ArkToken, postfix string, enforceBasicKeyring bool) error

SaveToken saves the token to the keyring for the specified profile and postfix.

type ArkLogger

type ArkLogger struct {
	*log.Logger
	// contains filtered or unexported fields
}

ArkLogger is a custom logger for the Ark SDK.

func GetLogger

func GetLogger(app string, logLevel int) *ArkLogger

GetLogger creates a new instance of ArkLogger with the specified application name and log level.

func NewArkLogger

func NewArkLogger(name string, level int, verbose bool, resolveLogLevelFromEnv bool) *ArkLogger

NewArkLogger creates a new instance of ArkLogger with the specified parameters.

func (*ArkLogger) Debug

func (l *ArkLogger) Debug(msg string, v ...interface{})

Debug logs a debug message if the logger is verbose and the log level is set to Debug or higher.

func (*ArkLogger) Error

func (l *ArkLogger) Error(msg string, v ...interface{})

Error logs an error message if the logger is verbose and the log level is set to Error or higher.

func (*ArkLogger) Fatal

func (l *ArkLogger) Fatal(msg string, v ...interface{})

Fatal logs a fatal message if the logger is verbose and the log level is set to Critical or higher, then exits the program.

func (*ArkLogger) Info

func (l *ArkLogger) Info(msg string, v ...interface{})

Info logs an info message if the logger is verbose and the log level is set to Info or higher.

func (*ArkLogger) LogLevel

func (l *ArkLogger) LogLevel() int

LogLevel returns the current log level of the logger.

func (*ArkLogger) SetVerbose

func (l *ArkLogger) SetVerbose(value bool)

SetVerbose sets the verbosity of the logger.

func (*ArkLogger) Warning

func (l *ArkLogger) Warning(msg string, v ...interface{})

Warning logs a warning message if the logger is verbose and the log level is set to Warning or higher.

type ArkPage

type ArkPage[T any] struct {
	Items []*T `json:"items" mapstructure:"items"`
}

ArkPage is a generic struct representing a paginated response from the Ark service.

Directories

Path Synopsis
ssh

Jump to

Keyboard shortcuts

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