22
33namespace Prism \Bedrock ;
44
5+ use Aws \Credentials \CredentialProvider ;
6+ use Aws \Credentials \Credentials ;
57use Illuminate \Support \ServiceProvider ;
68
79class BedrockServiceProvider extends ServiceProvider
@@ -11,11 +13,28 @@ public function boot(): void
1113 $ this ->registerWithPrism ();
1214 }
1315
16+ /**
17+ * @param array<string,mixed> $config
18+ */
19+ public static function getCredentials (array $ config ): Credentials
20+ {
21+ if ($ config ['use_default_credential_provider ' ] ?? false ) {
22+ $ provider = CredentialProvider::defaultProvider ();
23+ } else {
24+ $ provider = CredentialProvider::fromCredentials (new Credentials (
25+ key: $ config ['api_key ' ],
26+ secret: $ config ['api_secret ' ],
27+ token: $ config ['session_token ' ] ?? null ,
28+ ));
29+ }
30+
31+ return $ provider ()->wait ();
32+ }
33+
1434 protected function registerWithPrism (): void
1535 {
1636 $ this ->app ->get ('prism-manager ' )->extend (Bedrock::KEY , fn ($ app , $ config ): \Prism \Bedrock \Bedrock => new Bedrock (
17- apiKey: $ config ['api_key ' ],
18- apiSecret: $ config ['api_secret ' ],
37+ credentials: BedrockServiceProvider::getCredentials ($ config ),
1938 region: $ config ['region ' ]
2039 ));
2140 }
0 commit comments