RotateAPIKey for an entities.User
(ctx context.Context, source string, userID entities.UserID)
| 254 | |
| 255 | // RotateAPIKey for an entities.User |
| 256 | func (service *UserService) RotateAPIKey(ctx context.Context, source string, userID entities.UserID) (*entities.User, error) { |
| 257 | ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger) |
| 258 | defer span.End() |
| 259 | |
| 260 | user, err := service.repository.RotateAPIKey(ctx, userID) |
| 261 | if err != nil { |
| 262 | msg := fmt.Sprintf("could not rotate API key for [%T] with ID [%s]", user, userID) |
| 263 | return nil, service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) |
| 264 | } |
| 265 | |
| 266 | ctxLogger.Info(fmt.Sprintf("rotated the api key for [%T] with ID [%s] in the [%T]", user, user.ID, service.repository)) |
| 267 | |
| 268 | event, err := service.createEvent(events.UserAPIKeyRotated, source, &events.UserAPIKeyRotatedPayload{ |
| 269 | UserID: user.ID, |
| 270 | Email: user.Email, |
| 271 | Timestamp: time.Now().UTC(), |
| 272 | Timezone: user.Timezone, |
| 273 | }) |
| 274 | if err != nil { |
| 275 | msg := fmt.Sprintf("cannot create event [%s] for user [%s]", events.UserAPIKeyRotated, user.ID) |
| 276 | ctxLogger.Error(stacktrace.Propagate(err, msg)) |
| 277 | return user, nil |
| 278 | } |
| 279 | |
| 280 | if err = service.dispatcher.Dispatch(ctx, event); err != nil { |
| 281 | msg := fmt.Sprintf("cannot dispatch [%s] event for user [%s]", event.Type(), user.ID) |
| 282 | ctxLogger.Error(stacktrace.Propagate(err, msg)) |
| 283 | return user, nil |
| 284 | } |
| 285 | |
| 286 | return user, nil |
| 287 | } |
| 288 | |
| 289 | // Delete an entities.User |
| 290 | func (service *UserService) Delete(ctx context.Context, source string, userID entities.UserID) error { |
nothing calls this directly
no test coverage detected