Skip to content

Commit 4ca612f

Browse files
authored
add namespace permission originator id (#48)
For [ENG-1758](https://linear.app/pomerium/issue/ENG-1758/terraform-add-originator-id)
1 parent c827bb4 commit 4ca612f

File tree

4 files changed

+49
-8
lines changed

4 files changed

+49
-8
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/hashicorp/terraform-plugin-go v0.25.0
1212
github.com/hashicorp/terraform-plugin-log v0.9.0
1313
github.com/iancoleman/strcase v0.3.0
14-
github.com/pomerium/enterprise-client-go v0.28.1-0.20250306195545-d8048381f24f
14+
github.com/pomerium/enterprise-client-go v0.28.1-0.20250310151140-91b9684b1537
1515
github.com/pomerium/pomerium v0.28.1-0.20250218200206-b9fd926618e2
1616
github.com/rs/zerolog v1.33.0
1717
github.com/stretchr/testify v1.10.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
7878
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7979
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
8080
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
81-
github.com/pomerium/enterprise-client-go v0.28.1-0.20250306195545-d8048381f24f h1:yaLu3zRz02Y0lPrIVeoVtYhqzHBcuRGZsiaKNPgOhBQ=
82-
github.com/pomerium/enterprise-client-go v0.28.1-0.20250306195545-d8048381f24f/go.mod h1:36+cCZpNgJQb5B1+y4rCcyQ8CM865NBNmEAQFS+73DQ=
81+
github.com/pomerium/enterprise-client-go v0.28.1-0.20250310151140-91b9684b1537 h1:5zM4pm7dPXWMx2Eq0G7XuoQJV5gZqMbjiWjRq6YH5Ws=
82+
github.com/pomerium/enterprise-client-go v0.28.1-0.20250310151140-91b9684b1537/go.mod h1:36+cCZpNgJQb5B1+y4rCcyQ8CM865NBNmEAQFS+73DQ=
8383
github.com/pomerium/pomerium v0.28.1-0.20250218200206-b9fd926618e2 h1:UtyGKmmFs/DVuvhOUeFowruCv+xObqAbqNmPqhMZ88o=
8484
github.com/pomerium/pomerium v0.28.1-0.20250218200206-b9fd926618e2/go.mod h1:8Uf1ya/wSjJyeUo5X4TqctlrYxbc5iPfFG18x1t0Deo=
8585
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM=

internal/provider/namespace_permission_model.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package provider
33
import (
44
"github.com/hashicorp/terraform-plugin-framework/diag"
55
"github.com/hashicorp/terraform-plugin-framework/types"
6+
67
"github.com/pomerium/enterprise-client-go/pb"
78
)
89

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

3738
pbNamespacePermission := &pb.NamespacePermission{
38-
Id: src.ID.ValueString(),
39-
NamespaceId: src.NamespaceID.ValueString(),
40-
Role: src.Role.ValueString(),
41-
SubjectId: src.SubjectID.ValueString(),
42-
SubjectType: src.SubjectType.ValueString(),
39+
OriginatorId: OriginatorID,
40+
Id: src.ID.ValueString(),
41+
NamespaceId: src.NamespaceID.ValueString(),
42+
Role: src.Role.ValueString(),
43+
SubjectId: src.SubjectID.ValueString(),
44+
SubjectType: src.SubjectType.ValueString(),
4345
}
4446

4547
return pbNamespacePermission, diagnostics
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package provider_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/google/go-cmp/cmp"
7+
"github.com/hashicorp/terraform-plugin-framework/types"
8+
"github.com/stretchr/testify/assert"
9+
"google.golang.org/protobuf/testing/protocmp"
10+
11+
"github.com/pomerium/enterprise-client-go/pb"
12+
"github.com/pomerium/enterprise-terraform-provider/internal/provider"
13+
)
14+
15+
func TestConvertNamespacePermissionToPB(t *testing.T) {
16+
t.Parallel()
17+
18+
expected := &pb.NamespacePermission{
19+
Id: "NAMESPACE_PERMISSION_ID",
20+
NamespaceId: "NAMESPACE_ID",
21+
SubjectType: "SUBJECT_TYPE",
22+
SubjectId: "SUBJECT_ID",
23+
Role: "ROLE",
24+
OriginatorId: "terraform",
25+
}
26+
actual, diag := provider.ConvertNamespacePermissionToPB(&provider.NamespacePermissionModel{
27+
ID: types.StringValue("NAMESPACE_PERMISSION_ID"),
28+
NamespaceID: types.StringValue("NAMESPACE_ID"),
29+
Role: types.StringValue("ROLE"),
30+
SubjectID: types.StringValue("SUBJECT_ID"),
31+
SubjectType: types.StringValue("SUBJECT_TYPE"),
32+
})
33+
if !assert.Equal(t, 0, diag.ErrorsCount()) {
34+
t.Log(diag.Errors())
35+
}
36+
if diff := cmp.Diff(expected, actual, protocmp.Transform()); diff != "" {
37+
t.Errorf("unexpected difference: %s", diff)
38+
}
39+
}

0 commit comments

Comments
 (0)