|
| 1 | +package v2 |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + v1 "github.com/brevdev/cloud/v1" |
| 7 | + sfc "github.com/sfcompute/sfc-go" |
| 8 | +) |
| 9 | + |
| 10 | +const CloudProviderID = "sfcompute" |
| 11 | + |
| 12 | +// SFCCredentialV2 holds authentication details for a Brev-managed SFCompute V2 account. |
| 13 | +type SFCCredentialV2 struct { |
| 14 | + RefID string |
| 15 | + APIKey string `json:"api_key"` |
| 16 | +} |
| 17 | + |
| 18 | +var _ v1.CloudCredential = &SFCCredentialV2{} |
| 19 | + |
| 20 | +func NewSFCCredentialV2(refID, apiKey string) *SFCCredentialV2 { |
| 21 | + return &SFCCredentialV2{ |
| 22 | + RefID: refID, |
| 23 | + APIKey: apiKey, |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +func (c *SFCCredentialV2) GetReferenceID() string { |
| 28 | + return c.RefID |
| 29 | +} |
| 30 | + |
| 31 | +func (c *SFCCredentialV2) GetAPIType() v1.APIType { |
| 32 | + return v1.APITypeGlobal |
| 33 | +} |
| 34 | + |
| 35 | +func (c *SFCCredentialV2) GetCloudProviderID() v1.CloudProviderID { |
| 36 | + return CloudProviderID |
| 37 | +} |
| 38 | + |
| 39 | +func (c *SFCCredentialV2) GetTenantID() (string, error) { |
| 40 | + return "", nil |
| 41 | +} |
| 42 | + |
| 43 | +type SFCClientV2 struct { |
| 44 | + v1.NotImplCloudClient |
| 45 | + refID string |
| 46 | + location string |
| 47 | + client *sfc.SDK |
| 48 | + logger v1.Logger |
| 49 | +} |
| 50 | + |
| 51 | +var _ v1.CloudClient = &SFCClientV2{} |
| 52 | + |
| 53 | +type SFCClientV2Option func(c *SFCClientV2) |
| 54 | + |
| 55 | +func WithLogger(logger v1.Logger) SFCClientV2Option { |
| 56 | + return func(c *SFCClientV2) { |
| 57 | + c.logger = logger |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +func (c *SFCCredentialV2) MakeClientWithOptions(_ context.Context, location string, opts ...SFCClientV2Option) (v1.CloudClient, error) { |
| 62 | + sfcClient := &SFCClientV2{ |
| 63 | + refID: c.RefID, |
| 64 | + location: location, |
| 65 | + client: sfc.New(sfc.WithSecurity(c.APIKey)), |
| 66 | + logger: &v1.NoopLogger{}, |
| 67 | + } |
| 68 | + |
| 69 | + for _, opt := range opts { |
| 70 | + opt(sfcClient) |
| 71 | + } |
| 72 | + |
| 73 | + return sfcClient, nil |
| 74 | +} |
| 75 | + |
| 76 | +func (c *SFCCredentialV2) MakeClient(ctx context.Context, location string) (v1.CloudClient, error) { |
| 77 | + return c.MakeClientWithOptions(ctx, location) |
| 78 | +} |
| 79 | + |
| 80 | +func (c *SFCClientV2) GetAPIType() v1.APIType { |
| 81 | + return v1.APITypeGlobal |
| 82 | +} |
| 83 | + |
| 84 | +func (c *SFCClientV2) GetCloudProviderID() v1.CloudProviderID { |
| 85 | + return CloudProviderID |
| 86 | +} |
| 87 | + |
| 88 | +func (c *SFCClientV2) GetReferenceID() string { |
| 89 | + return c.refID |
| 90 | +} |
| 91 | + |
| 92 | +func (c *SFCClientV2) GetTenantID() (string, error) { |
| 93 | + return "", nil |
| 94 | +} |
| 95 | + |
| 96 | +func (c *SFCClientV2) MakeClient(_ context.Context, location string) (v1.CloudClient, error) { |
| 97 | + c.location = location |
| 98 | + return c, nil |
| 99 | +} |
0 commit comments