diff --git a/sam/types/channel.go b/sam/types/channel.go index 3c42791c7..14b987569 100644 --- a/sam/types/channel.go +++ b/sam/types/channel.go @@ -1,9 +1,11 @@ package types import ( - "encoding/json" - "fmt" "time" + + "encoding/json" + + "github.com/crusttech/crust/system/types" ) type ( @@ -53,19 +55,13 @@ type ( ChannelType string ) -// Scope returns permissions group that for this type -func (c *Channel) Scope() string { - return "channel" -} - -// Resource returns a RBAC resource ID for this type -func (c *Channel) Resource() string { - return fmt.Sprintf("%s:%d", c.Scope(), c.ID) -} - -// Operation returns a RBAC resource-scoped role name for an operation -func (c *Channel) Operation(name string) string { - return fmt.Sprintf("%s/%s", c.Resource(), name) +// Resource returns a system resource ID for this type +func (r *Channel) Resource() types.Resource { + return types.Resource{ + ID: r.ID, + Name: r.Name, + Scope: "channel", + } } func (c *Channel) IsValid() bool { diff --git a/sam/types/organisation.go b/sam/types/organisation.go index fedbccf30..e3f7e3a89 100644 --- a/sam/types/organisation.go +++ b/sam/types/organisation.go @@ -1,27 +1,13 @@ package types import ( - "fmt" - "github.com/crusttech/crust/system/types" ) type ( - // Organisations - Organisations represent a top-level grouping entity. There may be many organisations defined in a single deployment. - Organisation types.Organisation + // Organisations - Organisations represent a top-level grouping entity. + // There may be many organisations defined in a single deployment. + Organisation struct { + types.Organisation + } ) - -// Scope returns permissions group that for this type -func (r *Organisation) Scope() string { - return "organisation" -} - -// Resource returns a RBAC resource ID for this type -func (r *Organisation) Resource() string { - return fmt.Sprintf("%s:%d", r.Scope(), r.ID) -} - -// Operation returns a RBAC resource-scoped role name for an operation -func (r *Organisation) Operation(name string) string { - return fmt.Sprintf("%s/%s", r.Resource(), name) -} diff --git a/sam/types/permissions.go b/sam/types/permissions.go index 9705b357c..c45712385 100644 --- a/sam/types/permissions.go +++ b/sam/types/permissions.go @@ -1,15 +1,12 @@ package types import ( - "github.com/crusttech/crust/internal/rules" + "github.com/crusttech/crust/system/types" ) type ( ResourceProvider interface { - Scope() string - Resource() string - Operation(name string) string - Permissions() []rules.OperationGroup + Resource() types.Resource } ) diff --git a/sam/types/team.go b/sam/types/team.go index 5361e98ac..969ed55d1 100644 --- a/sam/types/team.go +++ b/sam/types/team.go @@ -1,26 +1,11 @@ package types import ( - "fmt" - "github.com/crusttech/crust/system/types" ) type ( - Team types.Team + Team struct { + types.Team + } ) - -// Scope returns permissions group that for this type -func (r *Team) Scope() string { - return "team" -} - -// Resource returns a RBAC resource ID for this type -func (r *Team) Resource() string { - return fmt.Sprintf("%s:%d", r.Scope(), r.ID) -} - -// Operation returns a RBAC resource-scoped role name for an operation -func (r *Team) Operation(name string) string { - return fmt.Sprintf("%s/%s", r.Resource(), name) -}