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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [ "main", "*-rc" ]
pull_request:
branches: [ "main", "*-rc" ]
branches: [ "main", "*-rc", "release/3.x" ]

jobs:
build:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/cve-scanning-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,8 @@ jobs:
-i SFTY-20260603-52923
-i SFTY-20260603-52285
-i SFTY-20260615-45392
-i SFTY-20260803-49978
-i SFTY-20260803-85786
-i SFTY-20260803-45259
# Without poetry, use this command instead
# run: safety check -r requirements.txt --full-report --policy-file safety-policy.yml
# run: safety check -r requirements.txt --full-report --policy-file safety-policy.yml
2 changes: 1 addition & 1 deletion .github/workflows/e2e-build.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: e2e test
on:
push:
branches: [ "main" ]
branches: [ "main", "release/3.x" ]

jobs:
e2e-test:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,6 @@ jobs:
-i SFTY-20260603-52923
-i SFTY-20260603-52285
-i SFTY-20260615-45392
-i SFTY-20260803-49978
-i SFTY-20260803-85786
-i SFTY-20260803-45259
5 changes: 5 additions & 0 deletions .safety-policy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ security: # configuration for the `safety check` command
reason: The maintainer and multiple third parties believe that this vulnerability isn't valid because users shouldn't use untrusted templates without sandboxing.
96886:
reason: Fix requires urllib3>=2.7.0, which dropped Python 3.9 support. This project still supports Python 3.9 (see pyproject.toml), so the fixed version cannot be installed on that interpreter. Revisit when Python 3.9 support is dropped. NOTE this entry is superseded in CI, where -i flags on the safety check command are used instead for this and related IDs (see .github/workflows/security.yml) since -i replaces rather than merges with this list when both are passed.
# SFTY-20260803-49978, SFTY-20260803-85786 and SFTY-20260803-45259 (aiohttp, same Python 3.9
# rationale as above) are intentionally NOT listed here: the installed safety version (2.3.5)
# only accepts integer vulnerability IDs under ignore-vulnerabilities and fails to load this
# whole policy file otherwise. They are ignored via -i flags in the CI workflows instead
# (see .github/workflows/security.yml and .github/workflows/cve-scanning-python.yml).
continue-on-vulnerability-error: False # Suppress non-zero exit codes when vulnerabilities are found. Enable this in pipelines and CI/CD processes if you want to pass builds that have vulnerabilities
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,31 @@ _NOTE:_ Ensure you have an active Individual Contributor License Agreement (ICLA

For further inquiries, email [help@finos.org](mailto:help@finos.org).


### Updating Generated Code

Python BDK uses [OpenAPITools/openapi-generator](https://github.com/OpenAPITools/openapi-generator/) to generate code.
To update the generated code, follow these steps:

1. Download desired version of openapi generator.
```bash
cd api_client_generation
curl -L https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.14.0/openapi-generator-cli-7.14.0.jar -o openapi-generator-cli.jar
```
2. Adjust the commit for which the code is generated(inside generate.sh script)
3. Execute the generation script:
```bash
./generate.sh
```
4. Commit and push the newly generated code along with the updated JAR file.

Note: There are a few files that are not replaced(EX. api_client.py), those files require some modifications after code is generated.


### OLD Updating Generated Code (Deprecated)

Python BDK uses [OpenAPITools/openapi-generator](https://github.com/OpenAPITools/openapi-generator/) to generate code.
To update the generated code, follow these steps:

1. Checkout the latest branch of the fork (e.g., [sym-python-5.5.0](https://github.com/SymphonyPlatformSolutions/openapi-generator/tree/sym-python-5.5.0)).
2. Update the fork source code, review, and merge it.
3. Generate the JAR file in `openapi-generatormodules/openapi-generator-cli/target/openapi-generator-cli.jar`:
Expand Down
159 changes: 90 additions & 69 deletions api_client_generation/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,92 +4,113 @@ code_gen_dir=`pwd`
project_root=$code_gen_dir/..
echo $code_gen_dir

commit_hash=b63d67cc0ed7c5a3962e72f21001df4d2ed482f2
commit_hash=baf01bee3bd00612d57d2df481ea54aab9404017
api_spec_base_url=https://raw.githubusercontent.com/symphonyoss/symphony-api-spec/${commit_hash}
echo $api_spec_base_url

#local_api_spec_base_url=./local

# This function accepts the following parameters (in order):
# - name of the module we want to generate
# - uri of the file to be used for generation
# - uri of the support file needed for the generation
download_and_generate_files() {
name=$1
file_url=$2
file_name=${file_url##*/}
support_file_url=$3
support_file_name=${support_file_url##*/}

download_files ${file_url} ${file_name} ${support_file_url} ${support_file_name}
generate_files ${name} ${file_name}
cleanup_files ${file_name} ${support_file_name}
name=$1
file_url=$2
file_name=${file_url##*/}
support_file_url=$3
support_file_name=${support_file_url##*/}

download_files "${file_url}" "${file_name}" "${support_file_url}" "${support_file_name}"
generate_files "${name}" "${file_name}"
cleanup_files "${file_name}" "${support_file_name}"
}

download_files() {
# download files
file_url=$1
file_name=$2
support_file_url=$3
support_file_name=$4

cd $code_gen_dir
curl $file_url -o $file_name
if [ ! -z "${support_file_name}" ]
then
curl $support_file_url -o $support_file_name
fi
file_url=$1
file_name=$2
support_file_url=$3
support_file_name=$4

cd "$code_gen_dir"
curl -s "$file_url" -o "$file_name"
if [ -n "$support_file_name" ]; then
curl -s "$support_file_url" -o "$support_file_name"
fi
}

generate_files() {

name=$1
file_name=$2

# generate files
java -jar openapi-generator-cli.jar generate -g python -i $file_name --package-name symphony.bdk.gen -o output

# update api files
cd $code_gen_dir/output/symphony/bdk/gen/api/
sed -i "s/symphony\.bdk\.gen\.model\./symphony\.bdk\.gen\.${name}_model\./g" *.py
sed -i "s/ api\./ ${name}_api\./g" *.py
rm __init__.py # we don't care about __init__.py files
cp *.py $project_root/symphony/bdk/gen/${name}_api

# update model files
cd $code_gen_dir/output/symphony/bdk/gen/model/
sed -i "s/symphony\.bdk\.gen\.model\./symphony\.bdk\.gen\.${name}_model\./g" *.py
sed -i "s/model /${name}_model /g" *.py
rm __init__.py # we don't care about __init__.py files
cp *.py $project_root/symphony/bdk/gen/${name}_model

# update rest.py
cd $code_gen_dir/output/symphony/bdk/gen
cp rest.py $project_root/symphony/bdk/gen/rest.py

cd $code_gen_dir
rm -r output
name=$1
file_name=$2

# Generate files
java -jar openapi-generator-cli.jar generate -g python -i "$file_name" --library asyncio --package-name symphony.bdk.gen -o output

# Define source and destination directories
new_api_dir="$code_gen_dir/output/symphony/bdk/gen/api/"
new_models_dir="$code_gen_dir/output/symphony/bdk/gen/models/"
final_models_dir="$project_root/symphony/bdk/gen/${name}_model/"
final_api_dir="$project_root/symphony/bdk/gen/${name}_api/"
final_main_models_dir="$project_root/symphony/bdk/gen/models/"

# Update and copy API files
echo "Updating and copying API files..."
mkdir -p "$final_api_dir"
cd "$new_api_dir"
sed -i "s/symphony\.bdk\.gen\.models\./symphony\.bdk\.gen\.${name}_model\./g" *.py
sed -i "s/ api\./ ${name}_api\./g" *.py
rm __init__.py
cp *.py "$final_api_dir"

# Update and copy model files
echo "Updating and copying Model files..."
mkdir -p "$final_models_dir"
cd "$new_models_dir"
# Capture the imports from the generated __init__.py before removing it
# Use awk to filter out comments and empty lines and then sed to replace the import path
awk '/^from symphony\.bdk\.gen\.models\./' __init__.py | sed "s/symphony\.bdk\.gen\.models\./symphony\.bdk\.gen\.${name}_model\./" >> "$final_main_models_dir/__init__.py"
sed -i "s/symphony\.bdk\.gen\.models\./symphony\.bdk\.gen\.${name}_model\./g" *.py
rm __init__.py

# Copy the actual model files
cp *.py "$final_models_dir"

# The rest of the files
# Here we have more files generated that are not updated because they require changes(EX. api_client)
cd "$code_gen_dir/output/symphony/bdk/gen"
cp rest.py "$project_root/symphony/bdk/gen/rest.py"

# Clean up
cd "$code_gen_dir"
rm -r output
}

cleanup_files() {
file_name=$1
support_file_name=$2

# remove downloaded files
cd $code_gen_dir
rm -r output
rm $file_name
if [ ! -z "${support_file_name}" ]
then
rm $support_file_name
fi
file_name=$1
support_file_name=$2

# remove downloaded files
cd "$code_gen_dir"
rm "$file_name"
if [ -n "$support_file_name" ]; then
rm "$support_file_name"
fi
}

main() {
# Prepare the target directory for the models
rm -rf "$project_root/symphony/bdk/gen/models"
mkdir -p "$project_root/symphony/bdk/gen/models"

# Add initial header to the main __init__.py
echo "# coding: utf-8" > "$project_root/symphony/bdk/gen/models/__init__.py"
echo "" >> "$project_root/symphony/bdk/gen/models/__init__.py"
echo "# This file is auto-generated by a script. Do not edit manually." >> "$project_root/symphony/bdk/gen/models/__init__.py"
echo "" >> "$project_root/symphony/bdk/gen/models/__init__.py"

download_and_generate_files agent "${api_spec_base_url}/agent/agent-api-public-deprecated.yaml"
download_and_generate_files auth "${api_spec_base_url}/authenticator/authenticator-api-public-deprecated.yaml"
download_and_generate_files login "${api_spec_base_url}/login/login-api-public.yaml"
download_and_generate_files pod "${api_spec_base_url}/pod/pod-api-public.yaml"
download_and_generate_files group "${api_spec_base_url}/profile-manager/profile-manager-api.yaml" "${api_spec_base_url}/profile-manager/symphony-common-definitions.yaml"
}

generate_files agent ${api_spec_base_url}/agent/agent-api-public-deprecated.yaml
generate_files auth ${api_spec_base_url}/authenticator/authenticator-api-public-deprecated.yaml
generate_files login ${api_spec_base_url}/login/login-api-public.yaml
generate_files pod ${api_spec_base_url}/pod/pod-api-public.yaml
generate_files group ${api_spec_base_url}/profile-manager/profile-manager-api.yaml ${api_spec_base_url}/profile-manager/symphony-common-definitions.yaml

#generate_files agent ${local_api_spec_base_url}/agent-api-public-deprecated-formValues-modified.yaml
main
Binary file modified api_client_generation/openapi-generator-cli.jar
Binary file not shown.
4 changes: 4 additions & 0 deletions examples/services/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ async def run():
)
await message_service.import_messages([msg])

results = await message_service.search_messages_semantic("greetings", limit=2)
for message in results:
logging.info(f"fround a message: {message.message}")

logging.info("Obo example:")
obo_auth_session = bdk.obo(username="username")
async with bdk.obo_services(obo_auth_session) as obo_services:
Expand Down
Loading
Loading