-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9274bb1
commit bc4fec1
Showing
8 changed files
with
139 additions
and
5 deletions.
There are no files selected for viewing
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,31 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
) | ||
|
||
func failOnError(err error, msg string) { | ||
if err != nil { | ||
panic(fmt.Sprintf("%s: %s", msg, err)) | ||
} | ||
} | ||
|
||
// GetSession returns Session for AWS. | ||
func GetSession(profile string, region string) *session.Session { | ||
sess, err := session.NewSessionWithOptions(session.Options{ | ||
Profile: profile, | ||
SharedConfigState: session.SharedConfigEnable, | ||
Config: aws.Config{ | ||
Region: aws.String(region), | ||
}, | ||
}) | ||
|
||
if err != nil { | ||
failOnError(err, "Couldnot connect to AWS.") | ||
} | ||
|
||
return sess | ||
} |
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 |
---|---|---|
|
@@ -11,7 +11,7 @@ import ( | |
|
||
func handle(err error) { | ||
if err != nil { | ||
exit.Error(err) | ||
exit.Error(err, "") | ||
} | ||
} | ||
|
||
|
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,21 @@ | ||
package slack | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/leapfrogtechnology/shift/deployment/utils/http" | ||
) | ||
|
||
// Notify sends data to slack webhook url | ||
func Notify(url string, text string, color string) { | ||
|
||
message := strings.Replace(text, "\"", "'", -1) | ||
|
||
content := fmt.Sprintf(`{"attachments": [{"text": %q, "color": "%s"}]}`, message, color) | ||
|
||
http.Client.R(). | ||
SetHeader("Content-Type", "application/json"). | ||
SetBody([]byte(content)). | ||
Post(url) | ||
} |
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,14 @@ | ||
package escape | ||
|
||
import ( | ||
"regexp" | ||
) | ||
|
||
const ansi = "[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))" | ||
|
||
var re = regexp.MustCompile(ansi) | ||
|
||
// Strip returns the same string by removeing ansi char. | ||
func Strip(str string) string { | ||
return re.ReplaceAllString(str, "") | ||
} |
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,19 @@ | ||
package file | ||
|
||
import ( | ||
"mime" | ||
"strings" | ||
) | ||
|
||
// GetFileContentType returns the content type of the file. | ||
func GetFileContentType(filename string) string { | ||
split := strings.Split(filename, ".") | ||
|
||
if len(split) == 0 { | ||
return "binary/octet-stream" | ||
} | ||
|
||
ext := split[len(split)-1] | ||
|
||
return mime.TypeByExtension("." + ext) | ||
} |
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,34 @@ | ||
package shell | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
|
||
"github.com/leapfrogtechnology/shift/deployment/utils/escape" | ||
) | ||
|
||
// Execute runs the process with the supplied environment. | ||
func Execute(command string) error { | ||
cmd := exec.Command("bash", "-c", command) | ||
|
||
var out bytes.Buffer | ||
var stderr bytes.Buffer | ||
|
||
cmd.Stderr = &stderr | ||
cmd.Stdout = &out | ||
|
||
cmd.Stdout = os.Stdout | ||
|
||
err := cmd.Run() | ||
if err != nil { | ||
fmt.Println(stderr.String()) | ||
|
||
errorMessage := escape.Strip(err.Error() + " :- " + stderr.String()) | ||
|
||
return errors.New(errorMessage) | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
package exit | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/leapfrogtechnology/shift/core/utils/logger" | ||
) | ||
|
||
// Error exits the application by showing the given message. | ||
func Error(err interface{}) { | ||
fmt.Println("Error") | ||
fmt.Println(err) | ||
func Error(err error, msg string) { | ||
logger.Error(err, msg) | ||
|
||
os.Exit(1) | ||
} |