/**
* Function to update the MX L7 firewall rules for a specified network.
*
* @param {Object} args - Arguments for updating the firewall rules.
* @param {string} args.networkId - The ID of the network to update.
* @param {Array<Object>} args.rules - An array of rule objects to apply.
* @param {string} args.rules[].policy - The policy for the rule (e.g., "allow" or "deny").
* @param {string} args.rules[].type - The type of the rule (e.g., "host", "port", "ipRange").
* @param {string} args.rules[].value - The value for the rule (e.g., the host name, port number, or IP range).
* @returns {Promise<Object>} - The result of the update operation.
*/
const executeFunction = async ({ networkId, rules }) => {
const baseUrl = 'https://api.meraki.com/api/v1';
const token = process.env.CISCO_MERAKI_S_PUBLIC_WORKSPACE_API_KEY;
try {
// Construct the URL for the API request
const url = `${baseUrl}/networks/${networkId}/appliance/firewall/l7FirewallRules`;
// Set up headers for the request
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': `Bearer ${token}`
};
// Prepare the request body
const body = JSON.stringify({ rules });
// Perform the fetch request
const response = await fetch(url, {
method: 'PUT',
headers,
body
});
// Check if the response was successful
if (!response.ok) {
const errorData = await response.json();
throw new Error(errorData);
}
// Parse and return the response data
const data = await response.json();
return data;
} catch (error) {
console.error('Error updating firewall rules:', error);
return { error: 'An error occurred while updating the firewall rules.' };
}
};
/**
* Tool configuration for updating MX L7 firewall rules.
* @type {Object}
*/
const apiTool = {
function: executeFunction,
definition: {
type: 'function',
function: {
name: 'updateNetworkApplianceFirewallL7FirewallRules',
description: 'Update the MX L7 firewall rules for 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 (e.g., "allow" or "deny").'
},
type: {
type: 'string',
description: 'The type of the rule (e.g., "host", "port", "ipRange").'
},
value: {
type: 'string',
description: 'The value for the rule (e.g., the host name, port number, or IP range).'
}
},
required: ['policy', 'type', 'value']
},
description: 'An array of rule objects to apply.'
}
},
required: ['networkId', 'rules']
}
}
}
};
export { apiTool };