Merge pull request #9 from harshavardhana/pr_out_implement_configure_command_and_update_description
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# Minio Client
|
||||
|
||||
mc - unified command line interface for Minio Object Storage released under [Apache license v2](./LICENSE).
|
||||
mc - unified command line interface for Minio Object Storage compatible with Amazon S3 API released under [Apache license v2](./LICENSE).
|
||||
|
||||
# Install
|
||||
|
||||
|
||||
+36
-16
@@ -23,7 +23,7 @@ import (
|
||||
var GetObject = cli.Command{
|
||||
Name: "get-object",
|
||||
Usage: "",
|
||||
Description: "",
|
||||
Description: "Retrieves objects from Amazon S3.",
|
||||
Action: doGetObject,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
@@ -42,7 +42,7 @@ var GetObject = cli.Command{
|
||||
var PutObject = cli.Command{
|
||||
Name: "put-object",
|
||||
Usage: "",
|
||||
Description: "",
|
||||
Description: "Adds an object to a bucket.",
|
||||
Action: doPutObject,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
@@ -64,10 +64,12 @@ var PutObject = cli.Command{
|
||||
}
|
||||
|
||||
var ListObjects = cli.Command{
|
||||
Name: "list-objects",
|
||||
Usage: "",
|
||||
Description: "",
|
||||
Action: doListObjects,
|
||||
Name: "list-objects",
|
||||
Usage: "",
|
||||
Description: `Returns some or all (up to 1000) of the objects in a bucket.
|
||||
You can use the request parameters as selection criteria to
|
||||
return a subset of the objects in a bucket.`,
|
||||
Action: doListObjects,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "bucket",
|
||||
@@ -78,18 +80,36 @@ var ListObjects = cli.Command{
|
||||
}
|
||||
|
||||
var ListBuckets = cli.Command{
|
||||
Name: "list-buckets",
|
||||
Usage: "",
|
||||
Description: "",
|
||||
Action: doListBuckets,
|
||||
Name: "list-buckets",
|
||||
Usage: "",
|
||||
Description: `Returns a list of all buckets owned by the authenticated
|
||||
sender of the request.`,
|
||||
Action: doListBuckets,
|
||||
}
|
||||
|
||||
var Configure = cli.Command{
|
||||
Name: "configure",
|
||||
Usage: "",
|
||||
Description: "",
|
||||
Action: doConfigure,
|
||||
Name: "configure",
|
||||
Usage: "",
|
||||
Description: `Configure minio client configuration data. If your config
|
||||
file does not exist (the default location is ~/.s3auth), it will be
|
||||
automatically created for you. Note that the configure command only writes
|
||||
values to the config file. It does not use any configuration values from
|
||||
the environment variables.`,
|
||||
Action: doConfigure,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "accesskey",
|
||||
Value: "",
|
||||
Usage: "AWS access key id",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "secretkey",
|
||||
Value: "",
|
||||
Usage: "AWS secret key id",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func doConfigure(c *cli.Context) {
|
||||
}
|
||||
const (
|
||||
S3_AUTH = ".s3auth"
|
||||
)
|
||||
|
||||
@@ -17,22 +17,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/minio-io/mc/pkg/s3"
|
||||
)
|
||||
|
||||
type MinioClient struct {
|
||||
bucketName string
|
||||
keyName string
|
||||
body string
|
||||
bucketAcls string
|
||||
policy string
|
||||
region string
|
||||
query string // TODO
|
||||
}
|
||||
|
||||
var Options = []cli.Command{
|
||||
Cp,
|
||||
Ls,
|
||||
@@ -48,21 +41,42 @@ var Options = []cli.Command{
|
||||
Configure,
|
||||
}
|
||||
|
||||
func getAWSEnvironment() (accessKey, secretKey string, err error) {
|
||||
accessKey = os.Getenv("AWS_ACCESS_KEY_ID")
|
||||
secretKey = os.Getenv("AWS_SECRET_ACCESS_KEY")
|
||||
if accessKey == "" && secretKey == "" {
|
||||
errstr := `You can configure your credentials by running "mc configure"`
|
||||
return "", "", errors.New(errstr)
|
||||
}
|
||||
if accessKey == "" {
|
||||
errstr := `Partial credentials found in the env, missing : AWS_ACCESS_KEY_ID`
|
||||
return "", "", errors.New(errstr)
|
||||
}
|
||||
func getAuthFilePath() string {
|
||||
home := os.Getenv("HOME")
|
||||
return path.Join(home, S3_AUTH)
|
||||
}
|
||||
|
||||
if secretKey == "" {
|
||||
errstr := `Partial credentials found in the env, missing : AWS_SECRET_ACCESS_KEY`
|
||||
return "", "", errors.New(errstr)
|
||||
func getAWSEnvironment() (accessKey, secretKey string, err error) {
|
||||
var s3Auth *os.File
|
||||
var auth s3.Auth
|
||||
s3Auth, err = os.OpenFile(getAuthFilePath(), os.O_RDWR, 0666)
|
||||
defer s3Auth.Close()
|
||||
if err != nil {
|
||||
accessKey = os.Getenv("AWS_ACCESS_KEY_ID")
|
||||
secretKey = os.Getenv("AWS_SECRET_ACCESS_KEY")
|
||||
if accessKey == "" && secretKey == "" {
|
||||
errstr := `You can configure your credentials by running "mc configure"`
|
||||
return "", "", errors.New(errstr)
|
||||
}
|
||||
if accessKey == "" {
|
||||
errstr := `Partial credentials found in the env, missing : AWS_ACCESS_KEY_ID`
|
||||
return "", "", errors.New(errstr)
|
||||
}
|
||||
|
||||
if secretKey == "" {
|
||||
errstr := `Partial credentials found in the env, missing : AWS_SECRET_ACCESS_KEY`
|
||||
return "", "", errors.New(errstr)
|
||||
}
|
||||
} else {
|
||||
var n int
|
||||
s3Authbytes := make([]byte, 256)
|
||||
n, err = s3Auth.Read(s3Authbytes)
|
||||
err = json.Unmarshal(s3Authbytes[:n], &auth)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
accessKey = auth.AccessKey
|
||||
secretKey = auth.SecretAccessKey
|
||||
}
|
||||
|
||||
return accessKey, secretKey, nil
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/minio-io/mc/pkg/s3"
|
||||
)
|
||||
|
||||
func parseConfigureInput(c *cli.Context) (accessKey, secretKey string, err error) {
|
||||
accessKey = c.String("accesskey")
|
||||
secretKey = c.String("secretkey")
|
||||
if accessKey == "" {
|
||||
return "", "", errors.New("accesskey is mandatory")
|
||||
}
|
||||
if secretKey == "" {
|
||||
return "", "", errors.New("secretkey is mandatory")
|
||||
}
|
||||
return accessKey, secretKey, nil
|
||||
}
|
||||
|
||||
func doConfigure(c *cli.Context) {
|
||||
var err error
|
||||
var jAuth []byte
|
||||
var accessKey, secretKey string
|
||||
accessKey, secretKey, err = parseConfigureInput(c)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
auth := s3.NewAuth(accessKey, secretKey, "s3.amazonaws.com")
|
||||
jAuth, err = json.Marshal(auth)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var s3File *os.File
|
||||
home := os.Getenv("HOME")
|
||||
s3File, err = os.OpenFile(path.Join(home, S3_AUTH), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
|
||||
defer s3File.Close()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = s3File.Write(jAuth)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@ package main
|
||||
|
||||
import (
|
||||
"github.com/codegangsta/cli"
|
||||
// "github.com/minio-io/mc/pkg/s3"
|
||||
)
|
||||
|
||||
var Cp = cli.Command{
|
||||
|
||||
+10
-6
@@ -347,13 +347,17 @@ func (c *Client) Delete(bucket, key string) error {
|
||||
return fmt.Errorf("Amazon HTTP error on DELETE: %d", res.StatusCode)
|
||||
}
|
||||
|
||||
func NewAuth(accessKey, secretKey, hostname string) (auth *Auth) {
|
||||
auth = &Auth{
|
||||
AccessKey: accessKey,
|
||||
SecretAccessKey: secretKey,
|
||||
Hostname: hostname}
|
||||
return
|
||||
}
|
||||
|
||||
func NewS3Client(accessKey, secretKey, hostname string) (client *Client) {
|
||||
client = &Client{
|
||||
&Auth{
|
||||
AccessKey: accessKey,
|
||||
SecretAccessKey: secretKey,
|
||||
Hostname: hostname},
|
||||
http.DefaultTransport}
|
||||
auth := NewAuth(accessKey, secretKey, hostname)
|
||||
client = &Client{auth, http.DefaultTransport}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user