-
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.
Merge pull request #15 from perriea/v0.0.4
V0.1.0
- Loading branch information
Showing
132 changed files
with
84,178 additions
and
331 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
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 was deleted.
Oops, something went wrong.
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,51 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws/awserr" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/ec2" | ||
"github.com/perriea/tfversion/error" | ||
) | ||
|
||
var ( | ||
sess *session.Session | ||
ec2svc *ec2.EC2 | ||
err error | ||
) | ||
|
||
func TestConnect() { | ||
|
||
// The SDK has support for the shared configuration file (~/.aws/config) | ||
// Create a session to share configuration, and load external configuration. | ||
sess = session.Must(session.NewSessionWithOptions(session.Options{ | ||
SharedConfigState: session.SharedConfigEnable, | ||
})) | ||
|
||
params := &ec2.DescribeInstancesInput{} | ||
|
||
// Create the service's client with the session. | ||
ec2svc = ec2.New(sess) | ||
_, err := ec2svc.DescribeInstances(params) | ||
|
||
if err != nil { | ||
tferror.Run(2, "[WARN] Your AWS access is not correct") | ||
if awsErr, ok := err.(awserr.Error); ok { | ||
|
||
if reqErr, ok := err.(awserr.RequestFailure); ok { | ||
// A service error occurred | ||
fmt.Printf("%s : %s (%s)", awsErr.Code(), awsErr.Message(), reqErr.RequestID()) | ||
} else { | ||
// Generic AWS Error with Code, Message, and original error (if any) | ||
fmt.Printf("%s : %s\n%s", awsErr.Code(), awsErr.Message(), awsErr.OrigErr()) | ||
} | ||
|
||
} else { | ||
tferror.Panic(err) | ||
} | ||
|
||
} else { | ||
tferror.Run(1, "Your AWS access is correct") | ||
} | ||
} |
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,44 @@ | ||
package tfcloud | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
|
||
"github.com/perriea/tfversion/cloud/aws" | ||
) | ||
|
||
var ( | ||
testaws bool | ||
testgcp bool | ||
testazure bool | ||
err error | ||
) | ||
|
||
func Run(params []string) error { | ||
|
||
cloud := flag.NewFlagSet("cloud", flag.ExitOnError) | ||
cloud.BoolVar(&testaws, "aws", false, "Test connection on AWS)") | ||
cloud.BoolVar(&testgcp, "gcp", false, "Test connection on GCP)") | ||
cloud.BoolVar(&testazure, "azure", false, "Test connection on Azure)") | ||
cloud.Parse(params) | ||
|
||
if testaws && testgcp && testazure { | ||
return fmt.Errorf("--aws, --gcp and --azure are mutually exclusive") | ||
} | ||
|
||
if len(params) != 1 { | ||
return fmt.Errorf("Too many arguments ...") | ||
} | ||
|
||
if testaws { | ||
aws.TestConnect() | ||
} else if testgcp { | ||
return fmt.Errorf("GCP test is not actived") | ||
} else if testazure { | ||
return fmt.Errorf("Azure test is not actived") | ||
} else { | ||
return fmt.Errorf("This provider doesn't exist !") | ||
} | ||
|
||
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
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,87 +1,87 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/perriea/tfversion/cloud" | ||
"github.com/perriea/tfversion/error" | ||
"github.com/perriea/tfversion/system/folders" | ||
"github.com/perriea/tfversion/system/network" | ||
"github.com/perriea/tfversion/terraform/download" | ||
"github.com/perriea/tfversion/github" | ||
"github.com/perriea/tfversion/terraform/install" | ||
"github.com/perriea/tfversion/terraform/list" | ||
"github.com/perriea/tfversion/terraform/uninstall" | ||
) | ||
|
||
type command struct { | ||
desc string | ||
usage string | ||
Func cmdHandler | ||
} | ||
|
||
var commands = map[string]command{ | ||
// list commands | ||
"install": command{"Install new versions or switch.", "[0.8.8 version of terraform]", tfinstall.Run}, | ||
"uninstall": command{"Clean cache (tmp files).", "[-a all], [-v version specific]", tfuninstall.Run}, | ||
"list": command{"List online or offline version of terraform.", "[-on list online], [-off list local]", tflist.Run}, | ||
"cloud": command{"Action cloud (Beta)", "[--aws test AWS]", tfcloud.Run}, | ||
} | ||
|
||
var ( | ||
// Errors | ||
errNetwork bool | ||
check bool | ||
err error | ||
// Flag func version param | ||
pathBin string | ||
pathTmp string | ||
install string | ||
// Flag launch func List | ||
listOnline bool | ||
listOffline bool | ||
cleanup bool | ||
version string | ||
err error | ||
) | ||
|
||
func init() { | ||
// Simply error | ||
check = false | ||
errNetwork = false | ||
// Paths | ||
pathBin = "/terraform/bin/" | ||
pathTmp = "/terraform/tmp/" | ||
// Flags CLI | ||
flag.BoolVar(&listOnline, "liston", false, "List online version of terraform") | ||
flag.BoolVar(&listOffline, "listoff", false, "List local version of terraform") | ||
flag.BoolVar(&cleanup, "cleanup", false, "Clean cache (tmp files)") | ||
flag.StringVar(&install, "install", "0", "Version of terraform to install or switch") | ||
flag.Parse() | ||
// version app | ||
version = "0.1.0" | ||
} | ||
|
||
func main() { | ||
// Check if internet is available (releases.hashicorp.com) | ||
errNetwork = tfnetwork.Run() | ||
if listOnline == true { | ||
|
||
if errNetwork { | ||
// Show version terraform | ||
tflist.ListOn() | ||
} else { | ||
// No network | ||
tferror.Run(2, "[ERROR] No internet connection ...") | ||
} | ||
type cmdHandler func([]string) error | ||
|
||
} else if listOffline == true { | ||
// List all versions local | ||
tflist.ListOff() | ||
func doHelp() error { | ||
|
||
} else if install != "0" { | ||
keys := make([]string, 0, len(commands)) | ||
for k := range commands { | ||
keys = append(keys, k) | ||
} | ||
|
||
if errNetwork { | ||
// Lauch Terraform download | ||
tffolder.CreateFolder(pathTmp, 0755) | ||
check = tfdownload.Run(install) | ||
fmt.Printf("tfversion v%s\n\n", version) | ||
fmt.Printf("Usage: tfversion <command> [args]\n\n") | ||
fmt.Printf("Common commands:\n") | ||
|
||
// Check if download is done and install | ||
if check { | ||
tffolder.CreateFolder(pathBin, 0755) | ||
tfinstall.Run(install) | ||
} | ||
for _, k := range keys { | ||
fmt.Printf("%10s: %s\n", k, commands[k].desc) | ||
fmt.Printf("\tUsage: %s %s\n", k, commands[k].usage) | ||
} | ||
|
||
} else { | ||
// No network | ||
tferror.Run(2, "[WARN] No internet connection ...") | ||
} | ||
fmt.Printf(" help: Show this help message\n\n") | ||
|
||
} else if cleanup { | ||
// Delete all cache | ||
tflist.Cleanup() | ||
// Show if the last version | ||
lastrelease, release := tfgithub.Lastversion(version) | ||
if !lastrelease && release != nil { | ||
tferror.Run(2, fmt.Sprintf("Your version of tfversion is out of date !\nThe latest version is %s (%s)", *release.TagName, *release.HTMLURL)) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func main() { | ||
|
||
if len(os.Args) < 2 || os.Args[1] == "help" { | ||
err = doHelp() | ||
tferror.Panic(err) | ||
return | ||
} | ||
|
||
if cmd, ok := commands[os.Args[1]]; ok { | ||
if err = cmd.Func(os.Args[2:]); err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
} | ||
} else { | ||
// Show version | ||
ShowVersion() | ||
fmt.Fprintf(os.Stderr, "Unknown command '%s'\n", os.Args[1]) | ||
fmt.Fprintf(os.Stderr, "Usage: %s command command_arguments\n", os.Args[0]) | ||
fmt.Fprintf(os.Stderr, "\tUse help command to list available commands\n") | ||
fmt.Fprintf(os.Stderr, "\tUse command help to get commands accepting options\n") | ||
} | ||
} |
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.