mirror of
https://github.com/harness/drone.git
synced 2025-05-06 02:10:05 +08:00

This change adds the following: - Space UID + Custom harness validation (accountId for top level space, harness identifier for child spaces) - Repo UID + Custom harness validation (harness identifier) - Store Unique casing of space / repo path and add Path.ValueUnique (with Unique index) to allow for application layer controlling the case sensitivity (case insensitive standalone vs partially case sensitive harness) - Token UID (unique index over ownertype + ownerID + tokenUID) - Add DisplayName for principals (replaces Name to avoid confustion) - Store Unique casing of principal UID and add Principal.ValueUnique (with unique index) to allow for application layer, per principal type control of case sensitivity (required in embedded mode) - Generate serviceAccount UID (+Email) Randomly (sa-{space|repo}-{ID}-{random}) - Allows to have a unique UID across all principals while reducing likelyhood of overlaps with users + avoid overlap across spaces / repos. - Sync casing of space names (accountId orgId projectId) when creating spaces on the fly (to ensure case sensitivity of - harness code) or use the existing space to update casing. - Update serviceaccount client to match updated NG Manager API - in embedded mode create spaces for harness resources owning the service account
57 lines
2.5 KiB
Go
57 lines
2.5 KiB
Go
// Copyright 2022 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 openapi
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/harness/gitness/internal/api/controller/user"
|
|
"github.com/harness/gitness/internal/api/usererror"
|
|
"github.com/harness/gitness/types"
|
|
|
|
"github.com/swaggest/openapi-go/openapi3"
|
|
)
|
|
|
|
type currentUserResponse struct {
|
|
Data *types.User `json:"data"`
|
|
Status string `json:"status" enum:"SUCCESS,FAILURE,ERROR"`
|
|
}
|
|
|
|
// helper function that constructs the openapi specification
|
|
// for user account resources.
|
|
func buildUser(reflector *openapi3.Reflector) {
|
|
opFind := openapi3.Operation{}
|
|
opFind.WithTags("user")
|
|
opFind.WithMapOfAnything(map[string]interface{}{"operationId": "getUser"})
|
|
_ = reflector.SetRequest(&opFind, nil, http.MethodGet)
|
|
_ = reflector.SetJSONResponse(&opFind, new(types.User), http.StatusOK)
|
|
_ = reflector.SetJSONResponse(&opFind, new(usererror.Error), http.StatusInternalServerError)
|
|
_ = reflector.Spec.AddOperation(http.MethodGet, "/user", opFind)
|
|
|
|
opUpdate := openapi3.Operation{}
|
|
opUpdate.WithTags("user")
|
|
opUpdate.WithMapOfAnything(map[string]interface{}{"operationId": "updateUser"})
|
|
_ = reflector.SetRequest(&opUpdate, new(user.UpdateInput), http.MethodPatch)
|
|
_ = reflector.SetJSONResponse(&opUpdate, new(types.User), http.StatusOK)
|
|
_ = reflector.SetJSONResponse(&opUpdate, new(usererror.Error), http.StatusInternalServerError)
|
|
_ = reflector.Spec.AddOperation(http.MethodPatch, "/user", opUpdate)
|
|
|
|
opToken := openapi3.Operation{}
|
|
opToken.WithTags("user")
|
|
opToken.WithMapOfAnything(map[string]interface{}{"operationId": "createToken"})
|
|
_ = reflector.SetRequest(&opToken, new(types.TokenResponse), http.MethodPost)
|
|
_ = reflector.SetJSONResponse(&opToken, new(types.User), http.StatusOK)
|
|
_ = reflector.SetJSONResponse(&opToken, new(usererror.Error), http.StatusInternalServerError)
|
|
_ = reflector.Spec.AddOperation(http.MethodPost, "/user/token", opToken)
|
|
|
|
opCurrent := openapi3.Operation{}
|
|
opCurrent.WithTags("user")
|
|
opCurrent.WithMapOfAnything(map[string]interface{}{"operationId": "getCurrentUser"})
|
|
_ = reflector.SetRequest(&opFind, new(baseRequest), http.MethodGet)
|
|
_ = reflector.SetJSONResponse(&opCurrent, new(currentUserResponse), http.StatusOK)
|
|
_ = reflector.SetJSONResponse(&opCurrent, new(usererror.Error), http.StatusInternalServerError)
|
|
_ = reflector.Spec.AddOperation(http.MethodGet, "/api/user/currentUser", opCurrent)
|
|
}
|