Skip to content

Commit

Permalink
feat: Add ServiceInstance resource (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
tremes authored and lholmquist committed Nov 13, 2018
1 parent becd927 commit 6f9b197
Show file tree
Hide file tree
Showing 5 changed files with 1,490 additions and 1,167 deletions.
2 changes: 1 addition & 1 deletion lib/config-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function loadConfig (client) {
endpoints: function endpoints () {
return ['apps', 'extensions', 'policy',
'authentication.k8s.io', 'authentication.k8s.io', 'rbac.authorization.k8s.io',
'certificates.k8s.io', 'storage.k8s.io']
'certificates.k8s.io', 'storage.k8s.io', 'servicecatalog.k8s.io']
.map(name => {
return { name, url: `/apis/${name}/v1beta1` };
}).reduce((map, obj) => { map[obj.name] = obj.url; return map; }, {});
Expand Down
4 changes: 3 additions & 1 deletion lib/openshift-rest-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const rolebindings = require('./role-bindings');
const routes = require('./routes');
const secrets = require('./secrets');
const services = require('./services');
const serviceinstances = require('./serviceinstances');

function bindModule (client, input) {
if (typeof input === 'object') {
Expand Down Expand Up @@ -87,7 +88,8 @@ function openshiftClient (settings = {}) {
rolebindings,
routes,
secrets,
services
services,
serviceinstances
}));

client.settings = settings;
Expand Down
142 changes: 142 additions & 0 deletions lib/serviceinstances.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
'use strict';

/*
*
* Copyright 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 request = require('./common-request');
const privates = require('./private-map');

function findAll (client) {
return function findAll (options = {}) {
const clientConfig = privates.get(client).config;
const url = `${clientConfig.cluster}${client.apis.v1beta1.endpoints()['servicecatalog.k8s.io']}/namespaces/${clientConfig.context.namespace}/serviceinstances`;

const req = {
method: 'GET',
url,
qs: options.qs
};

return request(client, req);
};
}

function find (client) {
return function find (serviceInstanceName, options = {}) {
if (!serviceInstanceName) {
return Promise.reject(new Error('Service Instance name is required'));
}

const clientConfig = privates.get(client).config;
const url =
`${clientConfig.cluster}${client.apis.v1beta1.endpoints()['servicecatalog.k8s.io']}/namespaces/${clientConfig.context.namespace}/serviceinstances/${serviceInstanceName}`;

const req = {
method: 'GET',
url
};

return request(client, req);
};
}

function create (client) {
return function create (serviceinstance, options = {}) {
const clientConfig = privates.get(client).config;
const url =
`${clientConfig.cluster}${client.apis.v1beta1.endpoints()['servicecatalog.k8s.io']}/namespaces/${clientConfig.context.namespace}/serviceinstances`;

const req = {
method: 'POST',
url,
json: false,
body: JSON.stringify(serviceinstance)
};

return request(client, req).then(body => {
return JSON.parse(body);
});
};
}

function update (client) {
return function create (name, serviceinstance, options = {}) {
if (!name) {
return Promise.reject(new Error('Service Instance name is required'));
}

const clientConfig = privates.get(client).config;
const url = `${clientConfig.cluster}${client.apis.v1beta1.endpoints()['servicecatalog.k8s.io']}/namespaces/${clientConfig.context.namespace}/serviceinstances/${name}`;

const req = {
method: 'PUT',
json: false,
url,
body: JSON.stringify(serviceinstance)
};

return request(client, req).then(body => {
return JSON.parse(body);
});
};
}

function remove (client) {
return function remove (name, options = {}) {
if (!name) {
return Promise.reject(new Error('Service Instance name is required'));
}
const clientConfig = privates.get(client).config;
const url =
`${clientConfig.cluster}${client.apis.v1beta1.endpoints()['servicecatalog.k8s.io']}/namespaces/${clientConfig.context.namespace}/serviceinstances/${name}`;

const req = {
method: 'DELETE',
url,
body: options.body,
qs: options.qs
};

return request(client, req);
};
}

function removeAll (client) {
return function removeAll (options = {}) {
const clientConfig = privates.get(client).config;
const url =
`${clientConfig.cluster}${client.apis.v1beta1.endpoints()['servicecatalog.k8s.io']}/namespaces/${clientConfig.context.namespace}/serviceinstances`;

const req = {
method: 'DELETE',
url,
qs: options.qs
};

return request(client, req);
};
}

module.exports = {
findAll: findAll,
find: find,
create: create,
update: update,
remove: remove,
removeAll: removeAll
};
Loading

0 comments on commit 6f9b197

Please sign in to comment.