generated from deploymenttheory/Template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from deploymenttheory/feature-scaffolding
separated stating logic from read func
- Loading branch information
Showing
6 changed files
with
317 additions
and
98 deletions.
There are no files selected for viewing
72 changes: 36 additions & 36 deletions
72
internal/resources/devicemanagement/beta/assignmentFilters/helpers.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,42 @@ | ||
package assignmentFilter | ||
|
||
import ( | ||
"fmt" | ||
// import ( | ||
// "fmt" | ||
|
||
"github.com/microsoftgraph/msgraph-beta-sdk-go/models" | ||
) | ||
// "github.com/microsoftgraph/msgraph-beta-sdk-go/models" | ||
// ) | ||
|
||
// StringToDevicePlatformType converts a string to DevicePlatformType. | ||
func StringToDevicePlatformType(platformStr string, supportedPlatformTypes map[string]models.DevicePlatformType) (*models.DevicePlatformType, error) { | ||
platform, exists := supportedPlatformTypes[platformStr] | ||
if !exists { | ||
return nil, fmt.Errorf("unsupported platform type: %s", platformStr) | ||
} | ||
return &platform, nil | ||
} | ||
// // StringToDevicePlatformType converts a string to DevicePlatformType. | ||
// func StringToDevicePlatformType(platformStr string, supportedPlatformTypes map[string]models.DevicePlatformType) (*models.DevicePlatformType, error) { | ||
// platform, exists := supportedPlatformTypes[platformStr] | ||
// if !exists { | ||
// return nil, fmt.Errorf("unsupported platform type: %s", platformStr) | ||
// } | ||
// return &platform, nil | ||
// } | ||
|
||
// DevicePlatformTypeToString converts a DevicePlatformType to its string representation. | ||
func DevicePlatformTypeToString(platform *models.DevicePlatformType) (string, error) { | ||
if platform == nil { | ||
return "", fmt.Errorf("platform is nil") | ||
} | ||
return platform.String(), nil | ||
} | ||
// // DevicePlatformTypeToString converts a DevicePlatformType to its string representation. | ||
// func DevicePlatformTypeToString(platform *models.DevicePlatformType) (string, error) { | ||
// if platform == nil { | ||
// return "", fmt.Errorf("platform is nil") | ||
// } | ||
// return platform.String(), nil | ||
// } | ||
|
||
// supportedPlatformTypes is a map of string representations to their corresponding platform types. | ||
var supportedPlatformTypes = map[string]models.DevicePlatformType{ | ||
"android": models.ANDROID_DEVICEPLATFORMTYPE, | ||
"androidForWork": models.ANDROIDFORWORK_DEVICEPLATFORMTYPE, | ||
"iOS": models.IOS_DEVICEPLATFORMTYPE, | ||
"macOS": models.MACOS_DEVICEPLATFORMTYPE, | ||
"windowsPhone81": models.WINDOWSPHONE81_DEVICEPLATFORMTYPE, | ||
"windows81AndLater": models.WINDOWS81ANDLATER_DEVICEPLATFORMTYPE, | ||
"windows10AndLater": models.WINDOWS10ANDLATER_DEVICEPLATFORMTYPE, | ||
"androidWorkProfile": models.ANDROIDWORKPROFILE_DEVICEPLATFORMTYPE, | ||
"unknown": models.UNKNOWN_DEVICEPLATFORMTYPE, | ||
"androidAOSP": models.ANDROIDAOSP_DEVICEPLATFORMTYPE, | ||
"androidMobileApplicationManagement": models.ANDROIDMOBILEAPPLICATIONMANAGEMENT_DEVICEPLATFORMTYPE, | ||
"iOSMobileApplicationManagement": models.IOSMOBILEAPPLICATIONMANAGEMENT_DEVICEPLATFORMTYPE, | ||
"unknownFutureValue": models.UNKNOWNFUTUREVALUE_DEVICEPLATFORMTYPE, | ||
"windowsMobileApplicationManagement": models.WINDOWSMOBILEAPPLICATIONMANAGEMENT_DEVICEPLATFORMTYPE, | ||
} | ||
// // supportedPlatformTypes is a map of string representations to their corresponding platform types. | ||
// var supportedPlatformTypes = map[string]models.DevicePlatformType{ | ||
// "android": models.ANDROID_DEVICEPLATFORMTYPE, | ||
// "androidForWork": models.ANDROIDFORWORK_DEVICEPLATFORMTYPE, | ||
// "iOS": models.IOS_DEVICEPLATFORMTYPE, | ||
// "macOS": models.MACOS_DEVICEPLATFORMTYPE, | ||
// "windowsPhone81": models.WINDOWSPHONE81_DEVICEPLATFORMTYPE, | ||
// "windows81AndLater": models.WINDOWS81ANDLATER_DEVICEPLATFORMTYPE, | ||
// "windows10AndLater": models.WINDOWS10ANDLATER_DEVICEPLATFORMTYPE, | ||
// "androidWorkProfile": models.ANDROIDWORKPROFILE_DEVICEPLATFORMTYPE, | ||
// "unknown": models.UNKNOWN_DEVICEPLATFORMTYPE, | ||
// "androidAOSP": models.ANDROIDAOSP_DEVICEPLATFORMTYPE, | ||
// "androidMobileApplicationManagement": models.ANDROIDMOBILEAPPLICATIONMANAGEMENT_DEVICEPLATFORMTYPE, | ||
// "iOSMobileApplicationManagement": models.IOSMOBILEAPPLICATIONMANAGEMENT_DEVICEPLATFORMTYPE, | ||
// "unknownFutureValue": models.UNKNOWNFUTUREVALUE_DEVICEPLATFORMTYPE, | ||
// "windowsMobileApplicationManagement": models.WINDOWSMOBILEAPPLICATIONMANAGEMENT_DEVICEPLATFORMTYPE, | ||
// } |
84 changes: 84 additions & 0 deletions
84
internal/resources/devicemanagement/beta/assignmentFilters/object.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package assignmentFilter | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
|
||
"github.com/microsoftgraph/msgraph-beta-sdk-go/models" | ||
) | ||
|
||
// constructResource maps the Terraform schema to the SDK model | ||
func constructResource(data *AssignmentFilterResourceModel) (*models.DeviceAndAppManagementAssignmentFilter, error) { | ||
requestBody := models.NewDeviceAndAppManagementAssignmentFilter() | ||
|
||
// Set DisplayName | ||
displayName := data.DisplayName.ValueString() | ||
requestBody.SetDisplayName(&displayName) | ||
|
||
// Set Description | ||
if !data.Description.IsNull() { | ||
description := data.Description.ValueString() | ||
requestBody.SetDescription(&description) | ||
} | ||
|
||
// Set Platform | ||
if !data.Platform.IsNull() { | ||
platformStr := data.Platform.ValueString() | ||
platform, err := models.ParseDevicePlatformType(platformStr) | ||
if err != nil { | ||
return nil, fmt.Errorf("invalid platform: %s", err) | ||
} | ||
if platform != nil { | ||
requestBody.SetPlatform(platform.(*models.DevicePlatformType)) | ||
} | ||
} | ||
|
||
// Set Rule | ||
rule := data.Rule.ValueString() | ||
requestBody.SetRule(&rule) | ||
|
||
// Set AssignmentFilterManagementType | ||
if !data.AssignmentFilterManagementType.IsNull() { | ||
assignmentFilterManagementTypeStr := data.AssignmentFilterManagementType.ValueString() | ||
assignmentFilterManagementType, err := models.ParseAssignmentFilterManagementType(assignmentFilterManagementTypeStr) | ||
if err != nil { | ||
return nil, fmt.Errorf("invalid assignment filter management type: %s", err) | ||
} | ||
if assignmentFilterManagementType != nil { | ||
requestBody.SetAssignmentFilterManagementType(assignmentFilterManagementType.(*models.AssignmentFilterManagementType)) | ||
} | ||
} | ||
|
||
// Set RoleScopeTags | ||
if !data.RoleScopeTags.IsNull() { | ||
var roleScopeTags []string | ||
for _, tag := range data.RoleScopeTags.Elements() { | ||
roleScopeTags = append(roleScopeTags, tag.(types.String).Value) | ||
} | ||
requestBody.SetRoleScopeTags(roleScopeTags) | ||
} | ||
|
||
// Set Payloads | ||
if !data.Payloads.IsNull() { | ||
var payloads []models.PayloadByFilterable | ||
for _, payloadElement := range data.Payloads.Elements() { | ||
payload := payloadElement.(types.Object) | ||
payloadID := payload.Attributes["payload_id"].(types.String).ValueString() | ||
payloadType := payload.Attributes["payload_type"].(types.String).ValueString() | ||
groupID := payload.Attributes["group_id"].(types.String).ValueString() | ||
assignmentFilterType := payload.Attributes["assignment_filter_type"].(types.String).ValueString() | ||
|
||
payloadModel := models.NewPayloadCompatibleAssignmentFilter() | ||
payloadModel.SetPayloadId(&payloadID) | ||
payloadModel.SetPayloadType(&payloadType) | ||
payloadModel.SetGroupId(&groupID) | ||
payloadModel.SetAssignmentFilterType(&assignmentFilterType) | ||
|
||
payloads = append(payloads, payloadModel) | ||
} | ||
requestBody.SetPayloads(payloads) | ||
} | ||
|
||
return requestBody, nil | ||
} |
Oops, something went wrong.