-
Notifications
You must be signed in to change notification settings - Fork 63
/
transform.go
57 lines (47 loc) · 1.27 KB
/
transform.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors.
// Licensed under the BSD-3-Clause License (the "License").
// You may not use this file except in compliance with the License.
package volume
import (
"context"
"fmt"
"strings"
)
// TransformFromSchema parses an input schema and returns an instantiated
// VolumeConfig
func TransformFromSchema(ctx context.Context, data interface{}) (interface{}, error) {
volume := VolumeConfig{}
switch entry := data.(type) {
case string:
var split []string
if strings.Contains(entry, ":") {
split = strings.Split(entry, ":")
if len(split) > 2 {
return nil, fmt.Errorf("expected format template value to be <url>@<version>")
}
volume.source = split[0]
if len(split) == 2 {
volume.destination = split[1]
}
} else {
// When no colon is specified, assume the root file system
volume.source = entry
volume.destination = "/"
}
case map[string]interface{}:
for key, prop := range entry {
switch key {
case "driver":
volume.driver = prop.(string)
case "source":
volume.source = prop.(string)
case "destination":
volume.destination = prop.(string)
case "readonly":
volume.readOnly = prop.(bool)
}
}
}
return volume, nil
}