auth

package
v2.0.400-0...-14731b4 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AddonAuthConfigFile config file for addon auth credentials
	AddonAuthConfigFile = "addonAuth.yaml"
	// JenkinsAuthConfigFile config file for Jenkins auth credentials
	JenkinsAuthConfigFile = "jenkinsAuth.yaml"
	// IssuesAuthConfigFile config file for Issues auth credentials
	IssuesAuthConfigFile = "issuesAuth.yaml"
	// CreateAuthUserFromEnvironment config file for chat auth credentials
	ChatAuthConfigFile = "chatAuth.yaml"
	// GitAuthConfigFile config file for git auth credentials
	GitAuthConfigFile = "gitAuth.yaml"
	// ChartmuseumAuthConfigFile config file for chartmusuem auth credentials
	ChartmuseumAuthConfigFile = "chartmuseumAuth.yaml"
)
View Source
const (
	DefaultUsername = "dummy"
)

Variables

This section is empty.

Functions

func ApiTokenEnv

func ApiTokenEnv(prefix string) string

ApiTokenEnv builds the api token environment variable name

func BearerTokenEnv

func BearerTokenEnv(prefix string) string

BearerTokenEnv builds the bearer token environment variable name

func IsConfigMapVaultAuth

func IsConfigMapVaultAuth(configMapClient v1.ConfigMapInterface) bool

IsConfigMapVaultAuth checks if is able to find any auth config in a config map

func UsernameEnv

func UsernameEnv(prefix string) string

UsernameEnv builds the username environment variable name

Types

type AuthConfig

type AuthConfig struct {
	Servers []*AuthServer `json:"servers"`

	DefaultUsername  string `json:"defaultusername"`
	CurrentServer    string `json:"currentserver"`
	PipeLineUsername string `json:"pipelineusername"`
	PipeLineServer   string `json:"pipelineserver"`
}

func (*AuthConfig) AddServer

func (c *AuthConfig) AddServer(server *AuthServer)

func (*AuthConfig) CurrentAuthServer

func (c *AuthConfig) CurrentAuthServer() *AuthServer

CurrentAuthServer returns the current AuthServer configured in the configuration

func (*AuthConfig) CurrentUser

func (c *AuthConfig) CurrentUser(server *AuthServer, inCluster bool) *UserAuth

func (*AuthConfig) DeleteServer

func (c *AuthConfig) DeleteServer(url string)

DeleteServer deletes the server for the given URL and updates the current server if is the same with the deleted server

func (*AuthConfig) EditUserAuth

func (c *AuthConfig) EditUserAuth(serverLabel string, auth *UserAuth, defaultUserName string, editUser, batchMode bool, fn PrintUserFn, handles util.IOFileHandles) error

EditUserAuth Lets the user input/edit the user auth

func (*AuthConfig) FindUserAuth

func (c *AuthConfig) FindUserAuth(serverURL string, username string) *UserAuth

FindUserAuth finds the auth for the given user name if no username is specified and there is only one auth then return that else nil

func (*AuthConfig) FindUserAuths

func (c *AuthConfig) FindUserAuths(serverURL string) []*UserAuth

func (*AuthConfig) GetOrCreateServer

func (c *AuthConfig) GetOrCreateServer(url string) *AuthServer

func (*AuthConfig) GetOrCreateServerName

func (c *AuthConfig) GetOrCreateServerName(url string, name string, kind string) *AuthServer

func (*AuthConfig) GetOrCreateUserAuth

func (c *AuthConfig) GetOrCreateUserAuth(url string, username string) *UserAuth

func (*AuthConfig) GetPipelineAuth

func (c *AuthConfig) GetPipelineAuth() (*AuthServer, *UserAuth)

GetPipelineAuth returns the current pipline server and user authentication

func (*AuthConfig) GetServer

func (c *AuthConfig) GetServer(url string) *AuthServer

GetServerByName returns the server for the given URL or null if its not found

func (*AuthConfig) GetServerByKind

func (c *AuthConfig) GetServerByKind(kind string) *AuthServer

GetServerByKind returns the server for the given kind or null if its not found

func (*AuthConfig) GetServerByName

func (c *AuthConfig) GetServerByName(name string) *AuthServer

GetServerByName returns the server for the given name or null if its not found

func (*AuthConfig) GetServerNames

func (c *AuthConfig) GetServerNames() []string

GetServerNames returns the name of the server currently in the configuration

func (*AuthConfig) GetServerURLs

func (c *AuthConfig) GetServerURLs() []string

GetServerURLs returns the server URLs currently in the configuration

func (*AuthConfig) IndexOfServerName

func (c *AuthConfig) IndexOfServerName(name string) int

func (*AuthConfig) Merge

func (c *AuthConfig) Merge(o *AuthConfig)

Merge merges another auth config such as if loading git/credentials

func (*AuthConfig) PickOrCreateServer

func (c *AuthConfig) PickOrCreateServer(fallbackServerURL string, serverURL string, message string, batchMode bool, handles util.IOFileHandles) (*AuthServer, error)

PickOrCreateServer picks the server to use defaulting to the current server

func (*AuthConfig) PickServer

func (c *AuthConfig) PickServer(message string, batchMode bool, handles util.IOFileHandles) (*AuthServer, error)

func (*AuthConfig) PickServerUserAuth

func (c *AuthConfig) PickServerUserAuth(server *AuthServer, message string, batchMode bool, org string, handles util.IOFileHandles) (*UserAuth, error)

PickServerAuth Pick the servers auth

func (*AuthConfig) SetUserAuth

func (c *AuthConfig) SetUserAuth(url string, auth *UserAuth)

func (*AuthConfig) UpdatePipelineServer

func (c *AuthConfig) UpdatePipelineServer(server *AuthServer, user *UserAuth)

UpdatePipelineServer updates the pipeline server in the configuration

type AuthConfigService

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

AuthConfigService implements the generic features of the ConfigService because we don't have superclasses

func NewAuthConfigService

func NewAuthConfigService(handler ConfigHandler) *AuthConfigService

NewAuthConfigService generates a AuthConfigService with a custom saver. This should not be used directly

func (*AuthConfigService) Config

func (s *AuthConfigService) Config() *AuthConfig

Config gets the AuthConfig from the service

func (*AuthConfigService) DeleteServer

func (s *AuthConfigService) DeleteServer(url string) error

DeleteServer removes the given server from the configuration

func (*AuthConfigService) LoadConfig

func (s *AuthConfigService) LoadConfig() (*AuthConfig, error)

LoadConfig loads the configuration from the users JX config directory

func (*AuthConfigService) SaveConfig

func (s *AuthConfigService) SaveConfig() error

SaveConfig saves the configuration to disk

func (*AuthConfigService) SaveUserAuth

func (s *AuthConfigService) SaveUserAuth(url string, userAuth *UserAuth) error

SaveUserAuth saves the given user auth for the server url

func (*AuthConfigService) SetConfig

func (s *AuthConfigService) SetConfig(c *AuthConfig)

SetConfig sets the AuthConfig object

type AuthServer

type AuthServer struct {
	URL   string      `json:"url"`
	Users []*UserAuth `json:"users"`
	Name  string      `json:"name"`
	Kind  string      `json:"kind"`

	CurrentUser string `json:"currentuser"`
}

func (*AuthServer) CurrentAuth

func (s *AuthServer) CurrentAuth() *UserAuth

CurrentAuth returns the current user auth, otherwise the first one

func (*AuthServer) DeleteUser

func (s *AuthServer) DeleteUser(username string) error

func (*AuthServer) Description

func (s *AuthServer) Description() string

func (*AuthServer) GetUserAuth

func (s *AuthServer) GetUserAuth(username string) *UserAuth

func (*AuthServer) GetUsernames

func (s *AuthServer) GetUsernames() []string

func (*AuthServer) HasUserAuths

func (s *AuthServer) HasUserAuths() bool

HasUserAuths checks if a server has any user auth configured

func (*AuthServer) Label

func (s *AuthServer) Label() string

type ConfigHandler

type ConfigHandler interface {
	// LoadConfig loads the configuration from the users JX config directory
	LoadConfig() (*AuthConfig, error)
	//HasConfigFile() (bool, error)
	// SaveConfig saves the configuration
	SaveConfig(config *AuthConfig) error
}

ConfigHandler is an interface that handles an AuthConfig

type ConfigMapVaultConfigHandler

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

ConfigMapVaultConfigHandler loads/save the config in a config map and the secrets in vault

func NewConfigMapVaultConfigHandler

func NewConfigMapVaultConfigHandler(secretName string, configMapClient v1.ConfigMapInterface,
	vaultClient secreturl.Client) ConfigMapVaultConfigHandler

NewConfigMapVaultConfigHandler creates a new configmap/vault config handler

func (*ConfigMapVaultConfigHandler) LoadConfig

func (c *ConfigMapVaultConfigHandler) LoadConfig() (*AuthConfig, error)

LoadConfig loads the auth config from a ConfigMap which stores in its data with a key equal with the secretName, also it resolves any secrets URIs by fetching their secret data from vault.

func (*ConfigMapVaultConfigHandler) SaveConfig

func (c *ConfigMapVaultConfigHandler) SaveConfig(config *AuthConfig) error

SaveConfig should save config but we keep this read-only to avoid overwriting the existing values configure during installation.

type ConfigService

type ConfigService interface {
	Config() *AuthConfig
	SetConfig(c *AuthConfig)
	// LoadConfig loads the configuration from the users JX config directory
	LoadConfig() (*AuthConfig, error)
	// SaveConfig saves the configuration
	SaveConfig() error
	// SaveUserAuth saves the given user auth for the server url
	SaveUserAuth(url string, userAuth *UserAuth) error
	// DeleteServer removes the given server from the configuration
	DeleteServer(url string) error
}

ConfigService is a service for handing the config of auth tokens

func NewConfigmapVaultAuthConfigService

func NewConfigmapVaultAuthConfigService(secretName string, configMapClient v1.ConfigMapInterface,
	secretURLClient secreturl.Client) ConfigService

NewConfigmapVaultAuthConfigService creates a new config service that load the config from a configmap and resolve the secrets URIs from vault

func NewFileAuthConfigService

func NewFileAuthConfigService(filename string, serverKind string) (ConfigService, error)

NewFileAuthConfigService creates a new file config service

func NewKubeAuthConfigService

func NewKubeAuthConfigService(client kubernetes.Interface, namespace string, kind string, serviceKind string) ConfigService

NewKubeAuthConfigService creates a config services that loads/stores the auth config from a Kubernetes secret

func NewMemoryAuthConfigService

func NewMemoryAuthConfigService() ConfigService

NewMemoryAuthConfigService creates a new memory based auth service

func NewVaultAuthConfigService

func NewVaultAuthConfigService(secretName string, vaultClient vault.Client) ConfigService

NewVaultAuthConfigService creates a new config service that loads/saves the auth config form/into vault

type FileAuthConfigHandler

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

FileAuthConfigHandler is a config handlerthat loads/saves the auth config from/to the local filesystem

func (*FileAuthConfigHandler) LoadConfig

func (s *FileAuthConfigHandler) LoadConfig() (*AuthConfig, error)

LoadConfig loads the configuration from the users JX config directory

func (*FileAuthConfigHandler) SaveConfig

func (s *FileAuthConfigHandler) SaveConfig(config *AuthConfig) error

SaveConfig saves the configuration to disk

type KubeAuthConfigHandler

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

KubeAuthConfigHandler loads/save the auth config from/into a kubernetes secret

func NewKubeAuthConfigHandler

func NewKubeAuthConfigHandler(client kubernetes.Interface, namespace string, kind string, serviceKind string) KubeAuthConfigHandler

NewKubeAuthConfigHandler creates a handler which loads/stores the auth config from/into Kubernetes secrets

func (*KubeAuthConfigHandler) LoadConfig

func (k *KubeAuthConfigHandler) LoadConfig() (*AuthConfig, error)

LoadConfig loads the config from kuberntes secrets

func (*KubeAuthConfigHandler) SaveConfig

func (k *KubeAuthConfigHandler) SaveConfig(config *AuthConfig) error

SaveConfig saves the config into kuberntes secret

type MemoryAuthConfigHandler

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

MemoryAuthConfigHandler loads/saves the auth config from/into memory

func (*MemoryAuthConfigHandler) LoadConfig

func (m *MemoryAuthConfigHandler) LoadConfig() (*AuthConfig, error)

LoadConfig returns the current config from memory

func (*MemoryAuthConfigHandler) SaveConfig

func (m *MemoryAuthConfigHandler) SaveConfig(config *AuthConfig) error

SaveConfig updates the config in memory

type PrintUserFn

type PrintUserFn func(username string) error

PrintUserFn prints the use name

type ServerKind

type ServerKind string

ServerKind indicates the server kind used to load the auth config from file

const GitServerKind ServerKind = "git"

GitServerKind indicate the server kind for git

type UserAuth

type UserAuth struct {
	Username    string `json:"username"`
	ApiToken    string `json:"apitoken"`
	BearerToken string `json:"bearertoken"`
	Password    string `json:"password,omitempty"`

	// GithubAppOwner if using GitHub Apps this represents the owner organisation/user which owns this token.
	// we need to maintain a different token per owner
	GithubAppOwner string `json:"appOwner,omitempty"`
}

func CreateAuthUserFromEnvironment

func CreateAuthUserFromEnvironment(prefix string) UserAuth

CreateAuthUserFromEnvironment creates a user auth from environment variables

func (*UserAuth) IsInvalid

func (a *UserAuth) IsInvalid() bool

IsInvalid returns true if the user auth has a valid token

func (*UserAuth) IsValid

func (a *UserAuth) IsValid() bool

Valid returns true when the user authentication is valid, otherwise false

type VaultAuthConfigHandler

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

VaultAuthConfigHandler is a config handler that loads/saves the auth configs from/to Vault

func (*VaultAuthConfigHandler) LoadConfig

func (v *VaultAuthConfigHandler) LoadConfig() (*AuthConfig, error)

LoadConfig loads the config from the vault

func (*VaultAuthConfigHandler) SaveConfig

func (v *VaultAuthConfigHandler) SaveConfig(config *AuthConfig) error

SaveConfig saves the config to the vault

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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