okdata-cli 4.3.0__py3-none-any.whl → 4.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -98,3 +98,34 @@ class PubsClient(SDK):
98
98
  url = f"{self.api_url}/audit/{env}/{client_id}/log"
99
99
  log.info(f"Fetching audit log from: {url}")
100
100
  return self.get(url).json()
101
+
102
+
103
+ class ProvidersClient(SDK):
104
+ def __init__(self, config=None, auth=None, env=None):
105
+ self.__name__ = "providers"
106
+ super().__init__(config, auth, env)
107
+ self.api_url = "https://api.data{}.oslo.systems/maskinporten/providers".format(
108
+ "-dev" if self.config.config["env"] == "dev" else ""
109
+ )
110
+
111
+ def get_providers(self):
112
+ log.info(f"Listing providers from: {self.api_url}")
113
+ providers = self.get(self.api_url).json()
114
+ return {p["provider_id"]: p["name"] for p in providers}
115
+
116
+
117
+ class ScopesClient(SDK):
118
+ def __init__(self, config=None, auth=None, env=None):
119
+ self.__name__ = "scopes"
120
+ super().__init__(config, auth, env)
121
+ self.api_url = "https://api.data{}.oslo.systems/maskinporten/scopes".format(
122
+ "-dev" if self.config.config["env"] == "dev" else ""
123
+ )
124
+
125
+ def get_scopes(self):
126
+ log.info(f"Listing scopes from: {self.api_url}")
127
+ scopes = self.get(self.api_url).json()
128
+ scopes_dict = {}
129
+ for scope in scopes:
130
+ scopes_dict.setdefault(scope["provider_id"], []).append(scope["scope"])
131
+ return scopes_dict
@@ -1,18 +1,14 @@
1
1
  import base64
2
2
  from datetime import datetime
3
+ from functools import cached_property
3
4
  from operator import itemgetter
4
5
 
5
6
  from okdata.sdk.team.client import TeamClient
6
7
 
7
8
  from okdata.cli import MAINTAINER
8
9
  from okdata.cli.command import BASE_COMMAND_OPTIONS, BaseCommand, confirm_to_continue
9
- from okdata.cli.commands.pubs.client import PubsClient
10
- from okdata.cli.commands.pubs.questions import (
11
- NoClientsError,
12
- NoKeysError,
13
- client_types,
14
- providers,
15
- )
10
+ from okdata.cli.commands.pubs.clients import ProvidersClient, PubsClient, ScopesClient
11
+ from okdata.cli.commands.pubs.questions import NoClientsError, NoKeysError, client_types
16
12
  from okdata.cli.commands.pubs.wizards import (
17
13
  audit_log_wizard,
18
14
  create_client_wizard,
@@ -54,6 +50,16 @@ Options:{BASE_COMMAND_OPTIONS}
54
50
  super().__init__()
55
51
  self.pubs_client = PubsClient(env=self.opt("env"))
56
52
  self.team_client = TeamClient(env=self.opt("env"))
53
+ self.providers_client = ProvidersClient(env=self.opt("env"))
54
+ self.scopes_client = ScopesClient(env=self.opt("env"))
55
+
56
+ @cached_property
57
+ def _providers(self):
58
+ return self.providers_client.get_providers()
59
+
60
+ @cached_property
61
+ def _scopes(self):
62
+ return self.scopes_client.get_scopes()
57
63
 
58
64
  def handler(self):
59
65
  if self.cmd("create-client"):
@@ -73,7 +79,9 @@ Options:{BASE_COMMAND_OPTIONS}
73
79
 
74
80
  def create_client(self):
75
81
  try:
76
- config = create_client_wizard(self.team_client)
82
+ config = create_client_wizard(
83
+ self.team_client, self._providers, self._scopes
84
+ )
77
85
  except NoTeamError:
78
86
  self.print(
79
87
  "We haven't yet registered you as member of any Origo team. "
@@ -91,7 +99,7 @@ Options:{BASE_COMMAND_OPTIONS}
91
99
  confirm_to_continue(
92
100
  "Will create a new {} client{} in {}{}.".format(
93
101
  client_types[client_type_id],
94
- f" for {providers[provider_id]}" if provider_id else "",
102
+ f" for {self._providers[provider_id]}" if provider_id else "",
95
103
  env,
96
104
  f" with scopes {scopes}" if scopes else "",
97
105
  )
@@ -1,4 +1,4 @@
1
- from operator import itemgetter
1
+ from operator import attrgetter, itemgetter
2
2
 
3
3
  from questionary import Choice
4
4
 
@@ -15,38 +15,6 @@ client_types = {
15
15
  "maskinporten": "Maskinporten",
16
16
  }
17
17
 
18
- providers = {
19
- "freg": "Folkeregisteret",
20
- "krr": "Kontaktregisteret",
21
- "skatt": "Skatteetaten",
22
- }
23
-
24
- _scopes = {
25
- "freg": [
26
- "folkeregister:deling/offentligmedhjemmel",
27
- "folkeregister:deling/offentligutenhjemmel",
28
- ],
29
- "krr": [
30
- "krr:global/digitalpost.read",
31
- "krr:global/kontaktinformasjon.read",
32
- ],
33
- "skatt": [
34
- "skatteetaten:arbeidsgiveravgift",
35
- "skatteetaten:avregning",
36
- "skatteetaten:boligsparingforungdom",
37
- "skatteetaten:inntekt",
38
- "skatteetaten:inntektsmottakere",
39
- "skatteetaten:mvameldingsopplysning",
40
- "skatteetaten:oppdragutenlandskevirksomheter",
41
- "skatteetaten:restanser",
42
- "skatteetaten:skattemelding",
43
- "skatteetaten:skatteplikt",
44
- "skatteetaten:spesifisertsummertskattegrunnlag",
45
- "skatteetaten:summertskattegrunnlag",
46
- "skatteetaten:tjenestepensjonsavtale",
47
- ],
48
- }
49
-
50
18
  _environments = [
51
19
  "test",
52
20
  "prod",
@@ -87,24 +55,29 @@ def q_client_type():
87
55
  }
88
56
 
89
57
 
90
- def q_provider():
58
+ def q_provider(providers):
91
59
  return {
92
60
  **required_style,
93
61
  "type": "select",
94
62
  "name": "provider_id",
95
63
  "message": "Provider",
96
- "choices": [Choice(pname, pid) for pid, pname in providers.items()],
64
+ "choices": sorted(
65
+ [Choice(pname, pid) for pid, pname in providers.items()],
66
+ key=attrgetter("title"),
67
+ ),
97
68
  "when": lambda x: x.get("client_type_id") == "maskinporten",
98
69
  }
99
70
 
100
71
 
101
- def q_scopes():
72
+ def q_scopes(scopes):
102
73
  return {
103
74
  **required_style,
104
75
  "type": "checkbox",
105
76
  "name": "scopes",
106
77
  "message": "Scopes",
107
- "choices": lambda x: _scopes[x["provider_id"]] if "provider_id" in x else [],
78
+ "choices": lambda x: (
79
+ sorted(scopes[x["provider_id"]]) if "provider_id" in x else []
80
+ ),
108
81
  "validate": (lambda choices: bool(choices) or "Select at least one scope"),
109
82
  "when": lambda x: x.get("client_type_id") == "maskinporten",
110
83
  }
@@ -20,13 +20,13 @@ from okdata.cli.commands.teams.questions import q_team
20
20
  from okdata.cli.commands.wizard import run_questionnaire
21
21
 
22
22
 
23
- def create_client_wizard(team_client):
23
+ def create_client_wizard(team_client, providers, scopes):
24
24
  choices = run_questionnaire(
25
25
  q_env(),
26
26
  q_team(team_client),
27
27
  q_client_type(),
28
- q_provider(),
29
- q_scopes(),
28
+ q_provider(providers),
29
+ q_scopes(scopes),
30
30
  q_integration(),
31
31
  q_redirect_uris(),
32
32
  q_post_logout_redirect_uris(),
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: okdata-cli
3
- Version: 4.3.0
3
+ Version: 4.4.0
4
4
  Summary: CLI for services provided by Oslo Origo
5
5
  Home-page: https://github.com/oslokommune/okdata-cli/
6
6
  Author: Oslo Origo
@@ -29,6 +29,7 @@ Dynamic: description
29
29
  Dynamic: description-content-type
30
30
  Dynamic: home-page
31
31
  Dynamic: license
32
+ Dynamic: license-file
32
33
  Dynamic: requires-dist
33
34
  Dynamic: requires-python
34
35
  Dynamic: summary
@@ -1,4 +1,4 @@
1
- okdata_cli-4.3.0-py3.12-nspkg.pth,sha256=LUsqeDUhjJQmFBD_9BYoicNcghGruF4e2xXxq0Ftwmc,467
1
+ okdata_cli-4.4.0-py3.13-nspkg.pth,sha256=LUsqeDUhjJQmFBD_9BYoicNcghGruF4e2xXxq0Ftwmc,467
2
2
  okdata/cli/__init__.py,sha256=72PLqW3-JGeKxQGusk3AX78ITwcn7DDawEMNLlsurz4,27
3
3
  okdata/cli/__main__.py,sha256=_jPIZ0MVIgtf6x-RzbodSihOa-oHvKBfwM8JO8-oQYo,2771
4
4
  okdata/cli/command.py,sha256=3Mo0e4OfPM7hI1QZ8HRpJVb5K3DRLPGYfOouzOhO1tc,4427
@@ -14,10 +14,10 @@ okdata/cli/commands/datasets/datasets.py,sha256=qZ-JnPduIVta0HkRwaesUWFkrK4fC0hm
14
14
  okdata/cli/commands/datasets/questions.py,sha256=UW4_oOscUVRyVvKsNJwqbKnGfMGMu-O80aKQVp8vVRs,4235
15
15
  okdata/cli/commands/datasets/wizards.py,sha256=yAh_PyWX1gkz9RshWj8sFs6RWbXatN7228fh7TBfytI,4383
16
16
  okdata/cli/commands/pubs/__init__.py,sha256=T105M_46YzyZ2Cici48QKNyjfJTIQJ1uyMFlo91rIZ4,81
17
- okdata/cli/commands/pubs/client.py,sha256=dOabTkeZKPvHFbgwZC4SX4DyvnvEezpeSiLQ1EY1hlo,3223
18
- okdata/cli/commands/pubs/pubs.py,sha256=zDYy7pJkeYI5h-vvO5bICCvUaw3RdFrqTHCZ6T_pf9U,11981
19
- okdata/cli/commands/pubs/questions.py,sha256=B0Iusq-8725DgaTVLa9MDhsO0AzgezlfNYLdySolAZE,7046
20
- okdata/cli/commands/pubs/wizards.py,sha256=fNhj-7G7ePEYVLrhmdXdNzRSdD-9BzVAcJxujuz7LwQ,3613
17
+ okdata/cli/commands/pubs/clients.py,sha256=-Sp3RE1nXqMsTDN3kLgXLNTeWRVVBFrgD7G5fMsnxEg,4376
18
+ okdata/cli/commands/pubs/pubs.py,sha256=RqZs00HAizdtrg9VDwX4O8_uL804AhTzUcirKpruEYo,12411
19
+ okdata/cli/commands/pubs/questions.py,sha256=Zaqf1FjAv3kT21NxFRbt9gdA9wF-IvDPwVvG-K-GFRQ,6239
20
+ okdata/cli/commands/pubs/wizards.py,sha256=SLAfqtgxeyS5XHozO-ztOqcQAYN2YljZouW-Py1pcuU,3647
21
21
  okdata/cli/commands/teams/questions.py,sha256=UqfHK2bwl6retyYYC-IywG_39aRDC-WbKYpMIQ83gfE,2997
22
22
  okdata/cli/commands/teams/teams.py,sha256=g33g8AS5UQnYdgDXdr4v5BVEtNQ5_XeQ9bc3ojhqNPc,5617
23
23
  okdata/cli/commands/teams/util.py,sha256=c7U6jI7CN7MUyfsK6Z3AawL0SJJBlFar4FvXfsJQzSk,456
@@ -40,10 +40,10 @@ okdata/cli/data/output-format/status_config.json,sha256=oq9uYZbPZrM2ksWrQDd9-VWO
40
40
  okdata/cli/data/output-format/status_history_config.json,sha256=Gh-l8w9688P0hdp_DtJ9cxMc1bdv5DuNp5QBftOnb9M,721
41
41
  okdata/cli/data/output-format/team_members_config.json,sha256=CYzlVLU3f41kpxBbovXYDYRYOvhScfYU2yxtwHFMcuQ,183
42
42
  okdata/cli/data/output-format/teams_config.json,sha256=z49y_7m3b9W02guXXcSdlX9XDAaIj0rRBDcqU68m9i0,124
43
- okdata_cli-4.3.0.dist-info/LICENSE,sha256=K5ut_rTozMMIoz2xdUWdkFZ5f51oYtMNd13-rJ38pTs,1082
44
- okdata_cli-4.3.0.dist-info/METADATA,sha256=ZGyG7FRkpLrJwJX_gul0bpgiDPENpUTFpfHdHpxq1jg,1406
45
- okdata_cli-4.3.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
46
- okdata_cli-4.3.0.dist-info/entry_points.txt,sha256=OyY5saQTVah33LZ9ixM40rsMPgsOKErioZA8rtVjgKo,52
47
- okdata_cli-4.3.0.dist-info/namespace_packages.txt,sha256=Pdf-ZpWHLtLL295sDedsbAP3f6H189730mXrfVAVCcY,7
48
- okdata_cli-4.3.0.dist-info/top_level.txt,sha256=cS1IEDv6oxHgvQHrGSxFxjHTv5CNc9dLowH1vpCqF_k,11
49
- okdata_cli-4.3.0.dist-info/RECORD,,
43
+ okdata_cli-4.4.0.dist-info/licenses/LICENSE,sha256=K5ut_rTozMMIoz2xdUWdkFZ5f51oYtMNd13-rJ38pTs,1082
44
+ okdata_cli-4.4.0.dist-info/METADATA,sha256=ELyeeAktmzqfKGb1mLTq2XeD0V1MKtEdqh-DaPgKPIc,1428
45
+ okdata_cli-4.4.0.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
46
+ okdata_cli-4.4.0.dist-info/entry_points.txt,sha256=OyY5saQTVah33LZ9ixM40rsMPgsOKErioZA8rtVjgKo,52
47
+ okdata_cli-4.4.0.dist-info/namespace_packages.txt,sha256=Pdf-ZpWHLtLL295sDedsbAP3f6H189730mXrfVAVCcY,7
48
+ okdata_cli-4.4.0.dist-info/top_level.txt,sha256=cS1IEDv6oxHgvQHrGSxFxjHTv5CNc9dLowH1vpCqF_k,11
49
+ okdata_cli-4.4.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.0)
2
+ Generator: setuptools (80.4.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5