2022-07-18 19:16:11 -04:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-02-02 17:15:17 -08:00
|
|
|
|
2022-07-18 19:16:11 -04:00
|
|
|
package credential
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
2023-03-10 15:06:39 -05:00
|
|
|
"github.com/hashicorp/boundary/globals"
|
2022-07-18 19:16:11 -04:00
|
|
|
"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"
|
2022-07-18 19:16:11 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func init() {
|
2023-11-15 19:55:46 -05:00
|
|
|
globals.RegisterPrefixToResourceInfo(globals.UsernamePasswordCredentialPrefix, resource.Credential, Domain, UsernamePasswordSubtype)
|
|
|
|
|
globals.RegisterPrefixToResourceInfo(globals.UsernamePasswordCredentialPreviousPrefix, resource.Credential, Domain, UsernamePasswordSubtype)
|
|
|
|
|
globals.RegisterPrefixToResourceInfo(globals.SshPrivateKeyCredentialPrefix, resource.Credential, Domain, SshPrivateKeySubtype)
|
|
|
|
|
globals.RegisterPrefixToResourceInfo(globals.JsonCredentialPrefix, resource.Credential, Domain, JsonSubtype)
|
2022-07-18 19:16:11 -04:00
|
|
|
}
|
|
|
|
|
|
2023-11-02 16:03:47 -04:00
|
|
|
const (
|
2023-11-15 19:55:46 -05:00
|
|
|
UsernamePasswordSubtype = globals.Subtype("username_password")
|
2023-11-02 16:03:47 -04:00
|
|
|
|
2023-11-15 19:55:46 -05:00
|
|
|
SshPrivateKeySubtype = globals.Subtype("ssh_private_key")
|
2023-11-02 16:03:47 -04:00
|
|
|
|
2023-11-15 19:55:46 -05:00
|
|
|
JsonSubtype = globals.Subtype("json")
|
2023-11-02 16:03:47 -04:00
|
|
|
)
|
|
|
|
|
|
2022-07-18 19:16:11 -04:00
|
|
|
func NewUsernamePasswordCredentialId(ctx context.Context) (string, error) {
|
2023-06-06 17:09:08 -04:00
|
|
|
id, err := db.NewPublicId(ctx, globals.UsernamePasswordCredentialPrefix)
|
2022-07-18 19:16:11 -04:00
|
|
|
if err != nil {
|
|
|
|
|
return "", errors.Wrap(ctx, err, "credential.NewUsernamePasswordCredentialId")
|
|
|
|
|
}
|
|
|
|
|
return id, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewSshPrivateKeyCredentialId(ctx context.Context) (string, error) {
|
2023-06-06 17:09:08 -04:00
|
|
|
id, err := db.NewPublicId(ctx, globals.SshPrivateKeyCredentialPrefix)
|
2022-07-18 19:16:11 -04:00
|
|
|
if err != nil {
|
|
|
|
|
return "", errors.Wrap(ctx, err, "credential.NewSshPrivateKeyCredentialId")
|
|
|
|
|
}
|
|
|
|
|
return id, nil
|
|
|
|
|
}
|
2022-09-16 15:00:04 -07:00
|
|
|
|
|
|
|
|
func NewJsonCredentialId(ctx context.Context) (string, error) {
|
2023-06-06 17:09:08 -04:00
|
|
|
id, err := db.NewPublicId(ctx, globals.JsonCredentialPrefix)
|
2022-09-16 15:00:04 -07:00
|
|
|
if err != nil {
|
|
|
|
|
return "", errors.Wrap(ctx, err, "credential.NewJsonCredentialId")
|
|
|
|
|
}
|
|
|
|
|
return id, nil
|
|
|
|
|
}
|