Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLOUDTRUST-2109] Authorization refactoring #156

Merged
merged 24 commits into from Jan 21, 2020

Conversation

harture
Copy link
Contributor

@harture harture commented Jan 15, 2020

We plan to split the authorizations refactoring in 2 phases (2 PR).
First, we deploy the 1st PR which contains the authorization edition/management. We perform the authorizations configuration which will be stored in DB. This config will not be used, the JSON is still used to check the authorizations.
Second step, we deploy the 2nd PR which will remove the usage of JSON and compute the authorization from the DB configuration.
This strategy should allow us to minimize the downtime and migration risks.

@coveralls
Copy link

coveralls commented Jan 15, 2020

Pull Request Test Coverage Report for Build 1529

  • 554 of 656 (84.45%) changed or added relevant lines in 24 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.9%) to 90.362%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/management/component.go 203 204 99.51%
pkg/statistics/authorization.go 22 23 95.65%
pkg/statistics/component.go 15 16 93.75%
pkg/event/http.go 2 4 50.0%
pkg/export/http.go 0 2 0.0%
pkg/export/storage.go 0 2 0.0%
pkg/statistics/endpoint.go 4 6 66.67%
pkg/export/component.go 0 3 0.0%
pkg/management/endpoint.go 64 67 95.52%
internal/keycloakb/configdbinstrumenting.go 0 25 0.0%
Totals Coverage Status
Change from base Build 1497: -0.9%
Covered Lines: 3694
Relevant Lines: 4088

💛 - Coveralls

@harture harture force-pushed the CLOUDTRUST-2109_AuthorizationRefactoring branch from 7fa2c70 to c22abf5 Compare January 15, 2020 08:22
@harture harture changed the title Cloudtrust 2109 authorization refactoring [CLOUDTRUST-2109] Authorization refactoring Jan 15, 2020
@harture harture requested review from bsoniam and fperot74 and removed request for bsoniam and fperot74 January 16, 2020 15:14
@cloudtrust cloudtrust deleted a comment from harture Jan 17, 2020
@harture harture requested a review from fperot74 January 20, 2020 07:45
@harture harture requested a review from bsoniam January 20, 2020 07:45
api/management/api.go Outdated Show resolved Hide resolved
api/management/api.go Outdated Show resolved Hide resolved
@@ -67,3 +76,76 @@ func (c *configurationDBModule) GetConfiguration(context context.Context, realmI
return config, err
}
}

func (c *configurationDBModule) GetAuthorizations(ctx context.Context, realmID string, groupName string) ([]dto.Authorization, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be reused in paper-card-service

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we will retrieve the authorizations to apply authorizations, we will retrieve all of them not just one for a specific realm and group.

internal/keycloakb/configdbmodule_test.go Outdated Show resolved Hide resolved
@@ -40,6 +42,23 @@ func (ec *component) reportEvent(ctx context.Context, apiCall string, values ...

}

// Get actions
func (ec *component) GetActions(ctx context.Context) ([]api.ActionRepresentation, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be part of the common lib

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this method is very similar for each Component but a simple and elegant way to do it ...
Would you have any idea ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say we will have a look at this when we'll have time for this... (it almost means never)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not sooner?

Copy link
Contributor Author

@harture harture left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Responses directly as comment

@harture harture merged commit ee02f6e into master Jan 21, 2020
@@ -2,6 +2,12 @@ package events_api

import "database/sql"

// ActionRepresentation struct
type ActionRepresentation struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same structure is used by papercard module.
If for the long term this stays the same, then we can move them in common service

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will move it in common during PR2

schema:
type: array
items:
type: string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is not the same as you code in the paper card?
/cards/actions:
get:
tags:
- Actions
summary: Get the list of all possible actions
responses:
200:
description: successful operation
content:
application/json:
schema:
type: array
items:
** $ref: '#/components/schemas/Actions' **

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, it was a bug, it is fixed in the PR #159

}

// ActionRepresentation struct
type ActionRepresentation struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before

@@ -15,6 +15,20 @@ tags:
- name: Roles
description: Roles management
paths:
/actions:
get:
tags:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO in PR2, thks

@@ -15,6 +15,12 @@ const (
RegExpTwoDigitsNumber = `^\d{1,2}$`
)

// ActionRepresentation struct
type ActionRepresentation struct {
Name *string `json:"name"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as before

@@ -9,6 +9,20 @@ tags:
- name: Statistics
description: Statistics management
paths:
/statistics/actions:
get:
tags:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as before

GroudIDs = "groupIds"
GroupID = "groupId"
GroupName = "groupName"
Name = "name"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name gives enough information?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will fix it

var actions []security.Action

func newAction(as string, scope security.Scope) security.Action {
a := security.Action{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from commom-service, master branch:
type Action struct {
Id int
Name string
Scope Scope
}
Id should be defined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I can remove this Id, we finally don't use it.

@@ -40,6 +42,23 @@ func (ec *component) reportEvent(ctx context.Context, apiCall string, values ...

}

// Get actions
func (ec *component) GetActions(ctx context.Context) ([]api.ActionRepresentation, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not sooner?

var actions []security.Action

func newAction(as string, scope security.Scope) security.Action {
a := security.Action{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

@fperot74 fperot74 deleted the CLOUDTRUST-2109_AuthorizationRefactoring branch January 6, 2021 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants