-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
a0f3d8d
commit 01bc4bb
Showing
10 changed files
with
144 additions
and
82 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 |
---|---|---|
@@ -1,29 +1,29 @@ | ||
{ | ||
"document": [ | ||
{ | ||
"id": "0", | ||
"file": "file", | ||
"resource": { | ||
"aws_redshift_cluster": { | ||
"default": { | ||
"master_password": "Mustbe8characters", | ||
"node_type": "dc1.large", | ||
"cluster_type": "single-node", | ||
"cluster_identifier": "tf-redshift-cluster", | ||
"database_name": "mydb", | ||
"master_username": "foo" | ||
}, | ||
"default1": { | ||
"master_username": "foo", | ||
"master_password": "Mustbe8characters", | ||
"node_type": "dc1.large", | ||
"cluster_type": "single-node", | ||
"publicly_accessible": true, | ||
"cluster_identifier": "tf-redshift-cluster", | ||
"database_name": "mydb" | ||
} | ||
} | ||
} | ||
} | ||
] | ||
"document": [ | ||
{ | ||
"id": "0", | ||
"file": "file", | ||
"resource": { | ||
"aws_redshift_cluster": { | ||
"default": { | ||
"master_password": "Mustbe8characters", | ||
"node_type": "dc1.large", | ||
"cluster_type": "single-node", | ||
"cluster_identifier": "tf-redshift-cluster", | ||
"database_name": "mydb", | ||
"master_username": "foo" | ||
}, | ||
"default1": { | ||
"master_username": "foo", | ||
"master_password": "Mustbe8characters", | ||
"node_type": "dc1.large", | ||
"cluster_type": "single-node", | ||
"publicly_accessible": true, | ||
"cluster_identifier": "tf-redshift-cluster", | ||
"database_name": "mydb" | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} |
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
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,30 +1,32 @@ | ||
package report | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
const jsonExtension = ".json" | ||
|
||
// PrintJSONReport prints on JSON file the summary results | ||
func PrintJSONReport(path, filename string, body interface{}) error { | ||
if !strings.Contains(filename, ".") { | ||
filename += jsonExtension | ||
} | ||
fullPath := filepath.Join(path, filename) | ||
|
||
f, err := os.OpenFile(filepath.Clean(fullPath), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.ModePerm) | ||
if err != nil { | ||
return err | ||
} | ||
if body != "" { | ||
summary, err := getSummary(body) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
defer closeFile(fullPath, filename, f) | ||
basePath, err := os.Getwd() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
encoder := json.NewEncoder(f) | ||
encoder.SetIndent("", "\t") | ||
for i := range summary.Queries { | ||
query := summary.Queries[i] | ||
for j := range query.Files { | ||
query.Files[j].FileName = getRelativePath(basePath, query.Files[j].FileName) | ||
} | ||
} | ||
body = summary | ||
} | ||
|
||
return encoder.Encode(body) | ||
return ExportJSONReport(path, filename, body) | ||
} |
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