lint after transform, remove un-needed lint rules, temp hack in transform

This commit is contained in:
Brad Rydzewski 2015-08-19 11:23:32 -07:00
parent 4fefabc1e8
commit 271d9a0d4f
4 changed files with 18 additions and 88 deletions

View file

@ -17,11 +17,6 @@ var lintRules = []lintRule{
expectBuild,
expectImage,
expectCommand,
expectTrustedSetup,
expectTrustedClone,
expectTrustedPublish,
expectTrustedDeploy,
expectTrustedNotify,
expectCloneInWorkspace,
expectCacheInWorkspace,
}
@ -61,52 +56,6 @@ func expectCommand(c *common.Config) error {
return nil
}
// lint rule that fails when a non-trusted clone plugin is used.
func expectTrustedClone(c *common.Config) error {
if c.Clone != nil && strings.Contains(c.Clone.Image, "/") {
return fmt.Errorf("Yaml must use trusted clone plugins")
}
return nil
}
// lint rule that fails when a non-trusted setup plugin is used.
func expectTrustedSetup(c *common.Config) error {
if c.Setup != nil && strings.Contains(c.Setup.Image, "/") {
return fmt.Errorf("Yaml must use trusted setup plugins")
}
return nil
}
// lint rule that fails when a non-trusted publish plugin is used.
func expectTrustedPublish(c *common.Config) error {
for _, step := range c.Publish {
if strings.Contains(step.Image, "/") {
return fmt.Errorf("Yaml must use trusted publish plugins")
}
}
return nil
}
// lint rule that fails when a non-trusted deploy plugin is used.
func expectTrustedDeploy(c *common.Config) error {
for _, step := range c.Deploy {
if strings.Contains(step.Image, "/") {
return fmt.Errorf("Yaml must use trusted deploy plugins")
}
}
return nil
}
// lint rule that fails when a non-trusted notify plugin is used.
func expectTrustedNotify(c *common.Config) error {
for _, step := range c.Notify {
if strings.Contains(step.Image, "/") {
return fmt.Errorf("Yaml must use trusted notify plugins")
}
}
return nil
}
// lint rule that fails if the clone directory is not contained
// in the root workspace.
func expectCloneInWorkspace(c *common.Config) error {

View file

@ -42,37 +42,6 @@ func Test_Linter(t *testing.T) {
g.Assert(expectImage(c) != nil).IsTrue()
})
g.It("Should fail when untrusted setup image", func() {
c := &common.Config{Setup: &common.Step{Image: "foo/bar"}}
g.Assert(expectTrustedSetup(c) != nil).IsTrue()
})
g.It("Should fail when untrusted clone image", func() {
c := &common.Config{Clone: &common.Step{Image: "foo/bar"}}
g.Assert(expectTrustedClone(c) != nil).IsTrue()
})
g.It("Should fail when untrusted publish image", func() {
c := &common.Config{}
c.Publish = map[string]*common.Step{}
c.Publish["docker"] = &common.Step{Image: "foo/bar"}
g.Assert(expectTrustedPublish(c) != nil).IsTrue()
})
g.It("Should fail when untrusted deploy image", func() {
c := &common.Config{}
c.Deploy = map[string]*common.Step{}
c.Deploy["amazon"] = &common.Step{Image: "foo/bar"}
g.Assert(expectTrustedDeploy(c) != nil).IsTrue()
})
g.It("Should fail when untrusted notify image", func() {
c := &common.Config{}
c.Notify = map[string]*common.Step{}
c.Notify["hipchat"] = &common.Step{Image: "foo/bar"}
g.Assert(expectTrustedNotify(c) != nil).IsTrue()
})
g.It("Should pass linter when build properly setup", func() {
c := &common.Config{}
c.Build = &common.Step{}

View file

@ -73,11 +73,7 @@ func ParseSingle(raw string, opts *Opts, r *common.Repo) (*common.Config, error)
if err != nil {
return nil, err
}
// lint the yaml file
err = Lint(conf)
if err != nil {
return nil, err
}
// apply rules / transforms
transform.Defaults(conf)
if !opts.Network {
@ -90,6 +86,12 @@ func ParseSingle(raw string, opts *Opts, r *common.Repo) (*common.Config, error)
transform.RemovePrivileged(conf)
}
transform.Repo(conf, r)
// lint the yaml file
err = Lint(conf)
if err != nil {
return nil, err
}
err = LintPlugins(conf, opts)
if err != nil {
return nil, err

View file

@ -80,6 +80,16 @@ func Repo(c *common.Config, r *common.Repo) {
func transformSetup(c *common.Config) {
c.Setup = &common.Step{}
c.Setup.Image = "plugins/drone-build"
// TODO move below code to separate transform
if c.Build == nil {
c.Build = &common.Step{}
}
if c.Build.Config == nil {
c.Build.Config = map[string]interface{}{}
}
////
c.Setup.Config = c.Build.Config
}