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
58 changes: 45 additions & 13 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -1,71 +1,103 @@
jobs:
arrange:
container: ghcr.io/elimity-com/insights-sdk:14245239418
container: ghcr.io/elimity-com/insights-sdk:18279107697
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- run: test -z "$(goarrange run -d)"

black:
Comment on lines +3 to +9

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
container: ghcr.io/elimity-com/insights-sdk:18279107697
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- run: poetry install
- run: poetry run black --check src

buf-generate:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
container: ghcr.io/elimity-com/insights-sdk:14245239418
container: ghcr.io/elimity-com/insights-sdk:18279107697
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npx buf generate
- run: buf generate
- run: poetry install
- run: poetry run protol -o gen/elimity --create-package --in-place buf
- run: touch gen/elimity/py.typed
- run: git -c safe.directory=/__w/insights-sdk/insights-sdk diff --quiet

buf-lint:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
container: ghcr.io/elimity-com/insights-sdk:14245239418
container: ghcr.io/elimity-com/insights-sdk:18279107697
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npx buf lint
- run: buf lint

check:
Comment on lines +29 to +35

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
container: ghcr.io/elimity-com/insights-sdk:18279107697
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- run: poetry check --lock

eslint:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
container: ghcr.io/elimity-com/insights-sdk:14245239418
container: ghcr.io/elimity-com/insights-sdk:18279107697
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npx eslint .

golangci-lint:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
container: ghcr.io/elimity-com/insights-sdk:14245239418
container: ghcr.io/elimity-com/insights-sdk:18279107697
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- run: GOFLAGS='-buildvcs=false' golangci-lint run

isort:
Comment on lines +51 to +57

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
container: ghcr.io/elimity-com/insights-sdk:18279107697
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- run: poetry install
- run: poetry run isort -c src

mypy:
Comment on lines +58 to +65

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
container: ghcr.io/elimity-com/insights-sdk:18279107697
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- run: poetry install
- run: poetry run mypy src

prettier:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
container: ghcr.io/elimity-com/insights-sdk:14245239418
container: ghcr.io/elimity-com/insights-sdk:18279107697
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npx prettier -c .

test:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
container: ghcr.io/elimity-com/insights-sdk:14245239418
container: ghcr.io/elimity-com/insights-sdk:18279107697
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- run: go test -v ./...

tidy:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
container: ghcr.io/elimity-com/insights-sdk:14245239418
container: ghcr.io/elimity-com/insights-sdk:18279107697
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- run: go mod tidy -diff

tsc:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
container: ghcr.io/elimity-com/insights-sdk:14245239418
container: ghcr.io/elimity-com/insights-sdk:18279107697
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npx tsc

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

on: pull_request
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
jobs:
job:
container: ghcr.io/elimity-com/insights-sdk:14245239418
container: ghcr.io/elimity-com/insights-sdk:18279107697
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm version --no-git-tag-version ${{ github.event.release.tag_name }}
- run: npx tsc
- run: env NPM_CONFIG_//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }} npm publish --access public
- run: poetry version $(poetry version -s --dry-run ${{ github.event.release.tag_name }})
- run: POETRY_PYPI_TOKEN_PYPI=${{ secrets.PYPI_TOKEN }} poetry publish --build
Comment on lines +3 to +12

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

on:
release:
Expand Down
2 changes: 2 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[settings]
profile = black
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
FROM node:lts
FROM node:lts-trixie
ARG TARGETARCH
ENV PATH=$PATH:/root/go/bin:/usr/local/go/bin
ENV PATH=$PATH:/root/.local/bin:/root/go/bin:/usr/local/go/bin
RUN \
curl -L https://go.dev/dl/go1.24.1.linux-$TARGETARCH.tar.gz | tar -C /usr/local -xz && \
curl https://install.python-poetry.org | python3 && \
curl https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh && \
go install github.com/bufbuild/buf/cmd/buf@latest && \
go install github.com/jdeflander/goarrange@latest
62 changes: 60 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Elimity Insights SDK

This repository contains a Go and NodeJS package to simplify the implementation of various interactions with Elimity
Insights servers.
This repository contains a Go, NodeJS and Python package to simplify the implementation of various interactions with
Elimity Insights servers.

## Usage

Expand Down Expand Up @@ -165,6 +165,58 @@ const sdkHandler = handler(generateItems);
express().use(authHandler, sdkHandler).listen(8080);
```

### Python

```python
from collections.abc import AsyncIterator
from os import listdir
from typing import Literal

from auth0_api_python import ApiClient, ApiClientOptions
from elimity_insights_sdk import EntityItem, Item, Level, LogItem, Value, app
from pydantic import BaseModel
from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint
from starlette.requests import Request
from starlette.responses import Response
from uvicorn import run

_options = ApiClientOptions("auth.elimity.com", "gateway")
_client = ApiClient(_options)


class _Claims(BaseModel):
base_url: Literal["https://example.elimity.com"]
gateway_url: Literal["https://gateway.example.com"]
source_id: Literal["42"]


class _Middleware(BaseHTTPMiddleware):
async def dispatch(
self, request: Request, call_next: RequestResponseEndpoint
) -> Response:
headers = dict(request.headers)
claims = await _client.verify_request(headers)
_Claims.model_validate(claims)
return await call_next(request)


class _Request(BaseModel):
path: str


async def _generate_items(fields: dict[str, object]) -> AsyncIterator[Item]:
request = _Request.model_validate(fields)
yield LogItem(Level.INFO, "Reading directory contents")
for file in listdir(request.path):
assignments: dict[str, Value] = {}
yield EntityItem(assignments, file, file, "file")


_app = app(_generate_items)
_middleware = _Middleware(_app)
run(_middleware)
```

## Installation

### Go
Expand All @@ -179,6 +231,12 @@ $ go get github.com/elimity-com/insights-sdk
$ npm i @elimity/insights-sdk
```

### Python

```
$ pip install elimity-insights-sdk
```

## Compatibility

| SDK version | Insights version |
Expand Down
9 changes: 9 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@ plugins:
out: gen
remote: buf.build/connectrpc/es:v1.6.1
revision: 1
- out: gen
remote: buf.build/connectrpc/python:v0.5.0
revision: 1
- out: gen
remote: buf.build/protocolbuffers/pyi:v29.5
revision: 1
- out: gen
remote: buf.build/protocolbuffers/python:v29.5
revision: 1
version: v2
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:
dev:
entrypoint: sleep infinity
image: ghcr.io/elimity-com/insights-sdk:14245239418
image: ghcr.io/elimity-com/insights-sdk:18279107697
init: true
volumes:
- .:/app
Expand Down
Empty file added gen/elimity/__init__.py
Empty file.
1 change: 1 addition & 0 deletions gen/elimity/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import insights
Empty file.
3 changes: 3 additions & 0 deletions gen/elimity/insights/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import common
from . import customgateway
from . import export
Empty file.
1 change: 1 addition & 0 deletions gen/elimity/insights/common/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import v1alpha1
Empty file.
1 change: 1 addition & 0 deletions gen/elimity/insights/common/v1alpha1/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import common_pb2
50 changes: 50 additions & 0 deletions gen/elimity/insights/common/v1alpha1/common_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions gen/elimity/insights/common/v1alpha1/common_pb2.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from google.protobuf import timestamp_pb2 as _timestamp_pb2
from google.protobuf.internal import containers as _containers
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from typing import ClassVar as _ClassVar, Mapping as _Mapping, Optional as _Optional, Union as _Union

DESCRIPTOR: _descriptor.FileDescriptor

class Entity(_message.Message):
__slots__ = ("attribute_assignments", "id", "name", "type")
class AttributeAssignmentsEntry(_message.Message):
__slots__ = ("key", "value")
KEY_FIELD_NUMBER: _ClassVar[int]
VALUE_FIELD_NUMBER: _ClassVar[int]
key: str
value: Value
def __init__(self, key: _Optional[str] = ..., value: _Optional[_Union[Value, _Mapping]] = ...) -> None: ...
ATTRIBUTE_ASSIGNMENTS_FIELD_NUMBER: _ClassVar[int]
ID_FIELD_NUMBER: _ClassVar[int]
NAME_FIELD_NUMBER: _ClassVar[int]
TYPE_FIELD_NUMBER: _ClassVar[int]
attribute_assignments: _containers.MessageMap[str, Value]
id: str
name: str
type: str
def __init__(self, attribute_assignments: _Optional[_Mapping[str, Value]] = ..., id: _Optional[str] = ..., name: _Optional[str] = ..., type: _Optional[str] = ...) -> None: ...

class Relationship(_message.Message):
__slots__ = ("attribute_assignments", "from_entity_id", "from_entity_type", "to_entity_id", "to_entity_type")
class AttributeAssignmentsEntry(_message.Message):
__slots__ = ("key", "value")
KEY_FIELD_NUMBER: _ClassVar[int]
VALUE_FIELD_NUMBER: _ClassVar[int]
key: str
value: Value
def __init__(self, key: _Optional[str] = ..., value: _Optional[_Union[Value, _Mapping]] = ...) -> None: ...
ATTRIBUTE_ASSIGNMENTS_FIELD_NUMBER: _ClassVar[int]
FROM_ENTITY_ID_FIELD_NUMBER: _ClassVar[int]
FROM_ENTITY_TYPE_FIELD_NUMBER: _ClassVar[int]
TO_ENTITY_ID_FIELD_NUMBER: _ClassVar[int]
TO_ENTITY_TYPE_FIELD_NUMBER: _ClassVar[int]
attribute_assignments: _containers.MessageMap[str, Value]
from_entity_id: str
from_entity_type: str
to_entity_id: str
to_entity_type: str
def __init__(self, attribute_assignments: _Optional[_Mapping[str, Value]] = ..., from_entity_id: _Optional[str] = ..., from_entity_type: _Optional[str] = ..., to_entity_id: _Optional[str] = ..., to_entity_type: _Optional[str] = ...) -> None: ...

class Value(_message.Message):
__slots__ = ("boolean", "date", "date_time", "number", "string", "time")
BOOLEAN_FIELD_NUMBER: _ClassVar[int]
DATE_FIELD_NUMBER: _ClassVar[int]
DATE_TIME_FIELD_NUMBER: _ClassVar[int]
NUMBER_FIELD_NUMBER: _ClassVar[int]
STRING_FIELD_NUMBER: _ClassVar[int]
TIME_FIELD_NUMBER: _ClassVar[int]
boolean: bool
date: _timestamp_pb2.Timestamp
date_time: _timestamp_pb2.Timestamp
number: float
string: str
time: _timestamp_pb2.Timestamp
def __init__(self, boolean: bool = ..., date: _Optional[_Union[_timestamp_pb2.Timestamp, _Mapping]] = ..., date_time: _Optional[_Union[_timestamp_pb2.Timestamp, _Mapping]] = ..., number: _Optional[float] = ..., string: _Optional[str] = ..., time: _Optional[_Union[_timestamp_pb2.Timestamp, _Mapping]] = ...) -> None: ...
Empty file.
1 change: 1 addition & 0 deletions gen/elimity/insights/customgateway/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import v1alpha1
Empty file.
2 changes: 2 additions & 0 deletions gen/elimity/insights/customgateway/v1alpha1/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import customgateway_pb2
from . import v1alpha1connect
Loading
Loading