Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
Merge branch 'develop' into webserver-cnf
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-stauffer committed Feb 7, 2024
2 parents 15a077f + 7ee56e6 commit c9e0fcc
Show file tree
Hide file tree
Showing 28 changed files with 1,953 additions and 3,728 deletions.
2 changes: 1 addition & 1 deletion apiserver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ To see how to make this your own, look here:
[README](https://openapi-generator.tech)

- API version: 1.0.0
- Build date: 2024-01-24T17:20:07.525819443Z[Etc/UTC]
- Build date: 2024-02-02T12:01:58.629258516Z[Etc/UTC]


### Running the server
Expand Down
12 changes: 4 additions & 8 deletions apiserver/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ import (
// The ConfigurationAPIRouter implementation should parse necessary information from the http request,
// pass the data to a ConfigurationAPIServicer to perform the required actions, then write the service results to the http response.
type ConfigurationAPIRouter interface {
GetAdvancedConfiguration(http.ResponseWriter, *http.Request)
GetAttributeMapping(http.ResponseWriter, *http.Request)
GetBasicConfiguration(http.ResponseWriter, *http.Request)
GetConfiguration(http.ResponseWriter, *http.Request)
GetPermissionMapping(http.ResponseWriter, *http.Request)
PutAdvancedConfiguration(http.ResponseWriter, *http.Request)
PutAttributeMapping(http.ResponseWriter, *http.Request)
PutBasicConfiguration(http.ResponseWriter, *http.Request)
PutConfiguration(http.ResponseWriter, *http.Request)
PutPermissionMapping(http.ResponseWriter, *http.Request)
}

Expand Down Expand Up @@ -57,13 +55,11 @@ type VersionAPIRouter interface {
// while the service implementation can be ignored with the .openapi-generator-ignore file
// and updated with the logic required for the API.
type ConfigurationAPIServicer interface {
GetAdvancedConfiguration(context.Context) (ImplResponse, error)
GetAttributeMapping(context.Context) (ImplResponse, error)
GetBasicConfiguration(context.Context) (ImplResponse, error)
GetConfiguration(context.Context) (ImplResponse, error)
GetPermissionMapping(context.Context) (ImplResponse, error)
PutAdvancedConfiguration(context.Context, AdvancedConfiguration) (ImplResponse, error)
PutAttributeMapping(context.Context, AttributeMap) (ImplResponse, error)
PutBasicConfiguration(context.Context, BasicConfiguration) (ImplResponse, error)
PutConfiguration(context.Context, Configuration) (ImplResponse, error)
PutPermissionMapping(context.Context, Permissions) (ImplResponse, error)
}

Expand Down
81 changes: 16 additions & 65 deletions apiserver/api_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,40 +50,30 @@ func NewConfigurationAPIController(s ConfigurationAPIServicer, opts ...Configura
// Routes returns all the api routes for the ConfigurationAPIController
func (c *ConfigurationAPIController) Routes() Routes {
return Routes{
"GetAdvancedConfiguration": Route{
strings.ToUpper("Get"),
"/v1/configuration/advanced",
c.GetAdvancedConfiguration,
},
"GetAttributeMapping": Route{
strings.ToUpper("Get"),
"/v1/configuration/attribute-mapping",
c.GetAttributeMapping,
},
"GetBasicConfiguration": Route{
"GetConfiguration": Route{
strings.ToUpper("Get"),
"/v1/configuration/basic",
c.GetBasicConfiguration,
"/v1/configuration",
c.GetConfiguration,
},
"GetPermissionMapping": Route{
strings.ToUpper("Get"),
"/v1/configuration/permission-mapping",
c.GetPermissionMapping,
},
"PutAdvancedConfiguration": Route{
strings.ToUpper("Put"),
"/v1/configuration/advanced",
c.PutAdvancedConfiguration,
},
"PutAttributeMapping": Route{
strings.ToUpper("Put"),
"/v1/configuration/attribute-mapping",
c.PutAttributeMapping,
},
"PutBasicConfiguration": Route{
"PutConfiguration": Route{
strings.ToUpper("Put"),
"/v1/configuration/basic",
c.PutBasicConfiguration,
"/v1/configuration",
c.PutConfiguration,
},
"PutPermissionMapping": Route{
strings.ToUpper("Put"),
Expand All @@ -93,18 +83,6 @@ func (c *ConfigurationAPIController) Routes() Routes {
}
}

// GetAdvancedConfiguration - Get Advanced Configuration
func (c *ConfigurationAPIController) GetAdvancedConfiguration(w http.ResponseWriter, r *http.Request) {
result, err := c.service.GetAdvancedConfiguration(r.Context())
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
return
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)
}

// GetAttributeMapping - Get Attribute Mapping
func (c *ConfigurationAPIController) GetAttributeMapping(w http.ResponseWriter, r *http.Request) {
result, err := c.service.GetAttributeMapping(r.Context())
Expand All @@ -117,9 +95,9 @@ func (c *ConfigurationAPIController) GetAttributeMapping(w http.ResponseWriter,
EncodeJSONResponse(result.Body, &result.Code, w)
}

// GetBasicConfiguration - Get Basic Configurations
func (c *ConfigurationAPIController) GetBasicConfiguration(w http.ResponseWriter, r *http.Request) {
result, err := c.service.GetBasicConfiguration(r.Context())
// GetConfiguration - Get Configurations
func (c *ConfigurationAPIController) GetConfiguration(w http.ResponseWriter, r *http.Request) {
result, err := c.service.GetConfiguration(r.Context())
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
Expand All @@ -141,33 +119,6 @@ func (c *ConfigurationAPIController) GetPermissionMapping(w http.ResponseWriter,
EncodeJSONResponse(result.Body, &result.Code, w)
}

// PutAdvancedConfiguration - Creates or Update Advanced Configuration
func (c *ConfigurationAPIController) PutAdvancedConfiguration(w http.ResponseWriter, r *http.Request) {
advancedConfigurationParam := AdvancedConfiguration{}
d := json.NewDecoder(r.Body)
d.DisallowUnknownFields()
if err := d.Decode(&advancedConfigurationParam); err != nil && !errors.Is(err, io.EOF) {
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
return
}
if err := AssertAdvancedConfigurationRequired(advancedConfigurationParam); err != nil {
c.errorHandler(w, r, err, nil)
return
}
if err := AssertAdvancedConfigurationConstraints(advancedConfigurationParam); err != nil {
c.errorHandler(w, r, err, nil)
return
}
result, err := c.service.PutAdvancedConfiguration(r.Context(), advancedConfigurationParam)
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
return
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)
}

// PutAttributeMapping - Creates or Update Attribute Mapping
func (c *ConfigurationAPIController) PutAttributeMapping(w http.ResponseWriter, r *http.Request) {
attributeMapParam := AttributeMap{}
Expand Down Expand Up @@ -195,24 +146,24 @@ func (c *ConfigurationAPIController) PutAttributeMapping(w http.ResponseWriter,
EncodeJSONResponse(result.Body, &result.Code, w)
}

// PutBasicConfiguration - Creates or Update Basic Configuration
func (c *ConfigurationAPIController) PutBasicConfiguration(w http.ResponseWriter, r *http.Request) {
basicConfigurationParam := BasicConfiguration{}
// PutConfiguration - Creates or Update Configuration
func (c *ConfigurationAPIController) PutConfiguration(w http.ResponseWriter, r *http.Request) {
configurationParam := Configuration{}
d := json.NewDecoder(r.Body)
d.DisallowUnknownFields()
if err := d.Decode(&basicConfigurationParam); err != nil && !errors.Is(err, io.EOF) {
if err := d.Decode(&configurationParam); err != nil && !errors.Is(err, io.EOF) {
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
return
}
if err := AssertBasicConfigurationRequired(basicConfigurationParam); err != nil {
if err := AssertConfigurationRequired(configurationParam); err != nil {
c.errorHandler(w, r, err, nil)
return
}
if err := AssertBasicConfigurationConstraints(basicConfigurationParam); err != nil {
if err := AssertConfigurationConstraints(configurationParam); err != nil {
c.errorHandler(w, r, err, nil)
return
}
result, err := c.service.PutBasicConfiguration(r.Context(), basicConfigurationParam)
result, err := c.service.PutConfiguration(r.Context(), configurationParam)
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
Expand Down
2 changes: 1 addition & 1 deletion apiserver/model_attribute_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ package apiserver
// AttributeMap - Maps SAML Attributes to the Eliona User Attributes
type AttributeMap struct {

// Configuration Id refer to basic config's id. Can only be 1
// Configuration Id refer to config's id. Can only be 1
Id int32 `json:"id,omitempty"`

// SAML attribute to map to the email (login) of a user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

package apiserver

// BasicConfiguration - The Basic Configurations for running a SAML 2.0 Service Provider
type BasicConfiguration struct {
// Configuration - The Configurations for running a SAML 2.0 Service Provider
type Configuration struct {

// Configuration Id. Can only be 1
Id int32 `json:"id,omitempty"`
Expand All @@ -35,14 +35,32 @@ type BasicConfiguration struct {

// If enabled, the new created user is archived and cannot login until a admin has activated it.
UserToArchive bool `json:"userToArchive,omitempty"`

// If the configuration is enabled or not
AllowInitializationByIdp bool `json:"allowInitializationByIdp,omitempty"`

// If the SP should make a signed SAML Authn-Request or not
SignedRequest bool `json:"signedRequest,omitempty"`

// Normaly this value is set to false for a SP. If set to true the user has to re-authenticate (login at IdP) even it has a valid session to the IdP.
ForceAuthn bool `json:"forceAuthn,omitempty"`

// If you have to use a customized Entity Id, you can overwrite it here. Normally the default value can be left as it is.
EntityId string `json:"entityId,omitempty"`

// only send cookies over encrypted connection (HTTPS)
CookieSecure bool `json:"cookieSecure,omitempty"`

// The url to redirect if the login failed. If this value is null the default page /noLogin will showed up
LoginFailedUrl string `json:"loginFailedUrl,omitempty"`
}

// AssertBasicConfigurationRequired checks if the required fields are not zero-ed
func AssertBasicConfigurationRequired(obj BasicConfiguration) error {
// AssertConfigurationRequired checks if the required fields are not zero-ed
func AssertConfigurationRequired(obj Configuration) error {
return nil
}

// AssertBasicConfigurationConstraints checks if the values respects the defined constraints
func AssertBasicConfigurationConstraints(obj BasicConfiguration) error {
// AssertConfigurationConstraints checks if the values respects the defined constraints
func AssertConfigurationConstraints(obj Configuration) error {
return nil
}
2 changes: 1 addition & 1 deletion apiserver/model_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ package apiserver
// Permissions - Sets default user permissions and optionaly maps SAML Attributes and Content to eliona's roles
type Permissions struct {

// Configuration Id refer to basic config's id. Can only be 1
// Configuration Id refer to config's id. Can only be 1
Id int32 `json:"id,omitempty"`

DefaultSystemRole string `json:"default_system_role,omitempty"`
Expand Down
70 changes: 34 additions & 36 deletions apiservices/api_configuration_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,58 +33,56 @@ func NewConfigurationApiService() apiserver.ConfigurationAPIServicer {
return &ConfigurationApiService{}
}

// GetAdvancedConfiguration - Get Advanced Configuration
func (s *ConfigurationApiService) GetAdvancedConfiguration(ctx context.Context) (apiserver.ImplResponse, error) {
advCnf, err := conf.GetAdvancedConfig(ctx)

return apiserver.Response(http.StatusOK, advCnf), err
}

// GetAttributeMapping - Get Attribute Mapping
func (s *ConfigurationApiService) GetAttributeMapping(ctx context.Context) (apiserver.ImplResponse, error) {
attrMap, err := conf.GetAttributeMapping(ctx)

return apiserver.Response(http.StatusOK, attrMap), err
am, err := conf.GetAttributeMapping(ctx)
if err != nil {
return apiserver.ImplResponse{Code: http.StatusInternalServerError}, err
}
return apiserver.Response(http.StatusOK, am), nil
}

// GetBasicConfiguration - Get Basic Configurations
func (s *ConfigurationApiService) GetBasicConfiguration(ctx context.Context) (apiserver.ImplResponse, error) {
basicCnf, err := conf.GetBasicConfig(ctx)

return apiserver.Response(http.StatusOK, basicCnf), err
// GetConfiguration - Get Configuration
func (s *ConfigurationApiService) GetConfiguration(ctx context.Context) (apiserver.ImplResponse, error) {
config, err := conf.GetConfig(ctx)
if err != nil {
return apiserver.ImplResponse{Code: http.StatusInternalServerError}, err
}
return apiserver.Response(http.StatusOK, config), nil
}

// GetPermissionMapping - Get Permission Mapping
func (s *ConfigurationApiService) GetPermissionMapping(ctx context.Context) (apiserver.ImplResponse, error) {
permMap, err := conf.GetPermissionSettings(ctx)

return apiserver.Response(http.StatusOK, permMap), err
}

// PutAdvancedConfiguration - Creates or Update Advanced Configuration
func (s *ConfigurationApiService) PutAdvancedConfiguration(ctx context.Context, advancedConfiguration apiserver.AdvancedConfiguration) (apiserver.ImplResponse, error) {
cnfRet, err := conf.SetAdvancedConfig(ctx, &advancedConfiguration)

return apiserver.Response(http.StatusOK, cnfRet), err
pm, err := conf.GetPermissionMapping(ctx)
if err != nil {
return apiserver.ImplResponse{Code: http.StatusInternalServerError}, err
}
return apiserver.Response(http.StatusOK, pm), nil
}

// PutAttributeMapping - Creates or Update Attribute Mapping
func (s *ConfigurationApiService) PutAttributeMapping(ctx context.Context, attributeMap apiserver.AttributeMap) (apiserver.ImplResponse, error) {
mapRet, err := conf.SetAttributeMapping(ctx, &attributeMap)

return apiserver.Response(http.StatusOK, mapRet), err
upsertedAttrMap, err := conf.SetAttributeMapping(ctx, &attributeMap)
if err != nil {
return apiserver.ImplResponse{Code: http.StatusInternalServerError}, err
}
return apiserver.Response(http.StatusCreated, upsertedAttrMap), nil
}

// PutBasicConfiguration - Creates or Update Basic Configuration
func (s *ConfigurationApiService) PutBasicConfiguration(ctx context.Context, basicConfiguration apiserver.BasicConfiguration) (apiserver.ImplResponse, error) {
cnfRet, err := conf.SetBasicConfig(ctx, &basicConfiguration)

return apiserver.Response(http.StatusOK, cnfRet), err
// PutConfiguration - Creates or Update Basic Configuration
func (s *ConfigurationApiService) PutConfiguration(ctx context.Context, config apiserver.Configuration) (apiserver.ImplResponse, error) {
upsertedConfig, err := conf.SetConfig(ctx, &config)
if err != nil {
return apiserver.ImplResponse{Code: http.StatusInternalServerError}, err
}
return apiserver.Response(http.StatusCreated, upsertedConfig), nil
}

// PutPermissionMapping - Creates or Update Permission Mapping Configurations
func (s *ConfigurationApiService) PutPermissionMapping(ctx context.Context, permissions apiserver.Permissions) (apiserver.ImplResponse, error) {
permRet, err := conf.SetPermissionSettings(ctx, &permissions)

return apiserver.Response(http.StatusOK, permRet), err
upsertedPerms, err := conf.SetPermissionMapping(ctx, &permissions)
if err != nil {
return apiserver.ImplResponse{Code: http.StatusInternalServerError}, err
}
return apiserver.Response(http.StatusCreated, upsertedPerms), nil
}
14 changes: 3 additions & 11 deletions apiservices/api_configuration_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,15 @@ func TestApp_AppApi_Configuration_InitDB(t *testing.T) {
}
}

func TestApp_AppApi_Configuration_GetBasicConfig(t *testing.T) {
func TestApp_AppApi_Configuration_GetConfig(t *testing.T) {
apiService := apiservices.NewConfigurationApiService()
cnf, err := apiService.GetBasicConfiguration(context.Background())
cnf, err := apiService.GetConfiguration(context.Background())
if err != sql.ErrNoRows {
t.Error(err)
}
fmt.Println(cnf)
}

func TestApp_AppApi_Configuration_GetAdvancedConfig(t *testing.T) {

}

func TestApp_AppApi_Configuration_GetAttributeMapping(t *testing.T) {

}
Expand All @@ -66,11 +62,7 @@ func TestApp_AppApi_Configuration_GetPermissionMap(t *testing.T) {

}

func TestApp_AppApi_Configuration_PutBasicConfig(t *testing.T) {

}

func TestApp_AppApi_Configuration_PutAdvancedConfig(t *testing.T) {
func TestApp_AppApi_Configuration_PutConfig(t *testing.T) {

}

Expand Down
Loading

0 comments on commit c9e0fcc

Please sign in to comment.