ability to provide secret to agent and generate token
This commit is contained in:
parent
771a6b7bbd
commit
5b1748aafd
2 changed files with 18 additions and 3 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/drone/drone/client"
|
"github.com/drone/drone/client"
|
||||||
|
"github.com/drone/drone/shared/token"
|
||||||
"github.com/samalba/dockerclient"
|
"github.com/samalba/dockerclient"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
|
@ -69,6 +70,11 @@ var AgentCmd = cli.Command{
|
||||||
Name: "drone-token",
|
Name: "drone-token",
|
||||||
Usage: "drone authorization token",
|
Usage: "drone authorization token",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
EnvVar: "DRONE_SECRET,DRONE_AGENT_SECRET",
|
||||||
|
Name: "drone-secret",
|
||||||
|
Usage: "drone agent secret",
|
||||||
|
},
|
||||||
cli.DurationFlag{
|
cli.DurationFlag{
|
||||||
EnvVar: "DRONE_BACKOFF",
|
EnvVar: "DRONE_BACKOFF",
|
||||||
Name: "backoff",
|
Name: "backoff",
|
||||||
|
@ -133,14 +139,23 @@ func start(c *cli.Context) {
|
||||||
} else {
|
} else {
|
||||||
logrus.SetLevel(logrus.WarnLevel)
|
logrus.SetLevel(logrus.WarnLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var accessToken string
|
||||||
|
if c.String("drone-secret") != "" {
|
||||||
|
secretToken := c.String("drone-secret")
|
||||||
|
accessToken, _ = token.New(token.AgentToken, "").Sign(secretToken)
|
||||||
|
} else {
|
||||||
|
accessToken = c.String("drone-token")
|
||||||
|
}
|
||||||
|
|
||||||
logrus.Infof("Connecting to %s with token %s",
|
logrus.Infof("Connecting to %s with token %s",
|
||||||
c.String("drone-server"),
|
c.String("drone-server"),
|
||||||
c.String("drone-token"),
|
accessToken,
|
||||||
)
|
)
|
||||||
|
|
||||||
client := client.NewClientToken(
|
client := client.NewClientToken(
|
||||||
c.String("drone-server"),
|
c.String("drone-server"),
|
||||||
c.String("drone-token"),
|
accessToken,
|
||||||
)
|
)
|
||||||
|
|
||||||
tls, err := dockerclient.TLSConfigFromCertPath(c.String("docker-cert-path"))
|
tls, err := dockerclient.TLSConfigFromCertPath(c.String("docker-cert-path"))
|
||||||
|
|
|
@ -72,7 +72,7 @@ var serverCmd = cli.Command{
|
||||||
Value: time.Minute * 15,
|
Value: time.Minute * 15,
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
EnvVar: "DRONE_AGENT_SECRET",
|
EnvVar: "DRONE_AGENT_SECRET,DRONE_SECRET",
|
||||||
Name: "agent-secret",
|
Name: "agent-secret",
|
||||||
Usage: "agent secret passcode",
|
Usage: "agent secret passcode",
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue