App-Regather

 view release on metacpan or  search on metacpan

lib/App/Regather/Plugin/configfile.pm  view on Meta::CPAN

	if ( $i eq 's' && ! $self->obj->exists( $self->cf->get('service', $self->service, 'map', $i, $j)) ) {
	  if ( $self->cf->get(qw(core dryrun)) ) {
	    $self->log->cc( pr => 'debug', fm => "%s: DRYRUN: %s to be deleted (no attribute: %s)",
		      ls => [ sprintf("%s:%s",__FILE__,__LINE__), $out_to, $self->cf->get('service', $self->service, 'map', $i, $j) ] );
	  } else {
	    if ( unlink $out_to ) {
	      $self->log->cc( pr => 'debug', fm => "%s: file %s deleted (no attribute: %s)",
			ls => [ sprintf("%s:%s",__FILE__,__LINE__), $out_to, $self->cf->get('service', $self->service, 'map', $i, $j) ] )
		if $self->{v} > 0;
	    } else {
	      $self->log->cc( pr => 'err', fm => "%s: %s not removed (no attribute: %s); error: %s",
			ls => [ sprintf("%s:%s",__FILE__,__LINE__), $out_to, $self->cf->get('service', $self->service, 'map', $i, $j), $! ],
			nt => 1, );
	    }
	  }

	  ### if any of `map s` attributes doesn't exist, we delete that config file
	  ### preliminaryly and skip that attribute from been processed by Template
	  next;

	} elsif ( $i eq 'm' && $self->obj->exists( $self->cf->get('service', $self->service, 'map', $i, $j)) ) {
	  $tt_vars->{$j} = $self->obj->get_value( $self->cf->get('service', $self->service, 'map', $i, $j),
					    asref => 1 );
	} else {
	  if ( $j =~ /certificateRevocationList/ ) {
	    $tt_vars->{$j} =
	      opensslize({ in => $self->obj->get_value( $self->cf->get('service', $self->service, 'map', $i, $j) ) });
	  } elsif ( $j =~ /cACertificate/ ) {
	    $tt_vars->{$j} =
	      opensslize({ cmd => 'x509',
			   in  => $self->obj->get_value( $self->cf->get('service', $self->service, 'map', $i, $j) ),
			   log => $self->log,
			   v => $self->{v} });
	  } else {
	    $tt_vars->{$j} = $self->obj->get_value( $self->cf->get('service', $self->service, 'map', $i, $j) ) // 'NA';
	  }
	}
      }
    }
  }

  $tt_vars->{prog}       = $self->{prog};
  $tt_vars->{DN}         = $self->obj->dn;
  $tt_vars->{date}       = strftime( $self->{ts_fmt}, localtime(time));
  $tt_vars->{descr}      = $self->obj->get_value('description')
    if $self->obj->exists('description');
  $tt_vars->{server}     = ( split(/\@/, $self->obj->get_value('authorizedService')) )[1]
    if $self->obj->exists('authorizedService');
  $tt_vars->{createdby}  =
    $self->obj->exists('creatorsName') ?
    ( split(/=/, ( split(/,/, $self->obj->get_value('creatorsName')) )[0]) )[1] :
    'UNKNOWN';
  $tt_vars->{modifiedby} =
    $self->obj->exists('modifiersName') ?
    ( split(/=/, ( split(/,/, $self->obj->get_value('modifiersName')) )[0]) )[1] :
    'UNKNOWN';

  if ( ! $self->force && -e $out_to &&
       ( generalizedTime_to_time($self->obj->get_value('modifyTimestamp'))
	 <
	 (stat($out_to))[9] ) ) {
    $self->log->cc( pr => 'debug',
	      fm => "%s: skip. object %s is older than target file %s, (object modifyTimestamp: %s is older than file mtime: %s",
	      ls => [ sprintf("%s:%s",__FILE__,__LINE__), $self->obj->dn, $out_to,
		      strftime( "%F %T",
				localtime(generalizedTime_to_time($self->obj->get_value('modifyTimestamp')))),
		      strftime( "%F %T", localtime((stat($out_to))[9])),
		    ] )
      if $self->{v} > 0;
    return;
  }

  ### PICKING ROOT OBJECT RDN (IN OUR CASE IT IS "UID")
  foreach ( reverse split(/,/, $self->obj->dn) ) {
    next if $_ !~ /^uid=/;
    $tt_vars->{uid} = ( split(/=/, $_) )[1];
    last;
  }

  ### DRYRUN
  if ( $self->cf->get(qw(core dryrun)) ) {

    $self->log->cc( pr => 'debug', fm => "%s: DRYRUN: %s -> %s",
	      ls => [ sprintf("%s:%s",__FILE__,__LINE__),
		     sprintf("%s/%s", $self->cf->get(qw(core tt_path)),
			     $self->cf->get('service', $self->service, 'tt_file')),
		     $dir. '/' . $out_file
		    ] );

    if ( $self->cf->is_set($self->service, 'chmod') ) {
      $self->log->cc( pr => 'err', fm => "%s: DRYRUN: chmod %s, %s",
		ls => [ sprintf("%s:%s",__FILE__,__LINE__), $self->cf->get('service', $self->service, 'chmod'), $out_to ] );
    } elsif ( $self->cf->is_set(qw(core chmod)) ) {
      $self->log->cc( pr => 'err', fm => "%s: DRYRUN: chmod %s, %s",
		ls => [ sprintf("%s:%s",__FILE__,__LINE__), $self->cf->get('core', 'chmod'), $out_to ] );
    }

    if ( $self->cf->is_set($self->service, 'chown') ) {
      $self->log->cc( pr => 'err', fm => "%s: DRYRUN: chown %s, %s, %s",
		ls => [ sprintf("%s:%s",__FILE__,__LINE__), $self->obj->get_value('uidNumber'),
			$self->obj->get_value('gidNumber'),
			$out_to ] );
    }
    return;
  }

  my ( $tmp_fh, $tmp_fn );
  eval { $tmp_fh = File::Temp->new( UNLINK => 0, DIR => $dir ); };
  if ( $@ ) {
    $self->log->cc( pr => 'err', fm => "%s: File::Temp->new( DIR => %s ); service \"%s\"; err: \"%s\"",
	      ls => [ sprintf("%s:%s",__FILE__,__LINE__), $dir, $self->service, $@ ] );
    return;
  }
  $tmp_fn = $tmp_fh->filename;
  my $tt = Template->new( TRIM        => $self->cf->get(qw(core tt_trim)),
			  ABSOLUTE    => 1,
			  RELATIVE    => 1,
			  OUTPUT_PATH => $dir,
			  DEBUG       => $self->log->foreground // $self->cf->get(qw(core tt_debug)) );

  $self->log->cc( pr => 'err', fm => "%s: Template->new( OUTPUT_PATH => %s ) for service %s error: %s",
	    ls => [ sprintf("%s:%s",__FILE__,__LINE__), $dir, $self->service, $! ] )
    if ! defined $tt;

  $tt->process( sprintf("%s/%s",
			$self->cf->get(qw(core tt_path)),
			$self->cf->get('service', $self->service, 'tt_file')),



( run in 2.269 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )