-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:fleetbase/core-api into feature-aut…
…hentication
- Loading branch information
Showing
19 changed files
with
257 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
use Aws\Credentials\CredentialProvider; | ||
|
||
$provider = CredentialProvider::defaultProvider(); | ||
|
||
$s3Config = [ | ||
'version' => 'latest', | ||
'bucket' => env('DB_BACKUP_BUCKET', 'fleetbase-db-backups'), | ||
'region' => env('AWS_DEFAULT_REGION', 'ap-southeast-1'), | ||
'endpoint' => env('AWS_ENDPOINT') | ||
]; | ||
|
||
if (env('APP_ENV') === 'local' || env('APP_ENV') === 'development') { | ||
$s3Config['key'] = env('AWS_ACCESS_KEY_ID'); | ||
$s3Config['secret'] = env('AWS_SECRET_ACCESS_KEY'); | ||
} else { | ||
$s3Config['credentials'] = $provider; | ||
} | ||
|
||
return [ | ||
/* | ||
* Configure with your Amazon S3 credentials | ||
* You should use an IAM user who only has PutObject access | ||
* to a specified bucket | ||
*/ | ||
's3' => $s3Config, | ||
|
||
/* | ||
* Want to add some custom mysqldump args? | ||
*/ | ||
'custom_mysqldump_args' => '--default-character-set=utf8mb4', | ||
|
||
/* | ||
* Whether or not to gzip the .sql file | ||
*/ | ||
'gzip' => true, | ||
|
||
/* | ||
* Time allowed to run backup | ||
*/ | ||
'sql_timout' => 7200, // 2 hours | ||
|
||
/* | ||
* Backup filename | ||
*/ | ||
'filename' => str_replace([' ', '-'], '_', env('APP_ENV', 'local')) . '_%s_backup-%s.sql', | ||
|
||
/* | ||
* Where to store the backup file locally | ||
*/ | ||
'backup_dir' => '/tmp', | ||
|
||
/* | ||
* Do you want to keep a copy of it or delete it | ||
* after it's been uploaded? | ||
*/ | ||
'keep_local_copy' => false, | ||
|
||
/* | ||
* Do you want to keep a rolling number of | ||
* backups on S3? How many days worth? | ||
*/ | ||
'rolling_backup_days' => 30, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Fleetbase\Http\Controllers\Api\v1; | ||
|
||
use Fleetbase\Http\Controllers\Controller; | ||
use Fleetbase\Http\Resources\Organization; | ||
use Fleetbase\Models\ApiCredential; | ||
use Fleetbase\Models\Company; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Str; | ||
|
||
class OrganizationController extends Controller | ||
{ | ||
public function getCurrent(Request $request) | ||
{ | ||
$token = $request->bearerToken(); | ||
$isSecretKey = Str::startsWith($token, '$'); | ||
|
||
// Depending on API key format set the connection to find credential on | ||
$connection = Str::startsWith($token, 'flb_test_') ? 'sandbox' : 'mysql'; | ||
|
||
// Find the API Credential record | ||
$findApKey = ApiCredential::on($connection) | ||
->where(function ($query) use ($isSecretKey, $token) { | ||
if ($isSecretKey) { | ||
$query->where('secret', $token); | ||
} else { | ||
$query->where('key', $token); | ||
} | ||
}) | ||
->with(['company.owner']) | ||
->withoutGlobalScopes(); | ||
|
||
// Get the api credential model record | ||
$apiCredential = $findApKey->first(); | ||
|
||
// Handle no api credential found | ||
if (!$apiCredential) { | ||
return response()->error('No API key found to fetch company details with.'); | ||
} | ||
|
||
// Get the organization owning the API key | ||
$organization = Company::where('uuid', $apiCredential->company_uuid)->first(); | ||
|
||
return new Organization($organization); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.