Skip to content
17 changes: 13 additions & 4 deletions cmd/bcloud/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import (

var providerRegistry = map[string]func() v1.CloudCredential{}

var providerIDToRegistryKey = map[string]string{
"lambda-labs": "lambdalabs",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these should be the same (provider id and registry key) strings lets refactor

"nebius": "nebius",
}

func RegisterProvider(id string, factory func() v1.CloudCredential) {
providerRegistry[id] = factory
}
Expand Down Expand Up @@ -67,14 +72,18 @@ func (c *CredentialEntry) decodeFromMap(m map[string]any, yamlKey string) error
if !ok || provider == "" {
return fmt.Errorf("invalid 'provider'")
}
factory, ok := providerRegistry[provider]
registryKey := provider
if mappedKey, exists := providerIDToRegistryKey[provider]; exists {
registryKey = mappedKey
}
factory, ok := providerRegistry[registryKey]
if !ok {
return fmt.Errorf("unknown provider: %s", provider)
}
cred := factory()

if _, hasRefID := m["ref_id"]; !hasRefID {
m["ref_id"] = yamlKey
if _, hasRefID := m["RefID"]; !hasRefID {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets go in to the provider credential and use tags to change them to ref_id api_key etc.

m["RefID"] = yamlKey
}

b, err := json.Marshal(m)
Expand All @@ -85,7 +94,7 @@ func (c *CredentialEntry) decodeFromMap(m map[string]any, yamlKey string) error
return err
}

c.Provider = provider
c.Provider = registryKey
c.Value = cred
return nil
}
Expand Down
Loading