-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add parameterized provider support to YAML
- Loading branch information
Showing
22 changed files
with
1,348 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright 2024, Pulumi Corporation. All rights reserved. | ||
|
||
// Package packages contains utilities for working with Pulumi package lock files. | ||
package packages | ||
|
||
import ( | ||
"encoding/base64" | ||
"fmt" | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
|
||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
type ParameterizationLock struct { | ||
// Name is the name of the parameterized package. | ||
Name string `yaml:"name"` | ||
// Version is the version of the parameterized package. | ||
Version string `yaml:"version"` | ||
// Value is the value of the parameter. Value is a base64 encoded byte array, use SetValue and GetValue to manipulate the actual value. | ||
Value string `yaml:"value"` | ||
} | ||
|
||
func (p *ParameterizationLock) GetValue() ([]byte, error) { | ||
return base64.StdEncoding.DecodeString(p.Value) | ||
} | ||
|
||
func (p *ParameterizationLock) SetValue(value []byte) { | ||
p.Value = base64.StdEncoding.EncodeToString(value) | ||
} | ||
|
||
type PackageLock struct { | ||
// Name is the name of the plugin. | ||
Name string `yaml:"name"` | ||
// Version is the version of the plugin. | ||
Version string `yaml:"version,omitempty"` | ||
// PluginDownloadURL is the URL to download the plugin from. | ||
DownloadURL string `yaml:"downloadUrl,omitempty"` | ||
// Parameterization is the parameterization of the package. | ||
Parameterization *ParameterizationLock `yaml:"parameterization,omitempty"` | ||
} | ||
|
||
func (p *PackageLock) Valid() bool { | ||
// All packages need a name | ||
if p.Name == "" { | ||
return false | ||
} | ||
|
||
// If parameterization is not nil, it must be valid. | ||
if p.Parameterization != nil { | ||
return p.Parameterization.Name != "" && p.Parameterization.Version != "" | ||
} | ||
|
||
return true | ||
} | ||
|
||
// SearchPackageLocks searches the given directory down recursively for package lock .yaml files. | ||
func SearchPackageLocks(directory string) ([]PackageLock, error) { | ||
var packages []PackageLock | ||
err := filepath.WalkDir(directory, func(path string, d fs.DirEntry, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// If the file is a directory, skip it. | ||
if d.IsDir() { | ||
return nil | ||
} | ||
|
||
// If the file is not a .yaml file, skip it. | ||
if filepath.Ext(path) != ".yaml" { | ||
return nil | ||
} | ||
|
||
// Read the file. | ||
data, err := os.ReadFile(path) | ||
if err != nil { | ||
return fmt.Errorf("reading %s: %w", path, err) | ||
} | ||
|
||
var packageLock PackageLock | ||
if err := yaml.Unmarshal(data, &packageLock); err != nil { | ||
return fmt.Errorf("unmarshalling %s: %w", path, err) | ||
} | ||
|
||
// If the file is not valid skip it | ||
if !packageLock.Valid() { | ||
return nil | ||
} | ||
|
||
// Else append it to the list of packages found. | ||
packages = append(packages, packageLock) | ||
return nil | ||
}) | ||
return packages, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2024, Pulumi Corporation. All rights reserved. | ||
|
||
package packages | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSearchPackageLocks(t *testing.T) { | ||
t.Parallel() | ||
|
||
expected := []PackageLock{ | ||
{ | ||
Name: "pkg", | ||
}, | ||
{ | ||
Name: "pkg2", | ||
Version: "1.2", | ||
DownloadURL: "github://api.github.com/pulumiverse", | ||
}, | ||
{ | ||
Name: "base", | ||
Parameterization: &ParameterizationLock{ | ||
Name: "pkg", | ||
Version: "1.0.0", | ||
Value: "cGtn", | ||
}, | ||
}, | ||
} | ||
|
||
actual, err := SearchPackageLocks("testdata") | ||
require.NoError(t, err) | ||
require.ElementsMatch(t, expected, actual) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# no name so this is invalid | ||
version: 1.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name: pkg | ||
parameterization: | ||
name: pkg | ||
# no version so this is invalid | ||
value: cGtn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
name: pkg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name: base | ||
parameterization: | ||
name: pkg | ||
version: 1.0.0 | ||
value: cGtn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: pkg2 | ||
version: 1.2 | ||
downloadUrl: github://api.github.com/pulumiverse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name: parameterized | ||
description: An integration test showing the use of a parameterized package | ||
runtime: yaml | ||
resources: | ||
res1: | ||
type: pkg:index:Random | ||
res2: | ||
type: pkg:index:Echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name: testprovider | ||
version: 0.0.1 | ||
parameterization: | ||
name: pkg | ||
version: 1.0.0 | ||
value: cGtn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pulumi-resource-testprovider | ||
schema-testprovider.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
runtime: go |
Oops, something went wrong.