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

CSS-4603 Refactor toward using canonical/ofga #990

Merged
merged 31 commits into from
Aug 21, 2023

Conversation

babakks
Copy link
Member

@babakks babakks commented Jul 7, 2023

Description

Refactored OpenFGA related packages to use canonical/ofga module.

Fixes CSS-4603

Engineering checklist

Check only items that apply

  • Documentation updated
  • Covered by unit tests
  • Covered by integration tests

Test instructions

Notes for code reviewers

@babakks babakks marked this pull request as ready for review July 12, 2023 08:44
Copy link
Contributor

@kian99 kian99 left a comment

Choose a reason for hiding this comment

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

I think this looks like a good improvement with nice shifting of some logic to the library.
I would say we need more reviews on this though.

.gitignore Outdated Show resolved Hide resolved
cmd/jimmctl/cmd/jimmsuite_test.go Show resolved Hide resolved
internal/openfga/names/names.go Show resolved Hide resolved
internal/openfga/openfga.go Show resolved Hide resolved
internal/openfga/openfga_test.go Outdated Show resolved Hide resolved
@@ -27,7 +27,7 @@ import (
// func TestJwtGenerator(t *testing.T) {
// c := qt.New(t)

// _, client, _, err := jimmtest.SetupTestOFGAClient(c.Name())
// client, _, _, err := jimmtest.SetupTestOFGAClient(c.Name())
Copy link
Contributor

Choose a reason for hiding this comment

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

This is commented out, do we still need it?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks to @kian99, we made a card for this TODO and removed the code part.

@@ -89,7 +89,7 @@ func setupService(ctx context.Context, c *qt.C) (*jimm.Service, *httptest.Server
err := store.CleanupJWKS(ctx)
c.Assert(err, qt.IsNil)

_, ofgaClient, cfg, err := jimmtest.SetupTestOFGAClient(c.Name())
_, _, cofgaParams, err := jimmtest.SetupTestOFGAClient(c.Name())
Copy link
Contributor

Choose a reason for hiding this comment

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

cofga is kind of ambiguous

Copy link
Member Author

@babakks babakks Aug 21, 2023

Choose a reason for hiding this comment

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

cofga is an alias for canonical/ofga module; I couldn't find any better, yet concise, replacement for it. Can you suggest me one? @ale8k @kian99

Copy link
Contributor

@ale8k ale8k left a comment

Choose a reason for hiding this comment

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

So it looks good to me, but won't approve until tests are all good and I'll go over it once more because it touches a lot of places. Also appears the new client is basically ours? Or at least inspired from ours?

Signed-off-by: Babak K. Shandiz <[email protected]>
Signed-off-by: Babak K. Shandiz <[email protected]>
Signed-off-by: Babak K. Shandiz <[email protected]>
Signed-off-by: Babak K. Shandiz <[email protected]>
Signed-off-by: Babak K. Shandiz <[email protected]>
Signed-off-by: Babak K. Shandiz <[email protected]>
Signed-off-by: Babak K. Shandiz <[email protected]>
Signed-off-by: Babak K. Shandiz <[email protected]>
@@ -27,7 +27,7 @@ import (
// func TestJwtGenerator(t *testing.T) {
// c := qt.New(t)

// _, client, _, err := jimmtest.SetupTestOFGAClient(c.Name())
// client, _, _, err := jimmtest.SetupTestOFGAClient(c.Name())
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

@@ -539,3 +492,14 @@ func key(candid *candidtest.Server, user string) *bakery.KeyPair {
Private: bakery.PrivateKey{Key: bakery.Key(key.Private.Key)},
}
}

func cofgaParamsToJIMMOpenFGAParams(cofgaParams cofga.OpenFGAParams) jimm.OpenFGAParams {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd godoc comment this to explain why

Copy link
Contributor

@ale8k ale8k left a comment

Choose a reason for hiding this comment

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

lgtm bar some comments

}

func (s *JIMMSuite) SetUpTest(c *gc.C) {
ofgaAPI, ofgaClient, ofgaConfig, err := SetupTestOFGAClient(c.TestName())
ofgaClient, cofgaClient, cofgaConfig, err := SetupTestOFGAClient(c.TestName())
Copy link
Contributor

Choose a reason for hiding this comment

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

var err error
c.OFGAClient, c.OFGAClient, c.OFGAConfig, err = SetupTestOFGAClient(c.TestName())

@@ -2,10 +2,12 @@

package names

import cofga "github.com/canonical/ofga"
Copy link
Contributor

Choose a reason for hiding this comment

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

there is no naming conflict here.. so i'd leave it as

import "github.com/canonical/ofga"

@@ -6,9 +6,9 @@ import (
"context"
"sort"

cofga "github.com/canonical/ofga"
Copy link
Contributor

Choose a reason for hiding this comment

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

again, no naming conflict so just import it as ofga...

"net/http"
"os"
"strconv"
"strings"
"time"

"github.com/canonical/candid/candidclient"
cofga "github.com/canonical/ofga"
Copy link
Contributor

Choose a reason for hiding this comment

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

see above

@babakks
Copy link
Member Author

babakks commented Aug 21, 2023

At the end I removed any unnecessary aliases to reference our internal openfga package (now accessed through openfga everywhere), and kept references to canonical/ofga under cofga alias.

@babakks babakks merged commit dc7f417 into canonical:feature-rebac Aug 21, 2023
1 check passed
@babakks babakks deleted the css-4603/use-ofga branch August 21, 2023 11:44
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.

4 participants