# app/Http/Controllers/Network/*

This documentation serves to explain the purpose, usage, bugs and future direction of the code used for the network controllers.

Network controllers in the context of Creatia are rather high level, and it handles functionality that is commonly shared across other controllers regarding prefix related functionality. There is also a few misc functions here that are relevant to networks as well. Please note that Creatia has underwent a few methodological and philosophical changes across it's development due to the rapidly changing nature of the requirements, needs for the system, and general skill of the team, which means that quite a bit of this code is not necessarily as DRY as possible, nor will it necessarily be segregated in the most coherent manner.

# Internal API Controller ( AdminApiController.php )
This serves as the entrypoint for API usage within both GSL and it's sister brands and partners to make changes to the state of Creatia's understanding of what network related information should look like. It currently allows the association and creation of prefixes to a given subtenant, the retrieval of a full list of subnets for a given subtenant, the cleaning of a prefix once someone is done with it, and the ability to set mitigation preferences. Now, normally mitigation related preferences would sit under a Goliath controller of sorts. However, in the name of simplicity and keeping code as uncomplicated as possible it makes more sense to include this single method here.

## associate_subnet(request, creatia_id)
- **request** (_Laravel Request_): The Laravel request object containing relevant fields. Fields:
    - **subnet** (_String, in the form of a CIDR compliant prefix_): .  
    - **name** (_String, in freeform_): This is the name of the given prefix for user reference.
    - **prefix_only** (_Boolean_): Whether or not subtenancy will grant control of this prefix itself. Kind of a bad name.
    - **children_allowed** (_Boolean_): Whether or not subtenancy will grant control of the prefixes subnets.
    - **override** (_Boolean_): Whether typical prefix safety is respected. This should never be used except in approved scenarios.
    - **brand** (_String, but must be one of 'gsl', 'go-dedicated', 'streamline'_): The brand that is responsible for this action. This is used to make sure that only a given brands staff can view a prefix. GSL has viewership of all prefixes however.
- **creatia_id** (_String, number as a string_): This is the organisational identifier for a given organisation in Creatia.

This is used to create a given prefix, or associate it with an organisation. An example of the usage of this endpoint is as follows:

```
POST https://api-creatia.securelayer.com/api/internal/organisation/{creatia_id}/network

JSON PAYLOAD: {
    "subnet": "203.1.1.3/32",
    "name": "Demo",
    "prefix_only": true,
    "children_allowed": true,
    "override": false,
    "brand": "gsl"
}
```

This would then grant an organisation the access to this prefix. If the prefix didn't exist, it would be created. This is only true however if the prefix has a valid parent. It also allows the user to create subnets and manage the prefix itself. Further, it will be a GSL owned prefix.