Skip to content

Commit

Permalink
#2192 remove aws deprecated thing types after 5mns (#2200)
Browse files Browse the repository at this point in the history
* Hide certificates when getting the magic ommand

* Remove AWS Thing type that was deparecated for 5mn ago

* refacto

---------

Co-authored-by: Kevin BEAUGRAND <contact@kbeaugrand.fr>
  • Loading branch information
ssgueye2 and kbeaugrand committed Jun 23, 2023
1 parent cfddabc commit 3fb58d7
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 22 deletions.
25 changes: 25 additions & 0 deletions src/IoTHub.Portal.Infrastructure/Jobs/AWS/SyncThingTypesJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,29 @@ private async Task SyncThingTypesAsDeviceModels()
await DeleteThingTypes(thingTypes);
}


private async Task<List<DescribeThingTypeResponse>> Remove5mnDeprecatedThingTypes(List<DescribeThingTypeResponse> thingTypes)
{
var awsThingTypes = new List< DescribeThingTypeResponse>();

foreach (var thingType in thingTypes)
{
var diffInMinutes = (DateTime.Now.Subtract(thingType.ThingTypeMetadata.DeprecationDate)).TotalMinutes;
if (thingType.ThingTypeMetadata.Deprecated && diffInMinutes > 5)
{
_ = await this.amazonIoTClient.DeleteThingTypeAsync(new DeleteThingTypeRequest
{
ThingTypeName = thingType.ThingTypeName
});
}
else
{
awsThingTypes.Add(thingType);
}
}

return awsThingTypes;
}
private async Task<List<DescribeThingTypeResponse>> GetAllThingTypes()
{
var thingTypes = new List<DescribeThingTypeResponse>();
Expand Down Expand Up @@ -116,6 +139,8 @@ private async Task<List<DescribeThingTypeResponse>> GetAllThingTypes()
}
while (!string.IsNullOrEmpty(nextToken));

thingTypes = await Remove5mnDeprecatedThingTypes(thingTypes);

return thingTypes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,20 @@ public async Task Execute_SyncNewAndExistingAndDepprecatedThingTypes_DeviceModel
ThingTypeMetadata = new ThingTypeMetadata
{
Deprecated = true,
DeprecationDate = new DateTime(2023, 6, 11, 10, 30, 0)
}
};



_ = this.iaAmazon.Setup(client => client.DescribeThingTypeAsync(It.Is<DescribeThingTypeRequest>(c => c.ThingTypeName == existingThingType.ThingTypeName), It.IsAny<CancellationToken>()))
.ReturnsAsync(existingThingType);
.ReturnsAsync(existingThingType);
_ = this.iaAmazon.Setup(client => client.DescribeThingTypeAsync(It.Is<DescribeThingTypeRequest>(c => c.ThingTypeName == newThingType.ThingTypeName), It.IsAny<CancellationToken>()))
.ReturnsAsync(newThingType);
.ReturnsAsync(newThingType);
_ = this.iaAmazon.Setup(client => client.DescribeThingTypeAsync(It.Is<DescribeThingTypeRequest>(c => c.ThingTypeName == depcrecatedThingType.ThingTypeName), It.IsAny<CancellationToken>()))
.ReturnsAsync(depcrecatedThingType);
_ = this.iaAmazon.Setup(client => client.DeleteThingTypeAsync(It.Is<DeleteThingTypeRequest>(c => c.ThingTypeName == depcrecatedThingType.ThingTypeName), It.IsAny<CancellationToken>()))
.ReturnsAsync(Fixture.Create<DeleteThingTypeResponse>);

_ = this.mockExternalDeviceService.Setup(client => client.IsEdgeDeviceModel(It.IsAny<ExternalDeviceModelDto>()))
.ReturnsAsync(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,32 @@

namespace IoTHub.Portal.Tests.Unit.Infrastructure.Services.AWS_Tests
{
using Amazon.GreengrassV2;
using IoTHub.Portal.Application.Managers;
using IoTHub.Portal.Domain.Repositories;
using IoTHub.Portal.Domain;
using IoTHub.Portal.Tests.Unit.UnitTests.Bases;
using NUnit.Framework;
using IoTHub.Portal.Application.Services;
using AutoMapper;
using IoTHub.Portal.Infrastructure.Services.AWS;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using Amazon.GreengrassV2.Model;
using System.Text;
using System.Threading;
using IoTHub.Portal.Models.v10;
using AutoFixture;
using System.Threading.Tasks;
using Amazon.GreengrassV2;
using Amazon.GreengrassV2.Model;
using Amazon.IoT;
using Amazon.IoT.Model;
using AutoFixture;
using AutoMapper;
using FluentAssertions;
using IoTHub.Portal.Application.Managers;
using IoTHub.Portal.Application.Services;
using IoTHub.Portal.Domain;
using IoTHub.Portal.Domain.Entities;
using System.Collections.Generic;
using System.IO;
using System.Text;
using IoTHub.Portal.Domain.Repositories;
using IoTHub.Portal.Infrastructure.Services.AWS;
using IoTHub.Portal.Models.v10;
using IoTHub.Portal.Tests.Unit.UnitTests.Bases;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using Newtonsoft.Json.Linq;
using System.Linq;
using FluentAssertions;
using System;
using NUnit.Framework;

[TestFixture]
public class AwsConfigTests : BackendUnitTest
Expand Down

0 comments on commit 3fb58d7

Please sign in to comment.