From 5ecf716ca28202f582fa24a7158f9ce2343a64a3 Mon Sep 17 00:00:00 2001 From: Kian Parvin Date: Fri, 14 Jun 2024 13:27:16 +0200 Subject: [PATCH 1/4] Update reading test auth model --- internal/jimmtest/openfga.go | 37 +----------------------------------- 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/internal/jimmtest/openfga.go b/internal/jimmtest/openfga.go index c410623a3..a32ae6939 100644 --- a/internal/jimmtest/openfga.go +++ b/internal/jimmtest/openfga.go @@ -4,11 +4,7 @@ import ( "context" "encoding/json" "fmt" - "io/fs" - "io/ioutil" "os" - "path" - "path/filepath" "strings" "sync" @@ -39,38 +35,7 @@ type testSetup struct { } func getAuthModelDefinition() (*sdk.AuthorizationModel, error) { - desiredFolder := "local" - authPath := "" - var pwd string - pwd, err := os.Getwd() - if err != nil { - return nil, err - } - for ok := true; ok; { - if pwd == "/" { - break - } - var files []fs.FileInfo - files, err = ioutil.ReadDir(pwd) - if err != nil { - return nil, err - } - - for _, f := range files { - if f.Name() == desiredFolder { - ok = true - authPath = pwd - } - } - // Move up a directory - pwd = filepath.Dir(pwd) - } - if authPath == "" { - err = fmt.Errorf("auth path is empty") - return nil, err - } - - b, err := os.ReadFile(path.Join(authPath, "/local/openfga/authorisation_model.json")) + b, err := os.ReadFile("../../openfga/authorisation_model.json") if err != nil { return nil, err } From fba62863d7055e7bc70f25d8c579a6ea623076ab Mon Sep 17 00:00:00 2001 From: Kian Parvin Date: Fri, 14 Jun 2024 15:17:27 +0200 Subject: [PATCH 2/4] Create a top level openfga package --- internal/jimmtest/openfga.go | 9 ++------- openfga/auth_model.go | 8 ++++++++ openfga/readme.md | 2 ++ 3 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 openfga/auth_model.go create mode 100644 openfga/readme.md diff --git a/internal/jimmtest/openfga.go b/internal/jimmtest/openfga.go index a32ae6939..c3e9b884a 100644 --- a/internal/jimmtest/openfga.go +++ b/internal/jimmtest/openfga.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "os" "strings" "sync" @@ -16,6 +15,7 @@ import ( "github.com/canonical/jimm/internal/errors" "github.com/canonical/jimm/internal/openfga" + auth_model "github.com/canonical/jimm/openfga" ) var ( @@ -35,13 +35,8 @@ type testSetup struct { } func getAuthModelDefinition() (*sdk.AuthorizationModel, error) { - b, err := os.ReadFile("../../openfga/authorisation_model.json") - if err != nil { - return nil, err - } - authModel := sdk.AuthorizationModel{} - err = json.Unmarshal(b, &authModel) + err := json.Unmarshal(auth_model.AuthModelFile, &authModel) if err != nil { return nil, err } diff --git a/openfga/auth_model.go b/openfga/auth_model.go new file mode 100644 index 000000000..ed5021c62 --- /dev/null +++ b/openfga/auth_model.go @@ -0,0 +1,8 @@ +package openfga + +import ( + _ "embed" +) + +//go:embed authorisation_model.json +var AuthModelFile []byte diff --git a/openfga/readme.md b/openfga/readme.md new file mode 100644 index 000000000..eec33129d --- /dev/null +++ b/openfga/readme.md @@ -0,0 +1,2 @@ +This folder/package exists to hold JIMM's OpenFGA authorisation model. +auth_model.go provides embeds the auth model and provides it for tests. From c22b74aa0629161bb7b1caf0e0ac09e1e0daa8a2 Mon Sep 17 00:00:00 2001 From: Kian Parvin Date: Fri, 14 Jun 2024 16:39:30 +0200 Subject: [PATCH 3/4] Move readme to package godoc --- openfga/auth_model.go | 2 ++ openfga/readme.md | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) delete mode 100644 openfga/readme.md diff --git a/openfga/auth_model.go b/openfga/auth_model.go index ed5021c62..3309b0527 100644 --- a/openfga/auth_model.go +++ b/openfga/auth_model.go @@ -1,3 +1,5 @@ +// This package exists to hold JIMM's OpenFGA authorisation model. +// It embeds the auth model and provides it for tests. package openfga import ( diff --git a/openfga/readme.md b/openfga/readme.md deleted file mode 100644 index eec33129d..000000000 --- a/openfga/readme.md +++ /dev/null @@ -1,2 +0,0 @@ -This folder/package exists to hold JIMM's OpenFGA authorisation model. -auth_model.go provides embeds the auth model and provides it for tests. From 40e58442ef46564fc057cccd7643359f65f5420c Mon Sep 17 00:00:00 2001 From: Kian Parvin Date: Mon, 17 Jun 2024 10:36:17 +0200 Subject: [PATCH 4/4] Add copyright line --- openfga/auth_model.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openfga/auth_model.go b/openfga/auth_model.go index 3309b0527..a851fe6b2 100644 --- a/openfga/auth_model.go +++ b/openfga/auth_model.go @@ -1,3 +1,5 @@ +// Copyright 2024 Canonical Ltd. + // This package exists to hold JIMM's OpenFGA authorisation model. // It embeds the auth model and provides it for tests. package openfga