Skip to content

Commit

Permalink
add s3 dirctory option (#457)
Browse files Browse the repository at this point in the history
  • Loading branch information
sadayuki-matsuno authored and kotakanbe committed Aug 7, 2017
1 parent cc3541a commit 0a255f2
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,7 @@ report:
[-aws-profile=default]
[-aws-region=us-west-2]
[-aws-s3-bucket=bucket_name]
[-aws-s3-results-dir=/bucket/path/to/results]
[-azure-account=accout]
[-azure-key=key]
[-azure-container=container]
Expand All @@ -1060,6 +1061,8 @@ report:
AWS region to use (default "us-east-1")
-aws-s3-bucket string
S3 bucket name
-aws-s3-results-dir string
/bucket/path/to/results (option)
-azure-account string
Azure account name to use. AZURE_STORAGE_ACCOUNT environment variable is used if not specified
-azure-container string
Expand Down Expand Up @@ -1123,7 +1126,7 @@ report:
-to-localfile
Write report to localfile
-to-s3
Write report to S3 (bucket/yyyyMMdd_HHmm/servername.json/xml/txt)
Write report to S3 (bucket/dir/yyyyMMdd_HHmm/servername.json/xml/txt)
-to-slack
Send report via Slack
```
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,7 @@ report:
[-aws-profile=default]
[-aws-region=us-west-2]
[-aws-s3-bucket=bucket_name]
[-aws-s3-results-dir=/bucket/path/to/results]
[-azure-account=accout]
[-azure-key=key]
[-azure-container=container]
Expand All @@ -1073,6 +1074,8 @@ report:
AWS region to use (default "us-east-1")
-aws-s3-bucket string
S3 bucket name
-aws-s3-results-dir string
/bucket/path/to/results (option)
-azure-account string
Azure account name to use. AZURE_STORAGE_ACCOUNT environment variable is used if not specified
-azure-container string
Expand Down Expand Up @@ -1136,7 +1139,7 @@ report:
-to-localfile
Write report to localfile
-to-s3
Write report to S3 (bucket/yyyyMMdd_HHmm/servername.json/xml/txt)
Write report to S3 (bucket/dir/yyyyMMdd_HHmm/servername.json/xml/txt)
-to-slack
Send report via Slack
```
Expand Down Expand Up @@ -1286,6 +1289,7 @@ $ vuls report \
-format-json \
-aws-region=ap-northeast-1 \
-aws-s3-bucket=vuls \
-aws-s3-results-dir=/bucket/path/to/results \
-aws-profile=default
```
With this sample command, it will ..
Expand Down
10 changes: 7 additions & 3 deletions commands/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ type ReportCmd struct {

gzip bool

awsProfile string
awsS3Bucket string
awsRegion string
awsProfile string
awsS3Bucket string
awsS3ResultsDir string
awsRegion string

azureAccount string
azureKey string
Expand Down Expand Up @@ -121,6 +122,7 @@ func (*ReportCmd) Usage() string {
[-aws-profile=default]
[-aws-region=us-west-2]
[-aws-s3-bucket=bucket_name]
[-aws-s3-results-dir=/bucket/path/to/results]
[-azure-account=accout]
[-azure-key=key]
[-azure-container=container]
Expand Down Expand Up @@ -263,6 +265,7 @@ func (p *ReportCmd) SetFlags(f *flag.FlagSet) {
f.StringVar(&p.awsProfile, "aws-profile", "default", "AWS profile to use")
f.StringVar(&p.awsRegion, "aws-region", "us-east-1", "AWS region to use")
f.StringVar(&p.awsS3Bucket, "aws-s3-bucket", "", "S3 bucket name")
f.StringVar(&p.awsS3ResultsDir, "aws-s3-results-dir", "", "/bucket/path/to/results")

f.BoolVar(&p.toAzureBlob,
"to-azure-blob",
Expand Down Expand Up @@ -357,6 +360,7 @@ func (p *ReportCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}
c.Conf.AwsRegion = p.awsRegion
c.Conf.AwsProfile = p.awsProfile
c.Conf.S3Bucket = p.awsS3Bucket
c.Conf.S3ResultsDir = p.awsS3ResultsDir
if err := report.CheckIfBucketExists(); err != nil {
util.Log.Errorf("Check if there is a bucket beforehand: %s, err: %s", c.Conf.S3Bucket, err)
return subcommands.ExitUsageError
Expand Down
7 changes: 4 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ type Config struct {

GZIP bool

AwsProfile string
AwsRegion string
S3Bucket string
AwsProfile string
AwsRegion string
S3Bucket string
S3ResultsDir string

AzureAccount string
AzureKey string
Expand Down
5 changes: 3 additions & 2 deletions report/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"encoding/json"
"encoding/xml"
"fmt"
"path"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -147,8 +148,8 @@ func putObject(svc *s3.S3, k string, b []byte) error {
}

if _, err := svc.PutObject(&s3.PutObjectInput{
Bucket: &c.Conf.S3Bucket,
Key: &k,
Bucket: aws.String(c.Conf.S3Bucket),
Key: aws.String(path.Join(c.Conf.S3ResultsDir, k)),
Body: bytes.NewReader(b),
}); err != nil {
return fmt.Errorf("Failed to upload data to %s/%s, %s",
Expand Down

0 comments on commit 0a255f2

Please sign in to comment.