IssueMagicAuthToken generates and persists a new magic auth token for a project.
(ctx context.Context, opts *IssueMagicAuthTokenOptions)
| 190 | |
| 191 | // IssueMagicAuthToken generates and persists a new magic auth token for a project. |
| 192 | func (s *Service) IssueMagicAuthToken(ctx context.Context, opts *IssueMagicAuthTokenOptions) (AuthToken, error) { |
| 193 | for mv := range opts.MetricsViewFilterJSONs { |
| 194 | if mv == "" { |
| 195 | return nil, fmt.Errorf("metrics view name cannot be empty in MetricsViewFilterJSONs") |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | tkn := authtoken.NewRandom(authtoken.TypeMagic) |
| 200 | |
| 201 | var expiresOn *time.Time |
| 202 | if opts.TTL != nil { |
| 203 | t := time.Now().Add(*opts.TTL) |
| 204 | expiresOn = &t |
| 205 | } |
| 206 | |
| 207 | dat, err := s.DB.InsertMagicAuthToken(ctx, &database.InsertMagicAuthTokenOptions{ |
| 208 | ID: tkn.ID.String(), |
| 209 | SecretHash: tkn.SecretHash(), |
| 210 | Secret: tkn.Secret[:], |
| 211 | ProjectID: opts.ProjectID, |
| 212 | ExpiresOn: expiresOn, |
| 213 | CreatedByUserID: opts.CreatedByUserID, |
| 214 | Attributes: opts.Attributes, |
| 215 | MetricsViewFilterJSONs: opts.MetricsViewFilterJSONs, |
| 216 | Fields: opts.Fields, |
| 217 | State: opts.State, |
| 218 | DisplayName: opts.DisplayName, |
| 219 | Internal: opts.Internal, |
| 220 | Resources: opts.Resources, |
| 221 | }) |
| 222 | if err != nil { |
| 223 | return nil, err |
| 224 | } |
| 225 | |
| 226 | return &magicAuthToken{model: dat, token: tkn}, nil |
| 227 | } |
| 228 | |
| 229 | // ExtendBrowserSessionAuthToken extends a Rill web browser session token when its |
| 230 | // remaining lifetime is at or below refreshThreshold. |
nothing calls this directly
no test coverage detected