Skip to content

Commit 1657499

Browse files
committed
add --linode-ua-prefix argument for "product/ver"
Also updated build to use `git describe` to auto-version
1 parent 6c525c3 commit 1657499

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ endif
1212

1313
.PHONY: build
1414
build: dep
15-
go build -o $(OUT_DIR)/$(PROG)$(BIN_SUFFIX) ./
15+
go build -ldflags "-X github.com/linode/docker-machine-driver-linode/pkg/drivers/linode.VERSION=`git describe --always`" -o $(OUT_DIR)/$(PROG)$(BIN_SUFFIX) ./
1616

1717
.PHONY: dep
1818
dep:

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ docker-machine create -d linode --linode-token=<linode-token> --linode-root-pass
6464
| `linode-stackscript` | `LINODE_STACKSCRIPT` | None | Specifies the Linode StackScript to use to create the instance, either by numeric ID, or using the form *username*/*label*.
6565
| `linode-stackscript-data` | `LINODE_STACKSCRIPT_DATA` | None | A JSON string specifying data that is passed (via UDF) to the selected StackScript.
6666
| `linode-create-private-ip` | `LINODE_CREATE_PRIVATE_IP` | None | A flag specifying to create private IP for the Linode instance.
67+
| `linode-ua-prefix` | `LINODE_UA_PREFIX` | None | Prefix the User-Agent in Linode API calls with some 'product/version'
68+
69+
## Notes
70+
71+
* When using the `linode/containerlinux` `linode-image`, the `linode-ssh-user` will default to `core`
6772

6873
## Debugging
6974

pkg/drivers/linode/linode.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type Driver struct {
2626
client *linodego.Client
2727

2828
APIToken string
29+
UserAgentPrefix string
2930
IPAddress string
3031
PrivateIPAddress string
3132
CreatePrivateIP bool
@@ -48,9 +49,12 @@ type Driver struct {
4849
StackScriptData map[string]string
4950
}
5051

51-
const (
52+
var (
5253
// VERSION represents the semver version of the package
53-
VERSION = "0.0.13"
54+
VERSION = "devel"
55+
)
56+
57+
const (
5458
defaultSSHPort = 22
5559
defaultSSHUser = "root"
5660
defaultInstanceImage = "linode/ubuntu18.04"
@@ -88,8 +92,14 @@ func (d *Driver) getClient() *linodego.Client {
8892
},
8993
}
9094

95+
ua := fmt.Sprintf("docker-machine-driver-%s/%s linodego/%s", d.DriverName(), VERSION, linodego.Version)
96+
9197
client := linodego.NewClient(oauth2Client)
92-
client.SetUserAgent(fmt.Sprintf("docker-machine-driver-%s/v%s linodego/%s", d.DriverName(), VERSION, linodego.Version))
98+
if len(d.UserAgentPrefix) > 0 {
99+
ua = fmt.Sprintf("%s %s", d.UserAgentPrefix, ua)
100+
}
101+
102+
client.SetUserAgent(ua)
93103
client.SetDebug(true)
94104
d.client = &client
95105
}
@@ -201,6 +211,11 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
201211
Name: "linode-create-private-ip",
202212
Usage: "Create private IP for the instance",
203213
},
214+
mcnflag.StringFlag{
215+
EnvVar: "LINODE_UA_PREFIX",
216+
Name: "linode-ua-prefix",
217+
Usage: fmt.Sprintf("Prefix the User-Agent in Linode API calls with some 'product/version'"),
218+
},
204219
}
205220
}
206221

@@ -241,6 +256,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
241256
d.SwapSize = flags.Int("linode-swap-size")
242257
d.DockerPort = flags.Int("linode-docker-port")
243258
d.CreatePrivateIP = flags.Bool("linode-create-private-ip")
259+
d.UserAgentPrefix = flags.String("linode-ua-prefix")
244260

245261
d.SetSwarmConfigFromFlags(flags)
246262

0 commit comments

Comments
 (0)