Skip to content

Commit

Permalink
Provide TUF keys as individual values in the secret
Browse files Browse the repository at this point in the history
  • Loading branch information
bkabrda committed Aug 9, 2024
1 parent 235bac9 commit 325070a
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions cmd/tuf/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,22 @@ func initTUFRepo(ctx context.Context, certsDir, targetDir, repoSecretName, keysS

// If we should also store created keys in a secret, compress the directory and put it into a secret
if keysSecretName != "" {
var compressedKeys bytes.Buffer
if err := repo.CompressFS(os.DirFS(dir), &compressedKeys, map[string]bool{"staged": true, "repository": true}); err != nil {
return fmt.Errorf("failed to compress the keys: %v", err)
keyFiles, err := os.ReadDir(filepath.Join(dir, "keys"))
if err != nil {
return fmt.Errorf("failed to list keys directory %v", err)
}
dataKeys := map[string][]byte{}
for _, keyFile := range keyFiles {
if !strings.HasSuffix(keyFile.Name(), ".json") {
continue
}
keyFilePath := filepath.Join(filepath.Join(dir, "keys", keyFile.Name()))
content, err := os.ReadFile(keyFilePath)
if err != nil {
return fmt.Errorf("failed reading file %s: %v", keyFilePath, err)
}
dataKeys[keyFile.Name()] = content
}
dataKeys := map[string][]byte{"keys": compressedKeys.Bytes()}
if err := secret.ReconcileSecret(ctx, keysSecretName, ns, dataKeys, nsSecret); err != nil {
return fmt.Errorf("failed to reconcile keys secret %s/%s: %v", ns, keysSecretName, err)
}
Expand Down

0 comments on commit 325070a

Please sign in to comment.