Exemplo n.º 1
0
 public override void ExecuteCmdlet()
 {
     base.ExecuteCmdlet();
     ConfirmAction(
         Force.IsPresent,
         string.Format(Properties.Resources.RemoveWebsiteWarning, Name),
         Properties.Resources.RemoveWebsiteMessage,
         Name,
         () =>
     {
         WebsitesClient.RemoveWebApp(ResourceGroupName, Name, null, deleteEmptyServerFarmByDefault, deleteMetricsByDefault, deleteSlotsByDefault);
     });
 }
        public override void ExecuteCmdlet()
        {
            WebJobHistoryFilterOptions options = new WebJobHistoryFilterOptions()
            {
                Name    = Name,
                Slot    = Slot,
                JobName = JobName,
                Latest  = Latest,
                RunId   = RunId
            };

            WriteObject(WebsitesClient.FilterWebJobHistory(options), true);
        }
Exemplo n.º 3
0
        public override void ExecuteCmdlet()
        {
            if (HyperV.IsPresent && Tier != "PremiumContainer")
            {
                throw new Exception("HyperV switch is only allowed for PremiumContainer tier");
            }
            if (!HyperV.IsPresent && Tier == "PremiumContainer")
            {
                throw new Exception("PremiumContainer tier is only allowed if HyperV switch is present");
            }

            if (string.IsNullOrWhiteSpace(Tier))
            {
                Tier = "Free";
            }

            if (string.IsNullOrWhiteSpace(WorkerSize))
            {
                WorkerSize = "Small";
            }

            var aseResourceGroupName = AseResourceGroupName;

            if (!string.IsNullOrEmpty(AseName) &&
                string.IsNullOrEmpty(aseResourceGroupName))
            {
                aseResourceGroupName = ResourceGroupName;
            }

            var capacity = NumberofWorkers < 1 ? 1 : NumberofWorkers;
            var skuName  = CmdletHelpers.GetSkuName(Tier, WorkerSize);

            var sku = new SkuDescription
            {
                Tier     = Tier,
                Name     = skuName,
                Capacity = capacity
            };

            var appServicePlan = new AppServicePlan
            {
                Location       = Location,
                Sku            = sku,
                AdminSiteName  = null,
                PerSiteScaling = PerSiteScaling,
                IsXenon        = HyperV.IsPresent
            };


            WriteObject(new PSAppServicePlan(WebsitesClient.CreateOrUpdateAppServicePlan(ResourceGroupName, Name, appServicePlan, AseName, aseResourceGroupName)), true);
        }
Exemplo n.º 4
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            string deletedSiteId = GetDeletedSiteResourceId();

            ResolveTargetParameters();

            DeletedAppRestoreRequest restoreReq = new DeletedAppRestoreRequest()
            {
                DeletedSiteId        = deletedSiteId,
                RecoverConfiguration = !this.RestoreContentOnly,
                UseDRSecondary       = UseDisasterRecovery
            };

            Action restoreAction = () => WebsitesClient.RestoreDeletedWebApp(TargetResourceGroupName, TargetName, TargetSlot, restoreReq);

            if (WebsitesClient.WebAppExists(TargetResourceGroupName, TargetName, TargetSlot))
            {
                ConfirmAction(this.Force.IsPresent, "Target web app contents will be overwritten with the contents of the deleted app.",
                              "The deleted app has been restored.", TargetName, restoreAction);
            }
            else
            {
                if (string.IsNullOrEmpty(TargetAppServicePlanName))
                {
                    throw new Exception("Target app " + TargetName + " does not exist. Specify TargetAppServicePlanName for it to be created automatically.");
                }
                AppServicePlan plan = WebsitesClient.GetAppServicePlan(TargetResourceGroupName, TargetAppServicePlanName);
                if (plan == null)
                {
                    throw new Exception("Target App Service Plan " + TargetAppServicePlanName + " not found in target Resource Group " + TargetResourceGroupName);
                }
                Action createRestoreAction = () =>
                {
                    WebsitesClient.CreateWebApp(TargetResourceGroupName, TargetName, TargetSlot, plan.Location, TargetAppServicePlanName,
                                                null, string.Empty, string.Empty);
                    restoreAction();
                };
                string confirmMsg = string.Format("This web app will be created. App Name: {0}, Resource Group: {1}", TargetResourceGroupName, TargetName);
                if (!string.IsNullOrEmpty(TargetSlot))
                {
                    confirmMsg += ", Slot: " + TargetSlot;
                }
                ConfirmAction(this.Force.IsPresent, confirmMsg, "The deleted app has been restored.", TargetName, createRestoreAction);
            }

            PSSite restoredApp = new PSSite(WebsitesClient.GetWebApp(TargetResourceGroupName, TargetName, TargetSlot));

            WriteObject(restoredApp);
        }
Exemplo n.º 5
0
        public override void ExecuteCmdlet()
        {
            CloningInfo cloningInfo = null;

            if (SourceWebApp != null)
            {
                cloningInfo = new CloningInfo
                {
                    SourceWebAppId            = SourceWebApp.Id,
                    CloneCustomHostNames      = !IgnoreCustomHostNames.IsPresent,
                    CloneSourceControl        = !IgnoreSourceControl.IsPresent,
                    TrafficManagerProfileId   = TrafficManagerProfileId,
                    TrafficManagerProfileName = TrafficManagerProfileName,
                    ConfigureLoadBalancing    = !string.IsNullOrEmpty(TrafficManagerProfileId) || !string.IsNullOrEmpty(TrafficManagerProfileName),
                    AppSettingsOverrides      = AppSettingsOverrides == null ? null : AppSettingsOverrides.Cast <DictionaryEntry>().ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value.ToString(), StringComparer.Ordinal)
                };
            }

            var cloneWebAppSlots = false;

            string[] slotNames            = null;
            string   srcResourceGroupName = null;
            string   srcwebAppName        = null;
            string   srcSlotName          = null;

            if (IncludeSourceWebAppSlots.IsPresent)
            {
                CmdletHelpers.TryParseWebAppMetadataFromResourceId(SourceWebApp.Id, out srcResourceGroupName,
                                                                   out srcwebAppName, out srcSlotName);
                var slots = WebsitesClient.ListWebApps(srcResourceGroupName, srcwebAppName);
                if (slots != null && slots.Any())
                {
                    slotNames        = slots.Select(s => s.Name.Replace(srcwebAppName + "/", string.Empty)).ToArray();
                    cloneWebAppSlots = true;
                }
            }

            if (cloneWebAppSlots)
            {
                WriteVerboseWithTimestamp("Cloning source web app '{0}' to destination web app {1}", srcwebAppName, Name);
            }

            WriteObject(WebsitesClient.CreateWebApp(ResourceGroupName, Name, null, Location, AppServicePlan, cloningInfo, AseName, AseResourceGroupName));

            if (cloneWebAppSlots)
            {
                WriteVerboseWithTimestamp("Cloning all deployment slots of source web app '{0}' to destination web app {1}", srcwebAppName, Name);
                CloneSlots(slotNames);
            }
        }
Exemplo n.º 6
0
 public override void ExecuteCmdlet()
 {
     ConfirmAction(
         Force.IsPresent,
         string.Format(Resources.RemoveWebsiteWarning, Name),
         Resources.RemoveWebsiteMessage,
         Name,
         () =>
     {
         Site websiteObject = WebsitesClient.GetWebsite(Name);
         WebsitesClient.DeleteWebsite(websiteObject.WebSpace, Name);
         Cache.RemoveSite(CurrentSubscription.SubscriptionId, websiteObject);
     });
 }
Exemplo n.º 7
0
        private Site CreateSite(WebSpace webspace, SiteWithWebSpace website)
        {
            Site createdWebsite = null;

            try
            {
                if (WebsitesClient.WebsiteExists(website.Name) && !string.IsNullOrEmpty(Slot))
                {
                    createdWebsite = WebsitesClient.GetWebsite(website.Name);

                    // API makes sure site is in Standard mode
                    WebsitesClient.CreateWebsite(createdWebsite.WebSpace, website, Slot);
                }
                else
                {
                    WebsitesClient.CreateWebsite(webspace.Name, website, null);
                }

                createdWebsite = WebsitesClient.GetWebsite(website.Name);

                Cache.AddSite(CurrentContext.Subscription.Id.ToString(), createdWebsite);
                SiteConfig websiteConfiguration = WebsitesClient.GetWebsiteConfiguration(createdWebsite.Name, Slot);
                WriteObject(new SiteWithConfig(createdWebsite, websiteConfiguration));
            }
            catch (CloudException ex)
            {
                if (SiteAlreadyExists(ex) && (Git || GitHub))
                {
                    // Handle conflict - it's ok to attempt to use cmdlet on an
                    // existing website if you're updating the source control stuff.
                    WriteWarning(ex.Message);
                    createdWebsite = WebsitesClient.GetWebsite(website.Name, null);
                }
                else if (HostNameValidationFailed(ex))
                {
                    WriteExceptionError(new Exception(Resources.InvalidHostnameValidation));
                }
                else if (BadPlan(ex))
                {
                    throw new EndpointNotFoundException();
                }
                else
                {
                    WriteExceptionError(new Exception(ex.Message));
                }
            }

            return(createdWebsite);
        }
        public override void ExecuteCmdlet()
        {
            if (!string.IsNullOrWhiteSpace(ResourceGroupName) && !string.IsNullOrWhiteSpace(WebAppName))
            {
                var                   webApp                = new PSSite(WebsitesClient.GetWebApp(ResourceGroupName, WebAppName, SlotName));
                SiteConfig            siteConfig            = webApp.SiteConfig;
                var                   accessRestrictionList = TargetScmSite ? siteConfig.ScmIpSecurityRestrictions : siteConfig.IpSecurityRestrictions;
                IpSecurityRestriction ipSecurityRestriction = null;
                int                   intPriority           = checked ((int)Priority);
                switch (ParameterSetName)
                {
                case IpAddressParameterSet:
                    ipSecurityRestriction = new IpSecurityRestriction(IpAddress, null, null, null, null, Action, null, intPriority, Name, Description);
                    accessRestrictionList.Add(ipSecurityRestriction);
                    break;

                case SubnetNameParameterSet:
                case SubnetIdParameterSet:
                    var Subnet = ParameterSetName == SubnetNameParameterSet ? SubnetName : SubnetId;
                    //Fetch RG of given SubNet
                    var subNetResourceGroupName = CmdletHelpers.GetSubnetResourceGroupName(DefaultContext, Subnet, VirtualNetworkName);
                    //If unble to fetch SubNet rg from above step, use the input RG to get validation error from api call.
                    subNetResourceGroupName = !String.IsNullOrEmpty(subNetResourceGroupName) ? subNetResourceGroupName : ResourceGroupName;
                    var subnetResourceId = CmdletHelpers.ValidateSubnet(Subnet, VirtualNetworkName, subNetResourceGroupName, DefaultContext.Subscription.Id);
                    if (!IgnoreMissingServiceEndpoint)
                    {
                        CmdletHelpers.VerifySubnetDelegation(subnetResourceId);
                    }

                    ipSecurityRestriction = new IpSecurityRestriction(null, null, subnetResourceId, null, null, Action, null, intPriority, Name, Description);
                    accessRestrictionList.Add(ipSecurityRestriction);
                    break;
                }

                if (ShouldProcess(WebAppName, $"Adding Access Restriction Rule for Web App '{WebAppName}'"))
                {
                    // Update web app configuration
                    WebsitesClient.UpdateWebAppConfiguration(ResourceGroupName, webApp.Location, WebAppName, SlotName, siteConfig);

                    if (PassThru)
                    {
                        // Refresh object to get the final state
                        webApp = new PSSite(WebsitesClient.GetWebApp(ResourceGroupName, WebAppName, SlotName));
                        var accessRestrictionSettings = new PSAccessRestrictionConfig(ResourceGroupName, WebAppName, webApp.SiteConfig, SlotName);
                        WriteObject(accessRestrictionSettings);
                    }
                }
            }
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            var list = WebsitesClient.GetSiteSnapshots(ResourceGroupName, Name, Slot, UseDisasterRecovery.IsPresent).Select(s => {
                return(new AzureWebAppSnapshot()
                {
                    ResourceGroupName = this.ResourceGroupName,
                    Name = this.Name,
                    Slot = string.IsNullOrEmpty(this.Slot) ? "Production" : this.Slot,
                    SnapshotTime = DateTime.Parse(s.Time, CultureInfo.InvariantCulture)
                });
            }).OrderByDescending(s => s.SnapshotTime).ToArray();

            WriteObject(list, true);
        }
        public override void ExecuteCmdlet()
        {
            var properties = new Dictionary <DiagnosticProperties, object>();

            properties[DiagnosticProperties.LogLevel] = LogLevel;

            if (File.IsPresent)
            {
                WebsitesClient.EnableApplicationDiagnostic(Name, WebsiteDiagnosticOutput.FileSystem, properties, Slot);
            }
            else if (TableStorage.IsPresent || BlobStorage.IsPresent)
            {
                if (string.IsNullOrWhiteSpace(StorageAccountName))
                {
                    properties[DiagnosticProperties.StorageAccountName] = Profile.Context.Subscription.GetStorageAccountName();
                }
                else
                {
                    properties[DiagnosticProperties.StorageAccountName] = StorageAccountName;
                }

                if (TableStorage.IsPresent)
                {
                    properties[DiagnosticProperties.StorageTableName] = string.IsNullOrEmpty(StorageTableName)
                        ? "websitesapplogs" + Name.ToLowerInvariant() : StorageTableName.ToLowerInvariant();

                    WebsitesClient.EnableApplicationDiagnostic(Name, WebsiteDiagnosticOutput.StorageTable, properties, Slot);
                }
                else
                {
                    // Blob storage

                    properties[DiagnosticProperties.StorageBlobContainerName] = string.IsNullOrEmpty(StorageBlobContainerName)
                        ? "websitesapplogs-" + Name.ToLowerInvariant() : StorageBlobContainerName.ToLowerInvariant();

                    WebsitesClient.EnableApplicationDiagnostic(Name, WebsiteDiagnosticOutput.StorageBlob, properties, Slot);
                }
            }
            else
            {
                throw new PSArgumentException();
            }

            if (PassThru.IsPresent)
            {
                WriteObject(true);
            }
        }
Exemplo n.º 11
0
        public override void ExecuteCmdlet()
        {
            PrepareFileFullPaths();

            // If a project file is specified, use MSBuild to build the package zip file.
            if (!string.IsNullOrEmpty(ProjectFile))
            {
                WriteVerbose(string.Format(Resources.StartBuildingProjectTemplate, fullProjectFile));
                fullPackage = WebsitesClient.BuildWebProject(fullProjectFile, configuration, Path.Combine(CurrentPath(), "build.log"));
                WriteVerbose(string.Format(Resources.CompleteBuildingProjectTemplate, fullProjectFile));
            }

            // Resolve the full path of the package file or folder when the "Package" parameter set is used.
            fullPackage = string.IsNullOrEmpty(fullPackage) ? this.TryResolvePath(Package) : fullPackage;
            WriteVerbose(string.Format(Resources.StartPublishingProjectTemplate, fullPackage));

            fullSetParametersFile = string.IsNullOrEmpty(fullSetParametersFile) ? this.TryResolvePath(SetParametersFile) : fullSetParametersFile;

            // Convert dynamic parameters to a connection string hash table.
            var connectionStrings = ConnectionString;

            if (connectionStrings == null)
            {
                connectionStrings = new Hashtable();
                if (dynamicParameters != null)
                {
                    foreach (var dp in dynamicParameters)
                    {
                        if (MyInvocation.BoundParameters.ContainsKey(dp.Key))
                        {
                            connectionStrings[dp.Value.Name.ToString()] = dp.Value.Value.ToString();
                        }
                    }
                }
            }

            try
            {
                // Publish the package.
                WebsitesClient.PublishWebProject(Name, Slot, fullPackage, fullSetParametersFile, connectionStrings, SkipAppData.IsPresent, DoNotDelete.IsPresent);
                WriteVerbose(string.Format(Resources.CompletePublishingProjectTemplate, fullPackage));
            }
            catch (Exception)
            {
                WriteVerbose(string.Format(Resources.FailPublishingProjectTemplate, fullPackage));
                throw;
            }
        }
Exemplo n.º 12
0
 public override void ExecuteCmdlet()
 {
     try
     {
         if (string.IsNullOrEmpty(Name) && websiteNameDiscovery)
         {
             // If the website name was not specified as a parameter try to infer it
             Name = GitWebsite.ReadConfiguration().Name;
         }
         Slot = string.IsNullOrEmpty(Slot) ? WebsitesClient.GetSlotName(Name) : Slot;
     }
     catch (Exception ex)
     {
         WriteExceptionError(ex);
     }
 }
Exemplo n.º 13
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            BackupRequest request = new BackupRequest()
            {
                // Location is required by Resource (base class of BackupRequest)
                // to not be null, but is not actually significant for the request.
                Location          = "",
                StorageAccountUrl = this.StorageAccountUrl,
                BackupRequestName = this.BackupName,
                Databases         = this.Databases
            };
            var backup = WebsitesClient.BackupSite(ResourceGroupName, Name, Slot, request);

            WriteObject(BackupRestoreUtils.BackupItemToAppBackup(backup, ResourceGroupName, Name, Slot));
        }
        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;
            }

            if (this.Force.IsPresent || ShouldProcess(Properties.Resources.EnterContainerPSSessionConfirmation))
            {
                WebsitesClient.RunWebAppContainerPSSessionScript(this, ResourceGroupName, Name, SlotName, true);
            }
        }
Exemplo n.º 15
0
        private void WriteWebsite(Site websiteObject)
        {
            SiteConfig config = WebsitesClient.GetWebsiteConfiguration(websiteObject.Name);

            var diagnosticSettings = new DiagnosticsSettings();

            try
            {
                diagnosticSettings = WebsitesClient.GetApplicationDiagnosticsSettings(websiteObject.Name);
            }
            catch
            {
                // Ignore exception and use default values
            }

            WriteObject(new SiteWithConfig(websiteObject, config, diagnosticSettings), false);
        }
Exemplo n.º 16
0
        private void GetBySubscription()
        {
            const string progressDescriptionFormat      = "Progress: {0}/{1} resource groups processed.";
            const string progressCurrentOperationFormat = "Getting web apps for resource group '{0}'";
            var          progressRecord = new ProgressRecord(1, "Get web apps from all resource groups in subscription", "Progress:")
            {
                CurrentOperation = "Getting all subscription resource groups ..."
            };

            WriteProgress(progressRecord);

            var resourceGroups = ResourcesClient.ResourceManagementClient.FilterResources(new FilterResourcesOptions
            {
                ResourceType = "Microsoft.Web/Sites"
            }).Select(s => s.ResourceGroupName).Distinct(StringComparer.OrdinalIgnoreCase).ToArray();

            var list = new List <PSSite>();

            for (var i = 0; i < resourceGroups.Length; i++)
            {
                var rg = resourceGroups[i];
                try
                {
                    var result = WebsitesClient.ListWebApps(rg, null);
                    if (result != null)
                    {
                        foreach (var item in result)
                        {
                            list.Add(new PSSite(item));
                        }
                    }
                }
                catch (Exception e)
                {
                    WriteExceptionError(e);
                }

                progressRecord.CurrentOperation  = string.Format(progressCurrentOperationFormat, rg);
                progressRecord.StatusDescription = string.Format(progressDescriptionFormat, i + 1, resourceGroups.Length);
                progressRecord.PercentComplete   = (100 * (i + 1)) / resourceGroups.Length;
                WriteProgress(progressRecord);
            }

            WriteObject(list, true);
        }
Exemplo n.º 17
0
        private string GetDeletedSiteResourceId()
        {
            switch (ParameterSetName)
            {
            case FromDeletedResourceNameParameterSet:
                IEnumerable <string> locations;
                if (string.IsNullOrEmpty(Location))
                {
                    locations = ResourcesClient.GetDeletedSitesLocations();
                }
                else
                {
                    locations = new List <string> {
                        Location
                    };
                }

                var deletedSites = WebsitesClient.GetDeletedSitesFromLocations(locations).Where(ds =>
                {
                    bool match = string.Equals(ds.ResourceGroup, ResourceGroupName, StringComparison.InvariantCultureIgnoreCase) &&
                                 string.Equals(ds.Name, Name, StringComparison.InvariantCultureIgnoreCase);
                    if (!string.IsNullOrEmpty(Slot))
                    {
                        match = match && string.Equals(ds.Slot, Slot, StringComparison.InvariantCultureIgnoreCase);
                    }
                    return(match);
                });
                if (!deletedSites.Any())
                {
                    throw new Exception("Deleted app not found");
                }
                DeletedSite lastDeleted = deletedSites.OrderBy(ds => DateTime.Parse(ds.DeletedTimestamp, new System.Globalization.CultureInfo("en-US"))).Last();
                if (deletedSites.Count() > 1)
                {
                    WriteWarning("Found multiple matching deleted apps. Restoring the most recently deleted app, deleted at " + lastDeleted.DeletedTimestamp);
                }
                return("/subscriptions/" + DefaultContext.Subscription.Id + "/providers/Microsoft.Web/locations/" + lastDeleted.GeoRegionName + "/deletedSites/" + lastDeleted.DeletedSiteId);

            case FromDeletedAppParameterSet:
                return("/subscriptions/" + InputObject.SubscriptionId + "/providers/Microsoft.Web/locations/" + InputObject.Location + "/deletedSites/" + InputObject.DeletedSiteId);

            default:
                throw new Exception("Parameter set error");
            }
        }
Exemplo n.º 18
0
        private void UpdateHostNames()
        {
            if (HostNames != null)
            {
                string        hostname     = WebsitesClient.GetHostName(Name, Slot);
                List <string> newHostNames = new List <string>();
                if (!HostNames.Contains(hostname))
                {
                    newHostNames.Add(hostname);
                    newHostNames.AddRange(HostNames);
                }

                if (newHostNames.Count > 0)
                {
                    WebsitesClient.UpdateWebsiteHostNames(website, newHostNames, Slot);
                }
            }
        }
Exemplo n.º 19
0
        private void UpdateConfig()
        {
            bool changes             = false;
            var  websiteConfigUpdate = new SiteWithConfig(website, currentSiteConfig);

            if (SiteWithConfig != null)
            {
                websiteConfigUpdate = SiteWithConfig;
                changes             = true;
            }

            changes = changes || ObjectDeltaMapper.Map(this, currentSiteConfig, websiteConfigUpdate, "HostNames", "SiteWithConfig", "PassThru");

            if (changes)
            {
                WebsitesClient.UpdateWebsiteConfiguration(Name, websiteConfigUpdate.GetSiteConfig(), Slot);
            }
        }
Exemplo n.º 20
0
        private void GetNoName()
        {
            Do(() =>
            {
                List <Site> websites;
                if (string.IsNullOrEmpty(Slot))
                {
                    websites = WebsitesClient.ListWebsites();
                }
                else
                {
                    websites = WebsitesClient.ListWebsites(Slot);
                }

                Cache.SaveSites(Profile.Context.Subscription.Id.ToString(), new Sites(websites));
                WriteWebsites(websites);
            });
        }
        public override void ExecuteCmdlet()
        {
            WebsitesClient = WebsitesClient ?? new WebsitesClient(CurrentSubscription, WriteDebug);

            if (File.IsPresent)
            {
                WebsitesClient.DisableApplicationDiagnostic(Name, WebsiteDiagnosticOutput.FileSystem);
            }
            else if (Storage.IsPresent)
            {
                WebsitesClient.DisableApplicationDiagnostic(Name, WebsiteDiagnosticOutput.StorageTable);
            }

            if (PassThru.IsPresent)
            {
                WriteObject(true);
            }
        }
Exemplo n.º 22
0
        private WebSpace GetDefaultWebSpace(IList <WebSpace> webspaceList)
        {
            WebSpace webspace = webspaceList.FirstOrDefault();

            if (webspace == null)
            {
                try
                {
                    string defaultLocation = WebsitesClient.GetDefaultLocation();
                    webspace = WebSpaceForLocation(defaultLocation);
                }
                catch
                {
                    throw new Exception(Resources.CreateWebsiteFailed);
                }
            }
            return(webspace);
        }
Exemplo n.º 23
0
        public override void ExecuteCmdlet()
        {
            // Get current config
            website = WebsitesClient.GetWebsite(Name, Slot);
            siteConfig = WebsitesClient.GetWebsiteConfiguration(Name, Slot);

            // Update the configuration
            if (siteConfig.RemoteDebuggingEnabled.Value)
            {
                siteConfig.RemoteDebuggingEnabled = false;
                WebsitesClient.UpdateWebsiteConfiguration(Name, siteConfig, Slot);
            }

            if (PassThru.IsPresent)
            {
                WriteObject(true);
            }
        }
Exemplo n.º 24
0
        private void GetNoName()
        {
            Do(() =>
            {
                List <Site> websites;
                if (string.IsNullOrEmpty(Slot))
                {
                    websites = WebsitesClient.ListWebsites();
                }
                else
                {
                    websites = WebsitesClient.ListWebsites(Slot);
                }

                Cache.SaveSites(CurrentSubscription.SubscriptionId, new Sites(websites));
                WriteWebsites(websites);
            });
        }
Exemplo n.º 25
0
        public override void ExecuteCmdlet()
        {
            WebJobFilterOptions options = new WebJobFilterOptions()
            {
                Name = Name, Slot = Slot, JobName = JobName, JobType = JobType
            };
            List <PSWebJob> jobs = new List <PSWebJob>();

            try
            {
                jobs = WebsitesClient.FilterWebJobs(options);
            }
            catch
            {
                // Ignore exceptions, just show empty list.
            }

            WriteObject(jobs, true);
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            bool inheritConfig = false;

            switch (ParameterSetName)
            {
            case InputValuesParameterSet:
                inheritConfig = ScmSiteUseMainSiteRestrictionConfig;
                break;

            case InputObjectParameterSet:
                inheritConfig     = InputObject.ScmSiteUseMainSiteRestrictionConfig;
                ResourceGroupName = InputObject.ResourceGroupName;
                Name     = InputObject.WebAppName;
                SlotName = InputObject.SlotName;
                break;
            }
            string updateActionText = inheritConfig ? "" : "not ";

            if (!string.IsNullOrWhiteSpace(ResourceGroupName) && !string.IsNullOrWhiteSpace(Name))
            {
                if (ShouldProcess(Name, $"Update Scm Site of WebApp '{Name}' to {updateActionText}use Main Site Access Restriction Config"))
                {
                    var        webApp     = new PSSite(WebsitesClient.GetWebApp(ResourceGroupName, Name, SlotName));
                    SiteConfig siteConfig = webApp.SiteConfig;

                    if (siteConfig.ScmIpSecurityRestrictionsUseMain != inheritConfig)
                    {
                        siteConfig.ScmIpSecurityRestrictionsUseMain = inheritConfig;

                        // Update web app configuration
                        WebsitesClient.UpdateWebAppConfiguration(ResourceGroupName, webApp.Location, Name, SlotName, siteConfig);
                    }

                    if (PassThru)
                    {
                        var accessRestrictionConfig = new PSAccessRestrictionConfig(ResourceGroupName, Name, webApp.SiteConfig, SlotName);
                        WriteObject(accessRestrictionConfig);
                    }
                }
            }
        }
Exemplo n.º 27
0
 internal void InitializeRemoteRepo(string webspace, string websiteName)
 {
     try
     {
         // Create website repository
         WebsitesClient.CreateWebsiteRepository(webspace, websiteName);
     }
     catch (Exception ex)
     {
         if (SiteRepositoryAlreadyExists(ex))
         {
             WriteWarning(ex.Message);
         }
         else
         {
             WriteExceptionError(ex);
         }
     }
 }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            RestoreRequest request = new RestoreRequest()
            {
                Location                   = "",
                StorageAccountUrl          = this.StorageAccountUrl,
                BlobName                   = this.BlobName,
                SiteName                   = CmdletHelpers.GenerateSiteWithSlotName(Name, Slot),
                Overwrite                  = this.Overwrite.IsPresent,
                IgnoreConflictingHostNames = this.IgnoreConflictingHostNames.IsPresent,
                Databases                  = this.Databases,
                OperationType              = BackupRestoreOperationType.Default
            };

            // The id here does not actually matter. It is an artifact of the CSM API requirements. It should be possible
            // to restore from a backup that is no longer stored in our Backups table.
            WebsitesClient.RestoreSite(ResourceGroupName, Name, Slot, "1", request);
        }
Exemplo n.º 29
0
        private void GetByResourceGroup()
        {
            var list = new List <Site>();

            try
            {
                var result = WebsitesClient.ListWebApps(ResourceGroupName, null);
                if (result != null)
                {
                    list.AddRange(result);
                }
            }
            catch (Exception e)
            {
                WriteExceptionError(e);
            }

            WriteObject(list, true);
        }
Exemplo n.º 30
0
        public override void ExecuteCmdlet()
        {
            var aseName          = (ParameterSetName == InputValuesParameterSet) ? Name : InputObject.Name;
            var aseResourceGroup = (ParameterSetName == InputValuesParameterSet) ? ResourceGroupName : InputObject.ResourceGroupName;

            ConfirmAction(
                Force.IsPresent,
                string.Format("Are you sure you want to remove the app service environment '{0}'?", aseName),
                "Removing app service environment",
                aseName,
                () =>
            {
                WebsitesClient.RemoveAppServiceEnvironment(aseResourceGroup, aseName);
                if (PassThru)
                {
                    WriteObject(true);
                }
            });
        }