Skip to content

Commit 5a6db19

Browse files
committed
exclude idp options for now
1 parent 8f4b0bd commit 5a6db19

File tree

3 files changed

+0
-92
lines changed

3 files changed

+0
-92
lines changed

internal/provider/convert.go

-32
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ package provider
22

33
import (
44
"context"
5-
"fmt"
65
"time"
76

87
"github.com/hashicorp/terraform-plugin-framework/attr"
98
"github.com/hashicorp/terraform-plugin-framework/diag"
109
"github.com/hashicorp/terraform-plugin-framework/types"
1110
"github.com/pomerium/enterprise-client-go/pb"
1211
"google.golang.org/protobuf/types/known/durationpb"
13-
"google.golang.org/protobuf/types/known/structpb"
1412
)
1513

1614
// StringP returns a pointer to the string value if not null, otherwise nil
@@ -133,33 +131,3 @@ func FromDurationP(d *durationpb.Duration) types.String {
133131
}
134132
return types.StringValue(d.AsDuration().String())
135133
}
136-
137-
// ToStruct converts a types.Map to a structpb.Struct and handles diagnostics internally
138-
func ToStruct(ctx context.Context, dst **structpb.Struct, m types.Map, field string, diagnostics *diag.Diagnostics) {
139-
if m.IsNull() {
140-
*dst = nil
141-
return
142-
}
143-
144-
var options map[string]interface{}
145-
diagnostics.Append(m.ElementsAs(ctx, &options, false)...)
146-
if !diagnostics.HasError() {
147-
if s, err := structpb.NewStruct(options); err == nil {
148-
*dst = s
149-
} else {
150-
diagnostics.AddError("invalid "+field, err.Error())
151-
}
152-
}
153-
}
154-
155-
// FromStruct converts a structpb.Struct to a types.Map
156-
func FromStruct(s *structpb.Struct) types.Map {
157-
if s == nil {
158-
return types.MapNull(types.StringType)
159-
}
160-
elements := make(map[string]attr.Value)
161-
for k, v := range s.AsMap() {
162-
elements[k] = types.StringValue(fmt.Sprint(v))
163-
}
164-
return types.MapValueMust(types.StringType, elements)
165-
}

internal/provider/convert_test.go

-58
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/stretchr/testify/assert"
1414
"github.com/stretchr/testify/require"
1515
"google.golang.org/protobuf/types/known/durationpb"
16-
"google.golang.org/protobuf/types/known/structpb"
1716
)
1817

1918
func TestStringP(t *testing.T) {
@@ -152,63 +151,6 @@ func TestFromDurationP(t *testing.T) {
152151
}
153152
}
154153

155-
func TestToStruct(t *testing.T) {
156-
ctx := context.Background()
157-
tests := []struct {
158-
name string
159-
input types.Map
160-
expectError bool
161-
validate func(*testing.T, *structpb.Struct)
162-
}{
163-
{
164-
name: "null map",
165-
input: types.MapNull(types.StringType),
166-
validate: func(t *testing.T, s *structpb.Struct) {
167-
assert.Nil(t, s)
168-
},
169-
},
170-
{
171-
name: "valid map",
172-
input: types.MapValueMust(types.StringType, map[string]attr.Value{
173-
"key1": types.StringValue("value1"),
174-
"key2": types.StringValue("value2"),
175-
}),
176-
validate: func(t *testing.T, s *structpb.Struct) {
177-
require.NotNil(t, s)
178-
require.NotNil(t, s.Fields)
179-
assert.Equal(t, "value1", s.Fields["key1"].GetStringValue())
180-
assert.Equal(t, "value2", s.Fields["key2"].GetStringValue())
181-
},
182-
},
183-
{
184-
name: "empty map",
185-
input: types.MapValueMust(types.StringType, map[string]attr.Value{}),
186-
validate: func(t *testing.T, s *structpb.Struct) {
187-
require.NotNil(t, s)
188-
assert.Empty(t, s.Fields)
189-
},
190-
},
191-
}
192-
193-
for _, tt := range tests {
194-
t.Run(tt.name, func(t *testing.T) {
195-
var result *structpb.Struct
196-
diagnostics := diag.Diagnostics{}
197-
provider.ToStruct(ctx, &result, tt.input, "test", &diagnostics)
198-
199-
if tt.expectError {
200-
assert.True(t, diagnostics.HasError())
201-
return
202-
}
203-
204-
assert.False(t, diagnostics.HasError())
205-
if tt.validate != nil {
206-
tt.validate(t, result)
207-
}
208-
})
209-
}
210-
}
211-
212154
func TestToStringList(t *testing.T) {
213155
ctx := context.Background()
214156
tests := []struct {

internal/provider/settings_model.go

-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ func ConvertSettingsToPB(
125125
pbSettings.GrpcInsecure = BoolP(src.GRPCInsecure)
126126
pbSettings.HttpRedirectAddr = StringP(src.HTTPRedirectAddr)
127127
pbSettings.IdentityProvider = StringP(src.IdentityProvider)
128-
ToStruct(ctx, &pbSettings.IdentityProviderOptions, src.IdentityProviderOptions, "identity_provider_options", &diagnostics)
129128
ToDurationP(&pbSettings.IdentityProviderRefreshInterval, src.IdentityProviderRefreshInterval, "identity_provider_refresh_interval", &diagnostics)
130129
ToDurationP(&pbSettings.IdentityProviderRefreshTimeout, src.IdentityProviderRefreshTimeout, "identity_provider_refresh_timeout", &diagnostics)
131130
pbSettings.IdpClientId = StringP(src.IdpClientID)
@@ -206,7 +205,6 @@ func ConvertSettingsFromPB(
206205
dst.GRPCInsecure = types.BoolPointerValue(src.GrpcInsecure)
207206
dst.HTTPRedirectAddr = types.StringPointerValue(src.HttpRedirectAddr)
208207
dst.IdentityProvider = types.StringPointerValue(src.IdentityProvider)
209-
dst.IdentityProviderOptions = FromStruct(src.IdentityProviderOptions)
210208
dst.IdentityProviderRefreshInterval = FromDurationP(src.IdentityProviderRefreshInterval)
211209
dst.IdentityProviderRefreshTimeout = FromDurationP(src.IdentityProviderRefreshTimeout)
212210
dst.IdpClientID = types.StringPointerValue(src.IdpClientId)

0 commit comments

Comments
 (0)