auth

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2022 License: Apache-2.0 Imports: 18 Imported by: 47

Documentation

Index

Constants

View Source
const WaitBeforeRefreshSeconds = 15

Variables

View Source
var InviteRefreshBeforeExpiryMinutes = int64(365*24*60 - 50)

InviteRefreshBeforeExpiryMinutes Invitations mechanism creates tokens that are valid for 1 year. We want to refresh the token every 50 minutes.

View Source
var RefreshBeforeExpiryMinutes = int64(10)

RefreshBeforeExpiryMinutes Artifactory's refresh token mechanism creates tokens that expired in 60 minutes. We want to refresh them after 50 minutes (when 10 minutes left)

Functions

func ExtractExpiryFromAccessToken

func ExtractExpiryFromAccessToken(token string) (int, error)

Extracts the expiry from an access token, in seconds

func ExtractUsernameFromAccessToken

func ExtractUsernameFromAccessToken(token string) (string, error)

func GetTokenMinutesLeft added in v0.9.1

func GetTokenMinutesLeft(token string) (int64, error)

Returns 0 if expired

func IsEncrypted

func IsEncrypted(buffer []byte) (bool, error)

func SshAuthentication

func SshAuthentication(url, sshKeyPath, sshPassphrase string) (sshAuthHeaders map[string]string, newUrl string, err error)

func SshTokenRefreshPreRequestInterceptor added in v0.9.1

func SshTokenRefreshPreRequestInterceptor(fields *CommonConfigFields, httpClientDetails *httputils.HttpClientDetails) error

Handles the process of acquiring a new ssh token

Types

type CommonConfigFields

type CommonConfigFields struct {
	Url                    string                         `json:"-"`
	User                   string                         `json:"-"`
	Password               string                         `json:"-"`
	ApiKey                 string                         `json:"-"`
	AccessToken            string                         `json:"-"`
	PreRequestInterceptors []ServiceDetailsPreRequestFunc `json:"-"`
	ClientCertPath         string                         `json:"-"`
	ClientCertKeyPath      string                         `json:"-"`
	Version                string                         `json:"-"`
	SshUrl                 string                         `json:"-"`
	SshKeyPath             string                         `json:"-"`
	SshPassphrase          string                         `json:"-"`
	SshAuthHeaders         map[string]string              `json:"-"`
	TokenMutex             sync.Mutex
	// contains filtered or unexported fields
}

func (*CommonConfigFields) AppendPreRequestFunction added in v0.21.0

func (ccf *CommonConfigFields) AppendPreRequestFunction(interceptor ServiceDetailsPreRequestFunc)

func (*CommonConfigFields) AuthenticateSsh

func (ccf *CommonConfigFields) AuthenticateSsh(sshKeyPath, sshPassphrase string) error

func (*CommonConfigFields) CreateHttpClientDetails

func (ccf *CommonConfigFields) CreateHttpClientDetails() httputils.HttpClientDetails

func (*CommonConfigFields) GetAccessToken

func (ccf *CommonConfigFields) GetAccessToken() string

func (*CommonConfigFields) GetApiKey

func (ccf *CommonConfigFields) GetApiKey() string

func (*CommonConfigFields) GetClient added in v0.21.0

func (*CommonConfigFields) GetClientCertKeyPath

func (ccf *CommonConfigFields) GetClientCertKeyPath() string

func (*CommonConfigFields) GetClientCertPath

func (ccf *CommonConfigFields) GetClientCertPath() string

func (*CommonConfigFields) GetPassword

func (ccf *CommonConfigFields) GetPassword() string

func (*CommonConfigFields) GetPreRequestFunctions added in v0.21.0

func (ccf *CommonConfigFields) GetPreRequestFunctions() []ServiceDetailsPreRequestFunc

func (*CommonConfigFields) GetSshAuthHeaders

func (ccf *CommonConfigFields) GetSshAuthHeaders() map[string]string

func (*CommonConfigFields) GetSshKeyPath

func (ccf *CommonConfigFields) GetSshKeyPath() string

func (*CommonConfigFields) GetSshPassphrase

func (ccf *CommonConfigFields) GetSshPassphrase() string

func (*CommonConfigFields) GetSshUrl

func (ccf *CommonConfigFields) GetSshUrl() string

func (*CommonConfigFields) GetUrl

func (ccf *CommonConfigFields) GetUrl() string

func (*CommonConfigFields) GetUser

func (ccf *CommonConfigFields) GetUser() string

func (*CommonConfigFields) InitSsh added in v0.10.0

func (ccf *CommonConfigFields) InitSsh() error

func (*CommonConfigFields) IsSshAuthHeaderSet

func (ccf *CommonConfigFields) IsSshAuthHeaderSet() bool

func (*CommonConfigFields) IsSshAuthentication

func (ccf *CommonConfigFields) IsSshAuthentication() bool

func (*CommonConfigFields) RunPreRequestFunctions added in v0.21.0

func (ccf *CommonConfigFields) RunPreRequestFunctions(httpClientDetails *httputils.HttpClientDetails) error

Runs an interceptor before sending a request via the http client

func (*CommonConfigFields) SetAccessToken

func (ccf *CommonConfigFields) SetAccessToken(accessToken string)

func (*CommonConfigFields) SetApiKey

func (ccf *CommonConfigFields) SetApiKey(apiKey string)

func (*CommonConfigFields) SetClient added in v0.21.0

func (ccf *CommonConfigFields) SetClient(client *jfroghttpclient.JfrogHttpClient)

func (*CommonConfigFields) SetClientCertKeyPath

func (ccf *CommonConfigFields) SetClientCertKeyPath(certificatePath string)

func (*CommonConfigFields) SetClientCertPath

func (ccf *CommonConfigFields) SetClientCertPath(certificatePath string)

func (*CommonConfigFields) SetHttpTimeout added in v0.25.0

func (ccf *CommonConfigFields) SetHttpTimeout(httpTimeout time.Duration)

func (*CommonConfigFields) SetPassword

func (ccf *CommonConfigFields) SetPassword(password string)

func (*CommonConfigFields) SetSshAuthHeaders

func (ccf *CommonConfigFields) SetSshAuthHeaders(sshAuthHeaders map[string]string)

func (*CommonConfigFields) SetSshKeyPath

func (ccf *CommonConfigFields) SetSshKeyPath(sshKeyPath string)

func (*CommonConfigFields) SetSshPassphrase

func (ccf *CommonConfigFields) SetSshPassphrase(sshPassphrase string)

func (*CommonConfigFields) SetSshUrl

func (ccf *CommonConfigFields) SetSshUrl(sshUrl string)

func (*CommonConfigFields) SetUrl

func (ccf *CommonConfigFields) SetUrl(url string)

func (*CommonConfigFields) SetUser

func (ccf *CommonConfigFields) SetUser(user string)

type CommonTokenParams added in v1.13.0

type CommonTokenParams struct {
	Scope        string `json:"scope,omitempty"`
	AccessToken  string `json:"access_token,omitempty"`
	ExpiresIn    int    `json:"expires_in,omitempty"`
	TokenType    string `json:"token_type,omitempty"`
	Refreshable  *bool  `json:"refreshable,omitempty"`
	RefreshToken string `json:"refresh_token,omitempty"`
	GrantType    string `json:"grant_type,omitempty"`
	Audience     string `json:"audience,omitempty"`
}

type CreateTokenResponseData added in v1.13.0

type CreateTokenResponseData struct {
	CommonTokenParams
}

type ServiceDetails added in v0.10.0

type ServiceDetails interface {
	GetUrl() string
	GetUser() string
	GetPassword() string
	GetApiKey() string
	GetAccessToken() string
	GetPreRequestFunctions() []ServiceDetailsPreRequestFunc
	GetClientCertPath() string
	GetClientCertKeyPath() string
	GetSshUrl() string
	GetSshKeyPath() string
	GetSshPassphrase() string
	GetSshAuthHeaders() map[string]string
	GetClient() *jfroghttpclient.JfrogHttpClient
	GetVersion() (string, error)

	SetUrl(url string)
	SetUser(user string)
	SetPassword(password string)
	SetApiKey(apiKey string)
	SetAccessToken(accessToken string)
	AppendPreRequestFunction(ServiceDetailsPreRequestFunc)
	SetClientCertPath(certificatePath string)
	SetClientCertKeyPath(certificatePath string)
	SetSshUrl(url string)
	SetSshKeyPath(sshKeyPath string)
	SetSshPassphrase(sshPassphrase string)
	SetSshAuthHeaders(sshAuthHeaders map[string]string)
	SetClient(client *jfroghttpclient.JfrogHttpClient)
	SetHttpTimeout(httpTimeout time.Duration)

	IsSshAuthHeaderSet() bool
	IsSshAuthentication() bool
	AuthenticateSsh(sshKey, sshPassphrase string) error
	InitSsh() error
	RunPreRequestFunctions(httpClientDetails *httputils.HttpClientDetails) error

	CreateHttpClientDetails() httputils.HttpClientDetails
}

type ServiceDetailsPreRequestFunc added in v0.21.0

type ServiceDetailsPreRequestFunc func(*CommonConfigFields, *httputils.HttpClientDetails) error

Implement this function and append it to create an interceptor that will run pre request in the http client

type SshAuthResult

type SshAuthResult struct {
	Href    string
	Headers map[string]string
}

type TokenPayload

type TokenPayload struct {
	Subject        string `json:"sub,omitempty"`
	Scope          string `json:"scp,omitempty"`
	Issuer         string `json:"iss,omitempty"`
	ExpirationTime int    `json:"exp,omitempty"`
	IssuedAt       int    `json:"iat,omitempty"`
	JwtId          string `json:"jti,omitempty"`
	// Audience was changed to slice. Handle this field manually so the unmarshalling will not fail.
	Audience      string
	AudienceArray []string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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