Skip to content

Commit

Permalink
uGW support for spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
DanBadt committed Oct 3, 2016
1 parent 46d7c54 commit 836dc5f
Show file tree
Hide file tree
Showing 15 changed files with 3,185 additions and 2 deletions.
3 changes: 2 additions & 1 deletion datastore/common/models/catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"title": "string"
},
"sandbox": "boolean",
"space-enabled": "boolean",
"title": "string",
"url": "string",
"snapshot-id": {
Expand All @@ -36,4 +37,4 @@
"relations": {},
"acls": [],
"methods": {}
}
}
12 changes: 12 additions & 0 deletions datastore/common/models/optimizedData.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ function ripCTX(ctx) {
ctx.instance['plan-registration'].apis = []; // old list, wipe it
locals.product = ctx.instance['plan-registration'].product;
locals.plan = {};
locals.spaces = ctx.instance['plan-registration'].spaces || [];

if (ctx.instance['plan-registration'].plan) {
locals.plan.name = ctx.instance['plan-registration'].plan.name;
Expand Down Expand Up @@ -392,6 +393,11 @@ function createOptimizedDataEntry(app, pieces, isWildcard, cb) {
var createTestApp = pieces.catalog['test-app-enabled'] &&
pieces.catalog['test-app-credentials'] &&
pieces.catalog.sandbox;
var spaceEnabled = pieces.catalog['space-enabled'];
var regSpaceId = [];
if (spaceEnabled && pieces.spaces && pieces.spaces.length) {
regSpaceId = pieces.spaces.map(function(space) { return space.id; });
}

async.each(
pieces.application.credentials,
Expand All @@ -406,6 +412,10 @@ function createOptimizedDataEntry(app, pieces, isWildcard, cb) {
var apiNameVer = apiName + ':' + apiVersion;
var apiId = api.id;
logger.debug('apiNameVer:', apiNameVer, ' apiId:', apiId);
var spaceId = regSpaceId;
if (spaceEnabled && spaceId.length === 0 && api.spaces && api.spaces.length) {
spaceId = api.spaces.map(function(space) { return space.id; });
}

// Find the named property (in the plan) for this API
var apiProperty;
Expand Down Expand Up @@ -602,6 +612,7 @@ function createOptimizedDataEntry(app, pieces, isWildcard, cb) {
'catalog-name': 'string',
'organization-id': 'string',
'organization-name': 'string',
'space-id': [],
'product-id': 'string',
'product-name': 'string',
'plan-id': 'string',
Expand Down Expand Up @@ -654,6 +665,7 @@ function createOptimizedDataEntry(app, pieces, isWildcard, cb) {
'catalog-name': pieces.catalog.name,
'organization-id': pieces.org.id,
'organization-name': pieces.org.name,
'space-id': spaceId,
'api-id': api.id,
'api-document': api['document-wo-assembly'],
'api-document-resolved': api['document-resolved'],
Expand Down
1 change: 1 addition & 0 deletions datastore/common/models/optimizedData.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"catalog-name": "string",
"organization-id": "string",
"organization-name": "string",
"space-id": [],
"product-id": "string",
"product-name": "string",
"plan-id": "string",
Expand Down
10 changes: 9 additions & 1 deletion datastore/common/models/subscription.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@
"id": {
"type": "string"
},
"spaces": [
{
"id": "string",
"name": "string",
"description": "string",
"title": "string"
}
],
"organization": {
"id": "string",
"name": "string",
Expand Down Expand Up @@ -121,4 +129,4 @@
"relations": {},
"acls": [],
"methods": {}
}
}
2 changes: 2 additions & 0 deletions lib/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ function processActivity(req, res, duration, opts) {
"requestBody" : "",
"source" : "9.20.85.122",
"orgId" : "542016d6e4b0f87216fdc806",
"spaceId" : [],
"timeToServeRequest" : 2989,
"requestHttpHeaders" : [],
"planId" : "54201a9de4b0f87216fdc8d3",
Expand Down Expand Up @@ -139,6 +140,7 @@ function buildApiEvent(req, res, duration) {
bytesReceived: req.socket.bytesRead ? req.socket.bytesRead : req.socket._bytesRead,
apiVersion: ctx.get('api.version'),
orgId: ctx.get('api.org.id') || '',
spaceId: ctx.get('_apis.spaceId') || [],
envId: process.env[env.APIMANAGER_CATALOG] || '',
apiId: ctx.get('_.api.id') || '',
appId: ctx.get('client.app.id') || '',
Expand Down
1 change: 1 addition & 0 deletions lib/security-check/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ function buildPreflowContext(EntryMatch, PathMatch, MethodMatch) {
rateLimits: MethodMatch['observed-rate-limit'],
rateLimitScope: MethodMatch['rate-limit-scope'],
testAppEnabled: EntryMatch['test-app-enabled'],
spaceId: EntryMatch['space-id'],
isPreflight: MethodMatch.isPreflight };

return context;
Expand Down
18 changes: 18 additions & 0 deletions test/definitions/spaces/cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-----BEGIN CERTIFICATE-----
MIIC2jCCAkOgAwIBAgIEXAWA7zANBgkqhkiG9w0BAQUFADBSMQswCQYDVQQGEwJV
UzELMAkGA1UECBMCTUExEjAQBgNVBAcTCUNhbWJyaWRnZTESMBAGA1UEChMJRGF0
YVBvd2VyMQ4wDAYDVQQDEwVBbGljZTAeFw0wNjA5MjgwMTI1MDZaFw0xNjA5MjUw
MTI1MDZaMFIxCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJNQTESMBAGA1UEBxMJQ2Ft
YnJpZGdlMRIwEAYDVQQKEwlEYXRhUG93ZXIxDjAMBgNVBAMTBUFsaWNlMIGfMA0G
CSqGSIb3DQEBAQUAA4GNADCBiQKBgQDhfHY/tcY2U74oRyXb8Y/o08HnAMiG55Ey
M0Qad/GVnlIpKndZPnGaYPMB7nA2J3Y/fOtKi3rQClqPMM+Wd54lYG37TwjHde67
YT2TjYncpKOrgScl9GAYyXGcMB/nBERFo0LIiWTQp1gHokCtglxdHqfAJWg7mC08
NeNDvv/xyQIDAQABo4G8MIG5MAwGA1UdEwQFMAMBAf8wHQYDVR0OBBYEFMERS5af
Hx/fIu1OqYpyJ4SDWhUEMH0GA1UdIwR2MHSAFMERS5afHx/fIu1OqYpyJ4SDWhUE
oVakVDBSMQswCQYDVQQGEwJVUzELMAkGA1UECBMCTUExEjAQBgNVBAcTCUNhbWJy
aWRnZTESMBAGA1UEChMJRGF0YVBvd2VyMQ4wDAYDVQQDEwVBbGljZYIEXAWA7zAL
BgNVHQ8EBAMCArwwDQYJKoZIhvcNAQEFBQADgYEAjA+44l1rYsQl9uIyKQz4+xJ5
YR3aiuPonmI8PfDTpc/e9jYZJFYKWgEI6/o1gZ61Fnr85QbJQSE4f7xptcuIaBU9
gkgg6/vBW8AmbNFHMMg3W60cImp8NvCO70AHymkGNidJVg4h4zwjs562JdiHUDP1
ygBCd5ZBhwEHKNs26nY=
-----END CERTIFICATE-----
15 changes: 15 additions & 0 deletions test/definitions/spaces/key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDhfHY/tcY2U74oRyXb8Y/o08HnAMiG55EyM0Qad/GVnlIpKndZ
PnGaYPMB7nA2J3Y/fOtKi3rQClqPMM+Wd54lYG37TwjHde67YT2TjYncpKOrgScl
9GAYyXGcMB/nBERFo0LIiWTQp1gHokCtglxdHqfAJWg7mC08NeNDvv/xyQIDAQAB
AoGBAK8zsAWszchkpTpSnf4Z4gG8l8tP9n+r6kuhPed7DwF8NMa7smRreoXDks4L
YLETVHPcMk6HtfN0OA1Old2KMBvRRUIreAqorngSOvVQ14ZAG7wAmVmNNoroHZ1b
uuAVEF8wl4RI8T5Y8RxWdLAr77npJ2cZnKMaeI3KVCA03ISpAkEA8Ne9R7HTGib7
osSwTVq+gnxeRlphdbqqdTRDy+jU0QNT/NYaCbYqvxBLyCasjSVQ+ko9EtKe8E3/
tng//Mt14wJBAO+tT3MajlIkba9a4IRR3vZV7y/5bebXa/un8lxZ69edJK6vlJsa
fLZ2YXQK1AVQHUK2p52uVSRUWdUk10rQKWMCQQDLEXyc6MjP8jKVyTXF409igi6T
Lz2hoGR9MjY/xe861I2KT5PgwGJGex0Kg+FVmTMv9kyMhF5Sy9FiLv30zjB1AkBB
udEzy3CD7iF2GQHAx4LRIre4/Dm7OBAQrvmzgaU/N4S7ssKZ1iWlE8mdvOpvmoyr
otNMVmZa1BbecH/psDPpAkAo96tZAIQggfphaNEIfK32MHcRQBornvLG5LgScsN6
LJ6MFF4HkmArnVI4LOHm/ijvQUmUuT647Sr/1c6lXK2w
-----END RSA PRIVATE KEY-----
Loading

0 comments on commit 836dc5f

Please sign in to comment.