Skip to content

Commit

Permalink
Issue3 ant.1 (#5)
Browse files Browse the repository at this point in the history
* Initial

* Initial

* Lint issues

* Update CHANGELOG.md
  • Loading branch information
antaenc authored Dec 22, 2022
1 parent c0f6515 commit 715b26f
Show file tree
Hide file tree
Showing 142 changed files with 370,352 additions and 725 deletions.
21 changes: 21 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
[pylint]
disable=
attribute-defined-outside-init,
broad-except,
consider-using-f-string,
duplicate-code,
global-statement,
global-variable-undefined,
import-error,
invalid-name,
line-too-long,
logging-fstring-interpolation,
missing-class-docstring,
missing-function-docstring,
missing-module-docstring,
protected-access,
redefined-outer-name,
simplifiable-if-statement,
too-few-public-methods,
too-many-arguments,
too-many-branches,
too-many-instance-attributes,
too-many-lines,
too-many-locals,
too-many-nested-blocks,
too-many-statements,
unspecified-encoding,
unused-argument,
good-names=
template-python
ignore=
Expand Down
20 changes: 2 additions & 18 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
[markdownlint](https://dlaa.me/markdownlint/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

- Thing 5
- Thing 4

## [1.0.1] - yyyy-mm-dd

### Added to 1.0.1

- Thing 3

### Fixed in 1.0.1

- Thing 2

## [1.0.0] - yyyy-mm-dd
## [1.0.0] - 2022-12-22

### Added to 1.0.0

- Thing 2
- Thing 1
- Initial
41 changes: 22 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
ARG BASE_IMAGE=debian:11.5-slim@sha256:e8ad0bc7d0ee6afd46e904780942033ab83b42b446b58efa88d31ecf3adf4678
ARG BASE_IMAGE=senzing/senzingapi-runtime
FROM ${BASE_IMAGE}

ENV REFRESHED_AT=2022-10-27
ENV REFRESHED_AT=2022-12-21

LABEL Name="senzing/template-python" \
LABEL Name="senzing/code-snippets" \
Maintainer="[email protected]" \
Version="1.0.0"

HEALTHCHECK CMD ["/app/healthcheck.sh"]
Version="0.0.1"

# Run as "root" for system installation.

Expand All @@ -17,29 +15,34 @@ USER root

RUN apt-get update \
&& apt-get -y install \
vim \
nano \
curl \
less \
python3 \
ipython3 \
python3-pip \
python3-virtualenv \
python3-venv \
&& rm -rf /var/lib/apt/lists/*

# Install packages via PIP.

COPY requirements.txt ./
RUN pip3 install --upgrade pip \
&& pip3 install -r requirements.txt \
&& rm requirements.txt

# Install packages via apt.

# Copy files from repository.
## Copy files from repository.

COPY ./Python/ /code-snippets/Python
COPY ./Resources/ /code-snippets/Resources
COPY ./rootfs /

# Make non-root container.

USER 1001

# Runtime execution.
# Runtime environment variables.

ENV LD_LIBRARY_PATH=/opt/senzing/g2/lib:/opt/senzing/g2/lib/debian
ENV PATH=${PATH}:/opt/senzing/g2/python
ENV PYTHONPATH=/opt/senzing/g2/sdk/python
ENV PYTHONUNBUFFERED=1
ENV SENZING_DOCKER_LAUNCHED=true

WORKDIR /app
CMD ["/app/sleep-infinity.sh"]
WORKDIR /code-snippets
ENTRYPOINT ["/bin/bash"]
41 changes: 41 additions & 0 deletions Python/APIs/G2Config/Data_Source_Management/addDataSource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#! /usr/bin/env python3

import os
import sys
from senzing import G2Config, G2ConfigMgr, G2BadInputException, G2Exception, G2RetryableException, G2UnrecoverableException

engine_config_json = os.getenv('SENZING_ENGINE_CONFIGURATION_JSON', None)
add_response = bytearray()
current_config = bytearray()
current_config_id = bytearray()
new_config = bytearray()
new_config_id = bytearray()

try:
g2_config = G2Config()
g2_config_mgr = G2ConfigMgr()

g2_config.init('G2Config', engine_config_json, False)
g2_config_mgr.init('G2ConfigMgr', engine_config_json, False)

g2_config_mgr.getDefaultConfigID(current_config_id)
g2_config_mgr.getConfig(current_config_id, current_config)

config_handle = g2_config.load(current_config)
g2_config.addDataSource(config_handle, '{"DSRC_CODE": "CUSTOMERS"}', add_response)
g2_config.addDataSource(config_handle, '{"DSRC_CODE": "WATCHLIST"}', add_response)
g2_config.addDataSource(config_handle, '{"DSRC_CODE": "REFERENCE"}', add_response)
g2_config.addDataSource(config_handle, '{"DSRC_CODE": "MYTEST"}', add_response)
g2_config.save(config_handle, new_config)

g2_config_mgr.addConfig(new_config, 'Test data sources added', new_config_id)
g2_config_mgr.setDefaultConfigID(new_config_id)

g2_config.destroy()
g2_config_mgr.destroy()

except (G2BadInputException, G2RetryableException, G2UnrecoverableException, G2Exception) as ex:
print(ex)
sys.exit(-1)

print(f'Datasources added, new default config ID: {new_config_id.decode()}')
40 changes: 40 additions & 0 deletions Python/APIs/G2Config/Data_Source_Management/deleteDataSource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#! /usr/bin/env python3

import os
import sys
from senzing import G2Config, G2ConfigMgr, G2BadInputException, G2Exception, G2RetryableException, G2UnrecoverableException

engine_config_json = os.getenv('SENZING_ENGINE_CONFIGURATION_JSON', None)
add_response = bytearray()
current_config = bytearray()
current_config_id = bytearray()
new_config = bytearray()
new_config_id = bytearray()


try:
g2_config = G2Config()
g2_config_mgr = G2ConfigMgr()

g2_config.init('G2Config', engine_config_json, False)
g2_config_mgr.init('G2ConfigMgr', engine_config_json, False)

g2_config_mgr.getDefaultConfigID(current_config_id)
g2_config_mgr.getConfig(current_config_id, current_config)

config_handle = g2_config.load(current_config)

g2_config.deleteDataSource(config_handle, '{"DSRC_CODE": "MYTEST"}')
g2_config.save(config_handle, new_config)
g2_config.close(config_handle)

g2_config_mgr.addConfig(new_config, 'Data source deleted', new_config_id)
g2_config_mgr.setDefaultConfigID(new_config_id)

g2_config.destroy()
g2_config_mgr.destroy()
except (G2BadInputException, G2RetryableException, G2UnrecoverableException, G2Exception) as ex:
print(ex)
sys.exit(-1)

print(f'Datasource deleted, new default config ID: {new_config_id.decode()}')
32 changes: 32 additions & 0 deletions Python/APIs/G2Config/Data_Source_Management/listDataSources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#! /usr/bin/env python3

import os
import sys
from senzing import G2Config, G2ConfigMgr, G2BadInputException, G2Exception, G2RetryableException, G2UnrecoverableException

engine_config_json = os.getenv('SENZING_ENGINE_CONFIGURATION_JSON', None)
current_config = bytearray()
current_config_id = bytearray()
data_sources = bytearray()

try:
g2_config = G2Config()
g2_config_mgr = G2ConfigMgr()

g2_config.init('G2Config', engine_config_json, False)
g2_config_mgr.init('G2ConfigMgr', engine_config_json, False)

g2_config_mgr.getDefaultConfigID(current_config_id)
g2_config_mgr.getConfig(current_config_id, current_config)
config_handle = g2_config.load(current_config)

g2_config.listDataSources(config_handle, data_sources)
g2_config.close(config_handle)

g2_config.destroy()
g2_config_mgr.destroy()
except (G2BadInputException, G2RetryableException, G2UnrecoverableException, G2Exception) as ex:
print(ex)
sys.exit(-1)

print(data_sources.decode())
25 changes: 25 additions & 0 deletions Python/APIs/G2ConfigMgr/Config_Management/addConfig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#! /usr/bin/env python3

import os
import sys
from senzing import G2ConfigMgr, G2BadInputException, G2Exception, G2RetryableException, G2UnrecoverableException

engine_config_json = os.getenv('SENZING_ENGINE_CONFIGURATION_JSON', None)
current_config_id = bytearray()
current_config = bytearray()
new_config_id = bytearray()

with open('../../../../Resources/Configs/Test_Config.json', 'r') as file:
config = file.read().strip()

try:
g2_config_mgr = G2ConfigMgr()
g2_config_mgr.init('G2ConfigMgr', engine_config_json, False)
g2_config_mgr.addConfig(config, 'Testing adding a config.', new_config_id)
g2_config_mgr.setDefaultConfigID(new_config_id.decode())
g2_config_mgr.destroy()
except (G2BadInputException, G2RetryableException, G2UnrecoverableException, G2Exception) as ex:
print(ex)
sys.exit(-1)

print(f'Configuration added, new configuration ID: {new_config_id.decode()}')
21 changes: 21 additions & 0 deletions Python/APIs/G2ConfigMgr/Config_Management/getConfig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#! /usr/bin/env python3

import os
import sys
from senzing import G2ConfigMgr, G2BadInputException, G2Exception, G2RetryableException, G2UnrecoverableException

engine_config_json = os.getenv('SENZING_ENGINE_CONFIGURATION_JSON', None)
current_config_id = bytearray()
config = bytearray()

try:
g2_config_mgr = G2ConfigMgr()
g2_config_mgr.init('G2ConfigMgr', engine_config_json, False)
g2_config_mgr.getDefaultConfigID(current_config_id)
g2_config_mgr.getConfig(current_config_id.decode(), config)
g2_config_mgr.destroy()
except (G2BadInputException, G2RetryableException, G2UnrecoverableException, G2Exception) as ex:
print(ex)
sys.exit(-1)

print(config.decode())
19 changes: 19 additions & 0 deletions Python/APIs/G2ConfigMgr/Config_Management/getConfigList.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#! /usr/bin/env python3

import os
import sys
from senzing import G2ConfigMgr, G2BadInputException, G2Exception, G2RetryableException, G2UnrecoverableException

engine_config_json = os.getenv('SENZING_ENGINE_CONFIGURATION_JSON', None)
config_list = bytearray()

try:
g2_config_mgr = G2ConfigMgr()
g2_config_mgr.init('G2ConfigMgr', engine_config_json, False)
g2_config_mgr.getConfigList(config_list)
g2_config_mgr.destroy()
except (G2BadInputException, G2RetryableException, G2UnrecoverableException, G2Exception) as ex:
print(ex)
sys.exit(-1)

print(config_list.decode())
19 changes: 19 additions & 0 deletions Python/APIs/G2ConfigMgr/Config_Management/getDefaultConfigID.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#! /usr/bin/env python3

import os
import sys
from senzing import G2ConfigMgr, G2BadInputException, G2Exception, G2RetryableException, G2UnrecoverableException

engine_config_json = os.getenv('SENZING_ENGINE_CONFIGURATION_JSON', None)
config_id = bytearray()

try:
g2_config_mgr = G2ConfigMgr()
g2_config_mgr.init('G2ConfigMgr', engine_config_json, False)
g2_config_mgr.getDefaultConfigID(config_id)
g2_config_mgr.destroy()
except (G2BadInputException, G2RetryableException, G2UnrecoverableException, G2Exception) as ex:
print(ex)
sys.exit(-1)

print(f'Default config ID: {config_id.decode()}')
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#! /usr/bin/env python3

import os
import sys
from senzing import G2ConfigMgr, G2BadInputException, G2Exception, G2RetryableException, G2UnrecoverableException

engine_config_json = os.getenv('SENZING_ENGINE_CONFIGURATION_JSON', None)
CURRENT_CONFIG_ID = 1646704028
NEW_CONFIG_ID = 1888647012

try:
g2_config_mgr = G2ConfigMgr()
g2_config_mgr.init('G2ConfigMgr', engine_config_json, False)
g2_config_mgr.replaceDefaultConfigID(CURRENT_CONFIG_ID, NEW_CONFIG_ID)
g2_config_mgr.destroy()
except (G2BadInputException, G2RetryableException, G2UnrecoverableException, G2Exception) as ex:
print(ex)
sys.exit(-1)

print(f'Previous config ID {CURRENT_CONFIG_ID} replaced with {NEW_CONFIG_ID}')
19 changes: 19 additions & 0 deletions Python/APIs/G2ConfigMgr/Config_Management/setDefaultConfigID.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#! /usr/bin/env python3

import os
import sys
from senzing import G2ConfigMgr, G2BadInputException, G2Exception, G2RetryableException, G2UnrecoverableException

engine_config_json = os.getenv('SENZING_ENGINE_CONFIGURATION_JSON', None)
CONFIG_ID = 1646704028

try:
g2_config_mgr = G2ConfigMgr()
g2_config_mgr.init('G2ConfigMgr', engine_config_json, False)
g2_config_mgr.setDefaultConfigID(CONFIG_ID)
g2_config_mgr.destroy()
except (G2BadInputException, G2RetryableException, G2UnrecoverableException, G2Exception) as ex:
print(ex)
sys.exit(-1)

print(f'Default config ID set to: {CONFIG_ID}')
Loading

0 comments on commit 715b26f

Please sign in to comment.