forked from jckuester/awsrm
-
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
Showing
5 changed files
with
234 additions
and
171 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/jckuester/awsrm/pkg/resource" | ||
|
||
"github.com/apex/log" | ||
|
||
"github.com/fatih/color" | ||
awsls "github.com/jckuester/awsls/aws" | ||
"github.com/jckuester/awsls/util" | ||
) | ||
|
||
func handleInputFromArgs(args []string, profile, region string, dryRun bool) int { | ||
log.Debug("input via args") | ||
|
||
var profiles []string | ||
var regions []string | ||
|
||
if profile != "" { | ||
profiles = []string{profile} | ||
} else { | ||
env, ok := os.LookupEnv("AWS_PROFILE") | ||
if ok { | ||
profiles = []string{env} | ||
} | ||
} | ||
|
||
if region != "" { | ||
regions = []string{region} | ||
} | ||
|
||
clients, err := util.NewAWSClientPool(profiles, regions) | ||
if err != nil { | ||
fmt.Fprint(os.Stderr, color.RedString("\nError: %s\n", err)) | ||
return 1 | ||
} | ||
|
||
var resources []awsls.Resource | ||
rType := args[0] | ||
for _, client := range clients { | ||
for _, id := range args[1:] { | ||
resources = append(resources, awsls.Resource{ | ||
Type: rType, | ||
ID: id, | ||
Profile: client.Profile, | ||
Region: client.Region, | ||
}) | ||
} | ||
} | ||
|
||
var clientKeys []util.AWSClientKey | ||
for k := range clients { | ||
clientKeys = append(clientKeys, k) | ||
} | ||
|
||
err = resource.Delete(clientKeys, resources, os.Stdin, dryRun) | ||
if err != nil { | ||
fmt.Fprint(os.Stderr, color.RedString("\nError: %s\n", err)) | ||
return 1 | ||
} | ||
|
||
return 0 | ||
} |
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,53 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/jckuester/awsrm/pkg/resource" | ||
|
||
"github.com/apex/log" | ||
"github.com/fatih/color" | ||
"github.com/jckuester/awsls/util" | ||
) | ||
|
||
func isInputFromPipe() bool { | ||
fileInfo, _ := os.Stdin.Stat() | ||
log.Debugf("%v\n", fileInfo.Mode()) | ||
|
||
return fileInfo.Mode()&os.ModeNamedPipe != 0 | ||
} | ||
|
||
func handleInputFromPipe(dryRun bool) int { | ||
log.Debug("input via pipe") | ||
|
||
resources, err := resource.Read(os.Stdin) | ||
if err != nil { | ||
fmt.Fprint(os.Stderr, color.RedString("\nError: %s\n", err)) | ||
return 1 | ||
} | ||
|
||
var clientKeys []util.AWSClientKey | ||
for _, r := range resources { | ||
clientKeys = append(clientKeys, util.AWSClientKey{Profile: r.Profile, Region: r.Region}) | ||
} | ||
|
||
err = os.Stdin.Close() | ||
if err != nil { | ||
fmt.Fprint(os.Stderr, color.RedString("\nError: %s\n", err)) | ||
return 1 | ||
} | ||
|
||
confirmDevice, err := os.Open("/dev/tty") | ||
if err != nil { | ||
log.Fatalf("can't open /dev/tty: %s", err) | ||
} | ||
|
||
err = resource.Delete(clientKeys, resources, confirmDevice, dryRun) | ||
if err != nil { | ||
fmt.Fprint(os.Stderr, color.RedString("\nError: %s\n", err)) | ||
return 1 | ||
} | ||
|
||
return 0 | ||
} |
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.