Skip to content

Commit 032f342

Browse files
Add project id to namespace API call (#118)
1 parent 88c9ad6 commit 032f342

File tree

13 files changed

+23
-21
lines changed

13 files changed

+23
-21
lines changed

deploy/lib/createNamespace.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const secrets = require('../../shared/secrets');
66
module.exports = {
77
createServerlessNamespace() {
88
return BbPromise.bind(this)
9-
.then(() => this.getNamespaceFromList(this.namespaceName))
9+
.then(() => this.getNamespaceFromList(this.namespaceName, this.provider.getScwProject()))
1010
.then(this.createIfNotExists);
1111
},
1212

info/lib/display.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = {
66
displayInfo() {
77
const configInput = this.serverless.configurationInput;
88

9-
this.getNamespaceFromList(configInput.service).then((namespace) => {
9+
this.getNamespaceFromList(configInput.service, this.provider.getScwProject()).then((namespace) => {
1010
if (namespace === undefined || namespace === null ||
1111
namespace.id === undefined || namespace.id === null) {
1212
return;

invoke/scalewayInvoke.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class ScalewayInvoke {
7272
.then(this.validate),
7373
'invoke:invoke': () => BbPromise.bind(this)
7474
.then(validateFunctionOrContainer)
75-
.then(() => this.getNamespaceFromList(this.namespaceName))
75+
.then(() => this.getNamespaceFromList(this.namespaceName, this.provider.getScwProject()))
7676
.then(lookUpFunctionOrContainer)
7777
.then(doInvoke)
7878
};

jwt/lib/getJwt.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ module.exports = {
77
getJwt() {
88
if (typeof this.listFunctions === 'function') {
99
return BbPromise.bind(this)
10-
.then(() => this.getNamespaceFromList(this.namespaceName))
10+
.then(() => this.getNamespaceFromList(this.namespaceName, this.provider.getScwProject()))
1111
.then(this.setNamespace)
1212
.then(this.getJwtNamespace)
1313
.then(() => this.listFunctions(this.namespace.id))
1414
.then(this.getJwtFunctions);
1515
} if (typeof this.listContainers === 'function') {
1616
return BbPromise.bind(this)
17-
.then(() => this.getNamespaceFromList(this.namespaceName))
17+
.then(() => this.getNamespaceFromList(this.namespaceName, this.provider.getScwProject()))
1818
.then(this.setNamespace)
1919
.then(this.getJwtNamespace)
2020
.then(() => this.listContainers(this.namespace.id))

logs/lib/getLogs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const BbPromise = require('bluebird');
55
module.exports = {
66
getLogs() {
77
return BbPromise.bind(this)
8-
.then(() => this.getNamespaceFromList(this.namespaceName))
8+
.then(() => this.getNamespaceFromList(this.namespaceName, this.provider.getScwProject()))
99
.then(this.listApplications)
1010
.all()
1111
.then(this.getApplicationId)

remove/lib/removeNamespace.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = {
66
removeNamespace() {
77
this.serverless.cli.log('Removing namespace and associated functions/triggers...');
88
return BbPromise.bind(this)
9-
.then(() => this.getNamespaceFromList(this.namespaceName))
9+
.then(() => this.getNamespaceFromList(this.namespaceName, this.provider.getScwProject()))
1010
.then(this.removeSingleNamespace);
1111
},
1212

shared/api/namespaces.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33
const { manageError } = require('./utils');
44

55
module.exports = {
6-
listNamespaces() {
7-
return this.apiManager.get('namespaces?page_size=100')
6+
listNamespaces(projectId) {
7+
const projectIdReq = projectId === undefined ? '' : `&project_id=${projectId}`;
8+
return this.apiManager.get(`namespaces?page_size=100${projectIdReq}`)
89
.then(response => response.data.namespaces || [])
910
.catch(manageError);
1011
},
1112

12-
getNamespaceFromList(namespaceName) {
13+
getNamespaceFromList(namespaceName, projectId) {
14+
const projectIdReq = projectId === undefined ? '' : `&project_id=${projectId}`;
1315
// query Scaleway API to check if space exists
14-
return this.apiManager.get(`namespaces?name=${namespaceName}`)
16+
return this.apiManager.get(`namespaces?name=${namespaceName}${projectIdReq}`)
1517
.then((response) => {
1618
const { namespaces } = response.data;
17-
return namespaces.find(ns => ns.name === namespaceName);
19+
return namespaces[0];
1820
})
1921
.catch(manageError);
2022
},

tests/containers/containers.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe('Service Lifecyle Integration Test', () => {
5555

5656
it('should deploy service/container to scaleway', async () => {
5757
serverlessDeploy();
58-
namespace = await api.getNamespaceFromList(serviceName);
58+
namespace = await api.getNamespaceFromList(serviceName, scwProject);
5959
namespace.containers = await api.listContainers(namespace.id);
6060
expect(namespace.containers[0].description).to.be.equal(descriptionTest);
6161
containerName = namespace.containers[0].name;

tests/containers/containers_private_registry.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ describe('Build and deploy on container with a base image private', () => {
8282

8383
it('should deploy service/container to scaleway', async () => {
8484
serverlessDeploy();
85-
namespace = await api.getNamespaceFromList(serviceName);
85+
namespace = await api.getNamespaceFromList(serviceName, scwProject);
8686
namespace.containers = await api.listContainers(namespace.id);
8787
containerName = namespace.containers[0].name;
8888
});

tests/functions/functions.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ describe('Service Lifecyle Integration Test', () => {
5959

6060
it('should deploy service to scaleway', async () => {
6161
serverlessDeploy();
62-
namespace = await api.getNamespaceFromList(serviceName);
62+
namespace = await api.getNamespaceFromList(serviceName, scwProject);
6363
namespace.functions = await api.listFunctions(namespace.id);
64-
expect(namespace.containers[0].description).to.be.equal(descriptionTest);
64+
expect(namespace.functions[0].description).to.be.equal(descriptionTest);
6565
functionName = namespace.functions[0].name;
6666
});
6767

tests/multi-region/multi_region.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe.each(regions)(
4343
apiUrl = `${FUNCTIONS_API_URL}/${region}`;
4444
api = new FunctionApi(apiUrl, scwToken);
4545
serverlessDeploy({ env: { SCW_REGION: region } });
46-
namespace = await api.getNamespaceFromList(serviceName);
46+
namespace = await api.getNamespaceFromList(serviceName, scwProject);
4747
namespace.functions = await api.listFunctions(namespace.id);
4848

4949
// Invoke function

tests/runtimes/runtimes.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ describe.each(exampleRepositories)(
6262
// If runtime is container => get container
6363
if (isContainer) {
6464
api = new ContainerApi(containerApiUrl, scwToken);
65-
namespace = await api.getNamespaceFromList(runtimeServiceName);
65+
namespace = await api.getNamespaceFromList(runtimeServiceName, scwProject);
6666
namespace.containers = await api.listContainers(namespace.id);
6767
} else {
6868
api = new FunctionApi(functionApiUrl, scwToken);
69-
namespace = await api.getNamespaceFromList(runtimeServiceName);
69+
namespace = await api.getNamespaceFromList(runtimeServiceName, scwProject);
7070
namespace.functions = await api.listFunctions(namespace.id);
7171
}
7272
});

tests/triggers/triggers.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ describe.each(runtimesToTest)(
5757
serverlessDeploy();
5858
if (runtime.isFunction) {
5959
api = new FunctionApi(functionApiUrl, scwToken);
60-
namespace = await api.getNamespaceFromList(runtimeServiceName);
60+
namespace = await api.getNamespaceFromList(runtimeServiceName, scwProject);
6161
namespace.functions = await api.listFunctions(namespace.id);
6262
} else {
6363
api = new ContainerApi(containerApiUrl, scwToken);
64-
namespace = await api.getNamespaceFromList(runtimeServiceName);
64+
namespace = await api.getNamespaceFromList(runtimeServiceName, scwProject);
6565
namespace.containers = await api.listContainers(namespace.id);
6666
}
6767
});

0 commit comments

Comments
 (0)