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

SMQ-2604 - Change PAT repo implementation #2680

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

nyagamunene
Copy link
Contributor

What type of PR is this?

What does this do?

Which issue(s) does this PR fix/relate to?

Have you included tests for your changes?

Did you document any new/modified feature?

Notes

@nyagamunene nyagamunene marked this pull request as ready for review February 4, 2025 14:25
@nyagamunene nyagamunene requested a review from a team as a code owner February 4, 2025 14:25
auth/postgres/init.go Show resolved Hide resolved
@dborovcanin
Copy link
Collaborator

@nyagamunene Please address comments @arvindh123 left.

return dbScopes
}

func patToDBRecords(pat auth.PAT) (dbPat, []dbScope, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please rename to toDBPatScope

return scope, nil
}

func fromAuthScope(patID string, scope auth.Scope) []dbScope {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please rename to toDBScope, then pass the entire auth.PAT.

Comment on lines 73 to 126
row, err := pr.db.NamedQueryContext(ctx, saveQuery, record)
if err != nil {
return postgres.HandleError(repoerr.ErrCreateEntity, err)
}
defer row.Close()

scopeRow, err := pr.db.NamedQueryContext(ctx, saveScopeQuery, scope)
if err != nil {
return postgres.HandleError(repoerr.ErrCreateEntity, err)
}
defer scopeRow.Close()

if err := pr.cache.Save(ctx, pat.ID, pat); err != nil {
return errors.Wrap(repoerr.ErrCreateEntity, err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please User transaction(tx),
If anyone fails then all others should be reverted. With Tx you can achieve it easily, For refer implmenetation, please check roles, clients, channels repo.

return auth.Scope{}, errors.Wrap(repoerr.ErrCreateEntity, err)
}

_, scope, err := patToDBRecords(pat)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use toDBScope which will return only scope
Signature of the function will be func toDBScope(auth.PAT) (dbScope,error)

Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Copy link

codecov bot commented Feb 12, 2025

Codecov Report

Attention: Patch coverage is 4.49937% with 1507 lines in your changes missing coverage. Please review.

Project coverage is 35.13%. Comparing base (597ad23) to head (58a40a3).

Files with missing lines Patch % Lines
auth/postgres/repo.go 0.00% 562 Missing ⚠️
channels/middleware/authorization.go 0.00% 110 Missing ⚠️
auth/postgres/pat.go 0.00% 96 Missing ⚠️
auth/pat.go 0.00% 92 Missing ⚠️
groups/middleware/authorization.go 0.00% 84 Missing ⚠️
clients/middleware/authorization.go 0.00% 72 Missing ⚠️
users/middleware/authorization.go 0.00% 65 Missing ⚠️
auth/mocks/pats.go 0.00% 53 Missing ⚠️
auth/mocks/cache.go 0.00% 51 Missing ⚠️
auth/mocks/service.go 3.77% 50 Missing and 1 partial ⚠️
... and 10 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2680      +/-   ##
==========================================
- Coverage   42.28%   35.13%   -7.16%     
==========================================
  Files         349      250      -99     
  Lines       47349    39094    -8255     
==========================================
- Hits        20021    13735    -6286     
+ Misses      25154    24281     -873     
+ Partials     2174     1078    -1096     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: nyagamunene <[email protected]>
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.

Change PATs repo implementation
3 participants