Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moves substitutions to better type #74

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions synchers/mariadb.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (root MariadbSyncRoot) GetPrerequisiteCommand(environment Environment, comm

return SyncCommand{
command: fmt.Sprintf("{{ .bin }} {{ .command }} || true"),
substitutions: map[string]interface{}{
substitutions: map[string]string{
"bin": lagoonSyncBin,
"command": command,
},
Expand Down Expand Up @@ -144,7 +144,7 @@ func (root MariadbSyncRoot) GetRemoteCommand(sourceEnvironment Environment) []Sy
//We remove the `.gz` from the transfer resource name for because we _first_ generate a plain `.sql` file
//and _then_ gzip it
resourceNameWithoutGz := strings.TrimSuffix(transferResource.Name, filepath.Ext(transferResource.Name))
substitutions := map[string]interface{}{
substitutions := map[string]string{
"dumpOptions": "--max-allowed-packet=500M --quick --add-locks --no-autocommit --single-transaction",
"hostname": m.DbHostname,
"username": m.DbUsername,
Expand Down Expand Up @@ -175,7 +175,7 @@ func (m MariadbSyncRoot) GetLocalCommand(targetEnvironment Environment) []SyncCo
resourceNameWithoutGz := strings.TrimSuffix(transferResource.Name, filepath.Ext(transferResource.Name))
return []SyncCommand{
generateSyncCommand("gunzip {{ .transferResource }}",
map[string]interface{}{
map[string]string{
"hostname": l.DbHostname,
"username": l.DbUsername,
"password": l.DbPassword,
Expand All @@ -184,7 +184,7 @@ func (m MariadbSyncRoot) GetLocalCommand(targetEnvironment Environment) []SyncCo
"transferResource": transferResource.Name,
}),
generateSyncCommand("mysql -h{{ .hostname }} -u{{ .username }} -p{{ .password }} -P{{ .port }} {{ .database }} < {{ .resourceNameWithoutGz }}",
map[string]interface{}{
map[string]string{
"hostname": l.DbHostname,
"username": l.DbUsername,
"password": l.DbPassword,
Expand Down
6 changes: 3 additions & 3 deletions synchers/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (root MongoDbSyncRoot) GetPrerequisiteCommand(environment Environment, comm

return SyncCommand{
command: fmt.Sprintf("{{ .bin }} {{ .command }} || true"),
substitutions: map[string]interface{}{
substitutions: map[string]string{
"bin": lagoonSyncBin,
"command": command,
},
Expand All @@ -126,7 +126,7 @@ func (root MongoDbSyncRoot) GetRemoteCommand(sourceEnvironment Environment) []Sy
transferResource := root.GetTransferResource(sourceEnvironment)
return []SyncCommand{{
command: fmt.Sprintf("mongodump --host {{ .hostname }} --port {{ .port }} --db {{ .database }} --archive={{ .transferResource }}"),
substitutions: map[string]interface{}{
substitutions: map[string]string{
"hostname": m.DbHostname,
"port": m.DbPort,
"database": m.DbDatabase,
Expand All @@ -144,7 +144,7 @@ func (m MongoDbSyncRoot) GetLocalCommand(targetEnvironment Environment) []SyncCo
transferResource := m.GetTransferResource(targetEnvironment)
return []SyncCommand{
generateSyncCommand("mongorestore --drop --host {{ .hostname }} --port {{ .port }} --archive={{ .transferResource }}",
map[string]interface{}{
map[string]string{
"hostname": l.DbHostname,
"port": l.DbPort,
"database": l.DbDatabase,
Expand Down
2 changes: 1 addition & 1 deletion synchers/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (root PostgresSyncRoot) GetPrerequisiteCommand(environment Environment, com

return SyncCommand{
command: fmt.Sprintf("{{ .bin }} {{ .command }}"),
substitutions: map[string]interface{}{
substitutions: map[string]string{
"bin": lagoonSyncBin,
"command": command,
},
Expand Down
2 changes: 1 addition & 1 deletion synchers/syncdefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Syncer interface {

type SyncCommand struct {
command string
substitutions map[string]interface{}
substitutions map[string]string
NoOp bool // NoOp can be set to true if this command performs no operation (in situations like file transfers)
}

Expand Down
2 changes: 1 addition & 1 deletion synchers/syncutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func generateNoOpSyncCommand() SyncCommand {
}
}

func generateSyncCommand(commandString string, substitutions map[string]interface{}) SyncCommand {
func generateSyncCommand(commandString string, substitutions map[string]string) SyncCommand {
return SyncCommand{
command: commandString,
substitutions: substitutions,
Expand Down