diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 14a9d19..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,40 +0,0 @@ -## [0.1.5](https://github.com/IBM/code-engine-node-sdk/compare/v0.1.4...v0.1.5) (2021-09-07) - - -### Bug Fixes - -* **build:** fixed integration test execution ([bb6a0e1](https://github.com/IBM/code-engine-node-sdk/commit/bb6a0e1a33b25dcbf22557f5f2a893e00d2332d3)) - -## [0.1.4](https://github.com/IBM/code-engine-node-sdk/compare/v0.1.3...v0.1.4) (2021-09-07) - - -### Bug Fixes - -* **build:** remove reference to example ([e9b4740](https://github.com/IBM/code-engine-node-sdk/commit/e9b47404205ef7429d4b49b66602c388d8f1347c)) - -## [0.1.3](https://github.com/IBM/code-engine-node-sdk/compare/v0.1.2...v0.1.3) (2021-09-07) - - -### Bug Fixes - -* **build:** exclude example directory from npm module ([797481e](https://github.com/IBM/code-engine-node-sdk/commit/797481e163e563ca62832150f5839c7878a31be0)) -* **build:** remove dry-run flag ([08921d9](https://github.com/IBM/code-engine-node-sdk/commit/08921d9c47b0ea917caf8c78954d55d65ff4134c)) -* **build:** updated publish configuration ([d1645bd](https://github.com/IBM/code-engine-node-sdk/commit/d1645bd7f987786072b915f8f411732c3fa64dca)) - -## [0.1.2](https://github.com/IBM/code-engine-node-sdk/compare/v0.1.1...v0.1.2) (2021-09-07) - - -### Bug Fixes - -* **build:** remove dry-run flag to enable npm publish ([3cd56ab](https://github.com/IBM/code-engine-node-sdk/commit/3cd56ab3b209b241415074f989d0f2f38466b335)) - -## [0.1.1](https://github.com/IBM/code-engine-node-sdk/compare/v0.1.0...v0.1.1) (2021-09-07) - - -### Bug Fixes - -* **build:** added coverage badge ([8fc995e](https://github.com/IBM/code-engine-node-sdk/commit/8fc995e0f943c9e9e80f55e1eba962ee7a14d3d2)) -* **build:** check husky ([7767ee0](https://github.com/IBM/code-engine-node-sdk/commit/7767ee0b3703f489d0f111d5e97f316dbcdb0061)) -* **build:** enable semantic-releases ([90fbf80](https://github.com/IBM/code-engine-node-sdk/commit/90fbf80764e2e92d3eeb043778400cc6057174c4)) -* **build:** fixed pre-push hook ([cdfb3f2](https://github.com/IBM/code-engine-node-sdk/commit/cdfb3f2986d255473dada2ba0237a5220ad898d9)) -* activated semantic releases ([8205efd](https://github.com/IBM/code-engine-node-sdk/commit/8205efd0a7a768b5ee5f9d08f201879327175564)) diff --git a/code-engine/v2.ts b/code-engine/v2.ts index fef62a1..7c32e78 100644 --- a/code-engine/v2.ts +++ b/code-engine/v2.ts @@ -15,7 +15,7 @@ */ /** - * IBM OpenAPI SDK Code Generator Version: 3.66.0-d6c2d7e0-20230215-221247 + * IBM OpenAPI SDK Code Generator Version: 3.72.2-2bede9d2-20230601-202845 */ /* eslint-disable max-classes-per-file */ @@ -301,7 +301,9 @@ class CodeEngineV2 extends BaseService { /** * List egress IP addresses. * - * Lists all egress IP addresses (public and private) that are used by components running in this project. + * Lists all egress IP addresses (public and private) that are used by components running in this project. For + * information about using egress IP addresses, see [Code Engine public and private IP + * addresses](https://cloud.ibm.com/docs/codeengine?topic=codeengine-network-addresses). * * @param {Object} params - The parameters to send to the service. * @param {string} params.projectId - The ID of the project. @@ -349,6 +351,58 @@ class CodeEngineV2 extends BaseService { return this.createRequest(parameters); } + + /** + * Get the status details for a project. + * + * Retrieves status details about the given project. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.projectId - The ID of the project. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public getProjectStatusDetails( + params: CodeEngineV2.GetProjectStatusDetailsParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['projectId']; + const _validParams = ['projectId', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const path = { + 'project_id': _params.projectId, + }; + + const sdkHeaders = getSdkHeaders( + CodeEngineV2.DEFAULT_SERVICE_NAME, + 'v2', + 'getProjectStatusDetails' + ); + + const parameters = { + options: { + url: '/projects/{project_id}/status_details', + method: 'GET', + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + { + 'Accept': 'application/json', + }, + _params.headers + ), + }), + }; + + return this.createRequest(parameters); + } /************************* * applications ************************/ @@ -418,7 +472,7 @@ class CodeEngineV2 extends BaseService { * * @param {Object} params - The parameters to send to the service. * @param {string} params.projectId - The ID of the project. - * @param {string} params.imageReference - The name of the image that is used for this job. The format is + * @param {string} params.imageReference - The name of the image that is used for this app. The format is * `REGISTRY/NAMESPACE/REPOSITORY:TAG` where `REGISTRY` and `TAG` are optional. If `REGISTRY` is not specified, the * default is `docker.io`. If `TAG` is not specified, the default is `latest`. If the image reference points to a * registry that requires authentication, make sure to also specify the property `image_secret`. @@ -439,8 +493,8 @@ class CodeEngineV2 extends BaseService { * @param {string[]} [params.runCommands] - Optional commands for the app that are passed to start the container. If * not specified an empty string array will be applied and the command specified by the container image, will be used * to start the container. - * @param {EnvVarPrototype[]} [params.runEnvVariables] - Optional references to config maps, secrets or a literal - * values that are exposed as environment variables within the running application. + * @param {EnvVarPrototype[]} [params.runEnvVariables] - Optional references to config maps, secrets or literal values + * that are exposed as environment variables within the running application. * @param {string} [params.runServiceAccount] - Optional name of the service account. For built-in service accounts, * you can use the shortened names `manager` , `none`, `reader`, and `writer`. * @param {VolumeMountPrototype[]} [params.runVolumeMounts] - Optional mounts of config maps or a secrets. @@ -451,6 +505,8 @@ class CodeEngineV2 extends BaseService { * requests. This option defaults to the value of the `scale_concurrency` option, if not specified. * @param {string} [params.scaleCpuLimit] - Optional number of CPU set for the instance of the app. For valid values * see [Supported memory and CPU combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + * @param {number} [params.scaleDownDelay] - Optional amount of time in seconds that delays the scale down behavior + * for an app instance. * @param {string} [params.scaleEphemeralStorageLimit] - Optional amount of ephemeral storage to set for the instance * of the app. The amount specified as ephemeral storage, must not exceed the amount of `scale_memory_limit`. The * units for specifying ephemeral storage are Megabyte (M) or Gigabyte (G), whereas G and M are the shorthand @@ -496,6 +552,7 @@ class CodeEngineV2 extends BaseService { 'scaleConcurrency', 'scaleConcurrencyTarget', 'scaleCpuLimit', + 'scaleDownDelay', 'scaleEphemeralStorageLimit', 'scaleInitialInstances', 'scaleMaxInstances', @@ -524,6 +581,7 @@ class CodeEngineV2 extends BaseService { 'scale_concurrency': _params.scaleConcurrency, 'scale_concurrency_target': _params.scaleConcurrencyTarget, 'scale_cpu_limit': _params.scaleCpuLimit, + 'scale_down_delay': _params.scaleDownDelay, 'scale_ephemeral_storage_limit': _params.scaleEphemeralStorageLimit, 'scale_initial_instances': _params.scaleInitialInstances, 'scale_max_instances': _params.scaleMaxInstances, @@ -669,7 +727,7 @@ class CodeEngineV2 extends BaseService { * to indicate to update any version available. This might result in stale updates. * @param {number} [params.imagePort] - Optional port the app listens on. While the app will always be exposed via * port `443` for end users, this port is used to connect to the port that is exposed by the container image. - * @param {string} [params.imageReference] - The name of the image that is used for this job. The format is + * @param {string} [params.imageReference] - The name of the image that is used for this app. The format is * `REGISTRY/NAMESPACE/REPOSITORY:TAG` where `REGISTRY` and `TAG` are optional. If `REGISTRY` is not specified, the * default is `docker.io`. If `TAG` is not specified, the default is `latest`. If the image reference points to a * registry that requires authentication, make sure to also specify the property `image_secret`. @@ -687,7 +745,7 @@ class CodeEngineV2 extends BaseService { * @param {string[]} [params.runCommands] - Optional commands for the app that are passed to start the container. If * not specified an empty string array will be applied and the command specified by the container image, will be used * to start the container. - * @param {EnvVarPrototype[]} [params.runEnvVariables] - Optional references to config maps, secrets or a literal + * @param {EnvVarPrototype[]} [params.runEnvVariables] - Optional references to config maps, secrets or literal * values. * @param {string} [params.runServiceAccount] - Optional name of the service account. For built-in service accounts, * you can use the shortened names `manager` , `none`, `reader`, and `writer`. @@ -700,6 +758,8 @@ class CodeEngineV2 extends BaseService { * requests. This option defaults to the value of the `scale_concurrency` option, if not specified. * @param {string} [params.scaleCpuLimit] - Optional number of CPU set for the instance of the app. For valid values * see [Supported memory and CPU combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). + * @param {number} [params.scaleDownDelay] - Optional amount of time in seconds that delays the scale down behavior + * for an app instance. * @param {string} [params.scaleEphemeralStorageLimit] - Optional amount of ephemeral storage to set for the instance * of the app. The amount specified as ephemeral storage, must not exceed the amount of `scale_memory_limit`. The * units for specifying ephemeral storage are Megabyte (M) or Gigabyte (G), whereas G and M are the shorthand @@ -746,6 +806,7 @@ class CodeEngineV2 extends BaseService { 'scaleConcurrency', 'scaleConcurrencyTarget', 'scaleCpuLimit', + 'scaleDownDelay', 'scaleEphemeralStorageLimit', 'scaleInitialInstances', 'scaleMaxInstances', @@ -773,6 +834,7 @@ class CodeEngineV2 extends BaseService { 'scale_concurrency': _params.scaleConcurrency, 'scale_concurrency_target': _params.scaleConcurrencyTarget, 'scale_cpu_limit': _params.scaleCpuLimit, + 'scale_down_delay': _params.scaleDownDelay, 'scale_ephemeral_storage_limit': _params.scaleEphemeralStorageLimit, 'scale_initial_instances': _params.scaleInitialInstances, 'scale_max_instances': _params.scaleMaxInstances, @@ -1050,11 +1112,11 @@ class CodeEngineV2 extends BaseService { * @param {string[]} [params.runArguments] - Set arguments for the job that are passed to start job run containers. If * not specified an empty string array will be applied and the arguments specified by the container image, will be * used to start the container. - * @param {number} [params.runAsUser] - The user ID (UID) to run the application (e.g., 1001). + * @param {number} [params.runAsUser] - The user ID (UID) to run the job (e.g., 1001). * @param {string[]} [params.runCommands] - Set commands for the job that are passed to start job run containers. If * not specified an empty string array will be applied and the command specified by the container image, will be used * to start the container. - * @param {EnvVarPrototype[]} [params.runEnvVariables] - Optional references to config maps, secrets or a literal + * @param {EnvVarPrototype[]} [params.runEnvVariables] - Optional references to config maps, secrets or literal * values. * @param {string} [params.runMode] - The mode for runs of the job. Valid values are `task` and `daemon`. In `task` * mode, the `max_execution_time` and `retry_limit` properties apply. In `daemon` mode, since there is no timeout and @@ -1281,11 +1343,11 @@ class CodeEngineV2 extends BaseService { * @param {string[]} [params.runArguments] - Set arguments for the job that are passed to start job run containers. If * not specified an empty string array will be applied and the arguments specified by the container image, will be * used to start the container. - * @param {number} [params.runAsUser] - The user ID (UID) to run the application (e.g., 1001). + * @param {number} [params.runAsUser] - The user ID (UID) to run the job (e.g., 1001). * @param {string[]} [params.runCommands] - Set commands for the job that are passed to start job run containers. If * not specified an empty string array will be applied and the command specified by the container image, will be used * to start the container. - * @param {EnvVarPrototype[]} [params.runEnvVariables] - Optional references to config maps, secrets or a literal + * @param {EnvVarPrototype[]} [params.runEnvVariables] - Optional references to config maps, secrets or literal * values. * @param {string} [params.runMode] - The mode for runs of the job. Valid values are `task` and `daemon`. In `task` * mode, the `max_execution_time` and `retry_limit` properties apply. In `daemon` mode, since there is no timeout and @@ -1481,11 +1543,11 @@ class CodeEngineV2 extends BaseService { * @param {string[]} [params.runArguments] - Set arguments for the job that are passed to start job run containers. If * not specified an empty string array will be applied and the arguments specified by the container image, will be * used to start the container. - * @param {number} [params.runAsUser] - The user ID (UID) to run the application (e.g., 1001). + * @param {number} [params.runAsUser] - The user ID (UID) to run the job (e.g., 1001). * @param {string[]} [params.runCommands] - Set commands for the job that are passed to start job run containers. If * not specified an empty string array will be applied and the command specified by the container image, will be used * to start the container. - * @param {EnvVarPrototype[]} [params.runEnvVariables] - Optional references to config maps, secrets or a literal + * @param {EnvVarPrototype[]} [params.runEnvVariables] - Optional references to config maps, secrets or literal * values. * @param {string} [params.runMode] - The mode for runs of the job. Valid values are `task` and `daemon`. In `task` * mode, the `max_execution_time` and `retry_limit` properties apply. In `daemon` mode, since there is no timeout and @@ -1690,6 +1752,222 @@ class CodeEngineV2 extends BaseService { return this.createRequest(parameters); } + /************************* + * serviceBindings + ************************/ + + /** + * List bindings. + * + * List all bindings in a project. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.projectId - The ID of the project. + * @param {number} [params.limit] - Optional maximum number of bindings per page. + * @param {string} [params.start] - An optional token that indicates the beginning of the page of results to be + * returned. If omitted, the first page of results is returned. This value is obtained from the 'start' query + * parameter in the 'next_url' field of the operation response. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public listBindings( + params: CodeEngineV2.ListBindingsParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['projectId']; + const _validParams = ['projectId', 'limit', 'start', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const query = { + 'limit': _params.limit, + 'start': _params.start, + }; + + const path = { + 'project_id': _params.projectId, + }; + + const sdkHeaders = getSdkHeaders(CodeEngineV2.DEFAULT_SERVICE_NAME, 'v2', 'listBindings'); + + const parameters = { + options: { + url: '/projects/{project_id}/bindings', + method: 'GET', + qs: query, + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + { + 'Accept': 'application/json', + }, + _params.headers + ), + }), + }; + + return this.createRequest(parameters); + } + + /** + * Create a binding. + * + * Create a binding. Creating a service binding with a Code Engine app will update the app, creating a new revision. + * For more information see the + * [documentaion](https://cloud.ibm.com/docs/codeengine?topic=codeengine-service-binding). + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.projectId - The ID of the project. + * @param {ComponentRef} params.component - A reference to another component. + * @param {string} params.prefix - Optional value that is set as prefix in the component that is bound. Will be + * generated if not provided. + * @param {string} params.secretName - The service access secret that is binding to a component. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public createBinding( + params: CodeEngineV2.CreateBindingParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['projectId', 'component', 'prefix', 'secretName']; + const _validParams = ['projectId', 'component', 'prefix', 'secretName', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const body = { + 'component': _params.component, + 'prefix': _params.prefix, + 'secret_name': _params.secretName, + }; + + const path = { + 'project_id': _params.projectId, + }; + + const sdkHeaders = getSdkHeaders(CodeEngineV2.DEFAULT_SERVICE_NAME, 'v2', 'createBinding'); + + const parameters = { + options: { + url: '/projects/{project_id}/bindings', + method: 'POST', + body, + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + }, + _params.headers + ), + }), + }; + + return this.createRequest(parameters); + } + + /** + * Get a binding. + * + * Display the details of a binding. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.projectId - The ID of the project. + * @param {string} params.id - The id of your binding. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public getBinding( + params: CodeEngineV2.GetBindingParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['projectId', 'id']; + const _validParams = ['projectId', 'id', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const path = { + 'project_id': _params.projectId, + 'id': _params.id, + }; + + const sdkHeaders = getSdkHeaders(CodeEngineV2.DEFAULT_SERVICE_NAME, 'v2', 'getBinding'); + + const parameters = { + options: { + url: '/projects/{project_id}/bindings/{id}', + method: 'GET', + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend( + true, + sdkHeaders, + { + 'Accept': 'application/json', + }, + _params.headers + ), + }), + }; + + return this.createRequest(parameters); + } + + /** + * Delete a binding. + * + * Delete a binding. + * + * @param {Object} params - The parameters to send to the service. + * @param {string} params.projectId - The ID of the project. + * @param {string} params.id - The id of your binding. + * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers + * @returns {Promise>} + */ + public deleteBinding( + params: CodeEngineV2.DeleteBindingParams + ): Promise> { + const _params = { ...params }; + const _requiredParams = ['projectId', 'id']; + const _validParams = ['projectId', 'id', 'headers']; + const _validationErrors = validateParams(_params, _requiredParams, _validParams); + if (_validationErrors) { + return Promise.reject(_validationErrors); + } + + const path = { + 'project_id': _params.projectId, + 'id': _params.id, + }; + + const sdkHeaders = getSdkHeaders(CodeEngineV2.DEFAULT_SERVICE_NAME, 'v2', 'deleteBinding'); + + const parameters = { + options: { + url: '/projects/{project_id}/bindings/{id}', + method: 'DELETE', + path, + }, + defaultOptions: extend(true, {}, this.baseOptions, { + headers: extend(true, sdkHeaders, {}, _params.headers), + }), + }; + + return this.createRequest(parameters); + } /************************* * builds ************************/ @@ -1761,11 +2039,6 @@ class CodeEngineV2 extends BaseService { * @param {string} params.outputImage - The name of the image. * @param {string} params.outputSecret - The secret that is required to access the image registry. Make sure that the * secret is granted with push permissions towards the specified container registry namespace. - * @param {string} params.sourceUrl - The URL of the code repository. This field is required if the `source_type` is - * `git`. If the `source_type` value is `local`, this field must be omitted. If the repository is publicly available - * you can provide a 'https' URL like `https://github.com/IBM/CodeEngine`. If the repository requires authentication, - * you need to provide a 'ssh' URL like `git@github.com:IBM/CodeEngine.git` along with a `source_secret` that points - * to a secret of format `ssh_auth`. * @param {string} params.strategyType - The strategy to use for building the image. * @param {string} [params.sourceContextDir] - Option directory in the repository that contains the buildpacks file or * the Dockerfile. @@ -1780,6 +2053,11 @@ class CodeEngineV2 extends BaseService { * repository or based on local source code. * * local - For builds from local source code. * * git - For builds from git version controlled source code. + * @param {string} [params.sourceUrl] - The URL of the code repository. This field is required if the `source_type` is + * `git`. If the `source_type` value is `local`, this field must be omitted. If the repository is publicly available + * you can provide a 'https' URL like `https://github.com/IBM/CodeEngine`. If the repository requires authentication, + * you need to provide a 'ssh' URL like `git@github.com:IBM/CodeEngine.git` along with a `source_secret` that points + * to a secret of format `ssh_auth`. * @param {string} [params.strategySize] - Optional size for the build, which determines the amount of resources used. * Build sizes are `small`, `medium`, `large`, `xlarge`. * @param {string} [params.strategySpecFile] - Optional path to the specification file that is used for build @@ -1793,25 +2071,18 @@ class CodeEngineV2 extends BaseService { params: CodeEngineV2.CreateBuildParams ): Promise> { const _params = { ...params }; - const _requiredParams = [ - 'projectId', - 'name', - 'outputImage', - 'outputSecret', - 'sourceUrl', - 'strategyType', - ]; + const _requiredParams = ['projectId', 'name', 'outputImage', 'outputSecret', 'strategyType']; const _validParams = [ 'projectId', 'name', 'outputImage', 'outputSecret', - 'sourceUrl', 'strategyType', 'sourceContextDir', 'sourceRevision', 'sourceSecret', 'sourceType', + 'sourceUrl', 'strategySize', 'strategySpecFile', 'timeout', @@ -1826,12 +2097,12 @@ class CodeEngineV2 extends BaseService { 'name': _params.name, 'output_image': _params.outputImage, 'output_secret': _params.outputSecret, - 'source_url': _params.sourceUrl, 'strategy_type': _params.strategyType, 'source_context_dir': _params.sourceContextDir, 'source_revision': _params.sourceRevision, 'source_secret': _params.sourceSecret, 'source_type': _params.sourceType, + 'source_url': _params.sourceUrl, 'strategy_size': _params.strategySize, 'strategy_spec_file': _params.strategySpecFile, 'timeout': _params.timeout, @@ -2688,12 +2959,15 @@ class CodeEngineV2 extends BaseService { * * @param {Object} params - The parameters to send to the service. * @param {string} params.projectId - The ID of the project. - * @param {string} params.format - Specify the format of the secret. + * @param {string} params.format - Specify the format of the secret. The format of the secret will determine how the + * secret is used. * @param {string} params.name - The name of the secret. * @param {SecretData} [params.data] - Data container that allows to specify config parameters and their values as a * key-value map. Each key field must consist of alphanumeric characters, `-`, `_` or `.` and must not be exceed a max * length of 253 characters. Each value field can consists of any character and must not be exceed a max length of * 1048576 characters. + * @param {ServiceAccessSecretPrototypeProps} [params.serviceAccess] - Properties for Service Access Secret + * Prototypes. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise>} */ @@ -2702,7 +2976,7 @@ class CodeEngineV2 extends BaseService { ): Promise> { const _params = { ...params }; const _requiredParams = ['projectId', 'format', 'name']; - const _validParams = ['projectId', 'format', 'name', 'data', 'headers']; + const _validParams = ['projectId', 'format', 'name', 'data', 'serviceAccess', 'headers']; const _validationErrors = validateParams(_params, _requiredParams, _validParams); if (_validationErrors) { return Promise.reject(_validationErrors); @@ -2712,6 +2986,7 @@ class CodeEngineV2 extends BaseService { 'format': _params.format, 'name': _params.name, 'data': _params.data, + 'service_access': _params.serviceAccess, }; const path = { @@ -2804,11 +3079,12 @@ class CodeEngineV2 extends BaseService { * @param {string} params.ifMatch - Version of the secret settings to be updated. Specify the version that you * retrieved as entity_tag (ETag header) when reading the secret. This value helps identifying parallel usage of this * API. Pass * to indicate to update any version available. This might result in stale updates. + * @param {string} params.format - Specify the format of the secret. The format of the secret will determine how the + * secret is used. * @param {SecretData} [params.data] - Data container that allows to specify config parameters and their values as a * key-value map. Each key field must consist of alphanumeric characters, `-`, `_` or `.` and must not be exceed a max * length of 253 characters. Each value field can consists of any character and must not be exceed a max length of * 1048576 characters. - * @param {string} [params.format] - Specify the format of the secret. * @param {OutgoingHttpHeaders} [params.headers] - Custom request headers * @returns {Promise>} */ @@ -2816,16 +3092,16 @@ class CodeEngineV2 extends BaseService { params: CodeEngineV2.ReplaceSecretParams ): Promise> { const _params = { ...params }; - const _requiredParams = ['projectId', 'name', 'ifMatch']; - const _validParams = ['projectId', 'name', 'ifMatch', 'data', 'format', 'headers']; + const _requiredParams = ['projectId', 'name', 'ifMatch', 'format']; + const _validParams = ['projectId', 'name', 'ifMatch', 'format', 'data', 'headers']; const _validationErrors = validateParams(_params, _requiredParams, _validParams); if (_validationErrors) { return Promise.reject(_validationErrors); } const body = { - 'data': _params.data, 'format': _params.format, + 'data': _params.data, }; const path = { @@ -2980,6 +3256,13 @@ namespace CodeEngineV2 { headers?: OutgoingHttpHeaders; } + /** Parameters for the `getProjectStatusDetails` operation. */ + export interface GetProjectStatusDetailsParams { + /** The ID of the project. */ + projectId: string; + headers?: OutgoingHttpHeaders; + } + /** Parameters for the `listApps` operation. */ export interface ListAppsParams { /** The ID of the project. */ @@ -2998,7 +3281,7 @@ namespace CodeEngineV2 { export interface CreateAppParams { /** The ID of the project. */ projectId: string; - /** The name of the image that is used for this job. The format is `REGISTRY/NAMESPACE/REPOSITORY:TAG` where + /** The name of the image that is used for this app. The format is `REGISTRY/NAMESPACE/REPOSITORY:TAG` where * `REGISTRY` and `TAG` are optional. If `REGISTRY` is not specified, the default is `docker.io`. If `TAG` is not * specified, the default is `latest`. If the image reference points to a registry that requires authentication, * make sure to also specify the property `image_secret`. @@ -3031,7 +3314,7 @@ namespace CodeEngineV2 { * will be applied and the command specified by the container image, will be used to start the container. */ runCommands?: string[]; - /** Optional references to config maps, secrets or a literal values that are exposed as environment variables + /** Optional references to config maps, secrets or literal values that are exposed as environment variables * within the running application. */ runEnvVariables?: EnvVarPrototype[]; @@ -3052,6 +3335,8 @@ namespace CodeEngineV2 { * combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). */ scaleCpuLimit?: string; + /** Optional amount of time in seconds that delays the scale down behavior for an app instance. */ + scaleDownDelay?: number; /** Optional amount of ephemeral storage to set for the instance of the app. The amount specified as ephemeral * storage, must not exceed the amount of `scale_memory_limit`. The units for specifying ephemeral storage are * Megabyte (M) or Gigabyte (G), whereas G and M are the shorthand expressions for GB and MB. For more information @@ -3133,7 +3418,7 @@ namespace CodeEngineV2 { * port is used to connect to the port that is exposed by the container image. */ imagePort?: number; - /** The name of the image that is used for this job. The format is `REGISTRY/NAMESPACE/REPOSITORY:TAG` where + /** The name of the image that is used for this app. The format is `REGISTRY/NAMESPACE/REPOSITORY:TAG` where * `REGISTRY` and `TAG` are optional. If `REGISTRY` is not specified, the default is `docker.io`. If `TAG` is not * specified, the default is `latest`. If the image reference points to a registry that requires authentication, * make sure to also specify the property `image_secret`. @@ -3160,7 +3445,7 @@ namespace CodeEngineV2 { * will be applied and the command specified by the container image, will be used to start the container. */ runCommands?: string[]; - /** Optional references to config maps, secrets or a literal values. */ + /** Optional references to config maps, secrets or literal values. */ runEnvVariables?: EnvVarPrototype[]; /** Optional name of the service account. For built-in service accounts, you can use the shortened names * `manager` , `none`, `reader`, and `writer`. @@ -3181,6 +3466,8 @@ namespace CodeEngineV2 { * combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). */ scaleCpuLimit?: string; + /** Optional amount of time in seconds that delays the scale down behavior for an app instance. */ + scaleDownDelay?: number; /** Optional amount of ephemeral storage to set for the instance of the app. The amount specified as ephemeral * storage, must not exceed the amount of `scale_memory_limit`. The units for specifying ephemeral storage are * Megabyte (M) or Gigabyte (G), whereas G and M are the shorthand expressions for GB and MB. For more information @@ -3303,13 +3590,13 @@ namespace CodeEngineV2 { * array will be applied and the arguments specified by the container image, will be used to start the container. */ runArguments?: string[]; - /** The user ID (UID) to run the application (e.g., 1001). */ + /** The user ID (UID) to run the job (e.g., 1001). */ runAsUser?: number; /** Set commands for the job that are passed to start job run containers. If not specified an empty string array * will be applied and the command specified by the container image, will be used to start the container. */ runCommands?: string[]; - /** Optional references to config maps, secrets or a literal values. */ + /** Optional references to config maps, secrets or literal values. */ runEnvVariables?: EnvVarPrototype[]; /** The mode for runs of the job. Valid values are `task` and `daemon`. In `task` mode, the `max_execution_time` * and `retry_limit` properties apply. In `daemon` mode, since there is no timeout and failed instances are @@ -3418,13 +3705,13 @@ namespace CodeEngineV2 { * array will be applied and the arguments specified by the container image, will be used to start the container. */ runArguments?: string[]; - /** The user ID (UID) to run the application (e.g., 1001). */ + /** The user ID (UID) to run the job (e.g., 1001). */ runAsUser?: number; /** Set commands for the job that are passed to start job run containers. If not specified an empty string array * will be applied and the command specified by the container image, will be used to start the container. */ runCommands?: string[]; - /** Optional references to config maps, secrets or a literal values. */ + /** Optional references to config maps, secrets or literal values. */ runEnvVariables?: EnvVarPrototype[]; /** The mode for runs of the job. Valid values are `task` and `daemon`. In `task` mode, the `max_execution_time` * and `retry_limit` properties apply. In `daemon` mode, since there is no timeout and failed instances are @@ -3532,13 +3819,13 @@ namespace CodeEngineV2 { * array will be applied and the arguments specified by the container image, will be used to start the container. */ runArguments?: string[]; - /** The user ID (UID) to run the application (e.g., 1001). */ + /** The user ID (UID) to run the job (e.g., 1001). */ runAsUser?: number; /** Set commands for the job that are passed to start job run containers. If not specified an empty string array * will be applied and the command specified by the container image, will be used to start the container. */ runCommands?: string[]; - /** Optional references to config maps, secrets or a literal values. */ + /** Optional references to config maps, secrets or literal values. */ runEnvVariables?: EnvVarPrototype[]; /** The mode for runs of the job. Valid values are `task` and `daemon`. In `task` mode, the `max_execution_time` * and `retry_limit` properties apply. In `daemon` mode, since there is no timeout and failed instances are @@ -3620,6 +3907,51 @@ namespace CodeEngineV2 { headers?: OutgoingHttpHeaders; } + /** Parameters for the `listBindings` operation. */ + export interface ListBindingsParams { + /** The ID of the project. */ + projectId: string; + /** Optional maximum number of bindings per page. */ + limit?: number; + /** An optional token that indicates the beginning of the page of results to be returned. If omitted, the first + * page of results is returned. This value is obtained from the 'start' query parameter in the 'next_url' field of + * the operation response. + */ + start?: string; + headers?: OutgoingHttpHeaders; + } + + /** Parameters for the `createBinding` operation. */ + export interface CreateBindingParams { + /** The ID of the project. */ + projectId: string; + /** A reference to another component. */ + component: ComponentRef; + /** Optional value that is set as prefix in the component that is bound. Will be generated if not provided. */ + prefix: string; + /** The service access secret that is binding to a component. */ + secretName: string; + headers?: OutgoingHttpHeaders; + } + + /** Parameters for the `getBinding` operation. */ + export interface GetBindingParams { + /** The ID of the project. */ + projectId: string; + /** The id of your binding. */ + id: string; + headers?: OutgoingHttpHeaders; + } + + /** Parameters for the `deleteBinding` operation. */ + export interface DeleteBindingParams { + /** The ID of the project. */ + projectId: string; + /** The id of your binding. */ + id: string; + headers?: OutgoingHttpHeaders; + } + /** Parameters for the `listBuilds` operation. */ export interface ListBuildsParams { /** The ID of the project. */ @@ -3643,13 +3975,6 @@ namespace CodeEngineV2 { * permissions towards the specified container registry namespace. */ outputSecret: string; - /** The URL of the code repository. This field is required if the `source_type` is `git`. If the `source_type` - * value is `local`, this field must be omitted. If the repository is publicly available you can provide a 'https' - * URL like `https://github.com/IBM/CodeEngine`. If the repository requires authentication, you need to provide a - * 'ssh' URL like `git@github.com:IBM/CodeEngine.git` along with a `source_secret` that points to a secret of - * format `ssh_auth`. - */ - sourceUrl: string; /** The strategy to use for building the image. */ strategyType: string; /** Option directory in the repository that contains the buildpacks file or the Dockerfile. */ @@ -3671,6 +3996,13 @@ namespace CodeEngineV2 { * * git - For builds from git version controlled source code. */ sourceType?: CreateBuildConstants.SourceType | string; + /** The URL of the code repository. This field is required if the `source_type` is `git`. If the `source_type` + * value is `local`, this field must be omitted. If the repository is publicly available you can provide a 'https' + * URL like `https://github.com/IBM/CodeEngine`. If the repository requires authentication, you need to provide a + * 'ssh' URL like `git@github.com:IBM/CodeEngine.git` along with a `source_secret` that points to a secret of + * format `ssh_auth`. + */ + sourceUrl?: string; /** Optional size for the build, which determines the amount of resources used. Build sizes are `small`, * `medium`, `large`, `xlarge`. */ @@ -3968,7 +4300,7 @@ namespace CodeEngineV2 { export interface CreateSecretParams { /** The ID of the project. */ projectId: string; - /** Specify the format of the secret. */ + /** Specify the format of the secret. The format of the secret will determine how the secret is used. */ format: CreateSecretConstants.Format | string; /** The name of the secret. */ name: string; @@ -3977,12 +4309,14 @@ namespace CodeEngineV2 { * Each value field can consists of any character and must not be exceed a max length of 1048576 characters. */ data?: SecretData; + /** Properties for Service Access Secret Prototypes. */ + serviceAccess?: ServiceAccessSecretPrototypeProps; headers?: OutgoingHttpHeaders; } /** Constants for the `createSecret` operation. */ export namespace CreateSecretConstants { - /** Specify the format of the secret. */ + /** Specify the format of the secret. The format of the secret will determine how the secret is used. */ export enum Format { GENERIC = 'generic', SSH_AUTH = 'ssh_auth', @@ -4014,19 +4348,19 @@ namespace CodeEngineV2 { * update any version available. This might result in stale updates. */ ifMatch: string; + /** Specify the format of the secret. The format of the secret will determine how the secret is used. */ + format: ReplaceSecretConstants.Format | string; /** Data container that allows to specify config parameters and their values as a key-value map. Each key field * must consist of alphanumeric characters, `-`, `_` or `.` and must not be exceed a max length of 253 characters. * Each value field can consists of any character and must not be exceed a max length of 1048576 characters. */ data?: SecretData; - /** Specify the format of the secret. */ - format?: ReplaceSecretConstants.Format | string; headers?: OutgoingHttpHeaders; } /** Constants for the `replaceSecret` operation. */ export namespace ReplaceSecretConstants { - /** Specify the format of the secret. */ + /** Specify the format of the secret. The format of the secret will determine how the secret is used. */ export enum Format { GENERIC = 'generic', SSH_AUTH = 'ssh_auth', @@ -4053,9 +4387,9 @@ namespace CodeEngineV2 { /** App is the response model for app resources. */ export interface App { - /** The date when the resource was created. */ + /** The timestamp when the resource was created. */ created_at?: string; - /** Optional URL to invoke app. Depending on visibility this is accessible publicly ot in the private network + /** Optional URL to invoke app. Depending on visibility this is accessible publicly or in the private network * only. Empty in case 'managed_domain_mappings' is set to 'local'. */ endpoint?: string; @@ -4071,7 +4405,7 @@ namespace CodeEngineV2 { * port is used to connect to the port that is exposed by the container image. */ image_port?: number; - /** The name of the image that is used for this job. The format is `REGISTRY/NAMESPACE/REPOSITORY:TAG` where + /** The name of the image that is used for this app. The format is `REGISTRY/NAMESPACE/REPOSITORY:TAG` where * `REGISTRY` and `TAG` are optional. If `REGISTRY` is not specified, the default is `docker.io`. If `TAG` is not * specified, the default is `latest`. If the image reference points to a registry that requires authentication, * make sure to also specify the property `image_secret`. @@ -4104,7 +4438,7 @@ namespace CodeEngineV2 { * will be applied and the command specified by the container image, will be used to start the container. */ run_commands: string[]; - /** References to config maps, secrets or a literal values, which are exposed as environment variables in the + /** References to config maps, secrets or literal values, which are exposed as environment variables in the * application. */ run_env_variables: EnvVar[]; @@ -4125,6 +4459,8 @@ namespace CodeEngineV2 { * combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). */ scale_cpu_limit: string; + /** Optional amount of time in seconds that delays the scale down behavior for an app instance. */ + scale_down_delay?: number; /** Optional amount of ephemeral storage to set for the instance of the app. The amount specified as ephemeral * storage, must not exceed the amount of `scale_memory_limit`. The units for specifying ephemeral storage are * Megabyte (M) or Gigabyte (G), whereas G and M are the shorthand expressions for GB and MB. For more information @@ -4174,7 +4510,7 @@ namespace CodeEngineV2 { export interface AppRevision { /** Name of the associated app. */ app_name?: string; - /** The date when the resource was created. */ + /** The timestamp when the resource was created. */ created_at?: string; /** When you provision a new revision, a URL is created identifying the location of the instance. */ href?: string; @@ -4184,7 +4520,7 @@ namespace CodeEngineV2 { * port is used to connect to the port that is exposed by the container image. */ image_port?: number; - /** The name of the image that is used for this job. The format is `REGISTRY/NAMESPACE/REPOSITORY:TAG` where + /** The name of the image that is used for this app. The format is `REGISTRY/NAMESPACE/REPOSITORY:TAG` where * `REGISTRY` and `TAG` are optional. If `REGISTRY` is not specified, the default is `docker.io`. If `TAG` is not * specified, the default is `latest`. If the image reference points to a registry that requires authentication, * make sure to also specify the property `image_secret`. @@ -4212,7 +4548,7 @@ namespace CodeEngineV2 { * will be applied and the command specified by the container image, will be used to start the container. */ run_commands: string[]; - /** References to config maps, secrets or a literal values, which are exposed as environment variables in the + /** References to config maps, secrets or literal values, which are exposed as environment variables in the * application. */ run_env_variables: EnvVar[]; @@ -4233,6 +4569,8 @@ namespace CodeEngineV2 { * combinations](https://cloud.ibm.com/docs/codeengine?topic=codeengine-mem-cpu-combo). */ scale_cpu_limit: string; + /** Optional amount of time in seconds that delays the scale down behavior for an app instance. */ + scale_down_delay?: number; /** Optional amount of ephemeral storage to set for the instance of the app. The amount specified as ephemeral * storage, must not exceed the amount of `scale_memory_limit`. The units for specifying ephemeral storage are * Megabyte (M) or Gigabyte (G), whereas G and M are the shorthand expressions for GB and MB. For more information @@ -4296,9 +4634,41 @@ namespace CodeEngineV2 { reason?: string; } + /** Describes the model of a binding. */ + export interface Binding { + /** A reference to another component. */ + component: ComponentRef; + /** When you provision a new binding, a URL is created identifying the location of the instance. */ + href?: string; + /** The ID of the binding. */ + id?: string; + /** The value that is set as prefix in the component that is bound. */ + prefix: string; + /** The ID of the project the resource is located in. */ + project_id?: string; + /** The type of the binding. */ + resource_type?: string; + /** The service access secret that is bound to a component. */ + secret_name: string; + /** The current status of the binding. */ + status?: string; + } + + /** Contains a list of bindings and pagination information. */ + export interface BindingList { + /** List of all bindings. */ + bindings: Binding[]; + /** Describes properties needed to retrieve the first page of a result list. */ + first?: ListFirstMetadata; + /** Maximum number of resources per page. */ + limit: number; + /** Describes properties needed to retrieve the next page of a result list. */ + next?: ListNextMetadata; + } + /** Response model for build definitions. */ export interface Build { - /** The date when the resource was created. */ + /** The timestamp when the resource was created. */ created_at?: string; /** The version of the build instance, which is used to achieve optimistic locking. */ entity_tag: string; @@ -4343,7 +4713,7 @@ namespace CodeEngineV2 { * 'ssh' URL like `git@github.com:IBM/CodeEngine.git` along with a `source_secret` that points to a secret of * format `ssh_auth`. */ - source_url: string; + source_url?: string; /** The current status of the build. */ status?: string; /** The detailed status of the build. */ @@ -4379,7 +4749,7 @@ namespace CodeEngineV2 { * `strategy_type`, `source_url`, `output_image` and `output_secret` to describe the build run. */ build_name: string; - /** The date when the resource was created. */ + /** The timestamp when the resource was created. */ created_at?: string; /** When you trigger a new build run, a URL is created identifying the location of the instance. */ href?: string; @@ -4471,9 +4841,17 @@ namespace CodeEngineV2 { reason?: string; } + /** A reference to another component. */ + export interface ComponentRef { + /** The name of the referenced component. */ + name: string; + /** The type of the referenced resource. */ + resource_type: string; + } + /** Describes the model of a configmap. */ export interface ConfigMap { - /** The date when the resource was created. */ + /** The timestamp when the resource was created. */ created_at?: string; /** The key-value pair for the config map. Values must be specified in `KEY=VALUE` format. */ data?: JsonObject; @@ -4537,7 +4915,7 @@ namespace CodeEngineV2 { /** Job is the response model for job resources. */ export interface Job { - /** The date when the resource was created. */ + /** The timestamp when the resource was created. */ created_at?: string; /** The version of the job instance, which is used to achieve optimistic locking. */ entity_tag: string; @@ -4567,14 +4945,14 @@ namespace CodeEngineV2 { * array will be applied and the arguments specified by the container image, will be used to start the container. */ run_arguments: string[]; - /** The user ID (UID) to run the application (e.g., 1001). */ + /** The user ID (UID) to run the job (e.g., 1001). */ run_as_user?: number; /** Set commands for the job that are passed to start job run containers. If not specified an empty string array * will be applied and the command specified by the container image, will be used to start the container. */ run_commands: string[]; - /** References to config maps, secrets or a literal values, which are exposed as environment variables in the - * job run. + /** References to config maps, secrets or literal values, which are exposed as environment variables in the job + * run. */ run_env_variables: EnvVar[]; /** The mode for runs of the job. Valid values are `task` and `daemon`. In `task` mode, the `max_execution_time` @@ -4635,7 +5013,7 @@ namespace CodeEngineV2 { /** Response model for job run resources. */ export interface JobRun { - /** The date when the resource was created. */ + /** The timestamp when the resource was created. */ created_at?: string; /** When you provision a new job run, a URL is created identifying the location of the instance. */ href?: string; @@ -4667,14 +5045,14 @@ namespace CodeEngineV2 { * array will be applied and the arguments specified by the container image, will be used to start the container. */ run_arguments: string[]; - /** The user ID (UID) to run the application (e.g., 1001). */ + /** The user ID (UID) to run the job (e.g., 1001). */ run_as_user?: number; /** Set commands for the job that are passed to start job run containers. If not specified an empty string array * will be applied and the command specified by the container image, will be used to start the container. */ run_commands: string[]; - /** References to config maps, secrets or a literal values, which are exposed as environment variables in the - * job run. + /** References to config maps, secrets or literal values, which are exposed as environment variables in the job + * run. */ run_env_variables: EnvVar[]; /** The mode for runs of the job. Valid values are `task` and `daemon`. In `task` mode, the `max_execution_time` @@ -4775,7 +5153,7 @@ namespace CodeEngineV2 { export interface Project { /** An alphanumeric value identifying the account ID. */ account_id?: string; - /** The date when the project was created. */ + /** The timestamp when the project was created. */ created_at?: string; /** The CRN of the project. */ crn?: string; @@ -4819,9 +5197,45 @@ namespace CodeEngineV2 { projects: Project[]; } + /** Describes the model of a project status details. */ + export interface ProjectStatusDetails { + /** Status of the domain created for the project. */ + domain: string; + /** Defines whether a project is enabled for management and consumption. */ + project: string; + } + + /** The service credential associated with the secret. */ + export interface ResourceKeyRef { + /** ID of the service credential associated with the secret. */ + id?: string; + /** Name of the service credential associated with the secret. */ + name?: string; + } + + /** The service credential associated with the secret. */ + export interface ResourceKeyRefPrototype { + /** ID of the service credential associated with the secret. */ + id?: string; + } + + /** A reference to the Role and Role CRN for service binding. */ + export interface RoleRef { + /** CRN of the IAM Role for thise service access secret. */ + crn?: string; + /** Role of the service credential. */ + name?: string; + } + + /** A reference to the Role and Role CRN for service binding. */ + export interface RoleRefPrototype { + /** CRN of the IAM Role for thise service access secret. */ + crn?: string; + } + /** Describes the model of a secret. */ export interface Secret { - /** The date when the resource was created. */ + /** The timestamp when the resource was created. */ created_at?: string; /** Data container that allows to specify config parameters and their values as a key-value map. Each key field * must consist of alphanumeric characters, `-`, `_` or `.` and must not be exceed a max length of 253 characters. @@ -4842,6 +5256,8 @@ namespace CodeEngineV2 { project_id?: string; /** The type of the secret. */ resource_type?: string; + /** Properties for Service Access Secrets. */ + service_access?: ServiceAccessSecretProps; } /** Data container that allows to specify config parameters and their values as a key-value map. Each key field must consist of alphanumeric characters, `-`, `_` or `.` and must not be exceed a max length of 253 characters. Each value field can consists of any character and must not be exceed a max length of 1048576 characters. */ @@ -4862,6 +5278,50 @@ namespace CodeEngineV2 { secrets: Secret[]; } + /** Properties for Service Access Secrets. */ + export interface ServiceAccessSecretProps { + /** The service credential associated with the secret. */ + resource_key: ResourceKeyRef; + /** A reference to the Role and Role CRN for service binding. */ + role?: RoleRef; + /** The IBM Cloud service instance associated with the secret. */ + service_instance: ServiceInstanceRef; + /** A reference to the Service ID used to the create service credential. */ + serviceid?: ServiceIDRef; + } + + /** Properties for Service Access Secret Prototypes. */ + export interface ServiceAccessSecretPrototypeProps { + /** The service credential associated with the secret. */ + resource_key: ResourceKeyRefPrototype; + /** A reference to the Role and Role CRN for service binding. */ + role?: RoleRefPrototype; + /** The IBM Cloud service instance associated with the secret. */ + service_instance: ServiceInstanceRefPrototype; + /** A reference to the Service ID used to the create service credential. */ + serviceid?: ServiceIDRef; + } + + /** A reference to the Service ID used to the create service credential. */ + export interface ServiceIDRef { + /** CRN value of a Service ID used to create the service credential. */ + crn?: string; + } + + /** The IBM Cloud service instance associated with the secret. */ + export interface ServiceInstanceRef { + /** ID of the IBM Cloud service instance associated with the secret. */ + id?: string; + /** Type of IBM Cloud service associated with the secret. */ + type?: string; + } + + /** The IBM Cloud service instance associated with the secret. */ + export interface ServiceInstanceRefPrototype { + /** ID of the IBM Cloud service instance associated with the secret. */ + id?: string; + } + /** Response model of a volume mount. */ export interface VolumeMount { /** The path that should be mounted. */ @@ -5326,6 +5786,85 @@ namespace CodeEngineV2 { } } + /** + * BindingsPager can be used to simplify the use of listBindings(). + */ + export class BindingsPager { + protected _hasNext: boolean; + + protected pageContext: any; + + protected client: CodeEngineV2; + + protected params: CodeEngineV2.ListBindingsParams; + + /** + * Construct a BindingsPager object. + * + * @param {CodeEngineV2} client - The service client instance used to invoke listBindings() + * @param {Object} params - The parameters to be passed to listBindings() + * @constructor + * @returns {BindingsPager} + */ + constructor(client: CodeEngineV2, params: CodeEngineV2.ListBindingsParams) { + if (params && params.start) { + throw new Error(`the params.start field should not be set`); + } + + this._hasNext = true; + this.pageContext = { next: undefined }; + this.client = client; + this.params = JSON.parse(JSON.stringify(params || {})); + } + + /** + * Returns true if there are potentially more results to be retrieved by invoking getNext(). + * @returns {boolean} + */ + public hasNext(): boolean { + return this._hasNext; + } + + /** + * Returns the next page of results by invoking listBindings(). + * @returns {Promise} + */ + public async getNext(): Promise { + if (!this.hasNext()) { + throw new Error('No more results available'); + } + + if (this.pageContext.next) { + this.params.start = this.pageContext.next; + } + const response = await this.client.listBindings(this.params); + const { result } = response; + + let next = null; + if (result && result.next) { + next = result.next.start; + } + this.pageContext.next = next; + if (!this.pageContext.next) { + this._hasNext = false; + } + return result.bindings; + } + + /** + * Returns all results by invoking listBindings() repeatedly until all pages of results have been retrieved. + * @returns {Promise} + */ + public async getAll(): Promise { + const results: Binding[] = []; + while (this.hasNext()) { + const nextPage = await this.getNext(); + results.push(...nextPage); + } + return results; + } + } + /** * BuildsPager can be used to simplify the use of listBuilds(). */ diff --git a/example/example_deprecated.js b/example/example_deprecated.js deleted file mode 100644 index ae2fa55..0000000 --- a/example/example_deprecated.js +++ /dev/null @@ -1,50 +0,0 @@ -/* eslint-disable no-console */ -/* eslint-disable require-jsdoc */ -/* eslint-disable node/no-unpublished-require */ -const CodeEngineV1 = require('../dist/ibm-cloud-code-engine/v1'); // require('ibm-code-engine-sdk/ibm-cloud-code-engine/v1'); -const { IamAuthenticator } = require('../dist/auth'); // require('ibm-code-engine-sdk/auth'); -const k8s = require('@kubernetes/client-node'); - -if (!process.env.CE_API_KEY || !process.env.CE_PROJECT_ID || !process.env.CE_PROJECT_REGION) { - throw new Error( - 'You must set the envrionment variables CE_API_KEY, CE_PROJECT_REGION and CE_PROJECT_ID before using the example.' - ); -} - -// Create an IAM authenticator. -const authenticator = new IamAuthenticator({ - apikey: process.env.CE_API_KEY, - clientId: 'bx', - clientSecret: 'bx', -}); - -// Construct the Code Engine client using the IAM authenticator. -const ceClient = new CodeEngineV1({ - authenticator, - serviceUrl: `https://api.${process.env.CE_PROJECT_REGION}.codeengine.cloud.ibm.com/api/v1`, -}); - -async function main() { - // Get tokens using the Authenticator. - const tokenResponse = await authenticator.tokenManager.requestToken(); - - // Get Code Engine project config using the Code Engine client. - const configResponse = await ceClient.listKubeconfig({ - refreshToken: tokenResponse.result.refresh_token, - id: process.env.CE_PROJECT_ID, - }); - - // Setup Kubernetes client. - const kubeConfig = new k8s.KubeConfig(); - kubeConfig.loadFromString(configResponse.result); - const kubeClient = kubeConfig.makeApiClient(k8s.CoreV1Api); - - // Get something from project. - const { namespace } = kubeConfig.getCurrentContextObject(); - const configMapList = await kubeClient.listNamespacedConfigMap(namespace); - console.log( - `Project ${process.env.CE_PROJECT_ID} has ${configMapList.body.items.length} configmaps.` - ); -} - -main(); diff --git a/examples/code-engine.v2.test.js b/examples/code-engine.v2.test.js index 5108a62..1bb4382 100644 --- a/examples/code-engine.v2.test.js +++ b/examples/code-engine.v2.test.js @@ -183,6 +183,34 @@ describe('CodeEngineV2', () => { // end-get_project_egress_ips }); + test('getProjectStatusDetails request example', async () => { + consoleLogMock.mockImplementation((output) => { + originalLog(output); + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + }); + + originalLog('getProjectStatusDetails() result:'); + // begin-get_project_status_details + + const params = { + projectId: '15314cc3-85b4-4338-903f-c28cdee6d005', + }; + + let res; + try { + res = await codeEngineService.getProjectStatusDetails(params); + console.log(JSON.stringify(res.result, null, 2)); + } catch (err) { + console.warn(err); + } + + // end-get_project_status_details + }); + test('listApps request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); @@ -586,6 +614,108 @@ describe('CodeEngineV2', () => { // end-get_job_run }); + test('listBindings request example', async () => { + consoleLogMock.mockImplementation((output) => { + originalLog(output); + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + }); + + originalLog('listBindings() result:'); + // begin-list_bindings + + const params = { + projectId: '15314cc3-85b4-4338-903f-c28cdee6d005', + limit: 100, + }; + + const allResults = []; + try { + const pager = new CodeEngineV2.BindingsPager(codeEngineService, params); + while (pager.hasNext()) { + const nextPage = await pager.getNext(); + expect(nextPage).not.toBeNull(); + allResults.push(...nextPage); + } + console.log(JSON.stringify(allResults, null, 2)); + } catch (err) { + console.warn(err); + } + + // end-list_bindings + }); + + test('createBinding request example', async () => { + consoleLogMock.mockImplementation((output) => { + originalLog(output); + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + }); + + originalLog('createBinding() result:'); + // begin-create_binding + + // Request models needed by this operation. + + // ComponentRef + const componentRefModel = { + name: 'my-app-1', + resource_type: 'app_v2', + }; + + const params = { + projectId: '15314cc3-85b4-4338-903f-c28cdee6d005', + component: componentRefModel, + prefix: 'MY_COS', + secretName: 'my-service-access', + }; + + let res; + try { + res = await codeEngineService.createBinding(params); + console.log(JSON.stringify(res.result, null, 2)); + } catch (err) { + console.warn(err); + } + + // end-create_binding + }); + + test('getBinding request example', async () => { + consoleLogMock.mockImplementation((output) => { + originalLog(output); + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + }); + + originalLog('getBinding() result:'); + // begin-get_binding + + const params = { + projectId: '15314cc3-85b4-4338-903f-c28cdee6d005', + id: 'a172ced-b5f21bc-71ba50c-1638604', + }; + + let res; + try { + res = await codeEngineService.getBinding(params); + console.log(JSON.stringify(res.result, null, 2)); + } catch (err) { + console.warn(err); + } + + // end-get_binding + }); + test('listBuilds request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); @@ -638,7 +768,6 @@ describe('CodeEngineV2', () => { name: 'my-build', outputImage: 'private.de.icr.io/icr_namespace/image-name', outputSecret: 'ce-auto-icr-private-eu-de', - sourceUrl: 'https://github.com/IBM/CodeEngine', strategyType: 'dockerfile', }; @@ -1036,6 +1165,7 @@ describe('CodeEngineV2', () => { projectId: '15314cc3-85b4-4338-903f-c28cdee6d005', name: 'my-secret', ifMatch: 'testString', + format: 'generic', }; let res; @@ -1179,6 +1309,32 @@ describe('CodeEngineV2', () => { // end-delete_job_run }); + test('deleteBinding request example', async () => { + consoleLogMock.mockImplementation((output) => { + originalLog(output); + }); + consoleWarnMock.mockImplementation((output) => { + // if an error occurs, display the message and then fail the test + originalWarn(output); + expect(true).toBeFalsy(); + }); + + // begin-delete_binding + + const params = { + projectId: '15314cc3-85b4-4338-903f-c28cdee6d005', + id: 'a172ced-b5f21bc-71ba50c-1638604', + }; + + try { + await codeEngineService.deleteBinding(params); + } catch (err) { + console.warn(err); + } + + // end-delete_binding + }); + test('deleteBuild request example', async () => { consoleLogMock.mockImplementation((output) => { originalLog(output); diff --git a/package-lock.json b/package-lock.json index 8fea06a..cf40b7b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@ibm-cloud/ibm-code-engine-sdk", - "version": "3.1.0", + "version": "4.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@ibm-cloud/ibm-code-engine-sdk", - "version": "3.1.0", + "version": "4.0.0", "license": "Apache-2.0", "dependencies": { "@types/node": "^12.0.8", diff --git a/package.json b/package.json index 53f3f1d..5df2a3c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ibm-cloud/ibm-code-engine-sdk", - "version": "3.1.0", + "version": "4.0.0", "description": "IBM Cloud Code Engine NodeJS SDK", "repository": { "type": "git", diff --git a/test/integration/v2.test.js b/test/integration/v2.test.js index 96e63c3..fc11811 100644 --- a/test/integration/v2.test.js +++ b/test/integration/v2.test.js @@ -592,6 +592,97 @@ describe('CodeEngineV2_integration', () => { expect(res.result).toBeDefined(); }); + test('createServiceAccessSecret', async () => { + const params = { + projectId: e2eTestProjectId, + format: 'service_access', + name: 'my-service-access', + serviceAccess: { + service_instance: { + id: '498131b4-d4b0-42ff-8592-ab3a2f6e3be6', + }, + }, + }; + + const res = await codeEngineService.createSecret(params); + expect(res).toBeDefined(); + expect(res.status).toBe(201); + expect(res.result).toBeDefined(); + }); + + test('createBinding()', async () => { + // Request models needed by this operation. + + // ComponentRef + const componentRefModel = { + name: 'my-app', + resource_type: 'app_v2', + }; + + const params = { + projectId: e2eTestProjectId, + component: componentRefModel, + prefix: 'MY_BIND', + secretName: 'my-service-access', + }; + + let res; + try { + res = await codeEngineService.createBinding(params); + console.log(JSON.stringify(res.result, null, 2)); + } catch (err) { + console.warn(err); + } + }); + + test('getBinding()', async () => { + const params = { + projectId: e2eTestProjectId, + id: 'a172ced-4c9a75c-afe863e-2e70477', + }; + + let res; + try { + res = await codeEngineService.getBinding(params); + console.log(JSON.stringify(res.result, null, 2)); + } catch (err) { + console.warn(err); + } + }); + + test('listBindings()', async () => { + const params = { + projectId: e2eTestProjectId, + limit: 100, + }; + + const allResults = []; + try { + const pager = new CodeEngineV2.BindingsPager(codeEngineService, params); + while (pager.hasNext()) { + const nextPage = await pager.getNext(); + expect(nextPage).not.toBeNull(); + allResults.push(...nextPage); + } + console.log(JSON.stringify(allResults, null, 2)); + } catch (err) { + console.warn(err); + } + }); + + test('deleteBinding()', async () => { + const params = { + projectId: e2eTestProjectId, + id: 'a172ced-4c9a75c-afe863e-2e70477', + }; + + try { + await codeEngineService.deleteBinding(params); + } catch (err) { + console.warn(err); + } + }); + test('listBuilds()', async () => { const params = { projectId: e2eTestProjectId, @@ -964,8 +1055,53 @@ describe('CodeEngineV2_integration', () => { format: 'tls', name: 'my-tls-secret', data: { - 'tls_key': '---BEGIN PRIVATE KEY------END PRIVATE KEY---', - 'tls_cert': '---BEGIN CERTIFICATE------END CERTIFICATE---', + 'tls_key': + '-----BEGIN PRIVATE KEY-----\n' + + 'MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCr+Qx5OrAHLWwm' + + '\nmstn7aEo317g/Lxv/Dmb/N/lanbGZfaVlnE1JrASNnEjps5CrVBLkjctbRYuAWOb' + + '\nvX4OKIGbSmT2JDu3gieg1v2gg0iuMmfqh9pgP8szlfB8lG7/rZ5m4ApEEB8iszIe' + + '\n+BrPsmlBBqd+tuJ3+t/BY9a7PjphkaMCbGlvoaDZEjT6KqubAMmZqkkYFT8mYx+A' + + '\nkwImgqVR5zMs4R2XSEl0QGLsFjnDtWLDvrHGdeGE0hnqTS5OusJ8bmNLJDOvSJSd' + + '\nZSWPtyahNQT4wAnp3RKxd3D2pdChqmxGdIs+eeNwzoXD42M2VEE/MgPLu7hPuPmC' + + '\nnN6AsET9AgMBAAECggEAc9d1cYv42zzbpz2KWt2VO6ULkl5syLqMS+kRIMaQb6Br' + + '\nc+Q9KeJ/pCUMHUnVktCQT/eUN4NN93t0D4qbiQn8FBEO5UcO+tQvwYZQnnkQ0lad' + + '\n7TvJ/B+8z2jm7+REyPG4y++KusJpVsSCtJ3H4bR6dhT3asHi15Mkem64TLTkOqf2' + + '\n5lWg5BUi3ZR5qFjriZdb7N3A+/Cb1fwOObCwNjRUJX6FAPpCdwEr+L9/o6bod+1N' + + '\nUArBYlSP8yMNyct3WzkPSpFnZxaYapjl0Nm9ipOfR5b9CHThoHg007WxdDF+6a/e' + + '\nSEJOZ0jRHwSctLhjSuL8/EOIuQGSHsyOK4SOmeHRgQKBgQDYlrafbArou+pStqIU' + + '\nZCmV51UqSfqZAAJ+YzV9rqhsM97yQKQYEESeIbgAnWCGlAbY7XrysIA/aOdglOuF' + + '\no60oRqlnkYZJT8SXjvnwmyxor67f3G0jbVuoefYL1G1EPdcL9l2K0xehOa2huYm0' + + '\n8lvlI8PPKKJkmu22r/TNyp6VEQKBgQDLRAHsDjNdwyMKVGe2G6ZmnyDWhGzVOOZf' + + '\n+Ixfmt0BK5AnmJBeABM6WRC/6EM0eX31lcev7sJMpWF4Iw0Op+tW2gmtfphi3j/l' + + '\nG7B3lU4V/M6jw0CrASy1RGY257ou3o+/yS4N6/lafZw/V8KDjgJngCeyRhgFf+Rj' + + '\nVNC3FIsBLQKBgERN43ILZLVY7eD/78V2gRbhSZ54jitKMX8iUnA8cKkPArRrZlSg' + + '\nbMNh5uFqwFIwxKgM3MVEnG1i6/Utgck3gRg+kJY08qCUI2+Yi4IxraOmJAQ9Q730' + + '\ncv+C1vGMIJlw1yzSmVV6lO0nf3aNSLxj4k81JD9klTIdGfKPMyjjSXfBAoGBALhl' + + '\nWI0JkOWlSZtsWK1mxfzgrMyOU6DWvn8fnlB4z7bpCxwwlf8AeHD9LWm6zYTEFlV8' + + '\n7CsZIOChQxvWSFkcUi13HUJrztgaIMK57Mt/AdiGf/sl/Ptk1GcYxtVWQJuWQbfN' + + '\nTN9KS+oge2cnOQlZAatdIiXi2pXaoJjP74u2sid9AoGAFuustiKF2vffjhyEg+HL' + + '\nU57p6LG7y6x02COLDhKTX4c/bEa6MX4f91ZKXy2S47tCgLSf4SYd49k1H0wQEDkl' + + '\nYs+pznN30O/Jxu063JfvFbLZxJkeayLpQL12w+NQUDwsF6MGvIYTnUefhkfb3LWC' + + '\njBKCTCcw9u4SVX1jK4f2/OU=' + + '\n-----END PRIVATE KEY-----', + 'tls_cert': + '-----BEGIN CERTIFICATE-----' + + '\nMIICqDCCAZACCQDB2CY2jE7CCjANBgkqhkiG9w0BAQsFADAWMRQwEgYDVQQDDAtm' + + '\nb28uYmFyLmNvbTAeFw0yMzA2MjkyMDM5MzhaFw0yNDA2MjgyMDM5MzhaMBYxFDAS' + + '\nBgNVBAMMC2Zvby5iYXIuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKC' + + '\nAQEAq/kMeTqwBy1sJprLZ+2hKN9e4Py8b/w5m/zf5Wp2xmX2lZZxNSawEjZxI6bO' + + '\nQq1QS5I3LW0WLgFjm71+DiiBm0pk9iQ7t4InoNb9oINIrjJn6ofaYD/LM5XwfJRu' + + '\n/62eZuAKRBAfIrMyHvgaz7JpQQanfrbid/rfwWPWuz46YZGjAmxpb6Gg2RI0+iqr' + + '\nmwDJmapJGBU/JmMfgJMCJoKlUeczLOEdl0hJdEBi7BY5w7Viw76xxnXhhNIZ6k0u' + + '\nTrrCfG5jSyQzr0iUnWUlj7cmoTUE+MAJ6d0SsXdw9qXQoapsRnSLPnnjcM6Fw+Nj' + + '\nNlRBPzIDy7u4T7j5gpzegLBE/QIDAQABMA0GCSqGSIb3DQEBCwUAA4IBAQCXRwhk' + + '\nwjvOzKh5R+QKHGjtcjutSkwZbMj5+5enN/8IwX2BbX0i/aALxEPcZExMK5aIS5rm' + + '\n+kUkDyZkYVaMQQoTGNHSnnET8WJf8zGqd/GdiVxZRVXjOnQ5tEezdwFm0a3TEEKw' + + '\n/2HG9chz24ywhbIZZMEFmse7LLrcy5XSUQzOTMWBKZ8fTEXBYaEVhD/9b4SPuLpw' + + '\ni4vDZPt+e+p96NcGNf0b932aod+X34dARUd55UM9PY4i4Z7UzzV7zK+U6tHjzzmg' + + '\nrv+JA2kDt3mwQXn7bfgRxLcpBZFpUHjLRe+MGlQJM2xFYAXop9ZzF1go58ErHbsT' + + '\nCyXJ56cw0ffDrXSn' + + '\n-----END CERTIFICATE-----', }, }; @@ -993,8 +1129,53 @@ describe('CodeEngineV2_integration', () => { name: 'my-tls-secret', ifMatch: '*', data: { - 'tls_key': '---BEGIN PRIVATE KEY------END PRIVATE KEY---', - 'tls_cert': '---BEGIN CERTIFICATE---test---END CERTIFICATE---', + 'tls_key': + '-----BEGIN PRIVATE KEY-----' + + '\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDGfJO9qkAlq8Vy' + + '\nKNyJEAwJ+VGurknonWKL+/B/8uS45qDYHP9McyokfHR6GEeL3p/vk4zf+QI/+5Dn' + + '\n0IK6jyiLzl4x0FlEVbEesLubi/6B8r6I+pYfWlOX+ShJkryuZcMjuEtvP6sli+Wj' + + '\nr5yILu8YHgAVVdvLs7XJmlDPv/kmq9R66Nsl02PgLazJfztijcdBGkQAPxClwwkJ' + + '\nzVCWE/G7fS0iYUb76ScHrxLwN7Bh+wTOIMHk6qqK2UA45a8MmyGOkD4SoB4K3z3y' + + '\nGNTQrxQbj+wCyK9kY2/sTs++kcsiwTfTx+17UYO05S0+ExqIWrD6bJpnYmWART/2' + + '\niBvcAfLvAgMBAAECggEBAKzVj6SJGmBzKXQVxquHEKSiuBC+bVcjrMsuL6aKb8Xd' + + '\n9VMaNOhyI9EvmhEzESHnUidAuVvSLbZfLTfeZedjfy/2HCmOPhz17UxHIqX4ij7H' + + '\njEgkxBI7Ci18ZStjne7SZ9CzyuPtce842VbmNQyUqde7T+FEKSdArlwFhrbQeHjF' + + '\ngJQrsroY8d0h9Xt6UlfVzX/CeNWP98YJLJ7my9WYRhZlcBE5qwyaMRIY2UKcjgpx' + + '\nXaViny79P5GwiaVGgOUYZ32bA+GHf7u5WP7lCiqT32SgTZzQ9dov9KN+QSkui7qO' + + '\nj0tC0c7OI59zatPAbp+t1LDjsgTjkuoReHes4nhupvECgYEA5b+S9uLtTn3XxLMf' + + '\nR00anvek8EUbTA/TRrJWUhCgvyVCafpyx0BqJC9eR5LnmD3f3yFXDvD5DF201zTn' + + '\n1Py+sk6oUfuPLXz8P76L5Wpz8ryRjR4LfLu0CTGMuUMDfE3NRHQJHNKnkrPwu0mX' + + '\njwbZrI08Xs8yjyx4gapdwE1cEvkCgYEA3SqPHW1AjCdnhSpnzf9QwxX0hzUKvUBK' + + '\neuuhKvmwh/AnE2y4b/6VH7TRj+fUvbaSFl63tTKXvUA2J7gHvz8o3j24EYAibwe/' + + '\nTvcloLjNxHOEq42vwB9zoZZ1UjvNhRo7lB6626/ffQRHXeSfoyMr2GTFYdpCAZds' + + '\nf8/fHA14RycCgYASzd9FfcVWi05Btzd0KodnQ3WohL97NkBgpPATv3CotG//JJSI' + + '\nYmlNlOLukMOL3mSYaq4pduerb3ABvT7MW/NvvKhiLWjGnFg5D2t7136t+2keV7sw' + + '\n9lwB9KBD+YwrfGK0m5qzVTqJ81hcu+U/u5vNV7H9QJAuz8D9O+h4eNx0YQKBgQC+' + + '\naa3dv/oasLJHzEKi8HYv/+8PmXMtjPSS79tKjL6XywNZjfkdMypgqeTi6M4Yp98O' + + '\ns22m63AI2AfIGoFQ/qfI74pSRudegGUNL2uN/I3r3SkUKmBuIKYFMOzBaAuB1RwG' + + '\nYo6uJbVchRqMlBF8+wL8w4XMwYSiqiQXxnhoRpCPcQKBgE2UoeHxvydgQjcfx7/M' + + '\n8BmmLqohWUF6tU62TVBMhYeO77H5Qkn/y0K6UPvar7x0lNAz2ljiUtYvvHc3S9Mc' + + '\nwSQ7GGIZu4ro/tLfi1xVfeQH5Ibm/pdk+1BZfcGeYAHC9Gr+LAT0iJRu8nFyWroB' + + '\nq/Tq26sIqxRotUdtRDJ6D6jf' + + '\n-----END PRIVATE KEY-----', + 'tls_cert': + '-----BEGIN CERTIFICATE-----' + + '\nMIICqDCCAZACCQDB2CY2jE7CCjANBgkqhkiG9w0BAQsFADAWMRQwEgYDVQQDDAtm' + + '\nb28uYmFyLmNvbTAeFw0yMzA2MjkyMDM5MzhaFw0yNDA2MjgyMDM5MzhaMBYxFDAS' + + '\nBgNVBAMMC2Zvby5iYXIuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKC' + + '\nAQEAq/kMeTqwBy1sJprLZ+2hKN9e4Py8b/w5m/zf5Wp2xmX2lZZxNSawEjZxI6bO' + + '\nQq1QS5I3LW0WLgFjm71+DiiBm0pk9iQ7t4InoNb9oINIrjJn6ofaYD/LM5XwfJRu' + + '\n/62eZuAKRBAfIrMyHvgaz7JpQQanfrbid/rfwWPWuz46YZGjAmxpb6Gg2RI0+iqr' + + '\nmwDJmapJGBU/JmMfgJMCJoKlUeczLOEdl0hJdEBi7BY5w7Viw76xxnXhhNIZ6k0u' + + '\nTrrCfG5jSyQzr0iUnWUlj7cmoTUE+MAJ6d0SsXdw9qXQoapsRnSLPnnjcM6Fw+Nj' + + '\nNlRBPzIDy7u4T7j5gpzegLBE/QIDAQABMA0GCSqGSIb3DQEBCwUAA4IBAQCXRwhk' + + '\nwjvOzKh5R+QKHGjtcjutSkwZbMj5+5enN/8IwX2BbX0i/aALxEPcZExMK5aIS5rm' + + '\n+kUkDyZkYVaMQQoTGNHSnnET8WJf8zGqd/GdiVxZRVXjOnQ5tEezdwFm0a3TEEKw' + + '\n/2HG9chz24ywhbIZZMEFmse7LLrcy5XSUQzOTMWBKZ8fTEXBYaEVhD/9b4SPuLpw' + + '\ni4vDZPt+e+p96NcGNf0b932aod+X34dARUd55UM9PY4i4Z7UzzV7zK+U6tHjzzmg' + + '\nrv+JA2kDt3mwQXn7bfgRxLcpBZFpUHjLRe+MGlQJM2xFYAXop9ZzF1go58ErHbsT' + + '\nCyXJ56cw0ffDrXSn' + + '\n-----END CERTIFICATE-----', }, format: 'tls', }; @@ -1107,7 +1288,7 @@ describe('CodeEngineV2_integration', () => { const params = { projectId: e2eTestProjectId, appName: 'my-app', - name: 'my-app-00001', + name: 'my-app-00003', }; const res = await codeEngineService.deleteAppRevision(params); @@ -1211,6 +1392,19 @@ describe('CodeEngineV2_integration', () => { expect(res.status).toBe(202); expect(res.result).toBeDefined(); }); + + test('deleteServiceAccessSecret()', async () => { + const params = { + projectId: e2eTestProjectId, + name: 'my-service-access', + }; + + const res = await codeEngineService.deleteSecret(params); + expect(res).toBeDefined(); + expect(res.status).toBe(202); + expect(res.result).toBeDefined(); + }); + test('deleteTLSSecret()', async () => { const params = { projectId: e2eTestProjectId, diff --git a/test/unit/code-engine.v2.test.js b/test/unit/code-engine.v2.test.js index 98a1519..8c942bb 100644 --- a/test/unit/code-engine.v2.test.js +++ b/test/unit/code-engine.v2.test.js @@ -579,6 +579,92 @@ describe('CodeEngineV2', () => { }); }); + describe('getProjectStatusDetails', () => { + describe('positive tests', () => { + function __getProjectStatusDetailsTest() { + // Construct the params object for operation getProjectStatusDetails + const projectId = '15314cc3-85b4-4338-903f-c28cdee6d005'; + const getProjectStatusDetailsParams = { + projectId, + }; + + const getProjectStatusDetailsResult = codeEngineService.getProjectStatusDetails( + getProjectStatusDetailsParams + ); + + // all methods should return a Promise + expectToBePromise(getProjectStatusDetailsResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/projects/{project_id}/status_details', 'GET'); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.path.project_id).toEqual(projectId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __getProjectStatusDetailsTest(); + + // enable retries and test again + createRequestMock.mockClear(); + codeEngineService.enableRetries(); + __getProjectStatusDetailsTest(); + + // disable retries and test again + createRequestMock.mockClear(); + codeEngineService.disableRetries(); + __getProjectStatusDetailsTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const projectId = '15314cc3-85b4-4338-903f-c28cdee6d005'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const getProjectStatusDetailsParams = { + projectId, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + codeEngineService.getProjectStatusDetails(getProjectStatusDetailsParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await codeEngineService.getProjectStatusDetails({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await codeEngineService.getProjectStatusDetails(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + describe('listApps', () => { describe('positive tests', () => { function __listAppsTest() { @@ -672,9 +758,9 @@ describe('CodeEngineV2', () => { const serviceUrl = codeEngineServiceOptions.url; const path = '/projects/15314cc3-85b4-4338-903f-c28cdee6d005/apps'; const mockPagerResponse1 = - '{"next":{"start":"1"},"total_count":2,"limit":1,"apps":[{"created_at":"2022-09-13T11:41:35+02:00","endpoint":"https://my-app.vg67hzldruk.eu-de.codeengine.appdomain.cloud","endpoint_internal":"http://my-app.vg67hzldruk.svc.cluster.local","entity_tag":"2385407409","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","image_port":8080,"image_reference":"icr.io/codeengine/helloworld","image_secret":"my-secret","managed_domain_mappings":"local_public","name":"my-app","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"app_v2","run_arguments":["run_arguments"],"run_as_user":1001,"run_commands":["run_commands"],"run_env_variables":[{"key":"MY_VARIABLE","name":"SOME","prefix":"PREFIX_","reference":"my-secret","type":"literal","value":"VALUE"}],"run_service_account":"default","run_volume_mounts":[{"mount_path":"/app","name":"codeengine-mount-b69u90","reference":"my-secret","type":"secret"}],"scale_concurrency":100,"scale_concurrency_target":80,"scale_cpu_limit":"1","scale_ephemeral_storage_limit":"4G","scale_initial_instances":1,"scale_max_instances":10,"scale_memory_limit":"4G","scale_min_instances":1,"scale_request_timeout":300,"status":"ready","status_details":{"latest_created_revision":"my-app-00001","latest_ready_revision":"my-app-00001","reason":"ready"}}]}'; + '{"next":{"start":"1"},"total_count":2,"limit":1,"apps":[{"created_at":"2022-09-13T11:41:35+02:00","endpoint":"https://my-app.vg67hzldruk.eu-de.codeengine.appdomain.cloud","endpoint_internal":"http://my-app.vg67hzldruk.svc.cluster.local","entity_tag":"2385407409","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","image_port":8080,"image_reference":"icr.io/codeengine/helloworld","image_secret":"my-secret","managed_domain_mappings":"local_public","name":"my-app","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"app_v2","run_arguments":["run_arguments"],"run_as_user":1001,"run_commands":["run_commands"],"run_env_variables":[{"key":"MY_VARIABLE","name":"SOME","prefix":"PREFIX_","reference":"my-secret","type":"literal","value":"VALUE"}],"run_service_account":"default","run_volume_mounts":[{"mount_path":"/app","name":"codeengine-mount-b69u90","reference":"my-secret","type":"secret"}],"scale_concurrency":100,"scale_concurrency_target":80,"scale_cpu_limit":"1","scale_down_delay":300,"scale_ephemeral_storage_limit":"4G","scale_initial_instances":1,"scale_max_instances":10,"scale_memory_limit":"4G","scale_min_instances":1,"scale_request_timeout":300,"status":"ready","status_details":{"latest_created_revision":"my-app-00001","latest_ready_revision":"my-app-00001","reason":"ready"}}]}'; const mockPagerResponse2 = - '{"total_count":2,"limit":1,"apps":[{"created_at":"2022-09-13T11:41:35+02:00","endpoint":"https://my-app.vg67hzldruk.eu-de.codeengine.appdomain.cloud","endpoint_internal":"http://my-app.vg67hzldruk.svc.cluster.local","entity_tag":"2385407409","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","image_port":8080,"image_reference":"icr.io/codeengine/helloworld","image_secret":"my-secret","managed_domain_mappings":"local_public","name":"my-app","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"app_v2","run_arguments":["run_arguments"],"run_as_user":1001,"run_commands":["run_commands"],"run_env_variables":[{"key":"MY_VARIABLE","name":"SOME","prefix":"PREFIX_","reference":"my-secret","type":"literal","value":"VALUE"}],"run_service_account":"default","run_volume_mounts":[{"mount_path":"/app","name":"codeengine-mount-b69u90","reference":"my-secret","type":"secret"}],"scale_concurrency":100,"scale_concurrency_target":80,"scale_cpu_limit":"1","scale_ephemeral_storage_limit":"4G","scale_initial_instances":1,"scale_max_instances":10,"scale_memory_limit":"4G","scale_min_instances":1,"scale_request_timeout":300,"status":"ready","status_details":{"latest_created_revision":"my-app-00001","latest_ready_revision":"my-app-00001","reason":"ready"}}]}'; + '{"total_count":2,"limit":1,"apps":[{"created_at":"2022-09-13T11:41:35+02:00","endpoint":"https://my-app.vg67hzldruk.eu-de.codeengine.appdomain.cloud","endpoint_internal":"http://my-app.vg67hzldruk.svc.cluster.local","entity_tag":"2385407409","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","image_port":8080,"image_reference":"icr.io/codeengine/helloworld","image_secret":"my-secret","managed_domain_mappings":"local_public","name":"my-app","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"app_v2","run_arguments":["run_arguments"],"run_as_user":1001,"run_commands":["run_commands"],"run_env_variables":[{"key":"MY_VARIABLE","name":"SOME","prefix":"PREFIX_","reference":"my-secret","type":"literal","value":"VALUE"}],"run_service_account":"default","run_volume_mounts":[{"mount_path":"/app","name":"codeengine-mount-b69u90","reference":"my-secret","type":"secret"}],"scale_concurrency":100,"scale_concurrency_target":80,"scale_cpu_limit":"1","scale_down_delay":300,"scale_ephemeral_storage_limit":"4G","scale_initial_instances":1,"scale_max_instances":10,"scale_memory_limit":"4G","scale_min_instances":1,"scale_request_timeout":300,"status":"ready","status_details":{"latest_created_revision":"my-app-00001","latest_ready_revision":"my-app-00001","reason":"ready"}}]}'; beforeEach(() => { unmock_createRequest(); @@ -758,6 +844,7 @@ describe('CodeEngineV2', () => { const scaleConcurrency = 100; const scaleConcurrencyTarget = 80; const scaleCpuLimit = '1'; + const scaleDownDelay = 300; const scaleEphemeralStorageLimit = '4G'; const scaleInitialInstances = 1; const scaleMaxInstances = 10; @@ -780,6 +867,7 @@ describe('CodeEngineV2', () => { scaleConcurrency, scaleConcurrencyTarget, scaleCpuLimit, + scaleDownDelay, scaleEphemeralStorageLimit, scaleInitialInstances, scaleMaxInstances, @@ -816,6 +904,7 @@ describe('CodeEngineV2', () => { expect(mockRequestOptions.body.scale_concurrency).toEqual(scaleConcurrency); expect(mockRequestOptions.body.scale_concurrency_target).toEqual(scaleConcurrencyTarget); expect(mockRequestOptions.body.scale_cpu_limit).toEqual(scaleCpuLimit); + expect(mockRequestOptions.body.scale_down_delay).toEqual(scaleDownDelay); expect(mockRequestOptions.body.scale_ephemeral_storage_limit).toEqual( scaleEphemeralStorageLimit ); @@ -1107,6 +1196,7 @@ describe('CodeEngineV2', () => { const scaleConcurrency = 100; const scaleConcurrencyTarget = 80; const scaleCpuLimit = '1'; + const scaleDownDelay = 300; const scaleEphemeralStorageLimit = '4G'; const scaleInitialInstances = 1; const scaleMaxInstances = 10; @@ -1130,6 +1220,7 @@ describe('CodeEngineV2', () => { scaleConcurrency, scaleConcurrencyTarget, scaleCpuLimit, + scaleDownDelay, scaleEphemeralStorageLimit, scaleInitialInstances, scaleMaxInstances, @@ -1166,6 +1257,7 @@ describe('CodeEngineV2', () => { expect(mockRequestOptions.body.scale_concurrency).toEqual(scaleConcurrency); expect(mockRequestOptions.body.scale_concurrency_target).toEqual(scaleConcurrencyTarget); expect(mockRequestOptions.body.scale_cpu_limit).toEqual(scaleCpuLimit); + expect(mockRequestOptions.body.scale_down_delay).toEqual(scaleDownDelay); expect(mockRequestOptions.body.scale_ephemeral_storage_limit).toEqual( scaleEphemeralStorageLimit ); @@ -1342,9 +1434,9 @@ describe('CodeEngineV2', () => { const serviceUrl = codeEngineServiceOptions.url; const path = '/projects/15314cc3-85b4-4338-903f-c28cdee6d005/apps/my-app/revisions'; const mockPagerResponse1 = - '{"next":{"start":"1"},"total_count":2,"limit":1,"revisions":[{"app_name":"my-app","created_at":"2022-09-13T11:41:35+02:00","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app/revisions/my-app-00001","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","image_port":8080,"image_reference":"icr.io/codeengine/helloworld","image_secret":"my-secret","name":"my-app-00001","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"app_revision_v2","run_arguments":["run_arguments"],"run_as_user":1001,"run_commands":["run_commands"],"run_env_variables":[{"key":"MY_VARIABLE","name":"SOME","prefix":"PREFIX_","reference":"my-secret","type":"literal","value":"VALUE"}],"run_service_account":"default","run_volume_mounts":[{"mount_path":"/app","name":"codeengine-mount-b69u90","reference":"my-secret","type":"secret"}],"scale_concurrency":100,"scale_concurrency_target":80,"scale_cpu_limit":"1","scale_ephemeral_storage_limit":"4G","scale_initial_instances":1,"scale_max_instances":10,"scale_memory_limit":"4G","scale_min_instances":1,"scale_request_timeout":300,"status":"ready","status_details":{"actual_instances":1,"reason":"ready"}}]}'; + '{"next":{"start":"1"},"total_count":2,"limit":1,"revisions":[{"app_name":"my-app","created_at":"2022-09-13T11:41:35+02:00","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app/revisions/my-app-00001","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","image_port":8080,"image_reference":"icr.io/codeengine/helloworld","image_secret":"my-secret","name":"my-app-00001","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"app_revision_v2","run_arguments":["run_arguments"],"run_as_user":1001,"run_commands":["run_commands"],"run_env_variables":[{"key":"MY_VARIABLE","name":"SOME","prefix":"PREFIX_","reference":"my-secret","type":"literal","value":"VALUE"}],"run_service_account":"default","run_volume_mounts":[{"mount_path":"/app","name":"codeengine-mount-b69u90","reference":"my-secret","type":"secret"}],"scale_concurrency":100,"scale_concurrency_target":80,"scale_cpu_limit":"1","scale_down_delay":300,"scale_ephemeral_storage_limit":"4G","scale_initial_instances":1,"scale_max_instances":10,"scale_memory_limit":"4G","scale_min_instances":1,"scale_request_timeout":300,"status":"ready","status_details":{"actual_instances":1,"reason":"ready"}}]}'; const mockPagerResponse2 = - '{"total_count":2,"limit":1,"revisions":[{"app_name":"my-app","created_at":"2022-09-13T11:41:35+02:00","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app/revisions/my-app-00001","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","image_port":8080,"image_reference":"icr.io/codeengine/helloworld","image_secret":"my-secret","name":"my-app-00001","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"app_revision_v2","run_arguments":["run_arguments"],"run_as_user":1001,"run_commands":["run_commands"],"run_env_variables":[{"key":"MY_VARIABLE","name":"SOME","prefix":"PREFIX_","reference":"my-secret","type":"literal","value":"VALUE"}],"run_service_account":"default","run_volume_mounts":[{"mount_path":"/app","name":"codeengine-mount-b69u90","reference":"my-secret","type":"secret"}],"scale_concurrency":100,"scale_concurrency_target":80,"scale_cpu_limit":"1","scale_ephemeral_storage_limit":"4G","scale_initial_instances":1,"scale_max_instances":10,"scale_memory_limit":"4G","scale_min_instances":1,"scale_request_timeout":300,"status":"ready","status_details":{"actual_instances":1,"reason":"ready"}}]}'; + '{"total_count":2,"limit":1,"revisions":[{"app_name":"my-app","created_at":"2022-09-13T11:41:35+02:00","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/apps/my-app/revisions/my-app-00001","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","image_port":8080,"image_reference":"icr.io/codeengine/helloworld","image_secret":"my-secret","name":"my-app-00001","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"app_revision_v2","run_arguments":["run_arguments"],"run_as_user":1001,"run_commands":["run_commands"],"run_env_variables":[{"key":"MY_VARIABLE","name":"SOME","prefix":"PREFIX_","reference":"my-secret","type":"literal","value":"VALUE"}],"run_service_account":"default","run_volume_mounts":[{"mount_path":"/app","name":"codeengine-mount-b69u90","reference":"my-secret","type":"secret"}],"scale_concurrency":100,"scale_concurrency_target":80,"scale_cpu_limit":"1","scale_down_delay":300,"scale_ephemeral_storage_limit":"4G","scale_initial_instances":1,"scale_max_instances":10,"scale_memory_limit":"4G","scale_min_instances":1,"scale_request_timeout":300,"status":"ready","status_details":{"actual_instances":1,"reason":"ready"}}]}'; beforeEach(() => { unmock_createRequest(); @@ -2705,6 +2797,431 @@ describe('CodeEngineV2', () => { }); }); + describe('listBindings', () => { + describe('positive tests', () => { + function __listBindingsTest() { + // Construct the params object for operation listBindings + const projectId = '15314cc3-85b4-4338-903f-c28cdee6d005'; + const limit = 100; + const start = 'testString'; + const listBindingsParams = { + projectId, + limit, + start, + }; + + const listBindingsResult = codeEngineService.listBindings(listBindingsParams); + + // all methods should return a Promise + expectToBePromise(listBindingsResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/projects/{project_id}/bindings', 'GET'); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.qs.limit).toEqual(limit); + expect(mockRequestOptions.qs.start).toEqual(start); + expect(mockRequestOptions.path.project_id).toEqual(projectId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __listBindingsTest(); + + // enable retries and test again + createRequestMock.mockClear(); + codeEngineService.enableRetries(); + __listBindingsTest(); + + // disable retries and test again + createRequestMock.mockClear(); + codeEngineService.disableRetries(); + __listBindingsTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const projectId = '15314cc3-85b4-4338-903f-c28cdee6d005'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const listBindingsParams = { + projectId, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + codeEngineService.listBindings(listBindingsParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await codeEngineService.listBindings({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await codeEngineService.listBindings(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + + describe('BindingsPager tests', () => { + const serviceUrl = codeEngineServiceOptions.url; + const path = '/projects/15314cc3-85b4-4338-903f-c28cdee6d005/bindings'; + const mockPagerResponse1 = + '{"next":{"start":"1"},"total_count":2,"bindings":[{"component":{"name":"my-app-1","resource_type":"app_v2"},"href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/bindings/my-binding","id":"a172ced-b5f21bc-71ba50c-1638604","prefix":"MY_COS","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"binding_v2","secret_name":"my-service-access","status":"active"}],"limit":1}'; + const mockPagerResponse2 = + '{"total_count":2,"bindings":[{"component":{"name":"my-app-1","resource_type":"app_v2"},"href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/bindings/my-binding","id":"a172ced-b5f21bc-71ba50c-1638604","prefix":"MY_COS","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"binding_v2","secret_name":"my-service-access","status":"active"}],"limit":1}'; + + beforeEach(() => { + unmock_createRequest(); + const scope = nock(serviceUrl) + .get((uri) => uri.includes(path)) + .reply(200, mockPagerResponse1) + .get((uri) => uri.includes(path)) + .reply(200, mockPagerResponse2); + }); + + afterEach(() => { + nock.cleanAll(); + mock_createRequest(); + }); + + test('getNext()', async () => { + const params = { + projectId: '15314cc3-85b4-4338-903f-c28cdee6d005', + limit: 100, + }; + const allResults = []; + const pager = new CodeEngineV2.BindingsPager(codeEngineService, params); + while (pager.hasNext()) { + const nextPage = await pager.getNext(); + expect(nextPage).not.toBeNull(); + allResults.push(...nextPage); + } + expect(allResults).not.toBeNull(); + expect(allResults).toHaveLength(2); + }); + + test('getAll()', async () => { + const params = { + projectId: '15314cc3-85b4-4338-903f-c28cdee6d005', + limit: 100, + }; + const pager = new CodeEngineV2.BindingsPager(codeEngineService, params); + const allResults = await pager.getAll(); + expect(allResults).not.toBeNull(); + expect(allResults).toHaveLength(2); + }); + }); + }); + + describe('createBinding', () => { + describe('positive tests', () => { + // Request models needed by this operation. + + // ComponentRef + const componentRefModel = { + name: 'my-app-1', + resource_type: 'app_v2', + }; + + function __createBindingTest() { + // Construct the params object for operation createBinding + const projectId = '15314cc3-85b4-4338-903f-c28cdee6d005'; + const component = componentRefModel; + const prefix = 'MY_COS'; + const secretName = 'my-service-access'; + const createBindingParams = { + projectId, + component, + prefix, + secretName, + }; + + const createBindingResult = codeEngineService.createBinding(createBindingParams); + + // all methods should return a Promise + expectToBePromise(createBindingResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/projects/{project_id}/bindings', 'POST'); + const expectedAccept = 'application/json'; + const expectedContentType = 'application/json'; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.body.component).toEqual(component); + expect(mockRequestOptions.body.prefix).toEqual(prefix); + expect(mockRequestOptions.body.secret_name).toEqual(secretName); + expect(mockRequestOptions.path.project_id).toEqual(projectId); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __createBindingTest(); + + // enable retries and test again + createRequestMock.mockClear(); + codeEngineService.enableRetries(); + __createBindingTest(); + + // disable retries and test again + createRequestMock.mockClear(); + codeEngineService.disableRetries(); + __createBindingTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const projectId = '15314cc3-85b4-4338-903f-c28cdee6d005'; + const component = componentRefModel; + const prefix = 'MY_COS'; + const secretName = 'my-service-access'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const createBindingParams = { + projectId, + component, + prefix, + secretName, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + codeEngineService.createBinding(createBindingParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await codeEngineService.createBinding({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await codeEngineService.createBinding(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + + describe('getBinding', () => { + describe('positive tests', () => { + function __getBindingTest() { + // Construct the params object for operation getBinding + const projectId = '15314cc3-85b4-4338-903f-c28cdee6d005'; + const id = 'a172ced-b5f21bc-71ba50c-1638604'; + const getBindingParams = { + projectId, + id, + }; + + const getBindingResult = codeEngineService.getBinding(getBindingParams); + + // all methods should return a Promise + expectToBePromise(getBindingResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/projects/{project_id}/bindings/{id}', 'GET'); + const expectedAccept = 'application/json'; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.path.project_id).toEqual(projectId); + expect(mockRequestOptions.path.id).toEqual(id); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __getBindingTest(); + + // enable retries and test again + createRequestMock.mockClear(); + codeEngineService.enableRetries(); + __getBindingTest(); + + // disable retries and test again + createRequestMock.mockClear(); + codeEngineService.disableRetries(); + __getBindingTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const projectId = '15314cc3-85b4-4338-903f-c28cdee6d005'; + const id = 'a172ced-b5f21bc-71ba50c-1638604'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const getBindingParams = { + projectId, + id, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + codeEngineService.getBinding(getBindingParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await codeEngineService.getBinding({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await codeEngineService.getBinding(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + + describe('deleteBinding', () => { + describe('positive tests', () => { + function __deleteBindingTest() { + // Construct the params object for operation deleteBinding + const projectId = '15314cc3-85b4-4338-903f-c28cdee6d005'; + const id = 'a172ced-b5f21bc-71ba50c-1638604'; + const deleteBindingParams = { + projectId, + id, + }; + + const deleteBindingResult = codeEngineService.deleteBinding(deleteBindingParams); + + // all methods should return a Promise + expectToBePromise(deleteBindingResult); + + // assert that create request was called + expect(createRequestMock).toHaveBeenCalledTimes(1); + + const mockRequestOptions = getOptions(createRequestMock); + + checkUrlAndMethod(mockRequestOptions, '/projects/{project_id}/bindings/{id}', 'DELETE'); + const expectedAccept = undefined; + const expectedContentType = undefined; + checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); + expect(mockRequestOptions.path.project_id).toEqual(projectId); + expect(mockRequestOptions.path.id).toEqual(id); + } + + test('should pass the right params to createRequest with enable and disable retries', () => { + // baseline test + __deleteBindingTest(); + + // enable retries and test again + createRequestMock.mockClear(); + codeEngineService.enableRetries(); + __deleteBindingTest(); + + // disable retries and test again + createRequestMock.mockClear(); + codeEngineService.disableRetries(); + __deleteBindingTest(); + }); + + test('should prioritize user-given headers', () => { + // parameters + const projectId = '15314cc3-85b4-4338-903f-c28cdee6d005'; + const id = 'a172ced-b5f21bc-71ba50c-1638604'; + const userAccept = 'fake/accept'; + const userContentType = 'fake/contentType'; + const deleteBindingParams = { + projectId, + id, + headers: { + Accept: userAccept, + 'Content-Type': userContentType, + }, + }; + + codeEngineService.deleteBinding(deleteBindingParams); + checkMediaHeaders(createRequestMock, userAccept, userContentType); + }); + }); + + describe('negative tests', () => { + test('should enforce required parameters', async () => { + let err; + try { + await codeEngineService.deleteBinding({}); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + + test('should reject promise when required params are not given', async () => { + let err; + try { + await codeEngineService.deleteBinding(); + } catch (e) { + err = e; + } + + expect(err.message).toMatch(/Missing required parameters/); + }); + }); + }); + describe('listBuilds', () => { describe('positive tests', () => { function __listBuildsTest() { @@ -2853,12 +3370,12 @@ describe('CodeEngineV2', () => { const name = 'my-build'; const outputImage = 'private.de.icr.io/icr_namespace/image-name'; const outputSecret = 'ce-auto-icr-private-eu-de'; - const sourceUrl = 'https://github.com/IBM/CodeEngine'; const strategyType = 'dockerfile'; const sourceContextDir = 'some/subfolder'; const sourceRevision = 'main'; const sourceSecret = 'testString'; const sourceType = 'git'; + const sourceUrl = 'https://github.com/IBM/CodeEngine'; const strategySize = 'medium'; const strategySpecFile = 'Dockerfile'; const timeout = 600; @@ -2867,12 +3384,12 @@ describe('CodeEngineV2', () => { name, outputImage, outputSecret, - sourceUrl, strategyType, sourceContextDir, sourceRevision, sourceSecret, sourceType, + sourceUrl, strategySize, strategySpecFile, timeout, @@ -2895,12 +3412,12 @@ describe('CodeEngineV2', () => { expect(mockRequestOptions.body.name).toEqual(name); expect(mockRequestOptions.body.output_image).toEqual(outputImage); expect(mockRequestOptions.body.output_secret).toEqual(outputSecret); - expect(mockRequestOptions.body.source_url).toEqual(sourceUrl); expect(mockRequestOptions.body.strategy_type).toEqual(strategyType); expect(mockRequestOptions.body.source_context_dir).toEqual(sourceContextDir); expect(mockRequestOptions.body.source_revision).toEqual(sourceRevision); expect(mockRequestOptions.body.source_secret).toEqual(sourceSecret); expect(mockRequestOptions.body.source_type).toEqual(sourceType); + expect(mockRequestOptions.body.source_url).toEqual(sourceUrl); expect(mockRequestOptions.body.strategy_size).toEqual(strategySize); expect(mockRequestOptions.body.strategy_spec_file).toEqual(strategySpecFile); expect(mockRequestOptions.body.timeout).toEqual(timeout); @@ -2928,7 +3445,6 @@ describe('CodeEngineV2', () => { const name = 'my-build'; const outputImage = 'private.de.icr.io/icr_namespace/image-name'; const outputSecret = 'ce-auto-icr-private-eu-de'; - const sourceUrl = 'https://github.com/IBM/CodeEngine'; const strategyType = 'dockerfile'; const userAccept = 'fake/accept'; const userContentType = 'fake/contentType'; @@ -2937,7 +3453,6 @@ describe('CodeEngineV2', () => { name, outputImage, outputSecret, - sourceUrl, strategyType, headers: { Accept: userAccept, @@ -4333,9 +4848,9 @@ describe('CodeEngineV2', () => { const serviceUrl = codeEngineServiceOptions.url; const path = '/projects/15314cc3-85b4-4338-903f-c28cdee6d005/secrets'; const mockPagerResponse1 = - '{"next":{"start":"1"},"total_count":2,"limit":1,"secrets":[{"created_at":"2022-09-13T11:41:35+02:00","data":{"mapKey":"inner"},"entity_tag":"2385407409","format":"generic","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/secrets/my-secret","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","name":"my-secret","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"resource_type"}]}'; + '{"next":{"start":"1"},"total_count":2,"limit":1,"secrets":[{"created_at":"2022-09-13T11:41:35+02:00","data":{"mapKey":"inner"},"entity_tag":"2385407409","format":"generic","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/secrets/my-secret","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","name":"my-secret","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"resource_type","service_access":{"resource_key":{"id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","name":"name"},"role":{"crn":"crn:v1:bluemix:public:iam::::serviceRole:Writer","name":"Manager"},"service_instance":{"id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","type":"type"},"serviceid":{"crn":"crn"}}}]}'; const mockPagerResponse2 = - '{"total_count":2,"limit":1,"secrets":[{"created_at":"2022-09-13T11:41:35+02:00","data":{"mapKey":"inner"},"entity_tag":"2385407409","format":"generic","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/secrets/my-secret","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","name":"my-secret","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"resource_type"}]}'; + '{"total_count":2,"limit":1,"secrets":[{"created_at":"2022-09-13T11:41:35+02:00","data":{"mapKey":"inner"},"entity_tag":"2385407409","format":"generic","href":"https://api.eu-de.codeengine.cloud.ibm.com/v2/projects/4e49b3e0-27a8-48d2-a784-c7ee48bb863b/secrets/my-secret","id":"e33b1cv7-7390-4437-a5c2-130d5ccdddc3","name":"my-secret","project_id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","resource_type":"resource_type","service_access":{"resource_key":{"id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","name":"name"},"role":{"crn":"crn:v1:bluemix:public:iam::::serviceRole:Writer","name":"Manager"},"service_instance":{"id":"4e49b3e0-27a8-48d2-a784-c7ee48bb863b","type":"type"},"serviceid":{"crn":"crn"}}}]}'; beforeEach(() => { unmock_createRequest(); @@ -4391,17 +4906,47 @@ describe('CodeEngineV2', () => { foo: 'testString', }; + // ResourceKeyRefPrototype + const resourceKeyRefPrototypeModel = { + id: '4e49b3e0-27a8-48d2-a784-c7ee48bb863b', + }; + + // RoleRefPrototype + const roleRefPrototypeModel = { + crn: 'crn:v1:bluemix:public:iam::::serviceRole:Writer', + }; + + // ServiceInstanceRefPrototype + const serviceInstanceRefPrototypeModel = { + id: '4e49b3e0-27a8-48d2-a784-c7ee48bb863b', + }; + + // ServiceIDRef + const serviceIdRefModel = { + crn: 'testString', + }; + + // ServiceAccessSecretPrototypeProps + const serviceAccessSecretPrototypePropsModel = { + resource_key: resourceKeyRefPrototypeModel, + role: roleRefPrototypeModel, + service_instance: serviceInstanceRefPrototypeModel, + serviceid: serviceIdRefModel, + }; + function __createSecretTest() { // Construct the params object for operation createSecret const projectId = '15314cc3-85b4-4338-903f-c28cdee6d005'; const format = 'generic'; const name = 'my-secret'; const data = secretDataModel; + const serviceAccess = serviceAccessSecretPrototypePropsModel; const createSecretParams = { projectId, format, name, data, + serviceAccess, }; const createSecretResult = codeEngineService.createSecret(createSecretParams); @@ -4421,6 +4966,7 @@ describe('CodeEngineV2', () => { expect(mockRequestOptions.body.format).toEqual(format); expect(mockRequestOptions.body.name).toEqual(name); expect(mockRequestOptions.body.data).toEqual(data); + expect(mockRequestOptions.body.service_access).toEqual(serviceAccess); expect(mockRequestOptions.path.project_id).toEqual(projectId); } @@ -4591,14 +5137,14 @@ describe('CodeEngineV2', () => { const projectId = '15314cc3-85b4-4338-903f-c28cdee6d005'; const name = 'my-secret'; const ifMatch = 'testString'; - const data = secretDataModel; const format = 'generic'; + const data = secretDataModel; const replaceSecretParams = { projectId, name, ifMatch, - data, format, + data, }; const replaceSecretResult = codeEngineService.replaceSecret(replaceSecretParams); @@ -4616,8 +5162,8 @@ describe('CodeEngineV2', () => { const expectedContentType = 'application/json'; checkMediaHeaders(createRequestMock, expectedAccept, expectedContentType); checkUserHeader(createRequestMock, 'If-Match', ifMatch); - expect(mockRequestOptions.body.data).toEqual(data); expect(mockRequestOptions.body.format).toEqual(format); + expect(mockRequestOptions.body.data).toEqual(data); expect(mockRequestOptions.path.project_id).toEqual(projectId); expect(mockRequestOptions.path.name).toEqual(name); } @@ -4642,12 +5188,14 @@ describe('CodeEngineV2', () => { const projectId = '15314cc3-85b4-4338-903f-c28cdee6d005'; const name = 'my-secret'; const ifMatch = 'testString'; + const format = 'generic'; const userAccept = 'fake/accept'; const userContentType = 'fake/contentType'; const replaceSecretParams = { projectId, name, ifMatch, + format, headers: { Accept: userAccept, 'Content-Type': userContentType,