0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

AWSのDescribeAvailablePatchesを使ってみた

Last updated at Posted at 2021-01-24

【執筆中】コードとかきれいにしてないけど現時点のメモ書きを載せておく
とりあえずセキュリティのパッチを取得してみる

        public static async Task<string> SayHelloAsync([ActivityTrigger] string name, ILogger log)
        {
            //log.LogInformation($"Saying hello to {name}.");
            var ssmClient = AwsSsmService.GetClient();


            // Windows Server 2019
            var request = new DescribeAvailablePatchesRequest();
            var productFilter = new PatchOrchestratorFilter();
            productFilter.Key = "PRODUCT";
            productFilter.Values.Add("WindowsServer2019");
            request.Filters.Add(productFilter);

            var classificationFilter = new PatchOrchestratorFilter();
            classificationFilter.Key = "CLASSIFICATION";
            classificationFilter.Values.Add("SecurityUpdates");

            request.Filters.Add(classificationFilter);

            try
            {
                var response = await ssmClient.DescribeAvailablePatchesAsync(request);
                string nextToken = null;
                var patches = new List<Patch>();
                int productCount = 0;
                int repositoryCount = 0;
                int savedProductCount = 0;
                int savedRepositoryCount = 0;

                if (response.HttpStatusCode == HttpStatusCode.OK)
                {
                    do
                    {
                        Thread.Sleep(500);

                        nextToken = response.NextToken;
                        patches.AddRange(response.Patches);

                        var platformList = patches.Select(r => r.Product).Distinct();
                        productCount = platformList.Count();

                        var repositoryList = patches.Select(r => r.Repository).Distinct();
                        repositoryCount = repositoryList.Count();

                    } while (nextToken != null);
                }
                else
                {
                    // Error
                    var code = response.HttpStatusCode;
                }

                // 2021/01のパッチだけ取得
                var date = new DateTime(2021, 1, 1, 0, 0, 0, 0);

                var currentPatches = patches.Where(r => r.ReleaseDate > date).ToList();

                var temp = string.Empty;

                return $"Hello {name}!";
            }
            catch (Exception ex)
            {   
                var message = ex.Message;
                throw;
            }

        }
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?