Add --timings phase logs and named-env deploys #3
+25
-36
@@ -218,6 +218,10 @@ func (d *Deployer) Sources() []*Source {
|
||||
// Deploy builds every environment, or only those named by env or branch; a named deploy skips purge and GC but unmarks what it swaps in.
|
||||
func (d *Deployer) Deploy(ctx context.Context, only []string, modules bool) error {
|
||||
ctx, end := d.phase(ctx, "run")
|
||||
want := map[string]bool{}
|
||||
for _, e := range only {
|
||||
want[e] = true
|
||||
}
|
||||
d.mu.Lock()
|
||||
clear(d.skips)
|
||||
clear(d.counts)
|
||||
@@ -226,11 +230,11 @@ func (d *Deployer) Deploy(ctx context.Context, only []string, modules bool) erro
|
||||
found := map[string]bool{}
|
||||
var errs []error
|
||||
for _, s := range d.Sources() {
|
||||
if err := d.deploySource(ctx, s, only, found, modules); err != nil {
|
||||
if err := d.deploySource(ctx, s, want, found, modules); err != nil {
|
||||
errs = append(errs, fmt.Errorf("source %s: %w", s.Name, err))
|
||||
}
|
||||
}
|
||||
for _, e := range only {
|
||||
for e := range want {
|
||||
if !found[e] {
|
||||
errs = append(errs, fmt.Errorf("environment %s not found", e))
|
||||
}
|
||||
@@ -261,17 +265,10 @@ func (d *Deployer) count(outcome string) {
|
||||
d.mu.Unlock()
|
||||
}
|
||||
|
||||
// Matches reports whether arg names env, either directly or as a branch that sanitises to it.
|
||||
func (s *Source) Matches(arg, env string) bool {
|
||||
n, _, err := s.EnvName(arg)
|
||||
return arg == env || err == nil && n == env
|
||||
}
|
||||
type envRef struct{ branch, sha string }
|
||||
|
||||
// Environments maps env name -> sha for every branch, or only the branches only names.
|
||||
func (d *Deployer) Environments(ctx context.Context, s *Source, only ...string) (map[string]string, []error) {
|
||||
wanted := func(branch, name string) bool {
|
||||
return len(only) == 0 || slices.ContainsFunc(only, func(a string) bool { return a == branch || name != "" && s.Matches(a, name) })
|
||||
}
|
||||
// Environments maps env name -> branch and sha for every branch, or only those want names by branch or env.
|
||||
func (d *Deployer) Environments(ctx context.Context, s *Source, want map[string]bool) (map[string]envRef, []error) {
|
||||
all, err := d.branches(ctx, d.srcMirror(s))
|
||||
if err != nil {
|
||||
return nil, []error{err}
|
||||
@@ -281,14 +278,14 @@ func (d *Deployer) Environments(ctx context.Context, s *Source, only ...string)
|
||||
names = append(names, b)
|
||||
}
|
||||
sort.Strings(names)
|
||||
envs := map[string]string{}
|
||||
envs := map[string]envRef{}
|
||||
var errs []error
|
||||
for _, b := range names {
|
||||
if s.Ignored(b) {
|
||||
continue
|
||||
}
|
||||
name, corrected, err := s.EnvName(b)
|
||||
if !wanted(b, name) {
|
||||
if len(want) > 0 && !want[b] && (name == "" || !want[name]) {
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
@@ -302,12 +299,12 @@ func (d *Deployer) Environments(ctx context.Context, s *Source, only ...string)
|
||||
errs = append(errs, fmt.Errorf("branch %s collides with environment %s, skipped", b, name))
|
||||
continue
|
||||
}
|
||||
envs[name] = all[b]
|
||||
envs[name] = envRef{b, all[b]}
|
||||
}
|
||||
return envs, errs
|
||||
}
|
||||
|
||||
func (d *Deployer) deploySource(ctx context.Context, s *Source, only []string, found map[string]bool, modules bool) error {
|
||||
func (d *Deployer) deploySource(ctx context.Context, s *Source, want, found map[string]bool, modules bool) error {
|
||||
fctx, end := d.phase(ctx, "source.fetch", "source", s.Name)
|
||||
err := d.syncMirror(fctx, d.srcMirror(s), s.Remote, nil, envRefspecs)
|
||||
end()
|
||||
@@ -315,30 +312,24 @@ func (d *Deployer) deploySource(ctx context.Context, s *Source, only []string, f
|
||||
return err
|
||||
}
|
||||
bctx, end := d.phase(ctx, "source.branches", "source", s.Name)
|
||||
envs, errs := d.Environments(bctx, s, only...)
|
||||
envs, errs := d.Environments(bctx, s, want)
|
||||
end("envs", len(envs))
|
||||
if envs == nil {
|
||||
return errors.Join(errs...)
|
||||
}
|
||||
for name := range envs {
|
||||
for _, a := range only {
|
||||
if s.Matches(a, name) {
|
||||
found[a] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := os.MkdirAll(s.Basedir, 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
var mu sync.Mutex
|
||||
var wg sync.WaitGroup
|
||||
for name, sha := range envs {
|
||||
for name, ref := range envs {
|
||||
found[name], found[ref.branch] = true, true
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
err := func() (err error) {
|
||||
defer recoverErr(&err, "environment "+name)
|
||||
return d.deployEnv(ctx, s, name, sha, modules)
|
||||
return d.deployEnv(ctx, s, name, ref, modules)
|
||||
}()
|
||||
if err != nil {
|
||||
mu.Lock()
|
||||
@@ -348,7 +339,7 @@ func (d *Deployer) deploySource(ctx context.Context, s *Source, only []string, f
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
if len(only) == 0 {
|
||||
if len(want) == 0 {
|
||||
errs = append(errs, d.purge(s, envs))
|
||||
}
|
||||
return errors.Join(errs...)
|
||||
@@ -380,7 +371,8 @@ func (d *Deployer) worktreePrefix(sha string) string {
|
||||
return sha + "-"
|
||||
}
|
||||
|
||||
func (d *Deployer) deployEnv(ctx context.Context, s *Source, name, sha string, modules bool) (err error) {
|
||||
func (d *Deployer) deployEnv(ctx context.Context, s *Source, name string, ref envRef, modules bool) (err error) {
|
||||
sha := ref.sha
|
||||
start := time.Now()
|
||||
ctx, total := d.phase(ctx, "env.total", "source", s.Name, "env", name)
|
||||
outcome := "unchanged"
|
||||
@@ -429,7 +421,7 @@ func (d *Deployer) deployEnv(ctx context.Context, s *Source, name, sha string, m
|
||||
if err := d.checkout(ctx, s, sha, target, mods); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return d.prepare(ctx, s, name, sha, checksum, target, mods, started)
|
||||
return d.prepare(ctx, s, name, ref, checksum, target, mods, started)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -662,7 +654,7 @@ func linkModule(root *os.Root, rel, dir string) error {
|
||||
}
|
||||
|
||||
// prepare runs last before a worktree can be swapped in; its out-of-tree done file marks the worktree complete.
|
||||
func (d *Deployer) prepare(ctx context.Context, s *Source, name, sha, checksum, target string, mods []resolved, started time.Time) (string, error) {
|
||||
func (d *Deployer) prepare(ctx context.Context, s *Source, name string, ref envRef, checksum, target string, mods []resolved, started time.Time) (string, error) {
|
||||
var skipped []error
|
||||
if d.cfg.W10k.GenerateTypes {
|
||||
_, end := d.phase(ctx, "env.generate_types")
|
||||
@@ -679,8 +671,8 @@ func (d *Deployer) prepare(ctx context.Context, s *Source, name, sha, checksum,
|
||||
_, end := d.phase(ctx, "env.marker")
|
||||
defer end()
|
||||
r := deployResult{
|
||||
Name: name,
|
||||
Signature: sha,
|
||||
Name: ref.branch,
|
||||
Signature: ref.sha,
|
||||
StartedAt: started,
|
||||
FinishedAt: d.now().UTC(),
|
||||
DeploySuccess: true,
|
||||
@@ -756,7 +748,7 @@ func Swap(target, link string) error {
|
||||
return os.Rename(tmp, link)
|
||||
}
|
||||
|
||||
func (d *Deployer) purge(s *Source, envs map[string]string) error {
|
||||
func (d *Deployer) purge(s *Source, envs map[string]envRef) error {
|
||||
entries, err := os.ReadDir(s.Basedir)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -901,9 +893,6 @@ func (d *Deployer) GC(ctx context.Context) error {
|
||||
liveMod, err := d.moduleRefs(liveEnv)
|
||||
if err != nil {
|
||||
g.errs = append(g.errs, err)
|
||||
for p := range g.marks {
|
||||
g.seen[p] = true
|
||||
}
|
||||
} else {
|
||||
keys, _ := os.ReadDir(d.path("modules"))
|
||||
for _, k := range keys {
|
||||
|
||||
@@ -628,7 +628,7 @@ func TestGenerateTypesBeforeSwap(t *testing.T) {
|
||||
newRepo(t, typed)
|
||||
commit(t, typed, map[string]string{
|
||||
"lib/puppet/type/typed.rb": "Puppet::Type.newtype(:typed) do\n newparam(:name, namevar: true)\nend\n",
|
||||
"lib/puppet/provider/typed/posix.rb": "",
|
||||
"lib/puppet/provider/typed/posix.rb": "Puppet::Type.type(:typed).provide(:posix) do\nend\n",
|
||||
})
|
||||
commit(t, f.control, map[string]string{
|
||||
"Puppetfile": fmt.Sprintf("moduledir 'external_modules'\nmod 'typed', :git => '%s'\n", f.url(typed)),
|
||||
@@ -658,7 +658,7 @@ func TestGenerateTypesBeforeSwap(t *testing.T) {
|
||||
}
|
||||
live = skipped
|
||||
|
||||
commit(t, f.control, map[string]string{"site/local/lib/puppet/type/local.rb": "Puppet::Type.newtype(:local) do\n newparam(:name)\nend\n" + strings.Repeat("module A\n", 300) + strings.Repeat("end\n", 300)})
|
||||
commit(t, f.control, map[string]string{"site/local/lib/puppet/type/local.rb": "Puppet::Type.newtype(:local) do\n newparam(:name) do\n newvalues(" + strings.Repeat("[", 300) + strings.Repeat("]", 300) + ")\n end\nend\n"})
|
||||
if err := f.deploy(false); err == nil || !strings.Contains(err.Error(), "deeper than") || !strings.Contains(err.Error(), "site/local/lib/puppet/type/local.rb") {
|
||||
t.Fatalf("a parser limit must fail the deploy naming the file: %v", err)
|
||||
}
|
||||
@@ -1086,3 +1086,84 @@ func TestConcurrentWorktreeAddsOneMirror(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGCRefsErrorDropsMarkOfLiveWorktree(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
s := &Source{Name: "s", Basedir: filepath.Join(root, "envs")}
|
||||
cfg := &Config{Cachedir: filepath.Join(root, "cache"), Sources: map[string]*Source{"s": s}}
|
||||
clock := time.Unix(1_700_000_000, 0)
|
||||
gc := func() error {
|
||||
d := New(cfg, 1, 10*time.Minute)
|
||||
d.now = func() time.Time { return clock }
|
||||
return d.GC(context.Background())
|
||||
}
|
||||
d := New(cfg, 1, 0)
|
||||
old, cur, broken := filepath.Join(d.srcWorktrees(s), "old"), filepath.Join(d.srcWorktrees(s), "cur"), filepath.Join(d.srcWorktrees(s), "broken")
|
||||
mkdirs(t, old, cur, broken, s.Basedir, filepath.Dir(d.doneFile(old)))
|
||||
for _, p := range []string{old, cur} {
|
||||
if err := os.WriteFile(d.doneFile(p), []byte(`{"modules":[]}`), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
link := filepath.Join(s.Basedir, "develop")
|
||||
if err := Swap(cur, link); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := gc(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
clock = clock.Add(time.Hour)
|
||||
if err := Swap(old, link); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := Swap(broken, filepath.Join(s.Basedir, "other")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := gc(); err == nil {
|
||||
t.Fatal("want moduleRefs error from live worktree without done file")
|
||||
}
|
||||
if err := os.WriteFile(d.doneFile(broken), []byte(`{"modules":[]}`), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := Swap(cur, link); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_ = gc()
|
||||
if !exists(old) {
|
||||
t.Fatal("worktree unreferenced this run was deleted in the same run via a stale mark kept while it was live")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeployOnlyLeavesLaterSourceAlone(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
commit(t, f.control, map[string]string{"manifests/site.pp": "node default {}\n"})
|
||||
gitT(t, f.control, "branch", "production")
|
||||
other := filepath.Join(f.root, "other")
|
||||
newRepo(t, other)
|
||||
commit(t, other, map[string]string{"manifests/site.pp": "node default {}\n"})
|
||||
otherBase := filepath.Join(f.root, "other-envs")
|
||||
cfg, err := ParseConfig(fmt.Appendf(nil, "cachedir: %s\nsources:\n aaa:\n remote: %s\n basedir: %s\n zzz:\n remote: %s\n basedir: %s\n", f.cfg.Cachedir, f.control, f.basedir, other, otherBase))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f.cfg = cfg
|
||||
if err := f.deploy(false, "production"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if exists(filepath.Join(otherBase, "main")) {
|
||||
t.Fatal("deploy production also deployed every env of the next source")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeployMarkerNameIsBranch(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
commit(t, f.control, map[string]string{"manifests/site.pp": "node default {}\n"})
|
||||
gitT(t, f.control, "checkout", "-q", "-b", "feat/x")
|
||||
commit(t, f.control, map[string]string{"manifests/site.pp": "node x {}\n"})
|
||||
if err := f.deploy(false, "feat_x"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if m := readMarker(t, f.env("feat_x")); m.Name != "feat/x" {
|
||||
t.Fatalf("marker name %q, want branch feat/x", m.Name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package gentypes
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func FuzzParseFile(f *testing.F) {
|
||||
err := filepath.WalkDir("testdata/env", func(p string, d fs.DirEntry, err error) error {
|
||||
if err == nil && strings.HasSuffix(p, ".rb") {
|
||||
b, rerr := os.ReadFile(p)
|
||||
f.Add(string(b))
|
||||
return rerr
|
||||
}
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
f.Fatal(err)
|
||||
}
|
||||
mix := "module PuppetX\n module M\n def exists?; end\n end\nend\n"
|
||||
f.Fuzz(func(t *testing.T, src string) {
|
||||
types, err := parseFile(src, func(string, bool) ([]string, error) { return []string{mix, src}, nil })
|
||||
if err == nil {
|
||||
for _, ty := range types {
|
||||
_, _ = render(ty, []string{"a"}, time.Unix(0, 0))
|
||||
}
|
||||
}
|
||||
_, _, _ = providerOf(src, "t")
|
||||
_, _ = mixinMethods(src, "PuppetX::M")
|
||||
_, _ = inertLib(src)
|
||||
_, _ = parsePType(src)
|
||||
})
|
||||
}
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
const OutDir = ".resource_types"
|
||||
|
||||
// Version changes whenever generated output can change, so deploys rebuild typed environments.
|
||||
const Version = "2"
|
||||
const Version = "3"
|
||||
|
||||
var moduleName = regexp.MustCompile(`^[a-z][a-z0-9_]*$`)
|
||||
|
||||
@@ -84,9 +84,9 @@ func Generate(env string, roots ...string) (st Stats, err error) {
|
||||
return st, err
|
||||
}
|
||||
for _, f := range files {
|
||||
typ, name := filepath.Base(d), strings.TrimSuffix(filepath.Base(f), ".rb")
|
||||
if !slices.Contains(providers[typ], name) {
|
||||
providers[typ] = append(providers[typ], name)
|
||||
typ := filepath.Base(d)
|
||||
if !slices.ContainsFunc(providers[typ], func(o string) bool { return filepath.Base(o) == filepath.Base(f) }) {
|
||||
providers[typ] = append(providers[typ], f)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,7 +119,7 @@ func Generate(env string, roots ...string) (st Stats, err error) {
|
||||
}
|
||||
var errs []error
|
||||
for _, in := range inputs {
|
||||
wrote, err := generateOne(in, out, providers, g.mixins(mods))
|
||||
wrote, err := generateOne(in, out, providers[strings.TrimSuffix(filepath.Base(in), ".rb")], g.libs(mods, in))
|
||||
switch {
|
||||
case err == nil && wrote:
|
||||
st.Generated++
|
||||
@@ -155,7 +155,13 @@ func openOut(env string) (*os.Root, error) {
|
||||
return root.OpenRoot(OutDir)
|
||||
}
|
||||
|
||||
func generateOne(in string, out *os.Root, providers map[string][]string, resolve Resolver) (bool, error) {
|
||||
// generateOne writes the type defined by in; providers are the first-found provider files the autoloader loads for it.
|
||||
func generateOne(in string, out *os.Root, providers []string, resolve Resolver) (wrote bool, err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err = fmt.Errorf("panic: %v", r)
|
||||
}
|
||||
}()
|
||||
ifi, err := os.Stat(in)
|
||||
if err != nil {
|
||||
return false, err
|
||||
@@ -182,7 +188,11 @@ func generateOne(in string, out *os.Root, providers map[string][]string, resolve
|
||||
if t == nil {
|
||||
return false, skipErr{fmt.Errorf("custom type %q was not defined", name)}
|
||||
}
|
||||
body, err := render(t, providers[name], time.Now())
|
||||
names, err := providerNames(t, providers)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
body, err := render(t, names, time.Now())
|
||||
if err != nil {
|
||||
return false, unparsed(err)
|
||||
}
|
||||
@@ -208,14 +218,49 @@ func generateOne(in string, out *os.Root, providers map[string][]string, resolve
|
||||
return true, out.Rename(tmp, dst)
|
||||
}
|
||||
|
||||
var camel = regexp.MustCompile(`([a-z0-9])([A-Z])|([A-Z])([A-Z][a-z])`)
|
||||
// providerNames returns the providers puppet registers for t, or a skip when a provider file is not a recognised provide call.
|
||||
func providerNames(t *rtype, files []string) ([]string, error) {
|
||||
var names, parents []string
|
||||
for _, f := range files {
|
||||
src, err := os.ReadFile(f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
name, parent, err := providerOf(string(src), t.name)
|
||||
switch {
|
||||
case err != nil:
|
||||
case t.rsapi && name != "":
|
||||
err = fmt.Errorf("provide on a Resource API type")
|
||||
case !t.rsapi && name == "":
|
||||
err = fmt.Errorf("no Puppet::Type.type(:%s).provide call", t.name)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, unparsed(fmt.Errorf("provider %s: %w", filepath.Base(f), err))
|
||||
}
|
||||
if !slices.Contains(names, name) && name != "" {
|
||||
names = append(names, name)
|
||||
}
|
||||
if parent != "" {
|
||||
parents = append(parents, parent)
|
||||
}
|
||||
}
|
||||
for _, p := range parents {
|
||||
if !slices.Contains(names, p) {
|
||||
return nil, skipErr{fmt.Errorf("parent provider %s is not defined", p)}
|
||||
}
|
||||
}
|
||||
return names, nil
|
||||
}
|
||||
|
||||
// mixins resolves a constant path to every module's lib/<snake_case path>.rb, as Ruby's require would find it.
|
||||
func (g *gen) mixins(mods []string) Resolver {
|
||||
return func(path string) ([]string, error) {
|
||||
rel := strings.ToLower(camel.ReplaceAllString(strings.ReplaceAll(path, "::", "/"), "${1}${3}_${2}${4}")) + ".rb"
|
||||
// libs resolves a lib-relative path in every module as Ruby's require would search, or only in the module of in when local.
|
||||
func (g *gen) libs(mods []string, in string) Resolver {
|
||||
own := filepath.Dir(filepath.Dir(filepath.Dir(filepath.Dir(in))))
|
||||
return func(rel string, local bool) ([]string, error) {
|
||||
var srcs []string
|
||||
for _, m := range mods {
|
||||
if local && m != own {
|
||||
continue
|
||||
}
|
||||
p := filepath.Join(m, "lib", rel)
|
||||
if _, err := os.Lstat(p); errors.Is(err, os.ErrNotExist) {
|
||||
continue
|
||||
@@ -230,9 +275,6 @@ func (g *gen) mixins(mods []string) Resolver {
|
||||
}
|
||||
srcs = append(srcs, string(b))
|
||||
}
|
||||
if len(srcs) == 0 {
|
||||
return nil, fmt.Errorf("no module provides lib/%s", rel)
|
||||
}
|
||||
return srcs, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,11 +20,14 @@ func uncommented(s string) string {
|
||||
return blankRun.ReplaceAllString(commentLine.ReplaceAllString(s, ""), "\n")
|
||||
}
|
||||
|
||||
// realOnly are golden files real puppet generates that w10k skips because it cannot prove the output matches.
|
||||
var realOnly = set("r_const_call r_helper r_inline_provide r_prov_class r_prov_empty r_rs_bad_uncertain r_rs_bad_undef r_send")
|
||||
|
||||
// GENTYPES_ENV/GENTYPES_GOLDEN compare a full environment without comments, since provider docs are not ported.
|
||||
func TestGolden(t *testing.T) {
|
||||
env, golden, view := "testdata/env", "testdata/golden", func(s string) string { _, rest, _ := strings.Cut(s, "\n"); return rest }
|
||||
env, golden, view, allowSkip := "testdata/env", "testdata/golden", func(s string) string { _, rest, _ := strings.Cut(s, "\n"); return rest }, realOnly
|
||||
if e := os.Getenv("GENTYPES_ENV"); e != "" {
|
||||
env, golden, view = e, os.Getenv("GENTYPES_GOLDEN"), uncommented
|
||||
env, golden, view, allowSkip = e, os.Getenv("GENTYPES_GOLDEN"), uncommented, nil
|
||||
}
|
||||
work := t.TempDir()
|
||||
if err := os.CopyFS(work, os.DirFS(env)); err != nil {
|
||||
@@ -40,12 +43,24 @@ func TestGolden(t *testing.T) {
|
||||
if len(want) == 0 {
|
||||
t.Fatal("no golden files")
|
||||
}
|
||||
got, _ := filepath.Glob(filepath.Join(work, OutDir, "*.pp"))
|
||||
for _, g := range got {
|
||||
if !exists(filepath.Join(golden, filepath.Base(g))) {
|
||||
t.Errorf("%s generated, real puppet does not generate it", filepath.Base(g))
|
||||
}
|
||||
}
|
||||
match := 0
|
||||
for _, w := range want {
|
||||
name := filepath.Base(w)
|
||||
t.Run(strings.TrimSuffix(name, ".pp"), func(t *testing.T) {
|
||||
wb, _ := os.ReadFile(w)
|
||||
gb, err := os.ReadFile(filepath.Join(work, OutDir, name))
|
||||
if allowSkip[strings.TrimSuffix(name, ".pp")] {
|
||||
if err == nil {
|
||||
t.Fatal("expected a skip")
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -58,7 +73,55 @@ func TestGolden(t *testing.T) {
|
||||
match++
|
||||
})
|
||||
}
|
||||
t.Logf("%d/%d golden files match", match, len(want))
|
||||
t.Logf("%d/%d golden files match", match, len(want)-len(allowSkip))
|
||||
}
|
||||
|
||||
// TestReviewSkips pins why each testdata/env/modules/review type that real puppet 9.3.0 fails to load, or that
|
||||
// w10k cannot prove, is skipped.
|
||||
func TestReviewSkips(t *testing.T) {
|
||||
work := t.TempDir()
|
||||
if err := os.CopyFS(work, os.DirFS("testdata/env")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
st, err := Generate(work)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := map[string]string{}
|
||||
for _, s := range st.Skipped {
|
||||
file, why, _ := strings.Cut(s.Error(), ": ")
|
||||
got[strings.TrimSuffix(filepath.Base(file), ".rb")] = why
|
||||
}
|
||||
for name, want := range map[string]string{
|
||||
"r_dollar": "line 4: unsupported top-level $",
|
||||
"r_prov_empty": "provider posix.rb: no Puppet::Type.type(:r_prov_empty).provide call",
|
||||
"r_prov_class": "provider posix.rb: no Puppet::Type.type(:r_prov_class).provide call",
|
||||
"r_prov_parent_missing": "parent provider nope is not defined",
|
||||
"r_send": "line 4: unsupported top-level Puppet::Type.type",
|
||||
"r_inline_provide": "line 4: unsupported top-level Puppet::Type.type",
|
||||
"r_helper": "line 1: unsupported top-level module RHelper",
|
||||
"r_const_call": "unsupported non-literal constant X",
|
||||
"r_require_missing": `require "puppet_x/review/nope": no module provides it`,
|
||||
"r_rs_str_key": "register_type: unsupported string key",
|
||||
"r_rs_bad_lower": `type "string": unsupported type`,
|
||||
"r_rs_bad_range": "unsupported Integer[5,1]",
|
||||
"r_rs_bad_regex": "unsupported regex /(/",
|
||||
"r_rs_bad_undef": "unsupported Undef",
|
||||
"r_rs_bad_uncertain": "cannot tell whether String and String[0] are the same type",
|
||||
"r_rs_bad_words": "unsupported word if",
|
||||
"r_dup_prop": "duplicate property a",
|
||||
"r_dup_param": "duplicate parameter a",
|
||||
"r_dup_ensure": "duplicate property ensure",
|
||||
"r_bare": "unsupported top-level Type.newtype",
|
||||
"r_mod_foo": "unsupported top-level module RFoo",
|
||||
"r_mod_compact": "unsupported top-level module Puppet::RCompact",
|
||||
"r_include_noreq": "include PuppetX::Review::Mix: no require defines it",
|
||||
"r_feature_const": "uninitialized constant RNope",
|
||||
} {
|
||||
if !strings.Contains(got[name], want) {
|
||||
t.Errorf("%s: got %q, want %q", name, got[name], want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestScrub(t *testing.T) {
|
||||
@@ -111,7 +174,7 @@ func TestQuote(t *testing.T) {
|
||||
|
||||
func typeOf(t *testing.T, body string) []string {
|
||||
t.Helper()
|
||||
types, err := parseFile("Puppet::Type.newtype(:t) do\n"+body+"\nend\n", nil)
|
||||
types, err := parseFile("require 'puppet/parameter/boolean'\nPuppet::Type.newtype(:t) do\n"+body+"\nend\n", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -146,25 +209,50 @@ func TestPuppetTypeMapping(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Expected values are ValueCreator.create_values on Puppet::Pops::Types::TypeParser.singleton.parse(typ) in openvox 9.3.0.
|
||||
func TestResourceAPIMapping(t *testing.T) {
|
||||
const str, num, boolean = "Pattern[//]", `Pattern[/^-?\d+$/]`, "Variant[Boolean, Enum['true', 'true', 'true', 'false', 'false', 'false']]"
|
||||
for typ, want := range map[string]string{
|
||||
"String": "Pattern[//]",
|
||||
"Optional[String[1]]": "Pattern[//]",
|
||||
"Integer[0,65535]": `Pattern[/^-?\d+$/]`,
|
||||
"Boolean": "Variant[Boolean, Enum['true', 'true', 'true', 'false', 'false', 'false']]",
|
||||
"Enum[present, absent]": "Enum['absent', 'present']",
|
||||
"Optional[Enum[a, b]]": "Any",
|
||||
"Array[String]": "Any",
|
||||
"Sensitive[String]": "Any",
|
||||
"Optional[Numeric]": "Pattern[/" + strings.ReplaceAll(numericRe, "/", `\/`) + "/]",
|
||||
"Variant[String, Undef]": "Any",
|
||||
"String": str,
|
||||
" Optional[String[1]] ": str,
|
||||
"Integer[0,65535]": num,
|
||||
"Boolean": boolean,
|
||||
"Enum[present, absent]": "Enum['absent', 'present']",
|
||||
"Optional[Enum[a, b]]": "Any",
|
||||
"Array[String]": "Any",
|
||||
"Sensitive[String]": "Any",
|
||||
"Optional[Numeric]": "Pattern[/" + strings.ReplaceAll(numericRe, "/", `\/`) + "/]",
|
||||
"Variant[String]": str,
|
||||
"Optional[Variant[Integer]]": num,
|
||||
"Variant[Optional[Float]]": "Pattern[/" + strings.ReplaceAll(numericRe, "/", `\/`) + "/]",
|
||||
"Variant[Integer[ 1 , 2 ], Integer[1,2]]": num,
|
||||
"Optional[Optional[String]]": "Any",
|
||||
"Optional['x']": str,
|
||||
"Variant[Variant[Boolean], Boolean]": boolean,
|
||||
"Variant[String, Integer]": "Any",
|
||||
"Optional": "Any",
|
||||
"Variant": "Any",
|
||||
"Hash[String, Integer, 1, 2]": "Any",
|
||||
"Integer[-5, default]": num,
|
||||
} {
|
||||
a := &attr{}
|
||||
rsapiValues(a, typ)
|
||||
if err := rsapiValues(a, typ); err != nil {
|
||||
t.Errorf("%s: %v", typ, err)
|
||||
continue
|
||||
}
|
||||
if got, _ := a.puppetType(); got != want {
|
||||
t.Errorf("%s = %s, want %s", typ, got, want)
|
||||
}
|
||||
}
|
||||
for _, typ := range []string{
|
||||
"string", "Stdlib::Port", "Optional[]", "Variant[]", "Integer[5,1]", "Integer[1.5]", "Numeric[1]", "Array[String, 3, 1]", "Hash[String]",
|
||||
"Float[2, 1.5]", "Pattern[/(/]", "Pattern['(']", "Pattern[/(?P<a>x)/]", "Enum[if]", "Variant[String, Undef]",
|
||||
"Variant[Integer, Integer[default,default]]", "Integer[0x10]", "String[1,2,3]", "Optional[String, Integer]", "Integer[",
|
||||
} {
|
||||
if err := rsapiValues(&attr{}, typ); err == nil {
|
||||
t.Errorf("%s: TypeParser rejects it or its values are not provable, want an error", typ)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHeredocs(t *testing.T) {
|
||||
@@ -196,13 +284,13 @@ func TestUnsupported(t *testing.T) {
|
||||
for _, c := range []struct{ src, want string }{
|
||||
{"Puppet::Type.newtype(:t) do\n newparam(name_var)\nend", "unsupported expression"},
|
||||
{"Puppet::Type.newtype(:t) do\n newparam(:a) do\n desc \"x #{NOPE}\"\n end\nend", "#{NOPE}"},
|
||||
{"Puppet::Type.newtype(:t) do\n newparam(:a, parent: Puppet::Parameter::Custom)\nend", "unsupported parent"},
|
||||
{"Puppet::Type.newtype(:t) do\n newparam(:a, parent: Puppet::Parameter::Custom)\nend", "uninitialized constant Puppet::Parameter::Custom"},
|
||||
{"Puppet::Type.newtype(:t) do\n if x\n newparam(:a)\n end\nend", "unsupported if x in type body"},
|
||||
{"Puppet::Type.newtype(:t) do\n if defined? X\n newparam(:a)\n end\nend", "unsupported conditional newparam"},
|
||||
{"Puppet::Type.newtype(:t) do\n [:a, :b].each { |n| newparam(n) }\nend", "unsupported [ :a , :b ].each in type body"},
|
||||
{"Puppet::Type.newtype(:t) do\n newparam(:a) do\n validate do\n newvalues(:x)\n end\n end\nend", "unsupported use of newvalues"},
|
||||
{"Puppet::Type.newtype(:t) do\n def self.title_patterns\n [[/(.*)/, [[:a, lambda { |x| x }]]]]\n end\nend", "title_patterns"},
|
||||
{"Puppet::Type.newtype(:t, parent: Puppet::Type::File) do\nend", "newtype with options"},
|
||||
{"Puppet::Type.newtype(:t, self_refresh: true) do\nend", "newtype with options"},
|
||||
{"Puppet::Type.newtype(:t) do\n newparam(:a) do\n desc 'x' + dynamic\n end\nend", "unsupported expression"},
|
||||
{"Puppet::Type.newtype(:t) do\n @isomorphic = false\nend", "@isomorphic"},
|
||||
{"Puppet::Type.newtype(:t) do\n newparam(:a)\n newparam(:b, namevar: true)\n newparam(:c, namevar: true)\nend", "two or more key attributes"},
|
||||
@@ -389,7 +477,7 @@ func TestGenerateErrors(t *testing.T) {
|
||||
})
|
||||
t.Run("parser limit fails the env", func(t *testing.T) {
|
||||
env := t.TempDir()
|
||||
writeFile(t, filepath.Join(env, "modules/m/lib/puppet/type/deep.rb"), "Puppet::Type.newtype(:deep) do\nend\n"+strings.Repeat("module A\n", 300)+strings.Repeat("end\n", 300))
|
||||
writeFile(t, filepath.Join(env, "modules/m/lib/puppet/type/deep.rb"), "Puppet::Type.newtype(:deep) do\n newparam(:a) do\n newvalues("+strings.Repeat("[", 300)+strings.Repeat("]", 300)+")\n end\nend\n")
|
||||
if st, err := Generate(env); !errors.Is(err, errLimit) || len(st.Skipped) != 0 {
|
||||
t.Fatalf("got %v, skipped %v", err, st.Skipped)
|
||||
}
|
||||
@@ -451,11 +539,8 @@ func parseWithin(t *testing.T, src string, resolve Resolver) ([]*rtype, error) {
|
||||
|
||||
func TestStrayCloserIsAnError(t *testing.T) {
|
||||
for src, want := range map[string]string{
|
||||
")\n": `unmatched ")"`,
|
||||
"]\n": `unmatched "]"`,
|
||||
"}\n": `unmatched "}"`,
|
||||
"end\n": `unmatched "end"`,
|
||||
"module A\n foo )\nend\n": `unmatched ")"`,
|
||||
")\n": "unsupported top-level )",
|
||||
"end\n": "unsupported top-level end",
|
||||
"Puppet::Type.newtype(:t) do\n }\nend\n": "line 2: unsupported } in type body",
|
||||
"Puppet::Type.newtype(:t) do\n newparam(:a) do\n )\n end\nend\n": "line 3: unsupported ) in attribute a",
|
||||
} {
|
||||
@@ -463,6 +548,11 @@ func TestStrayCloserIsAnError(t *testing.T) {
|
||||
t.Errorf("%q: got %v, want %q", src, err, want)
|
||||
}
|
||||
}
|
||||
for src, want := range map[string]string{")\n": `unmatched ")"`, "]\n": `unmatched "]"`, "}\n": `unmatched "}"`, "end\n": `unmatched "end"`, "class A\n foo )\nend\n": "unmatched"} {
|
||||
if _, _, err := providerOf(src, "t"); err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("provider %q: got %v, want %q", src, err, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestStepBudget(t *testing.T) {
|
||||
@@ -489,7 +579,6 @@ func TestDeepNestingIsAnError(t *testing.T) {
|
||||
}
|
||||
for _, src := range []string{
|
||||
"Puppet::Type.newtype(:u) do\n newparam(:a) do\n newvalues(" + strings.Repeat("[", 300) + strings.Repeat("]", 300) + ")\n end\nend\n",
|
||||
strings.Repeat("module A\n", 300) + strings.Repeat("end\n", 300),
|
||||
"Puppet::Type.newtype(:t) do\n newparam(:a) do\n" + strings.Repeat("if defined? X\n", 300) + strings.Repeat("end\n", 300) + "end\nend\n",
|
||||
`x = "` + strings.Repeat(`#{"`, 300) + strings.Repeat(`"}`, 300) + `"` + "\n",
|
||||
} {
|
||||
@@ -497,6 +586,9 @@ func TestDeepNestingIsAnError(t *testing.T) {
|
||||
t.Errorf("%.40q: got %v", src, err)
|
||||
}
|
||||
}
|
||||
if _, err := inertLib("module PuppetX\n" + strings.Repeat("module A\n", 300) + strings.Repeat("end\n", 301)); err == nil || !strings.Contains(err.Error(), "deeper than") {
|
||||
t.Errorf("nested required modules: got %v", err)
|
||||
}
|
||||
cmd := exec.Command(os.Args[0], "-test.run=^TestDeepNestingIsAnError$")
|
||||
cmd.Env = append(os.Environ(), "GENTYPES_DEEP_CHILD=1")
|
||||
if out, err := cmd.CombinedOutput(); err != nil {
|
||||
@@ -544,7 +636,7 @@ func mustParse(t *testing.T, src string) *rtype {
|
||||
}
|
||||
|
||||
func TestResourceAPIBehaviorSpelling(t *testing.T) {
|
||||
ty := mustParse(t, "Puppet::ResourceApi.register_type(name: 't', attributes: { name: { type: 'String', behavior: :namevar }, p: { type: 'String', behavior: :parameter } })\n")
|
||||
ty := mustParse(t, "require 'puppet/resource_api'\nPuppet::ResourceApi.register_type(name: 't', attributes: { name: { type: 'String', behavior: :namevar }, p: { type: 'String', behavior: :parameter } })\n")
|
||||
if len(ty.params) != 2 || !ty.params[0].namevar || ty.params[1].namevar || len(ty.props) != 0 {
|
||||
t.Fatalf("behavior: is an alias of behaviour: %+v %+v", ty.params, ty.props)
|
||||
}
|
||||
@@ -552,7 +644,7 @@ func TestResourceAPIBehaviorSpelling(t *testing.T) {
|
||||
"Puppet::ResourceApi.register_type(name: 't', attributes: { name: { type: 'String', behavior: :namevar, behaviour: :namevar } })\n": "both behavior and behaviour",
|
||||
"Puppet::ResourceApi.register_type(name: 't', attributes: { name: { type: 'String', behaviour: 'namevar' } })\n": "behaviour must be a symbol",
|
||||
} {
|
||||
if _, err := parseWithin(t, src, nil); err == nil || !strings.Contains(err.Error(), want) {
|
||||
if _, err := parseWithin(t, "require 'puppet/resource_api'\n"+src, nil); err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("%s: got %v, want %q", src, err, want)
|
||||
}
|
||||
}
|
||||
@@ -623,3 +715,52 @@ func TestLiteralNormalisation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestProviderOf(t *testing.T) {
|
||||
for src, want := range map[string]string{
|
||||
"Puppet::Type.type(:t).provide(:a) do\nend\n": "a ",
|
||||
"require 'json'\nPuppet::Type.type('t').provide :b, parent: :a do\nend\nclass X\nend\n": "b a",
|
||||
"Puppet::Type.type(:t).provide(:c, parent: Puppet::Provider::Foo) {}\n": "c ",
|
||||
"class Puppet::Provider::T::Rsapi\nend\n": " ",
|
||||
"": " ",
|
||||
"Puppet::Type.type(:t).provide(name) do\nend\n": "error",
|
||||
"Puppet::Type.type(:other).provide(:a) do\nend\n": "error",
|
||||
"Puppet::Type.type(:t).provide(:a)\nPuppet::Type.type(:t).provide(:b)\n": "error",
|
||||
"Puppet::Type.type(:t).provide(:a)\nPuppet::Type.type(:t).newparam(:x)\n": "error",
|
||||
"module M\n Puppet::Type.type(:t).provide(:a)\nend\n": "error",
|
||||
"Puppet::Type.type(:t).provide(:a, 'parent' => :b)\n": "error",
|
||||
"$": " ",
|
||||
} {
|
||||
name, parent, err := providerOf(src, "t")
|
||||
got := name + " " + parent
|
||||
if err != nil {
|
||||
got = "error"
|
||||
}
|
||||
if got != want {
|
||||
t.Errorf("%q: got %q (%v), want %q", src, got, err, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLexTrailingSigil(t *testing.T) {
|
||||
for _, src := range []string{"$", "x = $", "@", "@@", "Puppet::Type.newtype(:t) do\nend\n$"} {
|
||||
if _, err := parseWithin(t, src, nil); err == nil {
|
||||
t.Errorf("%q: want an error", src)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGeneratePanicFailsTheEnv(t *testing.T) {
|
||||
env := t.TempDir()
|
||||
in := filepath.Join(env, "modules/m/lib/puppet/type/mix.rb")
|
||||
writeFile(t, in, "require 'puppet_x/m/mix'\nPuppet::Type.newtype(:mix) do\n include PuppetX::M::Mix\nend\n")
|
||||
out, err := openOut(env)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() { _ = out.Close() }()
|
||||
_, err = generateOne(in, out, nil, func(string, bool) ([]string, error) { panic("boom") })
|
||||
if err == nil || !strings.Contains(err.Error(), "panic: boom") || errors.As(err, new(skipErr)) {
|
||||
t.Fatalf("a panic must be a hard error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,7 +231,7 @@ func (l *lexer) next(space bool) error {
|
||||
if c == '@' && l.peek(0) == '@' {
|
||||
l.pos++
|
||||
}
|
||||
if c == '$' && !isIdentStart(l.peek(0)) {
|
||||
if c == '$' && !isIdentStart(l.peek(0)) && l.pos < len(l.src) {
|
||||
l.pos++
|
||||
}
|
||||
for l.pos < len(l.src) && isIdentChar(l.src[l.pos]) {
|
||||
|
||||
+360
-53
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"math"
|
||||
"math/big"
|
||||
"path"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
@@ -75,15 +76,15 @@ type rval struct {
|
||||
|
||||
func (v rval) get(key string) (rval, bool) {
|
||||
for i, k := range v.keys {
|
||||
if (k.k == vSym || k.k == vStr) && k.s == key {
|
||||
if k.k == vSym && k.s == key {
|
||||
return v.arr[i], true
|
||||
}
|
||||
}
|
||||
return rval{}, false
|
||||
}
|
||||
|
||||
// Resolver returns the sources that may define a mixin module, by Ruby's constant-to-path convention.
|
||||
type Resolver func(path string) ([]string, error)
|
||||
// Resolver returns the sources of lib-relative file path in every module, or only the type's own module when local.
|
||||
type Resolver func(path string, local bool) ([]string, error)
|
||||
|
||||
type parser struct {
|
||||
toks []token
|
||||
@@ -95,6 +96,7 @@ type parser struct {
|
||||
steps int
|
||||
cond int
|
||||
resolve Resolver
|
||||
defined map[string]bool
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -123,8 +125,8 @@ func parseFile(src string, resolve Resolver) (types []*rtype, err error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p := &parser{toks: toks, consts: map[string]rval{}, used: map[int]bool{}, resolve: resolve}
|
||||
if err := p.body("", p.topStmt); err != nil {
|
||||
p := &parser{toks: toks, consts: map[string]rval{}, used: map[int]bool{}, resolve: resolve, defined: map[string]bool{"Facter": true, "Puppet::Parameter::Path": true, "Puppet::Property::Ensure": true}}
|
||||
if err := p.body("", p.topStmt(false)); err != nil {
|
||||
return nil, p.wrap(err)
|
||||
}
|
||||
for i, t := range p.toks {
|
||||
@@ -399,27 +401,175 @@ func (p *parser) strictConstAssign() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *parser) topStmt() (bool, error) {
|
||||
t := p.cur()
|
||||
switch {
|
||||
case t.kind == tIdent && t.text == "module":
|
||||
p.take()
|
||||
for p.cur().kind == tConst || p.op("::") {
|
||||
p.take()
|
||||
}
|
||||
return true, p.body("end", p.topStmt)
|
||||
case t.kind == tConst && p.methodCall("newtype"):
|
||||
return true, p.newtype()
|
||||
case t.kind == tConst && p.methodCall("register_type"):
|
||||
return true, p.registerType()
|
||||
case t.kind == tConst && p.at(1).kind == tOp && p.at(1).text == "=":
|
||||
return p.constAssign()
|
||||
var fileConsts = []string{"Puppet::Parameter::Boolean", "Puppet::Property::Boolean", "Puppet::Type::File::Owner", "Puppet::Type::File::Group", "Puppet::Type::File::Mode"}
|
||||
|
||||
// Libraries a type file may require without changing its type, present in openvox 9.3.0 and its Ruby;
|
||||
// puppetLibs maps each to the constants it defines beyond those loaded with Puppet::Type.
|
||||
var (
|
||||
rubyLibs = set("base64 digest/md5 erb fileutils ipaddr json net/http open3 pathname resolv securerandom set socket tempfile uri")
|
||||
puppetLibs = map[string][]string{
|
||||
"puppet": nil, "puppet/util": nil, "puppet/util/checksums": nil, "puppet/parameter/path": nil, "puppet/property/ensure": nil,
|
||||
"puppet/parameter/boolean": fileConsts[:2],
|
||||
"puppet/property/boolean": fileConsts[1:2],
|
||||
"puppet/resource_api": {"Puppet::ResourceApi"},
|
||||
"puppet/type/file": fileConsts, "puppet/type/file/owner": fileConsts, "puppet/type/file/group": fileConsts, "puppet/type/file/mode": fileConsts,
|
||||
}
|
||||
coreConsts = set("Puppet PuppetX Type ResourceApi")
|
||||
)
|
||||
|
||||
// topStmt allows only statements that cannot reach a type: requires, literal constants, module Puppet and the type definition.
|
||||
func (p *parser) topStmt(inPuppet bool) func() (bool, error) {
|
||||
return func() (bool, error) {
|
||||
t := p.cur()
|
||||
switch {
|
||||
case t.kind == tIdent && t.text == "module" && !inPuppet && p.at(1).kind == tConst && p.at(1).text == "Puppet" && (p.at(2).kind == tNL || p.at(2).text == ";"):
|
||||
p.i += 2
|
||||
return true, p.body("end", p.topStmt(true))
|
||||
case t.kind == tIdent && (t.text == "require" || t.text == "require_relative"):
|
||||
return true, p.require()
|
||||
case t.kind == tIdent && t.text == "begin":
|
||||
return true, p.beginRequire()
|
||||
case t.kind == tConst && p.methodCall("newtype", inPuppet):
|
||||
return true, p.newtype()
|
||||
case t.kind == tConst && p.methodCall("register_type", inPuppet):
|
||||
if !p.defined["Puppet::ResourceApi"] {
|
||||
return true, fmt.Errorf("Puppet::ResourceApi used without require 'puppet/resource_api'")
|
||||
}
|
||||
return true, p.registerType()
|
||||
case t.kind == tConst && p.assigns() && !coreConsts[t.text]:
|
||||
return true, p.strictConstAssign()
|
||||
}
|
||||
return true, fmt.Errorf("unsupported top-level %s", p.construct())
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// methodCall matches Const(::Const)*.name at the cursor and advances past the name.
|
||||
func (p *parser) methodCall(name string) bool {
|
||||
func (p *parser) require() error {
|
||||
rel := p.take().text == "require_relative"
|
||||
args, err := p.args()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(args) != 1 || args[0].k != vStr {
|
||||
return fmt.Errorf("unsupported require argument")
|
||||
}
|
||||
lib := args[0].s
|
||||
if rel {
|
||||
lib = path.Join("puppet/type", lib)
|
||||
}
|
||||
if lib == "" || path.IsAbs(args[0].s) || path.Clean(lib) != lib || lib == ".." || strings.HasPrefix(lib, "../") || strings.HasSuffix(lib, ".rb") {
|
||||
return fmt.Errorf("unsupported require %q", args[0].s)
|
||||
}
|
||||
var srcs []string
|
||||
if p.resolve != nil {
|
||||
if srcs, err = p.resolve(lib+".rb", rel); err != nil {
|
||||
return fmt.Errorf("require %q: %w", args[0].s, err)
|
||||
}
|
||||
}
|
||||
if consts, core := puppetLibs[lib]; !rel && (rubyLibs[lib] || core) {
|
||||
if len(srcs) > 0 {
|
||||
return fmt.Errorf("require %q is shadowed by a module", lib)
|
||||
}
|
||||
for _, c := range consts {
|
||||
p.defined[c] = true
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if len(srcs) == 0 {
|
||||
return fmt.Errorf("require %q: no module provides it", args[0].s)
|
||||
}
|
||||
var common map[string]bool
|
||||
for _, src := range srcs {
|
||||
mods, err := inertLib(src)
|
||||
if err != nil {
|
||||
return fmt.Errorf("require %q: %w", args[0].s, err)
|
||||
}
|
||||
next := map[string]bool{}
|
||||
for _, m := range mods {
|
||||
if common == nil || common[m] {
|
||||
next[m] = true
|
||||
}
|
||||
}
|
||||
common = next
|
||||
}
|
||||
for m := range common {
|
||||
p.defined[m] = true
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// beginRequire allows begin; require ...; rescue ...; end, whose rescue never runs since every allowed require succeeds.
|
||||
func (p *parser) beginRequire() error {
|
||||
p.take()
|
||||
for {
|
||||
p.skipNL()
|
||||
switch {
|
||||
case p.is(tIdent, "end"):
|
||||
p.take()
|
||||
return nil
|
||||
case p.is(tIdent, "rescue"):
|
||||
for {
|
||||
p.skipNL()
|
||||
switch {
|
||||
case p.is(tIdent, "end"):
|
||||
p.take()
|
||||
return nil
|
||||
case p.is(tIdent, "else") || p.is(tIdent, "ensure") || p.cur().kind == tEOF:
|
||||
return fmt.Errorf("unsupported %s in begin", describe(p.cur()))
|
||||
}
|
||||
if err := p.skipStatement(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
case p.is(tIdent, "require") || p.is(tIdent, "require_relative"):
|
||||
if err := p.require(); err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("unsupported %s in begin", p.construct())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// inertLib returns the modules a required file defines, failing on anything but nested modules of methods and literal constants under PuppetX.
|
||||
func inertLib(src string) (mods []string, err error) {
|
||||
defer guard(&err)
|
||||
toks, err := lex(src)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p := &parser{toks: toks, consts: map[string]rval{}, used: map[int]bool{}}
|
||||
var scope func(prefix string) func() (bool, error)
|
||||
scope = func(prefix string) func() (bool, error) {
|
||||
return func() (bool, error) {
|
||||
c := p.cur()
|
||||
switch {
|
||||
case c.kind == tIdent && c.text == "module" && p.at(1).kind == tConst && (p.at(2).kind == tNL || p.at(2).text == ";") && (prefix != "" || p.at(1).text == "PuppetX"):
|
||||
name := p.at(1).text
|
||||
if prefix != "" {
|
||||
name = prefix + "::" + name
|
||||
}
|
||||
p.i += 2
|
||||
mods = append(mods, name)
|
||||
return true, p.body("end", scope(name))
|
||||
case prefix != "" && c.kind == tIdent && c.text == "def":
|
||||
return true, p.skipStatement()
|
||||
case prefix != "" && c.kind == tIdent && (c.text == "private" || c.text == "protected" || c.text == "public") && (p.at(1).kind == tNL || p.at(1).text == ";"):
|
||||
p.take()
|
||||
return true, nil
|
||||
case prefix != "" && c.kind == tConst && p.assigns():
|
||||
return true, p.strictConstAssign()
|
||||
}
|
||||
return true, fmt.Errorf("unsupported %s in required file", p.construct())
|
||||
}
|
||||
}
|
||||
if err := p.body("", scope("")); err != nil {
|
||||
return nil, p.wrap(err)
|
||||
}
|
||||
return mods, nil
|
||||
}
|
||||
|
||||
// methodCall matches Const(::Const)*.name at the cursor and advances past the name; a bare Type resolves only inside module Puppet.
|
||||
func (p *parser) methodCall(name string, inPuppet bool) bool {
|
||||
j := 0
|
||||
for p.at(j).kind == tConst && p.at(j+1).kind == tOp && p.at(j+1).text == "::" {
|
||||
j += 2
|
||||
@@ -432,7 +582,7 @@ func (p *parser) methodCall(name string) bool {
|
||||
for k := p.i; k <= j; k++ {
|
||||
recv += p.toks[k].text
|
||||
}
|
||||
if (name == "newtype" && recv != "Puppet::Type" && recv != "Type") || (name == "register_type" && recv != "Puppet::ResourceApi") {
|
||||
if (name == "newtype" && recv != "Puppet::Type" && (recv != "Type" || !inPuppet)) || (name == "register_type" && recv != "Puppet::ResourceApi") {
|
||||
return false
|
||||
}
|
||||
p.used[j+2] = true
|
||||
@@ -482,7 +632,7 @@ func (p *parser) newtype() error {
|
||||
}
|
||||
a := &attr{name: "ensure", ensure: true}
|
||||
a.defaultValues()
|
||||
t.addProp(a)
|
||||
return t.addProp(a)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -665,8 +815,7 @@ func (p *parser) typeStmt(t *rtype) (bool, error) {
|
||||
} else if err := p.body(closeTok, func() (bool, error) { return p.attrStmt(a) }); err != nil {
|
||||
return true, err
|
||||
}
|
||||
t.addProp(a)
|
||||
return true, nil
|
||||
return true, t.addProp(a)
|
||||
case c.kind == tIdent && c.text == "def" && p.at(1).kind == tIdent && p.at(1).text == "self" && p.at(2).text == "." && p.at(3).text == "title_patterns":
|
||||
p.used[p.i+3] = true
|
||||
p.i += 4
|
||||
@@ -715,10 +864,17 @@ func (p *parser) include(t *rtype) error {
|
||||
if p.resolve == nil {
|
||||
return fmt.Errorf("include %s: mixin source is not available", path)
|
||||
}
|
||||
srcs, err := p.resolve(path)
|
||||
if !p.defined[path] {
|
||||
return fmt.Errorf("include %s: no require defines it", path)
|
||||
}
|
||||
rel := strings.ToLower(camel.ReplaceAllString(strings.ReplaceAll(path, "::", "/"), "${1}${3}_${2}${4}")) + ".rb"
|
||||
srcs, err := p.resolve(rel, false)
|
||||
if err != nil {
|
||||
return fmt.Errorf("include %s: %w", path, err)
|
||||
}
|
||||
if len(srcs) == 0 {
|
||||
return fmt.Errorf("include %s: no module provides lib/%s", path, rel)
|
||||
}
|
||||
for _, src := range srcs {
|
||||
names, err := mixinMethods(src, path)
|
||||
if err != nil {
|
||||
@@ -795,14 +951,28 @@ func mixinMethods(src, path string) (methods []string, err error) {
|
||||
return methods, nil
|
||||
}
|
||||
|
||||
func (t *rtype) addProp(a *attr) {
|
||||
func (t *rtype) addProp(a *attr) error {
|
||||
if slices.ContainsFunc(t.props, func(o *attr) bool { return o.name == a.name }) {
|
||||
return fmt.Errorf("duplicate property %s", a.name)
|
||||
}
|
||||
if a.name == "ensure" {
|
||||
t.props = append([]*attr{a}, t.props...)
|
||||
return
|
||||
return nil
|
||||
}
|
||||
t.props = append(t.props, a)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *rtype) addParam(a *attr) error {
|
||||
if t.hasParam(a.name) {
|
||||
return fmt.Errorf("duplicate parameter %s", a.name)
|
||||
}
|
||||
t.params = append(t.params, a)
|
||||
return nil
|
||||
}
|
||||
|
||||
var camel = regexp.MustCompile(`([a-z0-9])([A-Z])|([A-Z])([A-Z][a-z])`)
|
||||
|
||||
var parents = map[string][]string{
|
||||
"Puppet::Parameter::Boolean": {"true", "false", "yes", "no"},
|
||||
"Puppet::Property::Boolean": nil,
|
||||
@@ -813,6 +983,51 @@ var parents = map[string][]string{
|
||||
"Puppet::Type::File::Mode": nil,
|
||||
}
|
||||
|
||||
// attrOptions returns the options that change generated output, keyed by symbol. newparam reads only symbol keys and
|
||||
// applies :attributes through setters; newproperty applies every key except :parent through setters, of which only
|
||||
// doc= and required_features= change output (Puppet::Property.public_methods in openvox 9.3.0).
|
||||
func attrOptions(h rval, property bool) (rval, error) {
|
||||
var out rval
|
||||
seen := map[string]bool{}
|
||||
for i, k := range h.keys {
|
||||
if k.k != vSym && k.k != vStr {
|
||||
return out, fmt.Errorf("unsupported %s option key", k.kindName())
|
||||
}
|
||||
id := k.s
|
||||
if !property {
|
||||
id = k.kindName() + id
|
||||
}
|
||||
if seen[id] {
|
||||
return out, fmt.Errorf("duplicate option %s", k.s)
|
||||
}
|
||||
seen[id] = true
|
||||
switch {
|
||||
case !property && k.k == vStr:
|
||||
continue
|
||||
case !property && k.s == "attributes" || property && k.s == "doc":
|
||||
return out, fmt.Errorf("unsupported option %s", k.s)
|
||||
case property && k.k == vStr && k.s == "parent":
|
||||
continue
|
||||
}
|
||||
out.keys, out.arr = append(out.keys, rval{k: vSym, s: k.s}), append(out.arr, h.arr[i])
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func symHash(h rval, what string) error {
|
||||
seen := map[string]bool{}
|
||||
for _, k := range h.keys {
|
||||
if k.k != vSym {
|
||||
return fmt.Errorf("%s: unsupported %s key", what, k.kindName())
|
||||
}
|
||||
if seen[k.s] {
|
||||
return fmt.Errorf("%s: duplicate key %s", what, k.s)
|
||||
}
|
||||
seen[k.s] = true
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *parser) newattr(t *rtype, property bool) error {
|
||||
args, err := p.args()
|
||||
if err != nil {
|
||||
@@ -830,7 +1045,10 @@ func (p *parser) newattr(t *rtype, property bool) error {
|
||||
return fmt.Errorf("attribute %s: unsupported arguments", name)
|
||||
}
|
||||
if len(args) == 2 {
|
||||
opts := args[1]
|
||||
opts, err := attrOptions(args[1], property)
|
||||
if err != nil {
|
||||
return fmt.Errorf("attribute %s: %w", name, err)
|
||||
}
|
||||
if v, ok := opts.get("parent"); ok {
|
||||
vals, known := parents[v.s]
|
||||
if v.k != vConst || !known {
|
||||
@@ -860,11 +1078,9 @@ func (p *parser) newattr(t *rtype, property bool) error {
|
||||
}
|
||||
}
|
||||
if property {
|
||||
t.addProp(a)
|
||||
} else {
|
||||
t.params = append(t.params, a)
|
||||
return t.addProp(a)
|
||||
}
|
||||
return nil
|
||||
return t.addParam(a)
|
||||
}
|
||||
|
||||
func features(v rval) ([]string, error) {
|
||||
@@ -1327,6 +1543,9 @@ func (p *parser) primary() (rval, error) {
|
||||
if c, ok := p.consts[path]; ok {
|
||||
return c, nil
|
||||
}
|
||||
if p.defined != nil && !p.defined[path] {
|
||||
return rval{}, fmt.Errorf("uninitialized constant %s", path)
|
||||
}
|
||||
return rval{k: vConst, s: path}, nil
|
||||
case tOp:
|
||||
switch t.text {
|
||||
@@ -1424,6 +1643,9 @@ func str(v rval, ok bool) (string, bool) {
|
||||
}
|
||||
|
||||
func resourceAPIType(def rval) (*rtype, error) {
|
||||
if err := symHash(def, "register_type"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
name, ok := str(def.get("name"))
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("register_type: name must be a string")
|
||||
@@ -1443,7 +1665,13 @@ func resourceAPIType(def rval) (*rtype, error) {
|
||||
if !ok || attrs.k != vHash {
|
||||
return nil, fmt.Errorf("register_type: attributes must be a literal hash")
|
||||
}
|
||||
for _, opts := range attrs.arr {
|
||||
if err := symHash(attrs, "register_type attributes"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i, opts := range attrs.arr {
|
||||
if err := symHash(opts, "attribute "+attrs.keys[i].s); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for j, k := range opts.keys {
|
||||
if k.k == vSym && k.s == "behavior" {
|
||||
if _, both := opts.get("behaviour"); both {
|
||||
@@ -1460,11 +1688,12 @@ func resourceAPIType(def rval) (*rtype, error) {
|
||||
insyncable = true
|
||||
}
|
||||
}
|
||||
if feats, _ := def.get("features"); !insyncable && feats.k == vArray {
|
||||
for _, f := range feats.arr {
|
||||
if f.s == "custom_insync" {
|
||||
t.props = append(t.props, &attr{name: "rsapi_custom_insync_trigger", doc: "A hidden property which enables a type with custom insync to perform an insync check without specifying any insyncable properties (a Enum[do_not_specify_in_manifest])"})
|
||||
}
|
||||
if feats, ok := def.get("features"); ok {
|
||||
if feats.k != vArray {
|
||||
return nil, fmt.Errorf("register_type: features must be a literal array")
|
||||
}
|
||||
if !insyncable && slices.ContainsFunc(feats.arr, func(f rval) bool { return f.k == vStr && f.s == "custom_insync" }) {
|
||||
t.props = append(t.props, &attr{name: "rsapi_custom_insync_trigger", doc: "A hidden property which enables a type with custom insync to perform an insync check without specifying any insyncable properties (a Enum[do_not_specify_in_manifest])"})
|
||||
}
|
||||
}
|
||||
for i, k := range attrs.keys {
|
||||
@@ -1473,10 +1702,11 @@ func resourceAPIType(def rval) (*rtype, error) {
|
||||
if !ok || opts.k != vHash {
|
||||
return nil, fmt.Errorf("register_type: attribute %d must be name => hash", i)
|
||||
}
|
||||
typ, ok := str(opts.get("type"))
|
||||
if !ok {
|
||||
tv, ok := opts.get("type")
|
||||
if !ok || tv.k != vStr {
|
||||
return nil, fmt.Errorf("attribute %s: type must be a string", an)
|
||||
}
|
||||
typ := tv.s
|
||||
bv, hasB := opts.get("behaviour")
|
||||
if hasB && bv.k != vSym {
|
||||
return nil, fmt.Errorf("attribute %s: behaviour must be a symbol", an)
|
||||
@@ -1494,11 +1724,15 @@ func resourceAPIType(def rval) (*rtype, error) {
|
||||
case behaviour != "parameter" && behaviour != "read_only" && behaviour != "init_only":
|
||||
return nil, fmt.Errorf("attribute %s: invalid behaviour %s", an, behaviour)
|
||||
}
|
||||
rsapiValues(a, typ)
|
||||
if err := rsapiValues(a, typ); err != nil {
|
||||
return nil, fmt.Errorf("attribute %s: %w", an, err)
|
||||
}
|
||||
add := t.addParam
|
||||
if property {
|
||||
t.addProp(a)
|
||||
} else {
|
||||
t.params = append(t.params, a)
|
||||
add = t.addProp
|
||||
}
|
||||
if err := add(a); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
t.custom = true
|
||||
@@ -1507,6 +1741,9 @@ func resourceAPIType(def rval) (*rtype, error) {
|
||||
return nil, fmt.Errorf("title_patterns must be a literal array")
|
||||
}
|
||||
for _, e := range tp.arr {
|
||||
if err := symHash(e, "title_patterns"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
re, ok := e.get("pattern")
|
||||
if e.k != vHash || !ok || re.k != vRegex {
|
||||
return nil, fmt.Errorf("title_patterns entries need a literal regex pattern")
|
||||
@@ -1529,13 +1766,13 @@ func resourceAPIType(def rval) (*rtype, error) {
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func rsapiValues(a *attr, typ string) {
|
||||
inner := strings.TrimSpace(typ)
|
||||
if strings.HasPrefix(inner, "Optional[") && strings.HasSuffix(inner, "]") {
|
||||
inner = strings.TrimSpace(inner[len("Optional[") : len(inner)-1])
|
||||
// rsapiValues adds the values puppet-resource_api's ValueCreator.create_values defines for typ.
|
||||
func rsapiValues(a *attr, typ string) error {
|
||||
base, err := parsePType(typ)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
base, _, _ := strings.Cut(inner, "[")
|
||||
switch strings.TrimSpace(base) {
|
||||
switch base {
|
||||
case "String":
|
||||
a.addValue("", ®ex{})
|
||||
case "Boolean":
|
||||
@@ -1552,4 +1789,74 @@ func rsapiValues(a *attr, typ string) {
|
||||
a.addValue("absent", nil)
|
||||
a.addValue("present", nil)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// providerOf returns the name and symbol parent of the one top-level Puppet::Type.type(:typ).provide call in a provider file,
|
||||
// or no name when the file makes no provide call; any other Puppet::Type statement or provide call is an error.
|
||||
func providerOf(src, typ string) (name, parent string, err error) {
|
||||
defer guard(&err)
|
||||
toks, err := lex(src)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
p := &parser{toks: toks, consts: map[string]rval{}, used: map[int]bool{}}
|
||||
calls := 0
|
||||
for i, t := range toks {
|
||||
if t.kind == tIdent && t.text == "provide" && i > 0 && toks[i-1].text == "." {
|
||||
calls++
|
||||
}
|
||||
}
|
||||
stmt := func() (bool, error) {
|
||||
if !p.is(tConst, "Puppet") || p.at(1).text != "::" || p.at(2).text != "Type" {
|
||||
return false, nil
|
||||
}
|
||||
if name != "" || p.at(3).text != "." || p.at(4).text != "type" || p.at(5).text != "(" {
|
||||
return true, fmt.Errorf("unsupported %s", p.construct())
|
||||
}
|
||||
p.i += 5
|
||||
args, err := p.args()
|
||||
if err != nil {
|
||||
return true, err
|
||||
}
|
||||
if len(args) != 1 || args[0].k != vSym && args[0].k != vStr || args[0].s != typ {
|
||||
return true, fmt.Errorf("provide must target Puppet::Type.type(:%s)", typ)
|
||||
}
|
||||
if !p.op(".") || p.at(1).text != "provide" {
|
||||
return true, fmt.Errorf("unsupported %s", p.construct())
|
||||
}
|
||||
p.i += 2
|
||||
if args, err = p.args(); err != nil {
|
||||
return true, err
|
||||
}
|
||||
if len(args) == 0 || len(args) > 2 || args[0].k != vSym && args[0].k != vStr || len(args) == 2 && args[1].k != vHash {
|
||||
return true, fmt.Errorf("unsupported provide arguments")
|
||||
}
|
||||
name = args[0].s
|
||||
if len(args) == 2 {
|
||||
if err := symHash(args[1], "provide "+name); err != nil {
|
||||
return true, err
|
||||
}
|
||||
if v, ok := args[1].get("parent"); ok {
|
||||
switch v.k {
|
||||
case vSym, vStr:
|
||||
parent = v.s
|
||||
case vConst:
|
||||
default:
|
||||
return true, fmt.Errorf("unsupported provider parent %s", v.kindName())
|
||||
}
|
||||
}
|
||||
}
|
||||
if p.is(tIdent, "do") || p.op("{") {
|
||||
return true, p.skipBlock()
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
if err := p.body("", stmt); err != nil {
|
||||
return "", "", p.wrap(err)
|
||||
}
|
||||
if name == "" && calls > 0 || name != "" && calls != 1 {
|
||||
return "", "", fmt.Errorf("unsupported provide call")
|
||||
}
|
||||
return name, parent, nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,334 @@
|
||||
package gentypes
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"regexp"
|
||||
"regexp/syntax"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ptype is a Resource API type string parsed the way Puppet::Pops::Types::TypeParser does,
|
||||
// limited to the forms whose result puppet-resource_api's ValueCreator.create_values can be decided for.
|
||||
type ptype struct {
|
||||
name string
|
||||
canon string
|
||||
kids []*ptype
|
||||
}
|
||||
|
||||
type tparser struct {
|
||||
s string
|
||||
pos int
|
||||
}
|
||||
|
||||
var (
|
||||
intLit = regexp.MustCompile(`^(?:0|[1-9][0-9]*)$`)
|
||||
floatLit = regexp.MustCompile(`^(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$`)
|
||||
enumWord = regexp.MustCompile(`^[a-z][a-z0-9_]*$`)
|
||||
typeName = regexp.MustCompile(`^[A-Z][A-Za-z0-9_]*`)
|
||||
puppetKws = set("and application attr case class consumes default define else elsif environment false function if import in inherits node or private produces site true type undef unless plan apply")
|
||||
// Onigmo syntax RE2 accepts with another meaning, or accepts where Ruby raises.
|
||||
reUnsafe = regexp.MustCompile(`\(\?P|\(\?[imsU-]*[sU]|\\[pPxQEC0-9]|\[\^?\]`)
|
||||
)
|
||||
|
||||
// parsePType returns the value category ValueCreator sees after unwrapping one Optional:
|
||||
// String, Boolean, Integer, Float, Numeric, or "" for any other type.
|
||||
func parsePType(s string) (string, error) {
|
||||
p := &tparser{s: s}
|
||||
t, err := p.typ(0)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("type %q: %w", s, err)
|
||||
}
|
||||
if p.skip(); p.pos != len(p.s) {
|
||||
return "", fmt.Errorf("type %q: unsupported trailing input", s)
|
||||
}
|
||||
if t, err = normalize(t); err != nil {
|
||||
return "", fmt.Errorf("type %q: %w", s, err)
|
||||
}
|
||||
if t.name == "Optional" {
|
||||
if len(t.kids) == 0 {
|
||||
return "", nil
|
||||
}
|
||||
t = t.kids[0]
|
||||
}
|
||||
switch t.name {
|
||||
case "String", "Boolean", "Integer", "Float", "Numeric":
|
||||
return t.name, nil
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// normalize mirrors PVariantType.maybe_create: flatten nested variants, drop eql duplicates, collapse a single member.
|
||||
// Members are only known eql when their canonical text matches, so a choice it cannot decide is an error.
|
||||
func normalize(t *ptype) (*ptype, error) {
|
||||
switch t.name {
|
||||
case "Optional":
|
||||
if len(t.kids) == 0 {
|
||||
return t, nil
|
||||
}
|
||||
k, err := normalize(t.kids[0])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &ptype{name: "Optional", canon: "Optional[" + k.canon + "]", kids: []*ptype{k}}, nil
|
||||
case "Variant":
|
||||
if len(t.kids) == 0 {
|
||||
return t, nil
|
||||
}
|
||||
var members []*ptype
|
||||
seen := map[string]bool{}
|
||||
for _, k := range t.kids {
|
||||
k, err := normalize(k)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
flat := []*ptype{k}
|
||||
if k.name == "Variant" && len(k.kids) > 0 {
|
||||
flat = k.kids
|
||||
}
|
||||
for _, m := range flat {
|
||||
if !seen[m.canon] {
|
||||
seen[m.canon] = true
|
||||
members = append(members, m)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(members) == 1 {
|
||||
return members[0], nil
|
||||
}
|
||||
for i, a := range members {
|
||||
for _, b := range members[i+1:] {
|
||||
if a.name == b.name && a.name != "" {
|
||||
return nil, fmt.Errorf("cannot tell whether %s and %s are the same type", a.canon, b.canon)
|
||||
}
|
||||
}
|
||||
}
|
||||
canon := make([]string, len(members))
|
||||
for i, m := range members {
|
||||
canon[i] = m.canon
|
||||
}
|
||||
return &ptype{name: "Variant", canon: "Variant[" + strings.Join(canon, ",") + "]", kids: members}, nil
|
||||
}
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func (p *tparser) skip() {
|
||||
for p.pos < len(p.s) && strings.IndexByte(" \t\r\n", p.s[p.pos]) >= 0 {
|
||||
p.pos++
|
||||
}
|
||||
}
|
||||
|
||||
func (p *tparser) peek() byte {
|
||||
p.skip()
|
||||
if p.pos < len(p.s) {
|
||||
return p.s[p.pos]
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type targ struct {
|
||||
t *ptype
|
||||
text string
|
||||
kind byte // 't' type, 'i' integer, 'f' float, 'd' default, 's' string, 'w' word, 'r' regex
|
||||
}
|
||||
|
||||
func (p *tparser) typ(depth int) (*ptype, error) {
|
||||
if depth > maxDepth {
|
||||
return nil, fmt.Errorf("nesting deeper than %d: %w", maxDepth, errLimit)
|
||||
}
|
||||
p.skip()
|
||||
name := typeName.FindString(p.s[p.pos:])
|
||||
if name == "" || p.pos+len(name) < len(p.s) && p.s[p.pos+len(name)] == ':' {
|
||||
return nil, fmt.Errorf("unsupported type at offset %d", p.pos)
|
||||
}
|
||||
p.pos += len(name)
|
||||
var args []targ
|
||||
hasArgs := p.peek() == '['
|
||||
if hasArgs {
|
||||
p.pos++
|
||||
for {
|
||||
if p.peek() == ']' {
|
||||
p.pos++
|
||||
break
|
||||
}
|
||||
a, err := p.arg(depth)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
args = append(args, a)
|
||||
if c := p.peek(); c == ',' {
|
||||
p.pos++
|
||||
} else if c != ']' {
|
||||
return nil, fmt.Errorf("expected , or ] at offset %d", p.pos)
|
||||
}
|
||||
}
|
||||
if len(args) == 0 {
|
||||
return nil, fmt.Errorf("%s[] takes parameters", name)
|
||||
}
|
||||
}
|
||||
t := &ptype{name: name}
|
||||
kinds := ""
|
||||
texts := make([]string, len(args))
|
||||
for i, a := range args {
|
||||
kinds += string(a.kind)
|
||||
texts[i] = a.text
|
||||
if a.t != nil {
|
||||
t.kids = append(t.kids, a.t)
|
||||
}
|
||||
}
|
||||
t.canon = name
|
||||
if hasArgs {
|
||||
t.canon += "[" + strings.Join(texts, ",") + "]"
|
||||
}
|
||||
ok := false
|
||||
switch name {
|
||||
case "String":
|
||||
ok = rangeArgs(kinds, args, false)
|
||||
case "Integer":
|
||||
ok = rangeArgs(kinds, args, false)
|
||||
case "Float":
|
||||
ok = rangeArgs(kinds, args, true)
|
||||
case "Numeric", "Boolean":
|
||||
ok = !hasArgs
|
||||
case "Optional":
|
||||
ok = kinds == "" || kinds == "t" || kinds == "s"
|
||||
if kinds == "s" {
|
||||
t.kids = []*ptype{{name: "String", canon: "String[" + texts[0] + "]"}}
|
||||
}
|
||||
case "Variant":
|
||||
ok = !strings.ContainsFunc(kinds, func(r rune) bool { return r != 't' })
|
||||
case "Enum", "Pattern", "Array", "Hash", "Sensitive":
|
||||
t.name = ""
|
||||
switch name {
|
||||
case "Enum":
|
||||
ok = hasArgs && !strings.ContainsFunc(kinds, func(r rune) bool { return r != 's' && r != 'w' })
|
||||
case "Pattern":
|
||||
ok = hasArgs && !strings.ContainsFunc(kinds, func(r rune) bool { return r != 's' && r != 'r' })
|
||||
for i, a := range args {
|
||||
if a.kind == 's' && !rubyRegexp(unquote(texts[i])) {
|
||||
return nil, fmt.Errorf("unsupported regex %s", texts[i])
|
||||
}
|
||||
}
|
||||
case "Array":
|
||||
ok = kinds == "" || len(kinds) <= 3 && kinds[0] == 't' && rangeArgs(kinds[1:], args[1:], false)
|
||||
case "Hash":
|
||||
ok = kinds == "" || kinds == "tt" || len(kinds) == 4 && kinds[:2] == "tt" && rangeArgs(kinds[2:], args[2:], false)
|
||||
case "Sensitive":
|
||||
ok = kinds == "" || kinds == "t"
|
||||
}
|
||||
}
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unsupported %s", t.canon)
|
||||
}
|
||||
return t, nil
|
||||
}
|
||||
|
||||
// rangeArgs accepts [], [min] and [min, max] of integers (or floats) and default, rejecting min > max as TypeParser does.
|
||||
func rangeArgs(kinds string, args []targ, float bool) bool {
|
||||
if len(kinds) > 2 || strings.ContainsFunc(kinds, func(r rune) bool { return r != 'i' && r != 'd' && (!float || r != 'f') }) {
|
||||
return false
|
||||
}
|
||||
if kinds != "ii" && kinds != "if" && kinds != "fi" && kinds != "ff" {
|
||||
return true
|
||||
}
|
||||
a, _, err1 := big.ParseFloat(args[0].text, 10, 256, big.ToNearestEven)
|
||||
b, _, err2 := big.ParseFloat(args[1].text, 10, 256, big.ToNearestEven)
|
||||
return err1 == nil && err2 == nil && a.Cmp(b) <= 0
|
||||
}
|
||||
|
||||
func (p *tparser) arg(depth int) (targ, error) {
|
||||
c := p.peek()
|
||||
switch {
|
||||
case c >= 'A' && c <= 'Z':
|
||||
t, err := p.typ(depth + 1)
|
||||
if err != nil {
|
||||
return targ{}, err
|
||||
}
|
||||
return targ{t: t, text: t.canon, kind: 't'}, nil
|
||||
case c == '-' || c >= '0' && c <= '9':
|
||||
neg := c == '-'
|
||||
if neg {
|
||||
p.pos++
|
||||
p.skip()
|
||||
}
|
||||
s := p.pos
|
||||
for p.pos < len(p.s) {
|
||||
c := p.s[p.pos]
|
||||
sign := c == '+' || c == '-'
|
||||
if strings.IndexByte("0123456789.eE_xXabcdefABCDEF", c) < 0 && (!sign || p.pos == s || p.s[p.pos-1] != 'e' && p.s[p.pos-1] != 'E') {
|
||||
break
|
||||
}
|
||||
p.pos++
|
||||
}
|
||||
text := p.s[s:p.pos]
|
||||
if neg {
|
||||
text = "-" + text
|
||||
}
|
||||
switch {
|
||||
case intLit.MatchString(strings.TrimPrefix(text, "-")):
|
||||
if _, err := strconv.ParseInt(text, 10, 64); err != nil {
|
||||
return targ{}, fmt.Errorf("unsupported integer %s", text)
|
||||
}
|
||||
return targ{text: text, kind: 'i'}, nil
|
||||
case floatLit.MatchString(strings.TrimPrefix(text, "-")):
|
||||
return targ{text: text, kind: 'f'}, nil
|
||||
}
|
||||
return targ{}, fmt.Errorf("unsupported number %s", text)
|
||||
case c == '\'':
|
||||
s := p.pos
|
||||
for p.pos++; p.pos < len(p.s) && p.s[p.pos] != '\''; p.pos++ {
|
||||
if p.s[p.pos] == '\\' {
|
||||
p.pos++
|
||||
}
|
||||
}
|
||||
if p.pos >= len(p.s) {
|
||||
return targ{}, fmt.Errorf("unterminated string")
|
||||
}
|
||||
p.pos++
|
||||
return targ{text: p.s[s:p.pos], kind: 's'}, nil
|
||||
case c == '/':
|
||||
s := p.pos
|
||||
for p.pos++; p.pos < len(p.s) && p.s[p.pos] != '/'; p.pos++ {
|
||||
if p.s[p.pos] == '\\' {
|
||||
p.pos++
|
||||
}
|
||||
}
|
||||
if p.pos >= len(p.s) {
|
||||
return targ{}, fmt.Errorf("unterminated regex")
|
||||
}
|
||||
p.pos++
|
||||
text := p.s[s:p.pos]
|
||||
if !rubyRegexp(strings.ReplaceAll(text[1:len(text)-1], `\/`, "/")) {
|
||||
return targ{}, fmt.Errorf("unsupported regex %s", text)
|
||||
}
|
||||
return targ{text: text, kind: 'r'}, nil
|
||||
case c >= 'a' && c <= 'z':
|
||||
s := p.pos
|
||||
for p.pos < len(p.s) && (isIdentChar(p.s[p.pos]) && p.s[p.pos] < 0x80) {
|
||||
p.pos++
|
||||
}
|
||||
w := p.s[s:p.pos]
|
||||
switch {
|
||||
case w == "default":
|
||||
return targ{text: w, kind: 'd'}, nil
|
||||
case enumWord.MatchString(w) && !puppetKws[w] && p.peek() != ':':
|
||||
return targ{text: "'" + w + "'", kind: 'w'}, nil
|
||||
}
|
||||
return targ{}, fmt.Errorf("unsupported word %s", w)
|
||||
}
|
||||
return targ{}, fmt.Errorf("unsupported parameter at offset %d", p.pos)
|
||||
}
|
||||
|
||||
func unquote(s string) string {
|
||||
return strings.NewReplacer(`\\`, `\`, `\'`, `'`).Replace(s[1 : len(s)-1])
|
||||
}
|
||||
|
||||
// rubyRegexp reports whether Ruby's Regexp.new surely accepts src: RE2 parses it and it avoids syntax the engines disagree on.
|
||||
func rubyRegexp(src string) bool {
|
||||
if reUnsafe.MatchString(src) {
|
||||
return false
|
||||
}
|
||||
_, err := syntax.Parse(src, syntax.Perl)
|
||||
return err == nil
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
class Puppet::Provider::RProvClass
|
||||
end
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
Puppet::Type.type(:r_prov_name).provide(:other) do
|
||||
desc ''
|
||||
end
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
Puppet::Type.type(:r_prov_parent).provide(:a) do
|
||||
end
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
require 'json'
|
||||
Puppet::Type.type(:r_prov_parent).provide :b, parent: :a do
|
||||
end
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
Puppet::Type.type(:r_prov_parent_missing).provide(:a, parent: :nope) do
|
||||
end
|
||||
@@ -0,0 +1,3 @@
|
||||
Type.newtype(:r_bare) do
|
||||
newparam(:name, namevar: true)
|
||||
end
|
||||
@@ -0,0 +1,10 @@
|
||||
begin
|
||||
require 'ipaddr'
|
||||
rescue LoadError => e
|
||||
Puppet.warning("#{__FILE__}: #{e}")
|
||||
end
|
||||
DOC = 'Literal doc.'.freeze
|
||||
Puppet::Type.newtype(:r_begin) do
|
||||
@doc = DOC
|
||||
newparam(:name, namevar: true)
|
||||
end
|
||||
@@ -0,0 +1,4 @@
|
||||
X = File.join('a', 'b')
|
||||
Puppet::Type.newtype(:r_const_call) do
|
||||
newparam(:name, namevar: true)
|
||||
end
|
||||
@@ -0,0 +1,4 @@
|
||||
Puppet::Type.newtype(:r_dollar) do
|
||||
newparam(:name, namevar: true)
|
||||
end
|
||||
$
|
||||
@@ -0,0 +1,5 @@
|
||||
Puppet::Type.newtype(:r_dup_ensure) do
|
||||
newparam(:name, namevar: true)
|
||||
ensurable
|
||||
newproperty(:ensure)
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
Puppet::Type.newtype(:r_dup_param) do
|
||||
newparam(:name, namevar: true)
|
||||
newparam(:a)
|
||||
newparam(:a)
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
Puppet::Type.newtype(:r_dup_prop) do
|
||||
newparam(:name, namevar: true)
|
||||
newproperty(:a)
|
||||
newproperty(:a)
|
||||
end
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
Puppet::Type.newtype(:r_feature_const) do
|
||||
feature :x, 'doc', methods: [RNope]
|
||||
newparam(:name, namevar: true)
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
module RHelper
|
||||
def self.add(type)
|
||||
type.newparam(:extra)
|
||||
end
|
||||
end
|
||||
Puppet::Type.newtype(:r_helper) do
|
||||
newparam(:name, namevar: true)
|
||||
end
|
||||
RHelper.add(Puppet::Type.type(:r_helper))
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
Puppet::Type.newtype(:r_include_noreq) do
|
||||
include PuppetX::Review::Mix
|
||||
newparam(:name, namevar: true)
|
||||
end
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
require 'puppet_x/review/mix'
|
||||
Puppet::Type.newtype(:r_include_req) do
|
||||
include PuppetX::Review::Mix
|
||||
newparam(:name, namevar: true)
|
||||
newproperty(:a)
|
||||
end
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
Puppet::Type.newtype(:r_inline_provide) do
|
||||
newparam(:name, namevar: true)
|
||||
end
|
||||
Puppet::Type.type(:r_inline_provide).provide(:inline) {}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
module Puppet::RCompact
|
||||
Type.newtype(:r_mod_compact) do
|
||||
newparam(:name, namevar: true)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
module RFoo
|
||||
Type.newtype(:r_mod_foo) do
|
||||
newparam(:name, namevar: true)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
module Puppet
|
||||
Type.newtype(:r_mod_puppet) do
|
||||
newparam(:name, namevar: true)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
Puppet::Type.newtype(:r_param_prop) do
|
||||
newparam(:name, namevar: true)
|
||||
newparam(:a)
|
||||
newproperty(:a)
|
||||
end
|
||||
@@ -0,0 +1,3 @@
|
||||
Puppet::Type.newtype(:r_prov_class) do
|
||||
newparam(:name, namevar: true)
|
||||
end
|
||||
@@ -0,0 +1,3 @@
|
||||
Puppet::Type.newtype(:r_prov_empty) do
|
||||
newparam(:name, namevar: true)
|
||||
end
|
||||
@@ -0,0 +1,3 @@
|
||||
Puppet::Type.newtype(:r_prov_name) do
|
||||
newparam(:name, namevar: true)
|
||||
end
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
Puppet::Type.newtype(:r_prov_parent) do
|
||||
newparam(:name, namevar: true)
|
||||
end
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
Puppet::Type.newtype(:r_prov_parent_missing) do
|
||||
newparam(:name, namevar: true)
|
||||
end
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
require 'puppet_x/review/nope'
|
||||
Puppet::Type.newtype(:r_require_missing) do
|
||||
newparam(:name, namevar: true)
|
||||
end
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
require 'puppet/resource_api'
|
||||
Puppet::ResourceApi.register_type(
|
||||
name: 'r_rs_bad_lower',
|
||||
attributes: {
|
||||
name: { type: 'String', desc: 'n', behaviour: :namevar },
|
||||
a: { type: 'string', desc: 'a' },
|
||||
},
|
||||
)
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
require 'puppet/resource_api'
|
||||
Puppet::ResourceApi.register_type(
|
||||
name: 'r_rs_bad_range',
|
||||
attributes: {
|
||||
name: { type: 'String', desc: 'n', behaviour: :namevar },
|
||||
a: { type: 'Integer[5,1]', desc: 'a' },
|
||||
},
|
||||
)
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
require 'puppet/resource_api'
|
||||
Puppet::ResourceApi.register_type(
|
||||
name: 'r_rs_bad_regex',
|
||||
attributes: {
|
||||
name: { type: 'String', desc: 'n', behaviour: :namevar },
|
||||
a: { type: 'Pattern[/(/]', desc: 'a' },
|
||||
},
|
||||
)
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
require 'puppet/resource_api'
|
||||
Puppet::ResourceApi.register_type(
|
||||
name: 'r_rs_bad_uncertain',
|
||||
attributes: {
|
||||
name: { type: 'String', desc: 'n', behaviour: :namevar },
|
||||
a: { type: 'Variant[String, String[0]]', desc: 'a' },
|
||||
},
|
||||
)
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
require 'puppet/resource_api'
|
||||
Puppet::ResourceApi.register_type(
|
||||
name: 'r_rs_bad_undef',
|
||||
attributes: {
|
||||
name: { type: 'String', desc: 'n', behaviour: :namevar },
|
||||
a: { type: 'Variant[String, Undef]', desc: 'a' },
|
||||
},
|
||||
)
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
require 'puppet/resource_api'
|
||||
Puppet::ResourceApi.register_type(
|
||||
name: 'r_rs_bad_words',
|
||||
attributes: {
|
||||
name: { type: 'String', desc: 'n', behaviour: :namevar },
|
||||
a: { type: 'Enum[if]', desc: 'a' },
|
||||
},
|
||||
)
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
require 'puppet/resource_api'
|
||||
Puppet::ResourceApi.register_type(
|
||||
name: 'r_rs_str_feature',
|
||||
features: ['custom_insync'],
|
||||
attributes: {
|
||||
name: { type: 'String', desc: 'n', behaviour: :namevar },
|
||||
},
|
||||
)
|
||||
@@ -0,0 +1,7 @@
|
||||
require 'puppet/resource_api'
|
||||
Puppet::ResourceApi.register_type(
|
||||
'name' => 'r_rs_str_key',
|
||||
'attributes' => {
|
||||
'name' => { 'type' => 'String', 'behaviour' => :namevar },
|
||||
},
|
||||
)
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
require 'puppet/resource_api'
|
||||
Puppet::ResourceApi.register_type(
|
||||
name: 'r_rs_sym_feature',
|
||||
features: [:custom_insync],
|
||||
attributes: {
|
||||
name: { type: 'String', desc: 'n', behaviour: :namevar },
|
||||
},
|
||||
)
|
||||
@@ -0,0 +1,18 @@
|
||||
require 'puppet/resource_api'
|
||||
Puppet::ResourceApi.register_type(
|
||||
name: 'r_rs_types',
|
||||
attributes: {
|
||||
name: { type: 'String', desc: 'n', behaviour: :namevar },
|
||||
a: { type: 'Variant[String]', desc: 'a' },
|
||||
b: { type: 'Optional[Variant[Integer]]', desc: 'b' },
|
||||
c: { type: 'Variant[Optional[String]]', desc: 'c' },
|
||||
d: { type: 'Variant[Integer[ 1 , 2 ], Integer[1,2]]', desc: 'd' },
|
||||
e: { type: "Optional['x']", desc: 'e' },
|
||||
f: { type: 'Optional[Optional[String]]', desc: 'f' },
|
||||
g: { type: 'Optional[Variant[String[1], Integer]]', desc: 'g' },
|
||||
h: { type: 'Variant[Float[0.5, 1], Numeric]', desc: 'h' },
|
||||
i: { type: 'Optional[Variant[Pattern[/^a\/b$/], Array[Enum[x, \'y\']]]]', desc: 'i' },
|
||||
j: { type: 'Integer[-5,default]', desc: 'j' },
|
||||
k: { type: 'Variant[Boolean,Boolean]', desc: 'k' },
|
||||
},
|
||||
)
|
||||
@@ -0,0 +1,4 @@
|
||||
Puppet::Type.newtype(:r_send) do
|
||||
newparam(:name, namevar: true)
|
||||
end
|
||||
Puppet::Type.type(:r_send).send(:newparam, :extra)
|
||||
@@ -0,0 +1,6 @@
|
||||
require 'puppet/parameter/boolean'
|
||||
Puppet::Type.newtype(:r_str_keys) do
|
||||
newparam(:path, 'namevar' => true)
|
||||
newparam(:flag, 'parent' => Puppet::Parameter::Boolean)
|
||||
newproperty(:p, 'required_features' => 'feat')
|
||||
end
|
||||
@@ -0,0 +1,10 @@
|
||||
module PuppetX
|
||||
module Review
|
||||
module Mix
|
||||
VERSION = '1'
|
||||
def exists?; end
|
||||
def create; end
|
||||
def destroy; end
|
||||
end
|
||||
end
|
||||
end
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
# This file was automatically generated on 2026-11-08 20:40:47 +1100.
|
||||
# Use the 'puppet generate types' command to regenerate this file.
|
||||
|
||||
# Literal doc.
|
||||
Puppet::Resource::ResourceType3.new(
|
||||
'r_begin',
|
||||
[
|
||||
|
||||
],
|
||||
[
|
||||
Puppet::Resource::Param(Any, 'name', true)
|
||||
],
|
||||
{
|
||||
/(?m-ix:(.*))/ => ['name']
|
||||
},
|
||||
true,
|
||||
false)
|
||||
@@ -0,0 +1,16 @@
|
||||
# This file was automatically generated on 2026-11-08 20:40:47 +1100.
|
||||
# Use the 'puppet generate types' command to regenerate this file.
|
||||
|
||||
Puppet::Resource::ResourceType3.new(
|
||||
'r_const_call',
|
||||
[
|
||||
|
||||
],
|
||||
[
|
||||
Puppet::Resource::Param(Any, 'name', true)
|
||||
],
|
||||
{
|
||||
/(?m-ix:(.*))/ => ['name']
|
||||
},
|
||||
true,
|
||||
false)
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
# This file was automatically generated on 2026-11-08 20:40:47 +1100.
|
||||
# Use the 'puppet generate types' command to regenerate this file.
|
||||
|
||||
Puppet::Resource::ResourceType3.new(
|
||||
'r_helper',
|
||||
[
|
||||
|
||||
],
|
||||
[
|
||||
Puppet::Resource::Param(Any, 'name', true),
|
||||
|
||||
Puppet::Resource::Param(Any, 'extra')
|
||||
],
|
||||
{
|
||||
/(?m-ix:(.*))/ => ['name']
|
||||
},
|
||||
true,
|
||||
false)
|
||||
@@ -0,0 +1,21 @@
|
||||
# This file was automatically generated on 2026-11-08 20:40:47 +1100.
|
||||
# Use the 'puppet generate types' command to regenerate this file.
|
||||
|
||||
Puppet::Resource::ResourceType3.new(
|
||||
'r_include_req',
|
||||
[
|
||||
# The basic property that the resource should be in.
|
||||
#
|
||||
# Valid values are `present`, `absent`.
|
||||
Puppet::Resource::Param(Enum['present', 'absent'], 'ensure'),
|
||||
|
||||
Puppet::Resource::Param(Any, 'a')
|
||||
],
|
||||
[
|
||||
Puppet::Resource::Param(Any, 'name', true)
|
||||
],
|
||||
{
|
||||
/(?m-ix:(.*))/ => ['name']
|
||||
},
|
||||
true,
|
||||
false)
|
||||
@@ -0,0 +1,24 @@
|
||||
# This file was automatically generated on 2026-11-08 20:40:47 +1100.
|
||||
# Use the 'puppet generate types' command to regenerate this file.
|
||||
|
||||
Puppet::Resource::ResourceType3.new(
|
||||
'r_inline_provide',
|
||||
[
|
||||
|
||||
],
|
||||
[
|
||||
Puppet::Resource::Param(Any, 'name', true),
|
||||
|
||||
# The specific backend to use for this `r_inline_provide`
|
||||
# resource. You will seldom need to specify this --- OpenVox will usually
|
||||
# discover the appropriate provider for your platform.Available providers are:
|
||||
#
|
||||
# inline
|
||||
# :
|
||||
Puppet::Resource::Param(Any, 'provider')
|
||||
],
|
||||
{
|
||||
/(?m-ix:(.*))/ => ['name']
|
||||
},
|
||||
true,
|
||||
false)
|
||||
@@ -0,0 +1,16 @@
|
||||
# This file was automatically generated on 2026-11-08 20:40:47 +1100.
|
||||
# Use the 'puppet generate types' command to regenerate this file.
|
||||
|
||||
Puppet::Resource::ResourceType3.new(
|
||||
'r_mod_puppet',
|
||||
[
|
||||
|
||||
],
|
||||
[
|
||||
Puppet::Resource::Param(Any, 'name', true)
|
||||
],
|
||||
{
|
||||
/(?m-ix:(.*))/ => ['name']
|
||||
},
|
||||
true,
|
||||
false)
|
||||
@@ -0,0 +1,18 @@
|
||||
# This file was automatically generated on 2026-11-08 20:40:47 +1100.
|
||||
# Use the 'puppet generate types' command to regenerate this file.
|
||||
|
||||
Puppet::Resource::ResourceType3.new(
|
||||
'r_param_prop',
|
||||
[
|
||||
Puppet::Resource::Param(Any, 'a')
|
||||
],
|
||||
[
|
||||
Puppet::Resource::Param(Any, 'name', true),
|
||||
|
||||
Puppet::Resource::Param(Any, 'a')
|
||||
],
|
||||
{
|
||||
/(?m-ix:(.*))/ => ['name']
|
||||
},
|
||||
true,
|
||||
false)
|
||||
@@ -0,0 +1,16 @@
|
||||
# This file was automatically generated on 2026-11-08 20:40:47 +1100.
|
||||
# Use the 'puppet generate types' command to regenerate this file.
|
||||
|
||||
Puppet::Resource::ResourceType3.new(
|
||||
'r_prov_class',
|
||||
[
|
||||
|
||||
],
|
||||
[
|
||||
Puppet::Resource::Param(Any, 'name', true)
|
||||
],
|
||||
{
|
||||
/(?m-ix:(.*))/ => ['name']
|
||||
},
|
||||
true,
|
||||
false)
|
||||
@@ -0,0 +1,16 @@
|
||||
# This file was automatically generated on 2026-11-08 20:40:47 +1100.
|
||||
# Use the 'puppet generate types' command to regenerate this file.
|
||||
|
||||
Puppet::Resource::ResourceType3.new(
|
||||
'r_prov_empty',
|
||||
[
|
||||
|
||||
],
|
||||
[
|
||||
Puppet::Resource::Param(Any, 'name', true)
|
||||
],
|
||||
{
|
||||
/(?m-ix:(.*))/ => ['name']
|
||||
},
|
||||
true,
|
||||
false)
|
||||
@@ -0,0 +1,24 @@
|
||||
# This file was automatically generated on 2026-11-08 20:40:47 +1100.
|
||||
# Use the 'puppet generate types' command to regenerate this file.
|
||||
|
||||
Puppet::Resource::ResourceType3.new(
|
||||
'r_prov_name',
|
||||
[
|
||||
|
||||
],
|
||||
[
|
||||
Puppet::Resource::Param(Any, 'name', true),
|
||||
|
||||
# The specific backend to use for this `r_prov_name`
|
||||
# resource. You will seldom need to specify this --- OpenVox will usually
|
||||
# discover the appropriate provider for your platform.Available providers are:
|
||||
#
|
||||
# other
|
||||
# :
|
||||
Puppet::Resource::Param(Any, 'provider')
|
||||
],
|
||||
{
|
||||
/(?m-ix:(.*))/ => ['name']
|
||||
},
|
||||
true,
|
||||
false)
|
||||
@@ -0,0 +1,27 @@
|
||||
# This file was automatically generated on 2026-11-08 20:40:47 +1100.
|
||||
# Use the 'puppet generate types' command to regenerate this file.
|
||||
|
||||
Puppet::Resource::ResourceType3.new(
|
||||
'r_prov_parent',
|
||||
[
|
||||
|
||||
],
|
||||
[
|
||||
Puppet::Resource::Param(Any, 'name', true),
|
||||
|
||||
# The specific backend to use for this `r_prov_parent`
|
||||
# resource. You will seldom need to specify this --- OpenVox will usually
|
||||
# discover the appropriate provider for your platform.Available providers are:
|
||||
#
|
||||
# a
|
||||
# :
|
||||
#
|
||||
# b
|
||||
# :
|
||||
Puppet::Resource::Param(Any, 'provider')
|
||||
],
|
||||
{
|
||||
/(?m-ix:(.*))/ => ['name']
|
||||
},
|
||||
true,
|
||||
false)
|
||||
@@ -0,0 +1,20 @@
|
||||
# This file was automatically generated on 2026-11-08 20:40:47 +1100.
|
||||
# Use the 'puppet generate types' command to regenerate this file.
|
||||
|
||||
Puppet::Resource::ResourceType3.new(
|
||||
'r_rs_bad_uncertain',
|
||||
[
|
||||
# a (a Variant[String, String[0]])
|
||||
Puppet::Resource::Param(Any, 'a')
|
||||
],
|
||||
[
|
||||
# n (a String)
|
||||
#
|
||||
# Values can match `//`.
|
||||
Puppet::Resource::Param(Pattern[//], 'name', true)
|
||||
],
|
||||
{
|
||||
/(?m-ix:(.*))/ => ['name']
|
||||
},
|
||||
true,
|
||||
false)
|
||||
@@ -0,0 +1,20 @@
|
||||
# This file was automatically generated on 2026-11-08 20:40:47 +1100.
|
||||
# Use the 'puppet generate types' command to regenerate this file.
|
||||
|
||||
Puppet::Resource::ResourceType3.new(
|
||||
'r_rs_bad_undef',
|
||||
[
|
||||
# a (a Variant[String, Undef])
|
||||
Puppet::Resource::Param(Any, 'a')
|
||||
],
|
||||
[
|
||||
# n (a String)
|
||||
#
|
||||
# Values can match `//`.
|
||||
Puppet::Resource::Param(Pattern[//], 'name', true)
|
||||
],
|
||||
{
|
||||
/(?m-ix:(.*))/ => ['name']
|
||||
},
|
||||
true,
|
||||
false)
|
||||
@@ -0,0 +1,20 @@
|
||||
# This file was automatically generated on 2026-11-08 20:40:47 +1100.
|
||||
# Use the 'puppet generate types' command to regenerate this file.
|
||||
|
||||
Puppet::Resource::ResourceType3.new(
|
||||
'r_rs_str_feature',
|
||||
[
|
||||
# A hidden property which enables a type with custom insync to perform an insync check without specifying any insyncable properties (a Enum[do_not_specify_in_manifest])
|
||||
Puppet::Resource::Param(Any, 'rsapi_custom_insync_trigger')
|
||||
],
|
||||
[
|
||||
# n (a String)
|
||||
#
|
||||
# Values can match `//`.
|
||||
Puppet::Resource::Param(Pattern[//], 'name', true)
|
||||
],
|
||||
{
|
||||
/(?m-ix:(.*))/ => ['name']
|
||||
},
|
||||
true,
|
||||
false)
|
||||
@@ -0,0 +1,19 @@
|
||||
# This file was automatically generated on 2026-11-08 20:40:47 +1100.
|
||||
# Use the 'puppet generate types' command to regenerate this file.
|
||||
|
||||
Puppet::Resource::ResourceType3.new(
|
||||
'r_rs_sym_feature',
|
||||
[
|
||||
|
||||
],
|
||||
[
|
||||
# n (a String)
|
||||
#
|
||||
# Values can match `//`.
|
||||
Puppet::Resource::Param(Pattern[//], 'name', true)
|
||||
],
|
||||
{
|
||||
/(?m-ix:(.*))/ => ['name']
|
||||
},
|
||||
true,
|
||||
false)
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
# This file was automatically generated on 2026-11-08 20:40:47 +1100.
|
||||
# Use the 'puppet generate types' command to regenerate this file.
|
||||
|
||||
Puppet::Resource::ResourceType3.new(
|
||||
'r_rs_types',
|
||||
[
|
||||
# a (a Variant[String])
|
||||
#
|
||||
# Values can match `//`.
|
||||
Puppet::Resource::Param(Pattern[//], 'a'),
|
||||
|
||||
# b (a Optional[Variant[Integer]])
|
||||
#
|
||||
# Values can match `/^-?\d+$/`.
|
||||
Puppet::Resource::Param(Pattern[/^-?\d+$/], 'b'),
|
||||
|
||||
# c (a Variant[Optional[String]])
|
||||
#
|
||||
# Values can match `//`.
|
||||
Puppet::Resource::Param(Pattern[//], 'c'),
|
||||
|
||||
# d (a Variant[Integer[ 1 , 2 ], Integer[1,2]])
|
||||
#
|
||||
# Values can match `/^-?\d+$/`.
|
||||
Puppet::Resource::Param(Pattern[/^-?\d+$/], 'd'),
|
||||
|
||||
# e (a Optional['x'])
|
||||
#
|
||||
# Values can match `//`.
|
||||
Puppet::Resource::Param(Pattern[//], 'e'),
|
||||
|
||||
# f (a Optional[Optional[String]])
|
||||
Puppet::Resource::Param(Any, 'f'),
|
||||
|
||||
# g (a Optional[Variant[String[1], Integer]])
|
||||
Puppet::Resource::Param(Any, 'g'),
|
||||
|
||||
# h (a Variant[Float[0.5, 1], Numeric])
|
||||
Puppet::Resource::Param(Any, 'h'),
|
||||
|
||||
# i (a Optional[Variant[Pattern[/^a\/b$/], Array[Enum[x, 'y']]]])
|
||||
Puppet::Resource::Param(Any, 'i'),
|
||||
|
||||
# j (a Integer[-5,default])
|
||||
#
|
||||
# Values can match `/^-?\d+$/`.
|
||||
Puppet::Resource::Param(Pattern[/^-?\d+$/], 'j'),
|
||||
|
||||
# k (a Variant[Boolean,Boolean])
|
||||
#
|
||||
# Valid values are `true` (also called `true, true`), `false` (also called `false, false`).
|
||||
Puppet::Resource::Param(Variant[Boolean, Enum['true', 'true', 'true', 'false', 'false', 'false']], 'k')
|
||||
],
|
||||
[
|
||||
# n (a String)
|
||||
#
|
||||
# Values can match `//`.
|
||||
Puppet::Resource::Param(Pattern[//], 'name', true)
|
||||
],
|
||||
{
|
||||
/(?m-ix:(.*))/ => ['name']
|
||||
},
|
||||
true,
|
||||
false)
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
# This file was automatically generated on 2026-11-08 20:40:47 +1100.
|
||||
# Use the 'puppet generate types' command to regenerate this file.
|
||||
|
||||
Puppet::Resource::ResourceType3.new(
|
||||
'r_send',
|
||||
[
|
||||
|
||||
],
|
||||
[
|
||||
Puppet::Resource::Param(Any, 'name', true),
|
||||
|
||||
Puppet::Resource::Param(Any, 'extra')
|
||||
],
|
||||
{
|
||||
/(?m-ix:(.*))/ => ['name']
|
||||
},
|
||||
true,
|
||||
false)
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
# This file was automatically generated on 2026-11-08 20:40:47 +1100.
|
||||
# Use the 'puppet generate types' command to regenerate this file.
|
||||
|
||||
Puppet::Resource::ResourceType3.new(
|
||||
'r_str_keys',
|
||||
[
|
||||
# Requires features feat.
|
||||
Puppet::Resource::Param(Any, 'p')
|
||||
],
|
||||
[
|
||||
Puppet::Resource::Param(Any, 'path'),
|
||||
|
||||
Puppet::Resource::Param(Any, 'flag')
|
||||
],
|
||||
{
|
||||
},
|
||||
true,
|
||||
false)
|
||||
Reference in New Issue
Block a user