diff --git a/src/TrafficManagement.php b/src/TrafficManagement.php index a357849..6adc233 100644 --- a/src/TrafficManagement.php +++ b/src/TrafficManagement.php @@ -4,6 +4,7 @@ use Dyn\TrafficManagement\Api\Client as ApiClient; use Dyn\TrafficManagement\Zone; +use Symfony\Component\Config\Definition\Exception\Exception; use Zend\Http\Client as HttpClient; class TrafficManagement @@ -182,6 +183,29 @@ public function getZone($zoneName) return false; } + + /** + * @param $start int + * @param $end int + * @return bool|Zone + */ + public function getQpsJobs($start,$end) + { + $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 * diff --git a/src/TrafficManagement/Api/Client.php b/src/TrafficManagement/Api/Client.php index 3401e4e..99d03f9 100644 --- a/src/TrafficManagement/Api/Client.php +++ b/src/TrafficManagement/Api/Client.php @@ -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) { @@ -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)); } diff --git a/src/TrafficManagement/Api/Response.php b/src/TrafficManagement/Api/Response.php index 880948c..38dc99e 100644 --- a/src/TrafficManagement/Api/Response.php +++ b/src/TrafficManagement/Api/Response.php @@ -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; diff --git a/src/TrafficManagement/Record/PTR.php b/src/TrafficManagement/Record/PTR.php index f813a8b..3f89ba3 100644 --- a/src/TrafficManagement/Record/PTR.php +++ b/src/TrafficManagement/Record/PTR.php @@ -46,9 +46,7 @@ public function getPtrdname() */ public function setRData(array $rdata) { - // TODO - - return $this; + $this->setPtrdname($rdata['ptrdname']); } /** diff --git a/src/TrafficManagement/Record/SPF.php b/src/TrafficManagement/Record/SPF.php index 58a964b..070fa24 100644 --- a/src/TrafficManagement/Record/SPF.php +++ b/src/TrafficManagement/Record/SPF.php @@ -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 diff --git a/src/TrafficManagement/Record/SRV.php b/src/TrafficManagement/Record/SRV.php index 351ac22..ce10c8a 100644 --- a/src/TrafficManagement/Record/SRV.php +++ b/src/TrafficManagement/Record/SRV.php @@ -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']; } /** diff --git a/src/TrafficManagement/Record/TXT.php b/src/TrafficManagement/Record/TXT.php index 56fff2d..5d5f8f2 100644 --- a/src/TrafficManagement/Record/TXT.php +++ b/src/TrafficManagement/Record/TXT.php @@ -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); } /** @@ -44,9 +52,8 @@ public function getTxtdata() */ public function setRData(array $rdata) { - // TODO - - return $this; + $this->rdata = $rdata; + $this->txtdata = $rdata['txtdata']; } /** diff --git a/src/TrafficManagement/Zone.php b/src/TrafficManagement/Zone.php index 005fb2a..43e4d82 100644 --- a/src/TrafficManagement/Zone.php +++ b/src/TrafficManagement/Zone.php @@ -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; + } + /** * Setter for type * @@ -215,6 +233,7 @@ public function getDefaultTtl($defaultTtl) return $this->defaultTtl; } + /** * Create the supplied record * @@ -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; diff --git a/test/DynTest/TrafficManagement/ZoneTest.php b/test/DynTest/TrafficManagement/ZoneTest.php index 7b142bb..28dea0a 100644 --- a/test/DynTest/TrafficManagement/ZoneTest.php +++ b/test/DynTest/TrafficManagement/ZoneTest.php @@ -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();