Skip to content

Commit d5451ae

Browse files
authored
Merge pull request #23 from brevdev/devin/1754781803-separate-lambdalabs-credentials
Separate Lambda Labs credential logic into credential.go
2 parents 9a4b188 + 37a0788 commit d5451ae

File tree

3 files changed

+56
-49
lines changed

3 files changed

+56
-49
lines changed

internal/lambdalabs/v1/client.go

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package v1
22

33
import (
44
"context"
5-
"crypto/sha256"
6-
"fmt"
75
"net/http"
86
"time"
97

@@ -12,51 +10,6 @@ import (
1210
"github.com/cenkalti/backoff/v4"
1311
)
1412

15-
// LambdaLabsCredential implements the CloudCredential interface for Lambda Labs
16-
type LambdaLabsCredential struct {
17-
RefID string
18-
APIKey string
19-
}
20-
21-
var _ v1.CloudCredential = &LambdaLabsCredential{}
22-
23-
// NewLambdaLabsCredential creates a new Lambda Labs credential
24-
func NewLambdaLabsCredential(refID, apiKey string) *LambdaLabsCredential {
25-
return &LambdaLabsCredential{
26-
RefID: refID,
27-
APIKey: apiKey,
28-
}
29-
}
30-
31-
// GetReferenceID returns the reference ID for this credential
32-
func (c *LambdaLabsCredential) GetReferenceID() string {
33-
return c.RefID
34-
}
35-
36-
// GetAPIType returns the API type for Lambda Labs
37-
func (c *LambdaLabsCredential) GetAPIType() v1.APIType {
38-
return v1.APITypeGlobal
39-
}
40-
41-
const CloudProviderID = "lambda-labs"
42-
43-
const DefaultRegion string = "us-west-1"
44-
45-
// GetCloudProviderID returns the cloud provider ID for Lambda Labs
46-
func (c *LambdaLabsCredential) GetCloudProviderID() v1.CloudProviderID {
47-
return CloudProviderID
48-
}
49-
50-
// GetTenantID returns the tenant ID for Lambda Labs
51-
func (c *LambdaLabsCredential) GetTenantID() (string, error) {
52-
return fmt.Sprintf("lambdalabs-%x", sha256.Sum256([]byte(c.APIKey))), nil
53-
}
54-
55-
// MakeClient creates a new Lambda Labs client from this credential
56-
func (c *LambdaLabsCredential) MakeClient(_ context.Context, _ string) (v1.CloudClient, error) {
57-
return NewLambdaLabsClient(c.RefID, c.APIKey), nil
58-
}
59-
6013
// LambdaLabsClient implements the CloudClient interface for Lambda Labs
6114
// It embeds NotImplCloudClient to handle unsupported features
6215
type LambdaLabsClient struct {
@@ -91,7 +44,7 @@ func (c *LambdaLabsClient) GetAPIType() v1.APIType {
9144

9245
// GetCloudProviderID returns the cloud provider ID for Lambda Labs
9346
func (c *LambdaLabsClient) GetCloudProviderID() v1.CloudProviderID {
94-
return "lambdalabs"
47+
return CloudProviderID
9548
}
9649

9750
// MakeClient creates a new client instance

internal/lambdalabs/v1/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestLambdaLabsClient_GetAPIType(t *testing.T) {
1818

1919
func TestLambdaLabsClient_GetCloudProviderID(t *testing.T) {
2020
client := &LambdaLabsClient{}
21-
assert.Equal(t, v1.CloudProviderID("lambdalabs"), client.GetCloudProviderID())
21+
assert.Equal(t, v1.CloudProviderID(CloudProviderID), client.GetCloudProviderID())
2222
}
2323

2424
func TestLambdaLabsClient_MakeClient(t *testing.T) {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package v1
2+
3+
import (
4+
"context"
5+
"crypto/sha256"
6+
"fmt"
7+
8+
v1 "github.com/brevdev/cloud/pkg/v1"
9+
)
10+
11+
const CloudProviderID = "lambda-labs"
12+
13+
const DefaultRegion string = "us-west-1"
14+
15+
// LambdaLabsCredential implements the CloudCredential interface for Lambda Labs
16+
type LambdaLabsCredential struct {
17+
RefID string
18+
APIKey string
19+
}
20+
21+
var _ v1.CloudCredential = &LambdaLabsCredential{}
22+
23+
// NewLambdaLabsCredential creates a new Lambda Labs credential
24+
func NewLambdaLabsCredential(refID, apiKey string) *LambdaLabsCredential {
25+
return &LambdaLabsCredential{
26+
RefID: refID,
27+
APIKey: apiKey,
28+
}
29+
}
30+
31+
// GetReferenceID returns the reference ID for this credential
32+
func (c *LambdaLabsCredential) GetReferenceID() string {
33+
return c.RefID
34+
}
35+
36+
// GetAPIType returns the API type for Lambda Labs
37+
func (c *LambdaLabsCredential) GetAPIType() v1.APIType {
38+
return v1.APITypeGlobal
39+
}
40+
41+
// GetCloudProviderID returns the cloud provider ID for Lambda Labs
42+
func (c *LambdaLabsCredential) GetCloudProviderID() v1.CloudProviderID {
43+
return CloudProviderID
44+
}
45+
46+
// GetTenantID returns the tenant ID for Lambda Labs
47+
func (c *LambdaLabsCredential) GetTenantID() (string, error) {
48+
return fmt.Sprintf("lambdalabs-%x", sha256.Sum256([]byte(c.APIKey))), nil
49+
}
50+
51+
// MakeClient creates a new Lambda Labs client from this credential
52+
func (c *LambdaLabsCredential) MakeClient(_ context.Context, _ string) (v1.CloudClient, error) {
53+
return NewLambdaLabsClient(c.RefID, c.APIKey), nil
54+
}

0 commit comments

Comments
 (0)