-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from dokku/99-ipv6
feat: add support for ipv6 addresses
- Loading branch information
Showing
3 changed files
with
73 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/[:/].*//' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |