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
21 changes: 17 additions & 4 deletions common-contract/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,22 @@ setup.py
pdo/__init__.py
pdo/contracts/common.py
pdo/contracts/__init__.py
pdo/contracts/jupyter/services.py
pdo/contracts/jupyter/groups.py
pdo/contracts/guardian/common/__init__.py
pdo/contracts/guardian/common/capability_keys.py
pdo/contracts/guardian/common/capability_keystore.py
pdo/contracts/guardian/common/endpoint_registry.py
pdo/contracts/guardian/common/guardian_service.py
pdo/contracts/guardian/common/secrets.py
pdo/contracts/guardian/common/utility.py
pdo/contracts/guardian/wsgi/__init__.py
pdo/contracts/guardian/wsgi/add_endpoint.py
pdo/contracts/guardian/wsgi/info.py
pdo/contracts/guardian/wsgi/process_capability.py
pdo/contracts/guardian/wsgi/provision_token_issuer.py
pdo/contracts/guardian/wsgi/provision_token_object.py
pdo/contracts/jupyter/__init__.py
pdo/contracts/jupyter/common_widgets.py
pdo/contracts/jupyter/utility.py
pdo/contracts/jupyter/groups.py
pdo/contracts/jupyter/keys.py
pdo/contracts/jupyter/__init__.py
pdo/contracts/jupyter/services.py
pdo/contracts/jupyter/utility.py
2 changes: 1 addition & 1 deletion common-contract/pdo/contracts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__all__ = [ 'common', 'jupyter' ]
__all__ = [ 'common', 'guardian', 'jupyter' ]
15 changes: 15 additions & 0 deletions common-contract/pdo/contracts/guardian/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2024 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

__all__ = [ 'common', 'scripts', 'wsgi']
22 changes: 22 additions & 0 deletions common-contract/pdo/contracts/guardian/common/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2023 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

__all__ = [
'capability_keys',
'capability_keystore',
'endpoint_registry',
'guardian_service',
'secrets',
'utility',
]
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import shelve

from pdo.inference.common.capability_keys import CapabilityKeys
from pdo.contracts.guardian.common.capability_keys import CapabilityKeys

import logging
logger = logging.getLogger(__name__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import json

from pdo.inference.common.utility import ValidateJSON
from pdo.contracts.guardian.common.utility import ValidateJSON
import pdo.common.crypto as crypto

import logging
Expand All @@ -44,7 +44,7 @@
def recv_secret(capability_key, secret) :
"""Process an incoming secret

:param capability_key pdo.inference.common.capability_keys.CapabilityKeys: decryption key
:param capability_key pdo.contracts.guardian.common.capability_keys.CapabilityKeys: decryption key
:param secret str: the secret to be unpacked
:returns dict: the parsed json message in the secret
"""
Expand All @@ -68,7 +68,7 @@ def recv_secret(capability_key, secret) :
def send_secret(capability_key, message) :
"""Create a secret for transmission

:param capability_key pdo.inference.common.capability_keys.CapabilityKeys: decryption key
:param capability_key pdo.contracts.guardian.common.capability_keys.CapabilityKeys: decryption key
:param message dict: dictionary that will be encrypted as JSON in the secret
:returns dict: the secret
"""
Expand Down
23 changes: 23 additions & 0 deletions common-contract/pdo/contracts/guardian/common/utility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2023 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import jsonschema

# -----------------------------------------------------------------
def ValidateJSON(instance, schema):
try:
jsonschema.validate(instance=instance, schema=schema)
except jsonschema.exceptions.ValidationError as err:
return False
return True
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
import pdo.common.utility as putils

from pdo.common.wsgi import AppWrapperMiddleware
from pdo.inference.wsgi import wsgi_operation_map
from pdo.inference.common.capability_keystore import CapabilityKeyStore
from pdo.inference.common.endpoint_registry import EndpointRegistry
from pdo.contracts.guardian.wsgi import wsgi_operation_map
from pdo.contracts.guardian.common.capability_keystore import CapabilityKeyStore
from pdo.contracts.guardian.common.endpoint_registry import EndpointRegistry

import logging
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -83,7 +83,7 @@ def TestService(config) :
"""

from pdo.service_client.generic import MessageException
from pdo.inference.common.guardian_service import GuardianServiceClient
from pdo.contracts.guardian.common.guardian_service import GuardianServiceClient

try :
http_port = config['GuardianService']['HttpPort']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from pdo.inference.wsgi.add_endpoint import AddEndpointApp
from pdo.inference.wsgi.info import InfoApp
from pdo.inference.wsgi.process_capability import ProcessCapabilityApp
from pdo.inference.wsgi.provision_token_issuer import ProvisionTokenIssuerApp
from pdo.inference.wsgi.provision_token_object import ProvisionTokenObjectApp
from pdo.contracts.guardian.wsgi.add_endpoint import AddEndpointApp
from pdo.contracts.guardian.wsgi.info import InfoApp
from pdo.contracts.guardian.wsgi.process_capability import ProcessCapabilityApp
from pdo.contracts.guardian.wsgi.provision_token_issuer import ProvisionTokenIssuerApp
from pdo.contracts.guardian.wsgi.provision_token_object import ProvisionTokenObjectApp


__all__ = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import io
import json

from pdo.inference.common.utility import ValidateJSON
from pdo.contracts.guardian.common.utility import ValidateJSON
from pdo.common.wsgi import ErrorResponse, UnpackJSONRequest

import logging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
"""

from http import HTTPStatus
import importlib
import json

from pdo.inference.common.utility import ValidateJSON
from pdo.inference.common.secrets import recv_secret
from pdo.inference.operations import capability_handler_map
from pdo.contracts.guardian.common.utility import ValidateJSON
from pdo.contracts.guardian.common.secrets import recv_secret
from pdo.common.wsgi import ErrorResponse, UnpackJSONRequest

import logging
Expand Down Expand Up @@ -63,8 +63,16 @@ def __init__(self, config, capability_store, endpoint_registry) :
self.capability_store = capability_store
self.endpoint_registry = endpoint_registry

try :
operation_module_name = config['GuardianService']['Operations']
except KeyError as ke :
logger.error('No operation map configured')
raise

operation_module = importlib.import_module(operation_module_name)

self.capability_handler_map = {}
for (op, handler) in capability_handler_map.items() :
for (op, handler) in operation_module.capability_handler_map.items() :
self.capability_handler_map[op] = handler(config)

# -----------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
from http import HTTPStatus
import json

from pdo.inference.common.utility import ValidateJSON
from pdo.inference.common.secrets import send_secret
from pdo.contracts.guardian.common.utility import ValidateJSON
from pdo.contracts.guardian.common.secrets import send_secret
from pdo.common.wsgi import ErrorResponse, UnpackJSONRequest
import pdo.common.crypto as crypto

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
from http import HTTPStatus
import json

from pdo.inference.common.utility import ValidateJSON
from pdo.inference.common.secrets import send_secret, recv_secret
from pdo.contracts.guardian.common.utility import ValidateJSON
from pdo.contracts.guardian.common.secrets import send_secret, recv_secret
from pdo.common.wsgi import ErrorResponse, UnpackJSONRequest
from pdo.common.keys import EnclaveKeys

Expand Down
5 changes: 4 additions & 1 deletion common-contract/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@
],
include_package_data=True,
install_requires = [
'colorama',
'ipywidgets',
'jsonschema>=3.0.1',
'requests',
'twisted',
'pdo-client>=' + pdo_client_version,
'pdo-common-library>=' + pdo_client_version,
'pdo-sservice>=' + pdo_client_version,
],
entry_points = {
}
Expand Down
12 changes: 0 additions & 12 deletions inference-contract/MANIFEST
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
MANIFEST.in
./setup.py
./pdo/__init__.py
./pdo/inference/wsgi/provision_token_issuer.py
./pdo/inference/wsgi/__init__.py
./pdo/inference/wsgi/add_endpoint.py
./pdo/inference/wsgi/provision_token_object.py
./pdo/inference/wsgi/info.py
./pdo/inference/wsgi/process_capability.py
./pdo/inference/model_scoring_scripts/__init__.py
./pdo/inference/model_scoring_scripts/image_classification.py
./pdo/inference/model_scoring_scripts/model_scoring_script_base.py
Expand All @@ -19,16 +13,10 @@ MANIFEST.in
./pdo/inference/__init__.py
./pdo/inference/resources/resources.py
./pdo/inference/resources/__init__.py
./pdo/inference/common/guardian_service.py
./pdo/inference/common/capability_keystore.py
./pdo/inference/common/secrets.py
./pdo/inference/common/__init__.py
./pdo/inference/common/endpoint_registry.py
./pdo/inference/common/ovms_predict.py
./pdo/inference/common/utility.py
./pdo/inference/common/capability_keys.py
./pdo/inference/scripts/__init__.py
./pdo/inference/scripts/guardianCLI.py
./pdo/inference/scripts/scripts.py
./pdo/inference/jupyter.py
./scripts/gs_stop.sh
Expand Down
3 changes: 2 additions & 1 deletion inference-contract/etc/guardian_service.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Identity = "${identity}"
HttpPort = 7900
Host = "${host}"
Operations = 'pdo.inference.operations'

# --------------------------------------------------
# StorageService -- information about passing kv stores
Expand Down Expand Up @@ -59,7 +60,7 @@ ScoringScriptModule = "ImageClassification"

#do not change the following variable. Please see README.mdb

OpenVINOModelServerAddress = "localhost"
OpenVINOModelServerAddress = "localhost"
OpenVINOModelServerPort = 9000

#model specific params, used by model scoring script
Expand Down
2 changes: 1 addition & 1 deletion inference-contract/pdo/inference/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__all__ = [ 'jupyter', 'plugins', 'wsgi', 'resources', 'scripts', 'common', 'model_scoring_scripts', 'operations']
__all__ = [ 'jupyter', 'plugins', 'resources', 'scripts', 'common', 'model_scoring_scripts', 'operations']
5 changes: 1 addition & 4 deletions inference-contract/pdo/inference/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
# limitations under the License.

__all__ = [
'capability_keys',
'capability_keystore',
'endpoint_registry',
'secrets',
'ovms_predict',
'utility',
]
11 changes: 1 addition & 10 deletions inference-contract/pdo/inference/common/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import jsonschema
import cv2

# -----------------------------------------------------------------
def ValidateJSON(instance, schema):
try:
jsonschema.validate(instance=instance, schema=schema)
except jsonschema.exceptions.ValidationError as err:
return False
return True

# -----------------------------------------------------------------
def CropResize(img,cropx,cropy):
y,x,c = img.shape
Expand All @@ -34,4 +25,4 @@ def CropResize(img,cropx,cropy):
x = cropx
startx = x//2-(cropx//2)
starty = y//2-(cropy//2)
return img[starty:starty+cropy,startx:startx+cropx,:]
return img[starty:starty+cropy,startx:startx+cropx,:]
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import cv2
import numpy as np

from pdo.inference.common.utility import ValidateJSON, CropResize
from pdo.inference.common.utility import CropResize
from pdo.contracts.guardian.common.utility import ValidateJSON

from pdo.inference.model_scoring_scripts.model_scoring_script_base import ModelScoringScriptBase
from pdo.inference.model_scoring_scripts.image_classes import imagenet_classes

Expand Down
2 changes: 1 addition & 1 deletion inference-contract/pdo/inference/operations/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
handling contract method invocation requests.
"""

from pdo.inference.common.utility import ValidateJSON
from pdo.contracts.guardian.common.utility import ValidateJSON
from pdo.common.key_value import KeyValueStore

from pdo.inference.model_scoring_scripts import model_scoring_scripts_map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import pdo.client.builder.shell as pshell
from pdo.client.builder import invocation_parameter

from pdo.inference.common.guardian_service import GuardianServiceClient
from pdo.contracts.guardian.common.guardian_service import GuardianServiceClient

__all__ = [
'op_provision_token_issuer',
Expand Down Expand Up @@ -283,4 +283,4 @@ def invoke(cls, state, context, provisioning_package, url=None, **kwargs) :
## -----------------------------------------------------------------
def load_commands(cmdclass) :
pshell.bind_shell_command(cmdclass, 'inference_guardian', do_inference_guardian)
pshell.bind_shell_command(cmdclass, 'inference_guardian_service', do_inference_guardian_service)
pshell.bind_shell_command(cmdclass, 'inference_guardian_service', do_inference_guardian_service)
Loading