Documentation ¶
Index ¶
- func CheckResponse(r *http.Response) error
- func WaitUntilStored(ctx context.Context, c *Client, transferID string) (SIPID string, err error)
- type ChecksumSet
- type Client
- func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error)
- func (c *Client) NewRequest(ctx context.Context, method, urlStr string, body interface{}, ...) (*http.Request, error)
- func (c *Client) NewRequestJSON(ctx context.Context, method, urlStr string, body interface{}, ...) (*http.Request, error)
- func (c *Client) TransferSession(name string) (*TransferSession, error)
- type ClientOpt
- type ErrorResponse
- type Job
- type JobStatus
- type JobsListRequest
- type JobsService
- type JobsServiceOp
- type MetadataSet
- type PackageCreateRequest
- type PackageCreateResponse
- type PackageService
- type PackageServiceOp
- type ProcessingConfig
- type ProcessingConfigOp
- type ProcessingConfigService
- type RequestOpt
- type Response
- type Task
- type TaskDateTime
- type TaskDetailed
- type TaskService
- type TaskServiceOp
- type TransferApproveRequest
- type TransferApproveResponse
- type TransferService
- type TransferServiceOp
- func (s *TransferServiceOp) Approve(ctx context.Context, r *TransferApproveRequest) (*TransferApproveResponse, *Response, error)
- func (s *TransferServiceOp) Start(ctx context.Context, r *TransferStartRequest) (*TransferStartResponse, *Response, error)
- func (s *TransferServiceOp) Status(ctx context.Context, ID string) (*TransferStatusResponse, *Response, error)
- func (s *TransferServiceOp) Unapproved(ctx context.Context, r *TransferUnapprovedRequest) (*TransferUnapprovedResponse, *Response, error)
- type TransferSession
- func (s *TransferSession) ChecksumMD5(name, sum string)
- func (s *TransferSession) ChecksumSHA1(name, sum string)
- func (s *TransferSession) ChecksumSHA256(name, sum string)
- func (s *TransferSession) Contents() []string
- func (s *TransferSession) Create(name string) (afero.File, error)
- func (s *TransferSession) Describe(field, value string)
- func (s *TransferSession) DescribeFile(name, field, value string)
- func (s *TransferSession) Destroy() error
- func (s *TransferSession) Start() (string, error)
- func (s *TransferSession) WithProcessingConfig(name string) *TransferSession
- type TransferStartRequest
- type TransferStartResponse
- type TransferStatusResponse
- type TransferUnapprovedRequest
- type TransferUnapprovedResponse
- type TransferUnapprovedResponseResult
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckResponse ¶
CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. API error responses are expected to have either no response body, or a JSON response body that maps to ErrorResponse. Any other response body will be silently ignored.
func WaitUntilStored ¶
WaitUntilStored blocks until the AIP generated after a transfer is confirmed to be stored. The implementation is based on TransferService.Status and JobsService.List.
The retry gives up as soon as one of the following events occur: * The caller cancels the context. * The total retry period exceeds maxWait.
TODO: we may want to give up earlier in case of specific errors, e.g. if TransferService.Status returns errors repeatedly?
Example ¶
package main import ( "context" "fmt" "log" "net/http" "time" "github.com/JiscSD/rdss-archivematica-channel-adapter/amclient" ) func main() { ctx := context.Background() client := amclient.NewClient(http.DefaultClient, "http://127.0.0.1:62080/api", "test", "test") // Start transfer. ctxTimeout, cancel := context.WithTimeout(ctx, time.Hour*2) defer cancel() payload, _, err := client.Package.Create(ctxTimeout, &amclient.PackageCreateRequest{ Name: "images", Type: "standard", Path: "/home/archivematica/archivematica-sampledata/SampleTransfers/Images", ProcessingConfig: "automated", }) if err != nil { log.Fatal("Package.Create failed: ", err) } // Wait until the AIP is stored. SIPID, err := amclient.WaitUntilStored(ctx, client, payload.ID) if err != nil || SIPID == "" { log.Fatal("WaitUntilStored failed: ", err) } fmt.Printf("Transfer stored successfully! AIP %s", SIPID) }
Output:
Types ¶
type ChecksumSet ¶
type ChecksumSet struct {
// contains filtered or unexported fields
}
ChecksumSet holds the checksums of the files for a sum algorithm.
func NewChecksumSet ¶
func NewChecksumSet(sumType string, fs afero.Fs) *ChecksumSet
func (*ChecksumSet) Add ¶
func (c *ChecksumSet) Add(name, sum string)
func (*ChecksumSet) Write ¶
func (c *ChecksumSet) Write() error
type Client ¶
type Client struct { // Base URL for API requests. BaseURL *url.URL // User agent for client UserAgent string // Authentication User string Key string // Services used for communicating with the API Transfer TransferService ProcessingConfig ProcessingConfigService Package PackageService Jobs JobsService Task TaskService // contains filtered or unexported fields }
Client manages communication with Archivematica API.
func (*Client) Do ¶
Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response will be written to v, without attempting to decode it.
func (*Client) NewRequest ¶
func (c *Client) NewRequest(ctx context.Context, method, urlStr string, body interface{}, opts ...RequestOpt) (*http.Request, error)
NewRequest creates an API request. A relative URL can be provided in urlStr, which will be resolved to the BaseURL of the Client. Relative URLS should always be specified without a preceding slash. If specified, the value pointed to by body is form encoded and included in as the request body.
func (*Client) NewRequestJSON ¶
func (c *Client) NewRequestJSON(ctx context.Context, method, urlStr string, body interface{}, opts ...RequestOpt) (*http.Request, error)
NewRequestJSON is similar to NewRequest but encodes the value to JSON.
func (*Client) TransferSession ¶
func (c *Client) TransferSession(name string) (*TransferSession, error)
TransferSession returns a new TransferSession bounded to this client.
type ClientOpt ¶
ClientOpt are options for New.
func SetFsPath ¶
SetFsPath is a client option for setting the local temporary filesystem to the desired local filesystem path.
func SetUserAgent ¶
SetUserAgent is a client option for setting the user agent.
type ErrorResponse ¶
An ErrorResponse reports the error caused by an API request
func (*ErrorResponse) Error ¶
func (r *ErrorResponse) Error() string
type JobStatus ¶
type JobStatus int
func (JobStatus) MarshalJSON ¶
MarshalJSON marshals the enum as a quoted json string
func (*JobStatus) UnmarshalJSON ¶
UnmarshalJSON unmashals a quoted json string to the enum value
type JobsListRequest ¶
type JobsService ¶
type JobsServiceOp ¶
type JobsServiceOp struct {
// contains filtered or unexported fields
}
func (*JobsServiceOp) List ¶
func (s *JobsServiceOp) List(ctx context.Context, ID string, r *JobsListRequest) ([]Job, *Response, error)
type MetadataSet ¶
type MetadataSet struct {
// contains filtered or unexported fields
}
MetadataSet holds the metadata entries of the transfer.
func NewMetadataSet ¶
func NewMetadataSet(fs afero.Fs) *MetadataSet
NewMetadataSet returns a new MetadataSet.
func (*MetadataSet) Add ¶
func (m *MetadataSet) Add(name, field, value string)
func (*MetadataSet) Entries ¶
func (m *MetadataSet) Entries() map[string][][2]string
Entries returns all entries that were created.
func (*MetadataSet) Write ¶
func (m *MetadataSet) Write() error
type PackageCreateRequest ¶
type PackageCreateRequest struct { Name string `json:"name"` Type string `json:"type"` Path string `json:"path"` AccessionSystemID string `json:"access_system_id,omitempty"` MetadataSetID string `json:"metadata_set_id,omitempty"` ProcessingConfig string `json:"processing_config,omitempty"` AutoApprove *bool `json:"auto_approve,omitempty"` }
type PackageCreateResponse ¶
type PackageCreateResponse struct {
ID string `json:"id,omitempty"`
}
type PackageService ¶
type PackageService interface {
Create(context.Context, *PackageCreateRequest) (*PackageCreateResponse, *Response, error)
}
type PackageServiceOp ¶
type PackageServiceOp struct {
// contains filtered or unexported fields
}
func (*PackageServiceOp) Create ¶
func (s *PackageServiceOp) Create(ctx context.Context, r *PackageCreateRequest) (*PackageCreateResponse, *Response, error)
type ProcessingConfig ¶
ProcessingConfig represents the processing configuration document returned by the Dashboard API.
type ProcessingConfigOp ¶
type ProcessingConfigOp struct {
// contains filtered or unexported fields
}
ProcessingConfigOp handles communication with the Tranfer related methods of the Archivematica API.
func (*ProcessingConfigOp) Get ¶
func (s *ProcessingConfigOp) Get(ctx context.Context, name string) (*ProcessingConfig, *Response, error)
Get obtains a processing configuration given its name.
type ProcessingConfigService ¶
type ProcessingConfigService interface {
Get(context.Context, string) (*ProcessingConfig, *Response, error)
}
ProcessingConfigService is an interface for interfacing with the processing configuration endpoints of the Dashboard API.
type RequestOpt ¶
RequestOpt is a function type used to alter requests.
func WithRequestAcceptXML ¶
func WithRequestAcceptXML() RequestOpt
WithRequestAcceptXML sets the Accept header to "application/xml". This is needed when consuming endpoints that require this configuration.
type Response ¶
Response is an Archivematica response. This wraps the standard http.Response returned from Archivematica.
type TaskDateTime ¶
func (*TaskDateTime) UnmarshalJSON ¶
func (t *TaskDateTime) UnmarshalJSON(data []byte) error
type TaskDetailed ¶
type TaskDetailed struct { ID string `json:"uuid"` ExitCode uint8 `json:"exit_code"` FileID string `json:"file_uuid"` Filename string `json:"file_name"` TimeCreated TaskDateTime `json:"time_created"` TimeStarted TaskDateTime `json:"time_started"` TimeEnded TaskDateTime `json:"time_ended"` Duration uint32 `json:"duration"` }
type TaskService ¶
type TaskServiceOp ¶
type TaskServiceOp struct {
// contains filtered or unexported fields
}
func (*TaskServiceOp) Read ¶
func (s *TaskServiceOp) Read(ctx context.Context, ID string) (*TaskDetailed, *Response, error)
type TransferApproveRequest ¶
type TransferApproveRequest struct { Type string `schema:"type"` Directory string `schema:"directory"` }
TransferApproveRequest represents a request to approve a transfer.
type TransferApproveResponse ¶
TransferApproveResponse represents a response to TransferApproveRequest.
type TransferService ¶
type TransferService interface { Start(context.Context, *TransferStartRequest) (*TransferStartResponse, *Response, error) Approve(context.Context, *TransferApproveRequest) (*TransferApproveResponse, *Response, error) Unapproved(context.Context, *TransferUnapprovedRequest) (*TransferUnapprovedResponse, *Response, error) Status(context.Context, string) (*TransferStatusResponse, *Response, error) }
TransferService is an interface for interfacing with the Transfer endpoints of the Dashboard API.
type TransferServiceOp ¶
type TransferServiceOp struct {
// contains filtered or unexported fields
}
TransferServiceOp handles communication with the Tranfer related methods of the Archivematica API.
func (*TransferServiceOp) Approve ¶
func (s *TransferServiceOp) Approve(ctx context.Context, r *TransferApproveRequest) (*TransferApproveResponse, *Response, error)
Approve approves an existing transfer awaiting for approval.
func (*TransferServiceOp) Start ¶
func (s *TransferServiceOp) Start(ctx context.Context, r *TransferStartRequest) (*TransferStartResponse, *Response, error)
Start starts a new transfer.
func (*TransferServiceOp) Status ¶
func (s *TransferServiceOp) Status(ctx context.Context, ID string) (*TransferStatusResponse, *Response, error)
func (*TransferServiceOp) Unapproved ¶
func (s *TransferServiceOp) Unapproved(ctx context.Context, r *TransferUnapprovedRequest) (*TransferUnapprovedResponse, *Response, error)
Unapproved lists existing transfers waiting for approval.
type TransferSession ¶
type TransferSession struct { Metadata *MetadataSet ChecksumsMD5 *ChecksumSet ChecksumsSHA1 *ChecksumSet ChecksumsSHA256 *ChecksumSet // contains filtered or unexported fields }
TransferSession is a convenience tool to make it easier to create and submit transfers.
A transfer session can be created using `NewTransferSession`. Before you create one, make sure that `TransferDir` is invoked indicating the absolute path of the transfer source location.
func NewTransferSession ¶
func NewTransferSession(c *Client, name string) (*TransferSession, error)
NewTransferSession returns a pointer to a new TransferSession.
func (*TransferSession) ChecksumMD5 ¶
func (s *TransferSession) ChecksumMD5(name, sum string)
ChecksumMD5 registers a MD5 checksum for a file.
func (*TransferSession) ChecksumSHA1 ¶
func (s *TransferSession) ChecksumSHA1(name, sum string)
ChecksumSHA1 registers a SHA1 checksum for a file.
func (*TransferSession) ChecksumSHA256 ¶
func (s *TransferSession) ChecksumSHA256(name, sum string)
ChecksumSHA256 registers a SHA256 checksum for a file.
func (*TransferSession) Contents ¶
func (s *TransferSession) Contents() []string
Contents returns a list with all the files currently available in the temporary transfer filesystem.
func (*TransferSession) Create ¶
func (s *TransferSession) Create(name string) (afero.File, error)
Create returns a new file created in the transfer directory.
func (*TransferSession) Describe ¶
func (s *TransferSession) Describe(field, value string)
Describe registers metadata of the whole dataset/transfer. It causes the transfer to include a `metadata.json` file with the metadata included.
func (*TransferSession) DescribeFile ¶
func (s *TransferSession) DescribeFile(name, field, value string)
DescribeFile registers metadata of a file. It causes the transfer to include a `metadata.json` file with the metadata of each file described.
func (*TransferSession) Destroy ¶
func (s *TransferSession) Destroy() error
Destroy removes the transfer directory and its contents. The caller should not expect TransferSession to be in a usable state once this method has been called.
func (*TransferSession) Start ¶
func (s *TransferSession) Start() (string, error)
Start the transfer using the Package API endpoint. This API is still in beta.
func (*TransferSession) WithProcessingConfig ¶
func (s *TransferSession) WithProcessingConfig(name string) *TransferSession
type TransferStartRequest ¶
type TransferStartRequest struct { Name string `schema:"name"` Type string `schema:"type"` Paths []string `schema:"paths"` }
TransferStartRequest represents a request to start a transfer.
type TransferStartResponse ¶
TransferStartResponse represents a response to TransferStartRequest.
type TransferStatusResponse ¶
type TransferStatusResponse struct { ID string `json:"uuid"` Status string `json:"status"` Name string `json:"name"` SIPID string `json:"sip_uuid"` Microservice string `json:"microservice"` Directory string `json:"directory"` Path string `json:"path"` Message string `json:"message"` Type string `json:"type"` }
func (TransferStatusResponse) SIP ¶
func (t TransferStatusResponse) SIP() (string, bool)
type TransferUnapprovedRequest ¶
type TransferUnapprovedRequest struct{}
TransferUnapprovedRequest represents a request to list unapproved transfer.
type TransferUnapprovedResponse ¶
type TransferUnapprovedResponse struct { Message string `json:"message"` Results []*TransferUnapprovedResponseResult `json:"results"` }
TransferUnapprovedResponse represents a response to TransferUnapprovedRequest.
type TransferUnapprovedResponseResult ¶
type TransferUnapprovedResponseResult struct { Type string `json:"type"` Directory string `json:"directory"` UUID string `json:"uuid"` }
TransferUnapprovedResponseResult represents a result of TransferUnapprovedResponse.