mirror of
https://github.com/harness/drone.git
synced 2025-05-05 05:51:56 +08:00

This change adds the initial stepping stones for harness integration: - Authentication: JWT/PAT/SAT support - Authorization: ACL integration (acl currently denies requests as gitness hasn't been integrated yet) - Remote Clients for Token, User, ServiceAccount, ACL - User Integration: Syncs harness users during authentication if unknown - SA integration: syncs harness service accounts during authentication if unknown - Initial harness API: THIS WILL BE CHANGED IN THE FUTURE! - single harness subpackage (all marked with harness build flag) - harness & standalone wire + make build commands
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
// Copyright 2021 Harness Inc. All rights reserved.
|
|
// Use of this source code is governed by the Polyform Free Trial License
|
|
// that can be found in the LICENSE.md file for this repository.
|
|
|
|
package users
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/harness/gitness/internal/api/render"
|
|
"github.com/harness/gitness/internal/api/request"
|
|
"github.com/harness/gitness/internal/store"
|
|
"github.com/rs/zerolog/hlog"
|
|
)
|
|
|
|
// HandleDelete returns an http.HandlerFunc that processes an http.Request
|
|
// to delete the named user account from the system.
|
|
func HandleDelete(userStore store.UserStore, tokenStore store.TokenStore) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
log := hlog.FromRequest(r)
|
|
user, _ := request.UserFrom(ctx)
|
|
|
|
// delete all tokens (okay if we fail after - user is tried to being deleted anyway)
|
|
err := tokenStore.DeleteForPrincipal(ctx, user.ID)
|
|
if err != nil {
|
|
log.Error().Err(err).Msg("Failed to delete tokens for user.")
|
|
|
|
render.UserfiedErrorOrInternal(w, err)
|
|
return
|
|
}
|
|
|
|
err = userStore.Delete(ctx, user.ID)
|
|
if err != nil {
|
|
log.Error().Err(err).
|
|
Str("user_uid", user.UID).
|
|
Msg("failed to delete user")
|
|
|
|
render.UserfiedErrorOrInternal(w, err)
|
|
return
|
|
}
|
|
|
|
w.WriteHeader(http.StatusNoContent)
|
|
}
|
|
}
|