public void IotSecuritySolution_CreateOrUpdate()
        {
            string IotHubResourceId =
                $"/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.Devices/IotHubs/{IotHubName}";

            string WorkspaceResourceId =
                $"/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{WorkspaceName}";

            var udrp = new UserDefinedResourcesProperties("where type != \"microsoft.devices/iothubs\" | where name contains \"v2\"", new[] { SubscriptionId });

            var iotSecuritySolutionData = new IoTSecuritySolutionModel()
            {
                Workspace            = WorkspaceResourceId,
                DisplayName          = $"{SolutionName}-{WorkspaceName}",
                IotHubs              = new[] { IotHubResourceId },
                Location             = AscLocation,
                UserDefinedResources = udrp,
            };

            using (var context = MockContext.Start(this.GetType()))
            {
                var securityCenterClient = GetSecurityCenterClient(context);
                var ret = securityCenterClient.IotSecuritySolution.CreateOrUpdate(ResourceGroupName, SolutionName, iotSecuritySolutionData);
                ret.Validate();
            }
        }
Example #2
0
        public override void ExecuteCmdlet()
        {
            switch (ParameterSetName)
            {
            case ParameterSetNames.ResourceGroupLevelResource:
                break;

            case ParameterSetNames.ResourceId:
                Name = AzureIdUtilities.GetResourceName(ResourceId);
                ResourceGroupName = AzureIdUtilities.GetResourceGroup(ResourceId);
                break;

            case ParameterSetNames.InputObject:
                Name = InputObject.Name;
                ResourceGroupName            = AzureIdUtilities.GetResourceGroup(InputObject.Id);
                Location                     = Location ?? InputObject.Location;
                DisabledDataSource           = DisabledDataSource ?? ((List <string>)InputObject.DisabledDataSources).ToArray();
                DisplayName                  = DisplayName ?? InputObject.DisplayName;
                Export                       = Export ?? ((List <string>)InputObject.Export).ToArray();
                IotHub                       = IotHub ?? ((List <string>)InputObject.IotHubs).ToArray();
                RecommendationsConfiguration = RecommendationsConfiguration ?? ((List <PSRecommendationConfiguration>)InputObject.RecommendationsConfiguration).ToArray();
                Enabled                      = InputObject.Status.ToLower().Equals("enabled");
                Tag = Tag ?? new Hashtable((IDictionary)(InputObject.Tags));
                UnmaskedIpLoggingStatus = UnmaskedIpLoggingStatus ?? InputObject.UnmaskedIpLoggingStatus;
                UserDefinedResource     = UserDefinedResource ?? InputObject.UserDefinedResources;
                Workspace = Workspace ?? InputObject.Workspace;
                break;

            default:
                throw new PSInvalidOperationException();
            }

            IoTSecuritySolutionModel solutionModel = new IoTSecuritySolutionModel
            {
                Location            = Location,
                DisabledDataSources = DisabledDataSource,
                DisplayName         = DisplayName,
                Export  = Export,
                IotHubs = IotHub,
                RecommendationsConfiguration = RecommendationsConfiguration?.CreatePSType(),
                Status = Enabled? "Enabled" : "Disabled",
                Tags   = Tag?.Cast <DictionaryEntry>().ToDictionary(t => (string)t.Key, t => (string)t.Value),
                UnmaskedIpLoggingStatus = UnmaskedIpLoggingStatus,
                UserDefinedResources    = UserDefinedResource?.CreatePSType(),
                Workspace = Workspace
            };

            if (ShouldProcess(Name, VerbsCommon.Set))
            {
                var outputSolution = SecurityCenterClient.IotSecuritySolution.CreateOrUpdateWithHttpMessagesAsync(ResourceGroupName, Name, solutionModel).GetAwaiter().GetResult().Body;
                WriteObject(outputSolution?.ConvertToPSType(), enumerateCollection: false);
            }
        }
 public static PSIotSecuritySolution ConvertToPSType(this IoTSecuritySolutionModel value)
 {
     return(new PSIotSecuritySolution()
     {
         Id = value.Id,
         Name = value.Name,
         Type = value.Type,
         Tags = value.Tags,
         Location = value.Location,
         Workspace = value.Workspace,
         DisplayName = value.DisplayName,
         Status = value.Status,
         Export = value.Export,
         DisabledDataSources = value.DisabledDataSources,
         IotHubs = value.IotHubs,
         UserDefinedResources = value.UserDefinedResources?.ConvertToPSType(),
         AutoDiscoveredResources = value.AutoDiscoveredResources,
         RecommendationsConfiguration = value.RecommendationsConfiguration?.ConvertToPSType(),
         UnmaskedIpLoggingStatus = value.UnmaskedIpLoggingStatus
     });
 }
 /// <summary>
 /// Use this method to create or update yours IoT Security solution
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group within the user's subscription. The name is
 /// case insensitive.
 /// </param>
 /// <param name='solutionName'>
 /// The name of the IoT Security solution.
 /// </param>
 /// <param name='iotSecuritySolutionData'>
 /// The security solution data
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <IoTSecuritySolutionModel> CreateOrUpdateAsync(this IIotSecuritySolutionOperations operations, string resourceGroupName, string solutionName, IoTSecuritySolutionModel iotSecuritySolutionData, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, solutionName, iotSecuritySolutionData, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
 /// <summary>
 /// Use this method to create or update yours IoT Security solution
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group within the user's subscription. The name is
 /// case insensitive.
 /// </param>
 /// <param name='solutionName'>
 /// The name of the IoT Security solution.
 /// </param>
 /// <param name='iotSecuritySolutionData'>
 /// The security solution data
 /// </param>
 public static IoTSecuritySolutionModel CreateOrUpdate(this IIotSecuritySolutionOperations operations, string resourceGroupName, string solutionName, IoTSecuritySolutionModel iotSecuritySolutionData)
 {
     return(operations.CreateOrUpdateAsync(resourceGroupName, solutionName, iotSecuritySolutionData).GetAwaiter().GetResult());
 }