(ctx context.Context, opts *database.InsertMagicAuthTokenOptions)
| 1636 | } |
| 1637 | |
| 1638 | func (c *connection) InsertMagicAuthToken(ctx context.Context, opts *database.InsertMagicAuthTokenOptions) (*database.MagicAuthToken, error) { |
| 1639 | if err := database.Validate(opts); err != nil { |
| 1640 | return nil, err |
| 1641 | } |
| 1642 | |
| 1643 | if opts.Fields == nil { |
| 1644 | opts.Fields = []string{} |
| 1645 | } |
| 1646 | |
| 1647 | encSecret, encKeyID, err := c.encrypt(opts.Secret) |
| 1648 | if err != nil { |
| 1649 | return nil, err |
| 1650 | } |
| 1651 | |
| 1652 | resources, err := marshalResourceNames(opts.Resources) |
| 1653 | if err != nil { |
| 1654 | return nil, err |
| 1655 | } |
| 1656 | |
| 1657 | if opts.MetricsViewFilterJSONs == nil { |
| 1658 | opts.MetricsViewFilterJSONs = make(map[string]string) |
| 1659 | } |
| 1660 | |
| 1661 | res := &magicAuthTokenDTO{} |
| 1662 | err = c.getDB(ctx).QueryRowxContext(ctx, ` |
| 1663 | INSERT INTO magic_auth_tokens (id, secret_hash, secret, secret_encryption_key_id, project_id, expires_on, created_by_user_id, attributes, metrics_view_filter_jsons, fields, state, display_name, internal, resources) |
| 1664 | VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) RETURNING *`, |
| 1665 | opts.ID, opts.SecretHash, encSecret, encKeyID, opts.ProjectID, opts.ExpiresOn, opts.CreatedByUserID, opts.Attributes, opts.MetricsViewFilterJSONs, opts.Fields, opts.State, opts.DisplayName, opts.Internal, resources, |
| 1666 | ).StructScan(res) |
| 1667 | if err != nil { |
| 1668 | return nil, parseErr("magic auth token", err) |
| 1669 | } |
| 1670 | return c.magicAuthTokenFromDTO(res, true) |
| 1671 | } |
| 1672 | |
| 1673 | func (c *connection) UpdateMagicAuthTokenUsedOn(ctx context.Context, ids []string) error { |
| 1674 | _, err := c.getDB(ctx).ExecContext(ctx, "UPDATE magic_auth_tokens SET used_on=now() WHERE id=ANY($1)", ids) |
nothing calls this directly
no test coverage detected