To run the example, create a Code Engine project from the Console or Code Engine CLI, and run the following commands from this directory:
npm installexport CE_API_KEY=<Your IBM Cloud API key>export CE_PROJECT_ID=<Your Code Engine project ID>export CE_PROJECT_REGION=<The region (e.g. 'us-south') of your Code Engine project>node example.js
const authenticator = new IamAuthenticator({
apikey: process.env.CE_API_KEY,
clientId: 'bx',
clientSecret: 'bx',
});const ceClient = new CodeEngineV1({
authenticator,
serviceUrl: `https://api.us-south.codeengine.cloud.ibm.com/api/v1`,
});This example uses Axios for its async/await support and querystring to encode the request parameters.
const iamResponse = await axios.post('https://iam.cloud.ibm.com/identity/token', querystring.stringify({
grant_type: 'urn:ibm:params:oauth:grant-type:apikey',
apikey: process.env.CE_API_KEY,
response_type: 'delegated_refresh_token',
receiver_client_ids: 'ce',
delegated_refresh_token_expiry: '3600'
}), {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
const delegatedRefreshToken = iamResponse.data.delegated_refresh_token;const configResponse = await ceClient.getKubeconfig({
xDelegatedRefreshToken: delegatedRefreshToken,
id: process.env.CE_PROJECT_ID,
});
const kubeConfigString = configResponse.result;The /namespaces/{id}/config endpoint function, listKubeconfig(), is deprecated, and will be removed before Code Engine is out of Beta. Please use the getKubeconfig() function, demonstrated in the example above.