Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/TrafficManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Dyn\TrafficManagement\Api\Client as ApiClient;
use Dyn\TrafficManagement\Zone;
use Symfony\Component\Config\Definition\Exception\Exception;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove this import, as it doesn't appear to be used.

use Zend\Http\Client as HttpClient;

class TrafficManagement
Expand Down Expand Up @@ -182,6 +183,29 @@ public function getZone($zoneName)
return false;
}


/**
* @param $start int
* @param $end int
* @return bool|Zone
*/
public function getQpsJobs($start,$end)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming this function createQpsReport would be more consistent with the others, since the API call is a POST, even though what it's doing is returning data.

Also, could you make the parameters camel cased versions of the actual API call args? So $startTs, $endTs.

I would be inclined to make this call return the actual data on success (rather than a response object), just so users of the function don't need to understand the structure of the response object as well:

if ($result && $result->isComplete()) {
    return $result->data;
}

{
$apiClient = $this->getApiClient();

///QPSReport/', );
$result = $apiClient->post(
'/QPSReport/',
['start_ts' => $start, 'end_ts' => $end, 'breakdown' => ['zones']]
);

if ($result && $result->isComplete()) {
return $result;
}

return $apiClient->getLastHttpResponse();
}

/**
* Returns an array of all zones from the account
*
Expand Down
3 changes: 2 additions & 1 deletion src/TrafficManagement/Api/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Client extends BaseClient
* Builds a request object for the given API path
*
* @param string $path
* @return Zend\Http\Request
* @return Request
*/
protected function buildRequest($path)
{
Expand Down Expand Up @@ -158,6 +158,7 @@ public function post($path, array $data = null)
$request = $this->buildRequest($path);

$request->setMethod(Request::METHOD_POST);

if ($data) {
$request->setContent(json_encode($data));
}
Expand Down
4 changes: 3 additions & 1 deletion src/TrafficManagement/Api/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public static function fromJson($json)
$response = new Response();
$response->job_id = $json->job_id;
$response->status = $json->status;
$response->msgs = $json->msgs;
if ($response->msgs){
$response->msgs = $json->msgs;
}
$response->data = $json->data;

return $response;
Expand Down
4 changes: 1 addition & 3 deletions src/TrafficManagement/Record/PTR.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ public function getPtrdname()
*/
public function setRData(array $rdata)
{
// TODO

return $this;
$this->setPtrdname($rdata['ptrdname']);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/TrafficManagement/Record/SPF.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Dyn\TrafficManagement\Record;

class SOA extends AbstractRecord
class SPF extends AbstractRecord
{
/**
* @var string
*/
protected $type = 'SOA';
protected $type = 'SPF';

/**
* SPF record information, e.g.: v=spfl mx ptr -all
Expand Down
5 changes: 4 additions & 1 deletion src/TrafficManagement/Record/SRV.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ public function setRData(array $rdata)
{
// TODO

return $this;
$this->port = $rdata['port'];
$this->priority = $rdata['priority'];
$this->target = $rdata['target'];
$this->weight = $rdata['weight'];
}

/**
Expand Down
15 changes: 11 additions & 4 deletions src/TrafficManagement/Record/TXT.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ public function setTxtdata($txtdata)
*/
public function getTxtdata()
{
return $this->txtdata;
return $this->sanitizeTxtData($this->txtdata);
}

/*filter for getting txt data so we remove any escape sequences
* mainly we are going to look for backslaches and get rid of them
*/
function sanitizeTxtData($txt){

return str_replace("\\","",$txt);
}

/**
Expand All @@ -44,9 +52,8 @@ public function getTxtdata()
*/
public function setRData(array $rdata)
{
// TODO

return $this;
$this->rdata = $rdata;
$this->txtdata = $rdata['txtdata'];
}

/**
Expand Down
21 changes: 20 additions & 1 deletion src/TrafficManagement/Zone.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,24 @@ public function getName()
return $this->name;
}


/**
*
* API request for this zones QPS reports for the given timeframe
*
* @param $start int
* @param $end int
* @return ApiResponse|false
*/
public function getQPS($start, $end)
{
$path = '/QPSReport/';

$result = $this->apiClient->post($path, ['start_ts'=>$start,'end_ts'=>$end,'zones'=>[$this->name]]);

return $result;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same feedback here as for the getQpsJobs() function.


/**
* Setter for type
*
Expand Down Expand Up @@ -215,6 +233,7 @@ public function getDefaultTtl($defaultTtl)
return $this->defaultTtl;
}


/**
* Create the supplied record
*
Expand Down Expand Up @@ -246,7 +265,7 @@ public function createRecord(RecordInterface $record, $fqdn = null)
*/
public function createRecordFromParams($type, $fqdn, array $params)
{
$result = $this->apiClient->post('/'.$type.'Record/'.$this->getName().'/'.$fqdn.'/', $params);
$result = $this->apiClient->post('/'.$type.'Record/'.$this->getName().'/'.$fqdn.'/', $params);
if ($result && $result->isOk()) {
if ($result->isComplete()) {
return true;
Expand Down
36 changes: 36 additions & 0 deletions test/DynTest/TrafficManagement/ZoneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,42 @@ public function setUp()
$this->zone->setName('example.com');
}

public function testoverwriteTXTRecords(){
$this->zone->overwriteTXTRecords(array(),$fqdn='example.com');
}

public function testoverwriteTXTRecordsWithArgs(){
//$params = array(
// 'rdata' => $record->getRData(),
// 'ttl' => $record->getTtl()
//);
$fqdn = 'example.com';
$rdataArray[] = array('txtdata' => 'whatevertxt');
$rdataArray[] = array('txtdata' => 'whatevertxt2');
$rdataArray[] = array('txtdata' => 'whatevertxt3');
$rdataArray[] = array('txtdata' => 'whatevertxt4');
$rparams = array(
'rdata' => $rdataArray,
'ttl' => 300 //$record->getTtl()
);
$records[]= array('rdata'=>'txtdata');
$this->zone->overwriteTXTRecords($rparams,$fqdn);
}

public function testoverwriteTXTRecordserrorsWithoutArgs(){
$this->zone->overwriteTXTRecords();
}

public function textoverwriteTXTRecordswithapicall(){
$this->apiClient->getHttpClient()->getAdapter()->setResponse(
"HTTP/1.1 200 OK" . "\r\n" .
"Content-type: application/json" . "\r\n\r\n" .
'{"status": "success", "data": {"url": "http://example.com/other", "code": "302", "keep_uri": "False", "fqdn": "test.example.com", "zone": "example.com"}, "job_id": 12345678, "msgs": [{"INFO": "add_node: New node added to zone", "SOURCE": "BLL", "ERR_CD": null, "LVL": "INFO"}, {"INFO": "add: Service added", "SOURCE": "BLL", "ERR_CD": null, "LVL": "INFO"}]}'
);


}

public function testHttpRedirectServiceCreation()
{
$httpRedirect = new HTTPRedirect();
Expand Down