-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide a new command, gof3r info, which fetches metadata about an ob…
…ject. The new command will print some small bits of metadata about an object on success and will exit with a non-zero exit code on failure. The info command can be used to query for a file's existence without downloading it, and performs only a HEAD request. Fixes #71
- Loading branch information
Showing
3 changed files
with
98 additions
and
0 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,60 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/rlmcpherson/s3gof3r" | ||
) | ||
|
||
var info infoOpts | ||
|
||
type infoOpts struct { | ||
Key string `long:"key" short:"k" description:"S3 object key" required:"true" no-ini:"true"` | ||
Bucket string `long:"bucket" short:"b" description:"S3 bucket" required:"true" no-ini:"true"` | ||
VersionID string `short:"v" long:"versionId" description:"Version ID of the object. Incompatible with md5 check (use --no-md5)." no-ini:"true"` | ||
} | ||
|
||
func (info *infoOpts) Execute(args []string) (err error) { | ||
conf := new(s3gof3r.Config) | ||
*conf = *s3gof3r.DefaultConfig | ||
k, err := getAWSKeys() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
s3 := s3gof3r.New(get.EndPoint, k) | ||
b := s3.Bucket(info.Bucket) | ||
conf.Concurrency = get.Concurrency | ||
|
||
if get.NoSSL { | ||
conf.Scheme = "http" | ||
} | ||
|
||
resp, err := s3gof3r.GetInfo(b, s3gof3r.DefaultConfig, info.Key, info.VersionID) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
if resp.StatusCode >= 200 && resp.StatusCode < 300 { | ||
log.Println("Found object:") | ||
log.Println(" Status: ", resp.StatusCode) | ||
log.Println(" Last-Modified: ", resp.Header["Last-Modified"]) | ||
log.Println(" Size: ", resp.Header["Content-Length"]) | ||
} else if resp.StatusCode == 403 { | ||
log.Fatal("Access Denied") | ||
} else { | ||
log.Fatal("Non-2XX status code: ", resp.StatusCode) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func init() { | ||
_, err := parser.AddCommand("info", "check info from S3", "get information about an object from S3", &info) | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
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