Skip to content

Commit 114bb60

Browse files
committed
fix(spdx): use configured external URL in document namespace
Hardcoded `factory.talos.dev` in SPDX document namespace broke deployments where image-factory runs under a different hostname. External URL now threads from service config through SPDXOptions and Builder down to namespace generation. Fixes #440 Signed-off-by: Mateusz Urbanek <mateusz.urbanek@siderolabs.com>
1 parent ccffefc commit 114bb60

7 files changed

Lines changed: 18 additions & 6 deletions

File tree

cmd/image-factory/cmd/service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ func buildEnterprisePlugins(
192192
}
193193

194194
spdxFrontend, err := enterprise.NewSpdxFrontend(logger, enterprise.SPDXOptions{
195+
ExternalURL: opts.HTTP.ExternalURL,
195196
SchematicFactory: configFactory,
196197
ArtifactsManager: artifactsManager,
197198
AssetBuilder: assetBuilder,

enterprise/spdx/builder/builder.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,23 @@ type AuthProvider interface {
4242
// Builder orchestrates SPDX extraction and caching.
4343
type Builder struct {
4444
storage storage.Storage
45+
sf singleflight.Group
46+
authProvider AuthProvider
4547
artifactsManager *artifacts.Manager
4648
assetBuilder *asset.Builder
4749
schematicFactory *schematic.Factory
4850
logger *zap.Logger
49-
sf singleflight.Group
50-
authProvider AuthProvider
51+
externalURL string
5152
}
5253

5354
// Options defines the dependencies for the SPDX builder.
5455
type Options struct {
5556
Storage storage.Storage
57+
AuthProvider AuthProvider
5658
ArtifactsManager *artifacts.Manager
5759
SchematicFactory *schematic.Factory
5860
AssetBuilder *asset.Builder
59-
AuthProvider AuthProvider
61+
ExternalURL string
6062
}
6163

6264
// NewBuilder creates a new SPDX bundle builder.
@@ -65,6 +67,7 @@ func NewBuilder(
6567
opts Options,
6668
) *Builder {
6769
return &Builder{
70+
externalURL: opts.ExternalURL,
6871
storage: opts.Storage,
6972
artifactsManager: opts.ArtifactsManager,
7073
schematicFactory: opts.SchematicFactory,
@@ -136,6 +139,7 @@ func (b *Builder) buildBundle(sc *schematicpkg.Schematic, schematicID, versionTa
136139
SchematicID: schematicID,
137140
TalosVersion: versionTag,
138141
Arch: string(arch),
142+
ExternalURL: b.externalURL,
139143
Files: []File{},
140144
}
141145

enterprise/spdx/builder/spdx.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ type Bundle struct {
4141
// Arch is the target architecture (e.g., "amd64").
4242
Arch string
4343

44+
// ExternalURL is the host used in the document namespace (e.g., "factory.sidero.dev").
45+
ExternalURL string
46+
4447
// Files contains the extracted SPDX files.
4548
Files []File
4649
}
@@ -60,7 +63,8 @@ func BundleToJSON(bundle *Bundle) (io.Reader, int64, error) {
6063
SPDXIdentifier: common.ElementID("DOCUMENT"),
6164
DocumentName: fmt.Sprintf("talos-%s-%s-%s", bundle.SchematicID, bundle.TalosVersion, bundle.Arch),
6265
DocumentNamespace: fmt.Sprintf(
63-
"https://factory.talos.dev/spdx/%s/%s/%s",
66+
"https://%s/spdx/%s/%s/%s",
67+
bundle.ExternalURL,
6468
bundle.SchematicID,
6569
bundle.TalosVersion,
6670
bundle.Arch,

internal/integration/frontend_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import (
1111
"net/http"
1212
"testing"
1313

14-
"github.com/siderolabs/image-factory/pkg/client"
1514
"github.com/stretchr/testify/assert"
1615
"github.com/stretchr/testify/require"
1716

17+
"github.com/siderolabs/image-factory/pkg/client"
1818
"github.com/siderolabs/image-factory/pkg/enterprise"
1919
schematicpkg "github.com/siderolabs/image-factory/pkg/schematic"
2020
)

internal/integration/spdx_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ func testSPDXFrontend(ctx context.Context, t *testing.T, baseURL string) {
7979
assert.Equal(t, spdx.Version, doc.SPDXVersion)
8080
assert.Equal(t, spdx.DataLicense, doc.DataLicense)
8181
assert.Contains(t, doc.DocumentName, "talos-"+emptySchematicID)
82-
assert.Contains(t, doc.DocumentNamespace, "https://factory.talos.dev/spdx/"+emptySchematicID)
82+
assert.Contains(t, doc.DocumentNamespace, "https://")
83+
assert.Contains(t, doc.DocumentNamespace, "/spdx/"+emptySchematicID)
8384
require.NotNil(t, doc.CreationInfo)
8485
assert.NotEmpty(t, doc.CreationInfo.Creators)
8586
})

pkg/enterprise/enterprise.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type FrontendPlugin interface {
2929

3030
// SPDXOptions holds configuration options for the SPDX frontend.
3131
type SPDXOptions struct {
32+
ExternalURL string
3233
CacheImageSigner signer.Signer
3334
SchematicFactory *schematic.Factory
3435
ArtifactsManager *artifacts.Manager

pkg/enterprise/enterprise_on.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func NewSpdxFrontend(logger *zap.Logger, opts SPDXOptions) (FrontendPlugin, erro
4848
}
4949

5050
builder := builder.NewBuilder(logger, builder.Options{
51+
ExternalURL: opts.ExternalURL,
5152
Storage: storage,
5253
ArtifactsManager: opts.ArtifactsManager,
5354
SchematicFactory: opts.SchematicFactory,

0 commit comments

Comments
 (0)