Skip to content

Commit

Permalink
Dokku app names are cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
odscjames committed Mar 17, 2023
1 parent 03deada commit 6f718ef
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- nginx / client_max_body_size option - set by command line option or environmental variable.
- nginx / proxy-read-timeout option - set by command line option or environmental variable.
- Dokku app names are cleaned up. Invalid characters are changed to "-". Lower case is enforced.

## Changed

Expand Down
10 changes: 9 additions & 1 deletion dokkusd/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ def get_remote_names_configured(git_remote_verbose_output):
return out


def clean_dokku_app_name(app_name: str) -> str:
app_name = app_name.replace("_", "-")
app_name = app_name.replace(":", "-")
app_name = app_name.replace("/", "-")
app_name = app_name.replace("\\", "-")
return app_name.lower()


class Task:
def __init__(
self,
Expand All @@ -31,7 +39,7 @@ def __init__(
self.remote_user = remote_user
self.remote_host = remote_host
self.remote_port = remote_port
self.app_name = app_name
self.app_name = clean_dokku_app_name(app_name)

def _dokku_command(self, command):
full_command = [
Expand Down
25 changes: 25 additions & 0 deletions test/test_clean_dokku_app_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from dokkusd.util import clean_dokku_app_name


def test_fine_1():
assert "cat" == clean_dokku_app_name("cat")


def test_bad_1():
assert "cat-" == clean_dokku_app_name("cat_")


def test_bad_2():
assert "cat-" == clean_dokku_app_name("cat:")


def test_bad_3():
assert "cat-" == clean_dokku_app_name("cat/")


def test_bad_4():
assert "cat-" == clean_dokku_app_name("cat\\")


def test_bad_5():
assert "cat" == clean_dokku_app_name("CAT")

0 comments on commit 6f718ef

Please sign in to comment.