/**
* Function to update the L3 firewall rules of a Meraki network.
*
* @param {Object} args - Arguments for updating firewall rules.
* @param {string} args.networkId - The ID of the network to update.
* @param {Array<Object>} args.rules - The firewall rules to apply.
* @param {boolean} args.syslogDefaultRule - The default rule for syslog.
* @returns {Promise<Object>} - The result of the update operation.
*/
const executeFunction = async ({ networkId, rules, syslogDefaultRule }) => {
const baseUrl = 'https://api.meraki.com/api/v1';
const token = process.env.CISCO_MERAKI_S_PUBLIC_WORKSPACE_API_KEY;
try {
const url = `${baseUrl}/networks/${networkId}/appliance/firewall/l3FirewallRules`;
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': `Bearer ${token}`
};
const body = JSON.stringify({
rules,
syslogDefaultRule
});
const response = await fetch(url, {
method: 'PUT',
headers,
body
});
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData);
}
const data = await response.json();
return data;
} catch (error) {
console.error('Error updating firewall rules:', error);
return { error: 'An error occurred while updating firewall rules.' };
}
};
/**
* Tool configuration for updating L3 firewall rules on a Meraki network.
* @type {Object}
*/
const apiTool = {
function: executeFunction,
definition: {
type: 'function',
function: {
name: 'updateNetworkApplianceFirewallL3FirewallRules',
description: 'Update the L3 firewall rules of an MX network.',
parameters: {
type: 'object',
properties: {
networkId: {
type: 'string',
description: 'The ID of the network to update.'
},
rules: {
type: 'array',
items: {
type: 'object',
properties: {
policy: {
type: 'string',
description: 'The policy for the rule (allow/deny).'
},
protocol: {
type: 'string',
description: 'The protocol for the rule (e.g., tcp, udp).'
},
srcCidr: {
type: 'string',
description: 'The source CIDR for the rule.'
},
destCidr: {
type: 'string',
description: 'The destination CIDR for the rule.'
},
comment: {
type: 'string',
description: 'A comment for the rule.'
},
srcPort: {
type: 'string',
description: 'The source port for the rule.'
},
destPort: {
type: 'string',
description: 'The destination port for the rule.'
},
syslogEnabled: {
type: 'boolean',
description: 'Whether syslog is enabled for the rule.'
}
},
required: ['policy', 'protocol', 'srcCidr', 'destCidr']
},
description: 'The firewall rules to apply.'
},
syslogDefaultRule: {
type: 'boolean',
description: 'The default rule for syslog.'
}
},
required: ['networkId', 'rules', 'syslogDefaultRule']
}
}
}
};
export { apiTool };