diff --git a/errors.go b/errors.go index b51b173c..6c28ff00 100644 --- a/errors.go +++ b/errors.go @@ -19,3 +19,4 @@ var configSecretErr = errors.New("secretkey is mandatory") var missingAccessSecretErr = errors.New("You can configure your credentials by running `mc configure`") var missingAccessErr = errors.New("Partial credentials found in the env, missing : AWS_ACCESS_KEY_ID") var missingSecretErr = errors.New("Partial credentials found in the env, missing : AWS_SECRET_ACCESS_KEY") +var invalidBucketErr = errors.New("Invalid bucket name") diff --git a/fs-mkdir.go b/fs-mkdir.go new file mode 100644 index 00000000..8cbd9ff4 --- /dev/null +++ b/fs-mkdir.go @@ -0,0 +1,47 @@ +/* + * Mini Object Storage, (C) 2014,2015 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "log" + + "github.com/codegangsta/cli" + "github.com/minio-io/mc/pkg/s3" +) + +func doFsMkdir(c *cli.Context) { + switch len(c.Args()) { + case 1: + if !s3.IsValidBucket(c.Args().Get(0)) { + log.Fatal(invalidBucketErr) + } + default: + log.Fatal() + } + bucketName := c.Args().Get(0) + var err error + var auth *s3.Auth + auth, err = getAWSEnvironment() + if err != nil { + log.Fatal(err) + } + s3c := s3.NewS3Client(auth) + err = s3c.PutBucket(bucketName) + if err != nil { + log.Fatal(err) + } +} diff --git a/fs-options.go b/fs-options.go index 86b6f6a3..9df2dde1 100644 --- a/fs-options.go +++ b/fs-options.go @@ -56,8 +56,5 @@ type fsOptions struct { isput bool } -func doFsMkdir(c *cli.Context) { -} - func doFsSync(c *cli.Context) { } diff --git a/pkg/s3/client.go b/pkg/s3/client.go index 016e53e8..dde4b9b4 100644 --- a/pkg/s3/client.go +++ b/pkg/s3/client.go @@ -127,6 +127,26 @@ func (c *Client) Stat(key, bucket string) (size int64, reterr error) { return 0, fmt.Errorf("s3: Unexpected status code %d statting object %v", res.StatusCode, key) } +func (c *Client) PutBucket(bucket string) error { + req := newReq(c.bucketURL(bucket)) + req.Method = "PUT" + c.Auth.SignRequest(req) + res, err := c.transport().RoundTrip(req) + if res != nil && res.Body != nil { + defer res.Body.Close() + } + + if err != nil { + return err + } + if res.StatusCode != http.StatusOK { + // res.Write(os.Stderr) + return fmt.Errorf("Got response code %d from s3", res.StatusCode) + } + return nil + +} + func (c *Client) Put(bucket, key string, md5 hash.Hash, size int64, body io.Reader) error { req := newReq(c.keyURL(bucket, key)) req.Method = "PUT"