UNPKG

openshift-rest-client

Version:
68 lines (59 loc) 2.38 kB
'use strict'; /* * * Copyright 2016-2017 Red Hat, Inc, and individual contributors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ const zlib = require('zlib'); const fs = require('fs'); const path = require('path'); const { Client, config, alias } = require('kubernetes-client'); // A list of shorthand aliases const resourceAliases = { 'apps.openshift.io': ['app'], 'authorization.openshift.io': ['authorization'], 'build.openshift.io': ['build'], 'image.openshift.io': ['image'], 'network.openshift.io': ['network'], 'oauth.openshift.io': ['oauth'], 'project.openshift.io': ['project'], 'quota.openshift.io': ['quota'], 'route.openshift.io': ['route'], 'security.openshift.io': ['security'], 'template.openshift.io': ['template'], 'user.openshift.io': ['user'] }; // function is passed in and called by the kubernetes-client to add the openshift aliases function getNames (resourceType) { const aliases = [resourceType]; if (resourceAliases[resourceType]) { return aliases.concat(resourceAliases[resourceType]); } return alias(resourceType); } // unzip and load the openshift openapi swagger spec file // Doesn't look like there is a way to query this from a running cluster // Perhaps, we could try to query https://raw.githubusercontent.com/openshift/origin/master/api/swagger-spec/openshift-openapi-spec.json ? const spec = JSON.parse(zlib.gunzipSync(fs.readFileSync(path.join(__dirname, 'specs', 'openshift-openapi-spec.json.gz')))); /** @param {object} [settings] - @returns {Promise} - Returns the Rest Client */ async function openshiftClient (settings = {}) { // TODO: need to be able to pass in the config object here const client = new Client({ config: settings.config || config.fromKubeconfig(), spec, getNames: getNames }); return client; } module.exports = exports = openshiftClient;