Skip to content

Commit

Permalink
p/a/rewrite,c/k/app: rename attributes generators
Browse files Browse the repository at this point in the history
  • Loading branch information
ibihim committed Jul 10, 2023
1 parent 66ca64c commit 7df10fa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions cmd/kube-rbac-proxy/app/kube-rbac-proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,15 +326,15 @@ func setupAuthorizer(krbInfo *server.KubeRBACProxyInfo, delegatedAuthz *serverco
var attrsGenerator rewrite.AttributesGenerator
switch {
case krbInfo.Authorization.ResourceAttributes != nil && krbInfo.Authorization.Rewrites == nil:
attrsGenerator = rewrite.NewBoundAttributesGenerator(
attrsGenerator = rewrite.NewResourceAttributesGenerator(
krbInfo.Authorization.ResourceAttributes,
)
case krbInfo.Authorization.ResourceAttributes != nil && krbInfo.Authorization.Rewrites != nil:
attrsGenerator = rewrite.NewRewritingAttributesGenerator(
attrsGenerator = rewrite.NewTemplatedResourceAttributesGenerator(
krbInfo.Authorization.ResourceAttributes,
)
default:
attrsGenerator = &rewrite.DefaultAttributesGenerator{}
attrsGenerator = &rewrite.NonResourceAttributesGenerator{}
}

rewritingAuthorizer := rewrite.NewRewritingAuthorizer(
Expand Down
16 changes: 8 additions & 8 deletions pkg/authorization/rewrite/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ type AttributesGenerator interface {
Generate(context.Context, authorizer.Attributes) []authorizer.Attributes
}

// DefaultAttributesGenerator reduces a given attribute to user and http based
// NonResourceAttributesGenerator reduces a given attribute to user and http based
// attributes.
type DefaultAttributesGenerator struct{}
type NonResourceAttributesGenerator struct{}

var _ AttributesGenerator = &DefaultAttributesGenerator{}
var _ AttributesGenerator = &NonResourceAttributesGenerator{}

// Generate reduces the original attributes to user and http based attributes.
func (d *DefaultAttributesGenerator) Generate(ctx context.Context, attr authorizer.Attributes) []authorizer.Attributes {
func (d *NonResourceAttributesGenerator) Generate(ctx context.Context, attr authorizer.Attributes) []authorizer.Attributes {
return []authorizer.Attributes{
authorizer.AttributesRecord{
User: attr.GetUser(),
Expand All @@ -56,8 +56,8 @@ type BoundAttributesGenerator struct {

var _ AttributesGenerator = &BoundAttributesGenerator{}

// NewBoundAttributesGenerator creates a BoundAttributesGenerator.
func NewBoundAttributesGenerator(attributes *ResourceAttributes) *BoundAttributesGenerator {
// NewResourceAttributesGenerator creates a BoundAttributesGenerator.
func NewResourceAttributesGenerator(attributes *ResourceAttributes) *BoundAttributesGenerator {
return &BoundAttributesGenerator{
attributes: attributes,
}
Expand Down Expand Up @@ -99,8 +99,8 @@ type RewritingAttributesGenerator struct {

var _ AttributesGenerator = &RewritingAttributesGenerator{}

// NewRewritingAttributesGenerator returns a RewritingAttributesGenerator.
func NewRewritingAttributesGenerator(attributes *ResourceAttributes) *RewritingAttributesGenerator {
// NewTemplatedResourceAttributesGenerator returns a RewritingAttributesGenerator.
func NewTemplatedResourceAttributesGenerator(attributes *ResourceAttributes) *RewritingAttributesGenerator {
return &RewritingAttributesGenerator{
attributes: attributes,

Expand Down
6 changes: 3 additions & 3 deletions pkg/authorization/rewrite/attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

func TestDefaultAttributesGenerator(t *testing.T) {
generator := &rewrite.DefaultAttributesGenerator{}
generator := &rewrite.NonResourceAttributesGenerator{}
testCases := []struct {
name string
attributes authorizer.AttributesRecord
Expand Down Expand Up @@ -242,7 +242,7 @@ func TestBoundAttributesGenerator(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
attrGen := rewrite.NewBoundAttributesGenerator(boundResource)
attrGen := rewrite.NewResourceAttributesGenerator(boundResource)
results := attrGen.Generate(context.Background(), tc.input)
if len(results) != 1 {
t.Errorf("Expected 1 generated attribute, but got %d", len(results))
Expand Down Expand Up @@ -347,7 +347,7 @@ func TestRewritingAttributesGenerator(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx := context.Background()
ctx = rewrite.WithKubeRBACProxyParams(ctx, tc.params)
attrGen := rewrite.NewRewritingAttributesGenerator(templateResource)
attrGen := rewrite.NewTemplatedResourceAttributesGenerator(templateResource)
results := attrGen.Generate(ctx, tc.input)
if len(results) != len(tc.params) {
t.Errorf(
Expand Down

0 comments on commit 7df10fa

Please sign in to comment.