Esempio n. 1
0
        public void CmkEnablementTest()
        {
            var resourceGroupName = TestUtilities.GenerateName("SdkRg");
            var jobName           = TestUtilities.GenerateName("SdkJob");
            //var jobName = "SdkJob5929";
            ContactDetails  contactDetails          = GetDefaultContactDetails();
            ShippingAddress shippingAddress         = GetDefaultShippingAddress();
            Sku             sku                     = GetDefaultSku();
            var             destinationAccountsList = new List <StorageAccountDetails>
            {
                new StorageAccountDetails
                {
                    StorageAccountId = "/subscriptions/fa68082f-8ff7-4a25-95c7-ce9da541242f/resourceGroups/databoxbvt1/providers/Microsoft.Storage/storageAccounts/databoxbvttestaccount2"
                }
            };
            JobDetails jobDetails = new DataBoxJobDetails
            {
                ContactDetails  = contactDetails,
                ShippingAddress = shippingAddress
            };

            jobDetails.DataImportDetails = new List <DataImportDetails>();
            jobDetails.DataImportDetails.Add(new DataImportDetails(destinationAccountsList.FirstOrDefault()));

            var jobResource = new JobResource
            {
                Sku      = sku,
                Location = TestConstants.DefaultResourceLocation,
                Details  = jobDetails,
            };

            this.RMClient.ResourceGroups.CreateOrUpdate(
                resourceGroupName,
                new ResourceGroup
            {
                Location = TestConstants.DefaultResourceLocation
            });

            var job = this.Client.Jobs.Create(resourceGroupName, jobName, jobResource);

            ValidateJobWithoutDetails(jobName, sku, job);
            Assert.Equal(StageName.DeviceOrdered, job.Status);

            // Set Msi details.
            string tenantId     = "72f988bf-86f1-41af-91ab-2d7cd011db47";
            string identityType = "SystemAssigned";
            var    identity     = new ResourceIdentity(identityType, Guid.NewGuid().ToString(), tenantId);
            var    updateParams = new JobResourceUpdateParameter
            {
                Identity = identity
            };

            var updateJob = this.Client.Jobs.Update(resourceGroupName, jobName, updateParams);

            ValidateJobWithoutDetails(jobName, sku, updateJob);

            var getJob = this.Client.Jobs.Get(resourceGroupName, jobName, TestConstants.Details);

            ValidateJobWithoutDetails(jobName, sku, job);
            ValidateJobDetails(contactDetails, shippingAddress, getJob, JobDeliveryType.NonScheduled);

            Assert.Equal(StageName.DeviceOrdered, updateJob.Status);
            Assert.Equal(identityType, updateJob.Identity.Type);

            var keyEncryptionKey = new KeyEncryptionKey(KekType.CustomerManaged)
            {
                KekUrl             = @"https://sdkkeyvault.vault.azure.net/keys/SSDKEY/",
                KekVaultResourceID =
                    "/subscriptions/fa68082f-8ff7-4a25-95c7-ce9da541242f/resourceGroups/akvenkat/providers/Microsoft.KeyVault/vaults/SDKKeyVault"
            };

            var details = new UpdateJobDetails
            {
                KeyEncryptionKey = keyEncryptionKey
            };

            updateParams = new JobResourceUpdateParameter
            {
                Details = details
            };

            updateJob = this.Client.Jobs.Update(resourceGroupName, jobName, updateParams);
            ValidateJobWithoutDetails(jobName, sku, updateJob);
            getJob = this.Client.Jobs.Get(resourceGroupName, jobName, TestConstants.Details);
            ValidateJobDetails(contactDetails, shippingAddress, getJob, JobDeliveryType.NonScheduled);

            Assert.Equal(StageName.DeviceOrdered, updateJob.Status);
            Assert.Equal(KekType.CustomerManaged, getJob.Details.KeyEncryptionKey.KekType);
        }
        public override void ExecuteCmdlet()
        {
            if (DataBoxType == "DataBoxDisk" && ExpectedDataSizeInTeraBytes.Equals(0))
            {
                throw new PSArgumentNullException("ExpectedDataSizeInTeraBytes");
            }

            ShippingAddress shippingAddress = new ShippingAddress()
            {
                AddressType     = this.AddressType,
                CompanyName     = this.CompanyName,
                StreetAddress1  = this.StreetAddress1,
                StreetAddress2  = this.StreetAddress2,
                StreetAddress3  = this.StreetAddress3,
                City            = this.City,
                StateOrProvince = this.StateOrProvinceCode,
                Country         = this.CountryCode,
                PostalCode      = this.PostalCode
            };

            ContactDetails contactDetails = new ContactDetails()
            {
                Phone       = this.PhoneNumber,
                EmailList   = EmailId,
                ContactName = this.ContactName
            };

            List <DestinationAccountDetails> destinationAccountDetails = new List <DestinationAccountDetails>();

            foreach (var storageAccount in StorageAccountResourceId)
            {
                destinationAccountDetails.Add(
                    new DestinationAccountDetails(storageAccount));
            }

            DataBoxDiskJobDetails  diskDetails;
            DataBoxJobDetails      databoxDetails;
            DataBoxHeavyJobDetails heavyDetails;

            JobResource newJobResource = new JobResource();

            Sku sku = new Sku();

            switch (DataBoxType)
            {
            case "DataBoxDisk":
                diskDetails    = new DataBoxDiskJobDetails(contactDetails, shippingAddress, destinationAccountDetails, expectedDataSizeInTeraBytes: ExpectedDataSizeInTeraBytes);
                sku.Name       = SkuName.DataBoxDisk;
                newJobResource = new JobResource(Location, sku, details: diskDetails);
                break;

            case "DataBox":
                databoxDetails = new DataBoxJobDetails(contactDetails, shippingAddress, destinationAccountDetails);
                sku.Name       = SkuName.DataBox;
                newJobResource = new JobResource(Location, sku, details: databoxDetails);
                break;

            case "DataBoxHeavy":
                heavyDetails   = new DataBoxHeavyJobDetails(contactDetails, shippingAddress, destinationAccountDetails);
                sku.Name       = SkuName.DataBoxHeavy;
                newJobResource = new JobResource(Location, sku, details: heavyDetails);
                break;

            default: break;
            }

            AddressValidationOutput addressValidationResult = ServiceOperationsExtensions.ValidateAddressMethod(
                DataBoxManagementClient.Service, Location, shippingAddress, newJobResource.Sku.Name);

            if (addressValidationResult.ValidationStatus != AddressValidationStatus.Valid)
            {
                WriteVerbose(Resource.AddressValidationStatus + addressValidationResult.ValidationStatus + "\n");

                //print alternate address
                if (addressValidationResult.ValidationStatus == AddressValidationStatus.Ambiguous)
                {
                    WriteVerbose(Resource.SupportAddresses + "\n\n");
                    foreach (ShippingAddress address in addressValidationResult.AlternateAddresses)
                    {
                        WriteVerbose(Resource.AddressType + address.AddressType + "\n");
                        if (!(string.IsNullOrEmpty(address.CompanyName)))
                        {
                            WriteVerbose(Resource.CompanyName + address.CompanyName);
                        }
                        if (!(string.IsNullOrEmpty(address.StreetAddress1)))
                        {
                            WriteVerbose(Resource.StreetAddress1 + address.StreetAddress1);
                        }
                        if (!(string.IsNullOrEmpty(address.StreetAddress2)))
                        {
                            WriteVerbose(Resource.StreetAddress2 + address.StreetAddress2);
                        }
                        if (!(string.IsNullOrEmpty(address.StreetAddress3)))
                        {
                            WriteVerbose(Resource.StreetAddress3 + address.StreetAddress3);
                        }
                        if (!(string.IsNullOrEmpty(address.City)))
                        {
                            WriteVerbose(Resource.City + address.City);
                        }
                        if (!(string.IsNullOrEmpty(address.StateOrProvince)))
                        {
                            WriteVerbose(Resource.StateOrProvince + address.StateOrProvince);
                        }
                        if (!(string.IsNullOrEmpty(address.Country)))
                        {
                            WriteVerbose(Resource.Country + address.Country);
                        }
                        if (!(string.IsNullOrEmpty(address.PostalCode)))
                        {
                            WriteVerbose(Resource.PostalCode + address.PostalCode);
                        }
                        if (!(string.IsNullOrEmpty(address.ZipExtendedCode)))
                        {
                            WriteVerbose(Resource.ZipExtendedCode + address.ZipExtendedCode);
                        }
                        WriteVerbose("\n\n");
                    }
                    throw new PSNotSupportedException(Resource.AmbiguousAddressMessage);
                }
                throw new PSNotSupportedException(Resource.InvalidAddressMessage);
            }

            if (ShouldProcess(this.Name, string.Format(Resource.CreatingDataboxJob + this.Name + Resource.InResourceGroup + this.ResourceGroupName)))
            {
                JobResource finalJobResource = JobsOperationsExtensions.Create(
                    DataBoxManagementClient.Jobs,
                    ResourceGroupName,
                    Name,
                    newJobResource);

                WriteObject(new PSDataBoxJob(finalJobResource));
            }
        }
Esempio n. 3
0
        public void TestJobCRUDOperations()
        {
            var             resourceGroupName = TestUtilities.GenerateName("SdkRg");
            var             jobName           = TestUtilities.GenerateName("SdkJob");
            ContactDetails  contactDetails    = GetDefaultContactDetails();
            ShippingAddress shippingAddress   = GetDefaultShippingAddress();
            Sku             sku = GetDefaultSku();
            var             destinationAccountsList = GetDestinationAccountsList();
            JobDetails      jobDetails = new DataBoxJobDetails
            {
                ContactDetails  = contactDetails,
                ShippingAddress = shippingAddress
            };

            jobDetails.DataImportDetails = new List <DataImportDetails>();
            jobDetails.DataImportDetails.Add(new DataImportDetails(destinationAccountsList.FirstOrDefault()));
            var jobResource = new JobResource
            {
                Sku      = sku,
                Location = TestConstants.DefaultResourceLocation,
                Details  = jobDetails
            };

            this.RMClient.ResourceGroups.CreateOrUpdate(
                resourceGroupName,
                new ResourceGroup
            {
                Location = TestConstants.DefaultResourceLocation
            });

            var job = this.Client.Jobs.Create(resourceGroupName, jobName, jobResource);

            ValidateJobWithoutDetails(jobName, sku, job);
            Assert.Equal(StageName.DeviceOrdered, job.Status);

            var getJob = this.Client.Jobs.Get(resourceGroupName, jobName, TestConstants.Details);

            ValidateJobWithoutDetails(jobName, sku, getJob);
            ValidateJobDetails(contactDetails, shippingAddress, getJob, JobDeliveryType.NonScheduled);
            Assert.Equal(StageName.DeviceOrdered, job.Status);

            contactDetails.ContactName    = "Update Job";
            getJob.Details.ContactDetails = contactDetails;

            var Details = new UpdateJobDetails
            {
                ContactDetails  = getJob.Details.ContactDetails,
                ShippingAddress = getJob.Details.ShippingAddress
            };

            var updateParams = new JobResourceUpdateParameter
            {
                Details = Details
            };
            var updateJob = this.Client.Jobs.Update(resourceGroupName, jobName, updateParams);

            ValidateJobWithoutDetails(jobName, sku, updateJob);
            Assert.Equal(StageName.DeviceOrdered, updateJob.Status);

            getJob = this.Client.Jobs.Get(resourceGroupName, jobName, TestConstants.Details);
            ValidateJobWithoutDetails(jobName, sku, getJob);
            ValidateJobDetails(contactDetails, shippingAddress, getJob, JobDeliveryType.NonScheduled);
            Assert.Equal(StageName.DeviceOrdered, getJob.Status);

            var jobList = this.Client.Jobs.List();

            Assert.NotNull(jobList);

            jobList = this.Client.Jobs.ListByResourceGroup(resourceGroupName);
            Assert.NotNull(jobList);

            this.Client.Jobs.Cancel(resourceGroupName, jobName, "CancelTest");
            getJob = this.Client.Jobs.Get(resourceGroupName, jobName, TestConstants.Details);
            Assert.Equal(StageName.Cancelled, getJob.Status);

            while (!string.IsNullOrWhiteSpace(getJob.Details.ContactDetails.ContactName))
            {
                Wait(TimeSpan.FromMinutes(5));
                getJob = this.Client.Jobs.Get(resourceGroupName, jobName, TestConstants.Details);
            }
            this.Client.Jobs.Delete(resourceGroupName, jobName);
        }
Esempio n. 4
0
        public void CreateJobWithUserAssignedIdentity()
        {
            var resourceGroupName = TestUtilities.GenerateName("SdkRg");
            var jobName           = TestUtilities.GenerateName("SdkJob");
            //var jobName = "SdkJob5929";
            ContactDetails  contactDetails          = GetDefaultContactDetails();
            ShippingAddress shippingAddress         = GetDefaultShippingAddress();
            Sku             sku                     = GetDefaultSku();
            var             destinationAccountsList = new List <StorageAccountDetails>
            {
                new StorageAccountDetails
                {
                    StorageAccountId = "/subscriptions/fa68082f-8ff7-4a25-95c7-ce9da541242f/resourceGroups/databoxbvt1/providers/Microsoft.Storage/storageAccounts/databoxbvttestaccount2"
                }
            };

            var uaiId      = "/subscriptions/fa68082f-8ff7-4a25-95c7-ce9da541242f/resourceGroups/akvenkat/providers/Microsoft.ManagedIdentity/userAssignedIdentities/sdkIdentity";
            var kekDetails = new KeyEncryptionKey(KekType.CustomerManaged)
            {
                KekType            = KekType.CustomerManaged,
                KekUrl             = @"https://sdkkeyvault.vault.azure.net/keys/SSDKEY/",
                KekVaultResourceID =
                    "/subscriptions/fa68082f-8ff7-4a25-95c7-ce9da541242f/resourceGroups/akvenkat/providers/Microsoft.KeyVault/vaults/SDKKeyVault",
                IdentityProperties = new IdentityProperties
                {
                    Type         = "UserAssigned",
                    UserAssigned = new UserAssignedProperties {
                        ResourceId = uaiId
                    }
                }
            };
            JobDetails jobDetails = new DataBoxJobDetails(contactDetails,
                                                          default(IList <JobStages>), shippingAddress, default(PackageShippingDetails),
                                                          default(PackageShippingDetails), default(IList <DataImportDetails>),
                                                          default(IList <DataExportDetails>), default(Preferences),
                                                          default(IList <CopyLogDetails>), default(string), default(string),
                                                          kekDetails);

            jobDetails.DataImportDetails = new List <DataImportDetails>();
            jobDetails.DataImportDetails.Add(new DataImportDetails(destinationAccountsList.FirstOrDefault()));

            var jobResource = new JobResource
            {
                Sku      = sku,
                Location = TestConstants.DefaultResourceLocation,
                Details  = jobDetails,
            };


            UserAssignedIdentity uid = new UserAssignedIdentity();
            var identity             = new ResourceIdentity//ResourceIdentity checked by auto mapper
            {
                Type = "UserAssigned",
                UserAssignedIdentities = new Dictionary <string, UserAssignedIdentity>
                {
                    { uaiId, uid }
                },
            };

            jobResource.Identity = identity;

            this.RMClient.ResourceGroups.CreateOrUpdate(
                resourceGroupName,
                new ResourceGroup
            {
                Location = TestConstants.DefaultResourceLocation
            });

            var job = this.Client.Jobs.Create(resourceGroupName, jobName, jobResource);

            ValidateJobWithoutDetails(jobName, sku, job);
            Assert.Equal(StageName.DeviceOrdered, job.Status);
            String iden = "UserAssigned";

            Assert.Equal(iden, job.Identity.Type);
            var getJob = this.Client.Jobs.Get(resourceGroupName, jobName, TestConstants.Details);

            ValidateJobWithoutDetails(jobName, sku, getJob);
            ValidateJobDetails(contactDetails, shippingAddress, getJob, JobDeliveryType.NonScheduled);
            Assert.Equal(StageName.DeviceOrdered, getJob.Status);
            Assert.True(!string.IsNullOrEmpty(getJob.Identity.UserAssignedIdentities[uaiId].ClientId));
            Assert.True(!string.IsNullOrEmpty(getJob.Identity.UserAssignedIdentities[uaiId].PrincipalId));
        }