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

Update reading test auth model #1240

Merged
merged 5 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 2 additions & 42 deletions internal/jimmtest/openfga.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"io/fs"
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"
"sync"

Expand All @@ -20,6 +15,7 @@ import (

"github.com/canonical/jimm/internal/errors"
"github.com/canonical/jimm/internal/openfga"
auth_model "github.com/canonical/jimm/openfga"
)

var (
Expand All @@ -39,44 +35,8 @@ 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"))
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
}
Expand Down
12 changes: 12 additions & 0 deletions openfga/auth_model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2024 Canonical Ltd.

// This package exists to hold JIMM's OpenFGA authorisation model.
kian99 marked this conversation as resolved.
Show resolved Hide resolved
// It embeds the auth model and provides it for tests.
package openfga

import (
_ "embed"
)

//go:embed authorisation_model.json
var AuthModelFile []byte
Loading