create driver package for runtime
parent
1b06beb63c
commit
edde4db0f3
@ -1,60 +0,0 @@
|
||||
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Polyform License
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/drone/drone-go/drone"
|
||||
"github.com/drone/runner-go/manifest"
|
||||
"github.com/drone/runner-go/secret"
|
||||
)
|
||||
|
||||
// CompilerArgs provides compiler arguments.
|
||||
type CompilerArgs struct {
|
||||
// Manifest provides the parsed manifest.
|
||||
Manifest *manifest.Manifest
|
||||
|
||||
// Pipeline provides the parsed pipeline. This pipeline is
|
||||
// the compiler source and is converted to the intermediate
|
||||
// representation by the Compile method.
|
||||
Pipeline manifest.Resource
|
||||
|
||||
// Build provides the compiler with stage information that
|
||||
// is converted to environment variable format and passed to
|
||||
// each pipeline step. It is also used to clone the commit.
|
||||
Build *drone.Build
|
||||
|
||||
// Stage provides the compiler with stage information that
|
||||
// is converted to environment variable format and passed to
|
||||
// each pipeline step.
|
||||
Stage *drone.Stage
|
||||
|
||||
// Repo provides the compiler with repo information. This
|
||||
// repo information is converted to environment variable
|
||||
// format and passed to each pipeline step. It is also used
|
||||
// to clone the repository.
|
||||
Repo *drone.Repo
|
||||
|
||||
// System provides the compiler with system information that
|
||||
// is converted to environment variable format and passed to
|
||||
// each pipeline step.
|
||||
System *drone.System
|
||||
|
||||
// Netrc provides netrc parameters that can be used by the
|
||||
// default clone step to authenticate to the remote
|
||||
// repository.
|
||||
Netrc *drone.Netrc
|
||||
|
||||
// Secret returns a named secret value that can be injected
|
||||
// into the pipeline step.
|
||||
Secret secret.Provider
|
||||
}
|
||||
|
||||
// Compiler compiles the Yaml configuration file to an
|
||||
// intermediate representation optimized for simple execution.
|
||||
type Compiler interface {
|
||||
Compile(context.Context, CompilerArgs) Spec
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Polyform License
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
package replacer
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/drone/runner-go/pipeline/runtime/driver"
|
||||
)
|
||||
|
||||
func TestReplace(t *testing.T) {
|
||||
secrets := []driver.Secret{
|
||||
&secret{Name: "DOCKER_USERNAME", Data: "octocat", Mask: false},
|
||||
&secret{Name: "DOCKER_PASSWORD", Data: "correct-horse-batter-staple", Mask: true},
|
||||
&secret{Name: "DOCKER_EMAIL", Data: "", Mask: true},
|
||||
}
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
w := New(&nopCloser{buf}, secrets)
|
||||
w.Write([]byte("username octocat password correct-horse-batter-staple"))
|
||||
w.Close()
|
||||
|
||||
if got, want := buf.String(), "username octocat password ******"; got != want {
|
||||
t.Errorf("Want masked string %s, got %s", want, got)
|
||||
}
|
||||
}
|
||||
|
||||
// this test verifies that if there are no secrets to scan and
|
||||
// mask, the io.WriteCloser is returned as-is.
|
||||
func TestReplaceNone(t *testing.T) {
|
||||
secrets := []driver.Secret{
|
||||
&secret{Name: "DOCKER_USERNAME", Data: "octocat", Mask: false},
|
||||
&secret{Name: "DOCKER_PASSWORD", Data: "correct-horse-batter-staple", Mask: false},
|
||||
}
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
w := &nopCloser{buf}
|
||||
r := New(w, secrets)
|
||||
if w != r {
|
||||
t.Errorf("Expect buffer returned with no replacer")
|
||||
}
|
||||
}
|
||||
|
||||
type nopCloser struct {
|
||||
io.Writer
|
||||
}
|
||||
|
||||
func (*nopCloser) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type secret struct {
|
||||
Name string
|
||||
Data string
|
||||
Mask bool
|
||||
}
|
||||
|
||||
func (s *secret) GetName() string { return s.Name }
|
||||
func (s *secret) GetValue() string { return s.Data }
|
||||
func (s *secret) IsMasked() bool { return s.Mask }
|
@ -1,5 +0,0 @@
|
||||
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Polyform License
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
package runtime
|
Loading…
Reference in New Issue