git: 478456713cd9 - main - net/dataplaneapi: New port: HAProxy Data Plane API

From: Jesús Daniel Colmenares Oviedo <dtxdf_at_FreeBSD.org>
Date: Sat, 07 Jun 2025 18:35:45 UTC
The branch main has been updated by dtxdf:

URL: https://cgit.FreeBSD.org/ports/commit/?id=478456713cd98723956f27dc621f57fb2c4b6727

commit 478456713cd98723956f27dc621f57fb2c4b6727
Author:     Jesús Daniel Colmenares Oviedo <dtxdf@FreeBSD.org>
AuthorDate: 2025-06-07 05:25:06 +0000
Commit:     Jesús Daniel Colmenares Oviedo <dtxdf@FreeBSD.org>
CommitDate: 2025-06-07 18:34:56 +0000

    net/dataplaneapi: New port: HAProxy Data Plane API
    
    Data Plane API is a sidecar process that runs next to HAProxy and
    provides API endpoints for managing HAProxy. It requires HAProxy
    version 1.9.0 or higher.
    
    Approved by: acm (mentor)
---
 net/Makefile                                       |  1 +
 net/dataplaneapi/Makefile                          | 54 ++++++++++++++++++++++
 net/dataplaneapi/distinfo                          |  5 ++
 net/dataplaneapi/files/dataplaneapi.in             | 27 +++++++++++
 net/dataplaneapi/files/dataplaneapi.yaml           | 42 +++++++++++++++++
 .../files/patch-configuration_configuration.go     | 34 ++++++++++++++
 net/dataplaneapi/pkg-descr                         |  3 ++
 net/dataplaneapi/pkg-message                       |  7 +++
 8 files changed, 173 insertions(+)

diff --git a/net/Makefile b/net/Makefile
index 59a4cbb467ff..a76721724dae 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -109,6 +109,7 @@
     SUBDIR += dante
     SUBDIR += daq
     SUBDIR += datapipe
+    SUBDIR += dataplaneapi
     SUBDIR += dbeacon
     SUBDIR += delegate
     SUBDIR += deltachat-rpc-server
diff --git a/net/dataplaneapi/Makefile b/net/dataplaneapi/Makefile
new file mode 100644
index 000000000000..2196971ad3b5
--- /dev/null
+++ b/net/dataplaneapi/Makefile
@@ -0,0 +1,54 @@
+PORTNAME=	dataplaneapi
+DISTVERSIONPREFIX=	v
+DISTVERSION=	3.2.0
+CATEGORIES=	net
+
+MAINTAINER=	dtxdf@FreeBSD.org
+COMMENT=	HAProxy Data Plane API
+WWW=		https://github.com/haproxytech/${PORTNAME}
+
+LICENSE=	APACHE20
+LICENSE_FILE=	${WRKSRC}/LICENSE
+
+USES=		go:modules
+USE_GITHUB=	yes
+GH_ACCOUNT=	haproxytech
+
+USE_RC_SUBR=	${PORTNAME}
+
+GO_MOD_DIST=	github
+GO_MODULE=	github.com/haproxytech/${PORTNAME}
+GO_TARGET=	./cmd/${PORTNAME}
+GO_BUILDFLAGS=	-ldflags "\
+			-X 'main.GitRepo=https://github.com/haproxytech/${PORTNAME}' \
+			-X 'main.GitTag=${DISTVERSIONPREFIX}${DISTVERSION}' \
+			-X 'main.GitCommit=${GITID}' \
+			-X 'main.BuildTime=${BUILD_DATE}'"
+
+PLIST_FILES=	"@sample(,,640) etc/dataplaneapi.yaml.sample" \
+		bin/${PORTNAME}
+
+PORTDOCS=	CONFIG.md README.md
+
+OPTIONS_DEFINE=	DOCS
+
+# Run 'git checkout ${DISTVERSIONPREFIX}${DISTVERSION} && git rev-parse --short HEAD'
+# in the Data Plane API repository to get the value of GITID.
+GITID=		d5e775cc
+
+BUILD_DATE=	$$(date -u "+%Y-%m-%dT%H:%M:%SZ")
+
+post-patch:
+	@${REINPLACE_CMD} -e 's|%%PREFIX%%|${PREFIX}|' \
+		${WRKSRC}/configuration/configuration.go
+
+post-install:
+	${SED} -e 's|%%PREFIX%%|${PREFIX}|' ${FILESDIR}/dataplaneapi.yaml \
+		> ${STAGEDIR}${PREFIX}/etc/dataplaneapi.yaml.sample
+
+post-install-DOCS-on:
+	@${MKDIR} ${STAGEDIR}${DOCSDIR}
+	${INSTALL_DATA} ${WRKSRC}/README.md ${STAGEDIR}${DOCSDIR}
+	${INSTALL_DATA} ${WRKSRC}/configuration/doc/README.md ${STAGEDIR}${DOCSDIR}/CONFIG.md
+
+.include <bsd.port.mk>
diff --git a/net/dataplaneapi/distinfo b/net/dataplaneapi/distinfo
new file mode 100644
index 000000000000..c8e65fe057e2
--- /dev/null
+++ b/net/dataplaneapi/distinfo
@@ -0,0 +1,5 @@
+TIMESTAMP = 1749235275
+SHA256 (go/net_dataplaneapi/haproxytech-dataplaneapi-v3.2.0_GH0/go.mod) = 9a875890252c8d19cc0b58dacee89469dfa82b19630988331ca0f98f1481b3c0
+SIZE (go/net_dataplaneapi/haproxytech-dataplaneapi-v3.2.0_GH0/go.mod) = 4279
+SHA256 (go/net_dataplaneapi/haproxytech-dataplaneapi-v3.2.0_GH0/haproxytech-dataplaneapi-v3.2.0_GH0.tar.gz) = 039f46a0458ebf7e14f22963a2956b5c868fd527957f5a63edd726d066ff9d55
+SIZE (go/net_dataplaneapi/haproxytech-dataplaneapi-v3.2.0_GH0/haproxytech-dataplaneapi-v3.2.0_GH0.tar.gz) = 1066836
diff --git a/net/dataplaneapi/files/dataplaneapi.in b/net/dataplaneapi/files/dataplaneapi.in
new file mode 100644
index 000000000000..fb5f74c483c5
--- /dev/null
+++ b/net/dataplaneapi/files/dataplaneapi.in
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+# PROVIDE: dataplaneapi
+# REQUIRE: LOGIN haproxy
+# KEYWORD: shutdown
+#
+# Configuration settings for Data Plane API in /etc/rc.conf
+#
+# dataplaneapi_enable (bool):    Enable Data Plane API. (default=NO)
+#
+
+. /etc/rc.subr
+
+name="dataplaneapi"
+desc="HAProxy Data Plane API"
+rcvar="${name}_enable"
+
+load_rc_config $name
+
+: ${dataplaneapi_enable:="NO"}
+
+pidfile="/var/run/${name}.pid"
+procname="%%LOCALBASE%%/bin/${name}"
+command="/usr/sbin/daemon"
+command_args="-c -p ${pidfile} -t \"${desc}\" ${procname}"
+
+run_rc_command "$1"
diff --git a/net/dataplaneapi/files/dataplaneapi.yaml b/net/dataplaneapi/files/dataplaneapi.yaml
new file mode 100644
index 000000000000..00dca6fb2a5f
--- /dev/null
+++ b/net/dataplaneapi/files/dataplaneapi.yaml
@@ -0,0 +1,42 @@
+config_version: 2
+name: haproxy-dataplaneapi
+dataplaneapi:
+  host: 0.0.0.0
+  port: 5555
+  advertised:
+    api_address: ""
+    api_port: 0
+  scheme:
+  - http
+  userlist:
+    userlist: controller
+    userlist_file: ""
+  transaction:
+    transaction_dir: %%PREFIX%%/etc/haproxy/transactions
+    backups_number: 10
+    backups_dir: %%PREFIX%%/etc/haproxy/backups
+    max_open_transactions: 10
+  resources:
+    maps_dir: %%PREFIX%%/etc/haproxy/maps
+    ssl_certs_dir: %%PREFIX%%/etc/haproxy/ssl
+    general_storage_dir: %%PREFIX%%/etc/haproxy/general
+    dataplane_storage_dir: %%PREFIX%%/etc/haproxy/dataplane
+    spoe_dir: %%PREFIX%%/etc/haproxy/spoe
+haproxy:
+  config_file: %%PREFIX%%/etc/haproxy/haproxy.cfg
+  haproxy_bin: /usr/local/sbin/haproxy
+  master_worker_mode: false
+  reload:
+    reload_delay: 5
+    reload_cmd: service haproxy reload
+    restart_cmd: service haproxy restart
+    status_cmd: service haproxy status
+    reload_strategy: custom
+    validate_cmd: service haproxy configtest
+log_targets:
+- log_to: file
+  log_file: /var/log/haproxy-dataplaneapi.log
+  log_level: info
+  log_types:
+  - access
+  - app
diff --git a/net/dataplaneapi/files/patch-configuration_configuration.go b/net/dataplaneapi/files/patch-configuration_configuration.go
new file mode 100644
index 000000000000..ed3337fb83d8
--- /dev/null
+++ b/net/dataplaneapi/files/patch-configuration_configuration.go
@@ -0,0 +1,34 @@
+--- configuration/configuration.go.orig	2025-05-26 14:19:12 UTC
++++ configuration/configuration.go
+@@ -37,7 +37,7 @@ type HAProxyConfiguration struct {
+ var cfg *Configuration
+ 
+ type HAProxyConfiguration struct {
+-	SpoeDir              string        `long:"spoe-dir" description:"Path to SPOE directory." default:"/etc/haproxy/spoe" group:"resources"`
++	SpoeDir              string        `long:"spoe-dir" description:"Path to SPOE directory." default:"%%PREFIX%%/etc/haproxy/spoe" group:"resources"`
+ 	ServiceName          string        `long:"service" description:"Name of the HAProxy service" group:"reload"`
+ 	HAProxy              string        `short:"b" long:"haproxy-bin" description:"Path to the haproxy binary file" default:"haproxy" group:"haproxy"`
+ 	UserListFile         string        `long:"userlist-file" description:"Path to the dataplaneapi userlist file. By default userlist is read from HAProxy conf. When specified userlist would be read from this file" group:"userlist"`
+@@ -50,16 +50,16 @@ type HAProxyConfiguration struct {
+ 	TransactionDir       string        `short:"t" long:"transaction-dir" description:"Path to the transaction directory" default:"/tmp/haproxy" group:"transaction"`
+ 	ValidateCmd          string        `long:"validate-cmd" description:"Executes a custom command to perform the HAProxy configuration check" group:"reload"`
+ 	BackupsDir           string        `long:"backups-dir" description:"Path to directory in which to place backup files" group:"transaction"`
+-	MapsDir              string        `short:"p" long:"maps-dir" description:"Path to directory of map files managed by dataplane" default:"/etc/haproxy/maps" group:"resources"`
++	MapsDir              string        `short:"p" long:"maps-dir" description:"Path to directory of map files managed by dataplane" default:"%%PREFIX%%/etc/haproxy/maps" group:"resources"`
+ 	SpoeTransactionDir   string        `long:"spoe-transaction-dir" description:"Path to the SPOE transaction directory" default:"/tmp/spoe-haproxy" group:"resources"`
+-	DataplaneConfig      string        `short:"f" description:"Path to the dataplane configuration file" default:"/etc/haproxy/dataplaneapi.yaml" yaml:"-"`
+-	ConfigFile           string        `short:"c" long:"config-file" description:"Path to the haproxy configuration file" default:"/etc/haproxy/haproxy.cfg" group:"haproxy"`
++	DataplaneConfig      string        `short:"f" description:"Path to the dataplane configuration file" default:"%%PREFIX%%/etc/dataplaneapi.yaml" yaml:"-"`
++	ConfigFile           string        `short:"c" long:"config-file" description:"Path to the haproxy configuration file" default:"%%PREFIX%%/etc/haproxy/haproxy.cfg" group:"haproxy"`
+ 	Userlist             string        `short:"u" long:"userlist" description:"Userlist in HAProxy configuration to use for API Basic Authentication" default:"controller" group:"userlist"`
+ 	MasterRuntime        string        `short:"m" long:"master-runtime" description:"Path to the master Runtime API socket" group:"haproxy"`
+-	SSLCertsDir          string        `long:"ssl-certs-dir" description:"Path to SSL certificates directory" default:"/etc/haproxy/ssl" group:"resources"`
+-	GeneralStorageDir    string        `long:"general-storage-dir" description:"Path to general storage directory" default:"/etc/haproxy/general" group:"resources"`
++	SSLCertsDir          string        `long:"ssl-certs-dir" description:"Path to SSL certificates directory" default:"%%PREFIX%%/etc/haproxy/ssl" group:"resources"`
++	GeneralStorageDir    string        `long:"general-storage-dir" description:"Path to general storage directory" default:"%%PREFIX%%/etc/haproxy/general" group:"resources"`
+ 	ClusterTLSCertDir    string        `long:"cluster-tls-dir" description:"Path where cluster tls certificates will be stored. Defaults to same directory as dataplane configuration file" group:"cluster"`
+-	DataplaneStorageDir  string        `long:"dataplane-storage-dir" description:"Path to dataplane internal storage directory" default:"/etc/haproxy/dataplane" group:"resources"`
++	DataplaneStorageDir  string        `long:"dataplane-storage-dir" description:"Path to dataplane internal storage directory" default:"%%PREFIX%%/etc/haproxy/dataplane" group:"resources"`
+ 	PreferredTimeSuffix  string        `long:"time-suffix" description:"Preferred time unit to use when writing time values in configuration (nearest, none, ms, s, m, h, d)" default:"nearest" group:"haproxy"`
+ 	UpdateMapFilesPeriod int64         `long:"update-map-files-period" description:"Elapsed time in seconds between two maps syncing operations" default:"10" group:"resources"`
+ 	ReloadDelay          int           `short:"d" long:"reload-delay" description:"Minimum delay between two reloads (in s)" default:"5" group:"reload"`
diff --git a/net/dataplaneapi/pkg-descr b/net/dataplaneapi/pkg-descr
new file mode 100644
index 000000000000..c47451e43c33
--- /dev/null
+++ b/net/dataplaneapi/pkg-descr
@@ -0,0 +1,3 @@
+Data Plane API is a sidecar process that runs next to HAProxy and
+provides API endpoints for managing HAProxy. It requires HAProxy
+version 1.9.0 or higher.
diff --git a/net/dataplaneapi/pkg-message b/net/dataplaneapi/pkg-message
new file mode 100644
index 000000000000..cb87f2fccc0a
--- /dev/null
+++ b/net/dataplaneapi/pkg-message
@@ -0,0 +1,7 @@
+[
+{ type: install
+  message: <<EOM
+net/dataplaneapi needs HAProxy to work properly, please install it.
+EOM
+}
+]