-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathload-identity.php
More file actions
56 lines (50 loc) · 1.78 KB
/
load-identity.php
File metadata and controls
56 lines (50 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* Load the Team51 identity from 1Password.
*/
// Set the OPSOASIS_WP_USERNAME to the Team51 1Password account email.
$team51_op_account = array_filter(
list_1password_accounts() ?? array(),
static fn( object $account ) => 'ZVYA3AB22BC37JPJZJNSGOPYEQ' === $account->account_uuid
);
$team51_op_account = empty( $team51_op_account ) ? null : reset( $team51_op_account );
define( 'OPSOASIS_WP_USERNAME', $team51_op_account->email ?? null );
// Set the OPSOASIS_APP_PASSWORD either from the environment or from 1Password.
if ( ! empty( getenv( 'TEAM51_OPSOASIS_APP_PASSWORD' ) ) ) {
define( 'OPSOASIS_APP_PASSWORD', getenv( 'TEAM51_OPSOASIS_APP_PASSWORD' ) );
} else {
try {
$team51_op_logins = list_1password_items(
array(
'categories' => 'Login',
'vault' => 'Private',
)
);
foreach ( $team51_op_logins ?? array() as $op_login ) {
foreach ( $op_login->urls ?? array() as $url ) {
if ( 'opsoasis.wpspecialprojects.com' !== parse_url( $url->href, PHP_URL_HOST ) ) {
continue;
}
$op_login = get_1password_item( $op_login->id ); // Hydrate the custom fields.
foreach ( $op_login->fields as $field ) {
if ( 'App Password' === $field->label ) {
define( 'OPSOASIS_APP_PASSWORD', $field->value );
break 3;
}
}
}
}
} catch ( \RuntimeException $e ) {
console_writeln( "Error retrieving OpsOasis app password: {$e->getMessage()}" );
exit( 1 );
}
}
// Abort if we don't have the identity.
if ( ! defined( 'OPSOASIS_WP_USERNAME' ) || empty( OPSOASIS_WP_USERNAME ) ) {
console_writeln( 'Could not find the Team51 1Password account. Aborting!' );
exit( 1 );
}
if ( ! defined( 'OPSOASIS_APP_PASSWORD' ) || empty( OPSOASIS_APP_PASSWORD ) ) {
console_writeln( 'Could not find the OpsOasis app password. Aborting!' );
exit( 1 );
}