Skip to content

Commit

Permalink
Merge pull request #8 from deploymenttheory/feature-scaffolding
Browse files Browse the repository at this point in the history
separated stating logic from read func
  • Loading branch information
ShocOne authored Jul 22, 2024
2 parents 4104abe + f5d5744 commit c3d917d
Show file tree
Hide file tree
Showing 6 changed files with 317 additions and 98 deletions.
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,
// }
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
}
Loading

0 comments on commit c3d917d

Please sign in to comment.