Documentation
¶
Index ¶
- Constants
- Variables
- func GetProjectIDFromUsername(username string) string
- func IsValidUsername(username string) bool
- type Core
- func (c *Core) Create(ctx context.Context, m *Model) error
- func (c *Core) Delete(ctx context.Context, m *Model) error
- func (c *Core) Exists(ctx context.Context, key string) (bool, error)
- func (c *Core) Get(ctx context.Context, projectID, username string) (*Model, error)
- func (c *Core) List(ctx context.Context, projectID string) ([]*Model, error)
- type ICore
- type ICredentials
- type IRepo
- type Model
- type Repo
Constants ¶
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 ¶
var ( // CtxKey identified credentials will be populated in ctx with this key CtxKey = contextKey("CredentialsCtxKey") // ErrPasswordNotInExpectedFormat ... ErrPasswordNotInExpectedFormat = errors.New("Password not in expected format") )
var ( // UnauthenticatedError error returned when credential validation fails UnauthenticatedError = status.Error(codes.Unauthenticated, "Unauthenticated") )
Functions ¶
func GetProjectIDFromUsername ¶
GetProjectIDFromUsername returns the projectID for a given username extract only if the username was generated by metro, else return an empty string
func IsValidUsername ¶
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
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
type ICredentials ¶
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
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 ¶
NewCredential returns a new credential model
func (*Model) GetHiddenPassword ¶
GetHiddenPassword returns the Password after masking all but last 4 characters with * warning: make sure length of password is >= 4
func (*Model) GetPassword ¶
GetPassword returns the decrypted credential Password
func (*Model) GetProjectID ¶
GetProjectID returns the credential projectID
func (*Model) GetUsername ¶
GetUsername returns the credential Username