Skip to content
Draft
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
70 changes: 45 additions & 25 deletions generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"strings"

sprig "github.com/go-task/slim-sprig/v3"
v1 "github.com/metal-stack/api/go/metalstack/api/v2"
v2 "github.com/metal-stack/api/go/metalstack/api/v2"
"github.com/metal-stack/api/go/permissions"
"github.com/metal-stack/api/go/tests/protoparser"

Expand Down Expand Up @@ -106,8 +106,8 @@ func servicePermissions(root string) (*permissions.ServicePermissions, error) {
}
methods = permissions.Methods{
// Allow service reflection to list available methods
serverReflectionInfov1alpha1: true,
serverReflectionInfo: true,
serverReflectionInfov1alpha1: struct{}{},
serverReflectionInfo: struct{}{},
}
visibility = permissions.Visibility{
Public: map[string]bool{
Expand Down Expand Up @@ -149,55 +149,75 @@ func servicePermissions(root string) (*permissions.ServicePermissions, error) {
auditable[methodName] = true
// Tenant
switch role := *methodOpt.IdentifierValue; role {
case v1.TenantRole_TENANT_ROLE_OWNER.String(), v1.TenantRole_TENANT_ROLE_EDITOR.String(), v1.TenantRole_TENANT_ROLE_VIEWER.String(), v1.TenantRole_TENANT_ROLE_GUEST.String():
roles.Tenant[role] = append(roles.Tenant[role], methodName)
case v2.TenantRole_TENANT_ROLE_OWNER.String(), v2.TenantRole_TENANT_ROLE_EDITOR.String(), v2.TenantRole_TENANT_ROLE_VIEWER.String(), v2.TenantRole_TENANT_ROLE_GUEST.String():
apirole := v2.TenantRole(v2.TenantRole_value[role])
if methods := roles.Tenant[apirole]; methods == nil {
roles.Tenant[apirole] = permissions.Methods{}
}
roles.Tenant[apirole][methodName] = struct{}{}
visibility.Tenant[methodName] = true
case v1.TenantRole_TENANT_ROLE_UNSPECIFIED.String():
case v2.TenantRole_TENANT_ROLE_UNSPECIFIED.String():
// noop
// Project
case v1.ProjectRole_PROJECT_ROLE_OWNER.String(), v1.ProjectRole_PROJECT_ROLE_EDITOR.String(), v1.ProjectRole_PROJECT_ROLE_VIEWER.String():
roles.Project[role] = append(roles.Project[role], methodName)
case v2.ProjectRole_PROJECT_ROLE_OWNER.String(), v2.ProjectRole_PROJECT_ROLE_EDITOR.String(), v2.ProjectRole_PROJECT_ROLE_VIEWER.String():
apirole := v2.ProjectRole(v2.ProjectRole_value[role])
if methods := roles.Project[apirole]; methods == nil {
roles.Project[apirole] = permissions.Methods{}
}
roles.Project[apirole][methodName] = struct{}{}
visibility.Project[methodName] = true
case v1.ProjectRole_PROJECT_ROLE_UNSPECIFIED.String():
case v2.ProjectRole_PROJECT_ROLE_UNSPECIFIED.String():
// noop
// Admin
case v1.AdminRole_ADMIN_ROLE_EDITOR.String(), v1.AdminRole_ADMIN_ROLE_VIEWER.String():
roles.Admin[role] = append(roles.Admin[role], methodName)
case v2.AdminRole_ADMIN_ROLE_EDITOR.String(), v2.AdminRole_ADMIN_ROLE_VIEWER.String():
apirole := v2.AdminRole(v2.AdminRole_value[role])
if methods := roles.Admin[apirole]; methods == nil {
roles.Admin[apirole] = permissions.Methods{}
}
roles.Admin[apirole][methodName] = struct{}{}
visibility.Admin[methodName] = true
case v1.AdminRole_ADMIN_ROLE_UNSPECIFIED.String():
case v2.AdminRole_ADMIN_ROLE_UNSPECIFIED.String():
// noop
// Infra
case v1.InfraRole_INFRA_ROLE_EDITOR.String(), v1.InfraRole_INFRA_ROLE_VIEWER.String():
roles.Infra[role] = append(roles.Infra[role], methodName)
case v2.InfraRole_INFRA_ROLE_EDITOR.String(), v2.InfraRole_INFRA_ROLE_VIEWER.String():
apirole := v2.InfraRole(v2.InfraRole_value[role])
if methods := roles.Infra[apirole]; methods == nil {
roles.Infra[apirole] = permissions.Methods{}
}
roles.Infra[apirole][methodName] = struct{}{}
visibility.Infra[methodName] = true
case v1.InfraRole_INFRA_ROLE_UNSPECIFIED.String():
case v2.InfraRole_INFRA_ROLE_UNSPECIFIED.String():
// noop
// Machine
case v1.MachineRole_MACHINE_ROLE_EDITOR.String(), v1.MachineRole_MACHINE_ROLE_VIEWER.String():
roles.Machine[role] = append(roles.Machine[role], methodName)
case v2.MachineRole_MACHINE_ROLE_EDITOR.String(), v2.MachineRole_MACHINE_ROLE_VIEWER.String():
apirole := v2.MachineRole(v2.MachineRole_value[role])
if methods := roles.Machine[apirole]; methods == nil {
roles.Machine[apirole] = permissions.Methods{}
}
roles.Machine[apirole][methodName] = struct{}{}
visibility.Machine[methodName] = true
case v1.MachineRole_MACHINE_ROLE_UNSPECIFIED.String():
case v2.MachineRole_MACHINE_ROLE_UNSPECIFIED.String():
// noop
// Visibility
case v1.Visibility_VISIBILITY_PUBLIC.String():
case v2.Visibility_VISIBILITY_PUBLIC.String():
visibility.Public[methodName] = true
case v1.Visibility_VISIBILITY_SELF.String():
case v2.Visibility_VISIBILITY_SELF.String():
visibility.Self[methodName] = true
case v1.Visibility_VISIBILITY_UNSPECIFIED.String():
case v2.Visibility_VISIBILITY_UNSPECIFIED.String():
// noop
// Auditable
case v1.Auditing_AUDITING_EXCLUDED.String():
case v2.Auditing_AUDITING_EXCLUDED.String():
auditable[methodName] = false
case v1.Auditing_AUDITING_INCLUDED.String():
case v2.Auditing_AUDITING_INCLUDED.String():
auditable[methodName] = true
case v1.Auditing_AUDITING_UNSPECIFIED.String():
case v2.Auditing_AUDITING_UNSPECIFIED.String():
auditable[methodName] = true
// noop
default:
return nil, fmt.Errorf("unknown method identifier value detected:%s", *methodOpt.IdentifierValue)

}
methods[methodName] = true
methods[methodName] = struct{}{}
}
}
}
Expand Down
33 changes: 17 additions & 16 deletions generate/go_servicepermissions.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package permissions

import (
apiv2 "github.com/metal-stack/api/go/metalstack/api/v2"
"connectrpc.com/connect"
)

Expand All @@ -18,51 +19,51 @@ func GetServicePermissions() *ServicePermissions {
Roles: Roles{
Admin: Admin{
{{- range $role, $methods := .Roles.Admin }}
"{{ $role }}": []string{
{{- range $method := $methods }}
"{{ $method }}",
apiv2.AdminRole_{{ $role }}: map[string]struct{}{
{{- range $method,$v := $methods }}
"{{ $method }}":{{ $v }},
{{- end }}
},
{{- end }}
},
Infra: Infra{
{{- range $role, $methods := .Roles.Infra }}
"{{ $role }}": []string{
{{- range $method := $methods }}
"{{ $method }}",
apiv2.InfraRole_{{ $role }}: map[string]struct{}{
{{- range $method,$v := $methods }}
"{{ $method }}":{{ $v }},
{{- end }}
},
{{- end }}
},
Machine: Machine{
{{- range $role, $methods := .Roles.Machine }}
"{{ $role }}": []string{
{{- range $method := $methods }}
"{{ $method }}",
apiv2.MachineRole_{{ $role }}: map[string]struct{}{
{{- range $method,$v := $methods }}
"{{ $method }}":{{ $v }},
{{- end }}
},
{{- end }}
},
Tenant: Tenant{
{{- range $role, $methods := .Roles.Tenant }}
"{{ $role }}": []string{
{{- range $method := $methods }}
"{{ $method }}",
apiv2.TenantRole_{{ $role }}: map[string]struct{}{
{{- range $method,$v := $methods }}
"{{ $method }}":{{ $v }},
{{- end }}
},
{{- end }}
},
Project: Project{
{{- range $role, $methods := .Roles.Project }}
"{{ $role }}": []string{
{{- range $method := $methods }}
"{{ $method }}",
apiv2.ProjectRole_{{ $role }}: map[string]struct{}{
{{- range $method,$v := $methods }}
"{{ $method }}":{{ $v }},
{{- end }}
},
{{- end }}
},
},
Methods: map[string]bool{
Methods: map[string]struct{}{
{{- range $key, $value := .Methods }}
"{{ $key }}": {{ $value }} ,
{{- end }}
Expand Down
14 changes: 8 additions & 6 deletions go/permissions/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package permissions

import (
_ "embed"

apiv2 "github.com/metal-stack/api/go/metalstack/api/v2"
)

type (
Expand All @@ -13,16 +15,16 @@ type (
Services []string `json:"services,omitempty"`
}

Methods map[string]bool
Methods map[string]struct{}

Chargeable map[string]bool
Auditable map[string]bool

Admin map[string][]string
Infra map[string][]string
Machine map[string][]string
Tenant map[string][]string
Project map[string][]string
Admin map[apiv2.AdminRole]Methods
Infra map[apiv2.InfraRole]Methods
Machine map[apiv2.MachineRole]Methods
Tenant map[apiv2.TenantRole]Methods
Project map[apiv2.ProjectRole]Methods

// Roles
Roles struct {
Expand Down
Loading
Loading