cloudy

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: MIT Imports: 21 Imported by: 13

README

Cloudy

Planned to be an open source library that is a runtime adapter for AWS and Azure cloud capablilies. This library tries to provide simple capalbities instead of trying for a full-coverage. As you ned to use more complex capalbities they you should be able to tie into the underlying APIs from each of the Cloud Vendors.

Structure / Technical Approach

We use interfaces and common models through out this library

Authentication

Most clouds have similiar authentication strategies. For Azure there is a TenantID, ClientID and Client Secret, for AWS it is a AccessKey and secret

client, err := cloudy.NewClient(ctx, tenantId, clientId, clientSecret, nil)

Users

    users := client.Users()
    user, err := users.NewUser(ctx, userModel)

Groups

    groups := client.Groups()
    user, err := users.GetGroupsForUser(ctx, userIdorName)

Storage

    storage := client.Storage()
    storage.NewAccount()
    storage.NewBucket()

Configuration

  • Library wide defaults -- Region. API paths, etc

Models

  • Models are documented in OpenAPI V2 spec and compiled with Go-Swagger. These definitions can then be incorporated in other swagger files.
  • How to handle "more fields"? Either: Map or AllOf...
  • With additional fields... How to provide the field mapping? -- Maybe... --- Azure.User.Fields['job-title']="JobTitle" and use reflection?
    --- just an adapter.. azure.ToAzModel(user) AzureUzer.. I like #2 --- Only interface (all getters / setters).. ick --- Additional object added to base struct

Documentation

Index

Constants

View Source
const UserAnonymous = "ANONYMOUS"

Variables

View Source
var DriverNotFoundError = errors.New("Drive Not Found")
View Source
var GroupProviders = NewProviderRegistry[Users]()
View Source
var IDKey userkey = userkey("id")
View Source
var Log logkey
View Source
var UserKey userkey = userkey("userkey")
View Source
var UserProviders = NewProviderRegistry[Users]()

Functions

func BoolP

func BoolP(v bool) *bool

func CheckAddress

func CheckAddress(address string, timeout time.Duration) bool

func DeferableClose

func DeferableClose(ctx context.Context, closeme io.Closer)

func Error

func Error(ctx context.Context, msg string, args ...interface{}) error

func FromGabs

func FromGabs(c *gabs.Container, v interface{}) error

func GenerateId

func GenerateId(prefix string, num int) string

Generate an ID. The ID will follow the pattern {prefix}-{id} where the id is a randomly generated string of alphanumeric characters

func GeneratePassword

func GeneratePassword(passwordLength, minSpecialChar, minNum, minUpperCase int) string

func GetFieldString

func GetFieldString(v interface{}, field string) string

func GetID

func GetID(ctx context.Context) string

func GetLog

func GetLog(ctx context.Context) string

func HashId

func HashId(prefix string, parts ...string) string

func Info

func Info(ctx context.Context, msg string, args ...interface{})

func IsAdmin

func IsAdmin(user *UserJWT) bool

func IsMap

func IsMap(suspect interface{}) bool

func IsPointer

func IsPointer(item interface{}) bool

func IsZeroDate

func IsZeroDate(dt strfmt.DateTime) bool

func MapKey

func MapKey[T any](data map[string]T, key string, caseInsensitive bool) (T, bool)

func MapKeyStr

func MapKeyStr(data map[string]interface{}, key string, caseInsensitive bool) (string, bool)

func NewByteReadCloser

func NewByteReadCloser(data []byte) io.ReadCloser

func NewInstance

func NewInstance(v interface{}) interface{}

func NewInstanceT

func NewInstanceT[T any](v interface{}) (T, error)

func NewT

func NewT[T any]() (T, error)

func SetFieldString

func SetFieldString(v interface{}, field string, value string)

func StartContext

func StartContext() context.Context

func StringP

func StringP(s string) *string

func ToGabs

func ToGabs(item interface{}) (*gabs.Container, error)

func UnmarshallT

func UnmarshallT[T any](data []byte) (*T, error)

func WaitForAddress

func WaitForAddress(address string, timeout time.Duration) bool

func Warn

func Warn(ctx context.Context, msg string, args ...interface{})

func WithID

func WithID(ctx context.Context, ID string) context.Context

func WithLogging

func WithLogging(ctx context.Context) context.Context

func WithUser

func WithUser(ctx context.Context, user *UserJWT) context.Context

Types

type ByteCounter

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

func NewByteCounter

func NewByteCounter(stream io.ReadCloser) *ByteCounter

func (*ByteCounter) Close

func (bc *ByteCounter) Close() error

func (*ByteCounter) Read

func (bc *ByteCounter) Read(buf []byte) (n int, err error)

func (*ByteCounter) Total

func (bc *ByteCounter) Total() int64

type Groups

type Groups interface {
	ListGroups(ctx context.Context, uid string) ([]*models.Group, error)

	GetUserGroups(ctx context.Context, page interface{}, filter interface{}) ([]*models.Group, interface{}, error)

	NewGroup(ctx context.Context, grp *models.Group) (*models.Group, error)

	UpdateGroup(ctx context.Context, grp *models.Group) (bool, error)

	GetGroupMembers(ctx context.Context, grpId string) ([]string, error)
}

type Logs

type Logs struct {
	Info   *log.Logger
	Warn   *log.Logger
	Error  *log.Logger
	Buffer *bytes.Buffer
}

type ProviderFactory

type ProviderFactory[T any] interface {
	Create(cfg interface{}) (T, error)
}

type ProvidersRegistry

type ProvidersRegistry[T any] struct {
	Providers map[string]func(cfg interface{}) (T, error)
}

func NewProviderRegistry

func NewProviderRegistry[T any]() *ProvidersRegistry[T]

func (*ProvidersRegistry[T]) New

func (pr *ProvidersRegistry[T]) New(name string, cfg interface{}) (T, error)

func (*ProvidersRegistry[T]) Register

func (pr *ProvidersRegistry[T]) Register(name string, fn func(cfg interface{}) (T, error))

type SeekingBuffer

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

func NewSeekingBuffer

func NewSeekingBuffer(b []byte) *SeekingBuffer

func (*SeekingBuffer) Read

func (fb *SeekingBuffer) Read(p []byte) (n int, err error)

func (*SeekingBuffer) Seek

func (fb *SeekingBuffer) Seek(offset int64, whence int) (ret int64, err error)

type Storage

type Storage interface {
}

type UserJWT

type UserJWT struct {
	EXP               int64                  `json:"exp"`
	IAT               int64                  `json:"iat"`
	AuthTime          int64                  `json:"auth_time"`
	JTI               string                 `json:"jti"`
	ISS               string                 `json:"iss"`
	AUD               string                 `json:"aud"`
	TYP               string                 `json:"typ"`
	AZP               string                 `json:"azp"`
	Nonce             string                 `json:"nonce"`
	SessionState      string                 `json:"session_state"`
	ACR               string                 `json:"acr"`
	AllowedOrigins    []string               `json:"allowed-origins"`
	RealmAccess       *UserJWTRealmAccess    `json:"realm_access"`
	ResourceAccess    *UserJWTResourceAccess `json:"resource_access"`
	Scope             string                 `json:"scope"`
	EmailVerified     bool                   `json:"email_verified"`
	Name              string                 `json:"name"`
	PreferredUserName string                 `json:"preferred_username"`
	GivenName         string                 `json:"given_name"`
	FamilyName        string                 `json:"family_name"`
	Email             string                 `json:"email"`
	UPN               string                 `json:"upn"`
}

func GetUser

func GetUser(ctx context.Context) *UserJWT

func GetUserFromRequest

func GetUserFromRequest(ctx context.Context, request *http.Request) (*UserJWT, error)

func GetUserInfoFromToken

func GetUserInfoFromToken(token string) *UserJWT

GetUserInfoFromToken Gets a user information from the JWT (Authorization Header)

func ParseToken

func ParseToken(tokenstr string) (*UserJWT, error)

ParseToken Parses the id token from cognito

func (*UserJWT) IsAuthenticated

func (jwt *UserJWT) IsAuthenticated() bool

func (UserJWT) Valid

func (jwt UserJWT) Valid() error

Valid determines if the claims are valid

type UserJWTRealmAccess

type UserJWTRealmAccess struct {
	Roles []string `json:"roles"`
}

type UserJWTResourceAccess

type UserJWTResourceAccess struct {
	Account *UserJWTResourceAccessAccount `json:"account"`
}

type UserJWTResourceAccessAccount

type UserJWTResourceAccessAccount struct {
	Roles []string `json:"roles"`
}

type Users

type Users interface {
	ListUsers(ctx context.Context, page interface{}, filter interface{}) ([]*models.User, interface{}, error)

	// Retrieves a specific user.
	GetUser(ctx context.Context, uid string) (*models.User, error)

	// NewUser creates a new user with the given information and returns the new user with any additional
	// fields populated
	NewUser(ctx context.Context, newUser *models.User) (*models.User, error)

	UpdateUser(ctx context.Context, usr *models.User) (bool, error)

	Enable(ctx context.Context, uid string) (bool, error)

	Disable(ctx context.Context, uid string) (bool, error)

	DeleteUser(ctx context.Context, uid string) (bool, error)
}

User interface manager

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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