Skip to content

Commit 5224ab8

Browse files
authored
Merge pull request #393 from oasisprotocol/kostko/feature/rofl-metadata
feat(cmd/rofl): Add repository/author/license and other app metadata
2 parents 49aa7f4 + 55cce34 commit 5224ab8

File tree

5 files changed

+69
-4
lines changed

5 files changed

+69
-4
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ linters-settings:
7474
- golang.org/x/text
7575
- gopkg.in/yaml.v3
7676
- github.com/compose-spec/compose-go/v2
77+
- github.com/github/go-spdx/v2
7778
exhaustive:
7879
# Switch statements are to be considered exhaustive if a 'default' case is
7980
# present, even if all enum members aren't listed in the switch.

build/rofl/manifest.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ package rofl
33
import (
44
"errors"
55
"fmt"
6+
"maps"
7+
"net/mail"
8+
"net/url"
69
"os"
710
"path/filepath"
811
"strings"
912

1013
"gopkg.in/yaml.v3"
1114

15+
"github.com/github/go-spdx/v2/spdxexp"
1216
"github.com/oasisprotocol/oasis-core/go/common/version"
1317

1418
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/modules/rofl"
@@ -45,6 +49,16 @@ type Manifest struct {
4549
Name string `yaml:"name" json:"name"`
4650
// Version is the ROFL app version.
4751
Version string `yaml:"version" json:"version"`
52+
// Repository is the ROFL app repository URL.
53+
Repository string `yaml:"repository,omitempty" json:"repository,omitempty"`
54+
// Author is the ROFL app author full name and e-mail.
55+
Author string `yaml:"author,omitempty" json:"author,omitempty"`
56+
// License is the ROFL app SPDX license expression.
57+
License string `yaml:"license,omitempty" json:"license,omitempty"`
58+
// Homepage is the ROFL app homepage.
59+
Homepage string `yaml:"homepage,omitempty" json:"homepage,omitempty"`
60+
// Description is the ROFL app description.
61+
Description string `yaml:"description,omitempty" json:"description,omitempty"`
4862
// TEE is the type of TEE to build for.
4963
TEE string `yaml:"tee" json:"tee"`
5064
// Kind is the kind of ROFL app to build.
@@ -122,6 +136,19 @@ func (m *Manifest) Validate() error {
122136
return fmt.Errorf("malformed version: %w", err)
123137
}
124138

139+
if _, err := url.Parse(m.Repository); err != nil && m.Repository != "" {
140+
return fmt.Errorf("malformed repository URL: %w", err)
141+
}
142+
if _, err := mail.ParseAddress(m.Author); err != nil && m.Author != "" {
143+
return fmt.Errorf("malformed author: %w", err)
144+
}
145+
if _, err := spdxexp.ExtractLicenses(m.License); err != nil && m.License != "" {
146+
return fmt.Errorf("malformed license: %w", err)
147+
}
148+
if _, err := url.Parse(m.Homepage); err != nil && m.Homepage != "" {
149+
return fmt.Errorf("malformed homepage URL: %w", err)
150+
}
151+
125152
switch m.TEE {
126153
case TEETypeSGX, TEETypeTDX:
127154
default:
@@ -154,6 +181,38 @@ func (m *Manifest) Validate() error {
154181
return nil
155182
}
156183

184+
// globalMetadataPrefix is the prefix used for all global metadata.
185+
const globalMetadataPrefix = "net.oasis.rofl."
186+
187+
// GetMetadata derives metadata from the attributes defined in the manifest and combines it with
188+
// the metadata for the specified deployment.
189+
func (m *Manifest) GetMetadata(deployment string) map[string]string {
190+
meta := make(map[string]string)
191+
for _, md := range []struct {
192+
name string
193+
value string
194+
}{
195+
{"name", m.Name},
196+
{"version", m.Version},
197+
{"repository", m.Repository},
198+
{"author", m.Author},
199+
{"license", m.License},
200+
{"homepage", m.Homepage},
201+
{"description", m.Description},
202+
} {
203+
if md.value == "" {
204+
continue
205+
}
206+
meta[globalMetadataPrefix+md.name] = md.value
207+
}
208+
209+
d, ok := m.Deployments[deployment]
210+
if ok {
211+
maps.Copy(meta, d.Metadata)
212+
}
213+
return meta
214+
}
215+
157216
// SourceFileName returns the filename of the manifest file from which the manifest was loaded or
158217
// an empty string in case the filename is not available.
159218
func (m *Manifest) SourceFileName() string {

cmd/rofl/mgmt.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ var (
6666
}
6767

6868
// Create a default manifest without any deployments.
69+
// TODO: Extract author and repository from Git configuration if available.
6970
manifest := buildRofl.Manifest{
7071
Name: appName,
7172
Version: "0.1.0",
@@ -225,8 +226,9 @@ var (
225226

226227
// Prepare transaction.
227228
tx := rofl.NewCreateTx(nil, &rofl.Create{
228-
Policy: *deployment.Policy,
229-
Scheme: idScheme,
229+
Policy: *deployment.Policy,
230+
Scheme: idScheme,
231+
Metadata: manifest.GetMetadata(deploymentName),
230232
})
231233

232234
acc := common.LoadAccount(cfg, npa.AccountName)
@@ -260,7 +262,7 @@ var (
260262
npa := common.GetNPASelection(cfg)
261263
txCfg := common.GetTransactionConfig()
262264

263-
_, deployment := roflCommon.LoadManifestAndSetNPA(cfg, npa, deploymentName, &roflCommon.ManifestOptions{
265+
manifest, deployment := roflCommon.LoadManifestAndSetNPA(cfg, npa, deploymentName, &roflCommon.ManifestOptions{
264266
NeedAppID: true,
265267
NeedAdmin: true,
266268
})
@@ -303,7 +305,7 @@ var (
303305
updateBody := rofl.Update{
304306
ID: appID,
305307
Policy: *deployment.Policy,
306-
Metadata: deployment.Metadata,
308+
Metadata: manifest.GetMetadata(deploymentName),
307309
Secrets: secrets,
308310
}
309311

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ require (
1717
github.com/compose-spec/compose-go/v2 v2.4.8
1818
github.com/ethereum/go-ethereum v1.15.0
1919
github.com/foxboron/go-uefi v0.0.0-20241017190036-fab4fdf2f2f3
20+
github.com/github/go-spdx/v2 v2.3.2
2021
github.com/miguelmota/go-ethereum-hdwallet v0.1.2
2122
github.com/mitchellh/mapstructure v1.5.0
2223
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos
177177
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
178178
github.com/fxamacker/cbor/v2 v2.4.0 h1:ri0ArlOR+5XunOP8CRUowT0pSJOwhW098ZCUyskZD88=
179179
github.com/fxamacker/cbor/v2 v2.4.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo=
180+
github.com/github/go-spdx/v2 v2.3.2 h1:IfdyNHTqzs4zAJjXdVQfRnxt1XMfycXoHBE2Vsm1bjs=
181+
github.com/github/go-spdx/v2 v2.3.2/go.mod h1:2ZxKsOhvBp+OYBDlsGnUMcchLeo2mrpEBn2L1C+U3IQ=
180182
github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY=
181183
github.com/gliderlabs/ssh v0.3.5/go.mod h1:8XB4KraRrX39qHhT6yxPsHedjA08I/uBVwj4xC+/+z4=
182184
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=

0 commit comments

Comments
 (0)