oclib

package module
v0.0.0-...-a0f436b Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2025 License: AGPL-3.0 Imports: 27 Imported by: 0

README

oc-lib

oc-lib allows read/write/search operations into the main OpenCloud databases.

It also provides common initialization and configuration utilities for all OpenCloud components

Usage example in a beego API

const appname = "oc-mycomponent"

func main() {
    // Init the oc-lib
    oclib.Init(appname)

    // Load the right config file

    /*  The configuration loader will load the configuration from the following sources:
    *  - the environment variables with the prefix OCAPPNAME_ - ex: OCMYCOMPONENT_MONGOURL
    *  - the file /etc/oc/appname.json - ex: /etc/oc/mycomponent.json
    *  - the file ./appname.json - ex: ./mycomponent.json
    *  The configuration loader will merge the configuration from the different sources
    *  The configuration loader will give priority to the environment variables
    *  The configuration loader will give priority to the local file over the default file
    */
    o := oclib.GetConfLoader()

    // init the local config object
    models.GetConfig().Port = o.GetIntDefault("port", 8080)
    models.GetConfig().LokiUrl = o.GetStringDefault("lokiurl", "")
    models.GetConfig().LogLevel = o.GetStringDefault("loglevel", "info")    
    models.GetConfig().MongoUrl = o.GetStringDefault("mongourl", "mongodb://127.0.0.1:27017")
    models.GetConfig().MongoDatabase = o.GetStringDefault("mongodatabase", "myDb")
    models.GetConfig().NatsUrl = o.GetStringDefault("natsurl", "nats://localhost:4222")

    models.GetConfig().mycomponentparam1 = o.GetStringDefault("mycomponentparam1", "mycomponentdefault1")    
    models.GetConfig().mycomponentparam2 = o.GetStringDefault("mycomponentparam2", "mycomponentdefault2")

    // feed the library with the loaded config, 
    // this will also initialize a logger available via oclib.GetLogger()
	oclib.SetConfig(
        models.GetConfig().MongoUrl
        models.GetConfig().MongoDatabase 
        models.GetConfig().NatsUrl
        models.GetConfig().LokiUrl
        models.GetConfig().LogLevel
	)

    // Beego init
    beego.BConfig.AppName = appname
    beego.BConfig.Listen.HTTPPort = models.GetConfig().Port
    beego.BConfig.WebConfig.DirectoryIndex = true
    beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"

    beego.Run()
}

SPECIAL FLOWS IN OC-LIB RESUME :

WORKFLOW AS ITS OWN WORKSPACE

A workflow on post, put, delete, manage a workspace with resources. This workspace is deeply related to workflow by sharing its naming such as : "<workflow_name>_worspace"

WORKFLOW GENERATE ITS OWN EXECUTION

A workflow on post, put, delete, with a schedule && schedule_active to "true", must manage execution by adding, deleting execution depending on change (update -> involved delete into add)

If schedule_active is set to "false" execution will be deleted.

WORKFLOW GENERATE ITS OWN BOOKING ON PEERS

A workflow on post, put, delete, with a schedule && schedule_active to "true", must manage booking by adding, deleting execution with http requests on peers depending on change (update -> involved delete into add)

If schedule_active is set to "false" booking will be deleted.

SHARED WORKSPACE : WORSPACE & WORKFLOW

You can create a share workspace with workspace & workflow. When a share workspace is post, put, delete it update workspace or workflow field. Workspace can be shared on one share workspace Workflow can be shared in multiple workspace

SHARED WORKSPACE SHARE TO PEER

When writing a shared workspace, it set up to date on peers involved in shared workspace It create or delete shared workspace in remote peers by http requests on oc-shared (update -> involved delete into add)

It create or delete workspace involved in shared workspace by http requests on oc-workspace (update -> involved delete into add) It create or delete workflow involved in shared workspace by http requests on oc-workflow (update -> involved delete into add)

WORKFLOW WRITE BUT SHARED

On delete & update & post, workflow will send to peer in field by http request on oc-workflow

WORKSPACE WRITE BUT SHARED

On delete & update & post, workspace will send to peer in field by http request on oc-workspace

Documentation

Index

Constants

View Source
const (
	INVALID             LibDataEnum = iota
	DATA_RESOURCE                   = tools.DATA_RESOURCE
	PROCESSING_RESOURCE             = tools.PROCESSING_RESOURCE
	STORAGE_RESOURCE                = tools.STORAGE_RESOURCE
	COMPUTE_RESOURCE                = tools.COMPUTE_RESOURCE
	WORKFLOW_RESOURCE               = tools.WORKFLOW_RESOURCE
	WORKFLOW                        = tools.WORKFLOW
	WORKSPACE                       = tools.WORKSPACE
	WORKFLOW_EXECUTION              = tools.WORKFLOW_EXECUTION
	PEER                            = tools.PEER
	COLLABORATIVE_AREA              = tools.COLLABORATIVE_AREA
	RULE                            = tools.RULE
	BOOKING                         = tools.BOOKING
	ORDER                           = tools.ORDER
)

init accessible constant to retrieve data from the database

Variables

This section is empty.

Functions

func ExtractTokenInfo

func ExtractTokenInfo(request http.Request) (string, string, []string)

func GetConfLoader

func GetConfLoader() *onion.Onion

func GetConfig

func GetConfig() *config.Config
GetConfig will get the config

* @return *Config

func GetLogger

func GetLogger() zerolog.Logger
GetLogger returns the main logger

* @return zerolog.Logger

func Init

func Init(appName string)

func InitDaemon

func InitDaemon(appName string)

func IsQueryParamsEquals

func IsQueryParamsEquals(input *context.BeegoInput, name string, val interface{}) bool

func SetConfig

func SetConfig(mongoUrl string, database string, natsUrl string, lokiUrl string, logLevel string) *config.Config
SetConfig will set the config and create a logger according to app configuration and initialize mongo accessor

* @param url string * @param database string * @param natsUrl string * @param lokiUrl string * @param logLevel string * @return *Config

func ToScheduler

func ToScheduler(m interface{}) (n *workflow_execution.WorkflowSchedule)

Types

type Claims

type Claims struct {
	Session SessionClaims `json:"session"`
}

Claims struct

type Filters

type Filters = dbs.Filters

type IDTokenClaims

type IDTokenClaims struct {
	UserID string   `json:"user_id"`
	PeerID string   `json:"peer_id"`
	Groups []string `json:"groups"`
}

type LibData

type LibData struct {
	Data utils.DBObject `bson:"data" json:"data"`
	Code int            `bson:"code" json:"code"`
	Err  string         `bson:"error" json:"error"`
}

model to define the data structure

func (*LibData) ToCollaborativeArea

func (l *LibData) ToCollaborativeArea() *collaborative_area.CollaborativeArea

func (*LibData) ToComputeResource

func (l *LibData) ToComputeResource() *resources.ComputeResource

func (*LibData) ToDataResource

func (l *LibData) ToDataResource() *resources.DataResource

func (*LibData) ToOrder

func (l *LibData) ToOrder() *order.Order

func (*LibData) ToPeer

func (l *LibData) ToPeer() *peer.Peer

func (*LibData) ToProcessingResource

func (l *LibData) ToProcessingResource() *resources.ProcessingResource

func (*LibData) ToRule

func (l *LibData) ToRule() *rule.Rule

func (*LibData) ToStorageResource

func (l *LibData) ToStorageResource() *resources.StorageResource

func (*LibData) ToWorkflow

func (l *LibData) ToWorkflow() *w2.Workflow

func (*LibData) ToWorkflowExecution

func (l *LibData) ToWorkflowExecution() *workflow_execution.WorkflowExecutions

func (*LibData) ToWorkflowResource

func (l *LibData) ToWorkflowResource() *resources.WorkflowResource

func (*LibData) ToWorkspace

func (l *LibData) ToWorkspace() *workspace.Workspace

type LibDataEnum

type LibDataEnum int

func (LibDataEnum) API

func (d LibDataEnum) API() string

will turn into standards api hostnames

func (LibDataEnum) EnumIndex

func (d LibDataEnum) EnumIndex() int

will turn into enum index

func (LibDataEnum) String

func (d LibDataEnum) String() string

will turn into standards name

type LibDataShallow

type LibDataShallow struct {
	Data []utils.ShallowDBObject `bson:"data" json:"data"`
	Code int                     `bson:"code" json:"code"`
	Err  string                  `bson:"error" json:"error"`
}

model to define the shallow data structure

type Request

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

func NewRequest

func NewRequest(collection LibDataEnum, user string, peerID string, groups []string, caller *tools.HTTPCaller) *Request

func (*Request) CheckBooking

func (r *Request) CheckBooking(wfID string, start string, end string, durationInS float64, cron string) bool

func (*Request) CopyOne

func (r *Request) CopyOne(object map[string]interface{}) (data LibData)

* CopyOne will copy one data from the database * @param collection LibDataEnum * @param object map[string]interface{} * @param c ...*tools.HTTPCaller * @return data LibData

func (*Request) DeleteOne

func (r *Request) DeleteOne(id string) (data LibData)

* DeleteOne will delete one data from the database * @param collection LibDataEnum * @param id string * @param c ...*tools.HTTPCaller * @return data LibData

func (*Request) DraftOrder

func (r *Request) DraftOrder(scheduler *workflow_execution.WorkflowSchedule) (*order.Order, error)

func (*Request) LoadAll

func (r *Request) LoadAll(isDraft bool) (data LibDataShallow)

* LoadAll will load all the data from the database * @param collection LibDataEnum * @param c ...*tools.HTTPCaller * @return data LibDataShallow

func (*Request) LoadOne

func (r *Request) LoadOne(id string) (data LibData)

* LoadOne will load one data from the database * @param collection LibDataEnum * @param id string * @param c ...*tools.HTTPCaller * @return data LibData

func (*Request) PaymentTunnel

func (r *Request) PaymentTunnel(o *order.Order, scheduler *workflow_execution.WorkflowSchedule) error

func (*Request) Schedule

func (r *Request) Schedule(wfID string, start string, end string, durationInS float64, cron string) (*workflow_execution.WorkflowSchedule, error)

func (*Request) Search

func (r *Request) Search(filters *dbs.Filters, word string, isDraft bool) (data LibDataShallow)

* Search will search for the data in the database * @param filters *dbs.Filters * @param word string * @param collection LibDataEnum * @param c ...*tools.HTTPCaller * @return data LibDataShallow

func (*Request) StoreOne

func (r *Request) StoreOne(object map[string]interface{}) (data LibData)

* StoreOne will store one data from the database * @param collection LibDataEnum * @param object map[string]interface{} * @param c ...*tools.HTTPCaller * @return data LibData

func (*Request) UpdateOne

func (r *Request) UpdateOne(set map[string]interface{}, id string) (data LibData)

* UpdateOne will update one data from the database * @param collection LibDataEnum * @param set map[string]interface{} * @param id string * @param c ...*tools.HTTPCaller * @return data LibData

type SessionClaims

type SessionClaims struct {
	AccessToken map[string]interface{} `json:"access_token"`
	IDToken     IDTokenClaims          `json:"id_token"`
}

SessionClaims struct

Jump to

Keyboard shortcuts

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