Create module for cluster IAM adapters

This commit is contained in:
Ingo Oppermann
2023-06-07 10:02:35 +02:00
parent 08bdf752f1
commit ae84fd1d21
3 changed files with 32 additions and 26 deletions

View File

@@ -14,6 +14,7 @@ import (
apiclient "github.com/datarhei/core/v16/cluster/client" apiclient "github.com/datarhei/core/v16/cluster/client"
"github.com/datarhei/core/v16/cluster/forwarder" "github.com/datarhei/core/v16/cluster/forwarder"
clusteriam "github.com/datarhei/core/v16/cluster/iam" clusteriam "github.com/datarhei/core/v16/cluster/iam"
clusteriamadapter "github.com/datarhei/core/v16/cluster/iam/adapter"
"github.com/datarhei/core/v16/cluster/proxy" "github.com/datarhei/core/v16/cluster/proxy"
"github.com/datarhei/core/v16/cluster/raft" "github.com/datarhei/core/v16/cluster/raft"
"github.com/datarhei/core/v16/cluster/store" "github.com/datarhei/core/v16/cluster/store"
@@ -758,12 +759,12 @@ func (c *cluster) SetProcessMetadata(origin string, id app.ProcessID, key string
} }
func (c *cluster) IAM(superuser iamidentity.User, jwtRealm, jwtSecret string) (iam.IAM, error) { func (c *cluster) IAM(superuser iamidentity.User, jwtRealm, jwtSecret string) (iam.IAM, error) {
policyAdapter, err := clusteriam.NewPolicyAdapter(c.store) policyAdapter, err := clusteriamadapter.NewPolicyAdapter(c.store)
if err != nil { if err != nil {
return nil, fmt.Errorf("cluster policy adapter: %w", err) return nil, fmt.Errorf("cluster policy adapter: %w", err)
} }
identityAdapter, err := clusteriam.NewIdentityAdapter(c.store) identityAdapter, err := clusteriamadapter.NewIdentityAdapter(c.store)
if err != nil { if err != nil {
return nil, fmt.Errorf("cluster identitry adapter: %w", err) return nil, fmt.Errorf("cluster identitry adapter: %w", err)
} }

View File

@@ -0,0 +1,28 @@
package adapter
import (
"github.com/datarhei/core/v16/cluster/store"
iamidentity "github.com/datarhei/core/v16/iam/identity"
)
type identityAdapter struct {
store store.Store
}
func NewIdentityAdapter(store store.Store) (iamidentity.Adapter, error) {
a := &identityAdapter{
store: store,
}
return a, nil
}
func (a *identityAdapter) LoadIdentities() ([]iamidentity.User, error) {
users := a.store.UserList()
return users.Users, nil
}
func (a *identityAdapter) SaveIdentities([]iamidentity.User) error {
return nil
}

View File

@@ -1,4 +1,4 @@
package iam package adapter
import ( import (
"strings" "strings"
@@ -6,7 +6,6 @@ import (
"github.com/datarhei/core/v16/cluster/store" "github.com/datarhei/core/v16/cluster/store"
iamaccess "github.com/datarhei/core/v16/iam/access" iamaccess "github.com/datarhei/core/v16/iam/access"
iamidentity "github.com/datarhei/core/v16/iam/identity"
"github.com/casbin/casbin/v2/model" "github.com/casbin/casbin/v2/model"
) )
@@ -101,25 +100,3 @@ func (a *policyAdapter) HasDomain(name string) bool {
return ok return ok
} }
type identityAdapter struct {
store store.Store
}
func NewIdentityAdapter(store store.Store) (iamidentity.Adapter, error) {
a := &identityAdapter{
store: store,
}
return a, nil
}
func (a *identityAdapter) LoadIdentities() ([]iamidentity.User, error) {
users := a.store.UserList()
return users.Users, nil
}
func (a *identityAdapter) SaveIdentities([]iamidentity.User) error {
return nil
}