{"id":18981895,"url":"https://github.com/nodeshift/openshift-rest-client","last_synced_at":"2025-05-08T23:46:42.986Z","repository":{"id":20811571,"uuid":"90980476","full_name":"nodeshift/openshift-rest-client","owner":"nodeshift","description":"Node based Openshift REST admin client","archived":false,"fork":false,"pushed_at":"2025-03-20T08:29:36.000Z","size":6475,"stargazers_count":25,"open_issues_count":13,"forks_count":28,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-05-08T23:46:36.164Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nodeshift.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-05-11T13:09:47.000Z","updated_at":"2025-02-28T14:23:37.000Z","dependencies_parsed_at":"2023-01-11T20:59:10.773Z","dependency_job_id":"c70cf948-190d-4453-afe2-7a4809829766","html_url":"https://github.com/nodeshift/openshift-rest-client","commit_stats":{"total_commits":356,"total_committers":25,"mean_commits":14.24,"dds":0.5252808988764045,"last_synced_commit":"1e1f693d4740ccc9fe930cd544e22ff767a64118"},"previous_names":[],"tags_count":57,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeshift%2Fopenshift-rest-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeshift%2Fopenshift-rest-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeshift%2Fopenshift-rest-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeshift%2Fopenshift-rest-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nodeshift","download_url":"https://codeload.github.com/nodeshift/openshift-rest-client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253166474,"owners_count":21864467,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T16:11:38.397Z","updated_at":"2025-05-08T23:46:42.967Z","avatar_url":"https://github.com/nodeshift.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Node.js CI](https://github.com/nodeshift/openshift-rest-client/workflows/Node.js%20CI/badge.svg)\n[![Coverage Status](https://coveralls.io/repos/github/nodeshift/openshift-rest-client/badge.svg?branch=main)](https://coveralls.io/github/nodeshift/openshift-rest-client?branch=main)\n\n### Openshift Client\n\nNode.js based client for the Openshift REST API, not unlike the Fabric8 Maven Plugin, but for node clients/builds.\n\n### Basic Usage\n\n`npm install --save openshift-rest-client`\n\nCode:\n\n    const openshiftRestClient = require('openshift-rest-client').OpenshiftClient;\n\n    openshiftRestClient().then((client) =\u003e {\n      // Use the client object to find a list of projects, for example\n      client.apis['project.openshift.io'].v1.projects.get().then((response) =\u003e {\n        console.log(response.body);\n      });\n    });\n\n\nThe openshift-rest-client translates Path Item Objects \\[[1]\\] (*e.g*.,\n`/apis/project.openshift.io/v1/projects`) to object chains ending in HTTP methods (*e.g.*,\n`apis['project.openshift.io'].v1.projects.get`).\n\nSo, to fetch all Projects:\n\n```js\nconst projects = await client.apis['project.openshift.io'].v1.projects.get()\n```\n\nIf needed, [Query Parameters](https://docs.openshift.com/container-platform/3.11/rest_api/apis-project.openshift.io/v1.Project.html#query-parameters-3) can be used:\n\n```js\nconst projects = await client.apis['project.openshift.io'].v1.projects.get({qs: {labelSelector: 'someOpenShiftLabel'}})\n```\n\nThe openshift-rest-client translates Path Templating \\[[2]\\] (*e.g.*,\n`/apis/build.openshift.io/v1/namespaces/$NAMESPACE/buildconfigs`) to function calls (*e.g.*,\n`apis['build.openshift.io'].v1.namespaces('default').buildconfigs`).\n\nSo, to create a new Build Config in the default Namespace:\n\n```js\nconst buildConfig = require('./build-config.json')\nconst create = await client.apis['build.openshift.io'].v1.namespaces('default').buildconfigs.post({ body: buildConfig })\n```\n\nand then fetch your newly created Build Config:\n\n```js\nconst deployment = await client.apis['build.openshift.io'].v1.namespaces('default').buildconfigs(buildConfig.metadata.name).get()\n```\n\nand finally, remove the Build Config:\n\n```js\nawait client.apis['build.openshift.io'].v1.namespaces('default').buildconfigs(buildConfig.metadata.name).delete()\n```\n\nThe openshift-rest-client supports `.delete`, `.get`, `.patch`, `.post`, and `.put`.\n\nThere are also aliases defined, so instead of writing `client.apis['build.openshift.io']`, you can just use `client.apis.build` for example.  The list of aliases can be seen here: https://github.com/nodeshift/openshift-rest-client/blob/HEAD/lib/openshift-rest-client.js\n\n### Advanced Usage\n\nBy default, the openshift-rest-client will use the [kubernetes-client](https://www.npmjs.com/package/kubernetes-client) module to get your configuration.\n\nThe openshift-rest-client exposes the config module from the kubernetes client for ease of use.\n\nFor example, if you want to provide a different path to your configuration, you can do something like this:\n\n    const openshiftRestClient = require('openshift-rest-client').OpenshiftClient;\n\n    const config = '~/some/path/config';\n\n    openshiftRestClient({ config }).then((client) =\u003e {\n      // Use the client object to find a list of projects, for example\n      client.apis['project.openshift.io'].v1.project.get().then((response) =\u003e {\n        console.log(response.body);\n      });\n    });\n\nYou can also pass a plain object or a [KubeConfig](https://github.com/nodeshift/openshift-rest-client/blob/049059de652d9467b342f465a9394f321fc960bf/index.js#L23) object.\n\nAn example of a plain object:\n\n```\n    const openshiftRestClient = require('openshift-rest-client').OpenshiftClient;\n    const k8Config = require('openshift-rest-client').config;\n\n    const config = {\n      apiVersion: 'v1',\n      kind: 'Config',\n      clusters: [\n          {\n            name: 'cluster',\n            cluster: {\n              skipTLSVerify: true,\n              server: 'server-time'\n            }\n          }\n        ],\n        users: [{ name: 'user', token: '123456' }],\n        contexts: [\n          {\n            context: {\n              user: 'user',\n              cluster: 'cluster'\n            },\n            name: 'context'\n          }\n        ],\n        'current-context': 'context'\n      };\n\n    openshiftRestClient({config}).then((client) =\u003e {\n      console.log(client);\n    });\n```\n\nAn example of a KubeConfig object:\n\n```\n    const openshiftRestClient = require('openshift-rest-client').OpenshiftClient;\n    const k8Config = require('openshift-rest-client').config;\n\n    const config = {\n      apiVersion: 'v1',\n      kind: 'Config',\n      clusters: [\n          {\n            name: 'cluster',\n            cluster: {\n              skipTLSVerify: true,\n              server: 'server-time'\n            }\n          }\n        ],\n        users: [{ name: 'user', token: '123456' }],\n        contexts: [\n          {\n            context: {\n              user: 'user',\n              cluster: 'cluster'\n            },\n            name: 'context'\n          }\n        ],\n        'current-context': 'context'\n      };\n\n      k8Config.loadFromString(JSON.stringify(config));\n\n\n      openshiftRestClient({config: k8Config}).then((client) =\u003e {\n        console.log(client);\n      });\n```\n\n\nIf you want to use a username/password combo to authenticate to Openshift, you might do something like this:\n\n```\nconst openshiftRestClient = require('openshift-rest-client').OpenshiftClient;\n\n\n(async function () {\n  const settings = {\n  };\n\n  settings.config = {\n    url: process.env.CLUSTER_URL,\n    auth: {\n      username: process.env.ADMIN_USERNAME,\n      password: process.env.ADMIN_PASSWORD\n    },\n    insecureSkipTlsVerify: true\n  };\n\n  const client = await openshiftRestClient(settings);\n\n  const projects = await client.apis['build.openshift.io'].v1.ns('myproject').builds.get();\n  console.log(projects);\n})();\n```\n\nIt is also possible to send in a valid auth token instead of a username/password.  If we use the above example,  the settings object might look something like this:\n\n```\nconst settings = {\n  };\n\nsettings.config = {\n  url: process.env.CLUSTER_URL,\n  auth: {\n    token: process.env.TOKEN\n  },\n  insecureSkipTlsVerify: true\n};\n```\n\nTo see more examples of how to customize your config, check out the [kubernetes-client Initializing section](https://www.npmjs.com/package/kubernetes-client#initializing)\n\n#### Load API from a Remote Cluster\n\nBy default, the openshift-rest-client, will load a swagger spec file that is included with the module.  This has all the basic API's that come with Openshift and Kubernetes.  If you are using operators to extend your cluster, the openshift-rest-client, by default, won't know about them.\n\nTo fix this, you can tell the openshift-rest-client to load the spec file from your remote cluster using the `loadSpecFromCluster` option.  Setting this to true, will try to load the spec file from your clusters `/openapi/v2` endpoint.  If that doesn't exist, it will also try, `/swagger.json`\n\nIf the remote spec cannot be loaded,  a warning will be output to the console and the default spec will be loaded.\n\nIn a future version of this client,  this might become the default.\n\n\n\n#### Changes in 2.0\n\nThe client has been totally rewritten for the 2.0 release.  This includes a new, more fluent, API.\n\nThe old API will live in the 1.x branch.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodeshift%2Fopenshift-rest-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnodeshift%2Fopenshift-rest-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodeshift%2Fopenshift-rest-client/lists"}