-
Notifications
You must be signed in to change notification settings - Fork 0
/
identity.go
32 lines (27 loc) · 816 Bytes
/
identity.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
// Copyright 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package agent
import (
"os"
"github.com/juju/errors"
"github.com/juju/utils/v2"
)
var ErrNoStateServingInfo = errors.New("StateServingInfo missing")
func WriteSystemIdentityFile(c Config) error {
info, ok := c.StateServingInfo()
if !ok {
return errors.Trace(ErrNoStateServingInfo)
}
// Write non-empty contents to the file, otherwise delete it
if info.SystemIdentity != "" {
logger.Infof("writing system identity file")
err := utils.AtomicWriteFile(c.SystemIdentityPath(), []byte(info.SystemIdentity), 0600)
if err != nil {
return errors.Annotate(err, "cannot write system identity")
}
} else {
logger.Infof("removing system identity file")
os.Remove(c.SystemIdentityPath())
}
return nil
}