Skip to content

Commit

Permalink
make the PullPreview user configurable. (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
holyfabi authored Jul 5, 2024
1 parent 1f45e86 commit eb850f7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/pullpreview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
.env.amigor
# https://git-scm.com/docs/git-sparse-checkout#_internalscone_mode_handling
sparse-checkout-cone-mode: false
- run: echo "TRANSMORPHER_AUTH_TOKEN=\"${{ secrets.PULLPREVIEW_TRANSMORPHER_AUTH_TOKEN }}\"" >> .env.amigor
- run: echo "TRANSMORPHER_AUTH_TOKEN=\"${{ secrets.PULLPREVIEW_SANCTUM_AUTH_TOKEN }}\"" >> .env.amigor

- name: Upload Amigor .env file
# https://github.com/actions/upload-artifact
Expand Down Expand Up @@ -46,8 +46,10 @@ jobs:
secrets:
ENV_VARS: |
APP_KEY="${{ secrets.PULLPREVIEW_APP_KEY }}"
TRANSMORPHER_SIGNING_KEYPAIR="${{ secrets.PULLPREVIEW_TRANSMORPHER_SIGNING_KEYPAIR }}"
TRANSMORPHER_AUTH_TOKEN_HASH="${{ secrets.PULLPREVIEW_TRANSMORPHER_AUTH_TOKEN_HASH }}"
SEED_USER_NAME="${{ secrets.PULLPREVIEW_USER_NAME }}"
SEED_USER_EMAIL="${{ secrets.PULLPREVIEW_USER_EMAIL }}"
TRANSMORPHER_SIGNING_KEYPAIR="${{ secrets.PULLPREVIEW_SODIUM_KEYPAIR }}"
TRANSMORPHER_AUTH_TOKEN_HASH="${{ secrets.PULLPREVIEW_SANCTUM_AUTH_TOKEN_HASH }}"
PULLPREVIEW_AWS_ACCESS_KEY_ID: ${{ secrets.PULLPREVIEW_AWS_ACCESS_KEY_ID }}
PULLPREVIEW_AWS_SECRET_ACCESS_KEY: ${{ secrets.PULLPREVIEW_AWS_SECRET_ACCESS_KEY }}
PULLPREVIEW_BASIC_AUTH: ${{ secrets.PULLPREVIEW_BASIC_AUTH }}
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,12 @@ There are additional settings in the `transmorpher.php` config file.
Media always belongs to a user. To easily create one, use the provided command:

```bash
php artisan create:user <name> <email>
php artisan create:user <name> <email> <api_url>
```

The server sends notifications to the api url, for example, video transcoding information.
For our standard laravel client implementation, this is: `https://example.com/transmorpher/notifications`.

This command will provide you with a [Laravel Sanctum](https://laravel.com/docs/11.x/sanctum) token, which has to be
written in the `.env` file of a client system.
> The token will be passed for all API requests for authorization and is connected to the corresponding user.
Expand Down Expand Up @@ -486,9 +489,11 @@ For more information, take a look at the PullPreview section of the [github-work
App-specific GitHub Secrets:

- PULLPREVIEW_APP_KEY
- PULLPREVIEW_TRANSMORPHER_SIGNING_KEYPAIR
- PULLPREVIEW_TRANSMORPHER_AUTH_TOKEN
- PULLPREVIEW_TRANSMORPHER_AUTH_TOKEN_HASH
- PULLPREVIEW_SODIUM_KEYPAIR
- PULLPREVIEW_SANCTUM_AUTH_TOKEN
- PULLPREVIEW_SANCTUM_AUTH_TOKEN_HASH
- PULLPREVIEW_USER_NAME
- PULLPREVIEW_USER_EMAIL

#### Companion App

Expand All @@ -505,6 +510,12 @@ php artisan create:user pullpreview [email protected] http://pullpreview.t
Take the hash of the token from the `personal_access_tokens` table and save it to GitHub secrets. The command also provides a `TRANSMORPHER_AUTH_TOKEN`, which should be stored
securely to use in client systems.

#### Using your custom PullPreview environment

In addition to the GitHub Secrets, you'll need to set the `CLIENT_CONTAINER_NAME` env variable for the Transmorpher server.

You may use the `CLIENT_NOTIFICATION_ROUTE` env variable if you have a custom notifications url, which differs from the default client implementation.

## License

The Transmorpher media server is licensed under the [MIT license](https://opensource.org/licenses/MIT).
10 changes: 8 additions & 2 deletions app/Console/Commands/CreateUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class CreateUser extends Command
protected $signature = 'create:user
{name : The name of the user.}
{email : The E-Mail of the user.}
{api_url : The URL at which the client can receive notifications.}';
{api_url : The URL at which the client can receive notifications.}
{--password= : The password of the user.}';

/**
* The console command description.
Expand Down Expand Up @@ -69,7 +70,12 @@ public function handle(): int
* we will just generate a string of random bytes.
* This needs to be encoded to base64 because null bytes are not accepted anymore (PHP 8.3).
*/
$user = User::create(['name' => $name, 'email' => $email, 'api_url' => $apiUrl, 'password' => Hash::make(base64_encode(random_bytes(300)))]);
$user = User::create([
'name' => $name,
'email' => $email,
'api_url' => $apiUrl,
'password' => $this->option('password') ?: base64_encode(random_bytes(300))
]);

$this->info(sprintf('Successfully created new user %s: %s (%s)', $user->getKey(), $user->name, $user->email));
$this->newLine();
Expand Down
7 changes: 6 additions & 1 deletion database/seeders/PullpreviewSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ class PullpreviewSeeder extends Seeder
*/
public function run(): void
{
Artisan::call('create:user pullpreview [email protected] http://amigor/transmorpher/notifications');
Artisan::call('create:user', [
'name' => env('SEED_USER_NAME'),
'email' => env('SEED_USER_EMAIL'),
'api_url' => sprintf('http://%s/%s', env('CLIENT_CONTAINER_NAME'), env('CLIENT_NOTIFICATION_ROUTE', 'transmorpher/notifications')),
'--password' => env('SEED_USER_PASSWORD')
]);

DB::table('personal_access_tokens')->where('id', 1)->update(['token' => env('TRANSMORPHER_AUTH_TOKEN_HASH')]);
}
Expand Down
1 change: 1 addition & 0 deletions docker-compose.pullpreview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ services:
PULLPREVIEW_FIRST_RUN: ${PULLPREVIEW_FIRST_RUN}
VIDEO_TRANSCODING_WORKERS_AMOUNT: ${VIDEO_TRANSCODING_WORKERS_AMOUNT:-1}
APP_URL: ${PULLPREVIEW_URL}/transmorpherServer
CLIENT_CONTAINER_NAME: ${AMIGOR_CONTAINER_NAME:-amigor}
volumes:
- 'app-storage:/var/www/html/storage'
labels:
Expand Down

0 comments on commit eb850f7

Please sign in to comment.