-
Notifications
You must be signed in to change notification settings - Fork 1
/
domains.go
52 lines (38 loc) · 1.06 KB
/
domains.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
package pass1
import (
"fmt"
"github.com/taubyte/tcc/object"
"github.com/taubyte/tcc/taubyte/v1/utils"
)
type domains struct{}
func Domains() object.Transformer[object.Refrence] {
return &domains{}
}
func (a *domains) Process(ct object.Context, o object.Object[object.Refrence]) (object.Object[object.Refrence], error) {
os, err := o.Child("domains").Object()
if err != nil {
if err == object.ErrNotExist {
return o, nil
}
return nil, fmt.Errorf("fetching domains failed with %w", err)
}
for _, ch := range os.Children() {
sel := os.Child(ch)
// TODO: need to read the files
sel.Move("certificate-data", "cert-file")
sel.Move("certificate-key", "key-file")
sel.Move("certificate-type", "cert-type")
id, err := sel.Get("id")
if err != nil {
return nil, fmt.Errorf("fetching id failed with %w", err)
}
sel.Set("name", ch)
sel.Delete("id")
sel.Rename(id.(string))
err = utils.IndexById(ct, "domains", ch, id.(string))
if err != nil {
return nil, fmt.Errorf("indexing domain %s failed with %w", ch, err)
}
}
return o, nil
}