Skip to content

Commit

Permalink
Adjust network list interface (#296)
Browse files Browse the repository at this point in the history
* fix: adjust network list interface code sample

* add note to inform firewall functions must have an event as an outcome

* remove blank space from sample call

* Update src/content/docs/pt-br/pages/azion-edge-runtime/api-reference/network-list/index.mdx

* Update src/content/docs/pt-br/pages/azion-edge-runtime/api-reference/network-list/index.mdx

* Update src/content/docs/pt-br/pages/azion-edge-runtime/api-reference/network-list/index.mdx
  • Loading branch information
gabriel-azion authored Sep 29, 2023
1 parent 35f665e commit f4b8339
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The `Azion.networkList.contains()` interface can be used by edge functions on Ed
## Syntax

```js
Azion.networkList.contains(networklistID, ipAddress)
Azion.networkList.contains(networklistID, ipAddress)
```

---
Expand Down Expand Up @@ -49,15 +49,20 @@ Basic usage of `Azion.networkList.contains()` with a specific IP address and net

try {
let found = Azion.networkList.contains(String(networkListId), ip); // Checking if the ip is in the list
if (found) {
event.deny(); // If it's in the list, deny the request
if (!found) {
event.continue(); // If it's not in the list, accept the request
return;
}
} catch (err) {
event.console.error(`Error: `, err.stack);
}
event.deny();
});
```

:::note
All edge functions used on Edge Firewall must have a *finishing outcome* in it, such as: `event.continue()`, `event.deny()`, and `event.drop()`.
:::
---

## Error handling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ A interface `Azion.networkList.contains()` pode ser usada por edge functions no
## Sintaxe

```js
Azion.networkList.contains(networklistID, ipAddress)
Azion.networkList.contains(networklistID, ipAddress)
```

### Parâmetros
Expand All @@ -40,15 +40,22 @@ Saiba mais sobre [Network Lists na plataforma da Azion](/pt-br/documentacao/prod

try {
let found = Azion.networkList.contains(String(networkListId), ip); // Verificando se a IP está na lista
if (found) {
event.deny(); // Se estiver na lista, a requisição é negada
if (!found) {
event.continue(); // Se não estiver listado, a request é liberada
return;
}
} catch (err) {
event.console.error(`Error: `, err.stack);
}
event.deny();
});
```

:::note
Todas as edge functions usadas no Edge Firewall devem ter um *resultado final* nelas, como: `event.continue()`, `event.deny()` e `event.drop()`.
:::


## Tratamento de erros

Se ocorrer um erro durante a execução, uma exceção pode ser retornada. Certifique-se de tratar os possíveis erros e fornecer mensagens de erro apropriadas ou ações de fallback em seu código.
Expand Down

0 comments on commit f4b8339

Please sign in to comment.