Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v1.5.7 #272

Merged
merged 4 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
uses: actions/checkout@v4
-
name: Run Labeler
uses: crazy-max/ghaction-github-labeler@de749cf181958193cb7debf1a9c5bb28922f3e1b
uses: crazy-max/ghaction-github-labeler@b54af0c25861143e7c8813d7cbbf46d2c341680c
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
yaml-file: .github/labels.yml
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/release-notify-slack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Notify Dev DX Channel on Release
on:
release:
types: [published]
workflow_dispatch: null

jobs:
notify:
if: github.repository == 'linode/packer-plugin-linode'
runs-on: ubuntu-latest
steps:
- name: Notify Slack - Main Message
id: main_message
uses: slackapi/slack-github-action@v1.27.0
with:
channel-id: ${{ secrets.DEV_DX_SLACK_CHANNEL_ID }}
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*New Release Published: _packer-plugin-linode_ <${{ github.event.release.html_url }}|${{ github.event.release.tag_name }}> is now live!* :tada:"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
3 changes: 3 additions & 0 deletions .web-docs/components/builder/linode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ can also be supplied to override the typical auto-generated key:
`images:read_write`, `linodes:read_write`, and `events:read_only`
scopes are required for the API token.

- `api_ca_path` (string) - The path to a CA file to trust when making API requests.
It can also be specified using the `LINODE_CA` environment variable.

<!-- End of code generated from the comments of the LinodeCommon struct in helper/common.go; -->

<!-- Code generated from the comments of the Config struct in builder/linode/config.go; DO NOT EDIT MANUALLY -->
Expand Down
3 changes: 3 additions & 0 deletions .web-docs/components/data-source/image/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ data "linode-image" "ubuntu22_lts" {
`images:read_write`, `linodes:read_write`, and `events:read_only`
scopes are required for the API token.

- `api_ca_path` (string) - The path to a CA file to trust when making API requests.
It can also be specified using the `LINODE_CA` environment variable.

<!-- End of code generated from the comments of the LinodeCommon struct in helper/common.go; -->


Expand Down
12 changes: 10 additions & 2 deletions builder/linode/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,16 @@ func (b *Builder) Prepare(raws ...any) ([]string, []string, error) {

func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook) (ret packersdk.Artifact, err error) {
ui.Say("Running builder ...")
var client *linodego.Client

client := helper.NewLinodeClient(b.config.PersonalAccessToken)
if b.config.APICAPath != "" {
client, err = helper.NewLinodeClientWithCA(b.config.PersonalAccessToken, b.config.APICAPath)
if err != nil {
return nil, err
}
} else {
client = helper.NewLinodeClient(b.config.PersonalAccessToken)
}

state := new(multistep.BasicStateBag)
state.Put("config", &b.config)
Expand Down Expand Up @@ -90,7 +98,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
artifact := Artifact{
ImageLabel: image.Label,
ImageID: image.ID,
Driver: &client,
Driver: client,
StateData: map[string]any{
"generated_data": state.Get("generated_data"),
"source_image": b.config.Image,
Expand Down
4 changes: 4 additions & 0 deletions builder/linode/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ func (c *Config) Prepare(raws ...any) ([]string, error) {
c.PersonalAccessToken = os.Getenv("LINODE_TOKEN")
}

if c.APICAPath == "" {
c.APICAPath = os.Getenv("LINODE_CA")
}

if c.ImageLabel == "" {
if def, err := interpolate.Render("packer-{{timestamp}}", nil); err == nil {
c.ImageLabel = def
Expand Down
2 changes: 2 additions & 0 deletions builder/linode/config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion builder/linode/step_create_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

type stepCreateImage struct {
client linodego.Client
client *linodego.Client
}

func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
Expand Down
2 changes: 1 addition & 1 deletion builder/linode/step_create_linode.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

type stepCreateLinode struct {
client linodego.Client
client *linodego.Client
}

func flattenConfigInterfaceIPv4(i *InterfaceIPv4) *linodego.VPCIPv4 {
Expand Down
2 changes: 1 addition & 1 deletion builder/linode/step_shutdown_linode.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

type stepShutdownLinode struct {
client linodego.Client
client *linodego.Client
}

func (s *stepShutdownLinode) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
Expand Down
12 changes: 11 additions & 1 deletion datasource/image/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,17 @@ func (d *Datasource) OutputSpec() hcldec.ObjectSpec {
}

func (d *Datasource) Execute() (cty.Value, error) {
client := helper.NewLinodeClient(d.config.PersonalAccessToken)
var client *linodego.Client
var err error

if d.config.APICAPath != "" {
client, err = helper.NewLinodeClientWithCA(d.config.PersonalAccessToken, d.config.APICAPath)
if err != nil {
return cty.NullVal(cty.EmptyObject), err
}
} else {
client = helper.NewLinodeClient(d.config.PersonalAccessToken)
}

filters := linodego.Filter{}

Expand Down
2 changes: 2 additions & 0 deletions datasource/image/data.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.22.5
require (
github.com/hashicorp/hcl/v2 v2.22.0
github.com/hashicorp/packer-plugin-sdk v0.5.4
github.com/linode/linodego v1.41.0
github.com/linode/linodego v1.42.0
github.com/mitchellh/mapstructure v1.5.0
github.com/zclconf/go-cty v1.13.3
golang.org/x/crypto v0.28.0
Expand Down Expand Up @@ -84,7 +84,7 @@ require (
go.opencensus.io v0.24.0 // indirect
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/term v0.25.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/linode/linodego v1.41.0 h1:GcP7JIBr9iLRJ9FwAtb9/WCT1DuPJS/xUApapfdjtiY=
github.com/linode/linodego v1.41.0/go.mod h1:Ow4/XZ0yvWBzt3iAHwchvhSx30AyLintsSMvvQ2/SJY=
github.com/linode/linodego v1.42.0 h1:ZSbi4MtvwrfB9Y6bknesorvvueBGGilcmh2D5dq76RM=
github.com/linode/linodego v1.42.0/go.mod h1:2yzmY6pegPBDgx2HDllmt0eIk2IlzqcgK6NR0wFCFRY=
github.com/masterzen/simplexml v0.0.0-20160608183007-4572e39b1ab9/go.mod h1:kCEbxUJlNDEBNbdQMkPSp6yaKcRXVI6f4ddk8Riv4bc=
github.com/masterzen/simplexml v0.0.0-20190410153822-31eea3082786 h1:2ZKn+w/BJeL43sCxI2jhPLRv73oVVOjEKZjKkflyqxg=
github.com/masterzen/simplexml v0.0.0-20190410153822-31eea3082786/go.mod h1:kCEbxUJlNDEBNbdQMkPSp6yaKcRXVI6f4ddk8Riv4bc=
Expand Down Expand Up @@ -373,8 +373,8 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
Expand Down
61 changes: 55 additions & 6 deletions helper/client.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package helper

import (
"crypto/tls"
"crypto/x509"
"fmt"
"net/http"
"os"
"path/filepath"

"github.com/linode/linodego"
"github.com/linode/packer-plugin-linode/version"
Expand All @@ -11,14 +15,31 @@ import (

const TokenEnvVar = "LINODE_TOKEN"

func NewLinodeClient(token string) linodego.Client {
tokenSource := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})
// AddRootCAToTransport applies the CA at the given path to the given *http.Transport
func AddRootCAToTransport(CAPath string, transport *http.Transport) error {
CAData, err := os.ReadFile(filepath.Clean(CAPath))
if err != nil {
return fmt.Errorf("failed to read CA file %s: %w", CAPath, err)
}

oauthTransport := &oauth2.Transport{
Source: tokenSource,
if transport.TLSClientConfig == nil {
transport.TLSClientConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
}
}

if transport.TLSClientConfig.RootCAs == nil {
transport.TLSClientConfig.RootCAs = x509.NewCertPool()
}

transport.TLSClientConfig.RootCAs.AppendCertsFromPEM(CAData)

return nil
}

func linodeClientFromTransport(transport http.RoundTripper) *linodego.Client {
oauth2Client := &http.Client{
Transport: oauthTransport,
Transport: transport,
}

client := linodego.NewClient(oauth2Client)
Expand All @@ -28,5 +49,33 @@ func NewLinodeClient(token string) linodego.Client {
version.PluginVersion.FormattedVersion(), projectURL, linodego.Version)

client.SetUserAgent(userAgent)
return client
return &client
}

func getDefaultTransportWithCA(CAPath string) (*http.Transport, error) {
httpTransport := http.DefaultTransport.(*http.Transport).Clone()
return httpTransport, AddRootCAToTransport(CAPath, httpTransport)
}

func getOauth2TransportWithToken(token string, baseTransport http.RoundTripper) *oauth2.Transport {
tokenSource := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})
oauthTransport := &oauth2.Transport{
Source: tokenSource,
Base: baseTransport,
}
return oauthTransport
}

func NewLinodeClient(token string) *linodego.Client {
oauthTransport := getOauth2TransportWithToken(token, nil)
return linodeClientFromTransport(oauthTransport)
}

func NewLinodeClientWithCA(token, CAPath string) (*linodego.Client, error) {
transport, err := getDefaultTransportWithCA(CAPath)
if err != nil {
return nil, err
}
oauthTransport := getOauth2TransportWithToken(token, transport)
return linodeClientFromTransport(oauthTransport), nil
}
4 changes: 4 additions & 0 deletions helper/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ type LinodeCommon struct {
// `images:read_write`, `linodes:read_write`, and `events:read_only`
// scopes are required for the API token.
PersonalAccessToken string `mapstructure:"linode_token"`

// The path to a CA file to trust when making API requests.
// It can also be specified using the `LINODE_CA` environment variable.
APICAPath string `mapstructure:"api_ca_path"`
}
Loading