| 16 | ) |
| 17 | |
| 18 | func New(organizationID uuid.UUID, name string, tags map[string]string) (database.InsertProvisionerKeyParams, string, error) { |
| 19 | secret, hashed, err := apikey.GenerateSecret(secretLength) |
| 20 | if err != nil { |
| 21 | return database.InsertProvisionerKeyParams{}, "", xerrors.Errorf("generate secret: %w", err) |
| 22 | } |
| 23 | |
| 24 | if tags == nil { |
| 25 | tags = map[string]string{} |
| 26 | } |
| 27 | |
| 28 | return database.InsertProvisionerKeyParams{ |
| 29 | ID: uuid.New(), |
| 30 | CreatedAt: dbtime.Now(), |
| 31 | OrganizationID: organizationID, |
| 32 | Name: name, |
| 33 | HashedSecret: hashed, |
| 34 | Tags: tags, |
| 35 | }, secret, nil |
| 36 | } |
| 37 | |
| 38 | func Validate(token string) error { |
| 39 | if len(token) != secretLength { |