2021-06-22 22:26:26 -04:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-01-11 09:08:22 -08:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-02-02 17:15:17 -08:00
|
|
|
|
2021-06-22 22:26:26 -04:00
|
|
|
package vault
|
|
|
|
|
|
|
|
|
|
import (
|
2023-06-06 17:09:08 -04:00
|
|
|
"context"
|
|
|
|
|
|
2023-03-10 15:06:39 -05:00
|
|
|
"github.com/hashicorp/boundary/globals"
|
2021-06-22 22:26:26 -04:00
|
|
|
"github.com/hashicorp/boundary/internal/credential"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/db"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/errors"
|
2023-11-15 19:55:46 -05:00
|
|
|
"github.com/hashicorp/boundary/internal/types/resource"
|
2021-06-22 22:26:26 -04:00
|
|
|
)
|
|
|
|
|
|
2021-07-27 09:59:52 -07:00
|
|
|
func init() {
|
2023-11-15 19:55:46 -05:00
|
|
|
globals.RegisterPrefixToResourceInfo(globals.VaultCredentialStorePrefix, resource.CredentialStore, credential.Domain, Subtype)
|
|
|
|
|
globals.RegisterPrefixToResourceInfo(globals.VaultDynamicCredentialPrefix, resource.Credential, credential.Domain, Subtype)
|
|
|
|
|
globals.RegisterPrefixToResourceInfo(globals.VaultCredentialLibraryPrefix, resource.CredentialLibrary, credential.Domain, GenericLibrarySubtype)
|
|
|
|
|
globals.RegisterPrefixToResourceInfo(globals.VaultSshCertificateCredentialLibraryPrefix, resource.CredentialLibrary, credential.Domain, SSHCertificateLibrarySubtype)
|
2021-07-27 09:59:52 -07:00
|
|
|
}
|
|
|
|
|
|
2023-11-02 16:03:47 -04:00
|
|
|
// PublicId prefixes for the resources in the vault package.
|
|
|
|
|
const (
|
2023-11-15 19:55:46 -05:00
|
|
|
Subtype = globals.Subtype("vault")
|
|
|
|
|
GenericLibrarySubtype = globals.Subtype("vault-generic")
|
|
|
|
|
SSHCertificateLibrarySubtype = globals.Subtype("vault-ssh-certificate")
|
2023-11-02 16:03:47 -04:00
|
|
|
)
|
|
|
|
|
|
2023-06-06 17:09:08 -04:00
|
|
|
func newCredentialStoreId(ctx context.Context) (string, error) {
|
|
|
|
|
id, err := db.NewPublicId(ctx, globals.VaultCredentialStorePrefix)
|
2021-06-22 22:26:26 -04:00
|
|
|
if err != nil {
|
2023-06-06 17:09:08 -04:00
|
|
|
return "", errors.Wrap(ctx, err, "vault.newCredentialStoreId")
|
2021-06-22 22:26:26 -04:00
|
|
|
}
|
|
|
|
|
return id, nil
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-06 17:09:08 -04:00
|
|
|
func newCredentialId(ctx context.Context) (string, error) {
|
2023-10-18 14:48:44 -07:00
|
|
|
id, err := db.NewPublicId(ctx, globals.VaultDynamicCredentialPrefix)
|
2021-06-22 22:26:26 -04:00
|
|
|
if err != nil {
|
2023-06-06 17:09:08 -04:00
|
|
|
return "", errors.Wrap(ctx, err, "vault.newCredentialId")
|
2021-06-22 22:26:26 -04:00
|
|
|
}
|
|
|
|
|
return id, nil
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-06 17:09:08 -04:00
|
|
|
func newCredentialLibraryId(ctx context.Context) (string, error) {
|
|
|
|
|
id, err := db.NewPublicId(ctx, globals.VaultCredentialLibraryPrefix)
|
2021-06-22 22:26:26 -04:00
|
|
|
if err != nil {
|
2023-06-06 17:09:08 -04:00
|
|
|
return "", errors.Wrap(ctx, err, "vault.newCredentialLibraryId")
|
2021-06-22 22:26:26 -04:00
|
|
|
}
|
|
|
|
|
return id, nil
|
|
|
|
|
}
|
2023-01-11 09:08:22 -08:00
|
|
|
|
2023-06-06 17:09:08 -04:00
|
|
|
func newSSHCertificateCredentialLibraryId(ctx context.Context) (string, error) {
|
|
|
|
|
id, err := db.NewPublicId(ctx, globals.VaultSshCertificateCredentialLibraryPrefix)
|
2023-01-11 09:08:22 -08:00
|
|
|
if err != nil {
|
2023-06-06 17:09:08 -04:00
|
|
|
return "", errors.Wrap(ctx, err, "vault.newSSHCertificateCredentialLibraryPrefix")
|
2023-01-11 09:08:22 -08:00
|
|
|
}
|
|
|
|
|
return id, nil
|
|
|
|
|
}
|