Skip to content

Commit

Permalink
Merge pull request #3 from therealgambo/basic-auth-plugin
Browse files Browse the repository at this point in the history
Add wrapper class for basic auth plugin
  • Loading branch information
therealgambo authored May 23, 2017
2 parents 025e130 + 0336107 commit 136daac
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
94 changes: 94 additions & 0 deletions src/Kong/Apis/Plugins/BasicAuth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace TheRealGambo\Kong\Apis\Plugins;

use TheRealGambo\Kong\Apis\AbstractApi;
use TheRealGambo\Kong\Apis\Consumer;

final class BasicAuth extends AbstractApi implements BasicAuthInterface
{
/**
* Create a new consumer in Kong
*
* @see https://getkong.org/plugins/basic-authentication/#create-a-consumer
*
* @param array $body
* @param array $headers
*
* @return array|\stdClass
*/
public function createConsumer(array $body = [], array $headers = [])
{
$consumer = new Consumer($this->url, $this->port);

return $consumer->add($body, $headers);
}

/**
* Create a new basic auth credential for a consumer
*
* @see https://getkong.org/plugins/basic-authentication/#create-a-credential
*
* @param string $identifier
* @param array $body
* @param array $headers
*
* @return array|\stdClass
*/
public function create($identifier, array $body = [], array $headers = [])
{
$this->setAllowedOptions(['username', 'password']);
$body = $this->createRequestBody($body);

return $this->postRequest('consumers/' . $identifier . '/basic-auth', $body, $headers);
}

/**
* Delete a basic auth credential for a consumer
*
* @see
*
* @param $identifier
* @param $auth_identifier
* @param array $headers
*
* @return array|\stdClass
*/
public function delete($identifier, $auth_identifier, array $headers = [])
{
return $this->deleteRequest('consumers/' . $identifier . '/basic-auth/' . $auth_identifier, $headers);
}

/**
* List all basic auth credentials for a consumer
*
* @see
*
* @param string $identifier
* @param array $params
* @param array $headers
*
* @return array|\stdClass
*/
public function list($identifier, array $params = [], array $headers = [])
{
return $this->getRequest('consumers/' . $identifier . '/basic-auth', $params, $headers);
}

/**
* Get a single basic auth credential for a consumer
*
* @see
*
* @param string $identifier
* @param string $auth_identifier
* @param array $params
* @param array $headers
*
* @return array|\stdClass
*/
public function get($identifier, $auth_identifier, array $params = [], array $headers = [])
{
return $this->getRequest('consumers/' . $identifier . '/basic-auth/' . $auth_identifier, $params, $headers);
}
}
12 changes: 12 additions & 0 deletions src/Kong/Apis/Plugins/BasicAuthInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace TheRealGambo\Kong\Apis\Plugins;

interface BasicAuthInterface
{
public function createConsumer(array $body = [], array $headers = []);
public function create($identifier, array $body = [], array $headers = []);
public function delete($identifier, $auth_identifier, array $headers = []);
public function list($identifier, array $params = [], array $headers = []);
public function get($identifier, $auth_identifier, array $params = [], array $headers = []);
}
11 changes: 11 additions & 0 deletions src/Kong/Kong.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use TheRealGambo\Kong\Apis\Consumer;
use TheRealGambo\Kong\Apis\Node;
use TheRealGambo\Kong\Apis\Plugin;
use TheRealGambo\Kong\Apis\Plugins\BasicAuth;
use TheRealGambo\Kong\Apis\Plugins\KeyAuth;
use TheRealGambo\Kong\Apis\Sni;
use TheRealGambo\Kong\Apis\Upstream;
Expand Down Expand Up @@ -192,4 +193,14 @@ public function getPluginKeyAuth()
{
return new KeyAuth($this->url, $this->port);
}

/**
* Returns a new instance of the Basic Auth Plugin
*
* @return \TheRealGambo\Kong\Apis\Plugins\BasicAuth
*/
public function getPluginBasicAuth()
{
return new BasicAuth($this->url, $this->port);
}
}

0 comments on commit 136daac

Please sign in to comment.