Commit 1b8b0ada authored by Morten Brekkevold's avatar Morten Brekkevold
Browse files

Implement a Kind service filter option

Because:
- Devices in Kind belong to different services, and should potentially be
  grouped into separate NAV installs.
parent 86594b20
......@@ -61,7 +61,7 @@ def main():
initlogging(args.debug, args.no_timestamps)
kind = get_kind_data()
kind = get_kind_data(services=args.tjeneste)
LOG.debug("Fant %s utstyrsposter i Kind", len(kind))
# Data set verification
find_kind_duplicates(kind)
......@@ -114,6 +114,12 @@ def parse_args():
default=os.environ.get("NAV_API_TOKEN"),
help="NAV API Token",
)
parser.add_argument(
"--tjeneste",
type=int,
action="append",
help="Use this Kind Tjeneste-ID to filter devices from the Kind API",
)
parser.add_argument(
"--no-timestamps",
action="store_true",
......@@ -187,9 +193,13 @@ def _is_valid_ip(addr):
return False
def get_kind_data():
LOG.debug("Henter data fra %s", KIND_SERVICE_URL)
return requests.get(KIND_SERVICE_URL).json()
def get_kind_data(services: list = None):
"""Fetches device data from Kind, using an optional service filter"""
LOG.debug("Henter data fra %s (tjenestefilter: %r)", KIND_SERVICE_URL, services)
params = {"tjenester": services} if services else {}
response = requests.get(KIND_SERVICE_URL, params=params)
LOG.debug("Fikk respons fra %s", response.url)
return response.json()
def find_kind_duplicates(kind_data):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment