Skip to content
Merged
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
6 changes: 6 additions & 0 deletions protocol/codegen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ var mappings = []helperMapping{
ProtoImportPath: "github.com/opentdf/platform/protocol/go/authorization/v2",
ProtoImportAlias: "authorizationv2",
},
{
Source: "policy",
Target: "policy",
ProtoImportPath: "github.com/opentdf/platform/protocol/go/policy",
ProtoImportAlias: "policy",
},
}

const generatedHeader = "// Code generated by protocol/codegen. DO NOT EDIT.\n\n"
Expand Down
61 changes: 61 additions & 0 deletions protocol/go/internal/policy/enums.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package policy

import (
"github.com/opentdf/platform/protocol/go/common"
policy "github.com/opentdf/platform/protocol/go/policy"
)

// Shorthand constants for SubjectMappingOperatorEnum.
//
// Example:
//
// condition := &policy.Condition{
// SubjectExternalSelectorValue: ".email",
// Operator: policy.OperatorInContains,
// SubjectExternalValues: []string{"@example.com"},
// }
const (
OperatorIn = policy.SubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_IN
OperatorNotIn = policy.SubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_NOT_IN
OperatorInContains = policy.SubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_IN_CONTAINS
)

// Shorthand constants for ConditionBooleanTypeEnum.
//
// Example:
//
// group := &policy.ConditionGroup{
// BooleanOperator: policy.BooleanAnd,
// Conditions: conditions,
// }
const (
BooleanAnd = policy.ConditionBooleanTypeEnum_CONDITION_BOOLEAN_TYPE_ENUM_AND
BooleanOr = policy.ConditionBooleanTypeEnum_CONDITION_BOOLEAN_TYPE_ENUM_OR
)

// Shorthand constants for AttributeRuleTypeEnum.
//
// Example:
//
// req := &attributes.CreateAttributeRequest{
// Name: "clearance",
// Rule: policy.RuleHierarchy,
// }
const (
RuleAllOf = policy.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_ALL_OF
RuleAnyOf = policy.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_ANY_OF
RuleHierarchy = policy.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_HIERARCHY
)

// Shorthand constants for ActiveStateEnum (from the common package).
//
// Example:
//
// req := &attributes.ListAttributesRequest{
// State: policy.StateActive,
// }
const (
StateActive = common.ActiveStateEnum_ACTIVE_STATE_ENUM_ACTIVE
StateInactive = common.ActiveStateEnum_ACTIVE_STATE_ENUM_INACTIVE
StateAny = common.ActiveStateEnum_ACTIVE_STATE_ENUM_ANY
)
53 changes: 53 additions & 0 deletions protocol/go/internal/policy/enums_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package policy

import (
"testing"

"github.com/opentdf/platform/protocol/go/common"
policyproto "github.com/opentdf/platform/protocol/go/policy"
)

func TestOperatorConstants(t *testing.T) {
if OperatorIn != policyproto.SubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_IN {
t.Errorf("OperatorIn = %d, want %d", OperatorIn, policyproto.SubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_IN)
}
if OperatorNotIn != policyproto.SubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_NOT_IN {
t.Errorf("OperatorNotIn = %d, want %d", OperatorNotIn, policyproto.SubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_NOT_IN)
}
if OperatorInContains != policyproto.SubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_IN_CONTAINS {
t.Errorf("OperatorInContains = %d, want %d", OperatorInContains, policyproto.SubjectMappingOperatorEnum_SUBJECT_MAPPING_OPERATOR_ENUM_IN_CONTAINS)
}
}

func TestBooleanConstants(t *testing.T) {
if BooleanAnd != policyproto.ConditionBooleanTypeEnum_CONDITION_BOOLEAN_TYPE_ENUM_AND {
t.Errorf("BooleanAnd = %d, want %d", BooleanAnd, policyproto.ConditionBooleanTypeEnum_CONDITION_BOOLEAN_TYPE_ENUM_AND)
}
if BooleanOr != policyproto.ConditionBooleanTypeEnum_CONDITION_BOOLEAN_TYPE_ENUM_OR {
t.Errorf("BooleanOr = %d, want %d", BooleanOr, policyproto.ConditionBooleanTypeEnum_CONDITION_BOOLEAN_TYPE_ENUM_OR)
}
}

func TestRuleConstants(t *testing.T) {
if RuleAllOf != policyproto.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_ALL_OF {
t.Errorf("RuleAllOf = %d, want %d", RuleAllOf, policyproto.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_ALL_OF)
}
if RuleAnyOf != policyproto.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_ANY_OF {
t.Errorf("RuleAnyOf = %d, want %d", RuleAnyOf, policyproto.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_ANY_OF)
}
if RuleHierarchy != policyproto.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_HIERARCHY {
t.Errorf("RuleHierarchy = %d, want %d", RuleHierarchy, policyproto.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_HIERARCHY)
}
}

func TestStateConstants(t *testing.T) {
if StateActive != common.ActiveStateEnum_ACTIVE_STATE_ENUM_ACTIVE {
t.Errorf("StateActive = %d, want %d", StateActive, common.ActiveStateEnum_ACTIVE_STATE_ENUM_ACTIVE)
}
if StateInactive != common.ActiveStateEnum_ACTIVE_STATE_ENUM_INACTIVE {
t.Errorf("StateInactive = %d, want %d", StateInactive, common.ActiveStateEnum_ACTIVE_STATE_ENUM_INACTIVE)
}
if StateAny != common.ActiveStateEnum_ACTIVE_STATE_ENUM_ANY {
t.Errorf("StateAny = %d, want %d", StateAny, common.ActiveStateEnum_ACTIVE_STATE_ENUM_ANY)
}
}
62 changes: 62 additions & 0 deletions protocol/go/policy/enums.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading