Example #1
0
        public override void ExecuteCmdlet()
        {
            if (this.IsParameterBound(c => c.ResourceId))
            {
                var resourceIdentifier = new ResourceIdentifier(this.ResourceId);
                this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
                this.WorkspaceName     = resourceIdentifier.ParentResource;
                this.WorkspaceName     = this.WorkspaceName.Substring(this.WorkspaceName.LastIndexOf('/') + 1);
                this.Name = resourceIdentifier.ResourceName;
            }

            if (this.IsParameterBound(c => c.WorkspaceObject))
            {
                this.ResourceGroupName = new ResourceIdentifier(this.WorkspaceObject.Id).ResourceGroupName;
                this.WorkspaceName     = this.WorkspaceObject.Name;
            }

            if (this.IsParameterBound(c => c.InputObject))
            {
                this.ResourceGroupName = InputObject.ResourceGroupName;
                this.WorkspaceName     = InputObject.WorkspaceName;
                this.Name = InputObject.Name;
            }

            if (string.Equals(Type, SynapseConstants.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 = SynapseAnalyticsClient.GetIntegrationRuntimeAsync(
                    ResourceGroupName,
                    WorkspaceName,
                    Name).ConfigureAwait(true).GetAwaiter().GetResult().IntegrationRuntime;

                isUpdate = true;
                if (Type != null && (resource.Properties is ManagedIntegrationRuntime ^
                                     Type.Equals(SynapseConstants.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(SynapseConstants.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,
                WorkspaceName     = WorkspaceName,
                Name     = Name,
                IsUpdate = isUpdate,
                IntegrationRuntimeResource = resource,
                Force         = Force.IsPresent,
                ConfirmAction = base.ConfirmAction
            };

            WriteObject(SynapseAnalyticsClient.CreateOrUpdateIntegrationRuntime(parameters));
        }
        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
                    {
                        var selfHosted = new SelfHostedIntegrationRuntime();
                        if (AuthKey != null)
                        {
                            var authKey = ConvertToUnsecureString(AuthKey);
                            selfHosted.LinkedInfo = new LinkedIntegrationRuntimeKey(new SecureString(authKey));
                        }

                        resource.Properties = selfHosted;
                    }
                }
                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));
        }