Add minio cli, move 's3' stuff with 's3' prefix
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
||||
"path"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/minio-io/mc/pkg/minio"
|
||||
"github.com/minio-io/mc/pkg/s3"
|
||||
)
|
||||
|
||||
@@ -36,6 +37,11 @@ var Options = []cli.Command{
|
||||
Usage: "",
|
||||
Subcommands: subS3APIOptions,
|
||||
},
|
||||
{
|
||||
Name: "minio",
|
||||
Usage: "",
|
||||
Subcommands: subMinioApiOptions,
|
||||
},
|
||||
}
|
||||
|
||||
var subS3Options = []cli.Command{
|
||||
@@ -53,15 +59,43 @@ var subS3APIOptions = []cli.Command{
|
||||
Configure,
|
||||
}
|
||||
|
||||
func getAuthFilePath() string {
|
||||
var subMinioApiOptions = []cli.Command{
|
||||
MinioGetObject,
|
||||
MinioPutObject,
|
||||
MinioListObjects,
|
||||
MinioListBuckets,
|
||||
MinioConfigure,
|
||||
}
|
||||
|
||||
func getAWSAuthFilePath() string {
|
||||
home := os.Getenv("HOME")
|
||||
return path.Join(home, AUTH)
|
||||
return path.Join(home, S3_AUTH)
|
||||
}
|
||||
|
||||
func getMinioAuthFilePath() string {
|
||||
home := os.Getenv("HOME")
|
||||
return path.Join(home, MINIO_AUTH)
|
||||
}
|
||||
|
||||
// TODO reply full json
|
||||
func getMinioEnvironment() (hostname string, err error) {
|
||||
var auth *minio.Auth
|
||||
minioAuth, err := os.OpenFile(getMinioAuthFilePath(), os.O_RDWR, 0666)
|
||||
defer minioAuth.Close()
|
||||
var n int
|
||||
minioAuthbytes := make([]byte, 256)
|
||||
n, err = minioAuth.Read(minioAuthbytes)
|
||||
err = json.Unmarshal(minioAuthbytes[:n], &auth)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return auth.Hostname, nil
|
||||
}
|
||||
|
||||
func getAWSEnvironment() (auth *s3.Auth, err error) {
|
||||
var s3Auth *os.File
|
||||
var accessKey, secretKey string
|
||||
s3Auth, err = os.OpenFile(getAuthFilePath(), os.O_RDWR, 0666)
|
||||
s3Auth, err = os.OpenFile(getAWSAuthFilePath(), os.O_RDWR, 0666)
|
||||
defer s3Auth.Close()
|
||||
if err != nil {
|
||||
accessKey = os.Getenv("AWS_ACCESS_KEY_ID")
|
||||
|
||||
+29
-2
@@ -7,6 +7,7 @@ import (
|
||||
"path"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/minio-io/mc/pkg/minio"
|
||||
"github.com/minio-io/mc/pkg/s3"
|
||||
)
|
||||
|
||||
@@ -22,7 +23,33 @@ func parseConfigureInput(c *cli.Context) (accessKey, secretKey string, err error
|
||||
return accessKey, secretKey, nil
|
||||
}
|
||||
|
||||
func doConfigure(c *cli.Context) {
|
||||
func doMinioConfigure(c *cli.Context) {
|
||||
hostname := c.String("hostname")
|
||||
if hostname == "" {
|
||||
log.Fatal("Invalid hostname")
|
||||
}
|
||||
auth := &minio.Auth{"", "", hostname}
|
||||
jAuth, err := json.Marshal(auth)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var minioFile *os.File
|
||||
home := os.Getenv("HOME")
|
||||
minioFile, err = os.OpenFile(path.Join(home, MINIO_AUTH), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
|
||||
defer minioFile.Close()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = minioFile.Write(jAuth)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func doS3Configure(c *cli.Context) {
|
||||
var err error
|
||||
var jAuth []byte
|
||||
var accessKey, secretKey string
|
||||
@@ -39,7 +66,7 @@ func doConfigure(c *cli.Context) {
|
||||
|
||||
var s3File *os.File
|
||||
home := os.Getenv("HOME")
|
||||
s3File, err = os.OpenFile(path.Join(home, AUTH), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
|
||||
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)
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* 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 (
|
||||
"github.com/codegangsta/cli"
|
||||
)
|
||||
|
||||
var MinioGetObject = cli.Command{
|
||||
Name: "get-object",
|
||||
Usage: "",
|
||||
Description: "Retrieves objects from Amazon S3.",
|
||||
Action: minioGetObject,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "bucket",
|
||||
Value: "",
|
||||
Usage: "bucket name",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "key",
|
||||
Value: "",
|
||||
Usage: "path to Object",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var MinioPutObject = cli.Command{
|
||||
Name: "put-object",
|
||||
Usage: "",
|
||||
Description: "Adds an object to a bucket.",
|
||||
Action: minioPutObject,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "bucket",
|
||||
Value: "",
|
||||
Usage: "bucket name",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "key",
|
||||
Value: "",
|
||||
Usage: "Object name",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "body",
|
||||
Value: "",
|
||||
Usage: "Object blob",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var MinioListObjects = cli.Command{
|
||||
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: minioListObjects,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "bucket",
|
||||
Value: "",
|
||||
Usage: "Bucket name",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var MinioListBuckets = cli.Command{
|
||||
Name: "list-buckets",
|
||||
Usage: "",
|
||||
Description: `Returns a list of all buckets owned by the authenticated
|
||||
sender of the request.`,
|
||||
Action: minioListBuckets,
|
||||
}
|
||||
|
||||
var MinioConfigure = cli.Command{
|
||||
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: doMinioConfigure,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "hostname",
|
||||
Value: "127.0.0.1:8080",
|
||||
Usage: "Minio object server",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const (
|
||||
MINIO_AUTH = ".minioauth"
|
||||
)
|
||||
|
||||
func minioPutObject(c *cli.Context) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
func minioListBuckets(c *cli.Context) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
func minioListObjects(c *cli.Context) {
|
||||
//TODO
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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 (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/minio-io/mc/pkg/minio"
|
||||
)
|
||||
|
||||
func minioGetObject(c *cli.Context) {
|
||||
var bucket, key, hostname string
|
||||
var err error
|
||||
var objectReader io.ReadCloser
|
||||
var objectSize int64
|
||||
|
||||
hostname, err = getMinioEnvironment()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
bucket = c.String("bucket")
|
||||
key = c.String("key")
|
||||
if bucket == "" {
|
||||
log.Fatal(bucketNameErr)
|
||||
}
|
||||
if key == "" {
|
||||
log.Fatal(objectNameErr)
|
||||
}
|
||||
|
||||
minio := minio.NewMinioClient(hostname)
|
||||
objectReader, objectSize, err = minio.Get(bucket, key)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = io.CopyN(os.Stdout, objectReader, objectSize)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package minio
|
||||
|
||||
type Auth struct {
|
||||
AccessKey string
|
||||
SecretAccessKey string
|
||||
Hostname string
|
||||
}
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/minio-io/mc/pkg/minio"
|
||||
)
|
||||
|
||||
func main() {
|
||||
newminio := minio.NewMinioClient("127.0.0.1:8080")
|
||||
objectReader, objectSize, err := newminio.Get("bucketname", "test")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = io.CopyN(os.Stdout, objectReader, objectSize)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -95,7 +95,7 @@ var Configure = cli.Command{
|
||||
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,
|
||||
Action: doS3Configure,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "accesskey",
|
||||
@@ -111,5 +111,5 @@ var Configure = cli.Command{
|
||||
}
|
||||
|
||||
const (
|
||||
AUTH = ".auth"
|
||||
S3_AUTH = ".auth"
|
||||
)
|
||||
Reference in New Issue
Block a user