-
Notifications
You must be signed in to change notification settings - Fork 9
/
secretserialization.go
43 lines (33 loc) · 1.04 KB
/
secretserialization.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
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package secrets
import (
"path/filepath"
"google.golang.org/protobuf/encoding/protojson"
"namespacelabs.dev/foundation/framework/kubernetes/kubenaming"
runtimepb "namespacelabs.dev/foundation/library/runtime"
"namespacelabs.dev/foundation/schema"
)
const SecretBaseMountPath = "/namespace/secrets"
type Serialized struct {
RelPath string
JSON []byte
}
func RelPath(res *schema.PackageRef) string {
return kubenaming.DomainFragLike(res.PackageName, res.Name)
}
func Serialize(res *schema.PackageRef) (*Serialized, error) {
relPath := RelPath(res)
instance := &runtimepb.SecretInstance{
Path: filepath.Join(SecretBaseMountPath, relPath),
}
serializedInstance, err := protojson.MarshalOptions{UseProtoNames: true}.Marshal(instance)
if err != nil {
return nil, err
}
return &Serialized{
RelPath: relPath,
JSON: serializedInstance,
}, nil
}