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
6 changes: 6 additions & 0 deletions common-contract/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ pdo/contracts/jupyter/groups.py
pdo/contracts/jupyter/keys.py
pdo/contracts/jupyter/services.py
pdo/contracts/jupyter/utility.py
scripts/gs_stop.sh
scripts/gs_start.sh
scripts/gs_status.sh
scripts/ss_stop.sh
scripts/ss_start.sh
scripts/ss_status.sh
4 changes: 1 addition & 3 deletions common-contract/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
recursive-include ../build/example-contract *.b64
recursive-include etc *.toml
recursive-include context *.toml
recursive-include scripts *.psh
recursive-include scripts *.psh *.sh
72 changes: 72 additions & 0 deletions common-contract/etc/guardian_service.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# 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.

# --------------------------------------------------
# GuardianService -- general information about the guardian service
# --------------------------------------------------
[GuardianService]
# Identity is a string used to identify the service in log files
Identity = "${identity}"
HttpPort = 7900
Host = "${host}"

## Operations is the name of a python module that defines capability handlers
## Operations = 'pdo.common.operations'

# --------------------------------------------------
# StorageService -- information about passing kv stores
# --------------------------------------------------
[StorageService]
URL = "http://${host}:7901"
KeyValueStore = "${data}/guardian_service.mdb"
BlockStore = "${data}/guardian_service.mdb"
Identity = "${identity}"
HttpPort = 7901
Host = "${host}"
GarbageCollectionInterval = 0
MaxDuration = 0

# --------------------------------------------------
# Keys -- configuration for retrieving service keys
# --------------------------------------------------
[Key]
SearchPath = [ ".", "./keys", "${keys}" ]
FileName = "${identity}_private.pem"

# --------------------------------------------------
# Logging -- configuration of service logging
# --------------------------------------------------
[Logging]
LogLevel = "INFO"
LogFile = "${logs}/${identity}.log"

# --------------------------------------------------
# Data -- names for the various databases
# --------------------------------------------------
[Data]
EndpointRegistry = "${data}/endpoints.db"
CapabilityKeyStore = "${data}/keystore.db"

# --------------------------------------------------
# TokenIssuer -- configuration for TI verification
# --------------------------------------------------
[TokenIssuer]
LedgerKey = ""
CodeHash = ""
ContractIDs = []

# --------------------------------------------------
# TokenObject -- configuration for TO verification
# --------------------------------------------------
[TokenObject]
15 changes: 15 additions & 0 deletions common-contract/pdo/contracts/guardian/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2022 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__ = [ 'guardian_service', ]
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""
inference guardian plugins
""" This file contains functions that can be used to implement most external guardian service
interactions. It provides the minimal set of operations required for the token-guardian protocol.
"""

import json
Expand All @@ -36,9 +36,6 @@
'op_add_endpoint',
'cmd_provision_token_issuer',
'cmd_provision_token_object',
'do_inference_guardian',
'do_inference_guardian_service',
'load_commands',
]

## -----------------------------------------------------------------
Expand Down Expand Up @@ -258,7 +255,6 @@ def invoke(cls, state, context, provisioning_package, url=None, **kwargs) :
cls.display('provisioned token object for guardian {}'.format(url))
return json.loads(to_package)


## -----------------------------------------------------------------
## Create the generic, shell independent version of the aggregate command
## -----------------------------------------------------------------
Expand All @@ -269,18 +265,18 @@ def invoke(cls, state, context, provisioning_package, url=None, **kwargs) :
op_add_endpoint,
]

do_inference_guardian_service = pcontract.create_shell_command('inference_guardian_service', __operations__)
do_guardian_service_ops = pcontract.create_shell_command('guardian_service_ops', __operations__)

__commands__ = [
cmd_provision_token_issuer,
cmd_provision_token_object,
]

do_inference_guardian = pcommand.create_shell_command('inference_guardian', __commands__)
do_guardian_service = pcommand.create_shell_command('guardian_service', __commands__)

## -----------------------------------------------------------------
## Enable binding of the shell independent version to a pdo-shell command
## -----------------------------------------------------------------
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, 'guardian_service_ops', do_guardian_service_ops)
pshell.bind_shell_command(cmdclass, 'guardian_service', do_guardian_service)
15 changes: 15 additions & 0 deletions common-contract/pdo/contracts/guardian/scripts/__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__ = [ 'guardianCLI' ]
Empty file.
18 changes: 18 additions & 0 deletions common-contract/pdo/contracts/resources/resources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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 pdo.client.builder.installer as pinstaller

def install_common_resources() :
pinstaller.install_plugin_resources('pdo.common.resources', 'common')
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ until $(${F_SERVICE_CMD} $@ --test 2> /dev/null > /dev/null) ; do
sleep 1
tries=$((tries+1))
if [ $tries = $max_tries ] ; then
if [ "${F_OUTPUTDIR}" != "" ] ; then
echo "guardian service failed to start, check logs:"
cat $EFILE
cat $OFILE
fi
die guardian service failed to start
fi
done
13 changes: 13 additions & 0 deletions common-contract/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,21 @@
url=author_url,
package_dir = {
'pdo' : 'pdo',
f'pdo.{contract_family}.resources.etc' : 'etc',
f'pdo.{contract_family}.resources.scripts' : 'scripts',
},
packages = [
'pdo',
f'pdo.{contract_family}',
f'pdo.{contract_family}.jupyter',
f'pdo.{contract_family}.guardian',
f'pdo.{contract_family}.guardian.common',
f'pdo.{contract_family}.guardian.plugins',
f'pdo.{contract_family}.guardian.scripts',
f'pdo.{contract_family}.guardian.wsgi',
f'pdo.{contract_family}.resources',
f'pdo.{contract_family}.resources.etc',
f'pdo.{contract_family}.resources.scripts',
],
include_package_data=True,
install_requires = [
Expand All @@ -93,5 +103,8 @@
'pdo-sservice>=' + pdo_client_version,
],
entry_points = {
'console_scripts' : [
'guardian_service=pdo.contracts.guardian.scripts.guardianCLI:Main',
]
}
)
4 changes: 0 additions & 4 deletions inference-contract/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ MANIFEST.in
./pdo/inference/operations/__init__.py
./pdo/inference/plugins/inference_token_object.py
./pdo/inference/plugins/__init__.py
./pdo/inference/plugins/inference_guardian.py
./pdo/inference/__init__.py
./pdo/inference/resources/resources.py
./pdo/inference/resources/__init__.py
Expand All @@ -19,9 +18,6 @@ MANIFEST.in
./pdo/inference/scripts/__init__.py
./pdo/inference/scripts/scripts.py
./pdo/inference/jupyter.py
./scripts/gs_stop.sh
./scripts/gs_start.sh
./scripts/gs_status.sh
./context/tokens.toml
./etc/inference.toml
./etc/guardian_service.toml
2 changes: 1 addition & 1 deletion inference-contract/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
recursive-include ../build/inference-contract *.b64
recursive-include etc *.toml
recursive-include context *.toml
recursive-include scripts *.sh
recursive-include scripts *.sh *.psh
2 changes: 1 addition & 1 deletion inference-contract/context/tokens.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ source = "${ContractFamily.Exchange.vetting.source}"
asset_type_context = "@{..asset_type}"

[token.${token}.guardian]
module = "pdo.inference.plugins.inference_guardian"
module = "pdo.contracts.guardian.plugins.guardian_service"
url = "${url}"
identity = "${..token_issuer.identity}"
token_issuer_context = "@{..token_issuer}"
Expand Down
2 changes: 1 addition & 1 deletion inference-contract/pdo/inference/jupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# set up the context
# -----------------------------------------------------------------
guardian_context = jp_common.ContextTemplate('guardian', {
'module' : 'pdo.inference.plugins.inference_guardian',
'module' : 'pdo.contracts.guardian.plugins.guardian_service',
'identity' : '${..token_issuer.identity}',
'token_issuer_context' : '@{..token_issuer}',
'service_only' : True,
Expand Down
2 changes: 1 addition & 1 deletion inference-contract/pdo/inference/plugins/__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__ = [ 'inference_guardian', 'inference_token_object']
__all__ = [ 'inference_token_object']
3 changes: 1 addition & 2 deletions inference-contract/pdo/inference/scripts/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ def inference_token() :
# -----------------------------------------------------------------
# -----------------------------------------------------------------
def inference_guardian() :
run_shell_command('do_inference_guardian', 'pdo.inference.plugins.inference_guardian')

run_shell_command('do_guardian_service', 'pdo.contracts.guardian.plugins.guardian_service')
2 changes: 0 additions & 2 deletions inference-contract/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
'pdo.inference.resources.etc' : 'etc',
'pdo.inference.resources.context' : 'context',
'pdo.inference.resources.contracts' : '../build/inference-contract',
'pdo.inference.resources.scripts' : 'scripts',
},
packages = [
'pdo',
Expand All @@ -75,7 +74,6 @@
'pdo.inference.resources.etc',
'pdo.inference.resources.context',
'pdo.inference.resources.contracts',
'pdo.inference.resources.scripts',
],
include_package_data=True,
# add everything from requirements.txt here
Expand Down
10 changes: 6 additions & 4 deletions inference-contract/test/script_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ fi
# -----------------------------------------------------------------
# Process command line arguments
# -----------------------------------------------------------------
COMMON_CONTRACT_ROOT=${PDO_HOME}/contracts/contracts

SCRIPTDIR="$(dirname $(readlink --canonicalize ${BASH_SOURCE}))"
SOURCE_ROOT="$(realpath ${SCRIPTDIR}/..)"

Expand Down Expand Up @@ -139,24 +141,24 @@ function cleanup {
done

yell "shutdown guardian and storage service"
${PDO_HOME}/contracts/inference/scripts/gs_stop.sh
${PDO_HOME}/contracts/inference/scripts/ss_stop.sh
${COMMON_CONTRACT_ROOT}/scripts/gs_stop.sh
${COMMON_CONTRACT_ROOT}/scripts/ss_stop.sh
}

trap cleanup EXIT

# -----------------------------------------------------------------
# Start the guardian service and the storage service
# -----------------------------------------------------------------
try ${PDO_HOME}/contracts/inference/scripts/ss_start.sh -c -o ${PDO_HOME}/logs -- \
try ${COMMON_CONTRACT_ROOT}/scripts/ss_start.sh -c -o ${PDO_HOME}/logs -- \
--loglevel debug \
--config guardian_service.toml \
--config-dir ${PDO_HOME}/etc/contracts \
--identity guardian_sservice

sleep 3

try ${PDO_HOME}/contracts/inference/scripts/gs_start.sh -c -o ${PDO_HOME}/logs -- \
try ${COMMON_CONTRACT_ROOT}/scripts/gs_start.sh -c -o ${PDO_HOME}/logs -- \
--loglevel debug \
--config guardian_service.toml \
--config-dir ${PDO_HOME}/etc/contracts \
Expand Down