Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit eb94574
Author: Terje Kvernes <[email protected]>
Date:   Tue Jun 11 15:30:11 2024 +0200

    Fix delegeation response.

      - Add support for "delegation" scope akin to "zone" scope in server responses for zones.

commit 4eb26e0
Author: Terje Kvernes <[email protected]>
Date:   Tue Jun 11 15:00:40 2024 +0200

    Fix network excluded range output.

      - Also use IPAddressField for ips in excluded ranges.

commit 833160a
Author: Peder Hovdan Andresen <[email protected]>
Date:   Tue Jun 11 11:51:00 2024 +0200

    Fix fetching paginated endpoints twice in `get_list_generic` (#261)

    * Fix fetching paginated endpoints twice in `get_list_generic`

    * Break instead of return

    * Refactor `get_list_generic` result checking

commit 59f5b8b
Author: Øyvind Hagberg <[email protected]>
Date:   Mon Jun 10 17:10:35 2024 +0200

    Add a check for frozen/force to "host add"

    We forgot to check if the network was frozen in "host add". Added a
    check for that in this commit, but we'll probably have to do
    something similar in a_aaaa.py.

    Went through more command output and verified it. Mostly network
    commands this time.

    Modified diff.py to not care about length of white space. Since ip
    addresses can vary between runs, formatted output can vary in length,
    spesifically how much whitespace is added.

commit 86a5f25
Author: Peder Hovdan Andresen <[email protected]>
Date:   Fri Jun 7 09:00:20 2024 +0200

    Fix fetching network from location header (#258)

    * Extract fetching resource by location to separate method

    Fixes failing `network create` tests

    * Use `field_for_endpoint()`

    * Prefer using location header verbatim

    Adds handling for endpoints that return invalid location headers.

    * Remove `field_for_endpoint()`

    * Remove placeholder comment, move src comments

    * Remove special label handling, never re-fetch labels

commit 205da62
Author: Øyvind Hagberg <[email protected]>
Date:   Wed Jun 5 16:26:06 2024 +0200

    Verified behaviour for all group commands

    I have looked at the new output and api calls for the "group" commands
    in the testsuite and it looks good to me.
    Fixed a bug in history.py concerning how history is printed when owners
    or hosts are added/removed from hostgroups.
    Made a minor change to the datetime regex in diff.py to handle the extra
    space that comes before a single digit date.

commit 98681c1
Author: Øyvind Hagberg <[email protected]>
Date:   Wed Jun 5 13:02:17 2024 +0200

    Verified behaviour for all zone commands

    I have looked at the new output and api calls for the "zone" commands in
    the testsuite and it looks good to me. Updating testsuite-result.json to
    reflect that.

commit 780cec6
Author: Peder Hovdan Andresen <[email protected]>
Date:   Wed Jun 5 10:42:33 2024 +0200

    Remove IP/network from `host add` OK message

commit 7f70f18
Author: pederhan <[email protected]>
Date:   Tue Jun 4 11:03:27 2024 +0200

    Add missing OK message for `host add`

commit e594a79
Author: pederhan <[email protected]>
Date:   Tue Jun 4 10:33:11 2024 +0200

    Use `APIMixin.patch()` in `Zone.set_default_ttl()`

commit 99a7890
Author: pederhan <[email protected]>
Date:   Tue Jun 4 10:32:27 2024 +0200

    Fix valid_numeric_ttl min and max value handling

commit bf4ca3e
Author: Terje Kvernes <[email protected]>
Date:   Mon Jun 3 21:58:50 2024 +0200

    Further culling of... old stuff.

commit 9990aff
Author: Øyvind Hagberg <[email protected]>
Date:   Mon Jun 3 11:14:58 2024 +0200

    Cull utility functions that aren't used anymore

commit 4bf7f87
Author: Terje Kvernes <[email protected]>
Date:   Mon Jun 3 08:40:22 2024 +0200

    Use specialized exceptions. (#256)

    - This PR migrates all use of CliError and CliWarning to more specialized exceptions.
      - Also fix a bug with handling broken filter expressions.
      - Prefixes Errors with ERROR as not everyone has color vision.

commit 14fa7f9
Author: Øyvind Hagberg <[email protected]>
Date:   Fri May 31 16:36:24 2024 +0200

    Use OutputManager instead of the cli_* methods

commit 219176a
Author: Øyvind Hagberg <[email protected]>
Date:   Fri May 31 14:47:54 2024 +0200

    Also use workaround for patch requests

commit 18a0fa4
Author: Øyvind Hagberg <[email protected]>
Date:   Wed May 29 15:58:32 2024 +0200

    Workaround for json-incapable server

commit 5d860ed
Author: Øyvind Hagberg <[email protected]>
Date:   Wed May 29 15:55:41 2024 +0200

    Update testsuite json with modified label commands

commit 80afcbe
Author: Øyvind Hagberg <[email protected]>
Date:   Wed May 29 11:41:36 2024 +0200

    Fix workflow annotations about GH action versions

commit c62dd72
Author: pederhan <[email protected]>
Date:   Wed May 29 10:34:05 2024 +0200

    Replace formatted datetime strings in output

commit 001d61d
Author: Øyvind Hagberg <[email protected]>
Date:   Mon May 27 14:58:35 2024 +0200

    Make the cli exceptions write to outputmanager
  • Loading branch information
pederhan committed Jun 12, 2024
1 parent 606a5c1 commit 4844c2d
Show file tree
Hide file tree
Showing 34 changed files with 1,932 additions and 2,176 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- '3.12'
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
# - name: Cache pip
# uses: actions/cache@v3
# with:
Expand All @@ -24,7 +24,7 @@ jobs:
# v1-pip-${{ runner.os }}
# v1-pip-
- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install mreg-cli
Expand All @@ -46,9 +46,9 @@ jobs:
- "3.12"

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
73 changes: 53 additions & 20 deletions ci/diff.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,52 @@
from __future__ import annotations

import difflib
import json
import re
import sys
from typing import Any, Dict, List


def replace_timestamps(obj: Any) -> Any:
"""Recursively replace timestamp values in a JSON object.
:param obj: A JSON object (dict, list, or primitive type).
:returns: A new object with timestamps replaced.
"""
timestamp_pattern = re.compile(
r"\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:[+-]\d{2}:\d{2})?|\d{4}-\d{2}-\d{2}"
)
if isinstance(obj, dict):
return {k: replace_timestamps(v) for k, v in obj.items()}
elif isinstance(obj, list):
return [replace_timestamps(elem) for elem in obj]
elif isinstance(obj, str):
return timestamp_pattern.sub("<TIME>", obj)
return obj
timestamp_pattern = re.compile(
r"\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:[+-]\d{2}:\d{2})?|\d{4}-\d{2}-\d{2}"
)
datetime_str_pattern = re.compile(
r"\b[A-Za-z]{3}\s[A-Za-z]{3}\s+([0-2]?[0-9]|3[0-1])\s([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])\s[0-9]{4}\b"
)
# datetime_str_pattern = re.compile(
# r"\b(Sun|Mon|Tue|Wed|Thu|Fri|Sat)\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s([0-2]?[0-9]|3[0-1])\s([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])\s[0-9]{4}\b"
# )
serial_pattern = re.compile(r"\b[sS]erial:\s+\d+")
ipv4_pattern = re.compile(r"((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}")
ipv6_pattern = re.compile(r"\b([0-9a-fA-F]{1,4}::?){1,7}[0-9a-fA-F]{1,4}\b")

# Keeping this code in case we need to revert back to it:
#
# def replace_timestamps_and_more(obj: Any) -> Any:
# """Recursively replace timestamp values in a JSON object.
#
# :param obj: A JSON object (dict, list, or primitive type).
# :returns: A new object with timestamps replaced.
# """
# if isinstance(obj, dict):
# #return {ipv4_pattern.sub("<IPv4>",k): replace_timestamps_and_more(v) for k, v in obj.items()}
# newdict = {}
# for k, v in obj.items():
# # some places, ip addresses are used as keys
# k = ipv4_pattern.sub("<IPv4>",k)
# k = ipv6_pattern.sub("<IPv6>",k)
# v = replace_timestamps_and_more(v)
# newdict[k] = v
# return newdict
# elif isinstance(obj, list):
# return [replace_timestamps_and_more(elem) for elem in obj]
# elif isinstance(obj, str):
# obj = timestamp_pattern.sub("<TIME>", obj)
# obj = datetime_str_pattern.sub("<TIME>", obj)
# obj = serial_pattern.sub("Serial: <NUMBER>", obj)
# obj = ipv4_pattern.sub("<IPv4>", obj)
# obj = ipv6_pattern.sub("<IPv6>", obj)
# return obj
# return obj


def group_objects(json_file_path: str) -> List[List[Dict[str, Any]]]:
Expand All @@ -30,9 +56,16 @@ def group_objects(json_file_path: str) -> List[List[Dict[str, Any]]]:
:returns: A list of grouped objects.
"""
with open(json_file_path, "r") as f:
data = json.load(f)

data = [replace_timestamps(obj) for obj in data]
s = f.read()
s = timestamp_pattern.sub("<TIME>", s)
s = datetime_str_pattern.sub("<TIME>", s)
s = serial_pattern.sub("Serial: <NUMBER>", s)
s = ipv4_pattern.sub("<IPv4>", s)
s = ipv6_pattern.sub("<IPv6>", s)
s = re.sub(r"\s+", " ", s) # replace all whitespace with one space, so the diff doesn't complain about different lengths
data = json.loads(s)

#data = [replace_timestamps_and_more(obj) for obj in data]

grouped_objects = []
temp = []
Expand Down
Loading

0 comments on commit 4844c2d

Please sign in to comment.