mirror of
https://github.com/harness/drone.git
synced 2025-05-31 11:43:15 +00:00
[CODE-617]: Add env variable in Gitness to allow/disallow sign-ups
This commit is contained in:
parent
af7c0385f8
commit
4c92c32c0a
@ -1,3 +1,4 @@
|
|||||||
GITNESS_TRACE=true
|
GITNESS_TRACE=true
|
||||||
GITNESS_WEBHOOK_ALLOW_LOOPBACK=true
|
GITNESS_WEBHOOK_ALLOW_LOOPBACK=true
|
||||||
GITNESS_PRINCIPAL_ADMIN_PASSWORD=changeit
|
GITNESS_PRINCIPAL_ADMIN_PASSWORD=changeit
|
||||||
|
GITNESS_ALLOW_SIGNUP=true
|
@ -17,9 +17,15 @@ import (
|
|||||||
* This differs from the Create method as it doesn't require auth, but has limited
|
* This differs from the Create method as it doesn't require auth, but has limited
|
||||||
* functionalities (unable to create admin user for example).
|
* functionalities (unable to create admin user for example).
|
||||||
*/
|
*/
|
||||||
func (c *Controller) Register(ctx context.Context, in *CreateInput) (*types.TokenResponse, error) {
|
func (c *Controller) Register(ctx context.Context, in *CreateInput, config *types.Config) (*types.TokenResponse, error) {
|
||||||
// TODO: allow to configure if open register is allowed.
|
// TODO: allow to configure if open register is allowed.
|
||||||
|
|
||||||
|
signUpFlag := config.AllowSignUp
|
||||||
|
|
||||||
|
if !signUpFlag {
|
||||||
|
return nil, fmt.Errorf("user sign-up is disabled")
|
||||||
|
}
|
||||||
|
|
||||||
user, err := c.CreateNoAuth(ctx, in, false)
|
user, err := c.CreateNoAuth(ctx, in, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create user: %w", err)
|
return nil, fmt.Errorf("failed to create user: %w", err)
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/harness/gitness/types"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/harness/gitness/internal/api/controller/user"
|
"github.com/harness/gitness/internal/api/controller/user"
|
||||||
@ -13,7 +14,7 @@ import (
|
|||||||
|
|
||||||
// HandleRegister returns an http.HandlerFunc that processes an http.Request
|
// HandleRegister returns an http.HandlerFunc that processes an http.Request
|
||||||
// to register the named user account with the system.
|
// to register the named user account with the system.
|
||||||
func HandleRegister(userCtrl *user.Controller) http.HandlerFunc {
|
func HandleRegister(userCtrl *user.Controller, config *types.Config) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
|
|
||||||
@ -24,7 +25,7 @@ func HandleRegister(userCtrl *user.Controller) http.HandlerFunc {
|
|||||||
Password: r.FormValue("password"),
|
Password: r.FormValue("password"),
|
||||||
}
|
}
|
||||||
|
|
||||||
tokenResponse, err := userCtrl.Register(ctx, in)
|
tokenResponse, err := userCtrl.Register(ctx, in, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
render.TranslatedUserError(w, err)
|
render.TranslatedUserError(w, err)
|
||||||
return
|
return
|
||||||
|
@ -46,7 +46,7 @@ import (
|
|||||||
"github.com/rs/zerolog/hlog"
|
"github.com/rs/zerolog/hlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// APIHandler is an abstraction of an http handler that handles API calls.
|
// APIHandler is an abstraction of a http handler that handles API calls.
|
||||||
type APIHandler interface {
|
type APIHandler interface {
|
||||||
http.Handler
|
http.Handler
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ func NewAPIHandler(
|
|||||||
|
|
||||||
r.Route("/v1", func(r chi.Router) {
|
r.Route("/v1", func(r chi.Router) {
|
||||||
setupRoutesV1(r, repoCtrl, spaceCtrl, pullreqCtrl, webhookCtrl, githookCtrl,
|
setupRoutesV1(r, repoCtrl, spaceCtrl, pullreqCtrl, webhookCtrl, githookCtrl,
|
||||||
saCtrl, userCtrl, principalCtrl, checkCtrl)
|
saCtrl, userCtrl, principalCtrl, checkCtrl, config)
|
||||||
})
|
})
|
||||||
|
|
||||||
// wrap router in terminatedPath encoder.
|
// wrap router in terminatedPath encoder.
|
||||||
@ -121,6 +121,7 @@ func setupRoutesV1(r chi.Router,
|
|||||||
userCtrl *user.Controller,
|
userCtrl *user.Controller,
|
||||||
principalCtrl principal.Controller,
|
principalCtrl principal.Controller,
|
||||||
checkCtrl *check.Controller,
|
checkCtrl *check.Controller,
|
||||||
|
config *types.Config,
|
||||||
) {
|
) {
|
||||||
setupSpaces(r, spaceCtrl, repoCtrl)
|
setupSpaces(r, spaceCtrl, repoCtrl)
|
||||||
setupRepos(r, repoCtrl, pullreqCtrl, webhookCtrl, checkCtrl)
|
setupRepos(r, repoCtrl, pullreqCtrl, webhookCtrl, checkCtrl)
|
||||||
@ -129,7 +130,7 @@ func setupRoutesV1(r chi.Router,
|
|||||||
setupPrincipals(r, principalCtrl)
|
setupPrincipals(r, principalCtrl)
|
||||||
setupInternal(r, githookCtrl)
|
setupInternal(r, githookCtrl)
|
||||||
setupAdmin(r, userCtrl)
|
setupAdmin(r, userCtrl)
|
||||||
setupAccount(r, userCtrl)
|
setupAccount(r, userCtrl, config)
|
||||||
setupSystem(r)
|
setupSystem(r)
|
||||||
setupResources(r)
|
setupResources(r)
|
||||||
}
|
}
|
||||||
@ -431,8 +432,8 @@ func setupAdmin(r chi.Router, userCtrl *user.Controller) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupAccount(r chi.Router, userCtrl *user.Controller) {
|
func setupAccount(r chi.Router, userCtrl *user.Controller, config *types.Config) {
|
||||||
r.Post("/login", account.HandleLogin(userCtrl))
|
r.Post("/login", account.HandleLogin(userCtrl))
|
||||||
r.Post("/register", account.HandleRegister(userCtrl))
|
r.Post("/register", account.HandleRegister(userCtrl, config))
|
||||||
r.Post("/logout", account.HandleLogout(userCtrl))
|
r.Post("/logout", account.HandleLogout(userCtrl))
|
||||||
}
|
}
|
||||||
|
@ -12,10 +12,12 @@ import (
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
// InstanceID specifis the ID of the gitness instance.
|
// InstanceID specifis the ID of the gitness instance.
|
||||||
// NOTE: If the value is not provided the hostname of the machine is used.
|
// NOTE: If the value is not provided the hostname of the machine is used.
|
||||||
InstanceID string `envconfig:"GITNESS_INSTANCE_ID"`
|
InstanceID string `envconfig:"GITNESS_INSTANCE_ID"`
|
||||||
Debug bool `envconfig:"GITNESS_DEBUG"`
|
Debug bool `envconfig:"GITNESS_DEBUG"`
|
||||||
Trace bool `envconfig:"GITNESS_TRACE"`
|
Trace bool `envconfig:"GITNESS_TRACE"`
|
||||||
Profiler struct {
|
AllowSignUp bool `envconfig:"GITNESS_ALLOW_SIGNUP"`
|
||||||
|
|
||||||
|
Profiler struct {
|
||||||
Type string `envconfig:"GITNESS_PROFILER_TYPE"`
|
Type string `envconfig:"GITNESS_PROFILER_TYPE"`
|
||||||
ServiceName string `envconfig:"GITNESS_PROFILER_SERVICE_NAME" default:"gitness"`
|
ServiceName string `envconfig:"GITNESS_PROFILER_SERVICE_NAME" default:"gitness"`
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user