-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathclient.go
More file actions
115 lines (90 loc) · 2.52 KB
/
Copy pathclient.go
File metadata and controls
115 lines (90 loc) · 2.52 KB
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
package v2
import (
"context"
v1 "github.com/brevdev/cloud/v1"
sfc "github.com/sfcompute/sfc-go"
)
const CloudProviderID = "sfcompute"
// SFCCredentialV2 holds authentication details for a Brev-managed SFCompute V2 account.
type SFCCredentialV2 struct {
RefID string
APIKey string `json:"api_key"`
Organization string `json:"organization"`
Workspace string `json:"workspace"`
}
var _ v1.CloudCredential = &SFCCredentialV2{}
func NewSFCCredentialV2(refID string, apiKey string, organization string, workspace string) *SFCCredentialV2 {
return &SFCCredentialV2{
RefID: refID,
APIKey: apiKey,
Organization: organization,
Workspace: workspace,
}
}
func (c *SFCCredentialV2) GetReferenceID() string {
return c.RefID
}
func (c *SFCCredentialV2) GetAPIType() v1.APIType {
return v1.APITypeGlobal
}
func (c *SFCCredentialV2) GetCloudProviderID() v1.CloudProviderID {
return CloudProviderID
}
func (c *SFCCredentialV2) GetTenantID() (string, error) {
return "", nil
}
type SFCClientV2 struct {
v1.NotImplCloudClient
refID string
organization string
workspace string
location string
client *sfc.SDK
logger v1.Logger
}
var _ v1.CloudClient = &SFCClientV2{}
type SFCClientV2Option func(c *SFCClientV2)
func WithLogger(logger v1.Logger) SFCClientV2Option {
return func(c *SFCClientV2) {
c.logger = logger
}
}
func (c *SFCCredentialV2) MakeClientWithOptions(_ context.Context, location string, opts ...SFCClientV2Option) (v1.CloudClient, error) {
sfcClient := &SFCClientV2{
refID: c.RefID,
organization: c.Organization,
workspace: c.Workspace,
location: location,
client: sfc.New(sfc.WithSecurity(c.APIKey)),
logger: &v1.NoopLogger{},
}
for _, opt := range opts {
opt(sfcClient)
}
return sfcClient, nil
}
func (c *SFCCredentialV2) MakeClient(ctx context.Context, location string) (v1.CloudClient, error) {
return c.MakeClientWithOptions(ctx, location)
}
func (c *SFCClientV2) GetAPIType() v1.APIType {
return v1.APITypeGlobal
}
func (c *SFCClientV2) GetCloudProviderID() v1.CloudProviderID {
return CloudProviderID
}
func (c *SFCClientV2) GetOrganization() string {
return c.organization
}
func (c *SFCClientV2) GetWorkspace() string {
return c.workspace
}
func (c *SFCClientV2) GetReferenceID() string {
return c.refID
}
func (c *SFCClientV2) GetTenantID() (string, error) {
return "", nil
}
func (c *SFCClientV2) MakeClient(_ context.Context, location string) (v1.CloudClient, error) {
c.location = location
return c, nil
}