Skip to content

Commit

Permalink
Report sdk version (#20)
Browse files Browse the repository at this point in the history
* add sdk version to id api response

* add to web api

* Update tests/test_utilities.py

Co-authored-by: Michael <michael.l.dangelo@gmail.com>

* Update tests/test_utilities.py

Co-authored-by: Michael <michael.l.dangelo@gmail.com>

* fix formatting bug

* Fix version test

Co-authored-by: mldangelo <michael.l.dangelo@gmail.com>
  • Loading branch information
ayinloya and mldangelo authored Nov 21, 2022
1 parent 754922c commit fe4b532
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 20 deletions.
64 changes: 64 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Add coverage reports.
- Added github action to release the package.

### Changed
- improved the documentation.
- Added types to IdApi, ServerError, Utilities, and WebApi classes.
- Renamed WebApi get_job_status param from sec_params to signature_params
- Renamed WebApi poll_job_status param from sec_params to signature_params

### Removed
- Remove sec key

## [1.0.9] - 2022-11-01
### Added
- Python 3.11 support.
- Package version now available via `__version__` attribute.

### Changed
- Project is now built with [Poetry](https://python-poetry.org).
- Moved information of python version to the class initialization.
- Lint codebase using black.

## [1.0.8] - 2022-04-26
### Fixed
- Fixed a bug with optional `job_type` parameter for job status endpoint.

## [1.0.7] - 2022-04-26
### Changed
- Do not require `job_type` to be set for job status endpoint.

## [1.0.6] - 2022-04-25
### Added
- Added support for image files ending with `.jpeg`.

### Changed
- make `return_images` and `return_history` optional arguments for job status endpoint.

## [1.0.5] - 2022-02-28
### Added
- Added support for Document Verification job type.

## [1.0.4] - 2022-02-07
## [1.0.3] - 2021-11-10
## [1.0.2] - 2021-11-02
## [1.0.1] - 2021-10-04
## [1.0.0] - 2021-09-13

## [0.0.13] - 2020-09-16
### Added
- Created changelog.
- Fixed job status error string format.
- Added black for code formatting.
- Fixed python semantics.
- Moved zipfile out from webapi class.

## [0.0.12] - 2022-08-19
12 changes: 6 additions & 6 deletions poetry.lock

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

8 changes: 5 additions & 3 deletions smile_id_core/IdApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from smile_id_core.Utilities import (
Utilities,
get_signature,
get_version,
sid_server_map,
validate_signature_params,
)
Expand Down Expand Up @@ -64,13 +65,14 @@ def __configure_json(
self, partner_params: Dict, id_params: Dict, signature: Dict
) -> Dict:
validate_signature_params(signature)
payload = {
return {
**signature,
"partner_id": self.partner_id,
"partner_params": partner_params,
"source_sdk": "Python",
"source_sdk_version": get_version(),
**id_params,
}
payload.update(id_params)
return payload

def __execute_http(self, payload: Dict) -> Response:
data = json.dumps(payload)
Expand Down
24 changes: 23 additions & 1 deletion smile_id_core/Utilities.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,42 @@
import json
import sys
from typing import Dict, Optional, Union

import requests
from requests import Response

# import importlib.metadata if available, otherwise importlib_metadata (for Python < 3.8)
if sys.version_info >= (3, 8):
import importlib.metadata as importlib_metadata
else:
import importlib_metadata

from smile_id_core.ServerError import ServerError
from smile_id_core.Signature import Signature

__all__ = ["Utilities", "get_signature", "validate_signature_params", "sid_server_map"]
__all__ = [
"Utilities",
"get_signature",
"get_version",
"validate_signature_params",
"sid_server_map",
]

sid_server_map = {
0: "https://testapi.smileidentity.com/v1",
1: "https://api.smileidentity.com/v1",
}


def get_version() -> str:
"""Return the module version number specified in pyproject.toml.
Returns:
str: The module version number
"""
return importlib_metadata.version(__package__)


class Utilities:
def __init__(self, partner_id: str, api_key: str, sid_server: Union[int, str]):
if not partner_id or not api_key:
Expand Down
3 changes: 3 additions & 0 deletions smile_id_core/WebApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from smile_id_core.Utilities import (
Utilities,
get_signature,
get_version,
sid_server_map,
validate_signature_params,
)
Expand Down Expand Up @@ -203,6 +204,8 @@ def __prepare_prep_upload_payload(
"model_parameters": {},
"callback_url": self.call_back_url,
"use_enrolled_image": use_enrolled_image,
"source_sdk": "Python",
"source_sdk_version": get_version(),
**signature_params,
}

Expand Down
11 changes: 2 additions & 9 deletions smile_id_core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import sys

if sys.version_info >= (3, 8):
import importlib.metadata as importlib_metadata
else:
import importlib_metadata

from smile_id_core.IdApi import IdApi
from smile_id_core.ServerError import ServerError
from smile_id_core.Signature import Signature
from smile_id_core.Utilities import Utilities
from smile_id_core.Utilities import Utilities, get_version
from smile_id_core.WebApi import WebApi

__version__ = importlib_metadata.version(__package__)
__version__ = get_version()
__all__ = ["IdApi", "Signature", "Utilities", "WebApi", "ServerError"]
11 changes: 10 additions & 1 deletion tests/test_utilities.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import base64
import re
from datetime import datetime
from uuid import uuid4

Expand All @@ -7,10 +8,18 @@
from Crypto.Cipher import PKCS1_v1_5
from Crypto.PublicKey import RSA

from smile_id_core import Signature, Utilities
from smile_id_core import Signature, Utilities, get_version
from tests.stub_mixin import TestCaseWithStubs


def test_get_version():
"""Test that a well formatted version string is returned."""
version = get_version()
assert isinstance(version, str)
# tests that the version is in the form of a semver string.
assert re.match(r"^\d+\.\d+\.\d+$", version)


class TestUtilities(TestCaseWithStubs):
def setUp(self):
self.key = RSA.generate(2048)
Expand Down

0 comments on commit fe4b532

Please sign in to comment.