Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
eladcon committed Jun 2, 2024
1 parent 2580043 commit 6be9e9c
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 63 deletions.
112 changes: 56 additions & 56 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,63 +30,63 @@ jobs:
name: python-package-distributions
path: dist/

# publish-to-pypi:
# name: Publish Python to PyPI
# needs:
# - build
# runs-on: ubuntu-latest
# environment:
# name: pypi
# url: https://pypi.org/p/wingsdk
# permissions:
# id-token: write # IMPORTANT: mandatory for trusted publishing
publish-to-pypi:
name: Publish Python to PyPI
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/wingsdk
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

# steps:
# - name: Download all the dists
# uses: actions/download-artifact@v4
# with:
# name: python-package-distributions
# path: dist/
# - name: Publish distribution 📦 to PyPI
# uses: pypa/gh-action-pypi-publish@release/v1
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

# github-release:
# name: Upload release GitHub
# needs:
# - publish-to-pypi
# runs-on: ubuntu-latest
github-release:
name: Upload release GitHub
needs:
- publish-to-pypi
runs-on: ubuntu-latest

# permissions:
# contents: write # IMPORTANT: mandatory for making GitHub Releases
# id-token: write # IMPORTANT: mandatory for sigstore
permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

# steps:
# - name: Download all the dists
# uses: actions/download-artifact@v4
# with:
# name: python-package-distributions
# path: dist/
# - name: Sign the dists with Sigstore
# uses: sigstore/[email protected]
# with:
# inputs: >-
# ./dist/*.tar.gz
# ./dist/*.whl
# - name: Create GitHub Release
# env:
# GITHUB_TOKEN: ${{ github.token }}
# run: >-
# gh release create
# '${{ github.ref_name }}'
# --repo '${{ github.repository }}'
# --notes ""
# - name: Upload artifact signatures to GitHub Release
# env:
# GITHUB_TOKEN: ${{ github.token }}
# # Upload to GitHub Release using the `gh` CLI.
# # `dist/` contains the built packages, and the
# # sigstore-produced signatures and certificates.
# run: >-
# gh release upload
# '${{ github.ref_name }}' dist/**
# --repo '${{ github.repository }}'
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/[email protected]
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--notes ""
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
62 changes: 55 additions & 7 deletions wing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import boto3
from botocore.exceptions import ClientError
import json
from typing import Optional, List, TypedDict
from typing import Optional, List, TypedDict, Any
import os
import random

Expand Down Expand Up @@ -105,29 +105,30 @@ class Connection(TypedDict):
clientConfig: ClientConfig

class DynamodbTableClient_base:
def __init__(self, connection: Connection, dynamodb_client: boto3.client):
def __init__(self, connection: Connection, resource: boto3.resource = None):
self.table_name = connection["tableName"]
self.connection = connection
self.dynamodb_client = dynamodb_client or boto3.client('dynamodb')
self.resource = resource or boto3.resource('dynamodb')
self.table = self.resource.Table(self.table_name)

def get(self, **kwargs):
return self.dynamodb_client.get_item(TableName=self.table_name, **kwargs)
return self.table.get_item(**kwargs)

def put(self, **kwargs):
return self.dynamodb_client.put_item(TableName=self.table_name, **kwargs)
return self.table.put_item(**kwargs)

def read_write_connection(self):
return self.connection

class DynamodbTableClient_aws(DynamodbTableClient_base):
def __init__(self, props: dict):
connection: Connection = props["connection"]
super().__init__(connection, boto3.client('dynamodb'))
super().__init__(connection, boto3.resource('dynamodb'))

class DynamodbTableClient_sim(DynamodbTableClient_base):
def __init__(self, props: dict):
connection: Connection = props["connection"]
super().__init__(connection, boto3.client(
super().__init__(connection, boto3.resource(
'dynamodb',
region_name=connection["clientConfig"]["region"],
endpoint_url=connection["clientConfig"]["endpoint"],
Expand Down Expand Up @@ -324,3 +325,50 @@ def from_api_response(res = None):
response["headers"] = res["headers"]

return response

class Aws:
@staticmethod
def api_to_lambda(event: dict[str, Any]):
target = os.getenv(f"WING_TARGET")
if target == "tf-aws":
return req
elif target == "sim":
data = event["payload"]
body = data["body"]
req = {
'httpMethod': data["method"],
'path': data["path"],
'queryStringParameters': data["query"],
'headers': data["headers"],
'body': None if body == "" else body,
'pathParameters': data["vars"],
'requestContext': {
'http': {
'method': data["method"],
'path': data["path"]
}
},
}
return req
else:
raise Exception(f"Unsupported target: {target}")

@staticmethod
def api_from_lambda(res: dict[str, Any]):
response = {}
if not res.get("statusCode"):
response["status"] = 200
else:
response["status"] = res["statusCode"]

if not res.get("body"):
response["body"] = ""
else:
response["body"] = res["body"]

if not res.get("headers"):
response["headers"] = {}
else:
response["headers"] = res["headers"]

return response

0 comments on commit 6be9e9c

Please sign in to comment.