Skip to content

Commit

Permalink
Add support for provider specific keys
Browse files Browse the repository at this point in the history
We now scan both ./keys/n/namespace/ and ./keys/n/namespace/provider/.
This allows users to provide both organization level keys and provider
specific keys.

Signed-off-by: Christian Mesh <[email protected]>
  • Loading branch information
cam72cam committed Oct 1, 2024
1 parent 21fa2de commit bd7982e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
28 changes: 22 additions & 6 deletions src/internal/gpg/keycollection.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,39 @@ import (
"strings"
)

// KeyCollection represents the GPG keys stored in the registry for a specific namespace.
// KeyCollection represents the GPG keys stored in the registry for a specific namespace and provider.
type KeyCollection struct {
Namespace string // The key namespace
Directory string // The root directory that the key lives in
Namespace string // The key namespace
ProviderName string // The key provider name
Directory string // The root directory that the key lives in
}

func (k KeyCollection) MetadataPath() string {
func (k KeyCollection) NamespacePath() string {
firstChar := strings.ToLower(k.Namespace[0:1])
return filepath.Join(k.Directory, firstChar, k.Namespace)
}

func (k KeyCollection) ListKeys() ([]Key, error) {
location := strings.ToLower(k.MetadataPath())
func (k KeyCollection) ProviderPath() string {
return filepath.Join(k.NamespacePath(), k.ProviderName)
}

func (k KeyCollection) ListKeys() ([]Key, error) {
namespaceKeys, namespaceErr := k.listKeysIn(k.NamespacePath())
if namespaceErr != nil {
return nil, namespaceErr
}
providerKeys, providerErr := k.listKeysIn(k.ProviderPath())
if providerErr != nil {
return nil, providerErr
}
return append(namespaceKeys, providerKeys...), nil
}
func (k KeyCollection) listKeysIn(location string) ([]Key, error) {
// check if the directory exists
if _, err := os.Stat(location); os.IsNotExist(err) {
return nil, nil
} else if err != nil {
return nil, err
}

// if it does exist, iterate across the files
Expand Down
5 changes: 3 additions & 2 deletions src/internal/v1api/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ func (p ProviderGenerator) VersionDetails() (map[string]ProviderVersionDetails,
versionDetails := make(map[string]ProviderVersionDetails)

keyCollection := gpg.KeyCollection{
Namespace: p.Provider.EffectiveNamespace(),
Directory: p.KeyLocation,
Namespace: p.Provider.EffectiveNamespace(),
ProviderName: p.Provider.ProviderName,
Directory: p.KeyLocation,
}

keys, err := keyCollection.ListKeys()
Expand Down

0 comments on commit bd7982e

Please sign in to comment.