Skip to content

Commit

Permalink
Merge branch 'v3' of https://github.com/canonical/jimm into list-all-…
Browse files Browse the repository at this point in the history
…model-summaries-jimm
  • Loading branch information
ale8k committed Jun 18, 2024
2 parents 034e8be + c0d845a commit 82cf6fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 42 deletions.
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.
// It embeds the auth model and provides it for tests.
package openfga

import (
_ "embed"
)

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

0 comments on commit 82cf6fb

Please sign in to comment.