Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
…into template_generator_update
  • Loading branch information
Mateusz Lapinski committed Sep 20, 2023
2 parents c301e63 + 1183c5c commit e05e280
Show file tree
Hide file tree
Showing 19 changed files with 1,905 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[Add more in depth analysis of what changed, provide logs, examples of usage]

# Checklist:
- [ ] Make sure to run pre-commit before commiting changes
- [ ] Make sure to run pre-commit before committing changes
- [ ] Make sure all checks have passed
- [ ] PR description is clear and comprehensive
- [ ] Mentioned the issue that this PR solves (if applicable)
Expand Down
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,8 @@ repos:
language: system
types: [python]
fail_fast: true

- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
hooks:
- id: detect-secrets
44 changes: 44 additions & 0 deletions ENDPOINTS.md

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# vManage-client
<p align="center">
<a href="#"><img src="docs/vManage-client_LOGO.svg" alt="vManage-client logo" style="height:150px" />
</p>

[![Python-Supported](https://img.shields.io/static/v1?label=Python&logo=Python&color=3776AB&message=3.8%20|%203.9%20|%203.10%20|%203.11)](https://www.python.org/)

vManage client is a package for creating simple and parallel automatic requests via official vManageAPI. It is intended to serve as a multiple session handler (provider, provider as a tenant, tenant). The library is not dependent on environment which is being run in, you just need a connection to any vManage.
vManage client is a package for creating simple and parallel automatic requests via official vManage API. It is intended to serve as a multiple session handler (provider, provider as a tenant, tenant). The library is not dependent on environment which is being run in, you just need a connection to any vManage.

## Installation
```console
Expand Down
47 changes: 47 additions & 0 deletions docs/vManage-client_LOGO.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion vmngclient/endpoints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,14 +519,18 @@ def merge_args(self, positional_args: Tuple, keyword_args: Dict[str, Any]) -> Di
Returns: Dict[str, Any]: all passed args as keyword arguments (excluding "self")
"""
all_args_names = [key for key in self.sig.parameters.keys()]
all_args_dict = dict(zip(all_args_names, positional_args))
all_args_dict = dict(self.defaults)
all_args_dict.update(dict(zip(all_args_names, positional_args)))
all_args_dict.update(keyword_args)
all_args_dict.pop("self", None)
return all_args_dict

def __call__(self, func):
original_func = getattr(func, "_ofunc", func) # grab original function
self.sig = signature(original_func)
self.defaults = {
key: value.default for (key, value) in self.sig.parameters.items() if value.default is not _empty
}
self.return_spec = self.specify_return_type()
self.payload_spec = self.specify_payload_type()
self.check_params()
Expand Down
262 changes: 262 additions & 0 deletions vmngclient/endpoints/configuration_policy_data_definition_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
# mypy: disable-error-code="empty-body"
from enum import Enum
from typing import Any, List, Optional, Union

from pydantic import BaseModel, Field, IPvAnyNetwork
from typing_extensions import Annotated, Literal

from vmngclient.endpoints import APIEndpoints, delete, get, post, put
from vmngclient.model.policy_definition import (
PolicyDefinition,
PolicyDefinitionCreationPayload,
PolicyDefinitionEditPayload,
PolicyDefinitionEditResponse,
PolicyDefinitionId,
PolicyDefinitionPreview,
)
from vmngclient.typed_list import DataSequence

# TODO: add validators for custom strings (eg.: port ranges, space separated networks)
# TODO: model actions


class DefaultActionType(str, Enum):
DROP = "drop"
ACCEPT = "accept"


class PLPEntryValues(str, Enum):
LOW = "low"
HIGH = "high"


class DNSEntryValues(str, Enum):
REQUEST = "request"
RESPONSE = "response"


class TrafficToEntryValues(str, Enum):
ACCESS = "access"
CORE = "core"
SERVICE = "service"


class DestinationRegionEntryValues(str, Enum):
PRIMARY = "primary-region"
SECONDARY = "secondary-region"
OTHER = "other-region"


class SequenceIpType(str, Enum):
IPV4 = "ipv4"
IPV6 = "ipv6"
ALL = "all"


class BaseAction(str, Enum):
DROP = "drop"
ACCEPT = "accept"


class SequenceType(str, Enum):
APPLICATION_FIREWALL = "applicationFirewall"
DATA = "data"
SERVICE_CHAINING = "serviceChaining"
TRAFFIC_ENGINEERING = "trafficEngineering"
QOS = "qos"


class PacketLengthEntry(BaseModel):
field: Literal["packetLength"]
value: str = Field(description="0-65536 range or single number")


class PLPEntry(BaseModel):
field: Literal["plp"]
value: PLPEntryValues


class ProtocolEntry(BaseModel):
field: Literal["protocol"]
value: str = Field(description="0-255 single numbers separate by space")


class DSCPEntry(BaseModel):
field: Literal["dscp"]
value: str = Field(description="0-63 single numbers separate by space")


class SourceIPEntry(BaseModel):
field: Literal["sourceIp"]
value: str = Field(description="IP network specifier separate by space")


class SourcePortEntry(BaseModel):
field: Literal["sourcePort"]
value: str = Field(description="0-65535 range or separate by space")


class DestinationIPEntry(BaseModel):
field: Literal["destinationIp"]
value: IPvAnyNetwork


class DestinationPortEntry(BaseModel):
field: Literal["destinationPort"]
value: str = Field(description="0-65535 range or separate by space")


class TCPEntry(BaseModel):
field: Literal["tcp"]
value: Literal["syn"]


class DNSEntry(BaseModel):
field: Literal["dns"]
value: DNSEntryValues


class TrafficToEntry(BaseModel):
field: Literal["trafficTo"]
value: TrafficToEntryValues


class DestinationRegionEntry(BaseModel):
field: Literal["destinationRegion"]
value: DestinationRegionEntryValues


class SourceDataPrefixListEntry(BaseModel):
field: Literal["sourceDataPrefixList"]
ref: str


class DestinationDataPrefixListEntry(BaseModel):
field: Literal["destinationDataPrefixList"]
ref: str


class SourceDataIPv6PrefixListEntry(BaseModel):
field: Literal["sourceDataIpv6PrefixList"]
ref: str


class DestinationDataIPv6PrefixListEntry(BaseModel):
field: Literal["destinationDataIpv6PrefixList"]
ref: str


class DNSAppListEntry(BaseModel):
field: Literal["dnsAppList"]
ref: str


class AppListEntry(BaseModel):
field: Literal["appList"]
ref: str


Entry = Annotated[
Union[
PacketLengthEntry,
PLPEntry,
ProtocolEntry,
DSCPEntry,
SourceIPEntry,
SourcePortEntry,
DestinationIPEntry,
DestinationPortEntry,
TCPEntry,
DNSEntry,
TrafficToEntry,
SourceDataPrefixListEntry,
DestinationDataPrefixListEntry,
SourceDataIPv6PrefixListEntry,
DestinationDataIPv6PrefixListEntry,
DestinationRegionEntry,
DNSAppListEntry,
AppListEntry,
],
Field(discriminator="field"),
]


class Match(BaseModel):
entries: List[Entry]


class Action(BaseModel):
pass


class Sequence(BaseModel):
sequence_id: int = Field(alias="sequenceId")
sequence_name: str = Field(alias="sequenceName")
base_action: BaseAction = Field(alias="baseAction")
sequence_type: SequenceType = Field(alias="sequenceType")
sequence_ip_type: SequenceIpType = Field(alias="sequenceIpType")
match: Match
actions: List[Any]


class DefaultAction(BaseModel):
type: DefaultActionType


class Data(BaseModel):
type: str = Field(default="data", const=True)
default_action: Optional[DefaultAction] = Field(
default=DefaultAction(type=DefaultActionType.DROP), alias="defaultAction"
)
is_activated_by_vsmart: Optional[bool] = Field(default=False, alias="isActivatedByVsmart")
sequences: List[Sequence] = []


class DataDefinitionCreationPayload(Data, PolicyDefinitionCreationPayload):
pass


class DataDefinitionEditPayload(Data, PolicyDefinitionEditPayload):
pass


class DataDefinition(Data, PolicyDefinition):
pass


class ConfigurationPolicyDataDefinitionBuilder(APIEndpoints):
@post("/template/policy/definition/data")
def create_policy_definition(self, payload: DataDefinitionCreationPayload) -> PolicyDefinitionId:
...

@delete("/template/policy/definition/data/{id}")
def delete_policy_definition(self, id: str) -> None:
...

def edit_multiple_policy_definition(self):
# PUT /template/policy/definition/data/multiple/{id}
...

@put("/template/policy/definition/data/{id}")
def edit_policy_definition(self, id: str, payload: DataDefinitionEditPayload) -> PolicyDefinitionEditResponse:
...

@get("/template/policy/definition/data", "data")
def get_definitions(self) -> DataSequence[PolicyDefinition]:
...

@get("/template/policy/definition/data/{id}")
def get_policy_definition(self, id: str) -> DataDefinition:
...

@post("/template/policy/definition/data/preview")
def preview_policy_definition(self, payload: DataDefinitionCreationPayload) -> PolicyDefinitionPreview:
...

@get("/template/policy/definition/data/preview/{id}")
def preview_policy_definition_by_id(self, id: str) -> PolicyDefinitionPreview:
...

def save_policy_definition_in_bulk(self):
# PUT /template/policy/definition/data/bulk
...
Loading

0 comments on commit e05e280

Please sign in to comment.