Commit ff35c743 by Jessica Forrester Committed by GitHub

Merge pull request #61 from benjaminapetersen/available-kinds-blacklist-update

Update calculateAvailableKinds to support both string & object
parents 871f3176 454f7a6a
......@@ -469,7 +469,12 @@ angular.module('openshiftCommonServices')
// Returns an array of available kinds, including their group
var calculateAvailableKinds = function(includeClusterScoped) {
var kinds = [];
var rejectedKinds = Constants.AVAILABLE_KINDS_BLACKLIST;
var rejectedKinds = _.map(Constants.AVAILABLE_KINDS_BLACKLIST, function(kind) {
return _.isString(kind) ?
{ kind: kind, group: '' } :
kind;
});
// ignore the legacy openshift kinds, these have been migrated to api groups
_.each(_.pick(API_CFG, function(value, key) {
......@@ -478,12 +483,13 @@ angular.module('openshiftCommonServices')
_.each(api.resources.v1, function(resource) {
if (resource.namespaced || includeClusterScoped) {
// Exclude subresources and any rejected kinds
if (resource.name.indexOf("/") >= 0 || _.contains(rejectedKinds, resource.kind)) {
if (_.contains(resource.name, '/') || _.find(rejectedKinds, { kind: resource.kind, group: '' })) {
return;
}
kinds.push({
kind: resource.kind
kind: resource.kind,
group: ''
});
}
});
......@@ -495,7 +501,7 @@ angular.module('openshiftCommonServices')
var preferredVersion = defaultVersion[group.name] || group.preferredVersion;
_.each(group.versions[preferredVersion].resources, function(resource) {
// Exclude subresources and any rejected kinds
if (resource.name.indexOf("/") >= 0 || _.contains(rejectedKinds, resource.kind)) {
if (_.contains(resource.name, '/') || _.find(rejectedKinds, {kind: resource.kind, group: group.name})) {
return;
}
......
......@@ -896,44 +896,6 @@ angular.module('openshiftCommonUI')
}
};
}]);
;// This is the default configuration for the dev mode of the web console.
// A generated version of this config is created at run-time when running
// the web console from the openshift binary.
//
// To change configuration for local development, copy this file to
// assets/app/config.local.js and edit the copy.
if (!window.OPENSHIFT_CONFIG) {
window.OPENSHIFT_CONFIG = {
apis: {
hostPort: "localhost:8443",
prefix: "/apis"
},
api: {
openshift: {
hostPort: "localhost:8443",
prefix: "/oapi"
},
k8s: {
hostPort: "localhost:8443",
prefix: "/api"
}
},
auth: {
oauth_authorize_uri: "https://localhost:8443/oauth/authorize",
oauth_token_uri: "https://localhost:8443/oauth/token",
oauth_redirect_base: "https://localhost:9000/dev-console",
oauth_client_id: "openshift-web-console",
logout_uri: ""
},
loggingURL: "",
metricsURL: ""
};
window.OPENSHIFT_VERSION = {
openshift: "dev-mode",
kubernetes: "dev-mode"
};
}
;'use strict';
angular.module('openshiftCommonUI')
......@@ -1815,7 +1777,12 @@ angular.module('openshiftCommonServices')
// Returns an array of available kinds, including their group
var calculateAvailableKinds = function(includeClusterScoped) {
var kinds = [];
var rejectedKinds = Constants.AVAILABLE_KINDS_BLACKLIST;
var rejectedKinds = _.map(Constants.AVAILABLE_KINDS_BLACKLIST, function(kind) {
return _.isString(kind) ?
{ kind: kind, group: '' } :
kind;
});
// ignore the legacy openshift kinds, these have been migrated to api groups
_.each(_.pick(API_CFG, function(value, key) {
......@@ -1824,12 +1791,13 @@ angular.module('openshiftCommonServices')
_.each(api.resources.v1, function(resource) {
if (resource.namespaced || includeClusterScoped) {
// Exclude subresources and any rejected kinds
if (resource.name.indexOf("/") >= 0 || _.contains(rejectedKinds, resource.kind)) {
if (_.contains(resource.name, '/') || _.find(rejectedKinds, { kind: resource.kind, group: '' })) {
return;
}
kinds.push({
kind: resource.kind
kind: resource.kind,
group: ''
});
}
});
......@@ -1841,7 +1809,7 @@ angular.module('openshiftCommonServices')
var preferredVersion = defaultVersion[group.name] || group.preferredVersion;
_.each(group.versions[preferredVersion].resources, function(resource) {
// Exclude subresources and any rejected kinds
if (resource.name.indexOf("/") >= 0 || _.contains(rejectedKinds, resource.kind)) {
if (_.contains(resource.name, '/') || _.find(rejectedKinds, {kind: resource.kind, group: group.name})) {
return;
}
......
......@@ -322,34 +322,7 @@ content ? (scope.truncatedContent = truncateFilter(content, scope.limit, scope.u
});
}
};
} ]), window.OPENSHIFT_CONFIG || (window.OPENSHIFT_CONFIG = {
apis:{
hostPort:"localhost:8443",
prefix:"/apis"
},
api:{
openshift:{
hostPort:"localhost:8443",
prefix:"/oapi"
},
k8s:{
hostPort:"localhost:8443",
prefix:"/api"
}
},
auth:{
oauth_authorize_uri:"https://localhost:8443/oauth/authorize",
oauth_token_uri:"https://localhost:8443/oauth/token",
oauth_redirect_base:"https://localhost:9000/dev-console",
oauth_client_id:"openshift-web-console",
logout_uri:""
},
loggingURL:"",
metricsURL:""
}, window.OPENSHIFT_VERSION = {
openshift:"dev-mode",
kubernetes:"dev-mode"
}), angular.module("openshiftCommonUI").filter("alertStatus", function() {
} ]), angular.module("openshiftCommonUI").filter("alertStatus", function() {
return function(type) {
var status;
switch (type) {
......@@ -740,22 +713,34 @@ return apiObject && apiObject.kind && (kind = apiObject.kind), apiObject && apiO
var kind = "<none>", version = "<none>";
return apiObject && apiObject.kind && (kind = apiObject.kind), apiObject && apiObject.apiVersion && (version = apiObject.apiVersion), "The API version " + version + " for kind " + kind + " is not supported by this server";
}, calculateAvailableKinds = function(includeClusterScoped) {
var kinds = [], rejectedKinds = Constants.AVAILABLE_KINDS_BLACKLIST;
var kinds = [], rejectedKinds = _.map(Constants.AVAILABLE_KINDS_BLACKLIST, function(kind) {
return _.isString(kind) ? {
kind:kind,
group:""
} :kind;
});
return _.each(_.pick(API_CFG, function(value, key) {
return "openshift" !== key;
}), function(api) {
_.each(api.resources.v1, function(resource) {
if (resource.namespaced || includeClusterScoped) {
if (resource.name.indexOf("/") >= 0 || _.contains(rejectedKinds, resource.kind)) return;
if (_.contains(resource.name, "/") || _.find(rejectedKinds, {
kind:resource.kind,
group:""
})) return;
kinds.push({
kind:resource.kind
kind:resource.kind,
group:""
});
}
});
}), _.each(APIS_CFG.groups, function(group) {
var preferredVersion = defaultVersion[group.name] || group.preferredVersion;
_.each(group.versions[preferredVersion].resources, function(resource) {
resource.name.indexOf("/") >= 0 || _.contains(rejectedKinds, resource.kind) || "extensions" === group.name && "HorizontalPodAutoscaler" === resource.kind || "batch" === group.name && "Job" === resource.kind || (resource.namespaced || includeClusterScoped) && kinds.push({
_.contains(resource.name, "/") || _.find(rejectedKinds, {
kind:resource.kind,
group:group.name
}) || "extensions" === group.name && "HorizontalPodAutoscaler" === resource.kind || "batch" === group.name && "Job" === resource.kind || (resource.namespaced || includeClusterScoped) && kinds.push({
kind:resource.kind,
group:group.name
});
......
......@@ -266,7 +266,12 @@ angular.module('openshiftCommonServices')
// Returns an array of available kinds, including their group
var calculateAvailableKinds = function(includeClusterScoped) {
var kinds = [];
var rejectedKinds = Constants.AVAILABLE_KINDS_BLACKLIST;
var rejectedKinds = _.map(Constants.AVAILABLE_KINDS_BLACKLIST, function(kind) {
return _.isString(kind) ?
{ kind: kind, group: '' } :
kind;
});
// ignore the legacy openshift kinds, these have been migrated to api groups
_.each(_.pick(API_CFG, function(value, key) {
......@@ -275,12 +280,13 @@ angular.module('openshiftCommonServices')
_.each(api.resources.v1, function(resource) {
if (resource.namespaced || includeClusterScoped) {
// Exclude subresources and any rejected kinds
if (resource.name.indexOf("/") >= 0 || _.contains(rejectedKinds, resource.kind)) {
if (_.contains(resource.name, '/') || _.find(rejectedKinds, { kind: resource.kind, group: '' })) {
return;
}
kinds.push({
kind: resource.kind
kind: resource.kind,
group: ''
});
}
});
......@@ -292,7 +298,7 @@ angular.module('openshiftCommonServices')
var preferredVersion = defaultVersion[group.name] || group.preferredVersion;
_.each(group.versions[preferredVersion].resources, function(resource) {
// Exclude subresources and any rejected kinds
if (resource.name.indexOf("/") >= 0 || _.contains(rejectedKinds, resource.kind)) {
if (_.contains(resource.name, '/') || _.find(rejectedKinds, {kind: resource.kind, group: group.name})) {
return;
}
......
......@@ -31,12 +31,15 @@ module.exports = function(config) {
"bower_components/hawtio-core/dist/hawtio-core.js",
"bower_components/kubernetes-container-terminal/dist/container-terminal.js",
"bower_components/hawtio-extension-service/dist/hawtio-extension-service.js",
'src/config.js',
// load up the fixtures first
'test/spec/fixtures/config.js',
'test/spec/fixtures/constants.js',
'test/spec/fixtures/api-discovery.js',
// TODO: is this causing modules to load multiple times? see `src/**/*.js` below
'src/**/*module.js',
'dist/scripts/templates.js',
'src/**/*.js',
'test/spec/spec-helper.js',
'test/spec/fixtures/api-discovery.js',
'test/spec/**/*.js'
],
......
window.OPENSHIFT_CONSTANTS = window.OPENSHIFT_CONSTANTS || {};
window.OPENSHIFT_CONSTANTS.AVAILABLE_KINDS_BLACKLIST = [
// using this kind to test the blacklisting function in apiService.
// "Binding"/servicecatalog.k8s.io will not actually be blacklisted.
{ kind: "Binding", group: "servicecatalog.k8s.io" },
"Ingress",
// These are things like DCPs that aren't actually persisted resources
"DeploymentConfigRollback",
// FOR TESTING:
// { kind: 'LocalSubjectAccessReview', group: ' authorization.openshift.io' }
// { kind: 'LocalSubjectAccessReview', group: ' authorization.k8s.io' }
];
......@@ -282,7 +282,7 @@ describe("APIService", function() {
});
// unlike the /oapi endpoint, the /api endpoint should still be listed
it('should list items from the k8s /api namespace (that do not have a group)', function() {
it('should list items from the k8s /api namespace where group is an empty string', function() {
var allKinds = APIService.availableKinds(true);
var shouldBeFound = [];
// this is a sampling of items from /api that should still be listed,
......@@ -298,7 +298,7 @@ describe("APIService", function() {
];
_.each(k8sAPIStillExistsSample, function(kindToFind) {
var found = _.find(allKinds, function(kind) {
return (kind.kind === kindToFind.kind) && !_.includes(_.keys(kind), 'group');
return (kind.kind === kindToFind.kind) && kind.group === '';
});
if(found) {
shouldBeFound.push(found);
......@@ -307,6 +307,21 @@ describe("APIService", function() {
expect(shouldBeFound.length).toEqual(k8sAPIStillExistsSample.length);
});
it('should not return kinds from the AVAILABLE_KINDS_BLACKLIST', function() {
var allKinds = APIService.availableKinds(true);
// calculateAvailableKinds will transform strings form AVAILABLE_KINDS_BLACKLIST
// into objects in this same way.
var blacklist = _.map(window.OPENSHIFT_CONSTANTS.AVAILABLE_KINDS_BLACKLIST, function(kind) {
return _.isString(kind) ?
{ kind: kind, group: '' } :
kind;
});
_.each(blacklist, function(blacklistedKind) {
expect(_.find(allKinds, blacklistedKind)).toEqual(undefined);
});
});
});
});
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