diff --git a/cli/operations/account/register.go b/cli/operations/account/register.go index 305634cab..e3343abb4 100644 --- a/cli/operations/account/register.go +++ b/cli/operations/account/register.go @@ -35,7 +35,7 @@ func (c *registerCommand) run(*kingpin.ParseContext) error { ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel() - input := &user.CreateInput{ + input := &user.RegisterInput{ UID: uid, Email: email, DisplayName: displayName, diff --git a/client/client.go b/client/client.go index 53fbecd36..6b3ec24c4 100644 --- a/client/client.go +++ b/client/client.go @@ -67,7 +67,7 @@ func (c *HTTPClient) Login(ctx context.Context, input *user.LoginInput) (*types. } // Register registers a new user and returns a JWT token. -func (c *HTTPClient) Register(ctx context.Context, input *user.CreateInput) (*types.TokenResponse, error) { +func (c *HTTPClient) Register(ctx context.Context, input *user.RegisterInput) (*types.TokenResponse, error) { out := new(types.TokenResponse) uri := fmt.Sprintf("%s/api/v1/register", c.base) err := c.post(ctx, uri, true, input, out) diff --git a/client/interface.go b/client/interface.go index 82f96df50..9c0b97002 100644 --- a/client/interface.go +++ b/client/interface.go @@ -17,7 +17,7 @@ type Client interface { Login(ctx context.Context, input *user.LoginInput) (*types.TokenResponse, error) // Register registers a new user and returns a JWT token. - Register(ctx context.Context, input *user.CreateInput) (*types.TokenResponse, error) + Register(ctx context.Context, input *user.RegisterInput) (*types.TokenResponse, error) // Self returns the currently authenticated user. Self(ctx context.Context) (*types.User, error) diff --git a/internal/api/controller/user/create.go b/internal/api/controller/user/create.go index fde9cf1c2..67fe30db9 100644 --- a/internal/api/controller/user/create.go +++ b/internal/api/controller/user/create.go @@ -20,6 +20,14 @@ import ( "golang.org/x/crypto/bcrypt" ) +type RegisterInput struct { + Email string `json:"email"` + + DisplayName string `json:"display_name"` + UID string `json:"uid"` + Password string `json:"password"` +} + // CreateInput is the input used for create operations. // On purpose don't expose admin, has to be enabled explicitly. type CreateInput struct { diff --git a/internal/api/controller/user/register.go b/internal/api/controller/user/register.go index 2565144e7..49bdb952b 100644 --- a/internal/api/controller/user/register.go +++ b/internal/api/controller/user/register.go @@ -18,7 +18,7 @@ import ( // This differs from the Create method as it doesn't require auth, but has limited // functionalities (unable to create admin user for example). func (c *Controller) Register(ctx context.Context, sysCtrl *system.Controller, - in *CreateInput) (*types.TokenResponse, error) { + in *RegisterInput) (*types.TokenResponse, error) { signUpAllowed, err := sysCtrl.IsUserRegistrationAllowed(ctx) if err != nil { return nil, err diff --git a/internal/api/handler/account/register.go b/internal/api/handler/account/register.go index 6b6fa8e58..523276da8 100644 --- a/internal/api/handler/account/register.go +++ b/internal/api/handler/account/register.go @@ -19,7 +19,7 @@ func HandleRegister(userCtrl *user.Controller, sysCtrl *system.Controller) http. return func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() - in := new(user.CreateInput) + in := new(user.RegisterInput) err := json.NewDecoder(r.Body).Decode(in) if err != nil { render.BadRequestf(w, "Invalid request body: %s.", err) diff --git a/internal/api/handler/system/list_configs.go b/internal/api/handler/system/list_configs.go index 5fea93271..6a58fcffd 100644 --- a/internal/api/handler/system/list_configs.go +++ b/internal/api/handler/system/list_configs.go @@ -11,13 +11,13 @@ import ( "github.com/harness/gitness/internal/api/render" ) -type ConfigsOutput struct { +type ConfigOutput struct { SignUpAllowed bool `json:"sign_up_allowed"` } -// HandleListConfig returns an http.HandlerFunc that processes an http.Request +// HandleGetConfig returns an http.HandlerFunc that processes an http.Request // and returns a struct containing all system configs exposed to the users. -func HandleListConfig(sysCtrl *system.Controller) http.HandlerFunc { +func HandleGetConfig(sysCtrl *system.Controller) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() @@ -26,7 +26,7 @@ func HandleListConfig(sysCtrl *system.Controller) http.HandlerFunc { render.TranslatedUserError(w, err) return } - render.JSON(w, http.StatusOK, ConfigsOutput{ + render.JSON(w, http.StatusOK, ConfigOutput{ SignUpAllowed: signUpAllowedCheck, }) } diff --git a/internal/api/openapi/account.go b/internal/api/openapi/account.go index d8deef248..cf01db147 100644 --- a/internal/api/openapi/account.go +++ b/internal/api/openapi/account.go @@ -21,7 +21,7 @@ type loginRequest struct { // request to register an account. type registerRequest struct { - user.CreateInput + user.RegisterInput } // helper function that constructs the openapi specification diff --git a/internal/api/openapi/system.go b/internal/api/openapi/system.go index 265a9ae04..e8e794713 100644 --- a/internal/api/openapi/system.go +++ b/internal/api/openapi/system.go @@ -16,12 +16,12 @@ import ( // helper function that constructs the openapi specification // for the system registration config endpoints. func buildSystem(reflector *openapi3.Reflector) { - onListConfigs := openapi3.Operation{} - onListConfigs.WithTags("system") - onListConfigs.WithMapOfAnything(map[string]interface{}{"operationId": "onListConfigs"}) - _ = reflector.SetRequest(&onListConfigs, nil, http.MethodGet) - _ = reflector.SetJSONResponse(&onListConfigs, new(system.ConfigsOutput), http.StatusOK) - _ = reflector.SetJSONResponse(&onListConfigs, new(usererror.Error), http.StatusInternalServerError) - _ = reflector.SetJSONResponse(&onListConfigs, new(usererror.Error), http.StatusBadRequest) - _ = reflector.Spec.AddOperation(http.MethodGet, "/system/config", onListConfigs) + onGetConfig := openapi3.Operation{} + onGetConfig.WithTags("system") + onGetConfig.WithMapOfAnything(map[string]interface{}{"operationId": "getSystemConfig"}) + _ = reflector.SetRequest(&onGetConfig, nil, http.MethodGet) + _ = reflector.SetJSONResponse(&onGetConfig, new(system.ConfigOutput), http.StatusOK) + _ = reflector.SetJSONResponse(&onGetConfig, new(usererror.Error), http.StatusInternalServerError) + _ = reflector.SetJSONResponse(&onGetConfig, new(usererror.Error), http.StatusBadRequest) + _ = reflector.Spec.AddOperation(http.MethodGet, "/system/config", onGetConfig) } diff --git a/internal/router/api.go b/internal/router/api.go index b491ed5d1..6c4500b53 100644 --- a/internal/router/api.go +++ b/internal/router/api.go @@ -408,7 +408,7 @@ func setupSystem(r chi.Router, sysCtrl *system.Controller) { r.Route("/system", func(r chi.Router) { r.Get("/health", handlersystem.HandleHealth) r.Get("/version", handlersystem.HandleVersion) - r.Get("/config", handlersystem.HandleListConfig(sysCtrl)) + r.Get("/config", handlersystem.HandleGetConfig(sysCtrl)) }) } diff --git a/mocks/mock_client.go b/mocks/mock_client.go index d551ba4f5..b16a6490e 100644 --- a/mocks/mock_client.go +++ b/mocks/mock_client.go @@ -52,7 +52,7 @@ func (mr *MockClientMockRecorder) Login(arg0, arg1 interface{}) *gomock.Call { } // Register mocks base method. -func (m *MockClient) Register(arg0 context.Context, arg1 *user.CreateInput) (*types.TokenResponse, error) { +func (m *MockClient) Register(arg0 context.Context, arg1 *user.RegisterInput) (*types.TokenResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Register", arg0, arg1) ret0, _ := ret[0].(*types.TokenResponse) diff --git a/types/config.go b/types/config.go index f8718e72c..a1c5c81db 100644 --- a/types/config.go +++ b/types/config.go @@ -13,8 +13,11 @@ type Config struct { // InstanceID specifis the ID of the gitness instance. // NOTE: If the value is not provided the hostname of the machine is used. InstanceID string `envconfig:"GITNESS_INSTANCE_ID"` - Debug bool `envconfig:"GITNESS_DEBUG"` - Trace bool `envconfig:"GITNESS_TRACE"` // GracefulShutdownTime defines the max time we wait when shutting down a server. + + Debug bool `envconfig:"GITNESS_DEBUG"` + Trace bool `envconfig:"GITNESS_TRACE"` + + // GracefulShutdownTime defines the max time we wait when shutting down a server. // 5min should be enough for most git clones to complete. GracefulShutdownTime time.Duration `envconfig:"GITNESS_GRACEFUL_SHUTDOWN_TIME" default:"300s"`