Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADD_ZONE_CNAME #2

Open
ziyedbe opened this issue Sep 27, 2024 · 0 comments
Open

ADD_ZONE_CNAME #2

ziyedbe opened this issue Sep 27, 2024 · 0 comments

Comments

@ziyedbe
Copy link

ziyedbe commented Sep 27, 2024

Hello,
Thank you for this library, it is helping a lot !
I was wondering why CNAME isn't supported ?
I looked into the processZoneRecord, wouldn't it work it if I just change 'A' to 'CNAME' to call this function ?

processZoneRecord('create', $view, $zone, 'A', \@rrs );
sub processZoneRecord
{
  my ($self, $action, $view, $zone, $rtype, $object) = @_;
  my $icHandle = $self->createHandle('Management/ResourceRecord');
  my @records = @{ $object };
  my $soapResponse;

  unless ( grep( /^$action$/, ( 'create', 'delete', 'modify' ) ) ) {
    return "unsupported action";
  }
  
  unless ( grep( /^$rtype$/, ( 'A', 'AAAA', 'CNAME', 'NAPTR', 'SRV', 'MX' ) ) ) {
    return "unsupported resource record type";
  }

  if ((scalar @records) <= 0) { return "nothing to do"; }

  if ($action eq 'modify') {
    # modify track
    my @nrec;
    my @orec;
    my $rt = lc ($rtype);
    my $method = 'update_' . $rt;
    
    foreach my $rs (@records) {
      unless (exists $rs->{new}{ttl}) { $rs->{new}{ttl} = 0; }
      unless (exists $rs->{old}{ttl}) { $rs->{old}{ttl} = 0; }
      if ($rtype eq 'NAPTR' and $rs->{new}{regexp} eq '') { $rs->{new}{regexp} = '""'; }
      if ($rtype eq 'NAPTR' and $rs->{old}{regexp} eq '') { $rs->{old}{regexp} = '""'; }
      push @nrec, $rs->{new};
      push @orec, $rs->{old};
    }

    my @args = (
      SOAP::Data->name( 'view_zones'  => [ { 'zone_name' => $zone, 'view_name' => $view } ] ),
      SOAP::Data->name( 'old_records' => [ \@orec ] ),
      SOAP::Data->name( 'new_records' => [ \@nrec ] ),
    );

    if ($rt eq 'a' || $rt eq 'aaaa') {
      push @args, SOAP::Data->name( 'sync_ptrs' => [ 1 ])
    }

    $soapResponse = $icHandle->$method(@args);
  } 
  else {
    # add or delete track
    foreach my $rs (@records) {
      unless ($rs->{'domain_name'} =~ /.+$zone$/) {
        #$rs->{'domain_name'} .= ".$zone";
      }
      unless (exists $rs->{'ttl'}) {
        $rs->{'ttl'} = 0;
      }
      if ($rtype eq 'NAPTR' and $rs->{'regexp'} eq '') {
        $rs->{'regexp'} = '""'; 
      }
    }

    my $rt = lc ($rtype);
    my $method =  $action eq 'create' ? 'add' : 'delete';
    $method .= '_' . $rt;

    my @args = (
      SOAP::Data->name( 'view_zones' => [ { 'zone_name' => $zone, 'view_name' => $view } ] ),
      SOAP::Data->name( "${rt}_records"  => [ \@records ] ),
    );

    if ($rt eq 'a' || $rt eq 'aaaa') {
      push @args, SOAP::Data->name( 'sync_ptrs' => [ 1 ])
    }
    
    $soapResponse = $icHandle->$method(@args);
  }

  return $self->verifySoapResponse( $soapResponse );
}

Thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant