Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add namespace permission originator id #48

Merged
merged 1 commit into from
Mar 11, 2025
Merged
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ require (
github.com/hashicorp/terraform-plugin-go v0.25.0
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/iancoleman/strcase v0.3.0
github.com/pomerium/enterprise-client-go v0.28.1-0.20250306195545-d8048381f24f
github.com/pomerium/enterprise-client-go v0.28.1-0.20250310151140-91b9684b1537
github.com/pomerium/pomerium v0.28.1-0.20250218200206-b9fd926618e2
github.com/rs/zerolog v1.33.0
github.com/stretchr/testify v1.10.0
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -78,8 +78,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pomerium/enterprise-client-go v0.28.1-0.20250306195545-d8048381f24f h1:yaLu3zRz02Y0lPrIVeoVtYhqzHBcuRGZsiaKNPgOhBQ=
github.com/pomerium/enterprise-client-go v0.28.1-0.20250306195545-d8048381f24f/go.mod h1:36+cCZpNgJQb5B1+y4rCcyQ8CM865NBNmEAQFS+73DQ=
github.com/pomerium/enterprise-client-go v0.28.1-0.20250310151140-91b9684b1537 h1:5zM4pm7dPXWMx2Eq0G7XuoQJV5gZqMbjiWjRq6YH5Ws=
github.com/pomerium/enterprise-client-go v0.28.1-0.20250310151140-91b9684b1537/go.mod h1:36+cCZpNgJQb5B1+y4rCcyQ8CM865NBNmEAQFS+73DQ=
github.com/pomerium/pomerium v0.28.1-0.20250218200206-b9fd926618e2 h1:UtyGKmmFs/DVuvhOUeFowruCv+xObqAbqNmPqhMZ88o=
github.com/pomerium/pomerium v0.28.1-0.20250218200206-b9fd926618e2/go.mod h1:8Uf1ya/wSjJyeUo5X4TqctlrYxbc5iPfFG18x1t0Deo=
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM=
12 changes: 7 additions & 5 deletions internal/provider/namespace_permission_model.go
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ package provider
import (
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"

"github.com/pomerium/enterprise-client-go/pb"
)

@@ -35,11 +36,12 @@ func ConvertNamespacePermissionToPB(
var diagnostics diag.Diagnostics

pbNamespacePermission := &pb.NamespacePermission{
Id: src.ID.ValueString(),
NamespaceId: src.NamespaceID.ValueString(),
Role: src.Role.ValueString(),
SubjectId: src.SubjectID.ValueString(),
SubjectType: src.SubjectType.ValueString(),
OriginatorId: OriginatorID,
Id: src.ID.ValueString(),
NamespaceId: src.NamespaceID.ValueString(),
Role: src.Role.ValueString(),
SubjectId: src.SubjectID.ValueString(),
SubjectType: src.SubjectType.ValueString(),
}

return pbNamespacePermission, diagnostics
39 changes: 39 additions & 0 deletions internal/provider/namespace_permission_model_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package provider_test

import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/stretchr/testify/assert"
"google.golang.org/protobuf/testing/protocmp"

"github.com/pomerium/enterprise-client-go/pb"
"github.com/pomerium/enterprise-terraform-provider/internal/provider"
)

func TestConvertNamespacePermissionToPB(t *testing.T) {
t.Parallel()

expected := &pb.NamespacePermission{
Id: "NAMESPACE_PERMISSION_ID",
NamespaceId: "NAMESPACE_ID",
SubjectType: "SUBJECT_TYPE",
SubjectId: "SUBJECT_ID",
Role: "ROLE",
OriginatorId: "terraform",
}
actual, diag := provider.ConvertNamespacePermissionToPB(&provider.NamespacePermissionModel{
ID: types.StringValue("NAMESPACE_PERMISSION_ID"),
NamespaceID: types.StringValue("NAMESPACE_ID"),
Role: types.StringValue("ROLE"),
SubjectID: types.StringValue("SUBJECT_ID"),
SubjectType: types.StringValue("SUBJECT_TYPE"),
})
if !assert.Equal(t, 0, diag.ErrorsCount()) {
t.Log(diag.Errors())
}
if diff := cmp.Diff(expected, actual, protocmp.Transform()); diff != "" {
t.Errorf("unexpected difference: %s", diff)
}
}