-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from srijanone/git-secrets
[WIP]: checkin install script for git-secrets
- Loading branch information
Showing
13 changed files
with
223 additions
and
94 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package git_secrets | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"io" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
|
||
"github.com/srijanone/vega/pkg/common" | ||
"github.com/srijanone/vega/pkg/git" | ||
) | ||
|
||
const ( | ||
commandName = "git-secrets" | ||
RequiredText = ` | ||
git-secrets is not installed, which is required to run the application. | ||
` | ||
InstallInstructions = ` | ||
Install using: curl -fsSL https://raw.githubusercontent.com/srijanone/vega/develop/scripts/install_git_secrets.sh| bash | ||
` | ||
) | ||
|
||
func IsInstalled() bool { | ||
_, err := exec.LookPath(commandName) | ||
return err == nil | ||
} | ||
|
||
func Configure(out io.Writer) { | ||
templateDir := filepath.Join(common.DefaultHome(), ".git-templates", "git-secrets") | ||
// This is a very rudimentary check, it checks if host, port, password etc in the database | ||
// array in settings.php(drupal) is written in plain text. In case these are written in plain | ||
// text the developer might write them in "", or '' and in case these are externalise typically | ||
// developers would use https://www.php.net/manual/en/function.getenv.php or some other function. | ||
drupalSecretRegex := "(\"|')?(host|port|password|username)(\"|')?\\s*(=>)\\s*(\"|')+(.*)(\"|')+\\s*" | ||
|
||
fmt.Print("Adding common AWS patterns to the git config...\n") | ||
execute(out, "--register-aws", "--global") | ||
|
||
fmt.Printf("Adding hooks to all local repositories...\n") | ||
execute(out, "--install", "-f", templateDir) | ||
args := []string{"config", "--global", "init.templateDir", templateDir} | ||
git.Execute(out, args...) | ||
|
||
fmt.Printf("Registering Drupal secrets patters...\n") | ||
execute(out, "--add", "--global", drupalSecretRegex) | ||
} | ||
|
||
func execute(out io.Writer, arguments ...string) error { | ||
if !IsInstalled() { | ||
fmt.Fprintf(out, RequiredText) | ||
fmt.Fprintf(out, InstallInstructions) | ||
return errors.New("git-secrets is not installed on system") | ||
} | ||
|
||
command := exec.Command(commandName, arguments...) | ||
command.Stdout = out | ||
command.Stderr = os.Stderr | ||
err := command.Run() | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.