Skip to content

Commit 39bbe5b

Browse files
authored
feat: Base implementation for Cache Operations (#2)
* feat: Base implementation for Cache Operations * formatting * format * add exception handling and response wrapping * rename files * formatting * rename packaging * add artifactory publish logic * Change method name * add newline at the bottom * Update README
1 parent 36ee5bf commit 39bbe5b

18 files changed

+517
-17
lines changed

.github/workflows/push_request.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: On Push
2+
3+
# If this is made manual, then also update the pull_request.yml, to run builds
4+
# on main on merge.
5+
on:
6+
push:
7+
branches: [ main ]
8+
9+
# Allows you to run this workflow manually from the Actions tab
10+
workflow_dispatch:
11+
12+
jobs:
13+
release:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
version: ${{ steps.release.outputs.release }}
17+
steps:
18+
- uses: actions/checkout@v2
19+
20+
- name: Set release
21+
id: semrel
22+
uses: go-semantic-release/action@v1
23+
with:
24+
github-token: ${{ secrets.GITHUB_TOKEN }}
25+
allow-initial-development-versions: true
26+
force-bump-patch-version: true
27+
28+
- name: Output release
29+
id: release
30+
run: echo "::set-output name=release::${{ steps.semrel.outputs.version }}"
31+
32+
publish_python:
33+
# The type of runner that the job will run on
34+
runs-on: ubuntu-latest
35+
needs: release
36+
37+
# Steps represent a sequence of tasks that will be executed as part of the job
38+
steps:
39+
- uses: actions/checkout@v2
40+
41+
- name: Setup Python
42+
uses: actions/setup-python@v2
43+
with:
44+
python-version: '3.x'
45+
46+
- name: Install python dependencies
47+
run: |
48+
python -m pip install --upgrade pip
49+
pip install setuptools wheel twine build
50+
- name: Configure Artifactory publish credentials
51+
run: |
52+
set -e
53+
set -x
54+
pushd artifactory_setup
55+
./jfrog_setup.sh deploy-user ${{ secrets.PUBLIC_ARTIFACTORY_DEPLOY_USER_MAGIC_PASSTOKEN }} >> ~/.pypirc
56+
popd
57+
shell: bash
58+
59+
- name: Build and publish package
60+
run: |
61+
set -e
62+
set -x
63+
export MOMENTO_SDK_VERSION="${{needs.release.outputs.version}}"
64+
if [ -z "$MOMENTO_SDK_VERSION"]
65+
then
66+
echo "Using default version"
67+
export MOMENTO_SDK_VERSION="0.0.dev"`date +%s`
68+
fi
69+
echo "MOMENTO_SDK_VERSION=${MOMENTO_SDK_VERSION}"
70+
python -m build
71+
twine upload -r local dist/* --config-file ~/.pypirc
72+
shell: bash

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Compiled python modules.
22
src/*.pyc
3+
src/momento/*.pyc
4+
src/momento/__pycache__
35

46
# Setuptools distribution folder.
57
/dist/

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,20 @@ The script creates a python virtual environment and installs dependencies
1212
## Setting up IDE
1313
### Visual Studio Code
1414
Use `Cmd` + `Shift` + `P` to search for `Python: Interpreter` and select:
15-
`./client_sdk_python_env/bin/python`
15+
`./client_sdk_python_env/bin/python`
16+
17+
# Developing
18+
Once your pre-requisites are accomplished
19+
20+
Run the following command to start your virtual environment
21+
22+
`source client_sdk_python_env/bin/activate`
23+
24+
To install the package under development
25+
26+
`pip install -e .`
27+
28+
To test your changes you can then just run your python shell as follows:
29+
30+
`python` this will start the interactive shell or if you prefer you may put all
31+
your code in a my_test.py file and run `python my_test.py`

artifactory_setup/jfrog_setup.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
# Configure Git Hub Workflow environment for Uploading to JFrog
3+
set -e
4+
set -x
5+
echo "[distutils]"
6+
echo "index-servers = local"
7+
echo "[local]"
8+
echo "repository: https://momento.jfrog.io/artifactory/api/pypi/pypi-local"
9+
echo "username: $1"
10+
echo "password: $2"
11+
echo ""

setup.cfg

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
[metadata]
2-
name = momento-sdk
2+
name = momento
33

44
[options]
55
package_dir =
66
= src
77
packages = find:
88
python_requires = >=3.6
99
install_requires =
10-
momento-wire-types==0.3.0
10+
momento-wire-types==0.6.0
1111
build
1212
setuptools
13+
pyjwt
14+
grpcio
1315

1416
[options.packages.find]
1517
where = src

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import time
44

5-
version = os.getenv("PYPI_MOMENTO_WIRE_TYPE_VERSION")
5+
version = os.getenv("MOMENTO_SDK_VERSION")
66

77
if [version == None]:
88
version = '0.0.dev'
File renamed without changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from . import _header_client_interceptor
2+
3+
4+
def get_authorization_interceptor(auth_token):
5+
return _header_client_interceptor.header_adder_interceptor(
6+
'authorization', auth_token)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from . import _header_client_interceptor
2+
3+
4+
def get_cache_name_interceptor(cache_name):
5+
return _header_client_interceptor.header_adder_interceptor(
6+
'cache', cache_name)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import grpc
2+
from . import errors
3+
from momento_wire_types import cacheclient_pb2 as cache_client_types
4+
5+
__rpc_to_error = {
6+
grpc.StatusCode.ALREADY_EXISTS: errors.CacheExistsError,
7+
grpc.StatusCode.INVALID_ARGUMENT: errors.CacheValueError,
8+
grpc.StatusCode.NOT_FOUND: errors.CacheNotFoundError,
9+
grpc.StatusCode.PERMISSION_DENIED: errors.PermissionError,
10+
}
11+
12+
# Till the time MR2 stops returning errors in Enums
13+
__ecache_result_to_error = {
14+
cache_client_types.Bad_Request: errors.CacheValueError,
15+
cache_client_types.Internal_Server_Error: errors.InternalServerError,
16+
cache_client_types.Service_Unavailable: errors.InternalServerError,
17+
cache_client_types.Unauthorized: errors.PermissionError,
18+
}
19+
20+
21+
def convert(exception):
22+
if (isinstance(exception, errors.SdkError)):
23+
return exception
24+
25+
if (isinstance(exception, grpc.RpcError)):
26+
if exception.code() in __rpc_to_error:
27+
return __rpc_to_error[exception.code()](exception.details())
28+
else:
29+
return errors.InternalServerError(
30+
'CacheService failed with an internal error')
31+
32+
return errors.ClientSdkError('Operation failed with error: ' +
33+
str(exception))
34+
35+
36+
def convert_ecache_result(ecache_result, message):
37+
if (ecache_result in __ecache_result_to_error):
38+
return __ecache_result_to_error[ecache_result](message)
39+
return errors.InternalServerError(
40+
'CacheService failed with an internal error')

0 commit comments

Comments
 (0)