App-FargateStack

 view release on metacpan or  search on metacpan

lib/App/FargateStack.pm  view on Meta::CPAN

use Text::ASCIITable::EasyTable;
use Term::ANSIColor;
use YAML qw(LoadFile);

use Role::Tiny::With;

# command methods
with 'App::FargateStack::Init';
with 'App::FargateStack::Logs';
with 'App::FargateStack::Route53';
with 'App::FargateStack::CloudTrail';
with 'App::FargateStack::CreateStack';
with 'App::FargateStack::Autoscaling';

with 'App::BenchmarkRole';

# builder methods
with 'App::FargateStack::Builder';
with 'App::FargateStack::Builder::Autoscaling';
with 'App::FargateStack::Builder::IAM';
with 'App::FargateStack::Builder::Certificate';
with 'App::FargateStack::Builder::Events';
with 'App::FargateStack::Builder::EFS';
with 'App::FargateStack::Builder::HTTPService';
with 'App::FargateStack::Builder::Cluster';
with 'App::FargateStack::Builder::LogGroup';
with 'App::FargateStack::Builder::SecurityGroup';
with 'App::FargateStack::Builder::Secrets';
with 'App::FargateStack::Builder::Service';
with 'App::FargateStack::Builder::S3Bucket';
with 'App::FargateStack::Builder::SQSQueue';
with 'App::FargateStack::Builder::TaskDefinition';
with 'App::FargateStack::Builder::Utils';
with 'App::FargateStack::Builder::WafV2';

our $VERSION = '1.0.50';

use parent qw(CLI::Simple);

__PACKAGE__->use_log4perl( config => $LOG4PERL_CONF );

caller or __PACKAGE__->main;

########################################################################
sub init_logger {
########################################################################
  my ($self) = @_;

  my $log4perl_conf = $self->get_log4perl_conf;

  if ( !$self->get_color ) {
    $log4perl_conf =~ s/ColoredLevels//xsm;

    if ( $self->get_log_level && $self->get_log_level =~ /debug|trace/xsm ) {
      $log4perl_conf =~ s/ConversionPattern(.*?)$/ConversionPattern = [%d] (%M:%L) %m%n/xsm;
    }
  }

  $self->set_log4perl_conf($log4perl_conf);

  return $self->SUPER::init_logger;
}

########################################################################
sub show_config {
########################################################################
  my ($self) = @_;

  my $config = $self->get_config;

  my $subnets = $self->get_subnets;

  my $dryrun = $self->command eq 'plan' ? '(dryrun)' : $self->get_dryrun;

  $self->section_break;

  $self->log_info( '           account: [%s]', $self->get_account );
  $self->log_info( '           profile: [%s]', $self->get_profile );
  $self->log_info( '    profile source: [%s]', $self->get_profile_source );
  $self->log_info( '            region: [%s]', $self->get_region );
  $self->section_break;

  $self->log_info( '   route53 profile: [%s]', $config->{route53}->{profile} // q{-} );
  $self->log_info( '   route53 zone_id: [%s]', $config->{route53}->{zone_id} // q{-} );
  $self->section_break;

  $self->log_info( '          app name: [%s]', $config->{app}->{name} );
  $self->log_info( '       app version: [%s]', $config->{app}->{version} // q{-} );
  $self->log_info( '     https service: [%s]', $self->get_http           // q{-} );
  $self->log_info( '  scheduled events: [%s]', $self->has_events ? 'yes' : 'no' );
  $self->section_break;

  $self->log_info( '    subnets in VPC: [%s]', $config->{vpc_id} );
  $self->log_info( '            public: [%s]', join q{,}, @{ $subnets->{public}  || [] } );
  $self->log_info( '           private: [%s]', join q{,}, @{ $subnets->{private} || [] } );
  $self->section_break;

  $self->log_info( '            config: [%s]', $self->get_config_name );
  $self->log_info( '         log level: [%s]', $self->get_log_level // 'info' );
  $self->log_info( '             cache: [%s]', $self->get_cache ? 'enabled' : 'disabled' );
  $self->log_warn( '     update config: [%s]', $self->get_update ? 'yes' : 'no' );
  $self->log_warn( '            dryrun: [%s]', $dryrun           ? 'yes' : 'no' );

  return;
}

########################################################################
sub check_service_name {
########################################################################
  my ( $self, $service_name, $return_on_missing ) = @_;

  my $tasks = $self->common_args('tasks');

  return $service_name
    if $service_name && $tasks->{$service_name};

  # if only 1 service in config, then let's stat that
  my ( $default_service, $error ) = grep { $tasks->{$_}->{type} =~ /daemon|http/xsm } keys %{$tasks};

  return
    if $default_service || ( !$default_service && $return_on_missing );



( run in 0.834 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )