MCPcopy Index your code
hub / github.com/NdoleStudio/httpsms / RotateAPIKey

Method RotateAPIKey

api/pkg/services/user_service.go:256–287  ·  view source on GitHub ↗

RotateAPIKey for an entities.User

(ctx context.Context, source string, userID entities.UserID)

Source from the content-addressed store, hash-verified

254
255// RotateAPIKey for an entities.User
256func (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
290func (service *UserService) Delete(ctx context.Context, source string, userID entities.UserID) error {

Callers

nothing calls this directly

Calls 7

createEventMethod · 0.80
StartWithLoggerMethod · 0.65
RotateAPIKeyMethod · 0.65
WrapErrorSpanMethod · 0.65
InfoMethod · 0.65
ErrorMethod · 0.65
DispatchMethod · 0.45

Tested by

no test coverage detected