Skip to content
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
36 changes: 36 additions & 0 deletions cirro/sdk/portal.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from cirro_api_client.v1.models import Executor

from cirro.auth.client_creds import ClientCredentialsAuth
from cirro.cirro_client import CirroApi
from cirro.config import AppConfig
from cirro.sdk.dataset import DataPortalDataset
from cirro.sdk.developer import DeveloperHelper
from cirro.sdk.exceptions import DataPortalAssetNotFound
Expand Down Expand Up @@ -40,6 +42,40 @@ def __init__(self, base_url: str = None, client: CirroApi = None):
else:
self._client = CirroApi(base_url=base_url)

@classmethod
def from_client_credentials(cls, client_id: str, client_secret: str, base_url: str = None) -> 'DataPortal':
"""
Set up the DataPortal object, authenticating using an OAuth client credentials pair
(e.g., a service account or automated integration), rather than an interactive user login.

Args:
client_id (str): OAuth Client ID
client_secret (str): OAuth Client Secret
base_url (str): Optional base URL of the Cirro instance
(if not provided, it uses the `CIRRO_BASE_URL` environment variable, or the config file)

Example:
```python
import os
from cirro import DataPortal

portal = DataPortal.from_client_credentials(
client_id=os.environ['CIRRO_CLIENT_ID'],
client_secret=os.environ['CIRRO_CLIENT_SECRET'],
base_url="app.cirro.bio"
)
portal.list_projects()
```
"""
app_config = AppConfig(base_url=base_url)
auth_info = ClientCredentialsAuth(
client_id=client_id,
client_secret=client_secret,
auth_endpoint=app_config.auth_endpoint
)
client = CirroApi(auth_info=auth_info, base_url=base_url)
return cls(client=client)

def list_projects(self) -> DataPortalProjects:
"""List all the projects available in the Data Portal."""

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cirro"
version = "1.13.0"
version = "1.13.1"
description = "CLI tool and SDK for interacting with the Cirro platform"
authors = ["Cirro Bio <support@cirro.bio>"]
license = "MIT"
Expand Down
26 changes: 26 additions & 0 deletions samples/Logging_In.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,32 @@
"# Wait for the user to complete the login, and then return a DataPortal object\n",
"portal = cirro_login.await_completion()"
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": [
"### Service Account / Automated Logon\n",
"\n",
"When logging in using a service account it is necessary to use the `from_client_credentials` method to provide the OAuth credentials."
]
},
{
"metadata": {},
"cell_type": "code",
"source": [
"import os\n",
"from cirro import DataPortal\n",
"\n",
"portal = DataPortal.from_client_credentials(\n",
" client_id=os.environ['CIRRO_CLIENT_ID'],\n",
" client_secret=os.environ['CIRRO_CLIENT_SECRET'],\n",
" base_url=\"app.cirro.bio\"\n",
")\n",
"portal.list_projects()"
],
"outputs": [],
"execution_count": null
}
],
"metadata": {
Expand Down
Loading