Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Website: Add secrets on-demand for more endpoints #1362

Merged
merged 2 commits into from
May 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 63 additions & 12 deletions packages/playground/website-deployment/custom-redirects-lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,23 +206,72 @@ function playground_maybe_set_environment( $requested_path ) {
}

if ( str_ends_with( $requested_path, 'logger.php' ) ) {
// WORKAROUND: Atomic_Persistent_Data wants the DB_PASSWORD constant
// which is not set yet. But we can force its definition.
__atomic_env_define( 'DB_PASSWORD' );

$secrets = new Atomic_Persistent_Data;
if ( isset(
$secrets->LOGGER_SLACK_CHANNEL,
$secrets->LOGGER_SLACK_TOKEN,
) ) {
putenv( "SLACK_CHANNEL={$secrets->LOGGER_SLACK_CHANNEL}" );
putenv( "SLACK_TOKEN={$secrets->LOGGER_SLACK_TOKEN}" );
// TODO: Remove this condition when we can confirm __atomic_env_define() is again always defined
if ( function_exists( '__atomic_env_define' ) ) {
// WORKAROUND: Atomic_Persistent_Data wants the DB_PASSWORD constant
// which is not set yet. But we can force its definition.
__atomic_env_define( 'DB_PASSWORD' );

$secrets = new Atomic_Persistent_Data;
if ( isset(
$secrets->LOGGER_SLACK_CHANNEL,
$secrets->LOGGER_SLACK_TOKEN,
) ) {
putenv( "SLACK_CHANNEL={$secrets->LOGGER_SLACK_CHANNEL}" );
putenv( "SLACK_TOKEN={$secrets->LOGGER_SLACK_TOKEN}" );
} else {
error_log( 'PLAYGROUND: Missing secrets for logger.php' );
}
} else {
error_log( 'PLAYGROUND: Unable to access secrets for logger.php' );
}

return true;
}

if ( str_ends_with( $requested_path, 'plugin-proxy.php' ) ) {
// TODO: Remove this condition when we can confirm __atomic_env_define() is again always defined
if ( function_exists( '__atomic_env_define' ) ) {
// WORKAROUND: Atomic_Persistent_Data wants the DB_PASSWORD constant
// which is not set yet. But we can force its definition.
__atomic_env_define( 'DB_PASSWORD' );

$secrets = new Atomic_Persistent_Data;
if ( isset( $secrets->GITHUB_TOKEN ) ) {
putenv( "GITHUB_TOKEN={$secrets->GITHUB_TOKEN}" );
} else {
error_log( 'PLAYGROUND: Missing secrets for plugin-proxy.php' );
}
} else {
error_log( 'PLAYGROUND: Missing secrets for logger.php' );
error_log( 'PLAYGROUND: Unable to access secrets for plugin-proxy.php' );
}
return true;
}

if ( str_ends_with( $requested_path, 'oauth.php' ) ) {
// TODO: Remove this condition when we can confirm __atomic_env_define() is again always defined
if ( function_exists( '__atomic_env_define' ) ) {
// WORKAROUND: Atomic_Persistent_Data wants the DB_PASSWORD constant
// which is not set yet. But we can force its definition.
__atomic_env_define( 'DB_PASSWORD' );

$secrets = new Atomic_Persistent_Data;
if ( isset(
$secrets->GITHUB_APP_CLIENT_ID,
$secrets->GITHUB_APP_CLIENT_SECRET,
) ) {
putenv( "GITHUB_APP_CLIENT_ID={$secrets->GITHUB_APP_CLIENT_ID}" );
putenv( "GITHUB_APP_CLIENT_SECRET={$secrets->GITHUB_APP_CLIENT_SECRET}" );
} else {
error_log( 'PLAYGROUND: Missing secrets for oauth.php' );
}
} else {
error_log( 'PLAYGROUND: Unable to access secrets for oauth.php' );
}
return true;
}


return false;
}

Expand All @@ -245,6 +294,7 @@ function playground_get_custom_response_headers( $filename ) {
'index.js',
'blueprint-schema.json',
'logger.php',
'oauth.php',
'wp-cli.phar',
'wordpress-importer.zip',
),
Expand All @@ -269,3 +319,4 @@ function playground_resolve_to_index_file( $real_path ) {
return false;
}
}

Loading