working epics ioc and tested
This commit is contained in:
+17
-4
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"os/user"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
@@ -42,11 +42,18 @@ type Config struct {
|
||||
// EPICS_CA_ADDR_LIST — space-separated list of server addresses
|
||||
// EPICS_CA_AUTO_ADDR_LIST — "NO" disables automatic broadcast addresses
|
||||
func ConfigFromEnv() Config {
|
||||
name := filepath.Base(os.Args[0])
|
||||
// CA security ACLs match on the client username, not the program name.
|
||||
// Use the OS username (same as libca), falling back to $USER, then "user".
|
||||
clientName := "user"
|
||||
if u, err := user.Current(); err == nil && u.Username != "" {
|
||||
clientName = u.Username
|
||||
} else if v := os.Getenv("USER"); v != "" {
|
||||
clientName = v
|
||||
}
|
||||
host, _ := os.Hostname()
|
||||
cfg := Config{
|
||||
AutoAddrList: true,
|
||||
ClientName: name,
|
||||
ClientName: clientName,
|
||||
HostName: host,
|
||||
}
|
||||
if v := os.Getenv("EPICS_CA_ADDR_LIST"); v != "" {
|
||||
@@ -103,7 +110,13 @@ func NewClient(ctx context.Context, cfg Config) (*Client, error) {
|
||||
}
|
||||
|
||||
if cfg.ClientName == "" {
|
||||
cfg.ClientName = filepath.Base(os.Args[0])
|
||||
if u, err := user.Current(); err == nil && u.Username != "" {
|
||||
cfg.ClientName = u.Username
|
||||
} else if v := os.Getenv("USER"); v != "" {
|
||||
cfg.ClientName = v
|
||||
} else {
|
||||
cfg.ClientName = "user"
|
||||
}
|
||||
}
|
||||
if cfg.HostName == "" {
|
||||
cfg.HostName, _ = os.Hostname()
|
||||
|
||||
Reference in New Issue
Block a user