@@ -3,27 +3,30 @@ import { FaableApi } from "./FaableApi";
33import { apikey_strategy } from "./strategies/apikey.strategy" ;
44import { getIDToken } from "@actions/core" ;
55import { oidc_strategy } from "./strategies/oidc.strategy" ;
6+ import { CredentialsStore } from "../lib/CredentialsStore" ;
67
78export const context = async ( ) => {
89
910 let api :FaableApi ;
1011 if ( process . env . FAABLE_APIKEY ) {
12+ // Apikey in environment
1113 const apikey = process . env . FAABLE_APIKEY ;
1214 api = FaableApi . create ( { authStrategy : apikey_strategy , auth : { apikey } } )
13- }
14-
15-
16- //const store = new CredentialsStore();
17- //(await store.loadCredentials())?.apikey
18-
19- // Github actions environment
20- if ( process . env . GITHUB_ACTIONS === 'true' ) {
15+ } else if ( process . env . GITHUB_ACTIONS === 'true' ) {
16+ // Github actions environment
2117 try {
2218 const idToken = process . env . FAABLE_ID_TOKEN || await getIDToken ( "https://faable.com" ) ;
2319 api = FaableApi . create ( { authStrategy : oidc_strategy , auth : { idToken } } )
2420 } catch ( _ ) {
2521 console . error ( "Error fetching token, configure 'permissions: id-token: write'" ) ;
2622 }
23+ } else {
24+ const store = new CredentialsStore ( ) ;
25+ const { apikey} = await store . loadCredentials ( )
26+ if ( ! apikey ) {
27+ throw new Error ( "No apikey found, please run 'faable login' first" ) ;
28+ }
29+ api = FaableApi . create ( { authStrategy : apikey_strategy , auth : { apikey } } )
2730 }
2831
2932
0 commit comments