grim/convey

we'll never again push a release to bitbucket so remove that config
// 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"
"hg.sr.ht/~grim/convey/logging"
"hg.sr.ht/~grim/convey/workspace"
)
// State holds all of the runtime data during a run.
type State struct {
Directory string
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
}