Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/provisioning/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,16 @@ function generate_access_key(sub_account_id, options = {}, callback) {
* @param [callback] {function}
*/
function update_access_key(sub_account_id, api_key, options = {}, callback) {
const params = pickOnlyExistingValues({
name: options.name,
enabled: options.enabled
}, 'name', 'enabled');
const params = pickOnlyExistingValues(
{
name: options.name,
enabled: options.enabled,
dedicated_for: options.dedicated_for
},
'name',
'enabled',
'dedicated_for'
);
options.content_type = "json";
const uri = ['sub_accounts', sub_account_id, 'access_keys', api_key];
return call_account_api('PUT', uri, params, callback, options);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"scripts": {
"test": "tools/scripts/test.sh",
"test:unit": "tools/scripts/test.es6.unit.sh",
"test:provisioning": "mocha \"./test/integration/api/provisioning/*.js\"",
"test-with-temp-cloud": "tools/scripts/tests-with-temp-cloud.sh",
"dtslint": "tools/scripts/ditslint.sh",
"lint": "tools/scripts/lint.sh",
Expand Down
66 changes: 49 additions & 17 deletions test/integration/api/provisioning/access_keys_spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable no-mixed-spaces-and-tabs */
/* eslint-disable no-tabs */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't disable eslint rules

const cloudinary = require("../../../../cloudinary");
const expect = require('expect.js');
const TIMEOUT = require('../../../testUtils/testConstants').TIMEOUT;
let runOnlyForInternalPRs = process.env.TRAVIS_SECURE_ENV_VARS ? describe : describe.skip;


describe.skip('Provisioning API - Access Keys Management', function () {
let CLOUD_SECRET;
Expand All @@ -11,7 +12,7 @@ describe.skip('Provisioning API - Access Keys Management', function () {
let CLOUD_NAME_PREFIX = `justaname${process.hrtime()[1] % 10000}`;
this.timeout(TIMEOUT.LONG);

before("Setup the required test", async () => {
before("Setup the required test", async function (){
let config = cloudinary.config(true);
if (!(config.provisioning_api_key && config.provisioning_api_secret && config.account_id)) {
// For external PRs the env variables are not availble, so we skip the provisioning API
Expand Down Expand Up @@ -48,30 +49,30 @@ describe.skip('Provisioning API - Access Keys Management', function () {
const accessKeys = await cloudinary.provisioning.account.access_keys(CLOUD_ID);
expect(Object.keys(accessKeys)).to.eql(['access_keys', 'total']);
expect(accessKeys.access_keys.length).to.eql(1);
expect(Object.keys(accessKeys.access_keys[0])).to.eql(['name', 'api_key', 'api_secret', 'created_at', 'updated_at', 'enabled']);
expect(Object.keys(accessKeys.access_keys[0])).to.eql(['name', 'api_key', 'api_secret', 'created_at', 'updated_at', 'enabled', 'root']);
});

it('Generate new access key', async () => {
const keyName = `test-access-key-${Date.now()}`
const newAccessKey = await cloudinary.provisioning.account.generate_access_key(CLOUD_ID, { name: keyName });
expect(Object.keys(newAccessKey)).to.eql(['name', 'api_key', 'api_secret', 'created_at', 'updated_at', 'enabled']);
expect(Object.keys(newAccessKey)).to.eql(['name', 'api_key', 'api_secret', 'created_at', 'updated_at', 'enabled', 'root']);
expect(newAccessKey.name).to.eql(keyName);
});

it('List access keys with optional query params', async () => {
const keyName1 = `A-test-access-key-${Date.now()}`
const newAccessKey1 = await cloudinary.provisioning.account.generate_access_key(CLOUD_ID, { name: keyName1 });
expect(Object.keys(newAccessKey1)).to.eql(['name', 'api_key', 'api_secret', 'created_at', 'updated_at', 'enabled']);
expect(Object.keys(newAccessKey1)).to.eql(['name', 'api_key', 'api_secret', 'created_at', 'updated_at', 'enabled', 'root']);
expect(newAccessKey1.name).to.eql(keyName1);

const keyName2 = `B-test-access-key-${Date.now()}`
const newAccessKey2 = await cloudinary.provisioning.account.generate_access_key(CLOUD_ID, { name: keyName2 });
expect(Object.keys(newAccessKey2)).to.eql(['name', 'api_key', 'api_secret', 'created_at', 'updated_at', 'enabled']);
expect(Object.keys(newAccessKey2)).to.eql(['name', 'api_key', 'api_secret', 'created_at', 'updated_at', 'enabled', 'root']);
expect(newAccessKey2.name).to.eql(keyName2);

const keyName3 = `C-test-access-key-${Date.now()}`
const newAccessKey3 = await cloudinary.provisioning.account.generate_access_key(CLOUD_ID, { name: keyName3 });
expect(Object.keys(newAccessKey3)).to.eql(['name', 'api_key', 'api_secret', 'created_at', 'updated_at', 'enabled']);
expect(Object.keys(newAccessKey3)).to.eql(['name', 'api_key', 'api_secret', 'created_at', 'updated_at', 'enabled', 'root']);
expect(newAccessKey3.name).to.eql(keyName3);

const pageSize = 2;
Expand All @@ -83,25 +84,56 @@ describe.skip('Provisioning API - Access Keys Management', function () {
});
expect(Object.keys(accessKeys)).to.eql(['access_keys', 'total']);
expect(accessKeys.access_keys.length).to.eql(pageSize);
expect(Object.keys(accessKeys.access_keys[0])).to.eql(['name', 'api_key', 'api_secret', 'created_at', 'updated_at', 'enabled']);
expect(Object.keys(accessKeys.access_keys[0])).to.eql(['name', 'api_key', 'api_secret', 'created_at', 'updated_at', 'enabled', 'root']);
});

it('Update access key', async () => {
const keyName = `test-access-key-${Date.now()}`
const newAccessKey = await cloudinary.provisioning.account.generate_access_key(CLOUD_ID, { name: keyName });
expect(Object.keys(newAccessKey)).to.eql(['name', 'api_key', 'api_secret', 'created_at', 'updated_at', 'enabled']);
it("Update access key", async () => {
const keyName = `test-access-key-${Date.now()}`;
const newAccessKey =
await cloudinary.provisioning.account.generate_access_key(
CLOUD_ID,
{ name: keyName, enabled: false }
);
expect(Object.keys(newAccessKey)).to.eql([
'name',
'api_key',
'api_secret',
'created_at',
'updated_at',
'enabled',
'root'
]);
expect(newAccessKey.name).to.eql(keyName);
expect(newAccessKey.enabled).to.eql(false);

const newName = `${keyName}-updated`;
const updatedAccessKey = await cloudinary.provisioning.account.update_access_key(CLOUD_ID, newAccessKey.api_key, { name: newName });
expect(Object.keys(newAccessKey)).to.eql(['name', 'api_key', 'api_secret', 'created_at', 'updated_at', 'enabled']);
const updatedAccessKey =
await cloudinary.provisioning.account.update_access_key(
CLOUD_ID,
newAccessKey.api_key,
{ name: newName, enabled: true, dedicated_for: "webhooks" }
);
expect(Object.keys(updatedAccessKey)).to.eql([
'name',
'api_key',
'api_secret',
'created_at',
'updated_at',
'enabled',
'dedicated_for',
'root'
]);
expect(updatedAccessKey.name).to.eql(newName);
expect(updatedAccessKey.enabled).to.eql(true);
expect(updatedAccessKey.dedicated_for).to.be.an("array");
expect(updatedAccessKey.dedicated_for.length).to.eql(1);
expect(updatedAccessKey.dedicated_for[0]).to.eql("webhooks");
});

it('Delete access keys', async () => {
const keyName = `test-access-key-${Date.now()}`
const newAccessKey = await cloudinary.provisioning.account.generate_access_key(CLOUD_ID, { name: keyName });
expect(Object.keys(newAccessKey)).to.eql(['name', 'api_key', 'api_secret', 'created_at', 'updated_at', 'enabled']);
expect(Object.keys(newAccessKey)).to.eql(['name', 'api_key', 'api_secret', 'created_at', 'updated_at', 'enabled', 'root']);
expect(newAccessKey.name).to.eql(keyName);

const deleteAccessKey = await cloudinary.provisioning.account.delete_access_key(CLOUD_ID, newAccessKey.api_key);
Expand All @@ -112,7 +144,7 @@ describe.skip('Provisioning API - Access Keys Management', function () {
it('Delete access keys by name', async () => {
const keyName = `test-access-key-${Date.now()}`
const newAccessKey = await cloudinary.provisioning.account.generate_access_key(CLOUD_ID, { name: keyName });
expect(Object.keys(newAccessKey)).to.eql(['name', 'api_key', 'api_secret', 'created_at', 'updated_at', 'enabled']);
expect(Object.keys(newAccessKey)).to.eql(['name', 'api_key', 'api_secret', 'created_at', 'updated_at', 'enabled', 'root']);
expect(newAccessKey.name).to.eql(keyName);

const deleteAccessKey = await cloudinary.provisioning.account.delete_access_key_by_name(CLOUD_ID, { name: keyName });
Expand Down
5 changes: 2 additions & 3 deletions test/integration/api/provisioning/account_spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const cloudinary = require("../../../../cloudinary");
const expect = require('expect.js');
const TIMEOUT = require('../../../testUtils/testConstants').TIMEOUT;
let runOnlyForInternalPRs = process.env.TRAVIS_SECURE_ENV_VARS ? describe : describe.skip;


runOnlyForInternalPRs('account API - Provisioning', function () {
describe.skip('account API - Provisioning', function () {
let CLOUD_SECRET;
let CLOUD_API;
let CLOUD_NAME;
Expand Down
3 changes: 2 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,8 @@ declare module 'cloudinary' {

function update_access_key(subAccountId: string, apiKey: string, options?: ProvisioningApiOptions | {
name?: string,
enabled?: boolean
enabled?: boolean,
dedicated_for?: string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dedicated_for?: string
dedicated_for?: 'webhooks'

}, callback?: ResponseCallback): Promise<AccessKeyDetails>;

function delete_access_key(subAccountId: string, apiKey: string, options?: ProvisioningApiOptions, callback?: ResponseCallback): Promise<DeleteAccessKeyResponse>;
Expand Down