Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into add_pr_template
Browse files Browse the repository at this point in the history
  • Loading branch information
reetasingh committed Aug 27, 2021
2 parents 254325f + 8d3ba22 commit 478877b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion provision/azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func Test_Azure_Auth_Contents_Invalid(t *testing.T) {
_, err := NewAzureProvisioner("SubscriptionID", "invalid contents")

if err == nil {
t.Errorf("want: error, but got: nil")
t.Fatalf("want: error, but got: nil")
}
}

Expand Down
18 changes: 14 additions & 4 deletions provision/linode.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package provision
import (
"context"
"fmt"
"net/http"
"strconv"

"github.com/linode/linodego"
"github.com/sethvargo/go-password/password"
"golang.org/x/oauth2"
"net/http"
"strconv"
)

type LinodeInterface interface {
Expand Down Expand Up @@ -65,6 +66,10 @@ func NewLinodeProvisioner(apiKey string) (*LinodeProvisioner, error) {
// Provision provisions a new Linode instance as an exit node
func (p *LinodeProvisioner) Provision(host BasicHost) (*ProvisionedHost, error) {

if len(host.Name) > 32 {
return nil, fmt.Errorf("name cannot be longer than 32 characters for Linode due to label limitations")
}

// Stack script is how linode does the cloud-init when provisioning a VM.
// Stack script is the inlets user data containing inlets auth token.
// Making stack script public will allow everyone to read the stack script
Expand All @@ -87,8 +92,13 @@ func (p *LinodeProvisioner) Provision(host BasicHost) (*ProvisionedHost, error)
return nil, err
}
instanceOptions := linodego.InstanceCreateOptions{
Label: "inlets-" + host.Name, StackScriptID: stackscript.ID,
Image: host.OS, Region: host.Region, Type: host.Plan, RootPass: rootPassword,
Label: host.Name,
StackScriptID: stackscript.ID,
Image: host.OS,
Region: host.Region,
Type: host.Plan,
RootPass: rootPassword,
Tags: []string{"inlets"},
}
instance, err := p.client.CreateInstance(instanceOptions)
if err != nil {
Expand Down
23 changes: 16 additions & 7 deletions provision/linode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ func Test_Linode_Provision(t *testing.T) {
returnedStackscript := &linodego.Stackscript{ID: 10}

expectedInstanceOptions := linodego.InstanceCreateOptions{
Label: "inlets-" + host.Name, StackScriptID: returnedStackscript.ID,
Image: host.OS, Region: host.Region, Type: host.Plan, RootPass: "testpass",
Label: host.Name,
StackScriptID: returnedStackscript.ID,
Image: host.OS,
Region: host.Region,
Type: host.Plan,
RootPass: "testpass",
Tags: []string{"inlets"},
}

returnedInstance := &linodego.Instance{
ID: 42,
Status: linodego.InstanceBooting,
Expand All @@ -43,19 +49,22 @@ func Test_Linode_Provision(t *testing.T) {
mockClient.EXPECT().CreateInstance(gomock.Any()).Return(returnedInstance, nil).Times(1).
Do(func(instanceOptions linodego.InstanceCreateOptions) {
if instanceOptions.Label != expectedInstanceOptions.Label {
t.Fail()
t.Fatalf("Label didn't match")
}
if instanceOptions.StackScriptID != expectedInstanceOptions.StackScriptID {
t.Fail()
t.Fatalf("StackScriptID didn't match")
}
if instanceOptions.Image != expectedInstanceOptions.Image {
t.Fail()
t.Fatalf("Image didn't match")
}
if instanceOptions.Region != expectedInstanceOptions.Region {
t.Fail()
t.Fatalf("Region didn't match")
}
if instanceOptions.Type != expectedInstanceOptions.Type {
t.Fail()
t.Fatalf("Type didn't match")
}
if len(instanceOptions.Tags) != len(expectedInstanceOptions.Tags) {
t.Fatalf("tags don't match")
}
})
provisionedHost, _ := provisioner.Provision(host)
Expand Down

0 comments on commit 478877b

Please sign in to comment.