// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
using System.Collections.Generic;
using System.Threading.Tasks;
using AWS.Deploy.Common.Data;
using AWS.Deploy.Orchestration.Data;
namespace AWS.Deploy.Orchestration.DisplayedResources
{
///
/// Interface for displayed resources such as
///
public interface IDisplayedResourceCommand
{
Task> Execute(string resourceId);
}
public interface IDisplayedResourceCommandFactory
{
IDisplayedResourceCommand? GetResource(string resourceType);
}
///
/// Factory class responsible to build and get the displayed resources.
///
public class DisplayedResourceCommandFactory : IDisplayedResourceCommandFactory
{
private const string RESOURCE_TYPE_APPRUNNER_SERVICE = "AWS::AppRunner::Service";
private const string RESOURCE_TYPE_ELASTICBEANSTALK_ENVIRONMENT = "AWS::ElasticBeanstalk::Environment";
private const string RESOURCE_TYPE_ELASTICLOADBALANCINGV2_LOADBALANCER = "AWS::ElasticLoadBalancingV2::LoadBalancer";
private const string RESOURCE_TYPE_S3_BUCKET = "AWS::S3::Bucket";
private const string RESOURCE_TYPE_CLOUDFRONT_DISTRIBUTION = "AWS::CloudFront::Distribution";
private const string RESOURCE_TYPE_EVENTS_RULE = "AWS::Events::Rule";
private readonly Dictionary _resources;
public DisplayedResourceCommandFactory(IAWSResourceQueryer awsResourceQueryer)
{
_resources = new Dictionary
{
{ RESOURCE_TYPE_APPRUNNER_SERVICE, new AppRunnerServiceResource(awsResourceQueryer) },
{ RESOURCE_TYPE_ELASTICBEANSTALK_ENVIRONMENT, new ElasticBeanstalkEnvironmentResource(awsResourceQueryer) },
{ RESOURCE_TYPE_ELASTICLOADBALANCINGV2_LOADBALANCER, new ElasticLoadBalancerResource(awsResourceQueryer) },
{ RESOURCE_TYPE_S3_BUCKET, new S3BucketResource(awsResourceQueryer) },
{ RESOURCE_TYPE_CLOUDFRONT_DISTRIBUTION, new CloudFrontDistributionResource(awsResourceQueryer) },
{ RESOURCE_TYPE_EVENTS_RULE, new CloudWatchEventResource(awsResourceQueryer) }
};
}
public IDisplayedResourceCommand? GetResource(string resourceType)
{
if (!_resources.ContainsKey(resourceType))
{
return null;
}
return _resources[resourceType];
}
}
}