-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathv2_package.go
60 lines (46 loc) · 1.54 KB
/
v2_package.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package amclient
import (
"context"
"encoding/base64"
"fmt"
)
const packageBasePath = "api/v2beta/package"
//go:generate mockgen -destination=./fake/mock_v2_package.go -package=fake github.com/artefactual-labs/enduro/internal/amclient PackageService
type PackageService interface {
Create(context.Context, *PackageCreateRequest) (*PackageCreateResponse, *Response, error)
}
type PackageServiceOp struct {
client *Client
}
var _ PackageService = &PackageServiceOp{}
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 struct {
ID string `json:"id,omitempty"`
}
const standardTransferType = "standard"
func (s *PackageServiceOp) Create(ctx context.Context, r *PackageCreateRequest) (*PackageCreateResponse, *Response, error) {
path := fmt.Sprintf("%s/", packageBasePath)
if r.Type == "" {
r.Type = standardTransferType
}
if r.AutoApprove == nil {
var approve = true
r.AutoApprove = &approve
}
r.Path = base64.StdEncoding.EncodeToString([]byte(r.Path))
req, err := s.client.NewRequestJSON(ctx, "POST", path, r)
if err != nil {
return nil, nil, err
}
payload := &PackageCreateResponse{}
resp, err := s.client.Do(ctx, req, payload)
return payload, resp, err
}