|
| 1 | +/** |
| 2 | + * (C) Copyright IBM Corp. 2020. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +/** |
| 18 | + * IBM OpenAPI SDK Code Generator Version: 3.12.0-64fe8d3f-20200820-144050 |
| 19 | + */ |
| 20 | + |
| 21 | + |
| 22 | +import * as extend from 'extend'; |
| 23 | +import { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http'; |
| 24 | +import { Authenticator, BaseService, getAuthenticatorFromEnvironment, getMissingParams, UserOptions } from 'ibm-cloud-sdk-core'; |
| 25 | +import { getSdkHeaders } from '../lib/common'; |
| 26 | + |
| 27 | +/** |
| 28 | + * The purpose is to provide an API to get Kubeconfig for IBM Cloud Code Engine Project |
| 29 | + */ |
| 30 | + |
| 31 | +class IbmCloudCodeEngineV1 extends BaseService { |
| 32 | + |
| 33 | + static DEFAULT_SERVICE_URL: string = 'https://ibm-cloud-code-engine.cloud.ibm.com/api/v1'; |
| 34 | + static DEFAULT_SERVICE_NAME: string = 'ibm_cloud_code_engine'; |
| 35 | + |
| 36 | + /************************* |
| 37 | + * Factory method |
| 38 | + ************************/ |
| 39 | + |
| 40 | + /** |
| 41 | + * Constructs an instance of IbmCloudCodeEngineV1 with passed in options and external configuration. |
| 42 | + * |
| 43 | + * @param {UserOptions} [options] - The parameters to send to the service. |
| 44 | + * @param {string} [options.serviceName] - The name of the service to configure |
| 45 | + * @param {Authenticator} [options.authenticator] - The Authenticator object used to authenticate requests to the service |
| 46 | + * @param {string} [options.serviceUrl] - The URL for the service |
| 47 | + * @returns {IbmCloudCodeEngineV1} |
| 48 | + */ |
| 49 | + |
| 50 | + public static newInstance(options: UserOptions): IbmCloudCodeEngineV1 { |
| 51 | + options = options || {}; |
| 52 | + |
| 53 | + if (!options.serviceName) { |
| 54 | + options.serviceName = this.DEFAULT_SERVICE_NAME; |
| 55 | + } |
| 56 | + if (!options.authenticator) { |
| 57 | + options.authenticator = getAuthenticatorFromEnvironment(options.serviceName); |
| 58 | + } |
| 59 | + const service = new IbmCloudCodeEngineV1(options); |
| 60 | + service.configureService(options.serviceName); |
| 61 | + if (options.serviceUrl) { |
| 62 | + service.setServiceUrl(options.serviceUrl); |
| 63 | + } |
| 64 | + return service; |
| 65 | + } |
| 66 | + |
| 67 | + |
| 68 | + /** |
| 69 | + * Construct a IbmCloudCodeEngineV1 object. |
| 70 | + * |
| 71 | + * @param {Object} options - Options for the service. |
| 72 | + * @param {string} [options.serviceUrl] - The base url to use when contacting the service (e.g. 'https://gateway.watsonplatform.net/api/v1'). The base url may differ between IBM Cloud regions. |
| 73 | + * @param {OutgoingHttpHeaders} [options.headers] - Default headers that shall be included with every request to the service. |
| 74 | + * @param {Authenticator} options.authenticator - The Authenticator object used to authenticate requests to the service |
| 75 | + * @constructor |
| 76 | + * @returns {IbmCloudCodeEngineV1} |
| 77 | + */ |
| 78 | + constructor(options: UserOptions) { |
| 79 | + options = options || {}; |
| 80 | + |
| 81 | + super(options); |
| 82 | + if (options.serviceUrl) { |
| 83 | + this.setServiceUrl(options.serviceUrl); |
| 84 | + } else { |
| 85 | + this.setServiceUrl(IbmCloudCodeEngineV1.DEFAULT_SERVICE_URL); |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + /************************* |
| 90 | + * getKubeconfig |
| 91 | + ************************/ |
| 92 | + |
| 93 | + /** |
| 94 | + * Retrieve KUBECONFIG for a specified project. |
| 95 | + * |
| 96 | + * Returns the KUBECONFIG, similar to the output of `kubectl config view --minify=true`. |
| 97 | + * |
| 98 | + * @param {Object} params - The parameters to send to the service. |
| 99 | + * @param {string} params.refreshToken - The IAM Refresh token associated with the IBM Cloud account. |
| 100 | + * @param {string} params.id - The id of the IBM Cloud Code Engine project. |
| 101 | + * @param {string} [params.accept] - The type of the response: application/json or text/html. A character encoding can |
| 102 | + * be specified by including a `charset` parameter. For example, 'text/html;charset=utf-8'. |
| 103 | + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers |
| 104 | + * @returns {Promise<IbmCloudCodeEngineV1.Response<IbmCloudCodeEngineV1.Empty>>} |
| 105 | + */ |
| 106 | + public listKubeconfig(params: IbmCloudCodeEngineV1.ListKubeconfigParams): Promise<IbmCloudCodeEngineV1.Response<IbmCloudCodeEngineV1.Empty>> { |
| 107 | + const _params = Object.assign({}, params); |
| 108 | + const requiredParams = ['refreshToken', 'id']; |
| 109 | + |
| 110 | + return new Promise((resolve, reject) => { |
| 111 | + const missingParams = getMissingParams(_params, requiredParams); |
| 112 | + if (missingParams) { |
| 113 | + return reject(missingParams); |
| 114 | + } |
| 115 | + |
| 116 | + const path = { |
| 117 | + 'id': _params.id |
| 118 | + }; |
| 119 | + |
| 120 | + const sdkHeaders = getSdkHeaders(IbmCloudCodeEngineV1.DEFAULT_SERVICE_NAME, 'v1', 'listKubeconfig'); |
| 121 | + |
| 122 | + const parameters = { |
| 123 | + options: { |
| 124 | + url: '/namespaces/{id}/config', |
| 125 | + method: 'GET', |
| 126 | + path, |
| 127 | + }, |
| 128 | + defaultOptions: extend(true, {}, this.baseOptions, { |
| 129 | + headers: extend(true, sdkHeaders, { |
| 130 | + 'Refresh-Token': _params.refreshToken, |
| 131 | + 'Accept': _params.accept |
| 132 | + }, _params.headers), |
| 133 | + }), |
| 134 | + }; |
| 135 | + |
| 136 | + return resolve(this.createRequest(parameters)); |
| 137 | + }); |
| 138 | + }; |
| 139 | + |
| 140 | +} |
| 141 | + |
| 142 | +/************************* |
| 143 | + * interfaces |
| 144 | + ************************/ |
| 145 | + |
| 146 | +namespace IbmCloudCodeEngineV1 { |
| 147 | + |
| 148 | + /** An operation response. */ |
| 149 | + export interface Response<T = any> { |
| 150 | + result: T; |
| 151 | + status: number; |
| 152 | + statusText: string; |
| 153 | + headers: IncomingHttpHeaders; |
| 154 | + } |
| 155 | + |
| 156 | + /** The callback for a service request. */ |
| 157 | + export type Callback<T> = (error: any, response?: Response<T>) => void; |
| 158 | + |
| 159 | + /** The body of a service request that returns no response data. */ |
| 160 | + export interface Empty { } |
| 161 | + |
| 162 | + /** A standard JS object, defined to avoid the limitations of `Object` and `object` */ |
| 163 | + export interface JsonObject { |
| 164 | + [key: string]: any; |
| 165 | + } |
| 166 | + |
| 167 | + /************************* |
| 168 | + * request interfaces |
| 169 | + ************************/ |
| 170 | + |
| 171 | + /** Parameters for the `listKubeconfig` operation. */ |
| 172 | + export interface ListKubeconfigParams { |
| 173 | + /** The IAM Refresh token associated with the IBM Cloud account. */ |
| 174 | + refreshToken: string; |
| 175 | + /** The id of the IBM Cloud Code Engine project. */ |
| 176 | + id: string; |
| 177 | + /** The type of the response: application/json or text/html. A character encoding can be specified by including |
| 178 | + * a `charset` parameter. For example, 'text/html;charset=utf-8'. |
| 179 | + */ |
| 180 | + accept?: ListKubeconfigConstants.Accept | string; |
| 181 | + headers?: OutgoingHttpHeaders; |
| 182 | + } |
| 183 | + |
| 184 | + /** Constants for the `listKubeconfig` operation. */ |
| 185 | + export namespace ListKubeconfigConstants { |
| 186 | + /** The type of the response: application/json or text/html. A character encoding can be specified by including a `charset` parameter. For example, 'text/html;charset=utf-8'. */ |
| 187 | + export enum Accept { |
| 188 | + APPLICATION_JSON = 'application/json', |
| 189 | + TEXT_HTML = 'text/html', |
| 190 | + } |
| 191 | + } |
| 192 | + |
| 193 | + /************************* |
| 194 | + * model interfaces |
| 195 | + ************************/ |
| 196 | + |
| 197 | +} |
| 198 | + |
| 199 | +export = IbmCloudCodeEngineV1; |
0 commit comments