Skip to content

Commit

Permalink
Merge pull request #17 from Tauffer-Consulting/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
vinicvaz authored Nov 15, 2023
2 parents baafac9 + e62b945 commit b8c76ce
Show file tree
Hide file tree
Showing 37 changed files with 1,180 additions and 424 deletions.
812 changes: 536 additions & 276 deletions .domino/compiled_metadata.json

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions .domino/dependencies_map.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@
"DataConversionPiece",
"GetDateTimePiece",
"PageScrapperPiece",
"LogPiece",
"CustomPythonPiece",
"ToStringPiece",
"ImageFilterPiece",
"SleepPiece",
"SaveImagePiece",
"SimpleLogPiece",
"ApiFetchPiece",
"GetItemFromArrayPiece"
"HttpRequestPiece",
"GetItemFromArrayPiece",
"LoremIpsumGeneratorPiece"
],
"secrets": [],
"source_image": "ghcr.io/tauffer-consulting/default_domino_pieces:0.6.0-group0"
"source_image": "ghcr.io/tauffer-consulting/default_domino_pieces:development-group0"
}
}
42 changes: 39 additions & 3 deletions .github/workflows/tests-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,52 @@ jobs:

- name: Run organize and build images
run: |
domino piece organize --build-images --source-url=https://github.com/${{github.repository}}
domino piece organize --build-images --source-url=https://github.com/${{github.repository}} --tag-overwrite=development
- name: Install Tests Dependencies
run: pip install -r requirements-tests.txt

# Remember to pass any necessary secrets as env vars here
- name: Run tests over built images
env:
PIECE_SECRET_1: ${{ secrets.PIECE_SECRET_1 }}
run: |
pytest --cov=pieces --cov-report=xml --cov-report=term-missing
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

- name: Publish images
env:
GHCR_USERNAME: ${{ github.actor }}
run: domino piece publish-images --registry-token ${{ secrets.GITHUB_TOKEN }}

- name: Commit files
id: commit_files
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
GIT_STATUS=$(git status -s)
if [[ ! -z "$GIT_STATUS" ]]; then
git add .domino/* && git commit -m "auto-organize" -a
echo "commit_sha=$(git rev-parse HEAD)" >> $GITHUB_ENV
else
echo "No changes to commit"
echo "commit_sha=${{ github.sha }}" >> $GITHUB_ENV
fi
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}

- name: Create Release
env:
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
domino piece delete-release --tag-name=development
domino piece release --tag-name=development --commit-sha=$commit_sha
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
[![codecov](https://codecov.io/gh/Tauffer-Consulting/default_domino_pieces/graph/badge.svg?token=DLCDR2S3B6)](https://codecov.io/gh/Tauffer-Consulting/default_domino_pieces)

# Default Domino Pieces
Default Domino Pieces that comes pre-installed:
Default Domino Pieces that comes pre-installed in every Domino workspace:

- **SimpleLogPiece** - A simple logging Piece.
- **SleepPiece** - A Piece that executes a Python sleep function for a user-defined duration.
- **GetDateTimePiece** - A Piece that returns the current date and time.
- **CustomPythonPiece** - A Piece that executes a user-defined Python function.
- **GetDateTimePiece** - A Piece that returns the current date and time.
- **GetItemFromArrayPiece** - A Piece that returns an item from an array.
- **HttpRequestPiece** - A Piece that makes an HTTP request to a given URL.
- **LogPiece** - A simple logging Piece.
- **LoremIpsumPiece** - A Piece that returns a random Lorem Ipsum text.
- **PageScrapperPiece** - A Piece that scrapes text from a web page, given a URL and a list of HTML tags.
- **SleepPiece** - A Piece that sleeps for a given number of seconds.
- **ToStringPiece** - A Piece that converts any input to string.
2 changes: 1 addition & 1 deletion config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ REGISTRY_NAME = "tauffer-consulting"
REPOSITORY_NAME = "default_domino_pieces"
REPOSITORY_LABEL = "Default Pieces Repository"

VERSION = "0.6.0"
VERSION = "0.7.0"
3 changes: 2 additions & 1 deletion dependencies/requirements_0.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pytz==2023.3
pandas==2.1.2
Pillow==10.1.0
beautifulsoup4==4.12.2
beautifulsoup4==4.12.2
python-lorem==1.3.0.post1
19 changes: 0 additions & 19 deletions pieces/ApiFetchPiece/metadata.json

This file was deleted.

13 changes: 0 additions & 13 deletions pieces/ApiFetchPiece/models.py

This file was deleted.

19 changes: 0 additions & 19 deletions pieces/ApiFetchPiece/piece.py

This file was deleted.

21 changes: 0 additions & 21 deletions pieces/ApiFetchPiece/test_api_fetch_piece.py

This file was deleted.

8 changes: 4 additions & 4 deletions pieces/CustomPythonPiece/metadata.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "CustomPythonPiece",
"description": "Run your custom Python code.",
"description": "Executes user-defined Python code.",
"dependency": {
"requirements_file": "requirements_0.txt"
},
"tags": [
"python",
"default"
"default",
"python"
],
"style": {
"node_label": "Custom Python Piece",
"node_label": "Custom Python",
"node_style": {
"backgroundColor": "#b3cde8"
},
Expand Down
4 changes: 2 additions & 2 deletions pieces/CustomPythonPiece/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class InputModel(BaseModel):
}
)
script: str = Field(
default="""# Do not modify the function definition line
default="""# Do not modify the function definition line
def custom_function(kwarg_1, kwarg_2):
# Write your code here
print(f"First argument: {kwarg_1}")
Expand All @@ -52,7 +52,7 @@ def custom_function(kwarg_1, kwarg_2):
description='Python script.',
json_schema_extra={
"from_upstream": "never",
'widget': "codeeditor",
'widget': "codeeditor-python",
}
)
output_args: List[OutputModifierModel] = Field(
Expand Down
6 changes: 3 additions & 3 deletions pieces/GetDateTimePiece/metadata.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "GetDateTimePiece",
"description": "A Piece that gets current system date and time.",
"description": "A Piece that gets system's current date and time.",
"dependency": {
"requirements_file": "requirements_0.txt"
},
"tags": [
"datetime",
"default"
"default",
"datetime"
],
"style": {
"node_label": "Get Datetime",
Expand Down
7 changes: 4 additions & 3 deletions pieces/GetItemFromArrayPiece/metadata.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "GetItemFromArrayPiece",
"description": "Get one item from an array",
"description": "Get one item from an input array.",
"dependency": {
"requirements_file": "requirements_0.txt"
},
"tags": [
"default"
"default",
"array"
],
"style": {
"node_label": "Get Item From Array Piece",
"node_label": "Get Item From Array",
"node_style": {
"backgroundColor": "#b3cde8"
},
Expand Down
19 changes: 19 additions & 0 deletions pieces/HttpRequestPiece/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "HttpRequestPiece",
"description": "Makes a HTTP request to a given URL.",
"dependency": {
"requirements_file": "requirements_0.txt"
},
"tags": [
"default",
"http",
"request"
],
"style": {
"node_label": "HTTP Request",
"node_style": {
"backgroundColor": "#b3cde8"
},
"icon_class_name": "material-symbols:send"
}
}
40 changes: 40 additions & 0 deletions pieces/HttpRequestPiece/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from pydantic import BaseModel, Field
from enum import Enum


class MethodTypes(str, Enum):
GET = 'GET'
POST = 'POST'
PUT = 'PUT'
DELETE = 'DELETE'


class InputModel(BaseModel):
url: str = Field(
description="URL to make a request to."
)
method: MethodTypes = Field(
default=MethodTypes.GET,
description="HTTP method to use."
)
bearer_token: str = Field(
default=None,
description="Bearer token to use for authentication."
)
body_json_data: str = Field(
default="""{
"key_1": "value_1",
"key_2": "value_2"
}
""",
description="JSON data to send in the request body.",
json_schema_extra={
'widget': "codeeditor-json",
}
)


class OutputModel(BaseModel):
base64_bytes_data: str = Field(
description='Output data as base64 encoded string.'
)
47 changes: 47 additions & 0 deletions pieces/HttpRequestPiece/piece.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from domino.base_piece import BasePiece
from .models import InputModel, OutputModel
import requests
import base64
import json


class HttpRequestPiece(BasePiece):
def piece_function(self, input_data: InputModel):

try:
url = input_data.url
method = input_data.method

headers = {}
if input_data.bearer_token:
headers['Authorization'] = f'Bearer {input_data.bearer_token}'

# Prepare the request body if applicable
body_data = None
if method in ["POST", "PUT"]:
try:
body_data = json.loads(input_data.body_json_data)
except json.JSONDecodeError:
raise Exception("Invalid JSON data in the request body.")

# Send the HTTP request
if method == "GET":
response = requests.get(url, headers=headers)
elif method == "POST":
response = requests.post(url, headers=headers, json=body_data)
elif method == "PUT":
response = requests.put(url, headers=headers, json=body_data)
elif method == "DELETE":
response = requests.delete(url, headers=headers)
else:
raise Exception(f"Unsupported HTTP method: {method}")

# Check for HTTP errors
response.raise_for_status()

except requests.RequestException as e:
raise Exception(f"HTTP request error: {e}")

# convert content to base64
base64_bytes_data = base64.b64encode(response.content).decode('utf-8')
return OutputModel(base64_bytes_data=base64_bytes_data)
Loading

0 comments on commit b8c76ce

Please sign in to comment.