MCPcopy
hub / github.com/henrygd/beszel / loadPublicKeys

Method loadPublicKeys

internal/cmd/agent/agent.go:113–135  ·  view source on GitHub ↗

loadPublicKeys loads the public keys from the command line flag, environment variable, or key file.

()

Source from the content-addressed store, hash-verified

111
112// loadPublicKeys loads the public keys from the command line flag, environment variable, or key file.
113func (opts *cmdOptions) loadPublicKeys() ([]ssh.PublicKey, error) {
114 // Try command line flag first
115 if opts.key != "" {
116 return agent.ParseKeys(opts.key)
117 }
118
119 // Try environment variable
120 if key, ok := utils.GetEnv("KEY"); ok && key != "" {
121 return agent.ParseKeys(key)
122 }
123
124 // Try key file
125 keyFile, ok := utils.GetEnv("KEY_FILE")
126 if !ok {
127 return nil, fmt.Errorf("no key provided: must set -key flag, KEY env var, or KEY_FILE env var. Use 'beszel-agent help' for usage")
128 }
129
130 pubKey, err := os.ReadFile(keyFile)
131 if err != nil {
132 return nil, fmt.Errorf("failed to read key file: %w", err)
133 }
134 return agent.ParseKeys(string(pubKey))
135}
136
137func (opts *cmdOptions) getAddress() string {
138 return agent.GetAddress(opts.listen)

Callers 2

mainFunction · 0.95
TestLoadPublicKeysFunction · 0.80

Calls 2

ParseKeysFunction · 0.92
GetEnvFunction · 0.92

Tested by 1

TestLoadPublicKeysFunction · 0.64