|
| 1 | +const Client = require('./client-base'); |
| 2 | + |
| 3 | +/** |
| 4 | + * Client for interacting with arbitrary Custom Resource Definitions (CRDs). |
| 5 | + * Allows fetching individual or all resources by manually constructing the API path. |
| 6 | + */ |
| 7 | +class CRDs extends Client { |
| 8 | + /** |
| 9 | + * Fetches a single custom resource or a list of custom resources. |
| 10 | + * |
| 11 | + * @param {Object} params - Parameters for the request. |
| 12 | + * @param {string} params.group - API group of the CRD. |
| 13 | + * @param {string} params.version - API version of the CRD. |
| 14 | + * @param {string} params.resource - Resource type (e.g., 'queues'). |
| 15 | + * @param {string} [params.name] - Optional resource name for fetching a specific resource. |
| 16 | + * @param {string} [params.labelSelector] - Optional label selector for filtering. |
| 17 | + * @returns {Promise<Object>} The API response containing the requested resource(s). |
| 18 | + */ |
| 19 | + async get({ name, group, version, resource, labelSelector } = {}) { |
| 20 | + const basePath = name |
| 21 | + ? `/apis/${group}/${version}/${resource}/${name}` |
| 22 | + : `/apis/${group}/${version}/${resource}`; |
| 23 | + |
| 24 | + const qs = labelSelector ? { labelSelector } : undefined; |
| 25 | + |
| 26 | + return this._client.backend.http({ |
| 27 | + method: 'GET', |
| 28 | + pathname: basePath, |
| 29 | + qs |
| 30 | + }); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Fetches all custom resources of the specified type. |
| 35 | + * |
| 36 | + * @param {Object} params - Parameters for the request. |
| 37 | + * @param {string} params.group - API group of the CRD. |
| 38 | + * @param {string} params.version - API version of the CRD. |
| 39 | + * @param {string} params.resource - Resource type (e.g., 'queues'). |
| 40 | + * @param {string} [params.labelSelector] - Optional label selector for filtering. |
| 41 | + * @returns {Promise<Object>} The API response containing the list of resources. |
| 42 | + */ |
| 43 | + all(params = {}) { |
| 44 | + return this.get(params); |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +module.exports = CRDs; |
0 commit comments