Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions src/OwaClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function setSetting( string $name, mixed $value ): void {
*
* Looked up in order: the 'credentials' config array, the OWA_API_KEY /
* OWA_AUTH_KEY environment variables, constants of the same names, then
* the [defaults] section of ~/.owa/credentials.
* the [defaults] or [default] section of ~/.owa/credentials.
*
* @return array{api_key: string, auth_key: string}
*/
Expand Down Expand Up @@ -134,8 +134,8 @@ private function readCredentialsFile(): ?array {

$ini = parse_ini_file( $file, true, INI_SCANNER_RAW );

// [defaults] section, or bare keys
$section = is_array( $ini ) ? ( $ini['defaults'] ?? $ini ) : null;
// [defaults] (what 1.0.x read), [default] (what its docs said), or bare keys
$section = is_array( $ini ) ? ( $ini['defaults'] ?? $ini['default'] ?? $ini ) : null;

if ( is_array( $section ) && isset( $section['api_key'], $section['auth_key'] ) ) {

Expand Down
10 changes: 8 additions & 2 deletions tests/OwaClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,17 @@ public function testCredentialsFromEnvironment(): void {
$this->assertSame( [ 'api_key' => self::API_KEY, 'auth_key' => self::AUTH_KEY ], $client->getCredentials() );
}

public function testCredentialsFromFileDefaultsSection(): void {
/**
* 1.0.x read [defaults]; its wiki documented [default].
*/
#[\PHPUnit\Framework\Attributes\TestWith( [ '[defaults]' ] )]
#[\PHPUnit\Framework\Attributes\TestWith( [ '[default]' ] )]
#[\PHPUnit\Framework\Attributes\TestWith( [ '' ] )]
public function testCredentialsFromFile( string $section ): void {

$this->tmp = sys_get_temp_dir() . '/owa-sdk-test-' . bin2hex( random_bytes( 4 ) );
mkdir( $this->tmp . '/.owa', 0700, true );
file_put_contents( $this->tmp . '/.owa/credentials', "[defaults]\napi_key = " . self::API_KEY . "\nauth_key = " . self::AUTH_KEY . "\n" );
file_put_contents( $this->tmp . '/.owa/credentials', "$section\napi_key = " . self::API_KEY . "\nauth_key = " . self::AUTH_KEY . "\n" );

$home = getenv( 'HOME' );
putenv( 'HOME=' . $this->tmp );
Expand Down
Loading