Skip to content

Commit

Permalink
Fix remove policies from certificate when deleting edge device
Browse files Browse the repository at this point in the history
  • Loading branch information
kbeaugrand committed Jun 23, 2023
1 parent 3b3c921 commit 70b90cb
Showing 1 changed file with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -450,17 +450,15 @@ public async Task RemoveDeviceCredentials(IoTEdgeDevice device)

private async Task RemoveGreengrassCertificateFromPrincipal(IoTEdgeDevice device, string principalId)
{
_ = await this.amazonIoTClient.DetachPolicyAsync(new DetachPolicyRequest
foreach (var item in this.configHandler.AWSGreengrassRequiredRoles)
{
Target = principalId,
PolicyName = "GreengrassV2IoTThingPolicy"
});
_ = await this.amazonIoTClient.AttachPolicyAsync(new AttachPolicyRequest
{
PolicyName = item,
Target = principalId
});
}

_ = await this.amazonIoTClient.DetachPolicyAsync(new DetachPolicyRequest
{
Target = principalId,
PolicyName = "GreengrassCoreTokenExchangeRoleAliasPolicy"
});
_ = await this.amazonIoTClient.DetachThingPrincipalAsync(device.DeviceName, principalId);

_ = await this.amazonSecretsManager.DeleteSecretAsync(new DeleteSecretRequest
Expand Down

0 comments on commit 70b90cb

Please sign in to comment.