-
Notifications
You must be signed in to change notification settings - Fork 8
/
instancemd.go
42 lines (33 loc) · 1.1 KB
/
instancemd.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
// 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 metadata
import (
"encoding/json"
"os"
"namespacelabs.dev/foundation/internal/fnerrors"
)
const (
wellKnownMetadataPath = "/var/run/nsc/metadata.json"
)
type InstanceMetadata struct {
Version string `json:"version,omitempty"`
InstanceEndpoint string `json:"instance_endpoint,omitempty"`
Certs struct {
PublicPemPath string `json:"public_pem_path,omitempty"`
PrivateKeyPath string `json:"private_key_path,omitempty"`
HostPublicPemPath string `json:"host_public_pem_path,omitempty"`
} `json:"certs,omitempty"`
}
func InstanceMetadataFromFile() (InstanceMetadata, error) {
var md InstanceMetadata
data, err := os.ReadFile(wellKnownMetadataPath)
if err != nil {
return md, err
}
//XXX check version first, then unmarshal to right struct
if err := json.Unmarshal(data, &md); err != nil {
return md, fnerrors.New("instance metadata is invalid: %w", err)
}
return md, nil
}