IssueServiceAuthToken generates and persists a new auth token for a service.
(ctx context.Context, serviceID string, ttl *time.Duration)
| 94 | |
| 95 | // IssueServiceAuthToken generates and persists a new auth token for a service. |
| 96 | func (s *Service) IssueServiceAuthToken(ctx context.Context, serviceID string, ttl *time.Duration) (AuthToken, error) { |
| 97 | tkn := authtoken.NewRandom(authtoken.TypeService) |
| 98 | |
| 99 | var expiresOn *time.Time |
| 100 | if ttl != nil { |
| 101 | t := time.Now().Add(*ttl) |
| 102 | expiresOn = &t |
| 103 | } |
| 104 | |
| 105 | sat, err := s.DB.InsertServiceAuthToken(ctx, &database.InsertServiceAuthTokenOptions{ |
| 106 | ID: tkn.ID.String(), |
| 107 | SecretHash: tkn.SecretHash(), |
| 108 | ServiceID: serviceID, |
| 109 | ExpiresOn: expiresOn, |
| 110 | }) |
| 111 | if err != nil { |
| 112 | return nil, err |
| 113 | } |
| 114 | |
| 115 | return &serviceAuthToken{model: sat, token: tkn}, nil |
| 116 | } |
| 117 | |
| 118 | // deploymentAuthToken implements AuthToken for tokens belonging to a deployment. |
| 119 | type deploymentAuthToken struct { |
nothing calls this directly
no test coverage detected