Skip to content

Commit

Permalink
Merge pull request #18 from cooperwalbrun/conversion-threshold
Browse files Browse the repository at this point in the history
Avoid Converting CIDRs to a New Prefix If the Result Is Over 256 CIDRs Long
  • Loading branch information
cooperwalbrun authored Nov 20, 2022
2 parents ce596d4 + 4db939a commit 5ba67cb
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 22 deletions.
46 changes: 33 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,72 +9,92 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

Nothing currently!

## v0.3.2 - 2022-11-20

### Changed

* The `--prefix` argument no longer converts CIDR blocks which would result in more than 256 CIDRs
(previously this threshold was 1024) (by [@cooperwalbrun](https://github.com/cooperwalbrun))

## v0.3.1 - 2022-11-20

### Changed

* IPv6 subnets in an `associating` state are now recognized by `aws-cidr-finder` (by [@cooperwalbrun](https://github.com/cooperwalbrun))
* IPv6 subnets in an `associating` state are now recognized by `aws-cidr-finder` (by
[@cooperwalbrun](https://github.com/cooperwalbrun))

## v0.3.0 - 2022-11-16

### Added

* Added project configuration for using `mypy` to statically type-check code during development and in the GitHub Actions pipeline (by [@cooperwalbrun](https://github.com/cooperwalbrun))
* Implemented proper typing throughout the source code and added a `py.typed` file per PEP 561 (by [@cooperwalbrun](https://github.com/cooperwalbrun))
* Added project configuration for using `mypy` to statically type-check code during development and
in the GitHub Actions pipeline (by [@cooperwalbrun](https://github.com/cooperwalbrun))
* Implemented proper typing throughout the source code and added a `py.typed` file per PEP 561 (by
[@cooperwalbrun](https://github.com/cooperwalbrun))

## v0.2.4 - 2022-11-08

### Added

* Added support for Python 3.11 to the pipeline and project configuration (by [@cooperwalbrun](https://github.com/cooperwalbrun))
* Added support for Python 3.11 to the pipeline and project configuration (by
[@cooperwalbrun](https://github.com/cooperwalbrun))

## v0.2.3 - 2022-10-12

### Changed

* The author email address in the wheel's metadata is now set to a real email address (by [@cooperwalbrun](https://github.com/cooperwalbrun))
* The author email address in the wheel's metadata is now set to a real email address (by
[@cooperwalbrun](https://github.com/cooperwalbrun))

## v0.2.2 - 2022-06-13

### Changed

* CIDR blocks that are in an `associating` state (instead of just the `associated` state) will now be considered in this CLI's functionality (by [@cooperwalbrun](https://github.com/cooperwalbrun))
* CIDR blocks that are in an `associating` state (instead of just the `associated` state) will now
be considered in this CLI's functionality (by [@cooperwalbrun](https://github.com/cooperwalbrun))

## v0.2.1 - 2022-06-11

### Changed

* Refactored the code to reduce code duplication between the IPv4 and IPv6 functionalities (by [@cooperwalbrun](https://github.com/cooperwalbrun))
* Refactored the code to reduce code duplication between the IPv4 and IPv6 functionalities (by
[@cooperwalbrun](https://github.com/cooperwalbrun))

## v0.2.0 - 2022-06-11

### Added

* Implemented support for IPv6 VPCs via the `--ipv6` CLI flag (by [@cooperwalbrun](https://github.com/cooperwalbrun))
* Implemented support for IPv6 VPCs via the `--ipv6` CLI flag (by
[@cooperwalbrun](https://github.com/cooperwalbrun))

### Changed

* The structure of the JSON output when specifying the `--json` CLI flag now includes VPC names, VPC CIDRs, and informational messages (by [@cooperwalbrun](https://github.com/cooperwalbrun))
* The structure of the JSON output when specifying the `--json` CLI flag now includes VPC names, VPC
CIDRs, and informational messages (by [@cooperwalbrun](https://github.com/cooperwalbrun))

### Fixed

* Gracefully handle situations where the requested `--prefix` causes a huge number of CIDRs to be returned (by [@cooperwalbrun](https://github.com/cooperwalbrun))
* Gracefully handle situations where the requested `--prefix` causes a huge number of CIDRs to be
returned (by [@cooperwalbrun](https://github.com/cooperwalbrun))

## v0.1.2 - 2022-05-08

### Changed

* Enabled querying by a prefix which is lower than at least one prefix in the returned CIDR list (by [@cooperwalbrun](https://github.com/cooperwalbrun))
* Enabled querying by a prefix which is lower than at least one prefix in the returned CIDR list (by
[@cooperwalbrun](https://github.com/cooperwalbrun))

## v0.1.1 - 2022-02-20

### Fixed

* Fixed `find_subnet_holes` slowness and incorrectness issues (by [@cooperwalbrun](https://github.com/cooperwalbrun))
* Fixed `find_subnet_holes` slowness and incorrectness issues (by
[@cooperwalbrun](https://github.com/cooperwalbrun))

## v0.1.0 - 2022-02-17

### Added

* Created the project (by [@cooperwalbrun](https://github.com/cooperwalbrun))
* Implemented the initial functionality of finding subnet "holes" in IPv4 VPCs (by [@cooperwalbrun](https://github.com/cooperwalbrun))
* Implemented the initial functionality of finding subnet "holes" in IPv4 VPCs (by
[@cooperwalbrun](https://github.com/cooperwalbrun))
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ Use `aws-cidr-finder -h` to see command options.

### An Example

It is easiest to see the value of this tool through an example. Pretend that we have the following
VPC setup in AWS:
It is easiest to see the value of this tool through an example. Imagine that we have the following
setup in AWS:

* A VPC whose CIDR is `172.31.0.0/16`, with a `Name` tag of `Hello World`
* Six subnets in that VPC whose CIDRs are:
* Six subnets inside that VPC whose CIDRs are:
* `172.31.0.0/20`
* `172.31.16.0/20`
* `172.31.32.0/20`
Expand Down Expand Up @@ -93,7 +93,7 @@ aws-cidr-finder --profile myprofile --prefix 18
We should see this output:

```
Note: skipping CIDR '172.31.96.0/19' because its prefix (19) is larger than the requested prefix (18)
Note: skipping CIDR '172.31.96.0/19' because its prefix (19) is numerically greater than the requested prefix (18)
Here are the available CIDR blocks in the 'Hello World' VPC (VPC CIDR block '172.31.0.0/16'):
CIDR IP Count
Expand Down
2 changes: 1 addition & 1 deletion src/aws_cidr_finder/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _parse_arguments(arguments: list[str]) -> dict[str, Any]:
def main() -> None:
arguments = _parse_arguments(_get_arguments())

boto = BotoWrapper(arguments.get("PROFILE"), arguments.get("REGION"))
boto = BotoWrapper(profile_name=arguments.get("PROFILE"), region=arguments.get("REGION"))

ipv6: bool = arguments["ipv6"]

Expand Down
2 changes: 1 addition & 1 deletion src/aws_cidr_finder/boto_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def _parse_subnet_cidrs(subnets: list[SubnetTypeDef], *, ipv6: bool) -> list[str


class BotoWrapper: # pragma: no cover
def __init__(self, profile_name: Optional[str], region: Optional[str]):
def __init__(self, *, profile_name: Optional[str], region: Optional[str]):
if profile_name is not None:
boto = boto3.session.Session(profile_name=profile_name, region_name=region)
else:
Expand Down
6 changes: 3 additions & 3 deletions src/aws_cidr_finder/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ def break_down_to_desired_prefix(cidrs: list[str], prefix: int) -> tuple[list[st
old_prefix = get_prefix(cidr)
if old_prefix > prefix:
messages.append((
f"Note: skipping the CIDR '{cidr}' because its prefix ({old_prefix}) is larger "
f"than the requested prefix ({prefix})"
f"Note: skipping the CIDR '{cidr}' because its prefix ({old_prefix}) is "
f"numerically greater than the requested prefix ({prefix})"
))
continue
elif prefix - old_prefix > 9:
elif prefix - old_prefix > 8:
messages.append((
f"Warning: skipping the CIDR '{cidr}' because its prefix is only {old_prefix} "
f"and converting it to a list of CIDRs with a prefix of {prefix} will result "
Expand Down

0 comments on commit 5ba67cb

Please sign in to comment.