Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

Commit

Permalink
Update abstra-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
abstra-bot committed Mar 7, 2023
1 parent 14950d3 commit 4a0cb44
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 17 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Remote resources can be:
- `files`
- `vars`
- `packages`
- `subdomain`

### List resources

Expand All @@ -84,6 +85,8 @@ abstra list hooks

abstra list jobs

abstra list subdomain

# Saving cloud packages to a requirements.txt file
abstra list packages > requirements.txt

Expand Down Expand Up @@ -297,6 +300,16 @@ Examples:
abstra update hook stripe-callback --enabled
```

#### `subdomain`

- `--name`: string (required parameter)

Examples:

```sh
abstra update subdomain new-subdomain-name
```

### Remove resource

Remove remote resources from your workspace.
Expand Down
1 change: 1 addition & 0 deletions abstra_cli/apis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
from .packages import *
from .public import *
from .dashes import *
from .subdomains import *
15 changes: 0 additions & 15 deletions abstra_cli/apis/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,3 @@ def hf_hasura_runner(query, variables={}):
raise Exception(jsond["errors"])


def get_subdomain():
query = """
query Subdomains {
subdomains {
name
}
}
"""

subdomains = hf_hasura_runner(query, {}).get("subdomains", [])
if not len(subdomains):
print("Could not find subdomain.")
exit()

return subdomains[0]["name"]
1 change: 0 additions & 1 deletion abstra_cli/apis/packages.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import abstra_cli.apis.main as api_main
import abstra_cli.utils as utils


def list_workspace_packages():
Expand Down
36 changes: 36 additions & 0 deletions abstra_cli/apis/subdomains.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import abstra_cli.apis.main as api_main


def get_subdomain():
query = """
query Subdomains {
subdomains {
name
}
}
"""

subdomains = api_main.hf_hasura_runner(query, {}).get("subdomains", [])
if not len(subdomains):
print("Could not find subdomain.")
exit()

return subdomains[0]["name"]

def update_subdomain(old_name, new_name):
query = """
mutation UpdateSubdomain($old_name: String!, $new_name: String!) {
update_subdomains(where: {name: {_eq: $old_name}}, _set: {name: $new_name}) {
returning {
name
}
}
}
"""
return (
api_main.hf_hasura_runner(query, {"old_name": old_name, "new_name": new_name})
.get("update_subdomains", {})
.get("returning", [])
)


4 changes: 3 additions & 1 deletion abstra_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import abstra_cli.messages as messages
import abstra_cli.decorators as decorators
import abstra_cli.credentials as credentials
from abstra_cli.resources import Forms, Files, Packages, Vars, Hooks, Jobs, Dashes
from abstra_cli.resources import Forms, Files, Packages, Vars, Hooks, Jobs, Dashes, Subdomains


class CLI(object):
Expand All @@ -29,6 +29,7 @@ def list(self, resource, **kwargs):
"hooks": Hooks.list,
"dashes": Dashes.list,
"packages": Packages.list,
"subdomain": Subdomains.list,
}.get(resource, messages.not_implemented)

list_func()
Expand Down Expand Up @@ -62,6 +63,7 @@ def update(self, resource, *args, **kwargs):
"hooks": Hooks.update,
"job": Jobs.update,
"jobs": Jobs.update,
"subdomain": Subdomains.update,
}.get(resource, messages.not_implemented)

update_func(*args, **kwargs)
Expand Down
7 changes: 7 additions & 0 deletions abstra_cli/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ def print_jobs(jobs):
f"{utils.format_digits(j['identifier'], max_idt)} - {utils.format_digits(j['schedule'], max_schedule)} - {utils.format_digits(j['title'], max_title)} ({enabled})"
)

def print_subdomains(subdomain):
print(f"workspace subdomain: {subdomain}")


def created_message(resource: str, form: str):
print(f"{resource} created successfully: {form}")
Expand Down Expand Up @@ -157,6 +160,10 @@ def missing_parameters_to_update(resource_name, resource):
print(f"missing parameters to be updated of {resource_name} {resource}")


def conflict_name(resource_name, resource):
print(f"Conflict error: {resource_name} already exists for {resource}")


def file_path_does_not_exists_message(path):
print(f"file path not found: {path}")

Expand Down
1 change: 1 addition & 0 deletions abstra_cli/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
from .packages import Packages
from .resources import Resource
from .dashes import Dashes
from .subdomains import Subdomains
26 changes: 26 additions & 0 deletions abstra_cli/resources/subdomains.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from abstra_cli.resources.resources import Resource
from abstra_cli.apis import get_subdomain, update_subdomain
import abstra_cli.messages as messages

class Subdomains(Resource):
@staticmethod
def list():
subdomain = get_subdomain()
messages.print_subdomains(subdomain)

@staticmethod
def update(*args, **kwargs):
if not len(args):
messages.missing_parameters_to_update("name", "subdomain")
exit()

new_subdomain = args[0]
old_subdomain = get_subdomain()
try:
updated_subdomain = update_subdomain(old_subdomain, new_subdomain)
messages.print_subdomains(updated_subdomain[0]['name'])
except Exception as error:
if len(error.args) > 0 and len(error.args[0]) > 0 and error.args[0][0]['extensions']['code'] == 'constraint-violation':
messages.conflict_name('name', 'subdomain')
else:
messages.update_failed('subdomain')

0 comments on commit 4a0cb44

Please sign in to comment.