Skip to content

Commit

Permalink
update url logic for groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Stamsy committed Dec 12, 2024
1 parent 681f65c commit da904fd
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 53 deletions.
38 changes: 36 additions & 2 deletions packages/nodes-base/nodes/Aws/IAM/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export async function presendFields(

let url = requestOptions.url;

// Logic for user operations
if (url.includes('ListUsers')) {
const prefix = additionalFields.PathPrefix;
if (prefix) url += `&PathPrefix=${prefix}`;
Expand Down Expand Up @@ -75,7 +76,8 @@ export async function presendFields(

url += `&${tagString}`;
}
} else {
} else if (url.includes('User')) {
// Logic for other user-related operations like AddUserToGroup, RemoveUserFromGroup, etc.
const userNameParam = this.getNodeParameter('UserName') as { mode: string; value: string };
userName = userNameParam.value;
url += `&UserName=${userName}`;
Expand Down Expand Up @@ -104,8 +106,40 @@ export async function presendFields(
}
}

requestOptions.url = url;
// Logic for group operations (Create, Update, etc.)
if (url.includes('CreateGroup')) {
groupName = this.getNodeParameter('GroupName') as string;
console.log(groupName);
url += `&GroupName=${groupName}`;

if (options.Path) {
url += `&Path=${options.Path}`;
}
} else if (url.includes('GetGroup') || url.includes('DeleteGroup')) {
const groupNameParam = this.getNodeParameter('GroupName') as { mode: string; value: string };
groupName = groupNameParam.value;
url += `&GroupName=${groupName}`;
} else if (url.includes('UpdateGroup')) {
const groupNameParam = this.getNodeParameter('GroupName') as { mode: string; value: string };
groupName = groupNameParam.value;
url += `&GroupName=${groupName}`;
const hasOptions = options.NewGroupName || options.NewPath;

if (!hasOptions) {
throw new NodeOperationError(
this.getNode(),
'At least one of the options (NewGroupName or Path) must be provided to update the group.',
);
}

if (options.NewGroupName) {
url += `&NewGroupName=${options.NewGroupName}`;
}
if (options.NewPath) {
url += `&NewPath=${options.NewPath}`;
}
}
requestOptions.url = url;
return requestOptions;
}

Expand Down
93 changes: 42 additions & 51 deletions packages/nodes-base/nodes/Aws/IAM/descriptions/GroupDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { INodeProperties } from 'n8n-workflow';
import {
handleErrorPostReceive,
handlePagination,
presendFields,
processGroupsResponse,
} from '../GenericFunctions';

Expand All @@ -24,9 +25,12 @@ export const groupOperations: INodeProperties[] = [
value: 'create',
description: 'Create a new group',
routing: {
send: {
preSend: [presendFields],
},
request: {
method: 'POST',
url: '=/?Action=CreateGroup&Version=2010-05-08&GroupName={{$parameter["GroupName"]}}&Path={{$parameter["options.path"]}}',
url: '/?Action=CreateGroup&Version=2010-05-08',
ignoreHttpStatusErrors: true,
},
output: {
Expand All @@ -40,9 +44,12 @@ export const groupOperations: INodeProperties[] = [
value: 'delete',
description: 'Delete an existing group',
routing: {
send: {
preSend: [presendFields],
},
request: {
method: 'POST',
url: '=/?Action=DeleteGroup&Version=2010-05-08&GroupName={{$parameter["GroupName"]}}',
url: '/?Action=DeleteGroup&Version=2010-05-08',
ignoreHttpStatusErrors: true,
},
output: {
Expand All @@ -56,9 +63,12 @@ export const groupOperations: INodeProperties[] = [
value: 'get',
description: 'Retrieve details of an existing group',
routing: {
send: {
preSend: [presendFields],
},
request: {
method: 'POST',
url: '=/?Action=GetGroup&Version=2010-05-08&GroupName={{$parameter["GroupName"]}}',
url: '/?Action=GetGroup&Version=2010-05-08',
ignoreHttpStatusErrors: true,
},
output: {
Expand All @@ -73,14 +83,15 @@ export const groupOperations: INodeProperties[] = [
description: 'Retrieve a list of groups',
routing: {
send: {
preSend: [presendFields],
paginate: true,
},
operations: {
pagination: handlePagination,
},
request: {
method: 'POST',
url: '=/?Action=ListGroups&Version=2010-05-08',
url: '/?Action=ListGroups&Version=2010-05-08',
qs: {
pageSize:
'={{ $parameter["limit"] ? ($parameter["limit"] < 60 ? $parameter["limit"] : 60) : 60 }}',
Expand All @@ -98,9 +109,12 @@ export const groupOperations: INodeProperties[] = [
value: 'update',
description: 'Update an existing group',
routing: {
send: {
preSend: [presendFields],
},
request: {
method: 'POST',
url: '=/?Action=UpdateGroup&GroupName={{$parameter["GroupName"]}}&NewGroupName={{$parameter["NewGroupName"]}}&Version=2010-05-08&Path={{$parameter["options.path"]}}',
url: '/?Action=UpdateGroup&Version=2010-05-08',
ignoreHttpStatusErrors: true,
},
output: {
Expand Down Expand Up @@ -143,11 +157,12 @@ const createFields: INodeProperties[] = [
options: [
{
displayName: 'Path',
name: 'path',
name: 'Path',
type: 'string',
default: '/',
default: '',
placeholder: 'e.g. /division_abc/engineering/',
description: 'The path to the group, if it is not included, it defaults to a slash (/)',
validateType: 'string',
},
],
placeholder: 'Add Option',
Expand Down Expand Up @@ -182,7 +197,7 @@ const deleteFields: INodeProperties[] = [
},
{
displayName: 'By Name',
name: 'GroupName', //TODO Check if we can delete group by id
name: 'GroupName',
type: 'string',
hint: 'Enter the group name',
validation: [
Expand Down Expand Up @@ -230,7 +245,7 @@ const getFields: INodeProperties[] = [
},
},
{
displayName: 'By Name', //TODO Try find a way to get group by id
displayName: 'By Name',
name: 'GroupName',
type: 'string',
hint: 'Enter the group name',
Expand Down Expand Up @@ -288,27 +303,6 @@ const getAllFields: INodeProperties[] = [
},
validateType: 'number',
},
//TODO Check whether we can add some filters and options about the fields to return
{
displayName: 'Simplified',
name: 'simplified',
type: 'boolean',
default: false,
description: 'Whether simplify the response if there are more than 10 fields',
displayOptions: {
show: {
resource: ['group'],
operation: ['getAll'],
},
},
routing: {
send: {
property: '$select',
type: 'query',
value: 'CreatedDate,Description,GroupName,LastModifiedDate,Precedence,',
},
},
},
];

const updateFields: INodeProperties[] = [
Expand Down Expand Up @@ -337,8 +331,8 @@ const updateFields: INodeProperties[] = [
},
},
{
displayName: 'By Name', //TODO Try to get group by id
name: 'GroupName',
displayName: 'By Name',
name: 'Group Name',
type: 'string',
hint: 'Enter the group name',
validation: [
Expand All @@ -356,22 +350,6 @@ const updateFields: INodeProperties[] = [
required: true,
type: 'resourceLocator',
},
{
displayName: 'New Name',
name: 'NewGroupName',
default: '',
placeholder: 'e.g. My New Group',
description: 'The new name of the group',
displayOptions: {
show: {
resource: ['group'],
operation: ['update'],
},
},
required: true,
type: 'string',
validateType: 'string',
},
{
displayName: 'Options',
name: 'options',
Expand All @@ -384,12 +362,25 @@ const updateFields: INodeProperties[] = [
},
options: [
{
displayName: 'Path',
name: 'path',
displayName: 'New Name',
name: 'NewGroupName',
default: '',
placeholder: 'e.g. My New Group',
description: 'The new name of the group',
type: 'string',
typeOptions: {
regex: '^[a-zA-Z0-9+=,.@_-]+$',
},
validateType: 'string',
},
{
displayName: 'New Path',
name: 'NewPath',
type: 'string',
default: '/',
default: '',
placeholder: 'e.g. /division_abc/engineering/',
description: 'The path to the group, if it is not included, it defaults to a slash (/)',
validateType: 'string',
},
],
placeholder: 'Add Option',
Expand Down

0 comments on commit da904fd

Please sign in to comment.