Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 1 addition & 48 deletions internal/lambdalabs/v1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package v1

import (
"context"
"crypto/sha256"
"fmt"
"net/http"
"time"

Expand All @@ -12,51 +10,6 @@ import (
"github.com/cenkalti/backoff/v4"
)

// LambdaLabsCredential implements the CloudCredential interface for Lambda Labs
type LambdaLabsCredential struct {
RefID string
APIKey string
}

var _ v1.CloudCredential = &LambdaLabsCredential{}

// NewLambdaLabsCredential creates a new Lambda Labs credential
func NewLambdaLabsCredential(refID, apiKey string) *LambdaLabsCredential {
return &LambdaLabsCredential{
RefID: refID,
APIKey: apiKey,
}
}

// GetReferenceID returns the reference ID for this credential
func (c *LambdaLabsCredential) GetReferenceID() string {
return c.RefID
}

// GetAPIType returns the API type for Lambda Labs
func (c *LambdaLabsCredential) GetAPIType() v1.APIType {
return v1.APITypeGlobal
}

const CloudProviderID = "lambda-labs"

const DefaultRegion string = "us-west-1"

// GetCloudProviderID returns the cloud provider ID for Lambda Labs
func (c *LambdaLabsCredential) GetCloudProviderID() v1.CloudProviderID {
return CloudProviderID
}

// GetTenantID returns the tenant ID for Lambda Labs
func (c *LambdaLabsCredential) GetTenantID() (string, error) {
return fmt.Sprintf("lambdalabs-%x", sha256.Sum256([]byte(c.APIKey))), nil
}

// MakeClient creates a new Lambda Labs client from this credential
func (c *LambdaLabsCredential) MakeClient(_ context.Context, _ string) (v1.CloudClient, error) {
return NewLambdaLabsClient(c.RefID, c.APIKey), nil
}

// LambdaLabsClient implements the CloudClient interface for Lambda Labs
// It embeds NotImplCloudClient to handle unsupported features
type LambdaLabsClient struct {
Expand Down Expand Up @@ -91,7 +44,7 @@ func (c *LambdaLabsClient) GetAPIType() v1.APIType {

// GetCloudProviderID returns the cloud provider ID for Lambda Labs
func (c *LambdaLabsClient) GetCloudProviderID() v1.CloudProviderID {
return "lambdalabs"
return CloudProviderID
}

// MakeClient creates a new client instance
Expand Down
2 changes: 1 addition & 1 deletion internal/lambdalabs/v1/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestLambdaLabsClient_GetAPIType(t *testing.T) {

func TestLambdaLabsClient_GetCloudProviderID(t *testing.T) {
client := &LambdaLabsClient{}
assert.Equal(t, v1.CloudProviderID("lambdalabs"), client.GetCloudProviderID())
assert.Equal(t, v1.CloudProviderID(CloudProviderID), client.GetCloudProviderID())
}

func TestLambdaLabsClient_MakeClient(t *testing.T) {
Expand Down
54 changes: 54 additions & 0 deletions internal/lambdalabs/v1/credential.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package v1

import (
"context"
"crypto/sha256"
"fmt"

v1 "github.com/brevdev/cloud/pkg/v1"
)

const CloudProviderID = "lambda-labs"

const DefaultRegion string = "us-west-1"

// LambdaLabsCredential implements the CloudCredential interface for Lambda Labs
type LambdaLabsCredential struct {
RefID string
APIKey string
}

var _ v1.CloudCredential = &LambdaLabsCredential{}

// NewLambdaLabsCredential creates a new Lambda Labs credential
func NewLambdaLabsCredential(refID, apiKey string) *LambdaLabsCredential {
return &LambdaLabsCredential{
RefID: refID,
APIKey: apiKey,
}
}

// GetReferenceID returns the reference ID for this credential
func (c *LambdaLabsCredential) GetReferenceID() string {
return c.RefID
}

// GetAPIType returns the API type for Lambda Labs
func (c *LambdaLabsCredential) GetAPIType() v1.APIType {
return v1.APITypeGlobal
}

// GetCloudProviderID returns the cloud provider ID for Lambda Labs
func (c *LambdaLabsCredential) GetCloudProviderID() v1.CloudProviderID {
return CloudProviderID
}

// GetTenantID returns the tenant ID for Lambda Labs
func (c *LambdaLabsCredential) GetTenantID() (string, error) {
return fmt.Sprintf("lambdalabs-%x", sha256.Sum256([]byte(c.APIKey))), nil
}

// MakeClient creates a new Lambda Labs client from this credential
func (c *LambdaLabsCredential) MakeClient(_ context.Context, _ string) (v1.CloudClient, error) {
return NewLambdaLabsClient(c.RefID, c.APIKey), nil
}
Loading