Skip to content

Commit

Permalink
Refactor ConfigManager -> DataManager
Browse files Browse the repository at this point in the history
  • Loading branch information
bobheadxi committed Jun 7, 2018
1 parent 9137144 commit 7dfdfe1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 26 deletions.
6 changes: 3 additions & 3 deletions daemon/inertiad/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var (
sslDirectory = "/app/host/inertia/config/ssl/"

userDatabasePath = "/app/host/inertia/data/users.db"
deploymentDatabasePath = "/app/host/inertia/data/deployments.db"
deploymentDatabasePath = "/app/host/inertia/data/project.db"
)

const (
Expand All @@ -48,7 +48,7 @@ func run(host, port, version, keyPath, certDir, userDir string) {
sslDirectory = certDir
}
if userDir != "" {
auth.UserDatabasePath = userDir
userDatabasePath = userDir
}

var (
Expand Down Expand Up @@ -85,7 +85,7 @@ func run(host, port, version, keyPath, certDir, userDir string) {

webPrefix := "/web/"
handler, err := auth.NewPermissionsHandler(
auth.UserDatabasePath, host, 120,
userDatabasePath, host, 120,
)
if err != nil {
println(err.Error())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ var (
envVariableBucket = []byte("envVariables")
)

// ConfigManager stores persistent deployment configuration
type ConfigManager struct {
// DataManager stores persistent deployment configuration
type DataManager struct {
// db is a boltdb database, which is an embedded
// key/value database where each "bucket" is a collection
db *bolt.DB
Expand All @@ -31,7 +31,7 @@ type ConfigManager struct {
decryptPrivateKey *[32]byte
}

func newConfigManager(dbPath string) (*ConfigManager, error) {
func newDataManager(dbPath string) (*DataManager, error) {
db, err := bolt.Open(dbPath, 0600, nil)
if err != nil {
return nil, err
Expand All @@ -58,7 +58,7 @@ func newConfigManager(dbPath string) (*ConfigManager, error) {
return nil, err
}

return &ConfigManager{
return &DataManager{
db,
encryptPublicKey, encryptPrivateKey,
decryptPublicKey, decryptPrivateKey,
Expand All @@ -67,7 +67,7 @@ func newConfigManager(dbPath string) (*ConfigManager, error) {

// AddEnvVariable adds a new environment variable that will be applied
// to all project containers
func (c *ConfigManager) AddEnvVariable(name, value string,
func (c *DataManager) AddEnvVariable(name, value string,
encrypt bool) error {
if len(name) == 0 || len(value) == 0 {
return errors.New("invalid env configuration")
Expand Down Expand Up @@ -106,22 +106,22 @@ func (c *ConfigManager) AddEnvVariable(name, value string,
}

// RemoveEnvVariable removes a previously set env variable
func (c *ConfigManager) RemoveEnvVariable(name, value string) error {
func (c *DataManager) RemoveEnvVariable(name, value string) error {
return nil
}

// AddPersistentFile adds a new persistent file to place in the project
// directory at buildtime
func (c *ConfigManager) AddPersistentFile(path string) error {
func (c *DataManager) AddPersistentFile(path string) error {
return nil
}

// RemovePersistentFile removes a persistent file
func (c *ConfigManager) RemovePersistentFile(path string) error {
func (c *DataManager) RemovePersistentFile(path string) error {
return nil
}

func (c *ConfigManager) getEnvVariables() (map[string]string, error) {
func (c *DataManager) getEnvVariables() (map[string]string, error) {
env := map[string]string{}

err := c.db.View(func(tx *bolt.Tx) error {
Expand Down Expand Up @@ -163,11 +163,11 @@ func (c *ConfigManager) getEnvVariables() (map[string]string, error) {
return env, nil
}

func (c *ConfigManager) getPersistentFiles() ([]string, error) {
func (c *DataManager) getPersistentFiles() ([]string, error) {
return nil, nil
}

func (c *ConfigManager) destroy() error {
func (c *DataManager) destroy() error {
return c.db.Update(func(tx *bolt.Tx) error {
return nil
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/assert"
)

func TestConfigManager_EnvVariableOperations(t *testing.T) {
func TestDataManager_EnvVariableOperations(t *testing.T) {
type args struct {
name string
value string
Expand All @@ -30,7 +30,7 @@ func TestConfigManager_EnvVariableOperations(t *testing.T) {
assert.Nil(t, err)
defer os.RemoveAll(dir)

c, err := newConfigManager(path.Join(dir, "deployment.db"))
c, err := newDataManager(path.Join(dir, "deployment.db"))
assert.Nil(t, err)

err = c.AddEnvVariable(tt.args.name, tt.args.value, tt.args.encrypt)
Expand Down
10 changes: 5 additions & 5 deletions daemon/inertiad/project/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type Deployment struct {
auth ssh.AuthMethod
mux sync.Mutex

ConfigManager *ConfigManager
DataManager *DataManager
}

// DeploymentConfig is used to configure Deployment
Expand Down Expand Up @@ -79,7 +79,7 @@ func NewDeployment(cfg DeploymentConfig, out io.Writer) (*Deployment, error) {
}

// Set up deployment database
manager, err := newConfigManager(cfg.DatabasePath)
manager, err := newDataManager(cfg.DatabasePath)
if err != nil {
return nil, err
}
Expand All @@ -104,8 +104,8 @@ func NewDeployment(cfg DeploymentConfig, out io.Writer) (*Deployment, error) {
auth: authMethod,
repo: repo,

// Persistent configuration manager
ConfigManager: manager,
// Persistent data manager
DataManager: manager,
}, nil
}

Expand Down Expand Up @@ -191,7 +191,7 @@ func (d *Deployment) Destroy(cli *docker.Client, out io.Writer) error {

d.mux.Lock()
defer d.mux.Unlock()
err := d.ConfigManager.destroy()
err := d.DataManager.destroy()
if err != nil {
fmt.Fprint(out, "unable to clear database records: "+err.Error())
}
Expand Down
11 changes: 6 additions & 5 deletions daemon/inertiad/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ func upHandler(w http.ResponseWriter, r *http.Request) {
if deployment == nil {
logger.Println("No deployment detected")
d, err := project.NewDeployment(project.DeploymentConfig{
ProjectName: upReq.Project,
BuildType: upReq.BuildType,
RemoteURL: gitOpts.RemoteURL,
Branch: gitOpts.Branch,
PemFilePath: auth.DaemonGithubKeyLocation,
ProjectName: upReq.Project,
BuildType: upReq.BuildType,
RemoteURL: gitOpts.RemoteURL,
Branch: gitOpts.Branch,
PemFilePath: auth.DaemonGithubKeyLocation,
DatabasePath: deploymentDatabasePath,
}, logger)
if err != nil {
logger.WriteErr(err.Error(), http.StatusPreconditionFailed)
Expand Down

0 comments on commit 7dfdfe1

Please sign in to comment.