From aa6da0f6d3a51b162845f18febd96d4d12347be8 Mon Sep 17 00:00:00 2001 From: Devon Steenberg Date: Mon, 16 Feb 2026 09:35:06 +1300 Subject: [PATCH] feat(api-testing): add api testing framework [BE-12571] (#1824) Co-authored-by: Chaim Lev-Ari --- .golangci-forward.yaml | 2 +- api/dataservices/ssl/ssl.go | 7 +++++++ api/dataservices/ssl/tx.go | 31 +++++++++++++++++++++++++++++++ api/datastore/services_tx.go | 4 +++- 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 api/dataservices/ssl/tx.go diff --git a/.golangci-forward.yaml b/.golangci-forward.yaml index 1486a4873..f9cedf5d7 100644 --- a/.golangci-forward.yaml +++ b/.golangci-forward.yaml @@ -6,7 +6,7 @@ linters: settings: forbidigo: forbid: - - pattern: ^dataservices.DataStore.(EdgeGroup|EdgeJob|EdgeStack|EndpointRelation|Endpoint|GitCredential|Registry|ResourceControl|Role|Settings|Snapshot|Stack|Tag|User)$ + - pattern: ^dataservices.DataStore.(EdgeGroup|EdgeJob|EdgeStack|EndpointRelation|Endpoint|GitCredential|Registry|ResourceControl|Role|Settings|Snapshot|SSLSettings|Stack|Tag|User)$ msg: Use a transaction instead analyze-types: true exclusions: diff --git a/api/dataservices/ssl/ssl.go b/api/dataservices/ssl/ssl.go index 58b5e3876..4270c85fc 100644 --- a/api/dataservices/ssl/ssl.go +++ b/api/dataservices/ssl/ssl.go @@ -31,6 +31,13 @@ func NewService(connection portainer.Connection) (*Service, error) { }, nil } +func (service *Service) Tx(tx portainer.Transaction) ServiceTx { + return ServiceTx{ + service: service, + tx: tx, + } +} + // Settings retrieve the ssl settings object. func (service *Service) Settings() (*portainer.SSLSettings, error) { var settings portainer.SSLSettings diff --git a/api/dataservices/ssl/tx.go b/api/dataservices/ssl/tx.go new file mode 100644 index 000000000..d0a2f27f8 --- /dev/null +++ b/api/dataservices/ssl/tx.go @@ -0,0 +1,31 @@ +package ssl + +import ( + portainer "github.com/portainer/portainer/api" +) + +type ServiceTx struct { + service *Service + tx portainer.Transaction +} + +func (service ServiceTx) BucketName() string { + return BucketName +} + +// Settings retrieve the settings object. +func (service ServiceTx) Settings() (*portainer.SSLSettings, error) { + var settings portainer.SSLSettings + + err := service.tx.GetObject(BucketName, []byte(key), &settings) + if err != nil { + return nil, err + } + + return &settings, nil +} + +// UpdateSettings persists a Settings object. +func (service ServiceTx) UpdateSettings(settings *portainer.SSLSettings) error { + return service.tx.UpdateObject(BucketName, []byte(key), settings) +} diff --git a/api/datastore/services_tx.go b/api/datastore/services_tx.go index e77fe11cc..f8781ca5f 100644 --- a/api/datastore/services_tx.go +++ b/api/datastore/services_tx.go @@ -74,7 +74,9 @@ func (tx *StoreTx) Snapshot() dataservices.SnapshotService { return tx.store.SnapshotService.Tx(tx.tx) } -func (tx *StoreTx) SSLSettings() dataservices.SSLSettingsService { return nil } +func (tx *StoreTx) SSLSettings() dataservices.SSLSettingsService { + return tx.store.SSLSettingsService.Tx(tx.tx) +} func (tx *StoreTx) Stack() dataservices.StackService { return tx.store.StackService.Tx(tx.tx)