Skip to content

Commit 981206f

Browse files
authored
Added support enroll groups and ip, load from agent config. (#92)
1 parent aac1c1b commit 981206f

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

cmd/agent/enrollment.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ func updateEnrollmentRequest(agent *agentClient, cmd *cobra.Command) {
129129
if err != nil {
130130
l.WithError(err).Fatalln("failed to get groups")
131131
}
132+
if len(groups) == 0 && agent.config.IsSet("enroll.groups") {
133+
groups = agent.config.GetStringSlice("enroll.groups", []string{})
134+
}
135+
132136
ip, err := cmd.Flags().GetString("ip")
133137
if err != nil {
134138
l.WithError(err).Fatalln("failed to get ip")
@@ -139,6 +143,16 @@ func updateEnrollmentRequest(agent *agentClient, cmd *cobra.Command) {
139143
os.Exit(1)
140144
}
141145
}
146+
147+
if ip == "" && agent.config.IsSet("enroll.ip") {
148+
ip = agent.config.GetString("enroll.ip", "")
149+
parseIP := net.ParseIP(ip)
150+
if parseIP == nil && ip != "" {
151+
l.WithError(err).Fatalln("ip is of invalid format")
152+
os.Exit(1)
153+
}
154+
}
155+
142156
hostname, err := os.Hostname()
143157
if err != nil {
144158
l.WithError(err).Errorln("error when getting hostname")

cmd/agent/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ type agentClient struct {
120120
l *logrus.Logger
121121
conn *grpc.ClientConn
122122
client protocol.AgentServiceClient
123+
config *conf.C
123124
}
124125

125126
func NewClient(l *logrus.Logger, config *conf.C) (*agentClient, error) {
@@ -186,7 +187,7 @@ func NewClient(l *logrus.Logger, config *conf.C) (*agentClient, error) {
186187

187188
client := protocol.NewAgentServiceClient(conn)
188189

189-
return &agentClient{l, conn, client}, nil
190+
return &agentClient{l, conn, client, config}, nil
190191
}
191192

192193
func (c agentClient) Close() error {

0 commit comments

Comments
 (0)