tokenmanager

package
v3.0.0-beta-2 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//CM login url
	CMLoginURL              = "/api/login"
	CMVersionURL            = "/api/v1/system/infra/info"
	CMAccessTokenExpiration = 5 * time.Minute
	TokenFetchFailed        = "Failed to fetch token"
	Ok                      = "OK"
	RetryInterval           = time.Duration(10)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Credentials

type Credentials struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

Credentials represent the username and password used for authentication.

type TokenManager

type TokenManager struct {
	ServerURL string

	SslInsecure  bool
	TrustedCerts string

	CMVersion     string
	StatusManager statusmanager.StatusManagerInterface
	// contains filtered or unexported fields
}

TokenManager is responsible for managing the authentication token.

func NewTokenManager

func NewTokenManager(serverURL string, credentials Credentials, trustedCerts string, sslInsecure bool, statusManager statusmanager.StatusManagerInterface) *TokenManager

NewTokenManager creates a new instance of TokenManager.

func (*TokenManager) GetCMVersion

func (tm *TokenManager) GetCMVersion() (string, error)

func (*TokenManager) GetToken

func (tm *TokenManager) GetToken() string

GetToken returns the current valid saved token.

func (*TokenManager) Start

func (tm *TokenManager) Start(stopCh chan struct{})

Start maintains valid token. It fetches a new token before expiry.

func (*TokenManager) SyncToken

func (tm *TokenManager) SyncToken()

SyncToken is a helper function to fetch token and retry on failure

func (*TokenManager) SyncTokenWithoutRetry

func (tm *TokenManager) SyncTokenWithoutRetry() (err error, exit bool)

SyncTokenWithoutRetry retrieves a new token from the CM.

type TokenResponse

type TokenResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	UserID       string `json:"user_id"`
}

TokenResponse represents the response received from the CM.

Jump to

Keyboard shortcuts

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