easclient

package module
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2024 License: MIT Imports: 15 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 Link struct {
	Type string `xml:"type,attr"`
	Href string `xml:"href,attr"`
}

type PostRecordResponse added in v0.4.0

type PostRecordResponse struct {
	XMLName xml.Name `xml:"recordArchive"`
	ID      struct {
		Value uuid.UUID `xml:",chardata"`
		Type  string    `xml:"type,attr"`
		Href  string    `xml:"href,attr"`
	} `xml:"id"`
}

type PutStoreRequest

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

type Record

type Record struct {
	Type                   string              `xml:"type"`
	Title                  string              `xml:"title"`
	DocumentType           string              `xml:"documentType"`
	MasterId               uuid.UUID           `xml:"masterId"`
	ArchiveDateTime        time.Time           `xml:"archiveDateTime"`
	ID                     uuid.UUID           `xml:"id"`
	Version                string              `xml:"version"`
	ArchiverLogin          string              `xml:"archiverLogin"`
	Archiver               string              `xml:"archiver"`
	InitialArchiver        string              `xml:"initialArchiver"`
	InitialArchiverLogin   string              `xml:"initialArchiverLogin"`
	InitialArchiveDateTime time.Time           `xml:"initialArchiveDateTime"`
	Fields                 []*RecordField      `xml:"field"`
	Attachments            []*RecordAttachment `xml:"attachment"`
}

func (*Record) GetHeaderFieldVal added in v0.7.0

func (r *Record) GetHeaderFieldVal(name string) string

type RecordAttachment

type RecordAttachment struct {
	Name     string    `xml:"name"`
	Size     int       `xml:"size"`
	Register string    `xml:"register"`
	Author   string    `xml:"author"`
	ID       uuid.UUID `xml:"id"`
}

type RecordField added in v0.7.0

type RecordField struct {
	Name  string `xml:"name,attr"`
	Value string `xml:",chardata"`
}

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 {
	XMLName xml.Name               `xml:"rss"`
	Version string                 `xml:"version,attr"`
	Channel *SearchResponseChannel `xml:"channel"`
}

type SearchResponseChannel added in v0.7.0

type SearchResponseChannel struct {
	Title        string `xml:"title"`
	Link         string `xml:"link"`
	Description  string `xml:"description"`
	TotalResults int    `xml:"totalResults"`
	ItemsPerPage int    `xml:"itemsPerPage"`
	StartIndex   int    `xml:"startIndex"`
	Query        struct {
		Role        string `xml:"role,attr"`
		SearchTerms string `xml:"searchTerms,attr"`
		StartPage   int    `xml:"startPage,attr"`
	} `xml:"Query"`
	Topn             int                   `xml:"topn"`
	EffectiveResults int                   `xml:"effectiveResults"`
	NextPage         string                `xml:"nextPage"`
	Items            []*SearchResponseItem `xml:"item"`
}

type SearchResponseItem added in v0.7.0

type SearchResponseItem struct {
	Title                  string         `xml:"title"`
	Link                   string         `xml:"link"`
	Description            string         `xml:"description"`
	Score                  float64        `xml:"score"`
	ExplainLink            Link           `xml:"explainLink"`
	VersionLink            Link           `xml:"versionLink"`
	HistoryLink            Link           `xml:"historyLink"`
	VerifyLink             Link           `xml:"verifyLink"`
	DocumentType           string         `xml:"documentType"`
	Fields                 []*RecordField `xml:"field"`
	MasterId               uuid.UUID      `xml:"masterId"`
	ArchiveDateTime        time.Time      `xml:"archiveDateTime"`
	Id                     uuid.UUID      `xml:"id"`
	Version                string         `xml:"version"`
	ArchiverLogin          string         `xml:"archiverLogin"`
	Archiver               string         `xml:"archiver"`
	InitialArchiver        string         `xml:"initialArchiver"`
	InitialArchiverLogin   string         `xml:"initialArchiverLogin"`
	InitialArchiveDateTime time.Time      `xml:"initialArchiveDateTime"`
}

type ServerClient

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

func NewServerClient

func NewServerClient(c *resty.Client) *ServerClient

NewServerClient creates a new client for server interaction.

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

NewStoreClient creates a new client for store interaction.

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) (*SearchResponseChannel, error)

func (*StoreClient) SearchQuery added in v0.3.0

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

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

type StoreStatus

type StoreStatus struct {
	XMLName  xml.Name `xml:"status"`
	Registry struct {
		Records struct {
			All     int `xml:"all"`
			Indexed int `xml:"indexed"`
		} `xml:"records"`
		Attachments struct {
			All     int `xml:"all"`
			Indexed int `xml:"indexed"`
		} `xml:"attachments"`
	} `xml:"registry"`
	Index struct {
		Documents    int  `xml:"documents"`
		IsCurrent    bool `xml:"isCurrent"`
		HasDeletions bool `xml:"hasDeletions"`
	} `xml:"index"`
}

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