[lxc-devel] [distrobuilder/master] shared: Validate action trigger

monstermunchkin on Github lxc-bot at linuxcontainers.org
Wed Apr 4 10:51:47 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 363 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180404/a626a9f2/attachment.bin>
-------------- next part --------------
From d2685bcb1ed0c3f35ca9a456cc33b28946f7593d Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Wed, 4 Apr 2018 12:49:11 +0200
Subject: [PATCH] shared: Validate action trigger

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 shared/definition.go      | 13 +++++++++++++
 shared/definition_test.go | 24 ++++++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/shared/definition.go b/shared/definition.go
index 9a34938..d3fd8d6 100644
--- a/shared/definition.go
+++ b/shared/definition.go
@@ -233,6 +233,19 @@ func (d *Definition) Validate() error {
 		}
 	}
 
+	validTriggers := []string{
+		"post-files",
+		"post-packages",
+		"post-unpack",
+		"post-update",
+	}
+
+	for _, action := range d.Actions {
+		if !shared.StringInSlice(action.Trigger, validTriggers) {
+			return fmt.Errorf("actions.*.trigger must be one of %v", validTriggers)
+		}
+	}
+
 	// Mapped architecture (distro name)
 	archMapped, err := d.getMappedArchitecture()
 	if err != nil {
diff --git a/shared/definition_test.go b/shared/definition_test.go
index a236d02..aa1f085 100644
--- a/shared/definition_test.go
+++ b/shared/definition_test.go
@@ -183,6 +183,30 @@ func TestValidateDefinition(t *testing.T) {
 			"packages.manager must be one of .+",
 			true,
 		},
+		{
+			"invalid action trigger",
+			Definition{
+				Image: DefinitionImage{
+					Distribution: "ubuntu",
+					Release:      "artful",
+				},
+				Source: DefinitionSource{
+					Downloader: "debootstrap",
+					URL:        "https://ubuntu.com",
+					Keys:       []string{"0xCODE"},
+				},
+				Packages: DefinitionPackages{
+					Manager: "apt",
+				},
+				Actions: []DefinitionAction{
+					{
+						Trigger: "post-build",
+					},
+				},
+			},
+			"actions\\.\\*\\.trigger must be one of .+",
+			true,
+		},
 	}
 
 	for i, tt := range tests {


More information about the lxc-devel mailing list