Commit 489271d0 by Jessica Forrester Committed by GitHub

Merge pull request #77 from benjaminapetersen/api-info-verbs

Update APIService.apiInfo to return verbs when possible
parents 46865349 da199af9
...@@ -391,6 +391,13 @@ angular.module('openshiftCommonServices') ...@@ -391,6 +391,13 @@ angular.module('openshiftCommonServices')
return resource; return resource;
} }
function kindToResourceGroupVersion(kind) {
return toResourceGroupVersion({
resource: kindToResource(kind.kind),
group: kind.group
});
}
// apiInfo returns the host/port, prefix, group, and version for the given resource, // apiInfo returns the host/port, prefix, group, and version for the given resource,
// or undefined if the specified resource/group/version is known not to exist. // or undefined if the specified resource/group/version is known not to exist.
var apiInfo = function(resource) { var apiInfo = function(resource) {
...@@ -423,12 +430,14 @@ angular.module('openshiftCommonServices') ...@@ -423,12 +430,14 @@ angular.module('openshiftCommonServices')
} }
var hostPrefixObj = _.get(APIS_CFG, ["groups", resource.group, 'hostPrefix']) || APIS_CFG; var hostPrefixObj = _.get(APIS_CFG, ["groups", resource.group, 'hostPrefix']) || APIS_CFG;
return { return {
resource: resource.resource,
group: resource.group,
version: resource.version,
protocol: hostPrefixObj.protocol, protocol: hostPrefixObj.protocol,
hostPort: hostPrefixObj.hostPort, hostPort: hostPrefixObj.hostPort,
prefix: hostPrefixObj.prefix, prefix: hostPrefixObj.prefix,
group: resource.group, namespaced: discoveredResource.namespaced,
version: resource.version, verbs: discoveredResource.verbs
namespaced: discoveredResource.namespaced
}; };
} }
...@@ -442,10 +451,12 @@ angular.module('openshiftCommonServices') ...@@ -442,10 +451,12 @@ angular.module('openshiftCommonServices')
continue; continue;
} }
return { return {
resource: resource.resource,
version: resource.version,
hostPort: api.hostPort, hostPort: api.hostPort,
prefix: api.prefix, prefix: api.prefix,
version: resource.version, namespaced: discoveredResource.namespaced,
namespaced: discoveredResource.namespaced verbs: discoveredResource.verbs
}; };
} }
return undefined; return undefined;
...@@ -545,6 +556,8 @@ angular.module('openshiftCommonServices') ...@@ -545,6 +556,8 @@ angular.module('openshiftCommonServices')
kindToResource: kindToResource, kindToResource: kindToResource,
kindToResourceGroupVersion: kindToResourceGroupVersion,
apiInfo: apiInfo, apiInfo: apiInfo,
invalidObjectKindOrVersion: invalidObjectKindOrVersion, invalidObjectKindOrVersion: invalidObjectKindOrVersion,
......
...@@ -1971,6 +1971,13 @@ angular.module('openshiftCommonServices') ...@@ -1971,6 +1971,13 @@ angular.module('openshiftCommonServices')
return resource; return resource;
} }
function kindToResourceGroupVersion(kind) {
return toResourceGroupVersion({
resource: kindToResource(kind.kind),
group: kind.group
});
}
// apiInfo returns the host/port, prefix, group, and version for the given resource, // apiInfo returns the host/port, prefix, group, and version for the given resource,
// or undefined if the specified resource/group/version is known not to exist. // or undefined if the specified resource/group/version is known not to exist.
var apiInfo = function(resource) { var apiInfo = function(resource) {
...@@ -2003,12 +2010,14 @@ angular.module('openshiftCommonServices') ...@@ -2003,12 +2010,14 @@ angular.module('openshiftCommonServices')
} }
var hostPrefixObj = _.get(APIS_CFG, ["groups", resource.group, 'hostPrefix']) || APIS_CFG; var hostPrefixObj = _.get(APIS_CFG, ["groups", resource.group, 'hostPrefix']) || APIS_CFG;
return { return {
resource: resource.resource,
group: resource.group,
version: resource.version,
protocol: hostPrefixObj.protocol, protocol: hostPrefixObj.protocol,
hostPort: hostPrefixObj.hostPort, hostPort: hostPrefixObj.hostPort,
prefix: hostPrefixObj.prefix, prefix: hostPrefixObj.prefix,
group: resource.group, namespaced: discoveredResource.namespaced,
version: resource.version, verbs: discoveredResource.verbs
namespaced: discoveredResource.namespaced
}; };
} }
...@@ -2022,10 +2031,12 @@ angular.module('openshiftCommonServices') ...@@ -2022,10 +2031,12 @@ angular.module('openshiftCommonServices')
continue; continue;
} }
return { return {
resource: resource.resource,
version: resource.version,
hostPort: api.hostPort, hostPort: api.hostPort,
prefix: api.prefix, prefix: api.prefix,
version: resource.version, namespaced: discoveredResource.namespaced,
namespaced: discoveredResource.namespaced verbs: discoveredResource.verbs
}; };
} }
return undefined; return undefined;
...@@ -2125,6 +2136,8 @@ angular.module('openshiftCommonServices') ...@@ -2125,6 +2136,8 @@ angular.module('openshiftCommonServices')
kindToResource: kindToResource, kindToResource: kindToResource,
kindToResourceGroupVersion: kindToResourceGroupVersion,
apiInfo: apiInfo, apiInfo: apiInfo,
invalidObjectKindOrVersion: invalidObjectKindOrVersion, invalidObjectKindOrVersion: invalidObjectKindOrVersion,
......
...@@ -723,6 +723,12 @@ resource = humanizeKind(resource); ...@@ -723,6 +723,12 @@ resource = humanizeKind(resource);
} }
return resource = String(resource).toLowerCase(), "endpoints" === resource || "securitycontextconstraints" === resource || ("s" === resource[resource.length - 1] ? resource += "es" :"y" === resource[resource.length - 1] ? resource = resource.substring(0, resource.length - 1) + "ies" :resource += "s"), resource; return resource = String(resource).toLowerCase(), "endpoints" === resource || "securitycontextconstraints" === resource || ("s" === resource[resource.length - 1] ? resource += "es" :"y" === resource[resource.length - 1] ? resource = resource.substring(0, resource.length - 1) + "ies" :resource += "s"), resource;
} }
function kindToResourceGroupVersion(kind) {
return toResourceGroupVersion({
resource:kindToResource(kind.kind),
group:kind.group
});
}
var defaultVersion = { var defaultVersion = {
"":"v1", "":"v1",
extensions:"v1beta1" extensions:"v1beta1"
...@@ -769,20 +775,24 @@ if (resource.group) { ...@@ -769,20 +775,24 @@ if (resource.group) {
if (discoveredResource = _.get(APIS_CFG, [ "groups", resource.group, "versions", resource.version, "resources", primaryResource ]), !discoveredResource) return void 0; if (discoveredResource = _.get(APIS_CFG, [ "groups", resource.group, "versions", resource.version, "resources", primaryResource ]), !discoveredResource) return void 0;
var hostPrefixObj = _.get(APIS_CFG, [ "groups", resource.group, "hostPrefix" ]) || APIS_CFG; var hostPrefixObj = _.get(APIS_CFG, [ "groups", resource.group, "hostPrefix" ]) || APIS_CFG;
return { return {
resource:resource.resource,
group:resource.group,
version:resource.version,
protocol:hostPrefixObj.protocol, protocol:hostPrefixObj.protocol,
hostPort:hostPrefixObj.hostPort, hostPort:hostPrefixObj.hostPort,
prefix:hostPrefixObj.prefix, prefix:hostPrefixObj.prefix,
group:resource.group, namespaced:discoveredResource.namespaced,
version:resource.version, verbs:discoveredResource.verbs
namespaced:discoveredResource.namespaced
}; };
} }
var api; var api;
for (var apiName in API_CFG) if (api = API_CFG[apiName], discoveredResource = _.get(api, [ "resources", resource.version, primaryResource ])) return { for (var apiName in API_CFG) if (api = API_CFG[apiName], discoveredResource = _.get(api, [ "resources", resource.version, primaryResource ])) return {
resource:resource.resource,
version:resource.version,
hostPort:api.hostPort, hostPort:api.hostPort,
prefix:api.prefix, prefix:api.prefix,
version:resource.version, namespaced:discoveredResource.namespaced,
namespaced:discoveredResource.namespaced verbs:discoveredResource.verbs
}; };
return void 0; return void 0;
}, invalidObjectKindOrVersion = function(apiObject) { }, invalidObjectKindOrVersion = function(apiObject) {
...@@ -836,6 +846,7 @@ parseGroupVersion:parseGroupVersion, ...@@ -836,6 +846,7 @@ parseGroupVersion:parseGroupVersion,
objectToResourceGroupVersion:objectToResourceGroupVersion, objectToResourceGroupVersion:objectToResourceGroupVersion,
deriveTargetResource:deriveTargetResource, deriveTargetResource:deriveTargetResource,
kindToResource:kindToResource, kindToResource:kindToResource,
kindToResourceGroupVersion:kindToResourceGroupVersion,
apiInfo:apiInfo, apiInfo:apiInfo,
invalidObjectKindOrVersion:invalidObjectKindOrVersion, invalidObjectKindOrVersion:invalidObjectKindOrVersion,
unsupportedObjectKindOrVersion:unsupportedObjectKindOrVersion, unsupportedObjectKindOrVersion:unsupportedObjectKindOrVersion,
......
...@@ -188,6 +188,13 @@ angular.module('openshiftCommonServices') ...@@ -188,6 +188,13 @@ angular.module('openshiftCommonServices')
return resource; return resource;
} }
function kindToResourceGroupVersion(kind) {
return toResourceGroupVersion({
resource: kindToResource(kind.kind),
group: kind.group
});
}
// apiInfo returns the host/port, prefix, group, and version for the given resource, // apiInfo returns the host/port, prefix, group, and version for the given resource,
// or undefined if the specified resource/group/version is known not to exist. // or undefined if the specified resource/group/version is known not to exist.
var apiInfo = function(resource) { var apiInfo = function(resource) {
...@@ -220,12 +227,14 @@ angular.module('openshiftCommonServices') ...@@ -220,12 +227,14 @@ angular.module('openshiftCommonServices')
} }
var hostPrefixObj = _.get(APIS_CFG, ["groups", resource.group, 'hostPrefix']) || APIS_CFG; var hostPrefixObj = _.get(APIS_CFG, ["groups", resource.group, 'hostPrefix']) || APIS_CFG;
return { return {
resource: resource.resource,
group: resource.group,
version: resource.version,
protocol: hostPrefixObj.protocol, protocol: hostPrefixObj.protocol,
hostPort: hostPrefixObj.hostPort, hostPort: hostPrefixObj.hostPort,
prefix: hostPrefixObj.prefix, prefix: hostPrefixObj.prefix,
group: resource.group, namespaced: discoveredResource.namespaced,
version: resource.version, verbs: discoveredResource.verbs
namespaced: discoveredResource.namespaced
}; };
} }
...@@ -239,10 +248,12 @@ angular.module('openshiftCommonServices') ...@@ -239,10 +248,12 @@ angular.module('openshiftCommonServices')
continue; continue;
} }
return { return {
resource: resource.resource,
version: resource.version,
hostPort: api.hostPort, hostPort: api.hostPort,
prefix: api.prefix, prefix: api.prefix,
version: resource.version, namespaced: discoveredResource.namespaced,
namespaced: discoveredResource.namespaced verbs: discoveredResource.verbs
}; };
} }
return undefined; return undefined;
...@@ -342,6 +353,8 @@ angular.module('openshiftCommonServices') ...@@ -342,6 +353,8 @@ angular.module('openshiftCommonServices')
kindToResource: kindToResource, kindToResource: kindToResource,
kindToResourceGroupVersion: kindToResourceGroupVersion,
apiInfo: apiInfo, apiInfo: apiInfo,
invalidObjectKindOrVersion: invalidObjectKindOrVersion, invalidObjectKindOrVersion: invalidObjectKindOrVersion,
......
...@@ -63,6 +63,77 @@ describe("APIService", function() { ...@@ -63,6 +63,77 @@ describe("APIService", function() {
}); });
describe('#kindToResourceGroupVersion', function() {
var kinds = [
[{kind: 'ServiceAccount', group: ''}, {"resource":"serviceaccounts","group":"","version":"v1"}],
[{kind: 'PodTemplate', group: ''}, {"resource":"podtemplates","group":"","version":"v1"}],
[{kind: 'HorizontalPodAutoscaler', group: 'autoscaling'}, {"resource":"horizontalpodautoscalers","group":"autoscaling","version":"v1"}],
[{kind: 'DaemonSet', group: 'extensions'}, {"resource":"daemonsets","group":"extensions","version":"v1beta1"}],
[{kind: 'RoleBinding', group: 'rbac.authorization.k8s.io'}, {"resource":"rolebindings","group":"rbac.authorization.k8s.io","version":"v1beta1"}],
[{kind: 'PodPreset', group: 'settings.k8s.io'}, {"resource":"podpresets","group":"settings.k8s.io","version":"v1alpha1"}],
[{kind: 'Policy', group: 'authorization.openshift.io'}, {"resource":"policies","group":"authorization.openshift.io","version":"v1"}],
[{kind: 'Template', group: 'template.openshift.io'}, {"resource":"templates","group":"template.openshift.io","version":"v1"}],
[{kind: 'NetworkPolicy', group: 'extensions'}, {"resource":"networkpolicies","group":"extensions","version":"v1beta1"}],
[{kind: 'EgressNetworkPolicy', group: 'network.openshift.io'}, {"resource":"egressnetworkpolicies","group":"network.openshift.io","version":"v1"}],
[{kind: 'LocalResourceAccessReview', group: 'authorization.openshift.io'}, {"resource":"localresourceaccessreviews","group":"authorization.openshift.io","version":"v1"}],
[{kind: 'SelfSubjectRulesReview', group: 'authorization.openshift.io'}, {"resource":"selfsubjectrulesreviews","group":"authorization.openshift.io","version":"v1"}],
[{kind: 'ReplicationControllerDummy', group: 'extensions'}, {"resource":"replicationcontrollerdummies","group":"extensions","version":"v1beta1"}]
];
_.each(kinds, _.spread(function(kind, expectedRGV) {
it('should result in ' + JSON.stringify(expectedRGV) + ' when called with ' + JSON.stringify(kind), function() {
var actualRGV = APIService.kindToResourceGroupVersion(kind);
expect(expectedRGV.resource).toEqual(actualRGV.resource);
expect(expectedRGV.group).toEqual(actualRGV.group);
expect(expectedRGV.version).toEqual(actualRGV.version);
});
}));
});
describe('#apiInfo', function() {
var rgvs = [
[
{"resource":"serviceaccounts","group":"","version":"v1"},
{resource: 'serviceaccounts', version: 'v1', hostPort: 'localhost:8443', prefix: '/api', namespaced: true, verbs: ['create', 'delete', 'deletecollection', 'get', 'list', 'patch', 'update', 'watch']}
],
[
{"resource":"horizontalpodautoscalers","group":"autoscaling","version":"v1"},
{resource: 'horizontalpodautoscalers', group: 'autoscaling', version: 'v1', protocol: undefined, hostPort: 'localhost:8443', prefix: '/apis', namespaced: true, verbs: ['create', 'delete', 'deletecollection', 'get', 'list', 'patch', 'update', 'watch']}
],
[
{"resource":"templates","group":"template.openshift.io","version":"v1"},
{resource: 'templates', group: 'template.openshift.io', version: 'v1', protocol: undefined, hostPort: 'localhost:8443', prefix: '/apis', namespaced: true, verbs: ['create', 'delete', 'deletecollection', 'get', 'list', 'patch', 'update', 'watch']}
],
[
{"resource":"policies","group":"authorization.openshift.io","version":"v1"},
{resource: 'policies', group: 'authorization.openshift.io', version: 'v1', protocol: undefined, hostPort: 'localhost:8443', prefix: '/apis', namespaced: true, verbs: ['create', 'delete', 'deletecollection', 'get', 'list', 'patch', 'update', 'watch']}
],
[
{"resource":"selfsubjectrulesreviews","group":"authorization.openshift.io","version":"v1"},
{resource: 'selfsubjectrulesreviews', group: 'authorization.openshift.io', version: 'v1', protocol: undefined, hostPort: 'localhost:8443', prefix: '/apis', namespaced: true, verbs: ['create']}
],
[
{"resource":"replicationcontrollerdummies","group":"extensions","version":"v1beta1"},
undefined
]
];
_.each(rgvs, _.spread(function(rgv, expectedAPIInfo) {
it('should result in ' + JSON.stringify(expectedAPIInfo) + ' when called with ' + JSON.stringify(rgv), function() {
var actualAPIInfo = APIService.apiInfo(rgv);
if(actualAPIInfo) {
expect(actualAPIInfo.resource).toEqual(expectedAPIInfo.resource);
expect(actualAPIInfo.group).toEqual(expectedAPIInfo.group);
expect(actualAPIInfo.version).toEqual(expectedAPIInfo.version);
expect(actualAPIInfo.hostPort).toEqual(expectedAPIInfo.hostPort);
expect(actualAPIInfo.prefix).toEqual(expectedAPIInfo.prefix);
expect(actualAPIInfo.namespaced).toEqual(expectedAPIInfo.namespaced);
expect(actualAPIInfo.verbs).toEqual(expectedAPIInfo.verbs);
} else {
expect(actualAPIInfo).toEqual(expectedAPIInfo);
}
});
}));
});
describe("#parseGroupVersion", function(){ describe("#parseGroupVersion", function(){
var tc = [ var tc = [
...@@ -310,7 +381,7 @@ describe("APIService", function() { ...@@ -310,7 +381,7 @@ describe("APIService", function() {
it('should not return kinds from the AVAILABLE_KINDS_BLACKLIST', function() { it('should not return kinds from the AVAILABLE_KINDS_BLACKLIST', function() {
var allKinds = APIService.availableKinds(true); var allKinds = APIService.availableKinds(true);
// calculateAvailableKinds will transform strings form AVAILABLE_KINDS_BLACKLIST // calculateAvailableKinds will transform strings form AVAILABLE_KINDS_BLACKLIST
// into objects in this same way. // into objects in this same way.
var blacklist = _.map(window.OPENSHIFT_CONSTANTS.AVAILABLE_KINDS_BLACKLIST, function(kind) { var blacklist = _.map(window.OPENSHIFT_CONSTANTS.AVAILABLE_KINDS_BLACKLIST, function(kind) {
return _.isString(kind) ? return _.isString(kind) ?
{ kind: kind, group: '' } : { kind: kind, group: '' } :
......
...@@ -85,7 +85,7 @@ describe("DataService", function(){ ...@@ -85,7 +85,7 @@ describe("DataService", function(){
[{resource:'nodes', version:'unknown'}, null], [{resource:'nodes', version:'unknown'}, null],
// Different API groups // Different API groups
[{resource:'jobs', group: 'extensions', version:'v1beta1', namespace:"foo"}, "http://localhost:8443/apis/extensions/v1beta1/namespaces/foo/jobs"] [{resource:'jobs', group: 'batch', version:'v1', namespace:"foo"}, "http://localhost:8443/apis/batch/v1/namespaces/foo/jobs"]
]; ];
angular.forEach(tc, function(item) { angular.forEach(tc, function(item) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment