Updated readme, install and other documentation, changed panel() to site() since it makes more sense that way with netbox. started fixing authentication, hostfact had a login method, but netbox does not, but the user model provides a password that we can authenticate against.
This commit is contained in:
parent
fee417f8bc
commit
0df9b15379
7 changed files with 120 additions and 92 deletions
15
INSTALL.md
15
INSTALL.md
|
|
@ -4,18 +4,27 @@
|
|||
The install of this package is pretty straight forward
|
||||
|
||||
## Install Steps
|
||||
### Install this package with composer:
|
||||
### Install
|
||||
Install this package with composer:
|
||||
```
|
||||
composer require wickedsoft/laravel-netbox
|
||||
```
|
||||
|
||||
### Copy the config files for laravel-netbox
|
||||
### Publish configuration
|
||||
Copy the config files for laravel-netbox
|
||||
```
|
||||
php artisan vendor:publish --provider="wickedsoft\NetBox\ServiceProvider" --tag="config"
|
||||
```
|
||||
|
||||
### Add the credentials to your environment file (.env)
|
||||
### Environment file
|
||||
Add the credentials to your environment file (.env)
|
||||
```
|
||||
NETBOX_DEFAULT_URL=
|
||||
NETBOX_DEFAULT_KEY=
|
||||
```
|
||||
|
||||
### MultiInstalls
|
||||
If you have multiple Netbox sites, you can add this to your environment file (.env), in order to pick a different default site than the default.
|
||||
```
|
||||
NETBOX_CONNECTION=
|
||||
```
|
||||
|
|
|
|||
160
README.md
160
README.md
|
|
@ -5,82 +5,12 @@ NetBox is an open source web application designed to help manage and document co
|
|||
- [Installation](INSTALL.md)
|
||||
- [Usage](#usage)
|
||||
- [Commands](#commands)
|
||||
- [Authentication](#authentication)
|
||||
- [MultiInstalls](multiinstalls)
|
||||
- [Change log](CHANGELOG.md)
|
||||
- [License](LICENSE.md)
|
||||
-
|
||||
|
||||
### Usage
|
||||
#### Authentication [users]
|
||||
It's possible to use a custom `netbox` authentication driver to login users in your application, by default the UserProfile will be cached for 60 minutes
|
||||
```php
|
||||
// config/auth.php
|
||||
'providers' => [
|
||||
'netbox' => [
|
||||
'driver' => 'netbox'
|
||||
],
|
||||
]
|
||||
|
||||
// Auth::attempt
|
||||
if(Auth::attempt(['username' => $username, 'password' => $password]))
|
||||
{
|
||||
dd(Auth::user(), Auth::id());
|
||||
}
|
||||
```
|
||||
|
||||
#### Multiple Installs [config]
|
||||
If you want to work with more Netbox installs, you can define more netboxes in the `config/netbox.php` file
|
||||
```php
|
||||
// config/netbox.php
|
||||
'panels' => [
|
||||
|
||||
'default' => [
|
||||
'url' => env('NETBOX_DEFAULT_URL'),
|
||||
'key' => env('NETBOX_DEFAULT_KEY'),
|
||||
],
|
||||
|
||||
'chicago' => [
|
||||
'url' => env('NETBOX_CHI_URL'),
|
||||
'key' => env('NETBOX_CHI_KEY'),
|
||||
],
|
||||
|
||||
],
|
||||
```
|
||||
|
||||
#### Multiple Installs [normal usage]
|
||||
To use another netbox than your default one, you can specify it with the panel-method
|
||||
```php
|
||||
// UsersController
|
||||
public function getIndex()
|
||||
{
|
||||
$users = NetBox::panel('chicago')->users()->list([
|
||||
'limit' => 20
|
||||
]);
|
||||
|
||||
//
|
||||
}
|
||||
```
|
||||
|
||||
#### Multiple Installs [dependency injection]
|
||||
```php
|
||||
// Route
|
||||
Route::get('/netbox/{netBox}/users', ['as' => 'netbox/users', 'uses' => 'UsersController@getIndex']);
|
||||
|
||||
Route::bind('netBox', function ($value, $route) {
|
||||
app('NetBox')->panel($value);
|
||||
|
||||
return app('NetBox');
|
||||
});
|
||||
|
||||
// UsersController
|
||||
public function getIndex(NetBox $netBox)
|
||||
{
|
||||
$users = $netBox->users()->list([
|
||||
'limit' => 20
|
||||
]);
|
||||
|
||||
//
|
||||
}
|
||||
```
|
||||
### Commands
|
||||
#### Global
|
||||
```php
|
||||
NetBox::status()->show(array $params)
|
||||
|
|
@ -660,4 +590,88 @@ NetBox::virtualMachines()->delete(int $id, array $params)
|
|||
NetBox::virtualMachines()->edit(int $id, array $params)
|
||||
NetBox::virtualMachines()->show(int $id, array $params)
|
||||
```
|
||||
|
||||
### Authentication
|
||||
It's possible to use a custom `netbox` authentication driver to login users in your application,
|
||||
#### Setup
|
||||
```php
|
||||
// config/auth.php
|
||||
'providers' => [
|
||||
'netbox' => [
|
||||
'driver' => 'netbox'
|
||||
],
|
||||
]
|
||||
|
||||
// Auth::attempt
|
||||
if(Auth::attempt(['username' => $username, 'password' => $password]))
|
||||
{
|
||||
dd(Auth::user(), Auth::id());
|
||||
}
|
||||
```
|
||||
#### Caching
|
||||
By default the UserProfile will be cached for 60 minutes, you can use the command below to clear it, it will refresh the next time it is needed.
|
||||
```php
|
||||
cache()->forget('netbox_user_id_' .$user_id);
|
||||
```
|
||||
|
||||
### MultiInstalls
|
||||
#### Configuration
|
||||
If you want to work with more Netbox installs, you can define more instances in the `config/netbox.php` file
|
||||
```php
|
||||
// config/netbox.php
|
||||
'sites' => [
|
||||
|
||||
'default' => [
|
||||
'url' => env('NETBOX_DEFAULT_URL'),
|
||||
'key' => env('NETBOX_DEFAULT_KEY'),
|
||||
],
|
||||
|
||||
'chicago' => [
|
||||
'url' => env('NETBOX_CHI_URL'),
|
||||
'key' => env('NETBOX_CHI_KEY'),
|
||||
],
|
||||
|
||||
],
|
||||
```
|
||||
#### Default site
|
||||
If you have multiple Netbox sites, you can add this to your environment file (.env), in order to pick a different default site than the default.
|
||||
```
|
||||
NETBOX_CONNECTION=
|
||||
```
|
||||
|
||||
#### Access
|
||||
To use another netbox than your default one, you can specify it with the panel-method
|
||||
```php
|
||||
// UsersController
|
||||
public function getIndex()
|
||||
{
|
||||
$users = NetBox::site('chicago')->users()->list([
|
||||
'limit' => 20
|
||||
]);
|
||||
|
||||
//
|
||||
}
|
||||
```
|
||||
|
||||
#### Dependency injection
|
||||
```php
|
||||
// Route
|
||||
Route::get('/netbox/{netBox}/users', ['as' => 'netbox/users', 'uses' => 'UsersController@getIndex']);
|
||||
|
||||
Route::bind('netBox', function ($value, $route) {
|
||||
app('NetBox')->site($value);
|
||||
|
||||
return app('NetBox');
|
||||
});
|
||||
|
||||
// UsersController
|
||||
public function getIndex(NetBox $netBox)
|
||||
{
|
||||
$users = $netBox->users()->list([
|
||||
'limit' => 20
|
||||
]);
|
||||
|
||||
//
|
||||
}
|
||||
```
|
||||
- - -
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ return [
|
|||
|
||||
'default' => env('NETBOX_CONNECTION', 'default'),
|
||||
|
||||
'panels' => [
|
||||
'sites' => [
|
||||
'default' => [
|
||||
'url' => env('NETBOX_DEFAULT_URL'),
|
||||
'key' => env('NETBOX_DEFAULT_KEY'),
|
||||
|
|
|
|||
|
|
@ -4,6 +4,17 @@ namespace wickedsoft\NetBox\Api\Users;
|
|||
|
||||
class Users extends AbstractApi
|
||||
{
|
||||
/**
|
||||
* @param $params
|
||||
* @return mixed
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function checkLogin($params)
|
||||
{
|
||||
return $this->get("/users/users/".$id."/", $params);
|
||||
//return $this->post(array_merge(['controller' => 'debtor', 'action' => 'checkLogin'], $params));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $params
|
||||
* @return mixed
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ class Client
|
|||
'tags' => 'Extras\Tags',
|
||||
|
||||
//ipam
|
||||
'aggregates' => 'IPAM\Aggregates'
|
||||
'aggregates' => 'IPAM\Aggregates',
|
||||
'ipAddresses' => 'IPAM\IpAddresses',
|
||||
'prefixes' => 'IPAM\Prefixes',
|
||||
'rirs' => 'IPAM\Rirs',
|
||||
|
|
@ -131,9 +131,7 @@ class Client
|
|||
if (!isset($this->classes[$name])) {
|
||||
throw new \InvalidArgumentException(sprintf('Undefined method called:"%s"', $name));
|
||||
}
|
||||
|
||||
$class = '\\wickedsoft\\NetBox\\Api\\' . $this->classes[$name];
|
||||
|
||||
return new $class($this);
|
||||
}
|
||||
|
||||
|
|
@ -145,9 +143,7 @@ class Client
|
|||
if (!isset($this->httpClient)) {
|
||||
$this->httpClient = new HttpClient();
|
||||
}
|
||||
|
||||
$this->httpClient->setOptions($this->getOptions());
|
||||
|
||||
return $this->httpClient;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class NetBox
|
|||
protected $client;
|
||||
|
||||
/** @var array */
|
||||
protected $panels = [];
|
||||
protected $sites = [];
|
||||
|
||||
/**
|
||||
* NetBox constructor.
|
||||
|
|
@ -36,17 +36,17 @@ class NetBox
|
|||
* @param null|string $name
|
||||
* @return \wickedsoft\NetBox\Client
|
||||
*/
|
||||
public function panel($name = null)
|
||||
public function site($name = null)
|
||||
{
|
||||
$name = $name ?: $this->getDefaultPanel();
|
||||
$name = $name ?: $this->getDefaultSite();
|
||||
|
||||
return $this->panels[$name] = $this->get($name);
|
||||
return $this->sites[$name] = $this->get($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultPanel()
|
||||
public function getDefaultSite()
|
||||
{
|
||||
return $this->app['config']['netbox.default'];
|
||||
}
|
||||
|
|
@ -57,7 +57,7 @@ class NetBox
|
|||
*/
|
||||
protected function get($name)
|
||||
{
|
||||
return $this->panels[$name] ?? $this->resolve($name);
|
||||
return $this->sites[$name] ?? $this->resolve($name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -83,6 +83,6 @@ class NetBox
|
|||
*/
|
||||
protected function getConfig($name)
|
||||
{
|
||||
return $this->app['config']["netbox.panels.{$name}"];
|
||||
return $this->app['config']["netbox.sites.{$name}"];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ class ServiceProvider extends \Illuminate\Support\ServiceProvider
|
|||
$this->publishes([
|
||||
__DIR__ . '/../config/netbox.php' => config_path('netbox.php')
|
||||
], 'config');
|
||||
|
||||
\Auth::provider('netbox', function ($app, array $config) {
|
||||
return new \wickedsoft\NetBox\Providers\NetBoxProvider();
|
||||
});
|
||||
|
|
@ -39,11 +38,10 @@ class ServiceProvider extends \Illuminate\Support\ServiceProvider
|
|||
{
|
||||
$this->app->singleton('wickedsoft\NetBox\NetBox', function ($app) {
|
||||
$netBox = new NetBox($app);
|
||||
$netBox->panel($netBox->getDefaultPanel());
|
||||
$netBox->site($netBox->getDefaultSite());
|
||||
|
||||
return $netBox;
|
||||
});
|
||||
|
||||
$this->app->alias('wickedsoft\NetBox\NetBox', 'NetBox');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
editor.link_modal.header
Reference in a new issue