backd

package
v0.0.0-...-20fe154 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderSessionID     = "X-Session-ID"
	HeaderApplicationID = "X-Application-ID"
)

Headers for the endpoints

View Source
const (
	StateAnonymous int = iota
	StateExpired
	StateLoggedIn
)

Session state

View Source
const (
	RBACActionGet    = "get"
	RBACActionSet    = "set"
	RBACActionAdd    = "add"
	RBACActionRemove = "remove"
)

RBAC Actions

Variables

HTTP Errors returns if found

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Reason  string `json:"reason,omitempty"`
	// contains filtered or unexported fields
}

APIError is the struct that is returned when an error is returned from the APIs

func (APIError) Error

func (a APIError) Error() string

type Admin

type Admin struct {
	Users  *AdminUsers
	Groups *AdminGroups
	// contains filtered or unexported fields
}

Admin is the struct that contains all the actions doable with the Objects API

type AdminAppRBAC

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

AdminAppRBAC holds groups operations

func (*AdminAppRBAC) Add

func (a *AdminAppRBAC) Add(rbac RBAC) error

Add adds role/s to the role permission set

func (*AdminAppRBAC) Get

func (a *AdminAppRBAC) Get(rbac *RBAC) error

Get get current role permission set

func (*AdminAppRBAC) Remove

func (a *AdminAppRBAC) Remove(rbac RBAC) error

Remove removes role/s to the role permission set

func (*AdminAppRBAC) Set

func (a *AdminAppRBAC) Set(rbac RBAC) error

Set sets a new role permission set

type AdminApplication

type AdminApplication struct {
	RBAC *AdminAppRBAC
	// contains filtered or unexported fields
}

AdminApplication is the struct that contains all the actions doable with the Objects API

type AdminGroups

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

AdminGroups holds groups operations

func (*AdminGroups) AddMember

func (a *AdminGroups) AddMember(id, userID string) error

AddMember adds a new member to the group

func (*AdminGroups) Delete

func (a *AdminGroups) Delete(id string) error

Delete removes a group by ID

func (*AdminGroups) GetByID

func (a *AdminGroups) GetByID(id string, object interface{}) error

GetByID returns an group by its ID

func (*AdminGroups) GetMany

func (a *AdminGroups) GetMany(queryOptions QueryOptions, object interface{}) error

GetMany returns all groups that matches the conditions especified

func (*AdminGroups) Insert

func (a *AdminGroups) Insert(object interface{}) (map[string]interface{}, error)

Insert inserts a new group on the desired collection if the user have the required permissions

func (*AdminGroups) RemoveMember

func (a *AdminGroups) RemoveMember(id, userID string) error

RemoveMember removes a member from a group by ID

func (*AdminGroups) Update

func (a *AdminGroups) Update(id string, from, to interface{}) error

Update updates the required group if the user has permissions for

from is the original group updated by the user
to   is the group retreived by the API

type AdminRBAC

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

AdminRBAC holds groups operations

func (*AdminRBAC) Add

func (a *AdminRBAC) Add(rbac RBAC) error

Add adds role/s to the role permission set

func (*AdminRBAC) Get

func (a *AdminRBAC) Get(rbac RBAC) error

Get get cirremt role permission set

func (*AdminRBAC) Remove

func (a *AdminRBAC) Remove(rbac RBAC) error

Remove removes role/s to the role permission set

func (*AdminRBAC) Set

func (a *AdminRBAC) Set(rbac RBAC) error

Set sets a new role permission set

type AdminUsers

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

AdminUsers holds users operations

func (*AdminUsers) Delete

func (a *AdminUsers) Delete(id string) error

Delete removes a user by ID

func (*AdminUsers) GetByID

func (a *AdminUsers) GetByID(id string, object interface{}) error

GetByID returns an user by its ID

func (*AdminUsers) GetMany

func (a *AdminUsers) GetMany(queryOptions QueryOptions, object interface{}) error

GetMany returns all users that matches the conditions especified

func (*AdminUsers) Insert

func (a *AdminUsers) Insert(object interface{}) (map[string]interface{}, error)

Insert inserts a new user on the desired collection if the user have the required permissions

func (*AdminUsers) Update

func (a *AdminUsers) Update(id string, from, to interface{}) error

Update updates the required user if the user has permissions for

from is the original user updated by the user
to   is the object retreived by the API

type Apps

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

Apps is a simple struct that holds the operations doable for applications

func (*Apps) Delete

func (a *Apps) Delete(id string) error

Delete removes an application by ID

func (*Apps) GetByID

func (a *Apps) GetByID(id string, object interface{}) error

GetByID returns an application by its ID

func (*Apps) GetMany

func (a *Apps) GetMany(queryOptions QueryOptions, object interface{}) error

GetMany returns all applications that matches the conditions especified

func (*Apps) Insert

func (a *Apps) Insert(object interface{}) (map[string]interface{}, error)

Insert inserts a new application on the desired collection if the user have the required permissions

func (*Apps) Update

func (a *Apps) Update(id string, from, to interface{}) error

Update updates the required application if the user has permissions for

from is the original domain updated by the user
to   is the updated application retreived by the API

type Backd

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

Backd is the struct that holds the client for the service

func NewClient

func NewClient(authURL, objectsURL, adminURL, functionsURL string) *Backd

NewClient returns an usable client to connect to an instance of Backd

func (*Backd) App

func (b *Backd) App(appID string) *AdminApplication

App returns an instance of the Admin struct

func (*Backd) Apps

func (b *Backd) Apps() *Apps

Apps returns an instance of the Apps struct

func (*Backd) BootstrapCluster

func (b *Backd) BootstrapCluster(code, name, username, email, password string) error

BootstrapCluster creates the first user on the cluster with full Administration permissions on the the backd application

func (*Backd) ConnectionTimeouts

func (b *Backd) ConnectionTimeouts(dialer, tlsHandshake, timeout time.Duration)

ConnectionTimeouts allow to change the client timeouts for:

  • Dialer
  • TLS Handshake
  • HTTP timeout

func (*Backd) Domain

func (b *Backd) Domain(domainID string) *Admin

Domain returns an instance of the Admin struct

func (*Backd) Domains

func (b *Backd) Domains() *Domains

Domains returns an instance of the Domains struct

func (*Backd) Functions

func (b *Backd) Functions(applicationID string) *Funcs

Functions returns an instance of Funcs exposing the helper functions

for the function publishing workflow

func (*Backd) Login

func (b *Backd) Login(username, password, domain string) error

Login sends a log in request to the API

func (*Backd) Logout

func (b *Backd) Logout() error

Logout deletes the session on the API so the client will make request (if any) as anonymous

func (*Backd) Me

func (b *Backd) Me() (user User, err error)

Me returns an instance of the current user logged

func (*Backd) MeMapInterface

func (b *Backd) MeMapInterface() (user map[string]interface{}, err error)

MeMapInterface returns an instance of the current user logged as map[string]interface{}

func (*Backd) Objects

func (b *Backd) Objects(applicationID string) *Objects

Objects returns an instance of the Objects struct

func (*Backd) RBAC

func (b *Backd) RBAC(appID string) *AdminAppRBAC

RBAC returns an instance of the AdminAppRBAC struct

func (*Backd) Session

func (b *Backd) Session() (string, int, time.Time)

Session returns current session status and remaining time if session is established

func (*Backd) SetSession

func (b *Backd) SetSession(sessionID string, expiresAt int64)

SetSession sets a sessionID and expires information from elsewhere, used as commodity for the cli

No check will be done on the client library so errors (if any) will arise when requesting the API

func (*Backd) SetSessionID

func (b *Backd) SetSessionID(sessionID string)

SetSessionID sets a sessionID and expires information from elsewhere, used as commodity for the cli

No check will be done on the client library so errors (if any) will arise when requesting the API

type BootstrapRequest

type BootstrapRequest struct {
	Code     string `json:"code"`
	Name     string `json:"name"`
	Username string `json:"username"`
	Email    string `json:"email"`
	Password string `json:"password"`
}

BootstrapRequest is the request to initialize a `backd` cluster

type Domain

type Domain struct {
	ID          string                 `json:"_id"`
	Description string                 `json:"desc"`
	Type        DomainType             `json:"type"`
	Config      map[string]interface{} `json:"config,omitempty"`
	Metadata    `json:"meta"`
}

Domain struct

type DomainType

type DomainType string

DomainType defines the behavior to build a session on a backd defined domain

const (
	// DomainTypeBackd when set the domain will use natively only the backd users/groups
	DomainTypeBackd DomainType = "b"
	// DomainTypeActiveDirectory when set the domain will inherit the groups from the users
	//   on logon. So user membership will be updated from the ones received when the user
	//   creates a session.
	DomainTypeActiveDirectory DomainType = "ad"
)

type Domains

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

Domains is a simple struct that holds the operations doable for domains

func (*Domains) Delete

func (a *Domains) Delete(id string) error

Delete removes a domain by ID

func (*Domains) GetByID

func (a *Domains) GetByID(id string, object interface{}) error

GetByID returns an domain by its ID

func (*Domains) GetMany

func (a *Domains) GetMany(queryOptions QueryOptions, object interface{}) error

GetMany returns all domains that matches the conditions especified

func (*Domains) Insert

func (a *Domains) Insert(object interface{}) (map[string]interface{}, error)

Insert inserts a new domain on the desired collection if the user have the required permissions

func (*Domains) Update

func (a *Domains) Update(id string, from, to interface{}) error

Update updates the required domain if the user has permissions for

from is the original domain updated by the user
to   is the updated domain retreived by the API

type Funcs

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

Funcs is the struct that contains all helpers to work with the

functions on the admin endpoint

func (*Funcs) Delete

func (a *Funcs) Delete(id string) error

Delete removes a function by ID

func (*Funcs) GetByID

func (a *Funcs) GetByID(id string, object interface{}) error

GetByID returns an function by its ID

func (*Funcs) GetMany

func (a *Funcs) GetMany(queryOptions QueryOptions, object interface{}) error

GetMany returns all functions that matches the conditions especified

func (*Funcs) Insert

func (a *Funcs) Insert(object interface{}) (map[string]interface{}, error)

Insert inserts a new function if the user have the required permissions

func (*Funcs) Run

func (a *Funcs) Run(id string, input map[string]interface{}) (map[string]interface{}, error)

Run executes a function by its ID(name), input expected is a map[string]interface{}

outputs a map[string]interface{} from the function itself

func (*Funcs) Update

func (a *Funcs) Update(id string, from, to interface{}) error

Update updates the required function if the user has permissions for

from is the original domain updated by the user
to   is the updated domain retreived by the API

type Function

type Function struct {
	ID       string `json:"_id"`
	Name     string `json:"name"`
	API      bool   `json:"api"`
	RunAs    string `json:"run_as"`
	Code     string `json:"code"`
	Metadata `json:"meta"`
}

Function defines a function to be called from other places API, scheduler, etc

type Group

type Group struct {
	ID          string `json:"_id"`            // (required) ID generated by the API
	Name        string `json:"name,omitempty"` // (required) Name of the group
	Description string `json:"desc,omitempty"` // (optional) Description
	Metadata    `json:"meta"`
}

Group is the struct that api expects

type Login

type Login struct {
	Username string `json:"username"`
	Password string `json:"password"`
	Domain   string `json:"domain"`
}

Login is the struct that is expected by the API as request for an user authentication

type LoginResponse

type LoginResponse struct {
	ID        string `json:"id"`
	ExpiresAt int64  `json:"expires_at"`
}

LoginResponse is the response if success. Upon a successful login it returns a

Session ID and ExpiresAt expiration date (as seconds from epoch)

type Metadata

type Metadata struct {
	CreatedBy string `json:"cby" mapstructure:"cby"`
	UpdatedBy string `json:"uby" mapstructure:"uby"`
	CreatedAt int64  `json:"cat" mapstructure:"cat"`
	UpdatedAt int64  `json:"uat" mapstructure:"uat"`
}

Metadata is the struct that defines how metadata is stored on the API

type Objects

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

Objects is the struct that contains all the actions doable with the Objects API

func (*Objects) Delete

func (o *Objects) Delete(collection, id string) error

Delete removes a object by ID

func (*Objects) GetByID

func (o *Objects) GetByID(collection, id string, object interface{}) error

GetByID returns an object by its ID

func (*Objects) GetMany

func (o *Objects) GetMany(collection string, queryOptions QueryOptions, object interface{}) error

GetMany returns all objects that matches the conditions especified

func (*Objects) GetRelationsOf

func (o *Objects) GetRelationsOf(collection, id, relation, direction string, object interface{}) error

GetRelationsOf returns all objects that matches the conditions especified

func (*Objects) Insert

func (o *Objects) Insert(collection string, object interface{}) (map[string]interface{}, error)

Insert inserts a new object on the desired collection if the user have the required permissions

func (*Objects) RelationDelete

func (o *Objects) RelationDelete(id string) error

RelationDelete removes a object by ID

func (*Objects) RelationGetByID

func (o *Objects) RelationGetByID(id string, object interface{}) error

RelationGetByID returns an object by its ID

func (*Objects) RelationGetMany

func (o *Objects) RelationGetMany(collection, id, direction string, object interface{}) error

RelationGetMany returns all relation structs that matches the conditions especified, not the items itself

func (*Objects) RelationInsert

func (o *Objects) RelationInsert(object interface{}) (map[string]interface{}, error)

RelationInsert inserts a new relation between items if the user have the required permissions

func (*Objects) Update

func (o *Objects) Update(collection, id string, from, to interface{}) error

Update updates the required object if the user has permissions for

from is the original object updated by the user
to   is the object retreived by the API

type Permission

type Permission string

Permission is the required level of permission required to operate

const (
	PermissionRead   Permission = "read"
	PermissionCreate Permission = "create"
	PermissionUpdate Permission = "update"
	PermissionDelete Permission = "delete"
	PermissionAdmin  Permission = "admin"
)

Exported permissions

type QueryOptions

type QueryOptions struct {
	Q       map[string]interface{} `json:"q,omitempty" url:"-"` // for url it must be decode to string
	Sort    []string               `json:"sort,omitempty" url:"sort,omitempty"`
	Page    int                    `json:"page,omitempty" url:"page,omitempty"`
	PerPage int                    `json:"per_page,omitempty" url:"per_page,omitempty"`
}

QueryOptions is the builder of query parameters used for getMany queries

type RBAC

type RBAC struct {
	Action       string   `json:"action,omitempty"` // allowed actions: add / remove / set
	DomainID     string   `json:"domain_id"`        // domain
	IdentityID   string   `json:"identity_id"`      // user_id / group_id
	Collection   string   `json:"collection"`       // collection if application, if domain there is no concept of 'collection' you can manage or not if entity_id match
	CollectionID string   `json:"collection_id"`    // id if application, entity_id if domain
	Permissions  []string `json:"permissions"`      // array of permissions matching entity and item
}

RBAC is the struct used to manage roles and permissions by the API

type Relation

type Relation struct {
	ID            string `json:"_id"`
	Source        string `json:"src"`
	SourceID      string `json:"sid"`
	Destination   string `json:"dst"`
	DestinationID string `json:"did"`
	Relation      string `json:"rel"`
	Metadata      `json:"meta"`
}

Relation is the representation of linked data.

type RequestByID

type RequestByID struct {
	ID string `json:"_id"`
}

RequestByID is a request that only especifies an ID (for simple things like group membership)

type User

type User struct {
	ID                string                 `json:"_id" mapstructure:"_id"`                                 // (required) ID generated by the API
	Username          string                 `json:"username" mapstructure:"username"`                       // (required) Username is the entity that will be used for logon. If email will be used as username then both must match
	Name              string                 `json:"name" mapstructure:"name"`                               // (required) Name of the user (it can get filled with the data from the remote authorization authority)
	Email             string                 `json:"email" mapstructure:"email"`                             // (required) Email of the user (the one used to notify by mail)
	Description       string                 `json:"desc,omitempty" mapstructure:"desc,omitempty"`           // (optional) User description
	Password          string                 `json:"password,omitempty" mapstructure:"-"`                    // (optional) Password is only used to get the initial password on user creation
	GeneratedPassword string                 `json:"generated_password,omitempty" mapstructure:"-"`          // GeneratedPassword will be filled only if the user didn't set a password on user creation, so it generates one randomly
	Active            bool                   `json:"active,omitempty" mapstructure:"active,omitempty"`       // (required) Active defines when the user can interact with the APIs (some authorizations can leave it as active if the authentication system will allow or restrict the user)
	Validated         bool                   `json:"validated,omitempty" mapstructure:"validated,omitempty"` // (required) Validated shows if the user needs to make any action to active its email (and probably its account too)
	Data              map[string]interface{} `json:"data,omitempty" mapstructure:"data,omitempty"`           // (optional) Data is the arbitrary information that can be stored for the user
	Metadata          `json:"meta" mapstructure:"meta"`
}

User is the struct that API expects to get on user operations

Jump to

Keyboard shortcuts

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