auth

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthRetryMiddleware

func AuthRetryMiddleware(tokenManager *TokenManager) func(*http.Request, func(*http.Request) (*http.Response, error)) (*http.Response, error)

AuthRetryMiddleware automatically retries requests with fresh tokens on 401/403 errors

func GetAdminToken

func GetAdminToken(settingsFile ...string) (string, error)

GetAdminToken generates an admin token using environment variables or settings file

func GetToken

func GetToken(email, password, apiKey string, opts ...option.RequestOption) (string, error)

GetToken attempts to generate a CloudCIX token for the given credentials

func GetTokenWithURL added in v0.5.1

func GetTokenWithURL(email, password, apiKey, apiURL string, opts ...option.RequestOption) (string, error)

GetTokenWithURL attempts to generate a CloudCIX token for the given credentials with a custom API URL If apiURL is empty, it uses the default configuration from environment variables or defaults

func WithAutoAuth

func WithAutoAuth(tokenManager *TokenManager) option.RequestOption

WithAutoAuth creates a request option that automatically adds authentication

func WithTokenAuth

func WithTokenAuth(token string) option.RequestOption

WithTokenAuth creates a request option that sets the X-Auth-Token header

Types

type TokenInfo

type TokenInfo struct {
	Token     string    `json:"token"`
	ExpiresAt time.Time `json:"expires_at"`
	IssuedAt  time.Time `json:"issued_at"`
}

TokenInfo holds token details and expiration

type TokenManager

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

TokenManager handles automatic token renewal

func NewTokenManager

func NewTokenManager(settings *config.Settings) *TokenManager

NewTokenManager creates a new token manager

func (*TokenManager) GetValidToken

func (tm *TokenManager) GetValidToken(ctx context.Context, opts ...option.RequestOption) (string, error)

GetValidToken returns a valid token, refreshing if necessary

func (*TokenManager) InvalidateToken

func (tm *TokenManager) InvalidateToken()

InvalidateToken forces token refresh on next request

func (*TokenManager) IsTokenValid

func (tm *TokenManager) IsTokenValid() bool

IsTokenValid checks if the current token is still valid

type TokenRequest

type TokenRequest struct {
	Email    string `json:"email"`
	Password string `json:"password"`
	ApiKey   string `json:"api_key"`
}

TokenRequest represents the request payload for token creation

type TokenResponse

type TokenResponse struct {
	Token string `json:"token"`
}

TokenResponse represents the response from token creation

Jump to

Keyboard shortcuts

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