Skip to content

Commit

Permalink
✨ Adds support for fetching ports and port descriptions (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
frenck authored Apr 9, 2019
1 parent 8b9d173 commit 22661a8
Showing 1 changed file with 62 additions and 0 deletions.
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

0 comments on commit 22661a8

Please sign in to comment.