summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/minio/minio-go/examples
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/minio/minio-go/examples')
-rw-r--r--vendor/github.com/minio/minio-go/examples/s3/composeobject.go74
-rw-r--r--vendor/github.com/minio/minio-go/examples/s3/copyobject.go18
-rw-r--r--vendor/github.com/minio/minio-go/examples/s3/get-encrypted-object.go6
-rw-r--r--vendor/github.com/minio/minio-go/examples/s3/put-encrypted-object.go5
-rw-r--r--vendor/github.com/minio/minio-go/examples/s3/putobject-getobject-sse.go87
-rw-r--r--vendor/github.com/minio/minio-go/examples/s3/putobject-progress.go5
6 files changed, 181 insertions, 14 deletions
diff --git a/vendor/github.com/minio/minio-go/examples/s3/composeobject.go b/vendor/github.com/minio/minio-go/examples/s3/composeobject.go
new file mode 100644
index 000000000..555d98bc3
--- /dev/null
+++ b/vendor/github.com/minio/minio-go/examples/s3/composeobject.go
@@ -0,0 +1,74 @@
+// +build ignore
+
+/*
+ * Minio Go Library for Amazon S3 Compatible Cloud Storage (C) 2016 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"
+
+ minio "github.com/minio/minio-go"
+)
+
+func main() {
+ // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-testfile, my-bucketname and
+ // my-objectname are dummy values, please replace them with original values.
+
+ // Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access.
+ // This boolean value is the last argument for New().
+
+ // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically
+ // determined based on the Endpoint value.
+ s3Client, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true)
+ if err != nil {
+ log.Fatalln(err)
+ }
+
+ // Enable trace.
+ // s3Client.TraceOn(os.Stderr)
+
+ // Prepare source decryption key (here we assume same key to
+ // decrypt all source objects.)
+ decKey := minio.NewSSEInfo([]byte{1, 2, 3}, "")
+
+ // Source objects to concatenate. We also specify decryption
+ // key for each
+ src1 := minio.NewSourceInfo("bucket1", "object1", decKey)
+ src1.SetMatchETag("31624deb84149d2f8ef9c385918b653a")
+
+ src2 := minio.NewSourceInfo("bucket2", "object2", decKey)
+ src2.SetMatchETag("f8ef9c385918b653a31624deb84149d2")
+
+ src3 := minio.NewSourceInfo("bucket3", "object3", decKey)
+ src3.SetMatchETag("5918b653a31624deb84149d2f8ef9c38")
+
+ // Create slice of sources.
+ srcs := []minio.SourceInfo{src1, src2, src3}
+
+ // Prepare destination encryption key
+ encKey := minio.NewSSEInfo([]byte{8, 9, 0}, "")
+
+ // Create destination info
+ dst := minio.NewDestinationInfo("bucket", "object", encKey)
+ err = s3Client.ComposeObject(dst, srcs)
+ if err != nil {
+ log.Println(err)
+ return
+ }
+
+ log.Println("Composed object successfully.")
+}
diff --git a/vendor/github.com/minio/minio-go/examples/s3/copyobject.go b/vendor/github.com/minio/minio-go/examples/s3/copyobject.go
index a9ec78fee..0de865555 100644
--- a/vendor/github.com/minio/minio-go/examples/s3/copyobject.go
+++ b/vendor/github.com/minio/minio-go/examples/s3/copyobject.go
@@ -42,24 +42,28 @@ func main() {
// Enable trace.
// s3Client.TraceOn(os.Stderr)
+ // Source object
+ src := minio.NewSourceInfo("my-sourcebucketname", "my-sourceobjectname", nil)
+
// All following conditions are allowed and can be combined together.
- // Set copy conditions.
- var copyConds = minio.CopyConditions{}
// Set modified condition, copy object modified since 2014 April.
- copyConds.SetModified(time.Date(2014, time.April, 0, 0, 0, 0, 0, time.UTC))
+ src.SetModifiedSinceCond(time.Date(2014, time.April, 0, 0, 0, 0, 0, time.UTC))
// Set unmodified condition, copy object unmodified since 2014 April.
- // copyConds.SetUnmodified(time.Date(2014, time.April, 0, 0, 0, 0, 0, time.UTC))
+ // src.SetUnmodifiedSinceCond(time.Date(2014, time.April, 0, 0, 0, 0, 0, time.UTC))
// Set matching ETag condition, copy object which matches the following ETag.
- // copyConds.SetMatchETag("31624deb84149d2f8ef9c385918b653a")
+ // src.SetMatchETagCond("31624deb84149d2f8ef9c385918b653a")
// Set matching ETag except condition, copy object which does not match the following ETag.
- // copyConds.SetMatchETagExcept("31624deb84149d2f8ef9c385918b653a")
+ // src.SetMatchETagExceptCond("31624deb84149d2f8ef9c385918b653a")
+
+ // Destination object
+ dst := minio.NewDestinationInfo("my-bucketname", "my-objectname", nil)
// Initiate copy object.
- err = s3Client.CopyObject("my-bucketname", "my-objectname", "/my-sourcebucketname/my-sourceobjectname", copyConds)
+ err = s3Client.CopyObject(dst, src)
if err != nil {
log.Fatalln(err)
}
diff --git a/vendor/github.com/minio/minio-go/examples/s3/get-encrypted-object.go b/vendor/github.com/minio/minio-go/examples/s3/get-encrypted-object.go
index e997140be..8f51f26ae 100644
--- a/vendor/github.com/minio/minio-go/examples/s3/get-encrypted-object.go
+++ b/vendor/github.com/minio/minio-go/examples/s3/get-encrypted-object.go
@@ -24,6 +24,7 @@ import (
"os"
"github.com/minio/minio-go"
+ "github.com/minio/minio-go/pkg/encrypt"
)
func main() {
@@ -59,10 +60,10 @@ func main() {
////
// Build a symmetric key
- symmetricKey := minio.NewSymmetricKey([]byte("my-secret-key-00"))
+ symmetricKey := encrypt.NewSymmetricKey([]byte("my-secret-key-00"))
// Build encryption materials which will encrypt uploaded data
- cbcMaterials, err := minio.NewCBCSecureMaterials(symmetricKey)
+ cbcMaterials, err := encrypt.NewCBCSecureMaterials(symmetricKey)
if err != nil {
log.Fatalln(err)
}
@@ -72,6 +73,7 @@ func main() {
if err != nil {
log.Fatalln(err)
}
+ defer reader.Close()
// Local file which holds plain data
localFile, err := os.Create("my-testfile")
diff --git a/vendor/github.com/minio/minio-go/examples/s3/put-encrypted-object.go b/vendor/github.com/minio/minio-go/examples/s3/put-encrypted-object.go
index f03f82147..b8f7e12f2 100644
--- a/vendor/github.com/minio/minio-go/examples/s3/put-encrypted-object.go
+++ b/vendor/github.com/minio/minio-go/examples/s3/put-encrypted-object.go
@@ -23,6 +23,7 @@ import (
"os"
"github.com/minio/minio-go"
+ "github.com/minio/minio-go/pkg/encrypt"
)
func main() {
@@ -65,10 +66,10 @@ func main() {
////
// Build a symmetric key
- symmetricKey := minio.NewSymmetricKey([]byte("my-secret-key-00"))
+ symmetricKey := encrypt.NewSymmetricKey([]byte("my-secret-key-00"))
// Build encryption materials which will encrypt uploaded data
- cbcMaterials, err := minio.NewCBCSecureMaterials(symmetricKey)
+ cbcMaterials, err := encrypt.NewCBCSecureMaterials(symmetricKey)
if err != nil {
log.Fatalln(err)
}
diff --git a/vendor/github.com/minio/minio-go/examples/s3/putobject-getobject-sse.go b/vendor/github.com/minio/minio-go/examples/s3/putobject-getobject-sse.go
new file mode 100644
index 000000000..92e6a4840
--- /dev/null
+++ b/vendor/github.com/minio/minio-go/examples/s3/putobject-getobject-sse.go
@@ -0,0 +1,87 @@
+// +build ignore
+
+/*
+ * Minio Go Library for Amazon S3 Compatible Cloud Storage (C) 2017 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 (
+ "bytes"
+ "crypto/md5"
+ "encoding/base64"
+ "io/ioutil"
+ "log"
+ "net/http"
+
+ minio "github.com/minio/minio-go"
+)
+
+func main() {
+ // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-testfile, my-bucketname and
+ // my-objectname are dummy values, please replace them with original values.
+
+ // New returns an Amazon S3 compatible client object. API compatibility (v2 or v4) is automatically
+ // determined based on the Endpoint value.
+ minioClient, err := minio.New("s3.amazonaws.com", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true)
+ if err != nil {
+ log.Fatalln(err)
+ }
+
+ content := bytes.NewReader([]byte("Hello again"))
+ key := []byte("32byteslongsecretkeymustprovided")
+ h := md5.New()
+ h.Write(key)
+ encryptionKey := base64.StdEncoding.EncodeToString(key)
+ encryptionKeyMD5 := base64.StdEncoding.EncodeToString(h.Sum(nil))
+
+ // Amazon S3 does not store the encryption key you provide.
+ // Instead S3 stores a randomly salted HMAC value of the
+ // encryption key in order to validate future requests.
+ // The salted HMAC value cannot be used to derive the value
+ // of the encryption key or to decrypt the contents of the
+ // encrypted object. That means, if you lose the encryption
+ // key, you lose the object.
+ var metadata = map[string][]string{
+ "x-amz-server-side-encryption-customer-algorithm": []string{"AES256"},
+ "x-amz-server-side-encryption-customer-key": []string{encryptionKey},
+ "x-amz-server-side-encryption-customer-key-MD5": []string{encryptionKeyMD5},
+ }
+
+ // minioClient.TraceOn(os.Stderr) // Enable to debug.
+ _, err = minioClient.PutObjectWithMetadata("mybucket", "my-encrypted-object.txt", content, metadata, nil)
+ if err != nil {
+ log.Fatalln(err)
+ }
+
+ var reqHeaders = minio.RequestHeaders{Header: http.Header{}}
+ for k, v := range metadata {
+ reqHeaders.Set(k, v[0])
+ }
+ coreClient := minio.Core{minioClient}
+ reader, _, err := coreClient.GetObject("mybucket", "my-encrypted-object.txt", reqHeaders)
+ if err != nil {
+ log.Fatalln(err)
+ }
+ defer reader.Close()
+
+ decBytes, err := ioutil.ReadAll(reader)
+ if err != nil {
+ log.Fatalln(err)
+ }
+ if !bytes.Equal(decBytes, []byte("Hello again")) {
+ log.Fatalln("Expected \"Hello, world\", got %s", string(decBytes))
+ }
+}
diff --git a/vendor/github.com/minio/minio-go/examples/s3/putobject-progress.go b/vendor/github.com/minio/minio-go/examples/s3/putobject-progress.go
index f668adf70..1179fd787 100644
--- a/vendor/github.com/minio/minio-go/examples/s3/putobject-progress.go
+++ b/vendor/github.com/minio/minio-go/examples/s3/putobject-progress.go
@@ -50,9 +50,8 @@ func main() {
log.Fatalln(err)
}
- // progress reader is notified as PutObject makes progress with
- // the read. For partial resume put object, progress reader is
- // appropriately advanced.
+ // Progress reader is notified as PutObject makes progress with
+ // the Reads inside.
progress := pb.New64(objectInfo.Size)
progress.Start()