IssueDeploymentAuthToken generates and persists a new auth token for a deployment.
(ctx context.Context, deploymentID string, ttl *time.Duration)
| 135 | |
| 136 | // IssueDeploymentAuthToken generates and persists a new auth token for a deployment. |
| 137 | func (s *Service) IssueDeploymentAuthToken(ctx context.Context, deploymentID string, ttl *time.Duration) (AuthToken, error) { |
| 138 | tkn := authtoken.NewRandom(authtoken.TypeDeployment) |
| 139 | |
| 140 | var expiresOn *time.Time |
| 141 | if ttl != nil { |
| 142 | t := time.Now().Add(*ttl) |
| 143 | expiresOn = &t |
| 144 | } |
| 145 | |
| 146 | dat, err := s.DB.InsertDeploymentAuthToken(ctx, &database.InsertDeploymentAuthTokenOptions{ |
| 147 | ID: tkn.ID.String(), |
| 148 | SecretHash: tkn.SecretHash(), |
| 149 | DeploymentID: deploymentID, |
| 150 | ExpiresOn: expiresOn, |
| 151 | }) |
| 152 | if err != nil { |
| 153 | return nil, err |
| 154 | } |
| 155 | |
| 156 | return &deploymentAuthToken{model: dat, token: tkn}, nil |
| 157 | } |
| 158 | |
| 159 | // magicAuthToken implements AuthToken for magic tokens belonging to a project. |
| 160 | type magicAuthToken struct { |
no test coverage detected