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

✨ Adds support for fetching ports and port descriptions #5

Merged
merged 1 commit into from
Apr 9, 2019
Merged
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
62 changes: 62 additions & 0 deletions lib/addons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,68 @@ function bashio::addon.network() {
bashio::addons "${slug}" "addons.${slug}.network" '.network'
}

# ------------------------------------------------------------------------------
# Returns a list of ports and their descriptions for this add-on.
#
# Arguments:
# $1 Add-on slug (optional, default: self)
# ------------------------------------------------------------------------------
function bashio::addon.network_description() {
local slug=${1:-'self'}
bashio::log.trace "${FUNCNAME[0]}" "$@"
bashio::addons "${slug}" \
"addons.${slug}.network_description" \
'.network_description'
}

# ------------------------------------------------------------------------------
# Returns a user configured port number for a original port number.
#
# Arguments:
# $1 Original port number
# $2 Add-on slug (optional, default: self)
# ------------------------------------------------------------------------------
function bashio::addon.port() {
local port=${1:-}
local slug=${2:-'self'}

bashio::log.trace "${FUNCNAME[0]}" "$@"

# Default to TCP if not specified.
if [[ "${port}" != *"/"* ]]; then
port="${port}/tcp"
fi

bashio::addons \
"${slug}" \
"addons.${slug}.network.${port//\//-}" \
".network[\"${port}\"]"
}

# ------------------------------------------------------------------------------
# Returns a description for port number for this add-on.
#
# Arguments:
# $1 Original port number
# $2 Add-on slug (optional, default: self)
# ------------------------------------------------------------------------------
function bashio::addon.port_description() {
local port=${1:-}
local slug=${2:-'self'}

bashio::log.trace "${FUNCNAME[0]}" "$@"

# Default to TCP if not specified.
if [[ "${port}" != *"/"* ]]; then
port="${port}/tcp"
fi

bashio::addons \
"${slug}" \
"addons.${slug}.network_description.${port//\//-}" \
".network_description[\"${port}\"]"
}

# ------------------------------------------------------------------------------
# Returns whether or not this add-on runs on the host network.
#
Expand Down