Skip to content

Commit

Permalink
feat: Specify custom folder
Browse files Browse the repository at this point in the history
  • Loading branch information
sauravpanda committed Feb 1, 2024
1 parent 732b3bd commit dd8b75c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,5 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
output/
main
main
cloudstate-*
13 changes: 13 additions & 0 deletions cmd/build.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Steps to Build release binaries

```
# For Windows 64-bit
GOOS=windows GOARCH=amd64 go build -o cloudstate-windows.exe ./cmd/main.go
# For macOS 64-bit
GOOS=darwin GOARCH=amd64 go build -o cloudstate-macos ./cmd/main.go
# For Linux 64-bit
GOOS=linux GOARCH=amd64 go build -o cloudstate-linux ./cmd/main.go
```
19 changes: 11 additions & 8 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var (
cloudProvider *string
resourceType *string
region *string
outputFolder *string
)

func main() {
Expand All @@ -29,10 +30,12 @@ func main() {
cloudProvider = gatherCmd.String("provider", "", "The cloud provider to interact with (e.g., 'aws', 'gcp', 'azure')")
resourceType = gatherCmd.String("resource", "", "The type of resource to fetch (e.g., 'vm', 'storage', 'network')")
region = gatherCmd.String("region", "", "The region for which the data should be fetched (e.g 'us-east-1', 'ap-south-1')")
outputFolder = gatherCmd.String("out-folder", "", "Specific folder in which data should be stored. Default: ./output/")
gatherCmd.Parse(os.Args[2:])
gather()
case "report":
cloudProvider = reportCmd.String("provider", "", "The cloud provider to interact with (e.g., 'aws', 'gcp', 'azure')")
outputFolder = reportCmd.String("out-folder", "", "Specific folder in which data should be stored. Default: ./output/")
reportCmd.Parse(os.Args[2:])
generateReport()
default:
Expand All @@ -52,11 +55,11 @@ func gather() {
// Handle the cloud region based on the input
switch *cloudProvider {
case "aws":
handleAWS(*region, *resourceType)
handleAWS(*region, *resourceType, *outputFolder)
case "gcp":
handleGCP(*region, *resourceType)
handleGCP(*region, *resourceType, *outputFolder)
case "azure":
handleAzure(*region, *resourceType)
handleAzure(*region, *resourceType, *outputFolder)
default:
fmt.Println("Unsupported cloud provider")
}
Expand All @@ -66,7 +69,7 @@ func generateReport() {
// Handle the cloud region based on the input
switch *cloudProvider {
case "aws":
awshandler.GenerateAWSReport()
awshandler.GenerateAWSReport(*outputFolder)
case "gcp":
fmt.Println("Report generation not implemented yet for gcp")
case "azure":
Expand All @@ -76,20 +79,20 @@ func generateReport() {
}
}

func handleAWS(region, resourceType string) {
func handleAWS(region, resourceType string, outFolder string) {
// Implement AWS-specific logic here
fmt.Printf("Provider: AWS \nregion: %s \n", region)
awshandler.StoreAWSData(region)
awshandler.StoreAWSData(region, outFolder)

}

func handleGCP(region, resourceType string) {
func handleGCP(region, resourceType string, outFolder string) {
// Implement GCP-specific logic here
fmt.Printf("Provider: GCP \n region: %s on resource: %s\n", region, resourceType)

}

func handleAzure(region, resourceType string) {
func handleAzure(region, resourceType string, outFolder string) {
// Implement Azure-specific logic here
fmt.Printf("Provider: Azure \n region: %s on resource: %s\n", region, resourceType)

Expand Down
8 changes: 6 additions & 2 deletions services/awshandler/generatereport.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ import (
"github.com/Cloud-Code-AI/cloudstate/services/utils"
)

func GenerateAWSReport() {
func GenerateAWSReport(outFolder string) {
// Get the most recent data stored for a provider
dir := "./output/aws/"

if outFolder == "" {
outFolder = "output"
}
dir := outFolder + "/aws/"

// Compiles and list all the stats in a single file.
regionStats := make(map[string]map[string]interface{})
Expand Down
7 changes: 5 additions & 2 deletions services/awshandler/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type BasicTemplate struct {
Data interface{} `json:"data"`
}

func StoreAWSData(region string) {
func StoreAWSData(region string, outFolder string) {

var regions []string

Expand All @@ -56,7 +56,10 @@ func StoreAWSData(region string) {
}

// parentpath := "output/aws/" + time.Now().Format("2006-01-02T15:04:05") + "/"
parentpath := "output/aws/"
if outFolder == "" {
outFolder = "output"
}
parentpath := outFolder + "/aws/"

for _, region := range regions {
sdkConfig, err := config.LoadDefaultConfig(
Expand Down

0 comments on commit dd8b75c

Please sign in to comment.