Skip to content

Commit

Permalink
Merge pull request #100 from dokku/99-ipv6
Browse files Browse the repository at this point in the history
feat: add support for ipv6 addresses
  • Loading branch information
josegonzalez committed Jan 29, 2024
2 parents 598565c + 6d2f500 commit 58c34ab
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM alpine:3.19.0

RUN apk --no-cache add git==2.43.0-r0 openssh==9.6_p1-r0 && \
RUN apk --no-cache add git==2.43.0-r0 python3==3.11.6-r1 openssh==9.6_p1-r0 && \
mkdir -p ~/.ssh

COPY bin /bin
56 changes: 47 additions & 9 deletions bin/parse-ssh-host
Original file line number Diff line number Diff line change
@@ -1,12 +1,50 @@
#!/bin/sh -l
set -e
#!/usr/bin/python3

if [ -n "$TRACE" ]; then
set -x
fi
import ipaddress
import os
import sys
import urllib.parse

if [ -n "$PLUGIN_GIT_REMOTE_URL" ]; then
export GIT_REMOTE_URL="$PLUGIN_GIT_REMOTE_URL"
fi

echo "$GIT_REMOTE_URL" | sed -e 's/.*@//' -e 's/[:/].*//'
def is_ipv6(ip):
"""
Returns True if the ip is an IPv6 address
"""
try:
return isinstance(ipaddress.ip_address(ip), ipaddress.IPv6Address)
except ValueError:
print(f"Invalid IP address: {ip}", file=sys.stderr)
return False


def main():
"""
Prints out the host of the git remote url
"""
git_remote_url = os.getenv("GIT_REMOTE_URL")
if os.getenv("PLUGIN_GIT_REMOTE_URL"):
git_remote_url = os.getenv("PLUGIN_GIT_REMOTE_URL")

if not git_remote_url:
print("GIT_REMOTE_URL is empty", file=sys.stderr)
sys.exit(1)

u = urllib.parse.urlparse(git_remote_url)
host = u.hostname
if is_ipv6(host):
host = f"[{host}]"
print(host)


if __name__ == "__main__":
main()

# if [ -n "$TRACE" ]; then
# set -x
# fi

# if [ -n "$PLUGIN_GIT_REMOTE_URL" ]; then
# export GIT_REMOTE_URL="$PLUGIN_GIT_REMOTE_URL"
# fi

# echo "$GIT_REMOTE_URL" | sed -e 's/.*@//' -e 's/[:/].*//'
38 changes: 25 additions & 13 deletions bin/parse-ssh-port
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
#!/bin/sh -l
set -e
#!/usr/bin/python3

if [ -n "$TRACE" ]; then
set -x
fi
import os
import sys
import urllib.parse

if [ -n "$PLUGIN_GIT_REMOTE_URL" ]; then
export GIT_REMOTE_URL="$PLUGIN_GIT_REMOTE_URL"
fi

ssh_port="$(echo "$GIT_REMOTE_URL" | sed -e 's/.*@//' -e 's/\/.*//' -ne 's/.*:\([0-9]*\)/\1/p')"
if [ -z "$ssh_port" ]; then
ssh_port=22
fi
def main():
"""
Prints out the port of the git remote url
"""
git_remote_url = os.getenv("GIT_REMOTE_URL")
if os.getenv("PLUGIN_GIT_REMOTE_URL"):
git_remote_url = os.getenv("PLUGIN_GIT_REMOTE_URL")

echo "$ssh_port"
if not git_remote_url:
print("GIT_REMOTE_URL is empty", file=sys.stderr)
sys.exit(1)

u = urllib.parse.urlparse(git_remote_url)
port = "22"
if u.port:
port = u.port

print(port)


if __name__ == "__main__":
main()

0 comments on commit 58c34ab

Please sign in to comment.