Ejemplo n.º 1
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            User user = WebsitesClient.GetPublishingCredentials(ResourceGroupName, Name, Slot);

            HttpResponseMessage r;
            string deployUrl;
            string deploymentStatusUrl = user.ScmUri + "/api/deployments/latest";

            if (ArchivePath.ToLower().EndsWith("war"))
            {
                deployUrl = user.ScmUri + "/api/wardeploy?isAsync=true";
            }
            else if (ArchivePath.ToLower().EndsWith("zip") || ArchivePath.ToLower().EndsWith("jar"))
            {
                deployUrl = user.ScmUri + "/api/zipdeploy?isAsync=true";
            }
            else
            {
                throw new Exception("Unknown archive type.");
            }

            Action zipDeployAction = () =>
            {
                using (var s = File.OpenRead(ArchivePath))
                {
                    HttpClient client    = new HttpClient();
                    var        byteArray = Encoding.ASCII.GetBytes(user.PublishingUserName + ":" + user.PublishingPassword);
                    client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
                    HttpContent fileContent = new StreamContent(s);
                    fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("multipart/form-data");
                    r = client.PostAsync(deployUrl, fileContent).Result;

                    int numChecks = 0;
                    do
                    {
                        Thread.Sleep(TimeSpan.FromSeconds(2));
                        r = client.GetAsync(deploymentStatusUrl).Result;
                        numChecks++;
                    } while (r.StatusCode == HttpStatusCode.Accepted && numChecks < NumStatusChecks);

                    if (r.StatusCode == HttpStatusCode.Accepted && numChecks >= NumStatusChecks)
                    {
                        var rec = new ErrorRecord(new Exception("Maximum status polling time exceeded. Deployment is still in progress."), string.Empty, ErrorCategory.OperationTimeout, null);
                        WriteError(rec);
                    }
                    else if (r.StatusCode != HttpStatusCode.OK)
                    {
                        var rec = new ErrorRecord(new Exception("Deployment failed with status code " + r.StatusCode), string.Empty, ErrorCategory.InvalidResult, null);
                        WriteError(rec);
                    }
                }
            };

            ConfirmAction(this.Force.IsPresent, $"Contents of {ArchivePath} will be deployed to the web app {Name}.", "The web app has been deployed.", Name, zipDeployAction);

            PSSite app = new PSSite(WebsitesClient.GetWebApp(ResourceGroupName, Name, Slot));

            WriteObject(app);
        }
 public override void ExecuteCmdlet()
 {
     if (ParameterSetName == ParameterSet2Name)
     {
         string rg, name, slot;
         Utilities.CmdletHelpers.TryParseWebAppMetadataFromResourceId(WebApp.Id, out rg, out name, out slot);
         ResourceGroupName = rg;
         Name     = name;
         SlotName = slot;
     }
     WriteObject(WebsitesClient.GetPublishingCredentials(ResourceGroupName, Name).ScmUri + "/docker/hook");
 }