-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from pradeep-dot-jaiswar/main
Github workflow
- Loading branch information
Showing
12 changed files
with
213 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Publish Python 🐍 distributions 📦 to PyPI | ||
|
||
# on: push | ||
on: | ||
release: | ||
types: | ||
- created | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build-n-publish: | ||
name: Build and publish Python 🐍 distributions 📦 to PyPI | ||
runs-on: ubuntu-18.04 | ||
steps: | ||
- uses: actions/checkout@master | ||
- name: Set up Python 3.8 | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.8 | ||
- name: Install pypa/build | ||
run: >- | ||
python -m | ||
pip install | ||
build | ||
--user | ||
- name: Build a binary wheel and a source tarball | ||
run: >- | ||
python -m | ||
build | ||
--sdist | ||
--wheel | ||
--outdir dist/ | ||
. | ||
- name: Publish distribution 📦 to PyPI | ||
if: startsWith(github.ref, 'refs/tags') | ||
uses: pypa/gh-action-pypi-publish@master | ||
with: | ||
password: ${{ secrets.PYPI_API_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Publish Python 🐍 distributions 📦 to TestPyPI | ||
|
||
# on: push | ||
on: | ||
release: | ||
types: | ||
- created | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build-n-publish: | ||
name: Build and publish Python 🐍 distributions 📦 to TestPyPI | ||
runs-on: ubuntu-18.04 | ||
steps: | ||
- uses: actions/checkout@master | ||
- name: Set up Python 3.8 | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.8 | ||
- name: Install pypa/build | ||
run: >- | ||
python -m | ||
pip install | ||
build | ||
--user | ||
- name: Build a binary wheel and a source tarball | ||
run: >- | ||
python -m | ||
build | ||
--sdist | ||
--wheel | ||
--outdir dist/ | ||
. | ||
- name: Publish distribution 📦 to Test PyPI | ||
uses: pypa/gh-action-pypi-publish@master | ||
with: | ||
password: ${{ secrets.TEST_PYPI_API_TOKEN }} | ||
repository_url: https://test.pypi.org/legacy/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Publish sf-apm-lib pip package | ||
============== | ||
[![made-with-python](https://img.shields.io/badge/Made%20with-Python-1f425f.svg)](https://www.python.org/) [![pypi-package](https://img.shields.io/badge/pypi-green)](https://pypi.org/project/sf-apm-lib/) | ||
|
||
|
||
Steps | ||
-------------- | ||
|
||
|
||
- Open [SF-APM-LIB Github Repo](https://github.com/snappyflow/py_snappyflow) | ||
|
||
- Go to [Actions](https://github.com/snappyflow/py_snappyflow/actions) tab and select <b>Build and publish Python 🐍 distributions 📦 to PyPI</b> or <b>Build and publish Python 🐍 distributions 📦 to TestPyPI</b> action and click on <i>Run workflow</i> | ||
|
||
- Select the desired branch e.g <i>main</i> or <i>master</i> branch and finally click on <b> Run workflow</b> button.<br> | ||
Above process will start building and then publishing your package. | ||
|
||
- Once build result of workflow is successful, Check published version of pip package in pypi or test.pypi repo based on selected action. | ||
|
||
|
||
<br> | ||
Note: Please make sure package version is updated to newer version before publishing. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,36 @@ | ||
py\_snappyflow | ||
sf-apm-lib | ||
============== | ||
[![made-with-python](https://img.shields.io/badge/Made%20with-Python-1f425f.svg)](https://www.python.org/) [![pypi-package](https://img.shields.io/badge/pypi-green)](https://pypi.org/project/sf-apm-lib/) | ||
|
||
Snappyflow modules | ||
|
||
Installation | ||
------------ | ||
pip install py_snappyflow | ||
pip install sf-apm-lib | ||
|
||
Then you should import the library. | ||
|
||
```python | ||
from sf_apm_lib.snappyflow import Snappyflow | ||
``` | ||
|
||
Usage | ||
----- | ||
* Get trace config | ||
|
||
``` | ||
from py_snappyflow import snappyflow as sf | ||
trace_config = sf.get_trace_config(<Snappyflow Profile Key>) | ||
``` | ||
Get trace config | ||
|
||
```python | ||
sf = Snappyflow() # Initialize Snappyflow. By default intialization will pick profileKey, projectName and appName from sfagent config.yaml. | ||
|
||
# Add below part to manually configure the initialization | ||
project_name = '<Snappyflow Project Name>' | ||
app_name = '<Snappyflow App Name>' | ||
profile_key = '<Snappyflow Profile Key>' | ||
|
||
sf.init(profile_key, project_name, app_name) | ||
# End of manual configuration | ||
|
||
trace_config = sf.get_trace_config() # Returns trace config | ||
|
||
print(trace_config) | ||
``` |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,25 +14,27 @@ def read(filename): | |
|
||
|
||
setup( | ||
name="py_snappyflow", | ||
version="0.1.1", | ||
name="sf_apm_lib", | ||
version="0.1.2", | ||
url="https://github.com/snappyflow/py_snappyflow", | ||
license='MIT', | ||
|
||
author="Maplelabs", | ||
author_email="[email protected]", | ||
|
||
description="Snappyflow modules", | ||
description="Snappyflow pip package", | ||
long_description=read("README.md"), | ||
long_description_content_type='text/markdown', | ||
|
||
packages=find_packages(exclude=('tests',)), | ||
|
||
install_requires=['cryptography', 'pycryptodome'], | ||
install_requires=['cryptography==3.4.7', 'pycryptodome==3.10.1', 'cffi==1.14.6', 'PyYAML==5.4.1'], | ||
|
||
classifiers=[ | ||
'Development Status :: 2 - Pre-Alpha', | ||
'License :: OSI Approved :: MIT License', | ||
'Programming Language :: Python', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.4', | ||
'Programming Language :: Python :: 3.5', | ||
'Programming Language :: Python :: 3.6', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
"""py_snappyflow - Snappyflow modules""" | ||
"""sf_apm_lib - Snappyflow pip package""" | ||
|
||
__version__ = '0.1.0' | ||
__author__ = 'Maplelabs <[email protected]>' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
from hashlib import sha256 | ||
import base64 | ||
from Crypto import Random | ||
from Crypto.Cipher import AES | ||
import json | ||
import platform | ||
import yaml | ||
from yaml.loader import SafeLoader | ||
|
||
|
||
class Snappyflow: | ||
def __init__(self): | ||
self.__CP_ENCRYPTED_KEY = "U25hcHB5RmxvdzEyMzQ1Ng==" | ||
self.project_name = None | ||
self.app_name = None | ||
self.profile_data = None | ||
path = '' | ||
os_type = platform.system().lower() | ||
if os_type == 'windows' or os_type == 'win32': | ||
path = 'C:\\Program Files (x86)\\Sfagent\\config.yaml' | ||
else: | ||
path = '/opt/sfagent/config.yaml' | ||
# with open(path) as file: | ||
try: | ||
yaml_file = open(path) | ||
data = yaml.load(yaml_file, Loader=SafeLoader) | ||
# self.profile_key = | ||
self.project_name = data['tags']['projectName'] | ||
self.app_name = data['tags']['appName'] | ||
self.profile_data = self._get_profile_data(data['key']) | ||
except Exception as ex: | ||
print('Can not read from config.yaml\nCall init method with parameters to initialize.') | ||
|
||
def init(self, profile_key, project_name, app_name): | ||
self.profile_data = self._get_profile_data(profile_key) | ||
self.project_name = project_name | ||
self.app_name = app_name | ||
|
||
def _get_profile_data(self, profile_key): | ||
unpad = lambda s : s[0:-ord(s[-1:])] | ||
|
||
key = base64.b64decode(self.__CP_ENCRYPTED_KEY) | ||
|
||
enc = base64.b64decode(profile_key) | ||
iv = enc[:16] | ||
cipher = AES.new(key, AES.MODE_CBC, iv ) | ||
message = unpad(cipher.decrypt( enc[16:] )).decode('utf-8') | ||
return json.loads(message) | ||
|
||
def get_trace_config(self): | ||
""" Returns Snappyflow trace config | ||
Args: | ||
profile_key ([string]): [Snappyflow Profile Key] | ||
project_name ([string]): [Project name] | ||
app_name ([string]): [App name] | ||
Raises: | ||
ValueError: [If profile key is invalid] | ||
Returns: | ||
[dict]: [trace config] | ||
""" | ||
|
||
|
||
try: | ||
data = self.profile_data | ||
global_labels = "_tag_projectName={},_tag_appName={},_tag_profileId={}".format( | ||
self.project_name, self.app_name, data['profile_id']) | ||
trace_data = { | ||
'SFTRACE_SERVER_URL': data['trace_server_url'], | ||
'SFTRACE_SPAN_FRAMES_MIN_DURATION': "1ms", | ||
'SFTRACE_STACK_TRACE_LIMIT': 2, | ||
'SFTRACE_CAPTURE_SPAN_STACK_TRACES': False, | ||
'SFTRACE_VERIFY_SERVER_CERT': False, | ||
'SFTRACE_GLOBAL_LABELS': global_labels | ||
} | ||
return trace_data | ||
except Exception as e: | ||
# print("ex", e) | ||
raise ValueError("\nPlease check config.yaml file is present. Or \nInit method is called with appropriate values.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters