Skip to content

Commit 98524c3

Browse files
committed
pkg/cdi: unexport spec.Write(), NewSpec().
This should reduce confusion about how generates Specs should be written (cache.WriteSpec() vs. spec.Write()) and also reduce the possibility/temptation for users to bypass the registry/cache when interacting with Specs. Signed-off-by: Krisztian Litkey <[email protected]>
1 parent 7c8505c commit 98524c3

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

pkg/cdi/cache.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,12 @@ func (c *Cache) WriteSpec(raw *cdi.Spec, name string) error {
294294
path += defaultSpecExt
295295
}
296296

297-
spec, err = NewSpec(raw, path, prio)
297+
spec, err = newSpec(raw, path, prio)
298298
if err != nil {
299299
return err
300300
}
301301

302-
return spec.Write(true)
302+
return spec.write(true)
303303
}
304304

305305
// RemoveSpec removes a Spec with the given name from the highest

pkg/cdi/spec.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,19 @@ func ReadSpec(path string, priority int) (*Spec, error) {
8686
return nil, errors.Errorf("failed to parse CDI Spec %q, no Spec data", path)
8787
}
8888

89-
spec, err := NewSpec(raw, path, priority)
89+
spec, err := newSpec(raw, path, priority)
9090
if err != nil {
9191
return nil, err
9292
}
9393

9494
return spec, nil
9595
}
9696

97-
// NewSpec creates a new Spec from the given CDI Spec data. The
97+
// newSpec creates a new Spec from the given CDI Spec data. The
9898
// Spec is marked as loaded from the given path with the given
99-
// priority. If Spec data validation fails NewSpec returns a nil
99+
// priority. If Spec data validation fails newSpec returns a nil
100100
// Spec and an error.
101-
func NewSpec(raw *cdi.Spec, path string, priority int) (*Spec, error) {
101+
func newSpec(raw *cdi.Spec, path string, priority int) (*Spec, error) {
102102
err := validateSpec(raw)
103103
if err != nil {
104104
return nil, err
@@ -124,8 +124,8 @@ func NewSpec(raw *cdi.Spec, path string, priority int) (*Spec, error) {
124124
}
125125

126126
// Write the CDI Spec to the file associated with it during instantiation
127-
// by NewSpec() or ReadSpec().
128-
func (s *Spec) Write(overwrite bool) error {
127+
// by newSpec() or ReadSpec().
128+
func (s *Spec) write(overwrite bool) error {
129129
var (
130130
data []byte
131131
dir string
@@ -259,7 +259,7 @@ func ParseSpec(data []byte) (*cdi.Spec, error) {
259259

260260
// SetSpecValidator sets a CDI Spec validator function. This function
261261
// is used for extra CDI Spec content validation whenever a Spec file
262-
// loaded (using ReadSpec() or NewSpec()) or written (Spec.Write()).
262+
// loaded (using ReadSpec() or written (using WriteSpec()).
263263
func SetSpecValidator(fn func(*cdi.Spec) error) {
264264
validatorLock.Lock()
265265
defer validatorLock.Unlock()

pkg/cdi/spec_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ devices:
246246
}
247247
require.NoError(t, err)
248248

249-
spec, err = NewSpec(raw, tc.name, 0)
249+
spec, err = newSpec(raw, tc.name, 0)
250250
if tc.invalid || tc.schemaFail {
251251
require.Error(t, err)
252252
require.Nil(t, spec)
@@ -367,22 +367,22 @@ devices:
367367
err = yaml.Unmarshal([]byte(tc.data), raw)
368368
require.NoError(t, err)
369369

370-
spec, err = NewSpec(raw, filepath.Join(dir, tc.name), 0)
370+
spec, err = newSpec(raw, filepath.Join(dir, tc.name), 0)
371371
if tc.invalid {
372-
require.Error(t, err, "NewSpec with invalid data")
373-
require.Nil(t, spec, "NewSpec with invalid data")
372+
require.Error(t, err, "newSpec with invalid data")
373+
require.Nil(t, spec, "newSpec with invalid data")
374374
return
375375
}
376376

377377
require.NoError(t, err)
378378
require.NotNil(t, spec)
379379

380-
err = spec.Write(true)
380+
err = spec.write(true)
381381
require.NoError(t, err)
382382
_, err = os.Stat(spec.GetPath())
383383
require.NoError(t, err, "spec.Write destination file")
384384

385-
err = spec.Write(false)
385+
err = spec.write(false)
386386
require.Error(t, err)
387387

388388
chk, err = ReadSpec(spec.GetPath(), spec.GetPriority())

0 commit comments

Comments
 (0)