Ejemplo n.º 1
0
        public static async Task <IList <string> > GetAksUpdates(IEnumerable <string> supportedLocations, string token, string subscriptionId, IDictionary <string, Version> storedLatestVersionPerLocation)
        {
            var messages = new List <string>();

            foreach (var supportedLocation in supportedLocations)
            {
                var     location            = supportedLocation.Replace(" ", "").ToLower();
                Version storedLatestVersion = new Version();

                if (storedLatestVersionPerLocation.ContainsKey(location))
                {
                    storedLatestVersion = storedLatestVersionPerLocation[location];
                }

                Version latestVersion = GetLatestVersion(await AzureApi.GetAksVersions(token, subscriptionId, location));

                string message = GetAksUpdateForSingleLocation(storedLatestVersion, supportedLocation, latestVersion);
                if (message != null)
                {
                    await AzureTableStorage.AddOrUpdateLatestVersion(location, latestVersion.ToString());

                    messages.Add(message);
                }
            }

            return(messages);
        }
Ejemplo n.º 2
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, TraceWriter log)
        {
            try
            {
                log.Info("C# HTTP trigger function processed a request.");

                string subscriptionId = Settings.GetSetting(Settings.SubscriptionId);
                if (string.IsNullOrWhiteSpace(subscriptionId))
                {
                    throw new Exception("No subscriptionId found");
                }

                string token = await AzureApi.GetAuthorizationToken();

                var storedLatestVersionPerLocation = await AzureTableStorage.GetStoredLatestVersions();

                var supportedlocations = GetLocationsWhichSupportAKS(await AzureApi.GetAksLocations(token, subscriptionId));

                var messages = await GetAksUpdates(supportedlocations, token, subscriptionId, storedLatestVersionPerLocation);

                string jsonToReturn = JsonConvert.SerializeObject(messages);

                return(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(jsonToReturn, Encoding.UTF8, "application/json")
                });
            }
            catch (Exception ex)
            {
                log.Error("Exception occured: " + ex.ToString());
                return(null);
            }
        }