Exemplo n.º 1
0
        public static async Task <ConnectionStringDictionary> GetConnectionStringsAsync(
            WebSiteManagementClient webAppClient, TargetSite targetSite)
        {
            var conStringDict = await webAppClient.WebApps.ListConnectionStringsAsync(targetSite);

            return(conStringDict);
        }
        public static async Task <PublishingProfile> GetPublishingProfile(TargetSite targetSite,
                                                                          ServicePrincipalAccount account)
        {
            string mgmtEndpoint = account.ResourceManagementEndpointBaseUri;
            var    token        = new TokenCredentials(await Auth.GetAuthTokenAsync(account));

            var azureCredentials = new AzureCredentials(
                token,
                token,
                account.TenantId,
                new AzureKnownEnvironment(account.AzureEnvironment).AsAzureSDKEnvironment())
                                   .WithDefaultSubscription(account.SubscriptionNumber);

            var restClient = RestClient
                             .Configure()
                             .WithBaseUri(mgmtEndpoint)
                             .WithEnvironment(new AzureKnownEnvironment(account.AzureEnvironment).AsAzureSDKEnvironment())
                             .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
                             .WithCredentials(azureCredentials)
                             .Build();

            var webAppClient = new WebSiteManagementClient(restClient)
            {
                SubscriptionId = account.SubscriptionNumber
            };

            var options = new CsmPublishingProfileOptions {
                Format = PublishingProfileFormat.WebDeploy
            };

            await webAppClient.WebApps.GetWithHttpMessagesAsync(targetSite.ResourceGroupName, targetSite.Site);

            using var publishProfileStream = targetSite.HasSlot
                ? await webAppClient.WebApps.ListPublishingProfileXmlWithSecretsSlotAsync(targetSite.ResourceGroupName,
                                                                                          targetSite.Site, options, targetSite.Slot)
                : await webAppClient.WebApps.ListPublishingProfileXmlWithSecretsAsync(targetSite.ResourceGroupName,
                                                                                      targetSite.Site,
                                                                                      options);

            using var streamReader = new StreamReader(publishProfileStream);
            var document = XDocument.Parse(await streamReader.ReadToEndAsync());

            var profile = (from el in document.Descendants("publishProfile")
                           where string.Compare(el.Attribute("publishMethod")?.Value, "MSDeploy",
                                                StringComparison.OrdinalIgnoreCase) == 0
                           select new PublishingProfile
            {
                PublishUrl = $"https://{el.Attribute("publishUrl")?.Value}",
                Username = el.Attribute("userName")?.Value,
                Password = el.Attribute("userPWD")?.Value,
                Site = el.Attribute("msdeploySite")?.Value
            }).FirstOrDefault();

            if (profile == null)
            {
                throw new Exception("Failed to retrieve publishing profile.");
            }

            return(profile);
        }
Exemplo n.º 3
0
        protected override string InternalHandler(HttpContext context, TargetSite target, string targetRootDir, string requestedPath, ViewModel vm)
        {
            string sitemapPath;
            if (target.HasCustomLayout)
            {
                sitemapPath = Path.Combine(targetRootDir, Constants.LayoutFolderName, Constants.SitemapFileName);
            }
            else
            {
                sitemapPath = Path.Combine(Session.GetInstance().WebRoot, Constants.LayoutFolderName, Constants.SitemapFileName);
            }

            if (!File.Exists(sitemapPath))
            {
                throw new InvalidOperationException(String.Format("Sitemap template file for '{0}' is missing. It should be at '{1}'", target.Name, sitemapPath));
            }

            vm.Sitemap = this.BuildSitemap(targetRootDir);

            SparkRenderer renderer = new SparkRenderer();
            string sitemapOutput = renderer.Render(sitemapPath, vm);

            vm.MarkdownHtml = sitemapOutput;
            string output = renderer.Render(target.TemplateFile, vm);

            return output;
        }
Exemplo n.º 4
0
 private void Initialize(IApplicationConfiguration config)
 {
     if (config != null)
     {
         _config     = config;
         _targetSite = _config.TargetWebsite;
         var result = PerformaAPIRequest(new RequestBase(_config));
     }
 }
Exemplo n.º 5
0
        public static async Task <string> GetBasicAuthCreds(ServicePrincipalAccount principalAccount,
                                                            TargetSite targetSite)
        {
            var publishingProfile = await PublishingProfile.GetPublishingProfile(targetSite, principalAccount);

            string credential =
                Convert.ToBase64String(
                    Encoding.ASCII.GetBytes($"{publishingProfile.Username}:{publishingProfile.Password}"));

            return(credential);
        }
Exemplo n.º 6
0
        protected override string InternalHandler(HttpContext context, TargetSite target, string targetRootDir, string requestedPath, ViewModel vm)
        {
            string mdFilePath = String.Format("{0}.md", Path.Combine(targetRootDir, requestedPath));

            vm.MarkdownHtml = MarkdownHelper.ProcessMarkdown(MarkdownHelper.GetMarkdown(mdFilePath));

            SparkRenderer renderer = new SparkRenderer();
            string output = renderer.Render(target.TemplateFile, vm);

            return output;
        }
        public static async Task <SiteConfigResource> GetConfigurationAsync(this IWebAppsOperations operations,
                                                                            TargetSite targetSite, CancellationToken cancellationToken = default)
        {
            if (targetSite.HasSlot)
            {
                return((await operations.GetConfigurationSlotWithHttpMessagesAsync(targetSite.ResourceGroupName,
                                                                                   targetSite.Site,
                                                                                   targetSite.Slot, cancellationToken: cancellationToken)).Body);
            }

            return((await operations.GetConfigurationWithHttpMessagesAsync(targetSite.ResourceGroupName,
                                                                           targetSite.Site, cancellationToken: cancellationToken)).Body);
        }
Exemplo n.º 8
0
 public HubLogConnection(TargetSite site)
 {
     connection = new HubConnectionBuilder()
                  .WithUrl(site.Url.TrimEnd('/', '\\') + "/MelvilleSpecialLoggingHubWellKnownUrl",
                           o => o.AccessTokenProvider = GetAccessToken)
                  .WithAutomaticReconnect()
                  .Build();
     disposeToStopReadingEvents = connection.On("SendEvent", (Action <string>)HandleLogEvent);
     if (site.Secret.Length > 0)
     {
         token = CapWebTokenFactory.CreateCapWebClient(site.Name, site.Secret);
     }
     connection.StartAsync();
 }
Exemplo n.º 9
0
        async Task AssertDeploySuccessAsync(TargetSite targetSite)
        {
            var imageName    = newVariables.Get(SpecialVariables.Action.Package.PackageId);
            var registryUrl  = newVariables.Get(SpecialVariables.Action.Package.Registry);
            var imageVersion = newVariables.Get(SpecialVariables.Action.Package.PackageVersion) ?? "latest";

            var config = await webMgmtClient.WebApps.GetConfigurationAsync(targetSite);

            Assert.AreEqual($@"DOCKER|{imageName}:{imageVersion}", config.LinuxFxVersion);

            var appSettings = await webMgmtClient.WebApps.ListApplicationSettingsAsync(targetSite);

            Assert.AreEqual("https://" + registryUrl, appSettings.Properties["DOCKER_REGISTRY_SERVER_URL"]);
        }
        public static int GetSiteId(this TargetSite site)
        {
            switch (site)
            {
            case TargetSite.Cryptopia_Production:
                return(EnvironmentConstants.ProductionSiteId);

            case TargetSite.Cryptopia_Development:
                return(EnvironmentConstants.DevelopmentSiteId);

            default:
                return(-1);
            }
        }
        private async Task PublishAppSettings(WebSiteManagementClient webAppClient, TargetSite targetSite,
                                              AppSetting[] appSettings, string authToken)
        {
            var settingsDict = new StringDictionary
            {
                Properties = new Dictionary <string, string>()
            };

            var existingSlotSettings = new List <string>();

            // for each app setting found on the web app (existing app setting) update it value and add if is a slot setting, add
            foreach (var(name, value, SlotSetting) in (await AppSettingsManagement.GetAppSettingsAsync(webAppClient,
                                                                                                       authToken, targetSite)).ToList())
            {
                settingsDict.Properties[name] = value;

                if (SlotSetting)
                {
                    existingSlotSettings.Add(name);
                }
            }

            // for each app setting defined by the user
            foreach (var setting in appSettings)
            {
                // add/update the settings value
                settingsDict.Properties[setting.Name] = setting.Value;

                // if the user indicates a settings should no longer be a slot setting
                if (existingSlotSettings.Contains(setting.Name) && !setting.SlotSetting)
                {
                    Log.Verbose($"Removing {setting.Name} from the list of slot settings");
                    existingSlotSettings.Remove(setting.Name);
                }
            }

            await AppSettingsManagement.PutAppSettingsAsync(webAppClient, settingsDict, targetSite);

            var slotSettings = appSettings
                               .Where(setting => setting.SlotSetting)
                               .Select(setting => setting.Name).ToArray();

            if (!slotSettings.Any())
            {
                return;
            }

            await AppSettingsManagement.PutSlotSettingsListAsync(webAppClient, targetSite,
                                                                 slotSettings.Union(existingSlotSettings), authToken);
        }
        public static async Task RestartAsync(this IWebAppsOperations operations, TargetSite targetSite,
                                              bool?softRestart = null, bool?synchronous = null, CancellationToken cancellationToken = default)
        {
            if (targetSite.HasSlot)
            {
                await operations.RestartSlotWithHttpMessagesAsync(targetSite.ResourceGroupName, targetSite.Site,
                                                                  targetSite.Slot, softRestart, synchronous, cancellationToken : cancellationToken);
            }

            else
            {
                await operations.RestartWithHttpMessagesAsync(targetSite.ResourceGroupName, targetSite.Site,
                                                              softRestart, synchronous, cancellationToken : cancellationToken);
            }
        }
Exemplo n.º 13
0
 public void CopyFrom(Skill skill)
 {
     id                = skill.id;
     displayName       = skill.displayName;
     cooldown          = skill.cooldown;
     manaCost          = skill.manaCost;
     isPassive         = skill.isPassive;
     icon              = skill.icon;
     description       = skill.description;
     targetType        = skill.targetType;
     targetCount       = skill.targetCount;
     targetSite        = skill.targetSite;
     possiblePositions = skill.possiblePositions;
     possibleTargets   = skill.possibleTargets;
     SkillEffects      = skill.SkillEffects;
     RemainingCooldown = skill.RemainingCooldown;
 }
Exemplo n.º 14
0
        private async Task <IDeploymentSlot> FindOrCreateSlot(IWebApp client, TargetSite site)
        {
            Log.Verbose($"Checking if slot {site.Slot} exists");

            var slot = await client.DeploymentSlots.GetByNameAsync(site.Slot);

            if (slot != null)
            {
                Log.Verbose($"Found existing slot {site.Slot}");
                return(slot);
            }

            Log.Verbose($"Slot {site.Slot} not found");
            Log.Info($"Creating slot {site.Slot}");
            return(await client.DeploymentSlots
                   .Define(site.Slot)
                   .WithConfigurationFromParent()
                   .CreateAsync());
        }
        public static async Task <StringDictionary> UpdateApplicationSettingsAsync(this IWebAppsOperations operations,
                                                                                   TargetSite targetSite, StringDictionary appSettings, CancellationToken cancellationToken = default)
        {
            if (targetSite.HasSlot)
            {
                using var operationResponse = await operations.UpdateApplicationSettingsSlotWithHttpMessagesAsync(
                          targetSite.ResourceGroupName, targetSite.Site, appSettings, targetSite.Slot,
                          cancellationToken : cancellationToken);

                return(operationResponse.Body);
            }
            else
            {
                using var operationResponse = await operations
                                              .UpdateApplicationSettingsWithHttpMessagesAsync(targetSite.ResourceGroupName, targetSite.Site,
                                                                                              appSettings,
                                                                                              cancellationToken : cancellationToken).ConfigureAwait(false);

                return(operationResponse.Body);
            }
        }
 public static async Task UpdateConnectionStringsAsync(this IWebAppsOperations operations, TargetSite targetSite,
                                                       ConnectionStringDictionary connectionStringDictionary, CancellationToken cancellationToken = default)
 {
     if (targetSite.HasSlot)
     {
         await operations.UpdateConnectionStringsSlotWithHttpMessagesAsync(targetSite.ResourceGroupName,
                                                                           targetSite.Site, connectionStringDictionary, targetSite.Slot, cancellationToken : cancellationToken);
     }
     else
     {
         await operations.UpdateConnectionStringsWithHttpMessagesAsync(targetSite.ResourceGroupName,
                                                                       targetSite.Site, connectionStringDictionary, cancellationToken : cancellationToken);
     }
 }
        public override string ToString()
        {
            string res = Source + "MutualExclusionException : " + meeMessage + " at " + TargetSite.ToString();

            return(res);
        }
 protected internal CbApi(string key, int timeout, TargetSite site)
 {
     _Settings.TargetSite = site;
     _Settings.DevKey     = key;
     _Settings.TimeoutMS  = timeout;
 }
Exemplo n.º 19
0
 public static async Task PutAppSettingsAsync(WebSiteManagementClient webAppClient, StringDictionary appSettings,
                                              TargetSite targetSite)
 {
     await webAppClient.WebApps.UpdateApplicationSettingsAsync(targetSite, appSettings);
 }
Exemplo n.º 20
0
        public static async Task PutSlotSettingsListAsync(WebSiteManagementClient webAppClient, TargetSite targetSite,
                                                          IEnumerable <string> slotConfigNames, string authToken)
        {
            var client = webAppClient.HttpClient;

            client.DefaultRequestHeaders.Clear();
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authToken);
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            var targetUrl =
                $"https://management.azure.com/subscriptions/{webAppClient.SubscriptionId}/resourceGroups/{targetSite.ResourceGroupName}/providers/Microsoft.Web/sites/{targetSite.Site}/config/slotconfignames?api-version=2018-11-01";

            var slotSettingsJson = new appSettingNamesRoot
            {
                properties = new properties {
                    appSettingNames = slotConfigNames
                }, name = targetSite.Site
            };
            var postBody = JsonConvert.SerializeObject(slotSettingsJson);

            //var body = new StringContent(postBody);
            var body     = new StringContent(postBody, Encoding.UTF8, "application/json");
            var response = await client.PutAsync(targetUrl, body);

            if (!response.IsSuccessStatusCode)
            {
                throw new HttpRequestException(response.ReasonPhrase);
            }
        }
Exemplo n.º 21
0
        public static async Task <IEnumerable <string> > GetSlotSettingsListAsync(WebSiteManagementClient webAppClient,
                                                                                  string authToken, TargetSite targetSite)
        {
            var client = webAppClient.HttpClient;

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authToken);
            var targetUrl =
                $"{client.BaseAddress}/subscriptions/{webAppClient.SubscriptionId}/resourceGroups/{targetSite.ResourceGroupName}/providers/Microsoft.Web/sites/{targetSite.Site}/config/slotconfignames?api-version=2018-11-01";

            var results = await client.GetStringAsync(targetUrl);

            var output = JsonConvert.DeserializeObject <appSettingNamesRoot>(results).properties.appSettingNames ??
                         new List <string>();

            return(output);
        }
Exemplo n.º 22
0
        public static async Task <IEnumerable <AppSetting> > GetAppSettingsAsync(WebSiteManagementClient webAppClient,
                                                                                 string authToken, TargetSite targetSite)
        {
            var webAppSettings = await webAppClient.WebApps.ListApplicationSettingsAsync(targetSite);

            var slotSettings = (await GetSlotSettingsListAsync(webAppClient, authToken, targetSite)).ToArray();

            return(webAppSettings.Properties.Select(
                       setting =>
                       new AppSetting
            {
                Name = setting.Key,
                Value = setting.Value,
                SlotSetting = slotSettings.Any(x => x == setting.Key)
            }).ToList());
        }
        private async Task PublishConnectionStrings(WebSiteManagementClient webAppClient, TargetSite targetSite,
                                                    ConnectionStringSetting[] newConStrings)
        {
            var conStrings = await AppSettingsManagement.GetConnectionStringsAsync(webAppClient, targetSite);

            foreach (var connectionStringSetting in newConStrings)
            {
                conStrings.Properties[connectionStringSetting.Name] =
                    new ConnStringValueTypePair(connectionStringSetting.Value, connectionStringSetting.Type);
            }

            await webAppClient.WebApps.UpdateConnectionStringsAsync(targetSite, conStrings);
        }
Exemplo n.º 24
0
 protected abstract string InternalHandler(HttpContext context, TargetSite target, string targetRootDir, string requestedPath, ViewModel vm);
 public static async Task UpdateConfigurationAsync(this IWebAppsOperations operations, TargetSite targetSite,
                                                   SiteConfigResource config, CancellationToken cancellationToken = default)
 {
     if (targetSite.HasSlot)
     {
         await operations.UpdateConfigurationSlotWithHttpMessagesAsync(targetSite.ResourceGroupName,
                                                                       targetSite.Site, config, targetSite.Slot, cancellationToken : cancellationToken);
     }
     else
     {
         await operations.UpdateConfigurationWithHttpMessagesAsync(targetSite.ResourceGroupName,
                                                                   targetSite.ScmSiteAndSlot, config, cancellationToken : cancellationToken);
     }
 }
Exemplo n.º 26
0
 public static ICBApi GetInstance(string developerKey, int timeoutMS, TargetSite site)
 {
     return(new CbApi(developerKey, timeoutMS, site));
 }
        public static async Task <ConnectionStringDictionary> ListConnectionStringsAsync(this IWebAppsOperations operations, TargetSite targetSite,
                                                                                         CancellationToken cancellationToken = default)
        {
            ConnectionStringDictionary body;

            if (targetSite.HasSlot)
            {
                var response = await operations.ListConnectionStringsSlotWithHttpMessagesAsync(targetSite.ResourceGroupName,
                                                                                               targetSite.Site, targetSite.Slot, cancellationToken : cancellationToken).ConfigureAwait(false);

                body = response.Body;
            }
            else
            {
                var response = await operations.ListConnectionStringsWithHttpMessagesAsync(targetSite.ResourceGroupName,
                                                                                           targetSite.Site, cancellationToken : cancellationToken).ConfigureAwait(false);

                body = response.Body;
            }

            return(body);
        }
Exemplo n.º 28
0
        }                                  //dont like this, otherwise immutable object made mutable.
        //infact its responsible for a bug.
        //decorator?

        public object InvokedOn(object target)
        {
            return(TargetSite.Invoke(target, Arguments.ToArray()));
        }