2019-04-15 17:22:25 -04:00
|
|
|
package linode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
2020-11-09 20:09:32 -05:00
|
|
|
"github.com/hashicorp/packer/builder/linode/version"
|
2019-04-15 17:22:25 -04:00
|
|
|
"github.com/linode/linodego"
|
|
|
|
"golang.org/x/oauth2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newLinodeClient(pat string) linodego.Client {
|
|
|
|
tokenSource := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: pat})
|
|
|
|
|
|
|
|
oauthTransport := &oauth2.Transport{
|
|
|
|
Source: tokenSource,
|
|
|
|
}
|
|
|
|
oauth2Client := &http.Client{
|
|
|
|
Transport: oauthTransport,
|
|
|
|
}
|
|
|
|
|
|
|
|
client := linodego.NewClient(oauth2Client)
|
|
|
|
|
|
|
|
projectURL := "https://www.packer.io"
|
|
|
|
userAgent := fmt.Sprintf("Packer/%s (+%s) linodego/%s",
|
2020-11-09 20:09:32 -05:00
|
|
|
version.LinodePluginVersion.FormattedVersion(), projectURL, linodego.Version)
|
2019-04-15 17:22:25 -04:00
|
|
|
|
|
|
|
client.SetUserAgent(userAgent)
|
|
|
|
return client
|
|
|
|
}
|