services

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2025 License: MIT Imports: 14 Imported by: 12

README

Services module

It provides FOXDEN/CHESS services codebase covering:

  • common service errors and codes
  • services response structure and functionality
  • HTTP read/write helpers which carry appropriate auth token

Documentation

Index

Constants

View Source
const (
	OK                    = 0
	GenericError          = iota + 100 // generic error
	DatabaseError                      // 101 database error
	TransactionError                   // 102 transaction error
	QueryError                         // 103 query error
	RowsScanError                      // 104 row scan error
	SessionError                       // 105 db session error
	CommitError                        // 106 db commit error
	ParseError                         // 107 parser error
	LoadError                          // 108 loading error, e.g. load template
	GetIDError                         // 109 get id db error
	InsertError                        // 110 db insert error
	UpdateError                        // 111 update error
	LastInsertError                    // 112 db last insert error
	ValidateError                      // 113 validation error
	PatternError                       // 114 pattern error
	DecodeError                        // 115 decode error
	EncodeError                        // 116 encode error
	ContentTypeError                   // 117 content type error
	ParametersError                    // 118 parameters error
	NotImplementedApiCode              // 119 not implemented API error
	ReaderError                        // 120 io reader error
	WriterError                        // 121 io writer error
	UnmarshalError                     // 122 json unmarshal error
	MarshalError                       // 123 marshal error
	HttpRequestError                   // 124 HTTP request error
	RemoveError                        // 125 remove error
	BindError                          // 126 bind error
	SchemaError                        // 127 schema error
	ServiceError                       // 128 service error
	CredentialsError                   // 129 credentials error
	TokenError                         // 130 token error
	ScopeError                         // 131 token scope error
	NotFoundError                      // 132 not found error
	AuthError                          // 133 auth error
	MetaError                          // 134 meta error
	StorageError                       // 135 storage error
	PredictError                       // 136 predict (inference) error
	FormDataError                      // 137 form data error
	UploadError                        // 138 upload error
	MarkdownError                      // 139 markdown error
	ZenodoError                        // 140 zenodo error
	FileError                          // 141 file error
	LDAPSearchError                    // 142 LDAP search error
	LDAPGroupError                     // 143 LDAP group error
)

Variables

This section is empty.

Functions

func LDAPUserAttributes added in v0.9.1

func LDAPUserAttributes(user string) (ldap.Entry, error)

LDAPUserAttributes function gets CHESS user attributes

func MetaDataRecords added in v0.6.8

func MetaDataRecords(query string, skeys []string, sorder, idx, limit int) ([]map[string]any, error)

MetaDataRecords return meta-data records for given query

Types

type CHESSUser added in v0.9.1

type CHESSUser struct {
	URL      string // ldap URL
	Login    string // ldap user name
	Password string // ldap password
	BaseDN   string // ldap baseDN
	// contains filtered or unexported fields
}

CHESSUser represents chess user with UserAttributes interface APIs

func (*CHESSUser) Get added in v0.9.1

func (c *CHESSUser) Get(name string) (User, error)

Get implements UserAttributes Get API

func (*CHESSUser) GetGroups added in v0.9.1

func (c *CHESSUser) GetGroups() ([]string, error)

GetGroups implements UserAttributes Get API

func (*CHESSUser) GetUsers added in v0.9.1

func (c *CHESSUser) GetUsers() ([]string, error)

GetUsers implement UserAttributes GetUsers API

func (*CHESSUser) Init added in v0.9.1

func (c *CHESSUser) Init()

Init function initialize CHESSUser ldap cache

type HTTPClient added in v0.9.0

type HTTPClient interface {
	SetToken(token string)
	GetToken()
	Get(rurl string) (*http.Response, error)
	Post(rurl, contentType string, buffer *bytes.Buffer) (*http.Response, error)
	Put(rurl, contentType string, buffer *bytes.Buffer) (*http.Response, error)
	Delete(rurl, contentType string, buffer *bytes.Buffer) (*http.Response, error)
	Request(method, rurl, contentType string, buffer *bytes.Buffer) (*http.Response, error)
	PostForm(rurl string, formData url.Values) (*http.Response, error)
}

HTTPClient defines generic interface of HTTP client

type HttpRequest

type HttpRequest struct {
	Token   string
	Scope   string
	Expires time.Time
	Verbose int
	Headers map[string][]string
}

HttpRequest manage http requests

func NewHttpRequest

func NewHttpRequest(scope string, verbose int) *HttpRequest

NewHttpRequest initilizes and returns new HttpRequest object

func (*HttpRequest) Delete added in v0.1.1

func (h *HttpRequest) Delete(rurl, contentType string, buffer *bytes.Buffer) (*http.Response, error)

Delete performs HTTP PUT request

func (*HttpRequest) Get

func (h *HttpRequest) Get(rurl string) (*http.Response, error)

Get performis HTTP GET request

func (*HttpRequest) GetToken

func (h *HttpRequest) GetToken()

GetToken obtains token from OAuth server

func (*HttpRequest) Post

func (h *HttpRequest) Post(rurl, contentType string, buffer *bytes.Buffer) (*http.Response, error)

Post performs HTTP POST request

func (*HttpRequest) PostForm

func (h *HttpRequest) PostForm(rurl string, formData url.Values) (*http.Response, error)

PostForm perform HTTP POST form request with bearer token

func (*HttpRequest) Put added in v0.1.3

func (h *HttpRequest) Put(rurl, contentType string, buffer *bytes.Buffer) (*http.Response, error)

Put performs HTTP PUT request

func (*HttpRequest) Request added in v0.1.3

func (h *HttpRequest) Request(method, rurl, contentType string, buffer *bytes.Buffer) (*http.Response, error)

Request performs HTTP request for given method

func (*HttpRequest) SetToken added in v0.9.0

func (h *HttpRequest) SetToken(token string)

SetToken obtains token from OAuth server

type MaglabUser added in v0.9.1

type MaglabUser struct {
	URL      string // ldap URL
	Login    string // ldap user name
	Password string // ldap password
	BaseDN   string // ldap baseDN
	// contains filtered or unexported fields
}

MaglabUser represents Maglab user with UserAttributes interface APIs

func (*MaglabUser) Get added in v0.9.1

func (c *MaglabUser) Get(name string) (User, error)

Get implements UserAttributes Get API

func (*MaglabUser) GetGroups added in v0.9.1

func (c *MaglabUser) GetGroups() ([]string, error)

GetGroups implements UserAttributes Get API

func (*MaglabUser) GetUsers added in v0.9.1

func (c *MaglabUser) GetUsers() ([]string, error)

GetUsers implement UserAttributes GetUsers API

func (*MaglabUser) Init added in v0.9.1

func (c *MaglabUser) Init()

Init function initialize MaglabUser ldap cache

type MetaRecord

type MetaRecord struct {
	Schema string
	Record map[string]any
}

MetaRecord represents meta-data record used for injection

func (*MetaRecord) JsonString

func (s *MetaRecord) JsonString() string

String converts ServiceResponse into string representation

type ServiceQuery

type ServiceQuery struct {
	Query      string         `json:"query"`
	Spec       map[string]any `json:"spec"`
	Projection map[string]any `json:"projection"`
	SQL        string         `json:"sql"`
	Idx        int            `json:"idx"`
	Limit      int            `json:"limit"`
	SortKeys   []string       `json:"sort_keys"`
	SortOrder  int            `json:"sort_order"`
}

ServiceQuery represents service query along with its results

type ServiceRequest

type ServiceRequest struct {
	Client       string       `json:"client"`
	ServiceQuery ServiceQuery `json:"service_query"`
}

ServiceRequest represents service request structure

func (*ServiceRequest) String

func (s *ServiceRequest) String() string

String converts ServiceRequest into string representation

type ServiceResponse

type ServiceResponse struct {
	HttpCode     int            `json:"http_code"`
	SrvCode      int            `json:"service_code"`
	Service      string         `json:"service"`
	Status       string         `json:"status"`
	Error        string         `json:"error"`
	ServiceQuery ServiceQuery   `json:"service_query,omitempty"`
	Results      ServiceResults `json:"results,omitempty"`
	Timestamp    string         `json:"timestamp"`
}

ServiceResponse represents service response structure

func Response

func Response(srv string, httpCode, srvCode int, err error) ServiceResponse

Response returns service status record

func (*ServiceResponse) JsonBytes added in v0.0.2

func (s *ServiceResponse) JsonBytes() []byte

JsonBytes converts ServiceResponse into bytes representation

func (*ServiceResponse) JsonString

func (s *ServiceResponse) JsonString() string

JsonString converts ServiceResponse into string representation

func (*ServiceResponse) String

func (s *ServiceResponse) String() string

String converts ServiceResponse into string representation

type ServiceResults

type ServiceResults struct {
	NRecords int              `json:"nrecords"`
	Records  []map[string]any `json:"records"`
}

ServiceResults represents service results

type Token

type Token struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	Expires     int64  `json:"expires_in"`
}

Token represents response from OAuth server call

type User added in v0.9.1

type User struct {
	Name         string
	Groups       []string
	Scopes       []string
	Btrs         []string
	FoxdenGroups []string
}

User defines FOXDEN user

type UserAttributes added in v0.8.0

type UserAttributes interface {
	// Init function initialize foxden user
	Init()
	// GetUsers should return all Foxden user names
	GetUsers() ([]string, error)
	// GetGroups should return all existing groups
	GetGroups() ([]string, error)
	// Get should return User
	Get(user string) (User, error)
}

UserAttributes defines generic interface of Foxden user attributes

Jump to

Keyboard shortcuts

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