Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ID-porten clients #217

Merged
merged 3 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## ?.?.? - Unreleased

* The `okdata pubreg` family of commands has been renamed to `okdata pubs` (for
"public services") to reflect that they now don't only handle Maskinporten
clients, but also ID-porten clients.
* Added support for creating CSV->Delta dataset pipelines.
* Added a shorthand for granting a user all permissions on a resource by not
specifying the `scope` parameter to the `permissions add` command, similar to
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Okdata CLI provides a unified interface to data services for Oslo Origo teams.

* [Install](doc/install.md)
* [Configuration](doc/configuration.md)
* [Public registers](doc/pubreg.md)
* [Public services](doc/pubs.md)
* [Teams](doc/teams.md)
* [Datasets](doc/datasets.md)
* [Permissions](doc/permissions.md)
Binary file removed doc/img/pubreg-wizard.png
Binary file not shown.
Binary file added doc/img/pubs-wizard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 16 additions & 15 deletions doc/pubreg.md → doc/pubs.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Public registers
# Public services

Commands related to accessing public registers are grouped under the `pubreg`
command prefix. Run the following command to see a list of all available
`pubreg` commands:
Commands related to accessing public services are grouped under the `pubs`
command prefix. Currently available public services are *Maskinporten* and
*ID-porten*. Run the following command to see a list of all available `pubs`
commands:

```sh
okdata pubreg -h
okdata pubs -h
```

Contents:
Expand All @@ -19,7 +20,7 @@ Contents:
* [Deleting a client key](#deleting-a-client-key)
* [Viewing a client's audit log](#viewing-a-clients-audit-log)

## Prerequisites
## Prerequisites for accessing public registries

Make sure you've got the right legal basis before accessing public registry
data. Read more about this in our [guidelines for accessing public
Expand All @@ -28,22 +29,22 @@ registers](https://github.com/oslokommune/dataplattform/blob/master/origo/regist
## Creating a client

The following command launches a step-by-step wizard to create a new client for
accessing a public register:
accessing a public service:

```sh
okdata pubreg create-client
okdata pubs create-client
```

Example values from the wizard:

![Example values from the wizard](img/pubreg-wizard.png)
![Example values from the wizard](img/pubs-wizard.png)

## Listing clients

Use the following command to display a table of all of your clients:

```sh
okdata pubreg list-clients
okdata pubs list-clients
```

## Deleting a client
Expand All @@ -52,7 +53,7 @@ When a client is no longer needed, it should be deleted by using the following
command:

```sh
okdata pubreg delete-client
okdata pubs delete-client
```

Clients with active keys cannot be deleted. In such cases, their keys have to be
Expand All @@ -73,7 +74,7 @@ The following command can be used to launch a step-by-step wizard to create a
new client key:

```sh
okdata pubreg create-key
okdata pubs create-key
```

Each client can hold a maximum of five keys. After reaching that limit, old keys
Expand Down Expand Up @@ -127,7 +128,7 @@ Use the following command to display a table of all the keys registered on one
or all of your clients:

```sh
okdata pubreg list-keys
okdata pubs list-keys
```

## Deleting a client key
Expand All @@ -136,7 +137,7 @@ When a key is no longer needed, it should be deleted by using the following
command:

```sh
okdata pubreg delete-key
okdata pubs delete-key
```

Note that key deletion is irreversible.
Expand All @@ -146,7 +147,7 @@ Note that key deletion is irreversible.
To view the audit log for a client, use the following command:

```sh
okdata pubreg audit-log
okdata pubs audit-log
```

Audit logs contain the history of events related to clients, including their
Expand Down
4 changes: 2 additions & 2 deletions okdata/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from okdata.cli.command import BaseCommand
from okdata.cli.commands.datasets import DatasetsCommand
from okdata.cli.commands.permissions import PermissionsCommand
from okdata.cli.commands.pubreg import PubregCommand
from okdata.cli.commands.pubs import PubsCommand
from okdata.cli.commands.status import StatusCommand
from okdata.cli.commands.teams.teams import TeamsCommand

Expand Down Expand Up @@ -69,7 +69,7 @@ def get_command_class(argv):
commands = {
"datasets": DatasetsCommand,
"permissions": PermissionsCommand,
"pubreg": PubregCommand,
"pubs": PubsCommand,
"status": StatusCommand,
"teams": TeamsCommand,
}
Expand Down
4 changes: 2 additions & 2 deletions okdata/cli/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ class BaseCommand:
usage:
okdata datasets [options]
okdata permissions [options]
okdata pubreg [options]
okdata pubs [options]
okdata status [options]
okdata teams [options]
okdata -h | --help

Commands available:
datasets
permissions
pubreg
pubs
status
teams

Expand Down
13 changes: 2 additions & 11 deletions okdata/cli/commands/datasets/questions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import csv

from questionary import Choice

from okdata.cli.commands.datasets.validators import (
from okdata.cli.commands.validators import (
KeywordValidator,
PhoneValidator,
SimpleEmailValidator,
Expand All @@ -11,7 +9,7 @@
StandardsValidator,
TitleValidator,
)
from okdata.cli.commands.wizard import required_style
from okdata.cli.commands.wizard import filter_comma_separated, required_style

pipeline_choices = {
"file": [
Expand All @@ -31,13 +29,6 @@
]


def filter_comma_separated(value):
values = next(
csv.reader([value], delimiter=",", escapechar="\\", skipinitialspace=True)
)
return [x.strip() for x in values if x]


def qs_create(include_extra_metadata=True):
return [
{
Expand Down
3 changes: 0 additions & 3 deletions okdata/cli/commands/pubreg/__init__.py

This file was deleted.

3 changes: 3 additions & 0 deletions okdata/cli/commands/pubs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from okdata.cli.commands.pubs.pubs import PubsCommand

__all__ = ["PubsCommand"]
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,48 @@
log = logging.getLogger()


class PubregClient(SDK):
class PubsClient(SDK):
def __init__(self, config=None, auth=None, env=None):
self.__name__ = "pubreg"
self.__name__ = "pubs"
super().__init__(config, auth, env)
self.api_url = "https://api.data{}.oslo.systems/maskinporten".format(
"-dev" if self.config.config["env"] == "dev" else ""
)

def create_client(self, team_id, provider, integration, scopes, env):
def create_maskinporten_client(self, team_id, provider, integration, scopes, env):
data = {
"client_type": "maskinporten",
"team_id": team_id,
"provider": provider,
"integration": integration,
"scopes": scopes,
"env": env,
}
log.info(f"Creating client with payload: {data}")
log.info(f"Creating Maskinporten client with payload: {data}")
return self.post(f"{self.api_url}/clients", data=data).json()

def create_idporten_client(
self,
team_id,
integration,
client_uri,
frontchannel_logout_uri,
redirect_uris,
post_logout_redirect_uris,
env,
):
data = {
"client_type": "idporten",
"team_id": team_id,
"provider": "idporten",
"integration": integration,
"client_uri": client_uri,
"frontchannel_logout_uri": frontchannel_logout_uri,
"redirect_uris": redirect_uris,
"post_logout_redirect_uris": post_logout_redirect_uris,
"env": env,
}
log.info(f"Creating ID-porten client with payload: {data}")
return self.post(f"{self.api_url}/clients", data=data).json()

def get_clients(self, env):
Expand Down
Loading
Loading