grim/convey

remove some leftovers that were missed
redux
2021-10-05, Gary Kramlich
57f9019fe520
Parents c0672a94a7d8
Children ded47c27b924
remove some leftovers that were missed
--- a/color/x11.go Tue Oct 05 02:52:17 2021 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-// Convey
-// Copyright 2016-2018 Gary Kramlich <grim@reaperworld.com>
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-package color
-
-var (
- x11ColorList = []string{
- "red",
- "green",
- "plum",
- "blue",
- "magenta",
- "cyan",
- "deeppink3",
- "darkgreen",
- "darkorchid2",
- "lightblue",
- "indigo",
- "cyan4",
- "SlateBlue",
- "SteelBlue",
- "LightSeaGreen",
- "gold",
- "goldenrod1",
- "IndianRed",
- "tomato",
- "coral",
- }
-
- x11ColorMap = map[string]string{}
-)
-
-// X11 returns an x11 color based on the hash of the given string.
-func X11(identifier string) string {
- return lookup(identifier, x11ColorList, x11ColorMap)
-}
--- a/script/script.go Tue Oct 05 02:52:17 2021 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,107 +0,0 @@
-// Convey
-// Copyright 2016-2018 Gary Kramlich <grim@reaperworld.com>
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-package script
-
-import (
- "strings"
-
- "github.com/kballard/go-shellquote"
-
- "keep.imfreedom.org/grim/convey/aws"
- "keep.imfreedom.org/grim/convey/docker"
- "keep.imfreedom.org/grim/convey/tasks"
-)
-
-// ParseFunc defines a function that can parse a shell command into a convey
-// task.
-type ParseFunc func(argv []string) (tasks.Task, error)
-
-var (
- commands = map[string]ParseFunc{
- "docker": docker.ParseCommand,
- "aws": aws.ParseCommand,
- }
-)
-
-// Parse will process a slice of commands and turn it into the proper tasks for
-// convey to run.
-func Parse(image, shell string, script []string) ([]tasks.Task, error) {
- newTasks := []tasks.Task{}
- currentScript := []string{}
-
- for _, cmd := range script {
- // trim whitespace from the command
- clean := strings.TrimSpace(cmd)
-
- // handle weirdo commands that are entirely wrapped in $()
- if strings.HasPrefix(clean, "$(") && strings.HasSuffix(clean, ")") {
- clean = strings.TrimPrefix(clean, "$(")
- clean = strings.TrimSuffix(clean, ")")
- }
-
- // handle weirdo commands that are entirely wrapped in `'s
- if strings.HasPrefix(clean, "`") && strings.HasSuffix(clean, "`") {
- clean = strings.TrimPrefix(clean, "`")
- clean = strings.TrimSuffix(clean, "`")
- }
-
- argv, err := shellquote.Split(clean)
- if err != nil {
- return nil, err
- }
-
- if len(argv) == 0 {
- continue
- }
-
- currentCmd := strings.TrimSpace(argv[0])
- if parser, ok := commands[currentCmd]; ok {
- if len(currentScript) > 0 {
- newTasks = append(newTasks, &docker.Run{
- Shell: shell,
- Script: currentScript,
- Image: image,
- WorkDir: "/workspace",
- })
-
- // reset our script
- currentScript = []string{}
- }
-
- task, err := parser(argv)
- if err != nil {
- return nil, err
- }
-
- newTasks = append(newTasks, task)
- } else {
- currentScript = append(currentScript, cmd)
- }
- }
-
- // if we have any unfinished script commands create a task for them
- if len(currentScript) > 0 {
- newTasks = append(newTasks, &docker.Run{
- Shell: shell,
- Script: currentScript,
- Image: image,
- WorkDir: "/workspace",
- })
- }
-
- return newTasks, nil
-}
--- a/script/script_test.go Tue Oct 05 02:52:17 2021 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,142 +0,0 @@
-// Convey
-// Copyright 2016-2018 Gary Kramlich <grim@reaperworld.com>
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-package script
-
-import (
- "testing"
-
- "github.com/stretchr/testify/assert"
-
- "keep.imfreedom.org/grim/convey/aws"
- "keep.imfreedom.org/grim/convey/docker"
- cYaml "keep.imfreedom.org/grim/convey/yaml"
-)
-
-func TestEmpty(t *testing.T) {
- parsedTasks, err := Parse("", "", []string{})
-
- assert.Nil(t, err)
- assert.Empty(t, parsedTasks)
-}
-
-func TestSimple(t *testing.T) {
- commands := []string{
- "#!/bin/sh",
- "false",
- }
-
- parsedTasks, err := Parse("", "", commands)
-
- assert.Nil(t, err)
- assert.Len(t, parsedTasks, 1)
-
- assert.IsType(t, parsedTasks[0], &docker.Run{})
-}
-
-func TestSubShellUnknown(t *testing.T) {
- commands := []string{"$(true)"}
-
- parsedTasks, err := Parse("", "", commands)
-
- assert.Nil(t, err)
- assert.Len(t, parsedTasks, 1)
-
- assert.IsType(t, parsedTasks[0], &docker.Run{})
-
- run := parsedTasks[0].(*docker.Run)
- assert.Equal(t, run.Script, cYaml.StringOrSlice([]string{"$(true)"}))
-}
-
-func TestBackTicksUnknown(t *testing.T) {
- commands := []string{"`true`"}
-
- parsedTasks, err := Parse("", "", commands)
-
- assert.Nil(t, err)
- assert.Len(t, parsedTasks, 1)
-
- assert.IsType(t, parsedTasks[0], &docker.Run{})
-
- run := parsedTasks[0].(*docker.Run)
- assert.Equal(t, run.Script, cYaml.StringOrSlice([]string{"`true`"}))
-}
-
-func TestDockerThenScript(t *testing.T) {
- commands := []string{
- "docker push foo",
- "pwd",
- }
-
- parsedTasks, err := Parse("", "", commands)
-
- assert.Nil(t, err)
- assert.Len(t, parsedTasks, 2)
-
- assert.IsType(t, parsedTasks[0], &docker.Push{})
- assert.IsType(t, parsedTasks[1], &docker.Run{})
-}
-
-func TestScriptThenDocker(t *testing.T) {
- commands := []string{
- "pwd",
- "docker push foo",
- }
-
- parsedTasks, err := Parse("", "", commands)
-
- assert.Nil(t, err)
- assert.Len(t, parsedTasks, 2)
-
- assert.IsType(t, parsedTasks[0], &docker.Run{})
- assert.IsType(t, parsedTasks[1], &docker.Push{})
-}
-
-func TestMixed(t *testing.T) {
- commands := []string{
- "pwd",
- "docker push foo",
- "pwd",
- }
-
- parsedTasks, err := Parse("", "", commands)
-
- assert.Nil(t, err)
- assert.Len(t, parsedTasks, 3)
-
- assert.IsType(t, parsedTasks[0], &docker.Run{})
- assert.IsType(t, parsedTasks[1], &docker.Push{})
- assert.IsType(t, parsedTasks[2], &docker.Run{})
-}
-
-func TestAWSECRGetLogin(t *testing.T) {
- commands := []string{
- "aws ecr get-login",
- "aws ecr get-login --region us-west-2",
- "$(aws ecr get-login)",
- "`aws ecr get-login`",
- }
-
- parsedTasks, err := Parse("", "", commands)
-
- assert.Nil(t, err)
- assert.Len(t, parsedTasks, 4)
-
- assert.IsType(t, parsedTasks[0], &aws.ECRGetLogin{})
- assert.IsType(t, parsedTasks[1], &aws.ECRGetLogin{})
- assert.IsType(t, parsedTasks[2], &aws.ECRGetLogin{})
- assert.IsType(t, parsedTasks[3], &aws.ECRGetLogin{})
-}
--- a/state/state.go Tue Oct 05 02:52:17 2021 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,85 +0,0 @@
-// Convey
-// Copyright 2016-2018 Gary Kramlich <grim@reaperworld.com>
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-// Package state contains the type that maintain the state during a run.
-package state
-
-import (
- "fmt"
- "os"
- "time"
-
- log "github.com/sirupsen/logrus"
-
- "keep.imfreedom.org/grim/convey/logging"
- "keep.imfreedom.org/grim/convey/workspace"
-)
-
-// State holds all of the runtime data during a run.
-type State struct {
- logger *log.Entry
-
- CfgPath string
- Workspace *workspace.Workspace
- KeepWorkspace bool
-
- DisableDeprecated bool
- ForceSequential bool
- EnableSSHAgent bool
- PlanTimeout time.Duration
-
- DockerConfig string
- CPUShares string
- Memory string
-}
-
-// New creates a new state.
-func New() *State {
- pwd, err := os.Getwd()
- if err != nil {
- panic(err)
- }
-
- ws, err := workspace.New(pwd)
- if err != nil {
- panic(err)
- }
-
- return &State{
- Workspace: ws,
- logger: logging.NewAdapter("state"),
- }
-}
-
-// Destroy will clean up the given state and run any registered cleanup
-// functions
-func (st *State) Destroy() {
- // finally remove the workspace if requested
- if !st.KeepWorkspace {
- st.Workspace.Destroy()
- }
-}
-
-// Valid validates whether the state is correct or not.
-func (st *State) Valid() error {
- if st.EnableSSHAgent {
- if val := os.Getenv("SSH_AUTH_SOCK"); val == "" {
- return fmt.Errorf("ssh-agent forwarding requested, but agent not running")
- }
- }
-
- return nil
-}