From 06396ea4c8b9902b5948fafe51806b24cc9aa652 Mon Sep 17 00:00:00 2001 From: padams Date: Wed, 21 Oct 2026 12:37:38 +0000 Subject: [PATCH] Read the [default] section of ~/.owa/credentials 1.0.x read [defaults]; the wiki documented [default]. Accept both. --- src/OwaClient.php | 6 +++--- tests/OwaClientTest.php | 10 ++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/OwaClient.php b/src/OwaClient.php index 2f16e10..df348ea 100644 --- a/src/OwaClient.php +++ b/src/OwaClient.php @@ -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} */ @@ -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'] ) ) { diff --git a/tests/OwaClientTest.php b/tests/OwaClientTest.php index 8a68fed..0258820 100644 --- a/tests/OwaClientTest.php +++ b/tests/OwaClientTest.php @@ -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 );