App-FargateStack

 view release on metacpan or  search on metacpan

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

      my $level = $p->[0] eq 'Required' ? 'warn' : 'info';

      $self->get_logger->$level("\n$table");
    }
    else {
      $self->log_warn( 'builder: no %s resources', lc $p->[0] );
    }
  }

  $self->update_config;

  return;
}

# resolves the resource value from the hash of resources
# TBD: better documentation of this method
########################################################################
sub resolve_resource_value {
########################################################################
  my ( $value, $dryrun ) = @_;

  return [$value]
    if !ref $value;

  if ( reftype($value) eq 'ARRAY' ) {
    my @values;

    foreach my $v ( @{$value} ) {
      if ( ref $v && reftype($v) eq 'CODE' ) {
        push @values, $v->($dryrun);
      }
      else {
        push @values, $v;
      }
    }
    return \@values;
  }
  else {
    return [ $value->($dryrun) ];
  }
}

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

  my $config = $self->get_config;
  my @scheduled_action_names;

  foreach ( keys %{ $config->{tasks} } ) {
    next if !exists $config->{tasks}->{$_}->{autoscaling};
    next if !exists $config->{tasks}->{$_}->{autoscaling}->{scheduled};
    push @scheduled_action_names, keys %{ $config->{tasks}->{$_}->{autoscaling}->{scheduled} };
  }

  return @scheduled_action_names;
}

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

  $Data::Dumper::Sortkeys = $TRUE;

  my $config = $self->get_config;

  delete $config->{id};
  delete $config->{last_updated};

  my $md5_hex = md5_hex( Dumper( $self->get_config ) );

  $config->{id} = $md5_hex;

  $config->{last_updated} = scalar localtime;

  return $config;
}

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

  $self->log_warn( 'builder: config file %s %s be updated', $self->get_config_name, $self->get_update ? 'will' : 'will not' );

  return
    if !$self->get_update;

  my ( $fh, $filename ) = tempfile( 'fargate-stack-XXXX', SUFFIX => '.yml' );

  my $config = $self->update_config_id();

  DumpFile( $filename, $config );

  my $config_name = $self->get_config_name;

  rename $config_name, "${config_name}.bak";

  rename $filename, $config_name;

  return;
}

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

  my $config = $self->get_config;

  my $is_secure = $self->has_https_service;

  # default ALB type is private with a listener on port 80
  my $alb_config = $config->{alb} // {};
  $alb_config->{type} //= $is_secure ? 'public' : 'private';
  $alb_config->{port} //= $is_secure ? '443'    : '80';

  # if it was already defined as public w/o a port, then 443 and
  # redirect 80 -> 443
  if ( $alb_config->{type} eq 'public' && !$alb_config->{port} ) {
    $alb_config->{port} = '443';
    if ( !defined $alb_config->{redirect_80} ) {
      $alb_config->{redirect_80} = $TRUE;
    }
  }

  croak "invalid alb type, must be 'public' or 'private'\n"
    if $alb_config->{type} !~ /^public|private$/xsm;

  $config->{alb} = $alb_config;

  return;
}

########################################################################
sub remove_listener_rules {
########################################################################
  my ( $self, $alb_arn ) = @_;

  my ( $config, $dryrun ) = $self->common_args(qw(config dryrun));



( run in 1.193 second using v1.01-cache-2.11-cpan-39bf76dae61 )