mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
chore: add provisioner key crud apis (#13857)
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package provisionerkey
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/coder/coder/v2/coderd/database"
|
||||
"github.com/coder/coder/v2/coderd/database/dbtime"
|
||||
"github.com/coder/coder/v2/cryptorand"
|
||||
)
|
||||
|
||||
func New(organizationID uuid.UUID, name string) (database.InsertProvisionerKeyParams, string, error) {
|
||||
id := uuid.New()
|
||||
secret, err := cryptorand.HexString(64)
|
||||
if err != nil {
|
||||
return database.InsertProvisionerKeyParams{}, "", xerrors.Errorf("generate token: %w", err)
|
||||
}
|
||||
hashedSecret := sha256.Sum256([]byte(secret))
|
||||
token := fmt.Sprintf("%s:%s", id, secret)
|
||||
|
||||
return database.InsertProvisionerKeyParams{
|
||||
ID: id,
|
||||
CreatedAt: dbtime.Now(),
|
||||
OrganizationID: organizationID,
|
||||
Name: name,
|
||||
HashedSecret: hashedSecret[:],
|
||||
}, token, nil
|
||||
}
|
||||
Reference in New Issue
Block a user