Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add git username config option #18

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions charm/charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ config:
git_ssh_key:
type: string
description: The private key for SSH authentication.
git_username:
type: string
description: The git username.
4 changes: 3 additions & 1 deletion httprequest_lego_provider/dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from git import Git, GitCommandError, Repo

from .settings import GIT_REPO_URL, GIT_SSH_KEY
from .settings import GIT_REPO_URL, GIT_SSH_KEY, GIT_USERNAME

FILENAME_TEMPLATE = "{domain}.domain"
SPLIT_GIT_REPO_URL = GIT_REPO_URL.rsplit("@", 1)
Expand Down Expand Up @@ -88,6 +88,7 @@ def write_dns_record(fqdn: str, value: str) -> None:
with TemporaryDirectory() as tmp_dir, Git().custom_environment(GIT_SSH_COMMAND=SSH_EXECUTABLE):
try:
repo = Repo.clone_from(REPOSITORY_BASE_URL, tmp_dir, branch=REPOSITORY_BRANCH)
repo.config_writer().set_value("user", "name", GIT_USERNAME).release()
domain, subdomain = _get_domain_and_subdomain_from_fqdn(fqdn)
filename = FILENAME_TEMPLATE.format(domain=domain)
dns_record_file = Path(f"{repo.working_tree_dir}/{filename}")
Expand Down Expand Up @@ -116,6 +117,7 @@ def remove_dns_record(fqdn: str) -> None:
with TemporaryDirectory() as tmp_dir, Git().custom_environment(GIT_SSH_COMMAND=SSH_EXECUTABLE):
try:
repo = Repo.clone_from(REPOSITORY_BASE_URL, tmp_dir, branch=REPOSITORY_BRANCH)
repo.config_writer().set_value("user", "name", GIT_USERNAME).release()
domain, subdomain = _get_domain_and_subdomain_from_fqdn(fqdn)
filename = FILENAME_TEMPLATE.format(domain=domain)
dns_record_file = Path(f"{repo.working_tree_dir}/{filename}")
Expand Down
1 change: 1 addition & 0 deletions httprequest_lego_provider/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@

GIT_REPO_URL = os.getenv("DJANGO_GIT_REPO", default="")
GIT_SSH_KEY = os.getenv("DJANGO_GIT_SSH_KEY", default="")
GIT_USERNAME = os.getenv("DJANGO_GIT_USERNAME", default="")
LOGIN_REDIRECT_URL = "/"
Loading