Skip to content

Commit

Permalink
Rename reflect to services inline with current Arc terminology, p…
Browse files Browse the repository at this point in the history
…lugin APIs, etc
  • Loading branch information
ryanblock committed Jul 6, 2023
1 parent fa1da03 commit 124a784
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 26 deletions.
2 changes: 1 addition & 1 deletion arc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os


def reflect():
def services():
path = "/" + os.environ["ARC_CLOUDFORMATION"]
ssm = boto3.client("ssm")
res = ssm.get_parameters_by_path(Path=path, Recursive=True)
Expand Down
4 changes: 2 additions & 2 deletions arc/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
import urllib.request # , urllib.parse

from . import reflect
from . import services


def publish(name, payload):
Expand All @@ -18,7 +18,7 @@ def publish(name, payload):
print("arc.events.publish to sandbox failed: " + str(e))
return data
else:
arc = reflect()
arc = services()
arn = arc["events"][name]
sns = boto3.client("sns")
return sns.publish(TopicArn=arn, Message=json.dumps(payload))
4 changes: 2 additions & 2 deletions arc/queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import urllib.request
import os

from . import reflect
from . import services


def publish(name, payload):
Expand All @@ -17,7 +17,7 @@ def publish(name, payload):
print("arc.queues.publish to sandbox failed: " + str(e))
return data
else:
arc = reflect()
arc = services()
arn = arc["queues"][name]
sqs = boto3.client("sqs")
return sqs.send_message(
Expand Down
4 changes: 2 additions & 2 deletions arc/tables.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import boto3

from . import reflect
from . import services


def name(tablename):
Expand All @@ -21,7 +21,7 @@ def name(tablename):
else:
return name[0]
else:
arc = reflect()
arc = services()
return arc["tables"][tablename]


Expand Down
4 changes: 2 additions & 2 deletions arc/ws.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import boto3
import json

from . import reflect
from . import services


def send(id, payload):
Expand All @@ -15,7 +15,7 @@ def send(id, payload):
print("arc.ws.send to sandbox failed: " + str(e))
return data
else:
arc = reflect()
arc = services()
https = arc["ws"]["https"]
api = boto3.client("apigatewaymanagementapi", endpoint_url=https)
return api.post_to_connection(Data=json.dumps(payload), ConnectionId=id)
5 changes: 2 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import json
import arc

def handler(event, context):
return {'body': json.dumps(arc.reflect())}
return {'body': json.dumps(arc.services())}
```

### `arc`

`arc.reflect` returns a dict of the the current AWS resources.
`arc.services()` returns a dict of the the current AWS resources.

Example output:
```
Expand Down Expand Up @@ -91,4 +91,3 @@ pipenv run python -m pep517.build --source --binary --out-dir dist/ .
```bash
twine upload dist/*
```

6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ def ddb_client(aws_credentials):


@pytest.fixture
def arc_reflection(ssm_client):
def arc_services(ssm_client):
os.environ["ARC_CLOUDFORMATION"] = "TestPythonStaging"

def mock_reflect(params):
def mock_services(params):
for k, v in params.items():
ssm_client.put_parameter(
Name=f"/TestPythonStaging/{k}",
Expand All @@ -53,4 +53,4 @@ def mock_reflect(params):
Type="String",
)

return mock_reflect
return mock_services
4 changes: 2 additions & 2 deletions tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@


@pytest.mark.filterwarnings("ignore:the imp module is deprecated")
def test_publish(arc_reflection, sns_client):
def test_publish(arc_services, sns_client):
topic_name = "ping"
sns_client.create_topic(Name=topic_name)
topics = sns_client.list_topics()

arc_reflection(params={f"events/{topic_name}": topics["Topics"][0]["TopicArn"]})
arc_services(params={f"events/{topic_name}": topics["Topics"][0]["TopicArn"]})
val = arc.events.publish(name=topic_name, payload={"python": True})
assert isinstance(val, dict)
assert "MessageId" in val
Expand Down
4 changes: 2 additions & 2 deletions tests/test_http_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_ddb_sign_unsign_fail():
assert valid == False


def test_jwe_read_write(arc_reflection, ddb_client):
def test_jwe_read_write(arc_services, ddb_client):
tablename = "sessions"
ddb_client.create_table(
TableName=tablename,
Expand All @@ -55,7 +55,7 @@ def test_jwe_read_write(arc_reflection, ddb_client):
BillingMode="PAY_PER_REQUEST",
)
tables = ddb_client.list_tables()
arc_reflection(params={f"tables/{tablename}": tables["TableNames"][0]})
arc_services(params={f"tables/{tablename}": tables["TableNames"][0]})

payload = {"_idx": "abc", "foo": {"bar": 123}, "yak": None}
token = ddb_write(payload, tablename)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@


@pytest.mark.filterwarnings("ignore:the imp module is deprecated")
def test_queue_publish(arc_reflection, sqs_client):
def test_queue_publish(arc_services, sqs_client):
queue_name = "continuum"
sqs_client.create_queue(QueueName=queue_name)
queues = sqs_client.list_queues()

arc_reflection(params={f"queues/{queue_name}": queues["QueueUrls"][0]})
arc_services(params={f"queues/{queue_name}": queues["QueueUrls"][0]})
val = arc.queues.publish(name=queue_name, payload={"python": True})
assert isinstance(val, dict)
assert "MessageId" in val
Expand Down
6 changes: 3 additions & 3 deletions tests/test_reflect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import arc


def test_arc_reflect(arc_reflection):
arc_reflection(params={"foo/bar": "this is it!"})
val = arc.reflect()
def test_arc_services(arc_services):
arc_services(params={"foo/bar": "this is it!"})
val = arc.services()
assert val == {"foo": {"bar": "this is it!"}}
4 changes: 2 additions & 2 deletions tests/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import arc.tables


def test_tables(arc_reflection, ddb_client):
def test_tables(arc_services, ddb_client):
tablename = "noises"
ddb_client.create_table(
TableName=tablename,
Expand All @@ -11,7 +11,7 @@ def test_tables(arc_reflection, ddb_client):
BillingMode="PAY_PER_REQUEST",
)
tables = ddb_client.list_tables()
arc_reflection(params={f"tables/{tablename}": tables["TableNames"][0]})
arc_services(params={f"tables/{tablename}": tables["TableNames"][0]})

val = arc.tables.name(tablename=tablename)
assert val == tables["TableNames"][0]
Expand Down

0 comments on commit 124a784

Please sign in to comment.