Skip to content

Commit

Permalink
using metadata api directly
Browse files Browse the repository at this point in the history
Signed-off-by: Diogenes Fernandes <[email protected]>
  • Loading branch information
diofeher committed Jan 10, 2025
1 parent e9f0f36 commit ed6662e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
13 changes: 10 additions & 3 deletions src/cmd/verify-gpg-key/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/ProtonMail/gopenpgp/v2/crypto"

"github.com/opentofu/libregistry/metadata"
"github.com/opentofu/libregistry/metadata/storage/filesystem"
"github.com/opentofu/registry-stable/internal/files"
"github.com/opentofu/registry-stable/internal/github"
Expand Down Expand Up @@ -171,16 +172,22 @@ func VerifyKey(ctx context.Context, providerDataDir string, location string, org
return nil
})

storageAPI := filesystem.New(providerDataDir)
providers, err := listProviders(ctx, storageAPI, orgName)
dataAPI, err := metadata.New(filesystem.New(providerDataDir))
if err != nil {
verifyStep.AddError(fmt.Errorf("failed to create a metadata API: %w", err))
verifyStep.Status = verification.StatusFailure
return verifyStep
}

providers, err := listProviders(ctx, dataAPI, orgName)

if err != nil {
verifyStep.AddError(fmt.Errorf("failed to list provider %s: %w", orgName, err))
verifyStep.Status = verification.StatusFailure
return verifyStep
}

keyVerification, err := buildKeyVerifier(storageAPI)
keyVerification, err := buildKeyVerifier(dataAPI)
if err != nil {
verifyStep.AddError(fmt.Errorf("failed to build key verifier: %w", err))
verifyStep.Status = verification.StatusFailure
Expand Down
12 changes: 3 additions & 9 deletions src/cmd/verify-gpg-key/verify-key-in-providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,23 @@ import (
"time"

"github.com/opentofu/libregistry/metadata"
"github.com/opentofu/libregistry/metadata/storage"
"github.com/opentofu/libregistry/provider_verifier"
"github.com/opentofu/libregistry/types/provider"
)

func buildKeyVerifier(storageAPI storage.API) (provider_verifier.KeyVerification, error) {
func buildKeyVerifier(dataAPI metadata.API) (provider_verifier.KeyVerification, error) {
httpClient := http.Client{
Timeout: time.Second * 10,
}

keyVerification, err := provider_verifier.New(httpClient, storageAPI)
keyVerification, err := provider_verifier.New(httpClient, dataAPI)
if err != nil {
return nil, err
}
return keyVerification, nil
}

func listProviders(ctx context.Context, storageAPI storage.API, namespace string) ([]provider.Addr, error) {
dataAPI, err := metadata.New(storageAPI)
if err != nil {
return nil, err
}

func listProviders(ctx context.Context, dataAPI metadata.API, namespace string) ([]provider.Addr, error) {
providers, err := dataAPI.ListProvidersByNamespace(ctx, namespace, false)
if err != nil {
return nil, err
Expand Down

0 comments on commit ed6662e

Please sign in to comment.