Class: Awsrm::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/awsrm/resource.rb

Constant Summary collapse

FILTER_MAP =
{
  name: 'tag:Name'
}.freeze
CLIENTS =
{
  ec2_client: Aws::EC2::Client,
  ecr_client: Aws::ECR::Client,
  ecs_client: Aws::ECS::Client,
  efs_client: Aws::EFS::Client,
  rds_client: Aws::RDS::Client,
  route53_client: Aws::Route53::Client,
  s3_client: Aws::S3::Client,
  autoscaling_client: Aws::AutoScaling::Client,
  elb_client: Aws::ElasticLoadBalancing::Client,
  elbv2_client: Aws::ElasticLoadBalancingV2::Client,
  lambda_client: Aws::Lambda::Client,
  iam_client: Aws::IAM::Client,
  kms_client: Aws::KMS::Client,
  elasticache_client: Aws::ElastiCache::Client,
  cloudwatch_client: Aws::CloudWatch::Client,
  cloudwatch_event_client: Aws::CloudWatchEvents::Client,
  ses_client: Aws::SES::Client,
  directconnect_client: Aws::DirectConnect::Client,
  cloudfront_client: Aws::CloudFront::Client,
  elastictranscoder_client: Aws::ElasticTranscoder::Client,
  elasticsearch_client: Aws::ElasticsearchService::Client,
  cloudtrail_client: Aws::CloudTrail::Client,
  waf_client: Aws::WAF::Client,
  sts_client: Aws::STS::Client,
  acm_client: Aws::ACM::Client,
  cloudwatch_logs_client: Aws::CloudWatchLogs::Client,
  dynamodb_client: Aws::DynamoDB::Client
}.freeze
CLIENT_OPTIONS =
{
  http_proxy: ENV['http_proxy'] || ENV['https_proxy'] || nil
}.freeze

Class Method Summary collapse

Class Method Details

.all(_params) ⇒ Object



49
50
51
# File 'lib/awsrm/resource.rb', line 49

def all(_params)
  raise 'not implemented'
end

.check_one(resources, params) ⇒ Object



61
62
63
64
65
# File 'lib/awsrm/resource.rb', line 61

def check_one(resources, params)
  raise Awsrm::NoResourceError, "No resource #{name} by #{params}" if resources.count == 0
  raise Awsrm::DuplicatedResourceError, "Duplicated resource #{name} by #{params}" if resources.count > 1
  true
end

.filters(params) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/awsrm/resource.rb', line 53

def filters(params)
  params.map do |key, value|
    raise UndefinedFilterParamError, key unless self::FILTER_MAP.key?(key)
    next self::FILTER_MAP[key].call(value) if self::FILTER_MAP[key].is_a?(Proc)
    { name: self::FILTER_MAP[key], values: [value] }
  end
end

.one(params) ⇒ Object



44
45
46
47
# File 'lib/awsrm/resource.rb', line 44

def one(params)
  res = all(params)
  res.first if check_one(res, params)
end