|
| 1 | +package provider |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/hashicorp/terraform-plugin-framework/types" |
| 5 | + "github.com/zentralopensource/goztl" |
| 6 | +) |
| 7 | + |
| 8 | +type mdmDataAsset struct { |
| 9 | + ID types.String `tfsdk:"id"` |
| 10 | + Type types.String `tfsdk:"type"` |
| 11 | + FileURI types.String `tfsdk:"file_uri"` |
| 12 | + FileSHA256 types.String `tfsdk:"file_sha256"` |
| 13 | + FileSize types.Int64 `tfsdk:"file_size"` |
| 14 | + Filename types.String `tfsdk:"filename"` |
| 15 | + ArtifactID types.String `tfsdk:"artifact_id"` |
| 16 | + IOS types.Bool `tfsdk:"ios"` |
| 17 | + IOSMaxVersion types.String `tfsdk:"ios_max_version"` |
| 18 | + IOSMinVersion types.String `tfsdk:"ios_min_version"` |
| 19 | + IPadOS types.Bool `tfsdk:"ipados"` |
| 20 | + IPadOSMaxVersion types.String `tfsdk:"ipados_max_version"` |
| 21 | + IPadOSMinVersion types.String `tfsdk:"ipados_min_version"` |
| 22 | + MacOS types.Bool `tfsdk:"macos"` |
| 23 | + MacOSMaxVersion types.String `tfsdk:"macos_max_version"` |
| 24 | + MacOSMinVersion types.String `tfsdk:"macos_min_version"` |
| 25 | + TVOS types.Bool `tfsdk:"tvos"` |
| 26 | + TVOSMaxVersion types.String `tfsdk:"tvos_max_version"` |
| 27 | + TVOSMinVersion types.String `tfsdk:"tvos_min_version"` |
| 28 | + DefaultShard types.Int64 `tfsdk:"default_shard"` |
| 29 | + ShardModulo types.Int64 `tfsdk:"shard_modulo"` |
| 30 | + ExcludedTagIDs types.Set `tfsdk:"excluded_tag_ids"` |
| 31 | + TagShards types.Set `tfsdk:"tag_shards"` |
| 32 | + Version types.Int64 `tfsdk:"version"` |
| 33 | +} |
| 34 | + |
| 35 | +func mdmDataAssetForState(mda *goztl.MDMDataAsset, fileURI types.String) mdmDataAsset { |
| 36 | + exTagIDs := exTagIDsForState(mda.MDMArtifactVersion) |
| 37 | + tagShards := tagShardsForState(mda.MDMArtifactVersion) |
| 38 | + |
| 39 | + return mdmDataAsset{ |
| 40 | + ID: types.StringValue(mda.ID), |
| 41 | + Type: types.StringValue(mda.Type), |
| 42 | + FileURI: fileURI, |
| 43 | + FileSHA256: types.StringValue(mda.FileSHA256), |
| 44 | + FileSize: types.Int64Value(mda.FileSize), |
| 45 | + Filename: types.StringValue(mda.Filename), |
| 46 | + ArtifactID: types.StringValue(mda.ArtifactID), |
| 47 | + IOS: types.BoolValue(mda.IOS), |
| 48 | + IOSMaxVersion: types.StringValue(mda.IOSMaxVersion), |
| 49 | + IOSMinVersion: types.StringValue(mda.IOSMinVersion), |
| 50 | + IPadOS: types.BoolValue(mda.IPadOS), |
| 51 | + IPadOSMaxVersion: types.StringValue(mda.IPadOSMaxVersion), |
| 52 | + IPadOSMinVersion: types.StringValue(mda.IPadOSMinVersion), |
| 53 | + MacOS: types.BoolValue(mda.MacOS), |
| 54 | + MacOSMaxVersion: types.StringValue(mda.MacOSMaxVersion), |
| 55 | + MacOSMinVersion: types.StringValue(mda.MacOSMinVersion), |
| 56 | + TVOS: types.BoolValue(mda.TVOS), |
| 57 | + TVOSMaxVersion: types.StringValue(mda.TVOSMaxVersion), |
| 58 | + TVOSMinVersion: types.StringValue(mda.TVOSMinVersion), |
| 59 | + DefaultShard: types.Int64Value(int64(mda.DefaultShard)), |
| 60 | + ShardModulo: types.Int64Value(int64(mda.ShardModulo)), |
| 61 | + ExcludedTagIDs: types.SetValueMust(types.Int64Type, exTagIDs), |
| 62 | + TagShards: types.SetValueMust(types.ObjectType{AttrTypes: tagShardAttrTypes}, tagShards), |
| 63 | + Version: types.Int64Value(int64(mda.Version)), |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +func mdmDataAssetRequestWithState(data mdmDataAsset) *goztl.MDMDataAssetRequest { |
| 68 | + exTagIDs := make([]int, 0) |
| 69 | + for _, exTagID := range data.ExcludedTagIDs.Elements() { // nil if null or unknown → no iterations |
| 70 | + exTagIDs = append(exTagIDs, int(exTagID.(types.Int64).ValueInt64())) |
| 71 | + } |
| 72 | + |
| 73 | + tagShards := make([]goztl.TagShard, 0) |
| 74 | + for _, tagShard := range data.TagShards.Elements() { // nil if null or unknown → no iterations |
| 75 | + tagShardMap := tagShard.(types.Object).Attributes() |
| 76 | + if tagShardMap != nil { |
| 77 | + tagShards = append( |
| 78 | + tagShards, |
| 79 | + goztl.TagShard{ |
| 80 | + TagID: int(tagShardMap["tag_id"].(types.Int64).ValueInt64()), |
| 81 | + Shard: int(tagShardMap["shard"].(types.Int64).ValueInt64()), |
| 82 | + }, |
| 83 | + ) |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + return &goztl.MDMDataAssetRequest{ |
| 88 | + Type: data.Type.ValueString(), |
| 89 | + FileURI: data.FileURI.ValueString(), |
| 90 | + FileSHA256: data.FileSHA256.ValueString(), |
| 91 | + MDMArtifactVersionRequest: goztl.MDMArtifactVersionRequest{ |
| 92 | + ArtifactID: data.ArtifactID.ValueString(), |
| 93 | + IOS: data.IOS.ValueBool(), |
| 94 | + IOSMaxVersion: data.IOSMaxVersion.ValueString(), |
| 95 | + IOSMinVersion: data.IOSMinVersion.ValueString(), |
| 96 | + IPadOS: data.IPadOS.ValueBool(), |
| 97 | + IPadOSMaxVersion: data.IPadOSMaxVersion.ValueString(), |
| 98 | + IPadOSMinVersion: data.IPadOSMinVersion.ValueString(), |
| 99 | + MacOS: data.MacOS.ValueBool(), |
| 100 | + MacOSMaxVersion: data.MacOSMaxVersion.ValueString(), |
| 101 | + MacOSMinVersion: data.MacOSMinVersion.ValueString(), |
| 102 | + TVOS: data.TVOS.ValueBool(), |
| 103 | + TVOSMaxVersion: data.TVOSMaxVersion.ValueString(), |
| 104 | + TVOSMinVersion: data.TVOSMinVersion.ValueString(), |
| 105 | + DefaultShard: int(data.DefaultShard.ValueInt64()), |
| 106 | + ShardModulo: int(data.ShardModulo.ValueInt64()), |
| 107 | + ExcludedTagIDs: exTagIDs, |
| 108 | + TagShards: tagShards, |
| 109 | + Version: int(data.Version.ValueInt64()), |
| 110 | + }, |
| 111 | + } |
| 112 | +} |
0 commit comments