11/*
2- * (C) Copyright IBM Corp. 2020 .
2+ * (C) Copyright IBM Corp. 2021 .
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55 * the License. You may obtain a copy of the License at
1818package com .ibm .cloud .code_engine .ibm_cloud_code_engine .v1 ;
1919
2020import com .ibm .cloud .code_engine .common .SdkCommon ;
21+ import com .ibm .cloud .code_engine .ibm_cloud_code_engine .v1 .model .GetKubeconfigOptions ;
2122import com .ibm .cloud .code_engine .ibm_cloud_code_engine .v1 .model .ListKubeconfigOptions ;
2223import com .ibm .cloud .sdk .core .http .RequestBuilder ;
2324import com .ibm .cloud .sdk .core .http .ResponseConverter ;
3132import java .util .Map .Entry ;
3233
3334/**
34- * The purpose is to provide an API to get Kubeconfig for IBM Cloud Code Engine Project.
35+ * The purpose is to provide an API to get Kubeconfig file for IBM Cloud Code Engine Project.
3536 *
3637 * @version v1
3738 */
@@ -78,9 +79,10 @@ public IbmCloudCodeEngine(String serviceName, Authenticator authenticator) {
7879 }
7980
8081 /**
81- * Retrieve KUBECONFIG for a specified project.
82+ * Deprecated soon: Retrieve KUBECONFIG for a specified project.
8283 *
83- * Returns the KUBECONFIG, similar to the output of `kubectl config view --minify=true`.
84+ * **Deprecated soon**: This API will be deprecated soon. Use the [GET /project/{id}/config](#get-kubeconfig) API
85+ * instead. Returns the KUBECONFIG file, similar to the output of `kubectl config view --minify=true`.
8486 *
8587 * @param listKubeconfigOptions the {@link ListKubeconfigOptions} containing the options for the call
8688 * @return a {@link ServiceCall} with a result of type {@link String}
@@ -95,8 +97,51 @@ public ServiceCall<String> listKubeconfig(ListKubeconfigOptions listKubeconfigOp
9597 for (Entry <String , String > header : sdkHeaders .entrySet ()) {
9698 builder .header (header .getKey (), header .getValue ());
9799 }
98- builder .header ("Accept" , "text/plain" );
99100 builder .header ("Refresh-Token" , listKubeconfigOptions .refreshToken ());
101+ if (listKubeconfigOptions .accept () != null ) {
102+ builder .header ("Accept" , listKubeconfigOptions .accept ());
103+ }
104+ ResponseConverter <String > responseConverter = ResponseConverterUtils .getString ();
105+ return createServiceCall (builder .build (), responseConverter );
106+ }
107+
108+ /**
109+ * Retrieve KUBECONFIG for a specified project.
110+ *
111+ * Returns the KUBECONFIG, similar to the output of `kubectl config view --minify=true`. There are 2 tokens in the
112+ * Request Header and a query parameter that you must provide.
113+ * These values can be generated as follows: 1. Auth Header Pass the generated IAM Token as the Authorization header
114+ * from the CLI as `token=cat $HOME/.bluemix/config.json | jq .IAMToken -r`. Generate the token with the [Create an
115+ * IAM access token for a user or service ID using an API
116+ * key](https://cloud.ibm.com/apidocs/iam-identity-token-api#gettoken-apikey) API.
117+ *
118+ * 2. X-Delegated-Refresh-Token Header Generate an IAM Delegated Refresh Token for Code Engine with the [Create an IAM
119+ * access token and delegated refresh token for a user or service
120+ * ID](https://cloud.ibm.com/apidocs/iam-identity-token-api#gettoken-apikey-delegatedrefreshtoken) API. Specify the
121+ * `receiver_client_ids` value to be `ce` and the `delegated_refresh_token_expiry` value to be `3600`.
122+ *
123+ * 3. Project ID In order to retrieve the Kubeconfig file for a specific Code Engine project, use the CLI to extract
124+ * the ID
125+ * `id=ibmcloud ce project get -n ${CE_PROJECT_NAME} -o jsonpath={.guid}` You must be logged into the account where
126+ * the project was created to retrieve the ID.
127+ *
128+ * @param getKubeconfigOptions the {@link GetKubeconfigOptions} containing the options for the call
129+ * @return a {@link ServiceCall} with a result of type {@link String}
130+ */
131+ public ServiceCall <String > getKubeconfig (GetKubeconfigOptions getKubeconfigOptions ) {
132+ com .ibm .cloud .sdk .core .util .Validator .notNull (getKubeconfigOptions ,
133+ "getKubeconfigOptions cannot be null" );
134+ Map <String , String > pathParamsMap = new HashMap <String , String >();
135+ pathParamsMap .put ("id" , getKubeconfigOptions .id ());
136+ RequestBuilder builder = RequestBuilder .get (RequestBuilder .resolveRequestUrl (getServiceUrl (), "/project/{id}/config" , pathParamsMap ));
137+ Map <String , String > sdkHeaders = SdkCommon .getSdkHeaders ("ibm_cloud_code_engine" , "v1" , "getKubeconfig" );
138+ for (Entry <String , String > header : sdkHeaders .entrySet ()) {
139+ builder .header (header .getKey (), header .getValue ());
140+ }
141+ builder .header ("X-Delegated-Refresh-Token" , getKubeconfigOptions .xDelegatedRefreshToken ());
142+ if (getKubeconfigOptions .accept () != null ) {
143+ builder .header ("Accept" , getKubeconfigOptions .accept ());
144+ }
100145 ResponseConverter <String > responseConverter = ResponseConverterUtils .getString ();
101146 return createServiceCall (builder .build (), responseConverter );
102147 }
0 commit comments