add s3 dirctory option (#457)

This commit is contained in:
sadayuki-matsuno
2017-08-07 11:48:10 +09:00
committed by kota kanbe
parent 0a3f0f9ffc
commit cbd1c12773
6 changed files with 25 additions and 12 deletions

4
Gopkg.lock generated
View File

@@ -44,10 +44,10 @@
version = "v1.0.0"
[[projects]]
branch = "master"
name = "github.com/cheggaaa/pb"
packages = ["."]
revision = "f6ccf2184de4dd34495277e38dc19b6e7fbe0ea2"
version = "v1.0.15"
revision = "0af82b7d15eb9371fbdf8f468ff10cbba62e0414"
[[projects]]
name = "github.com/dgrijalva/jwt-go"

View File

@@ -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]
@@ -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
@@ -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
```

View File

@@ -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]
@@ -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
@@ -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
```
@@ -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 ..

View File

@@ -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
@@ -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]
@@ -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",
@@ -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

View File

@@ -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

View File

@@ -22,6 +22,7 @@ import (
"encoding/json"
"encoding/xml"
"fmt"
"path"
"time"
"github.com/aws/aws-sdk-go/aws"
@@ -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",