easclient

package module
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2024 License: MIT Imports: 14 Imported by: 0

README

EAS Client

This project implements an HTTP client for the API of the Otris EAS developed by Otris AG.

Testing

Since this is an API client for a proprietary software, we have decided to not include any docker containers / images which would allow you to test the client against a running EAS instance.

That is why the CI pipeline skips tests which require a running EAS instance.

Documentation

Index

Constants

View Source
const (
	HeaderKeyOtrisErr = "X-Otris-Eas-Error"
)
View Source
const UserClaimsKey = "easclient-user-claims-key"

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigurationParameter

type ConfigurationParameter struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type ConfigurationTemplate

type ConfigurationTemplate struct {
	Name       string                   `json:"name"`
	Parameters []ConfigurationParameter `json:"parameters"`
}

type HeaderFields added in v0.3.0

type HeaderFields struct {
	DocumentType           string    `json:"_documentType"`
	MasterId               uuid.UUID `json:"_masterId"`
	ArchiveDateTime        time.Time `json:"_archiveDateTime"`
	Id                     uuid.UUID `json:"_id"`
	Version                string    `json:"_version"`
	ArchiverLogin          string    `json:"_archiverLogin"`
	InitialArchiverLogin   string    `json:"_initialArchiverLogin"`
	InitialArchiveDateTime time.Time `json:"_initialArchiveDateTime"`
}
type Link struct {
	Type  string `json:"type"`
	Title string `json:"title"`
	Href  string `json:"href"`
}

type PostRecordResponse added in v0.4.0

type PostRecordResponse struct {
	Records []struct {
		Id   uuid.UUID `json:"id"`
		Link struct {
			Type  string `json:"type"`
			Title string `json:"title"`
			Href  string `json:"href"`
		} `json:"link"`
	} `json:"records"`
}

type PutStoreRequest

type PutStoreRequest struct {
	ConfigurationTemplate `json:"configurationTemplate"`
}

type Record

type Record struct {
	HeaderFields HeaderFields        `json:"headerFields"`
	RecordFields RecordFields        `json:"recordFields"`
	Attachments  []*RecordAttachment `json:"attachments"`
}

func (*Record) GetHeaderField added in v0.1.2

func (rec *Record) GetHeaderField(name string) string

GetHeaderField returns either the value of the given header field or an empty string if the field does not exist.

type RecordAttachment

type RecordAttachment struct {
	Body            string    `json:"body"`
	Name            string    `json:"name"`
	Size            string    `json:"size"`
	Register        string    `json:"register"`
	Author          string    `json:"author"`
	Type            string    `json:"type"`
	DocumentType    string    `json:"documentType"`
	Id              uuid.UUID `json:"id"`
	FileId          uuid.UUID `json:"fileId"`
	MasterId        uuid.UUID `json:"masterId"`
	Version         string    `json:"version"`
	ArchiveDateTime time.Time `json:"archiveDateTime"`
}

type RecordFields added in v0.3.0

type RecordFields map[string]string

type RecordRequest added in v0.4.0

type RecordRequest struct {
	Fields      map[string]string
	Attachments []*RecordRequestAttachment
}

type RecordRequestAttachment added in v0.6.0

type RecordRequestAttachment struct {
	Name     string
	Path     string
	Size     uint64
	Register string
	Author   string
}

RecordRequestAttachment is used in a RecordRequest to specify spooled attachments to be added to the record.

The EAS expects at least Name and Path to be set.

type RequestHeader

type RequestHeader string
const (
	HeaderUser         RequestHeader = "x-otris-eas-user"
	HeaderUserFullname RequestHeader = "x-otris-eas-user-fullname"
	HeaderTokens       RequestHeader = "x-otris-eas-tokens"
)

type ResponseErr added in v0.5.0

type ResponseErr struct {
	Body []byte

	// Response is the original error response from the EAS. This may contain
	// zero values if the EAS did not return a valid error response.
	Response errorResponse
	// contains filtered or unexported fields
}

func NewResponseErr added in v0.5.0

func NewResponseErr(msg string, body []byte) *ResponseErr

func (*ResponseErr) Error added in v0.5.0

func (r *ResponseErr) Error() string

type SearchRequest added in v0.3.0

type SearchRequest struct {
	Query string `json:"query"`

	ItemsPerPage int `json:"itemsPerPage"`
	StartIndex   int `json:"startIndex"`

	// Sort is the field to sort by
	Sort string `json:"sort"`
	// SortOrder is the order to sort by, either "asc" or "desc"
	SortOrder string `json:"sortOrder"`
}

func SearchRequestFromURL added in v0.3.0

func SearchRequestFromURL(s string) (*SearchRequest, error)

func (SearchRequest) ToQuery added in v0.3.0

func (request SearchRequest) ToQuery() map[string]string

type SearchResponse added in v0.3.0

type SearchResponse struct {
	Query            string          `json:"query"`
	TotalHits        int             `json:"totalHits"`
	ItemsPerPage     int             `json:"itemsPerPage"`
	StartIndex       int             `json:"startIndex"`
	Topn             int             `json:"topn"`
	EffectiveResults int             `json:"effectiveResults"`
	Result           []*SearchResult `json:"result"`
}

type SearchResult added in v0.3.0

type SearchResult struct {
	Title            string       `json:"title"`
	Score            float64      `json:"score"`
	Id               uuid.UUID    `json:"id"`
	FileLink         Link         `json:"fileLink"`
	ExplainLink      Link         `json:"explainLink"`
	CheckVersionLink Link         `json:"checkVersionLink"`
	HistoryLink      Link         `json:"historyLink"`
	VerifyLink       Link         `json:"verifyLink"`
	HeaderFields     HeaderFields `json:"headerFields"`
	RecordFields     RecordFields `json:"recordFields"`
}

type ServerClient

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

func NewServerClient

func NewServerClient(c *resty.Client) *ServerClient

func (*ServerClient) PutStore

func (c *ServerClient) PutStore(ctx context.Context, storeName string, request *PutStoreRequest) error

type StoreClient

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

func NewStoreClient

func NewStoreClient(c *resty.Client) *StoreClient

func (*StoreClient) GetRecord

func (c *StoreClient) GetRecord(ctx context.Context, id uuid.UUID) (*Record, error)

func (*StoreClient) GetRecordAttachment

func (c *StoreClient) GetRecordAttachment(ctx context.Context, writer io.Writer, recordID, attachmentID uuid.UUID) (int64, error)

GetRecordAttachment retrieves the actual attachment. It is written to the given io.Writer.

This returns the number of bytes written and an error if any.

func (*StoreClient) GetStoreStatus

func (c *StoreClient) GetStoreStatus(ctx context.Context) (*StoreStatus, error)

func (*StoreClient) PostRecord added in v0.4.0

func (c *StoreClient) PostRecord(ctx context.Context, request *RecordRequest) (*PostRecordResponse, error)

func (*StoreClient) Search added in v0.3.0

func (c *StoreClient) Search(ctx context.Context, request *SearchRequest) (*SearchResponse, error)

func (*StoreClient) SearchQuery added in v0.3.0

func (c *StoreClient) SearchQuery(ctx context.Context, url string) (*SearchResponse, error)

SearchQuery is similar to Search but expects a URL from which SearchRequest is parsed via SearchRequestFromURL.

type StoreStatus

type StoreStatus struct {
	Registry struct {
		AllRecords         int `json:"allRecords"`
		IndexedRecords     int `json:"indexedRecords"`
		AllAttachments     int `json:"allAttachments"`
		IndexedAttachments int `json:"indexedAttachments"`
	} `json:"registry"`
	Index struct {
		Documents    int  `json:"documents"`
		IsCurrent    bool `json:"isCurrent"`
		HasDeletions bool `json:"hasDeletions"`
		Records      int  `json:"records"`
		Attachments  int  `json:"attachments"`
	} `json:"index"`
	Capacity struct {
		Maximum     int64     `json:"maximum"`
		Utilized    float64   `json:"utilized"`
		GrowthRate  float64   `json:"growthRate"`
		ExpectedEnd time.Time `json:"expectedEnd"`
		Lifetime    int       `json:"lifetime"`
	} `json:"capacity"`
	Periods []struct {
		Start    string `json:"start"`
		End      string `json:"end"`
		Registry struct {
			AllRecords         int `json:"allRecords"`
			IndexedRecords     int `json:"indexedRecords"`
			AllAttachments     int `json:"allAttachments"`
			IndexedAttachments int `json:"indexedAttachments"`
		} `json:"registry"`
		Index struct {
			Records     int `json:"records"`
			Attachments int `json:"attachments"`
		} `json:"index"`
		Capacity struct {
			Utilized float64 `json:"utilized"`
		} `json:"capacity"`
	} `json:"periods"`
}

type User

type User string

User is a custom type to represent one of the four EAS user instances.

const (
	// UserAdmin is the administrator which most permissions.
	UserAdmin User = "eas_administrator"
	// UserKeeper is responsible for auditing, moderating, etc.
	UserKeeper User = "eas_keeper"
	// UserUser is the default user being able to read and write.
	UserUser User = "eas_user"
	// UserGuest is a guest user.
	UserGuest User = "eas_guest"
)

type UserClaims

type UserClaims struct {
	// UserId - Technischer Identifikator des Nutzers, der im Host-System die Anfrage ausgelöst hat.
	UserId string `json:"user,omitempty"`

	// UserFullname - Optionaler, vollständiger Name des Nutzers, der im Host-System die Anfrage ausgelöst hat
	UserFullname string `json:"user_fullname,omitempty"`

	// Tokens - Securitytokens (Gruppenzugehörigkeit) -getrennt durch Kommata- des Nutzers, der im Host-System den Request
	// ausgelöst hat.
	Tokens []string `json:"tokens,omitempty"`
}

UserClaims aggregates all claims that are scoped to an EAS archive user.

func NewUserClaims

func NewUserClaims(userId string) *UserClaims

func UserClaimsFromContext

func UserClaimsFromContext(ctx context.Context) *UserClaims

func (*UserClaims) SetOnContext

func (claims *UserClaims) SetOnContext(ctx context.Context) context.Context

func (*UserClaims) SetOnHeader

func (claims *UserClaims) SetOnHeader(header http.Header)

SetOnHeader sets all possible eas.RequestHeader based on this UserClaims

Directories

Path Synopsis
Package eastest contains test helpers for testing with the EAS.
Package eastest contains test helpers for testing with the EAS.

Jump to

Keyboard shortcuts

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