public virtual PSIntegrationRuntime CreateOrUpdateIntegrationRuntime(CreatePSIntegrationRuntimeParameters parameters)
        {
            PSIntegrationRuntime psIntegrationRuntime = null;

            Action createOrUpdateIntegrationRuntime = () =>
            {
                var integrationRuntime = this.CreateOrUpdateIntegrationRuntimeAsync(
                    parameters.ResourceGroupName,
                    parameters.DataFactoryName,
                    parameters.Name,
                    parameters.IntegrationRuntimeResource).ConfigureAwait(true).GetAwaiter().GetResult();

                var managed = integrationRuntime.Properties as ManagedIntegrationRuntime;
                if (managed != null)
                {
                    psIntegrationRuntime = new PSManagedIntegrationRuntime(integrationRuntime,
                                                                           parameters.ResourceGroupName,
                                                                           parameters.DataFactoryName);
                }
                else
                {
                    var selfHosted = integrationRuntime.Properties as SelfHostedIntegrationRuntime;
                    if (selfHosted != null)
                    {
                        psIntegrationRuntime = new PSSelfHostedIntegrationRuntime(integrationRuntime,
                                                                                  parameters.ResourceGroupName,
                                                                                  parameters.DataFactoryName);
                    }
                }
            };

            parameters.ConfirmAction(
                parameters.Force,      // prompt only if the integration runtime exists
                string.Format(
                    CultureInfo.InvariantCulture,
                    Resources.IntegrationRuntimeExists,
                    parameters.Name,
                    parameters.DataFactoryName),
                string.Format(
                    CultureInfo.InvariantCulture,
                    Resources.IntegrationRuntimeUpdating,
                    parameters.Name,
                    parameters.DataFactoryName),
                parameters.Name,
                createOrUpdateIntegrationRuntime,
                () => parameters.IsUpdate);

            return(psIntegrationRuntime);
        }
        public override void ExecuteCmdlet()
        {
            this.ByResourceId();
            this.ByIntegrationRuntimeObject();

            if (string.Equals(Type, Constants.IntegrationRuntimeTypeManaged, StringComparison.OrdinalIgnoreCase))
            {
                if (AuthKey != null || !string.IsNullOrWhiteSpace(SharedIntegrationRuntimeResourceId))
                {
                    throw new PSArgumentException(
                              string.Format(
                                  CultureInfo.InvariantCulture,
                                  Resources.InvalidIntegrationRuntimeSharing),
                              "AuthKey");
                }
            }

            IntegrationRuntimeResource resource = null;
            var isUpdate = false;

            try
            {
                resource = DataFactoryClient.GetIntegrationRuntimeAsync(
                    ResourceGroupName,
                    DataFactoryName,
                    Name).ConfigureAwait(true).GetAwaiter().GetResult().IntegrationRuntime;

                isUpdate = true;
                if (Type != null && (resource.Properties is ManagedIntegrationRuntime ^
                                     Type.Equals(Constants.IntegrationRuntimeTypeManaged, StringComparison.OrdinalIgnoreCase)))
                {
                    throw new PSArgumentException(
                              string.Format(
                                  CultureInfo.InvariantCulture,
                                  Resources.IntegrationRuntimeWrongType,
                                  Name),
                              "Type");
                }

                if (AuthKey != null)
                {
                    throw new PSArgumentException(
                              string.Format(
                                  CultureInfo.InvariantCulture,
                                  Resources.UpdateAuthKeyNotAllowed,
                                  Name),
                              "AuthKey");
                }
            }
            catch (CloudException e)
            {
                if (e.Response.StatusCode == HttpStatusCode.NotFound)
                {
                    if (Type == null)
                    {
                        throw new PSArgumentException(
                                  string.Format(
                                      CultureInfo.InvariantCulture,
                                      Resources.NeedIntegrationRuntimeType),
                                  "Type");
                    }

                    resource = new IntegrationRuntimeResource();
                    if (Type.Equals(Constants.IntegrationRuntimeTypeManaged, StringComparison.OrdinalIgnoreCase))
                    {
                        resource.Properties = new ManagedIntegrationRuntime();
                    }
                    else
                    {
                        var selfHosted = new SelfHostedIntegrationRuntime();
                        if (AuthKey != null)
                        {
                            var authKey = ConvertToUnsecureString(AuthKey);
                            selfHosted.LinkedInfo = new LinkedIntegrationRuntimeKeyAuthorization(new SecureString(authKey));
                        }

                        resource.Properties = selfHosted;
                    }
                }
                else
                {
                    throw;
                }
            }

            if (!string.IsNullOrWhiteSpace(SharedIntegrationRuntimeResourceId))
            {
                var selfHostedIr = resource.Properties as SelfHostedIntegrationRuntime;
                if (selfHostedIr != null)
                {
                    selfHostedIr.LinkedInfo = new LinkedIntegrationRuntimeRbacAuthorization(SharedIntegrationRuntimeResourceId);
                }
                else
                {
                    throw new PSArgumentException(
                              string.Format(
                                  CultureInfo.InvariantCulture,
                                  Resources.InvalidIntegrationRuntimeSharing),
                              "SharedIntegrationRuntimeResourceId");
                }
            }

            if (!string.IsNullOrWhiteSpace(Description))
            {
                resource.Properties.Description = Description;
            }

            var managedIr = resource.Properties as ManagedIntegrationRuntime;

            if (managedIr != null)
            {
                HandleManagedIntegrationRuntime(managedIr);
            }

            var parameters = new CreatePSIntegrationRuntimeParameters()
            {
                ResourceGroupName = ResourceGroupName,
                DataFactoryName   = DataFactoryName,
                Name     = Name,
                IsUpdate = isUpdate,
                IntegrationRuntimeResource = resource,
                Force         = Force.IsPresent,
                ConfirmAction = base.ConfirmAction
            };

            WriteObject(DataFactoryClient.CreateOrUpdateIntegrationRuntime(parameters));
        }
Beispiel #3
0
        public override void ExecuteCmdlet()
        {
            this.ByResourceId();
            this.ByIntegrationRuntimeObject();

            IntegrationRuntimeResource resource = null;
            var isUpdate = false;

            try
            {
                resource = DataFactoryClient.GetIntegrationRuntimeAsync(
                    ResourceGroupName,
                    DataFactoryName,
                    base.Name).ConfigureAwait(true).GetAwaiter().GetResult().IntegrationRuntime;

                isUpdate = true;
                if (Type != null && (resource.Properties is ManagedIntegrationRuntime ^
                                     Type.Equals(Constants.IntegrationRuntimeTypeManaged, StringComparison.OrdinalIgnoreCase)))
                {
                    throw new PSArgumentException(
                              string.Format(
                                  CultureInfo.InvariantCulture,
                                  Resources.IntegrationRuntimeWrongType,
                                  base.Name),
                              "Type");
                }
            }
            catch (ErrorResponseException e)
            {
                if (e.Response.StatusCode == HttpStatusCode.NotFound)
                {
                    if (Type == null)
                    {
                        throw new PSArgumentException(
                                  string.Format(
                                      CultureInfo.InvariantCulture,
                                      Resources.NeedIntegrationRuntimeType),
                                  "Type");
                    }

                    resource = new IntegrationRuntimeResource();
                    if (Type.Equals(Constants.IntegrationRuntimeTypeManaged, StringComparison.OrdinalIgnoreCase))
                    {
                        resource.Properties = new ManagedIntegrationRuntime();
                    }
                    else
                    {
                        resource.Properties = new SelfHostedIntegrationRuntime();
                    }
                }
                else
                {
                    throw;
                }
            }

            if (!string.IsNullOrWhiteSpace(Description))
            {
                resource.Properties.Description = Description;
            }

            var managedIr = resource.Properties as ManagedIntegrationRuntime;

            if (managedIr != null)
            {
                HandleManagedIntegrationRuntime(managedIr);
            }

            var parameters = new CreatePSIntegrationRuntimeParameters()
            {
                ResourceGroupName = ResourceGroupName,
                DataFactoryName   = DataFactoryName,
                Name     = base.Name,
                IsUpdate = isUpdate,
                IntegrationRuntimeResource = resource,
                Force         = Force.IsPresent,
                ConfirmAction = base.ConfirmAction
            };

            WriteObject(DataFactoryClient.CreateOrUpdateIntegrationRuntime(parameters));
        }