credentials

package
v0.0.0-...-e2755d2 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2022 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Prefix for all credential keys in the registry
	Prefix = "credentials/"

	// PartSeparator used in constructing the username parts
	PartSeparator = "__"

	// AsteriskString used to return a masked password
	AsteriskString = "********"
)

Variables

View Source
var (
	// CtxKey identified credentials will be populated in ctx with this key
	CtxKey = contextKey("CredentialsCtxKey")

	// ErrPasswordNotInExpectedFormat ...
	ErrPasswordNotInExpectedFormat = errors.New("Password not in expected format")
)
View Source
var (

	// UnauthenticatedError error returned when credential validation fails
	UnauthenticatedError = status.Error(codes.Unauthenticated, "Unauthenticated")
)

Functions

func GetProjectIDFromUsername

func GetProjectIDFromUsername(username string) string

GetProjectIDFromUsername returns the projectID for a given username extract only if the username was generated by metro, else return an empty string

func IsValidUsername

func IsValidUsername(username string) bool

IsValidUsername checks if the username is of the expected format

Types

type Core

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

Core implements all business logic for a credential

func (*Core) Create

func (c *Core) Create(ctx context.Context, m *Model) error

Create creates a credential for a given project

func (*Core) Delete

func (c *Core) Delete(ctx context.Context, m *Model) error

Delete deletes the given credential

func (*Core) Exists

func (c *Core) Exists(ctx context.Context, key string) (bool, error)

Exists checks if credential exists

func (*Core) Get

func (c *Core) Get(ctx context.Context, projectID, username string) (*Model, error)

Get checks if credential exists

func (*Core) List

func (c *Core) List(ctx context.Context, projectID string) ([]*Model, error)

List returns a slice of credentials for the given projectID

type ICore

type ICore interface {
	Create(ctx context.Context, credential *Model) error
	Exists(ctx context.Context, key string) (bool, error)
	Delete(ctx context.Context, m *Model) error
	Get(ctx context.Context, projectID, username string) (*Model, error)
	List(ctx context.Context, projectID string) ([]*Model, error)
}

ICore is an interface over credential core

func NewCore

func NewCore(repo IRepo, projectCore project.ICore) ICore

NewCore returns an instance of Core

type ICredentials

type ICredentials interface {
	GetUsername() string
	GetPassword() string
	GetProjectID() string
}

ICredentials defines getters on a credential

type IRepo

type IRepo interface {
	common.IRepo
	List(ctx context.Context, prefix string) ([]common.IModel, error)
}

IRepo interface over database repository

func NewRepo

func NewRepo(registry registry.IRegistry) IRepo

NewRepo returns IRepo

type Model

type Model struct {
	common.BaseModel
	Username string `json:"username"`
	// warning: Password must be of length >= 4
	Password  string `json:"password"`
	ProjectID string `json:"project_id"`
}

Model for a credential

func GetValidatedModelForCreate

func GetValidatedModelForCreate(ctx context.Context, req *metrov1.ProjectCredentials) (*Model, error)

GetValidatedModelForCreate validates an incoming proto request and returns the model for create requests

func NewCredential

func NewCredential(username, password string) *Model

NewCredential returns a new credential model

func (*Model) GetHiddenPassword

func (m *Model) GetHiddenPassword() (string, error)

GetHiddenPassword returns the Password after masking all but last 4 characters with * warning: make sure length of password is >= 4

func (*Model) GetPassword

func (m *Model) GetPassword() string

GetPassword returns the decrypted credential Password

func (*Model) GetProjectID

func (m *Model) GetProjectID() string

GetProjectID returns the credential projectID

func (*Model) GetUsername

func (m *Model) GetUsername() string

GetUsername returns the credential Username

func (*Model) Key

func (m *Model) Key() string

Key returns the key for storing credentials in the registry

func (*Model) Prefix

func (m *Model) Prefix() string

Prefix returns the Key prefix

type Repo

type Repo struct {
	common.BaseRepo
}

Repo implements various repository methods

func (*Repo) List

func (r *Repo) List(ctx context.Context, prefix string) ([]common.IModel, error)

List returns a slice of credentials matching prefix

Jump to

Keyboard shortcuts

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