|
3 | 3 | package attributesources
|
4 | 4 |
|
5 | 5 | import (
|
6 |
| - "encoding/json" |
7 |
| - |
8 | 6 | "github.com/hashicorp/terraform-plugin-framework/types"
|
9 | 7 | "github.com/hashicorp/terraform-plugin-framework/types/basetypes"
|
10 | 8 | client "github.com/pingidentity/pingfederate-go-client/v1220/configurationapi"
|
11 |
| - internaljson "github.com/pingidentity/terraform-provider-pingfederate/internal/json" |
12 | 9 | internaltypes "github.com/pingidentity/terraform-provider-pingfederate/internal/types"
|
13 | 10 | )
|
14 | 11 |
|
15 |
| -func ClientStruct(attributeSourcesAttr basetypes.SetValue) ([]client.AttributeSourceAggregation, error) { |
| 12 | +func ClientStruct(attributeSourcesAttr basetypes.SetValue) []client.AttributeSourceAggregation { |
16 | 13 | attributeSourceAggregation := []client.AttributeSourceAggregation{}
|
17 | 14 | for _, source := range attributeSourcesAttr.Elements() {
|
18 | 15 | //Determine which attribute source type this is
|
19 | 16 | sourceAttrs := source.(types.Object).Attributes()
|
20 | 17 | attributeSourceInner := client.AttributeSourceAggregation{}
|
21 | 18 | if internaltypes.IsDefined(sourceAttrs["custom_attribute_source"]) {
|
22 | 19 | attributeSourceInner.CustomAttributeSource = &client.CustomAttributeSource{}
|
23 |
| - customAttributeSourceErr := json.Unmarshal([]byte(internaljson.FromValue(sourceAttrs["custom_attribute_source"], true)), attributeSourceInner.CustomAttributeSource) |
24 |
| - if customAttributeSourceErr != nil { |
25 |
| - return nil, customAttributeSourceErr |
| 20 | + customAttributeSourceAttrs := sourceAttrs["custom_attribute_source"].(types.Object).Attributes() |
| 21 | + if !customAttributeSourceAttrs["attribute_contract_fulfillment"].IsNull() && !customAttributeSourceAttrs["attribute_contract_fulfillment"].IsUnknown() { |
| 22 | + attributeSourceInner.CustomAttributeSource.AttributeContractFulfillment = &map[string]client.AttributeFulfillmentValue{} |
| 23 | + for key, attributeContractFulfillmentElement := range customAttributeSourceAttrs["attribute_contract_fulfillment"].(types.Map).Elements() { |
| 24 | + attributeContractFulfillmentValue := client.AttributeFulfillmentValue{} |
| 25 | + attributeContractFulfillmentAttrs := attributeContractFulfillmentElement.(types.Object).Attributes() |
| 26 | + attributeContractFulfillmentSourceValue := client.SourceTypeIdKey{} |
| 27 | + attributeContractFulfillmentSourceAttrs := attributeContractFulfillmentAttrs["source"].(types.Object).Attributes() |
| 28 | + attributeContractFulfillmentSourceValue.Id = attributeContractFulfillmentSourceAttrs["id"].(types.String).ValueStringPointer() |
| 29 | + attributeContractFulfillmentSourceValue.Type = attributeContractFulfillmentSourceAttrs["type"].(types.String).ValueString() |
| 30 | + attributeContractFulfillmentValue.Source = attributeContractFulfillmentSourceValue |
| 31 | + attributeContractFulfillmentValue.Value = attributeContractFulfillmentAttrs["value"].(types.String).ValueString() |
| 32 | + (*attributeSourceInner.CustomAttributeSource.AttributeContractFulfillment)[key] = attributeContractFulfillmentValue |
| 33 | + } |
| 34 | + } |
| 35 | + customAttributeSourceDataStoreRefValue := client.ResourceLink{} |
| 36 | + customAttributeSourceDataStoreRefAttrs := customAttributeSourceAttrs["data_store_ref"].(types.Object).Attributes() |
| 37 | + customAttributeSourceDataStoreRefValue.Id = customAttributeSourceDataStoreRefAttrs["id"].(types.String).ValueString() |
| 38 | + attributeSourceInner.CustomAttributeSource.DataStoreRef = customAttributeSourceDataStoreRefValue |
| 39 | + attributeSourceInner.CustomAttributeSource.Description = customAttributeSourceAttrs["description"].(types.String).ValueStringPointer() |
| 40 | + if !customAttributeSourceAttrs["filter_fields"].IsNull() && !customAttributeSourceAttrs["filter_fields"].IsUnknown() { |
| 41 | + attributeSourceInner.CustomAttributeSource.FilterFields = []client.FieldEntry{} |
| 42 | + for _, filterFieldsElement := range customAttributeSourceAttrs["filter_fields"].(types.Set).Elements() { |
| 43 | + filterFieldsValue := client.FieldEntry{} |
| 44 | + filterFieldsAttrs := filterFieldsElement.(types.Object).Attributes() |
| 45 | + filterFieldsValue.Name = filterFieldsAttrs["name"].(types.String).ValueString() |
| 46 | + filterFieldsValue.Value = filterFieldsAttrs["value"].(types.String).ValueStringPointer() |
| 47 | + attributeSourceInner.CustomAttributeSource.FilterFields = append(attributeSourceInner.CustomAttributeSource.FilterFields, filterFieldsValue) |
| 48 | + } |
26 | 49 | }
|
| 50 | + attributeSourceInner.CustomAttributeSource.Id = customAttributeSourceAttrs["id"].(types.String).ValueStringPointer() |
| 51 | + attributeSourceInner.CustomAttributeSource.Type = customAttributeSourceAttrs["type"].(types.String).ValueString() |
27 | 52 | }
|
28 | 53 | if internaltypes.IsDefined(sourceAttrs["jdbc_attribute_source"]) {
|
29 | 54 | attributeSourceInner.JdbcAttributeSource = &client.JdbcAttributeSource{}
|
30 |
| - jdbcAttributeSourceErr := json.Unmarshal([]byte(internaljson.FromValue(sourceAttrs["jdbc_attribute_source"], true)), attributeSourceInner.JdbcAttributeSource) |
31 |
| - if jdbcAttributeSourceErr != nil { |
32 |
| - return nil, jdbcAttributeSourceErr |
| 55 | + jdbcAttributeSourceAttrs := sourceAttrs["jdbc_attribute_source"].(types.Object).Attributes() |
| 56 | + if !jdbcAttributeSourceAttrs["attribute_contract_fulfillment"].IsNull() && !jdbcAttributeSourceAttrs["attribute_contract_fulfillment"].IsUnknown() { |
| 57 | + attributeSourceInner.JdbcAttributeSource.AttributeContractFulfillment = &map[string]client.AttributeFulfillmentValue{} |
| 58 | + for key, attributeContractFulfillmentElement := range jdbcAttributeSourceAttrs["attribute_contract_fulfillment"].(types.Map).Elements() { |
| 59 | + attributeContractFulfillmentValue := client.AttributeFulfillmentValue{} |
| 60 | + attributeContractFulfillmentAttrs := attributeContractFulfillmentElement.(types.Object).Attributes() |
| 61 | + attributeContractFulfillmentSourceValue := client.SourceTypeIdKey{} |
| 62 | + attributeContractFulfillmentSourceAttrs := attributeContractFulfillmentAttrs["source"].(types.Object).Attributes() |
| 63 | + attributeContractFulfillmentSourceValue.Id = attributeContractFulfillmentSourceAttrs["id"].(types.String).ValueStringPointer() |
| 64 | + attributeContractFulfillmentSourceValue.Type = attributeContractFulfillmentSourceAttrs["type"].(types.String).ValueString() |
| 65 | + attributeContractFulfillmentValue.Source = attributeContractFulfillmentSourceValue |
| 66 | + attributeContractFulfillmentValue.Value = attributeContractFulfillmentAttrs["value"].(types.String).ValueString() |
| 67 | + (*attributeSourceInner.JdbcAttributeSource.AttributeContractFulfillment)[key] = attributeContractFulfillmentValue |
| 68 | + } |
| 69 | + } |
| 70 | + if !jdbcAttributeSourceAttrs["column_names"].IsNull() && !jdbcAttributeSourceAttrs["column_names"].IsUnknown() { |
| 71 | + attributeSourceInner.JdbcAttributeSource.ColumnNames = []string{} |
| 72 | + for _, columnNamesElement := range jdbcAttributeSourceAttrs["column_names"].(types.List).Elements() { |
| 73 | + attributeSourceInner.JdbcAttributeSource.ColumnNames = append(attributeSourceInner.JdbcAttributeSource.ColumnNames, columnNamesElement.(types.String).ValueString()) |
| 74 | + } |
33 | 75 | }
|
| 76 | + jdbcAttributeSourceDataStoreRefValue := client.ResourceLink{} |
| 77 | + jdbcAttributeSourceDataStoreRefAttrs := jdbcAttributeSourceAttrs["data_store_ref"].(types.Object).Attributes() |
| 78 | + jdbcAttributeSourceDataStoreRefValue.Id = jdbcAttributeSourceDataStoreRefAttrs["id"].(types.String).ValueString() |
| 79 | + attributeSourceInner.JdbcAttributeSource.DataStoreRef = jdbcAttributeSourceDataStoreRefValue |
| 80 | + attributeSourceInner.JdbcAttributeSource.Description = jdbcAttributeSourceAttrs["description"].(types.String).ValueStringPointer() |
| 81 | + attributeSourceInner.JdbcAttributeSource.Filter = jdbcAttributeSourceAttrs["filter"].(types.String).ValueString() |
| 82 | + attributeSourceInner.JdbcAttributeSource.Id = jdbcAttributeSourceAttrs["id"].(types.String).ValueStringPointer() |
| 83 | + attributeSourceInner.JdbcAttributeSource.Schema = jdbcAttributeSourceAttrs["schema"].(types.String).ValueStringPointer() |
| 84 | + attributeSourceInner.JdbcAttributeSource.Table = jdbcAttributeSourceAttrs["table"].(types.String).ValueString() |
| 85 | + attributeSourceInner.JdbcAttributeSource.Type = jdbcAttributeSourceAttrs["type"].(types.String).ValueString() |
34 | 86 | }
|
35 | 87 | if internaltypes.IsDefined(sourceAttrs["ldap_attribute_source"]) {
|
36 | 88 | attributeSourceInner.LdapAttributeSource = &client.LdapAttributeSource{}
|
37 |
| - ldapAttributeSourceErr := json.Unmarshal([]byte(internaljson.FromValue(sourceAttrs["ldap_attribute_source"], true)), attributeSourceInner.LdapAttributeSource) |
38 |
| - if ldapAttributeSourceErr != nil { |
39 |
| - return nil, ldapAttributeSourceErr |
| 89 | + ldapAttributeSourceAttrs := sourceAttrs["ldap_attribute_source"].(types.Object).Attributes() |
| 90 | + if !ldapAttributeSourceAttrs["attribute_contract_fulfillment"].IsNull() && !ldapAttributeSourceAttrs["attribute_contract_fulfillment"].IsUnknown() { |
| 91 | + attributeSourceInner.LdapAttributeSource.AttributeContractFulfillment = &map[string]client.AttributeFulfillmentValue{} |
| 92 | + for key, attributeContractFulfillmentElement := range ldapAttributeSourceAttrs["attribute_contract_fulfillment"].(types.Map).Elements() { |
| 93 | + attributeContractFulfillmentValue := client.AttributeFulfillmentValue{} |
| 94 | + attributeContractFulfillmentAttrs := attributeContractFulfillmentElement.(types.Object).Attributes() |
| 95 | + attributeContractFulfillmentSourceValue := client.SourceTypeIdKey{} |
| 96 | + attributeContractFulfillmentSourceAttrs := attributeContractFulfillmentAttrs["source"].(types.Object).Attributes() |
| 97 | + attributeContractFulfillmentSourceValue.Id = attributeContractFulfillmentSourceAttrs["id"].(types.String).ValueStringPointer() |
| 98 | + attributeContractFulfillmentSourceValue.Type = attributeContractFulfillmentSourceAttrs["type"].(types.String).ValueString() |
| 99 | + attributeContractFulfillmentValue.Source = attributeContractFulfillmentSourceValue |
| 100 | + attributeContractFulfillmentValue.Value = attributeContractFulfillmentAttrs["value"].(types.String).ValueString() |
| 101 | + (*attributeSourceInner.LdapAttributeSource.AttributeContractFulfillment)[key] = attributeContractFulfillmentValue |
| 102 | + } |
| 103 | + } |
| 104 | + attributeSourceInner.LdapAttributeSource.BaseDn = ldapAttributeSourceAttrs["base_dn"].(types.String).ValueStringPointer() |
| 105 | + if !ldapAttributeSourceAttrs["binary_attribute_settings"].IsNull() && !ldapAttributeSourceAttrs["binary_attribute_settings"].IsUnknown() { |
| 106 | + attributeSourceInner.LdapAttributeSource.BinaryAttributeSettings = &map[string]client.BinaryLdapAttributeSettings{} |
| 107 | + for key, binaryAttributeSettingsElement := range ldapAttributeSourceAttrs["binary_attribute_settings"].(types.Map).Elements() { |
| 108 | + binaryAttributeSettingsValue := client.BinaryLdapAttributeSettings{} |
| 109 | + binaryAttributeSettingsAttrs := binaryAttributeSettingsElement.(types.Object).Attributes() |
| 110 | + binaryAttributeSettingsValue.BinaryEncoding = binaryAttributeSettingsAttrs["binary_encoding"].(types.String).ValueStringPointer() |
| 111 | + (*attributeSourceInner.LdapAttributeSource.BinaryAttributeSettings)[key] = binaryAttributeSettingsValue |
| 112 | + } |
| 113 | + } |
| 114 | + ldapAttributeSourceDataStoreRefValue := client.ResourceLink{} |
| 115 | + ldapAttributeSourceDataStoreRefAttrs := ldapAttributeSourceAttrs["data_store_ref"].(types.Object).Attributes() |
| 116 | + ldapAttributeSourceDataStoreRefValue.Id = ldapAttributeSourceDataStoreRefAttrs["id"].(types.String).ValueString() |
| 117 | + attributeSourceInner.LdapAttributeSource.DataStoreRef = ldapAttributeSourceDataStoreRefValue |
| 118 | + attributeSourceInner.LdapAttributeSource.Description = ldapAttributeSourceAttrs["description"].(types.String).ValueStringPointer() |
| 119 | + attributeSourceInner.LdapAttributeSource.Id = ldapAttributeSourceAttrs["id"].(types.String).ValueStringPointer() |
| 120 | + attributeSourceInner.LdapAttributeSource.MemberOfNestedGroup = ldapAttributeSourceAttrs["member_of_nested_group"].(types.Bool).ValueBoolPointer() |
| 121 | + if !ldapAttributeSourceAttrs["search_attributes"].IsNull() && !ldapAttributeSourceAttrs["search_attributes"].IsUnknown() { |
| 122 | + attributeSourceInner.LdapAttributeSource.SearchAttributes = []string{} |
| 123 | + for _, searchAttributesElement := range ldapAttributeSourceAttrs["search_attributes"].(types.Set).Elements() { |
| 124 | + attributeSourceInner.LdapAttributeSource.SearchAttributes = append(attributeSourceInner.LdapAttributeSource.SearchAttributes, searchAttributesElement.(types.String).ValueString()) |
| 125 | + } |
40 | 126 | }
|
| 127 | + attributeSourceInner.LdapAttributeSource.SearchFilter = ldapAttributeSourceAttrs["search_filter"].(types.String).ValueString() |
| 128 | + attributeSourceInner.LdapAttributeSource.SearchScope = ldapAttributeSourceAttrs["search_scope"].(types.String).ValueString() |
| 129 | + attributeSourceInner.LdapAttributeSource.Type = ldapAttributeSourceAttrs["type"].(types.String).ValueString() |
41 | 130 | }
|
42 | 131 | attributeSourceAggregation = append(attributeSourceAggregation, attributeSourceInner)
|
43 | 132 | }
|
44 |
| - return attributeSourceAggregation, nil |
| 133 | + return attributeSourceAggregation |
45 | 134 | }
|
0 commit comments