-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add v1beta1 api endpoints (#70)
This commit adds the set of v1beta1 endpoint URLs documented here: https://docs.openshift.com/container-platform/3.7/rest_api/index.html The only functional endpoint at the moment is for deployments. All of the others simply expose the endpoint URL but do expose any functional behavior. I've added a `client.apis` object which maps to the the 3 semi-supported APIs at the moment. ```js client.apis.oapi // { version: config.apiVersion, baseUrl: client.apiUrl } client.apis.kube // { version: config.apiVersion, baseUrl: client.kubeUrl } client.apis.v1beta1 // function endpoints() returning array of endpoint URLs ``` Fixes: #69
- Loading branch information
Showing
4 changed files
with
371 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
'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() | ||
.apps}/namespaces/${clientConfig | ||
.context.namespace}/deployments`; | ||
|
||
const req = { | ||
method: 'GET', | ||
url, | ||
qs: options.qs | ||
}; | ||
|
||
return request(client, req); | ||
}; | ||
} | ||
|
||
function find (client) { | ||
return function find (deploymentName, options = {}) { | ||
if (!deploymentName) { | ||
return Promise.reject(new Error('Deployment Name is required')); | ||
} | ||
|
||
const clientConfig = privates.get(client).config; | ||
const url = | ||
`${clientConfig.cluster}${client.apis.v1beta1.endpoints() | ||
.apps}/namespaces/${clientConfig.context.namespace}/deployments/${deploymentName}`; | ||
|
||
const req = { | ||
method: 'GET', | ||
url | ||
}; | ||
|
||
return request(client, req); | ||
}; | ||
} | ||
|
||
function create (client) { | ||
return function create (deployment, options = {}) { | ||
const clientConfig = privates.get(client).config; | ||
const url = | ||
`${clientConfig.cluster}${client.apis.v1beta1.endpoints() | ||
.apps}/namespaces/${clientConfig.context.namespace}/deployments`; | ||
|
||
const req = { | ||
method: 'POST', | ||
url, | ||
json: false, | ||
body: JSON.stringify(deployment) | ||
}; | ||
|
||
return request(client, req).then(body => { | ||
return JSON.parse(body); | ||
}); | ||
}; | ||
} | ||
|
||
function update (client) { | ||
return function create (name, deployment, options = {}) { | ||
if (!name) { | ||
return Promise.reject(new Error('Deployment Name is required')); | ||
} | ||
|
||
const clientConfig = privates.get(client).config; | ||
const url = | ||
`${clientConfig.cluster}${client.apis.v1beta1.endpoints() | ||
.apps}/namespaces/${clientConfig.context.namespace}/deployments/${name}`; | ||
|
||
const req = { | ||
method: 'PUT', | ||
json: false, | ||
url, | ||
body: JSON.stringify(deployment) | ||
}; | ||
|
||
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('Deployment Name is required')); | ||
} | ||
const clientConfig = privates.get(client).config; | ||
const url = | ||
`${clientConfig.cluster}${client.apis.v1beta1.endpoints() | ||
.apps}/namespaces/${clientConfig.context.namespace}/deployments/${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() | ||
.apps}/namespaces/${clientConfig.context.namespace}/deployments`; | ||
|
||
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.