Skip to content

Commit

Permalink
Made changes in as follows
Browse files Browse the repository at this point in the history
.env, config, services, trait
to secure book and author api's standalone access.
  • Loading branch information
code-architect committed Jan 5, 2019
1 parent 9447055 commit 982643b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions LumenApiGateway/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ CACHE_DRIVER=file
QUEUE_CONNECTION=sync

AUTHORS_SERVICE_BASE_URL=localhost:8066
AUTHORS_SERVICE_SECRET=
BOOKS_SERVICE_BASE_URL=localhost:8067
BOOKS_SERVICE_SECRET
7 changes: 7 additions & 0 deletions LumenApiGateway/app/Services/AuthorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@ class AuthorService
*/
public $baseUri;

/**
* Authorization secret to pass to author api
* @var string
*/
public $secret;

public function __construct()
{
$this->baseUri = config('services.authors.base_uri');
$this->secret = config('services.authors.secret');
}


Expand Down
7 changes: 7 additions & 0 deletions LumenApiGateway/app/Services/BookService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@ class BookService
*/
public $baseUri;

/**
* Authorization secret to pass to book api
* @var string
*/
public $secret;

public function __construct()
{
$this->baseUri = config('services.books.base_uri');
$this->secret = config('services.books.secret');
}


Expand Down
5 changes: 5 additions & 0 deletions LumenApiGateway/app/Traits/ConsumeExternalService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public function performRequest($method, $requestUrl, $formParams = [], $headers
'base_uri' => $this->baseUri,
]);

if(isset($this->secret))
{
$headers['Authorization'] = $this->secret;
}

$response = $client->request($method, $requestUrl, [
'form_params' => $formParams,
'headers' => $headers,
Expand Down
2 changes: 2 additions & 0 deletions LumenApiGateway/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
return [
'authors' => [
'base_uri' => env('AUTHORS_SERVICE_BASE_URL'),
'secret' => env('AUTHORS_SERVICE_SECRET'),
],

'books' => [
'base_uri' => env('BOOKS_SERVICE_BASE_URL'),
'secret' => env('BOOKS_SERVICE_SECRET'),
],
];

0 comments on commit 982643b

Please sign in to comment.