Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

Commit

Permalink
code changed based on V3 and UT's fixed (#1755)
Browse files Browse the repository at this point in the history
* code changed based on V3 and UT's fixed

* code updated

* code changes for /v2/spaces and /v2/org
  • Loading branch information
pawansap authored Nov 14, 2022
1 parent 7087e62 commit 310fa50
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,23 @@ class ServiceFabrikAdminController extends FabrikBaseController {
spaces = _
.chain(spaces)
.map(resource => {
const entity = resource.entity;
entity.guid = resource.metadata.guid;
const entity = {
guid: resource.guid,
name: resource.name,
organization_guid: resource.relationships.organization.data.guid
};
return entity;
})
.keyBy('guid')
.value();
organizations = _
.chain(organizations)
.map(resource => {
const entity = resource.entity;
entity.guid = resource.metadata.guid;
const entity = {
guid: resource.guid,
name: resource.name,
quota_definition_guid: resource.relationships.quota.data.guid
};
return entity;
})
.keyBy('guid')
Expand All @@ -169,6 +175,7 @@ class ServiceFabrikAdminController extends FabrikBaseController {
deployment.organization = organizations[_.get(deployment, 'space.organization_guid')];
}
});

return deployments;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1999,9 +1999,7 @@ describe('service-fabrik-api-sf2.0', function () {
it('should return 201 OK', function () {
mocks.uaa.tokenKey();
mocks.apiServerEventMesh.nockGetResource(CONST.APISERVER.RESOURCE_GROUPS.DEPLOYMENT, CONST.APISERVER.RESOURCE_TYPES.DIRECTOR, instance_id, dummyDeploymentResource);
mocks.cloudController.getSpace(space_guid, {
organization_guid: organization_guid
});
mocks.cloudController.getSpace(space_guid, organization_guid);
mocks.cloudController.getOrganization(organization_guid);
mocks.cloudController.getSpaceDevelopers(space_guid);
return chai.request(apps.external)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ describe('service-fabrik-api', function () {
mocks.verify();
});
});
});
});

describe('#backup-schedule', function () {
it('should return 503 - schedule backup feature not enabled', function () {
Expand Down Expand Up @@ -290,9 +290,7 @@ describe('service-fabrik-api', function () {
it('should return 201 OK', function () {
mocks.uaa.tokenKey();
mocks.apiServerEventMesh.nockGetResource(CONST.APISERVER.RESOURCE_GROUPS.DEPLOYMENT, CONST.APISERVER.RESOURCE_TYPES.DIRECTOR, instance_id, dummyDeploymentResource);
mocks.cloudController.getSpace(space_guid, {
organization_guid: organization_guid
});
mocks.cloudController.getSpace(space_guid, organization_guid);
mocks.cloudController.getOrganization(organization_guid);
mocks.cloudController.getSpaceDevelopers(space_guid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,15 +335,13 @@ describe('docker-operator', function () {
uri: `http://${username}:${password}@${docker_url.hostname}`
});
mocks.verify();
});
});
});
it('returns 201 Created and creates Security Group for shared instance binding', function () {
let target_space_guid = 'target_id';
let binding_id = 'binding_id';
mocks.docker.inspectContainer(instance_id);
mocks.cloudController.getSpace(target_space_guid, {
'organization_guid': organization_guid
});
mocks.cloudController.getSpace(target_space_guid,organization_guid);
mocks.cloudController.createSecurityGroup(binding_id);
const options = {
binding_id: binding_id,
Expand Down
2 changes: 1 addition & 1 deletion broker/bin/broker
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function init_without_instance() {
# space
space_guid=$(cat ~/.cf/config.json | jq -r .SpaceFields.GUID)
# refresh access token
cf curl "/v2/spaces/$space_guid" &>/dev/null
cf curl "/v3/spaces/$space_guid" &>/dev/null
# access token
auth_header=$(cat ~/.cf/config.json | jq -r .AccessToken)
}
Expand Down
6 changes: 3 additions & 3 deletions broker/core/platform-managers/src/CfPlatformManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class CfPlatformManager extends BasePlatformManager {
return Promise.resolve(true);
}
return this.cloudController.getSpace(options.bind_resource.space_guid)
.tap(targetSpaceDetails => logger.info(`shared instance binding: source instance organization: ${options.context.organization_guid}; target organization: ${targetSpaceDetails.entity.organization_guid}`))
.tap(targetSpaceDetails => logger.info(`shared instance binding: source instance organization: ${options.context.organization_guid}; target organization: ${targetSpaceDetails.relationships.organization.data.guid}`))
.then(targetSpaceDetails => {
if (options.context.organization_guid !== targetSpaceDetails.entity.organization_guid) {
if (options.context.organization_guid !== targetSpaceDetails.relationships.organization.data.guid) {
throw new CrossOrganizationSharingNotAllowed();
}
return true;
Expand Down Expand Up @@ -208,7 +208,7 @@ class CfPlatformManager extends BasePlatformManager {
const orgId = _.get(options, 'context.organization_guid');
assert.ok(orgId, 'OrgId must be present when checking for whitelisting of Tenant in CF Context');
return this.cloudController.getOrganization(orgId)
.then(org => _.includes(config.quota.whitelist, org.entity.name))
.then(org => _.includes(config.quota.whitelist, org.name))
.tap(result => logger.info(`Current org - ${orgId} is whitelisted: ${result}`));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,12 @@ describe('fabrik', function () {
before(function () {
getSpaceStub = sinon.stub(cloudController, 'getSpace').callsFake(() => {
return Promise.resolve({
entity: {
organization_guid: 'target'
relationships:{
organization:{
data:{
guid: 'target'
}
}
}
});
});
Expand Down Expand Up @@ -369,9 +373,7 @@ describe('fabrik', function () {
before(function () {
getOrgStub = sinon.stub(cloudController, 'getOrganization').callsFake(() => {
return Promise.resolve({
entity: {
name: 'test'
}
name: 'test'
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1416,9 +1416,7 @@ describe('#DirectorService', function () {
type: CONST.BACKUP.TYPE.ONLINE,
repeatInterval: '8 hours'
});
mocks.cloudController.getSpace(target_space_guid, {
'organization_guid': organization_guid
});
mocks.cloudController.getSpace(target_space_guid, organization_guid);
mocks.cloudController.createSecurityGroup(binding_id);
const options = {
binding_id: binding_id,
Expand Down
16 changes: 8 additions & 8 deletions broker/data-access-layer/cf/src/CloudControllerClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,15 @@ class CloudControllerClient extends HttpClient {
}

createSpaceStream(options) {
return this.createResourceStream('/v2/spaces', options);
return this.createResourceStream('/v3/spaces', options);
}

getSpaces(options) {
return this.createSpaceStream(options).all();
}

getSpace(space_guid, options) {
return this.getResource(`/v2/spaces/${space_guid}`, options);
return this.getResource(`/v3/spaces/${space_guid}`, options);
}

getOrgAndSpaceGuid(instance_guid, space_guid) {
Expand All @@ -273,9 +273,9 @@ class CloudControllerClient extends HttpClient {
.getServiceInstance(instance_guid)
.then(instance => this.getSpace(instance.entity.space_guid)))
.then(space => ({
space_name: space.entity.name,
space_guid: space.metadata.guid,
organization_guid: space.entity.organization_guid
space_name: space.name,
space_guid: space.guid,
organization_guid: space.relationships.organization.data.guid
}));
}

Expand All @@ -291,23 +291,23 @@ class CloudControllerClient extends HttpClient {
return this.getOrganization(data.organization_guid)
.then(org => {
_.assign(data, {
organization_name: org.entity.name
organization_name: org.name
});
return data;
});
});
}

createOrganizationStream(options) {
return this.createResourceStream('/v2/organizations', options);
return this.createResourceStream('/v3/organizations', options);
}

getOrganizations(options) {
return this.createOrganizationStream(options).all();
}

getOrganization(org_guid, options) {
return this.getResource(`/v2/organizations/${org_guid}`, options);
return this.getResource(`/v3/organizations/${org_guid}`, options);
}

getResource(pathname, options) {
Expand Down
49 changes: 39 additions & 10 deletions broker/data-access-layer/cf/test/cf.CloudControllerClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ describe('cf', function () {
},
responseType: 'json'
};
if (path.slice(0,7) == '/spaces' || path.slice(0,7) == '/organi') {
options.url = '/v3' + path
}

if (_.isObject(statusCode)) {
data = statusCode;
statusCode = undefined;
Expand Down Expand Up @@ -288,7 +292,7 @@ describe('cf', function () {
const calls = _.range(7);

function url(i) {
const firstUrl = '/v2/spaces?results-per-page=1';
const firstUrl = '/v3/spaces?results-per-page=1';
if (i === 0) {
return firstUrl;
}
Expand Down Expand Up @@ -357,35 +361,60 @@ describe('cf', function () {
});

describe('#getOrgAndSpaceDetails', function () {

// Response of Get a space and Get an organization into one
const SOresponse = {
guid: id,
name: name,
relationships:{
organization:{
data:{
guid: id
}
}
}
}
let spaceReqSpy, orgReqSpy;


const [optionsInstance, statusCodeInstance] = buildExpectedRequestArgs('GET', `/service_instances/${id}`);
const [optionsSpace, statusCodeSpace] = buildExpectedRequestArgs('GET', `/spaces/${id}`);
const [optionsOrg, statusCodeOrg] = buildExpectedRequestArgs('GET', `/organizations/${id}`);
//const [optionsSpace, statusCodeSpace] = buildExpectedRequestArgs('GET', `/spaces/${id}`);
//const [optionsOrg, statusCodeOrg] = buildExpectedRequestArgs('GET', `/organizations/${id}`);
const expectedResult = {
space_guid: id,
space_name: name,
organization_guid: id,
organization_name: name
};
beforeEach(function () {
spaceReqSpy = sinon.stub(cloudController, 'getSpace');
spaceReqSpy.returns(Promise.resolve(SOresponse));
orgReqSpy = sinon.stub(cloudController, 'getOrganization');
orgReqSpy.returns(Promise.resolve(SOresponse));
});
afterEach(function () {
spaceReqSpy.restore();
orgReqSpy.restore();
});
it('should return the JSON body with Status 200', function () {
return cloudController.getOrgAndSpaceDetails(id)
.then(result => {
expect(getAccessTokenSpy.callCount).to.equal(3);
expect(getAccessTokenSpy.callCount).to.equal(1);
expect(requestSpy.getCall(0)).to.be.calledWithExactly(optionsInstance, statusCodeInstance);
expect(requestSpy.getCall(1)).to.be.calledWithExactly(optionsSpace, statusCodeSpace);
expect(requestSpy.getCall(2)).to.be.calledWithExactly(optionsOrg, statusCodeOrg);
//expect(spaceReqSpy.getCall(1)).to.be.calledWithExactly(optionsSpace, statusCodeSpace);
//expect(orgReqSpy.getCall(2)).to.be.calledWithExactly(optionsOrg, statusCodeOrg);
expect(result).to.deep.equal(expectedResult);
});
});
it('should return the JSON body with Status 200', function () {
return cloudController.getOrgAndSpaceDetails(id, id)
.then(result => {
expect(getAccessTokenSpy).to.be.calledTwice;
expect(requestSpy.getCall(0)).to.be.calledWithExactly(optionsSpace, statusCodeSpace);
expect(requestSpy.getCall(1)).to.be.calledWithExactly(optionsOrg, statusCodeOrg);
//expect(getAccessTokenSpy).to.be.calledTwice;
//expect(spaceReqSpy.getCall(0)).to.be.calledWithExactly(optionsSpace, statusCodeSpace);
//expect(orgReqSpy.getCall(1)).to.be.calledWithExactly(optionsOrg, statusCodeOrg);
expect(result).to.deep.equal(expectedResult);
});
});
});

});
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CFPlatformQuotaManager extends BaseQuotaManager {

async isOrgWhitelisted(orgId) {
const org = await cloudController.getOrganization(orgId);
const orgLower = _.toLower(org.entity.name);
const orgLower = _.toLower(org.name);
logger.debug('current org details are ', org);
logger.debug('current org name is ', orgLower);
logger.debug('Whitelisted orgs are ', config.quota.whitelist);
Expand Down
10 changes: 3 additions & 7 deletions broker/data-access-layer/quota/test/quota.QuotaManager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ describe('quota', () => {
},
'tags': [],
'service_guid': 'fe503379-832b-4d56-ad12-3a6ef68dcb34',
'space_url': '/v2/spaces/6b48f3ea-0ef1-44eb-9de4-942d89779d37',
'space_url': '/v3/spaces/6b48f3ea-0ef1-44eb-9de4-942d89779d37',
'service_plan_url': '/v2/service_plans/cb862bfe-3a50-4d12-a8e2-156d6e11bed4',
'service_bindings_url': '/v2/service_instances/001ca5e5-2aeb-47c5-a063-567bdfe942ec/service_bindings',
'service_keys_url': '/v2/service_instances/001ca5e5-2aeb-47c5-a063-567bdfe942ec/service_keys',
Expand Down Expand Up @@ -444,12 +444,8 @@ describe('quota', () => {
let sandbox, getOrganizationStub;
let orgId = '63125bbc-81fe-46c3-9437-e5a8a6594774';
let org = {
'metadata': {
'guid': '63125bbc-81fe-46c3-9437-e5a8a6594774'
},
'entity': {
'name': 'Dev'
}
'guid': '63125bbc-81fe-46c3-9437-e5a8a6594774',
'name': 'Dev'
};
before(function () {
sandbox = sinon.createSandbox();
Expand Down
2 changes: 1 addition & 1 deletion broker/test/init
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ main(){
esac
}

main "${@:1}"
main "${@:1}"
Loading

0 comments on commit 310fa50

Please sign in to comment.