File: remote.go

package info (click to toggle)
golang-github-linbit-golinstor 0.55.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 480 kB
  • sloc: makefile: 11
file content (137 lines) | stat: -rw-r--r-- 4,848 bytes parent folder | download
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package client

import (
	"context"
	"fmt"

	"github.com/google/go-querystring/query"
)

type LinstorRemote struct {
	RemoteName string `json:"remote_name,omitempty"`
	Url        string `json:"url,omitempty"`
	Passphrase string `json:"passphrase,omitempty"`
	ClusterId  string `json:"cluster_id,omitempty"`
}

type RemoteList struct {
	S3Remotes      []S3Remote      `json:"s3_remotes,omitempty"`
	LinstorRemotes []LinstorRemote `json:"linstor_remotes,omitempty"`
	EbsRemotes     []EbsRemote     `json:"ebs_remotes,omitempty"`
}

type S3Remote struct {
	RemoteName   string `json:"remote_name,omitempty"`
	Endpoint     string `json:"endpoint,omitempty"`
	Bucket       string `json:"bucket,omitempty"`
	Region       string `json:"region,omitempty"`
	AccessKey    string `json:"access_key,omitempty"`
	SecretKey    string `json:"secret_key,omitempty"`
	UsePathStyle bool   `json:"use_path_style,omitempty"`
}

type EbsRemote struct {
	RemoteName       string `json:"remote_name,omitempty"`
	Endpoint         string `json:"endpoint,omitempty"`
	Region           string `json:"region,omitempty"`
	AvailabilityZone string `json:"availability_zone,omitempty"`
	AccessKey        string `json:"access_key,omitempty"`
	SecretKey        string `json:"secret_key,omitempty"`
}

type RemoteProvider interface {
	// GetAll returns the list of all registered remotes.
	GetAll(ctx context.Context, opts ...*ListOpts) (RemoteList, error)
	// GetAllLinstor returns the list of LINSTOR remotes.
	GetAllLinstor(ctx context.Context, opts ...*ListOpts) ([]LinstorRemote, error)
	// GetAllS3 returns the list of S3 remotes.
	GetAllS3(ctx context.Context, opts ...*ListOpts) ([]S3Remote, error)
	// GetAllEbs returns the list of EBS remotes.
	GetAllEbs(ctx context.Context, opts ...*ListOpts) ([]EbsRemote, error)
	// CreateLinstor creates a new LINSTOR remote.
	CreateLinstor(ctx context.Context, create LinstorRemote) error
	// CreateS3 creates a new S3 remote.
	CreateS3(ctx context.Context, create S3Remote) error
	// CreateEbs creates a new EBS remote.
	CreateEbs(ctx context.Context, create EbsRemote) error
	// Delete a named remote.
	Delete(ctx context.Context, remoteName string) error
	// ModifyLinstor modifies the given LINSTOR remote.
	ModifyLinstor(ctx context.Context, remoteName string, modify LinstorRemote) error
	// ModifyS3 modifies the given S3 remote.
	ModifyS3(ctx context.Context, remoteName string, modify S3Remote) error
	// ModifyEbs modifies the given EBS remote.
	ModifyEbs(ctx context.Context, remoteName string, modify EbsRemote) error
}

var _ RemoteProvider = &RemoteService{}

type RemoteService struct {
	client *Client
}

func (r *RemoteService) GetAll(ctx context.Context, opts ...*ListOpts) (RemoteList, error) {
	var list RemoteList
	_, err := r.client.doGET(ctx, "/v1/remotes", &list, opts...)
	return list, err
}

func (r *RemoteService) GetAllLinstor(ctx context.Context, opts ...*ListOpts) ([]LinstorRemote, error) {
	var list []LinstorRemote
	_, err := r.client.doGET(ctx, "/v1/remotes/linstor", &list, opts...)
	return list, err
}

func (r *RemoteService) GetAllS3(ctx context.Context, opts ...*ListOpts) ([]S3Remote, error) {
	var list []S3Remote
	_, err := r.client.doGET(ctx, "/v1/remotes/s3", &list, opts...)
	return list, err
}

func (r *RemoteService) GetAllEbs(ctx context.Context, opts ...*ListOpts) ([]EbsRemote, error) {
	var list []EbsRemote
	_, err := r.client.doGET(ctx, "/v1/remotes/ebs", &list, opts...)
	return list, err
}

func (r *RemoteService) CreateLinstor(ctx context.Context, create LinstorRemote) error {
	_, err := r.client.doPOST(ctx, "/v1/remotes/linstor", create)
	return err
}

func (r *RemoteService) CreateS3(ctx context.Context, create S3Remote) error {
	_, err := r.client.doPOST(ctx, "/v1/remotes/s3", create)
	return err
}

func (r *RemoteService) CreateEbs(ctx context.Context, create EbsRemote) error {
	_, err := r.client.doPOST(ctx, "/v1/remotes/ebs", create)
	return err
}

func (r *RemoteService) Delete(ctx context.Context, remoteName string) error {
	vals, err := query.Values(&struct {
		RemoteName string `url:"remote_name"`
	}{RemoteName: remoteName})
	if err != nil {
		return fmt.Errorf("failed to encode remote name: %w", err)
	}

	_, err = r.client.doDELETE(ctx, "/v1/remotes?"+vals.Encode(), nil)
	return err
}

func (r *RemoteService) ModifyLinstor(ctx context.Context, remoteName string, modify LinstorRemote) error {
	_, err := r.client.doPUT(ctx, "/v1/remotes/linstor/"+remoteName, modify)
	return err
}

func (r *RemoteService) ModifyS3(ctx context.Context, remoteName string, modify S3Remote) error {
	_, err := r.client.doPUT(ctx, "/v1/remotes/s3/"+remoteName, modify)
	return err
}

func (r *RemoteService) ModifyEbs(ctx context.Context, remoteName string, modify EbsRemote) error {
	_, err := r.client.doPUT(ctx, "/v1/remotes/ebs/"+remoteName, modify)
	return err
}