Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
47 changes: 39 additions & 8 deletions test/integration/api/provisioning/access_keys_spec.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/* 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 TIMEOUT = require('../../../testUtils/testConstants').TIMEOUT;
let runOnlyForInternalPRs = process.env.TRAVIS_SECURE_ENV_VARS ? describe : describe.skip;


describe.skip('Provisioning API - Access Keys Management', function () {
describe('Provisioning API - Access Keys Management', function () {
let CLOUD_SECRET;
let CLOUD_API;
let CLOUD_NAME;
let CLOUD_ID;
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 @@ -86,16 +88,45 @@ describe.skip('Provisioning API - Access Keys Management', function () {
expect(Object.keys(accessKeys.access_keys[0])).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 });
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"
]);
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"
]);
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 () => {
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