Skip to content

Commit 5585176

Browse files
authored
feat: add initial rules engine interface (#5)
1 parent 1fb3880 commit 5585176

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

internal/rules/engine.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package rules
2+
3+
import (
4+
"github.com/octopusdeploy/octopus-permissions-controller/api/v1beta1"
5+
)
6+
7+
type AgentName string
8+
9+
type Namespace string
10+
11+
type ServiceAccountName string
12+
13+
type Scope struct {
14+
Project string `json:"project"`
15+
Environment string `json:"environment"`
16+
Tenant string `json:"tenant"`
17+
Step string `json:"step"`
18+
}
19+
20+
type Rule struct {
21+
Permissions v1beta1.WorkloadServiceAccountPermissions `json:"permissions"`
22+
}
23+
24+
type Engine interface {
25+
GetServiceAccountForScope(scope Scope, agentName AgentName) (ServiceAccountName, error)
26+
AddScopeRuleset(scope Scope, rule Rule, targetNamespace Namespace) error
27+
RemoveScopeRuleset(scope Scope, rule Rule, targetNamespace Namespace) error
28+
}
29+
30+
type InMemoryEngine struct {
31+
rules map[AgentName]map[Scope]ServiceAccountName
32+
// client kubernetes.Interface
33+
}
34+
35+
func (i InMemoryEngine) GetServiceAccountForScope(scope Scope, agentName AgentName) (ServiceAccountName, error) {
36+
if agentRules, ok := i.rules[agentName]; ok {
37+
if sa, ok := agentRules[scope]; ok {
38+
return sa, nil
39+
}
40+
}
41+
return "", nil
42+
}
43+
44+
func (i InMemoryEngine) AddScopeRuleset(scope Scope, rule Rule, targetNamespace Namespace) error {
45+
// TODO: Implement me
46+
return nil
47+
}

0 commit comments

Comments
 (0)