libremotebuild

package module
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2020 License: Apache-2.0 Imports: 14 Imported by: 1

README

libDataManager

A go package implementing the DataManager protocol

Documentation

Index

Constants

View Source
const (
	// DMToken session token for DManager
	DMToken = "DM_Token"

	// DMUser username for DManger
	DMUser = "DM_USER"

	// DMHost Dmanager host
	DMHost = "DM_HOST"

	// DMHost Dmanager host
	DMNamespace = "DM_NAMESPACE"
)

DataManager Keys

View Source
const (
	// Ping
	EPPing Endpoint = "/ping"

	// User
	EPUser     Endpoint = "/user"
	EPLogin             = EPUser + "/login"
	EPRegister          = EPUser + "/register"

	// Jobs
	EPJob       Endpoint = "/job"
	EPJobAdd             = EPJob + "/create"
	EPJobLogs            = EPJob + "/logs"
	EPJobCancel          = EPJob + "/cancel"
	EPJobInfo            = EPJob + "/info"
	EPJobs               = EPJob + "s"

	EPJobState  = EPJob + "/state"
	EPJobPause  = EPJobState + "/pause"
	EPJobResume = EPJobState + "/resume"

	// Ccache
	EPCcache      Endpoint = "/ccache"
	EPCcacheClear          = EPCcache + "/clear"
	EPCcacheStats          = EPCcache + "/stats"
)

Remote endpoints

View Source
const (
	// HeaderStatus headername for status in response
	HeaderStatus string = "X-Response-Status"

	// HeaderStatusMessage headername for status in response
	HeaderStatusMessage string = "X-Response-Message"

	// HeaderContentType contenttype of response
	HeaderContentType string = "Content-Type"

	// HeaderRequest request content
	HeaderRequest string = "Request"

	// HeaderContentLength request content length
	HeaderContentLength string = "ContentLength"
)
View Source
const (
	AURPackage = "REPO"
)

AUR keys

Variables

View Source
var (
	// ErrInvalidResponseHeaders error on missing or malformed response headers
	ErrInvalidResponseHeaders = errors.New("Invalid response headers")
	// ErrResponseError response returned an error
	ErrResponseError = errors.New("response returned an error")
)

Functions

This section is empty.

Types

type AURBuild

type AURBuild struct {
	LibRB

	UploadType    UploadType
	DisableCcache bool
	// contains filtered or unexported fields
}

AURBuild build an AUR package

func (*AURBuild) CreateJob

func (aurBuild *AURBuild) CreateJob() (*AddJobResponse, error)

CreateJob build AUR package

func (*AURBuild) WithDmanager

func (aurBuild *AURBuild) WithDmanager(username, token, host, namespace string)

WithDmanager use dmnager for uplaod

func (*AURBuild) WithoutCcache

func (aurBuild *AURBuild) WithoutCcache() *AURBuild

WithoutCcache disables ccache

type AddJobRequest

type AddJobRequest struct {
	Type          JobType           `json:"buildtype"`
	Args          map[string]string `json:"args"`
	UploadType    UploadType        `json:"uploadtype"`
	DisableCcache bool              `json:"disableccache"`
}

AddJobRequest request for creating a new job

type AddJobResponse

type AddJobResponse struct {
	ID       uint `json:"id"`
	Position int  `json:"pos"`
}

AddJobResponse response for adding a job

type Authorization

type Authorization struct {
	Type    AuthorizationType
	Palyoad string
}

Authorization the authorization params for a server request

type AuthorizationType

type AuthorizationType string

AuthorizationType authorization type

const (
	Bearer AuthorizationType = "Bearer"
	Basic  AuthorizationType = "Basic"
)

Authorizanion types

type ContentType

type ContentType string

ContentType contenttype header of request

const (
	JSONContentType ContentType = "application/json"
)

Content types

type CredentialsRequest

type CredentialsRequest struct {
	MachineID string `json:"mid,omitempty"`
	Username  string `json:"username"`
	Password  string `json:"pass"`
}

CredentialsRequest request containing credentials

type Endpoint

type Endpoint string

Endpoint a remote url-path

type JobInfo

type JobInfo struct {
	ID           uint          `json:"id"`
	Info         string        `json:"info"`
	Position     uint          `json:"pos"`
	BuildType    JobType       `json:"jobtype"`
	UploadType   UploadType    `json:"uploadtype"`
	Status       JobState      `json:"state"`
	RunningSince time.Time     `json:"rs,omitempty"`
	Duration     time.Duration `json:"dr"`
}

JobInfo info of job

type JobLogsRequest

type JobLogsRequest struct {
	JobID uint      `json:"id"`
	Since time.Time `json:"since"`
}

JobLogsRequest cancel a job

type JobRequest

type JobRequest struct {
	JobID uint `json:"id"`
}

JobRequest cancel a job

type JobState

type JobState uint8

JobState a state of a job

const (
	JobWaiting JobState = iota
	JobCancelled
	JobFailed
	JobRunning
	JobDone
	JobPaused
)

...

func (JobState) String

func (js JobState) String() string

type JobType

type JobType uint8

JobType type of job

const (
	JobNoBuild JobType = iota
	JobAUR
)

...

func ParseJobType

func ParseJobType(inp string) JobType

ParseJobType parse a jobtype from string

func (JobType) String

func (jt JobType) String() string

type LibRB

type LibRB struct {
	Config *RequestConfig
}

LibRB data required in all requests

func NewLibRB

func NewLibRB(config *RequestConfig) *LibRB

NewLibRB create new libDM "class"

func (LibRB) AddJob

func (librb LibRB) AddJob(jobType JobType, uploadType UploadType, args map[string]string, disableCcache bool) (*AddJobResponse, error)

AddJob a job

func (LibRB) CancelJob

func (librb LibRB) CancelJob(jobID uint) error

CancelJob cancel a running or queued job

func (LibRB) ClearCcache

func (librb LibRB) ClearCcache() (string, error)

ClearCcache clear ccache on server

func (LibRB) JobInfo

func (librb LibRB) JobInfo(jobID uint) (*JobInfo, error)

JobInfo gets information for a job

func (LibRB) ListJobs

func (librb LibRB) ListJobs(limit int) (*ListJobsResponse, error)

ListJobs list running jobs

func (LibRB) Login

func (librb LibRB) Login(username, password string) (*LoginResponse, error)

Login login into the server

func (LibRB) Logs

func (librb LibRB) Logs(jobID uint, since time.Time) (*RestRequestResponse, error)

Logs for a job

func (LibRB) NewAURBuild

func (Librb LibRB) NewAURBuild(packageName string) *AURBuild

NewAURBuild build an AUR package

func (*LibRB) NewRequest

func (limdm *LibRB) NewRequest(endpoint Endpoint, payload interface{}) *Request

NewRequest creates a new post request

func (LibRB) Ping

func (librb LibRB) Ping() (*StringResponse, error)

Ping pings a server the REST way to ensure it is reachable

func (LibRB) QueryCcache

func (librb LibRB) QueryCcache() (StringResponse, error)

QueryCcache get ccache stats

func (LibRB) Register

func (librb LibRB) Register(username, password string) (*RestRequestResponse, error)

Register create a new account. Return true on success

func (LibRB) Request

func (libdm LibRB) Request(ep Endpoint, payload, response interface{}, authorized bool) (*RestRequestResponse, error)

Request do a request using libdm

func (LibRB) SetJobState

func (librb LibRB) SetJobState(jobID uint, state JobState) error

SetJobState pauses a running or queued job

type ListJobsRequest

type ListJobsRequest struct {
	Limit int `json:"l"`
}

ListJobsRequest request for listing jobs

type ListJobsResponse

type ListJobsResponse struct {
	Jobs []JobInfo `json:"jobs"`
}

ListJobsResponse list of queued jobs

type LoginResponse

type LoginResponse struct {
	Token string `json:"token"`
}

LoginResponse response for login

type Method

type Method string

Method http request method

const (
	GET    Method = "GET"
	POST   Method = "POST"
	DELETE Method = "DELETE"
	PUT    Method = "PUT"
)

Requests

type PingRequest

type PingRequest struct {
	Payload string
}

PingRequest a ping request content

type Request

type Request struct {
	RequestType   RequestType
	Endpoint      Endpoint
	Payload       interface{}
	Config        *RequestConfig
	Method        Method
	ContentType   ContentType
	Authorization *Authorization
	Headers       map[string]string
	BenchChan     chan time.Time
	CloseBody     bool
}

Request a rest server request

func (*Request) BuildClient

func (request *Request) BuildClient() *http.Client

BuildClient return client

func (Request) Do

func (request Request) Do(retVar interface{}) (*RestRequestResponse, error)

Do a better request method

func (*Request) DoHTTPRequest

func (request *Request) DoHTTPRequest() (*http.Response, error)

DoHTTPRequest do plain http request

func (*Request) WithAuth

func (request *Request) WithAuth(a Authorization) *Request

WithAuth with authorization

func (*Request) WithAuthFromConfig

func (request *Request) WithAuthFromConfig() *Request

WithAuthFromConfig with authorization

func (*Request) WithBenchCallback

func (request *Request) WithBenchCallback(c chan time.Time) *Request

WithBenchCallback with bench

func (*Request) WithContentType

func (request *Request) WithContentType(ct ContentType) *Request

WithContentType with contenttype

func (*Request) WithHeader

func (request *Request) WithHeader(name string, value string) *Request

WithHeader add header to request

func (*Request) WithMethod

func (request *Request) WithMethod(m Method) *Request

WithMethod use a different method

func (*Request) WithNoBodyClose

func (request *Request) WithNoBodyClose() *Request

WithNoBodyClose don't close body after request

func (*Request) WithRequestType

func (request *Request) WithRequestType(rType RequestType) *Request

WithRequestType use different request type

type RequestConfig

type RequestConfig struct {
	IgnoreCert   bool
	URL          string
	MachineID    string
	Username     string
	SessionToken string
}

RequestConfig configurations for requests

func (RequestConfig) GetBearerAuth

func (rc RequestConfig) GetBearerAuth() Authorization

GetBearerAuth returns bearer authorization from config

type RequestType

type RequestType uint8

RequestType type of request

const (
	JSONRequestType RequestType = iota
	RawRequestType
)

Request types

type ResponseErr

type ResponseErr struct {
	Response *RestRequestResponse
	Err      error
}

ResponseErr response error

func NewErrorFromResponse

func NewErrorFromResponse(r *RestRequestResponse, err ...error) *ResponseErr

NewErrorFromResponse return error from response

func (*ResponseErr) Error

func (reserr *ResponseErr) Error() string

type ResponseStatus

type ResponseStatus uint8

ResponseStatus the status of response

const (
	// ResponseError if there was an error
	ResponseError ResponseStatus = 0
	// ResponseSuccess if the response is successful
	ResponseSuccess ResponseStatus = 1
)

type RestRequestResponse

type RestRequestResponse struct {
	HTTPCode int
	Status   ResponseStatus
	Message  string
	Headers  *http.Header
	Response *http.Response
}

RestRequestResponse the response of a rest call

type SortByJob

type SortByJob []JobInfo

SortByJob sort jobs

func (SortByJob) Len

func (a SortByJob) Len() int

func (SortByJob) Less

func (a SortByJob) Less(i, j int) bool

func (SortByJob) Swap

func (a SortByJob) Swap(i, j int)

type StringResponse

type StringResponse struct {
	String string `json:"content"`
}

StringResponse response containing only one string

type StringSliceResponse

type StringSliceResponse struct {
	Slice []string `json:"slice"`
}

StringSliceResponse response containing only one string slice

type UploadType

type UploadType uint8

UploadType type of upload destination

const (
	NoUploadType UploadType = iota
	DataManagerUploadType
	LocalStorage
)

...

func ParseUploadType

func ParseUploadType(s string) UploadType

ParseUploadType an uploadtype string

func (UploadType) String

func (ut UploadType) String() string

Directories

Path Synopsis
config module

Jump to

Keyboard shortcuts

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