Example #1
0
        private static void CreateBucketWithObjectLockConfiguration()
        {
            bucketName = S3TestUtils.CreateBucketWithWait(Client, new PutBucketRequest
            {
                ObjectLockEnabledForBucket = true,
            });

            var objectLockConfiguration = new ObjectLockConfiguration();

            objectLockConfiguration.ObjectLockEnabled = ObjectLockEnabled.Enabled;
            objectLockConfiguration.Rule = new ObjectLockRule
            {
                DefaultRetention = new DefaultRetention
                {
                    Days = 1,
                    Mode = ObjectLockRetentionMode.Governance
                }
            };

            var putRequest = new PutObjectLockConfigurationRequest
            {
                BucketName              = bucketName,
                RequestPayer            = RequestPayer.Requester,
                ObjectLockConfiguration = objectLockConfiguration
            };

            var putResponse = Client.PutObjectLockConfiguration(putRequest);
        }
Example #2
0
        // Get the Object Lock Configuration on the bucket
        public async static Task Run(MinioClient minio,
                                     string bucketName = "my-bucket-name")
        {
            try
            {
                Console.WriteLine("Running example for API: GetObjectLockConfiguration");
                ObjectLockConfiguration config = await minio.GetObjectLockConfigurationAsync(
                    new GetObjectLockConfigurationArgs()
                    .WithBucket(bucketName)
                    );

                if (config != null)
                {
                    Console.WriteLine($"Object lock configuration on bucket {bucketName} is : " + config.ObjectLockEnabled);
                    if (config.Rule != null && config.Rule.DefaultRetention != null)
                    {
                        string mode = (config.Rule.DefaultRetention.Mode == RetentionMode.GOVERNANCE)? "GOVERNANCE" : "COMPLIANCE";
                        Console.WriteLine("Object Lock Configuration Rule Mode: " + mode + " Duration: " + config.Rule.DefaultRetention.Days + " days.");
                    }
                    Console.WriteLine();
                    return;
                }
                Console.WriteLine($"Object lock configuration unavailable on bucket {bucketName}.");
                Console.WriteLine();
            }
            catch (Exception e)
            {
                Console.WriteLine($"[Bucket]  Exception: {e}");
            }
        }
Example #3
0
        public PutObjectLockConfigurationResponse AddObjectLockConfiguration()
        {
            var objectLockConfiguration = new ObjectLockConfiguration();

            objectLockConfiguration.ObjectLockEnabled = ObjectLockEnabled.Enabled;
            objectLockConfiguration.Rule = new ObjectLockRule
            {
                DefaultRetention = new DefaultRetention
                {
                    Days = 1,
                    Mode = ObjectLockRetentionMode.Governance
                }
            };

            var putRequest = new PutObjectLockConfigurationRequest
            {
                BucketName              = bucketName,
                RequestPayer            = RequestPayer.Requester,
                ObjectLockConfiguration = objectLockConfiguration
            };

            var putResponse = Client.PutObjectLockConfiguration(putRequest);

            Assert.AreEqual(true, putResponse.HttpStatusCode == HttpStatusCode.OK);

            return(putResponse);
        }
 internal GetObjectLockConfigurationResponse(HttpStatusCode statusCode, string responseContent)
     : base(statusCode, responseContent)
 {
     if (string.IsNullOrEmpty(responseContent) || !HttpStatusCode.OK.Equals(statusCode))
     {
         this.LockConfiguration = null;
         return;
     }
     using (var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(responseContent)))
     {
         this.LockConfiguration = (ObjectLockConfiguration) new XmlSerializer(typeof(ObjectLockConfiguration)).Deserialize(stream);
     }
 }
    // Set Object Lock Configuration on the bucket
    public static async Task Run(MinioClient minio,
                                 string bucketName = "my-bucket-name",
                                 ObjectLockConfiguration config = null)
    {
        try
        {
            Console.WriteLine("Running example for API: SetObjectLockConfiguration");
            await minio.SetObjectLockConfigurationAsync(
                new SetObjectLockConfigurationArgs()
                .WithBucket(bucketName)
                .WithLockConfiguration(config)
                );

            Console.WriteLine($"Set object lock configuration on bucket {bucketName}");
            Console.WriteLine();
        }
        catch (Exception e)
        {
            Console.WriteLine($"[Bucket]  Exception: {e}");
        }
    }
        public PutObjectLockConfigurationResponse AddObjectLockConfiguration()
        {
            var objectLockConfiguration = new ObjectLockConfiguration();

            objectLockConfiguration.ObjectLockEnabled = ObjectLockEnabled.Enabled;
            objectLockConfiguration.Rule = new ObjectLockRule
            {
                DefaultRetention = new DefaultRetention
                {
                    Days = 1,
                    Mode = ObjectLockRetentionMode.Governance
                }
            };

            var putRequest = new PutObjectLockConfigurationRequest
            {
                BucketName              = bucketName,
                RequestPayer            = RequestPayer.Requester,
                ObjectLockConfiguration = objectLockConfiguration
            };

            var putResponse = Client.PutObjectLockConfiguration(putRequest);

            Assert.AreEqual(true, putResponse.HttpStatusCode == HttpStatusCode.OK);

            //Make sure the object lock has been enabled
            var getRequest = new GetObjectLockConfigurationRequest()
            {
                BucketName = bucketName
            };
            var getResponse = S3TestUtils.WaitForConsistency(() =>
            {
                var res = Client.GetObjectLockConfiguration(getRequest);
                return(res.ObjectLockConfiguration?.ObjectLockEnabled == ObjectLockEnabled.Enabled ? res : null);
            });

            return(putResponse);
        }
 public SetObjectLockConfigurationArgs WithLockConfiguration(ObjectLockConfiguration config)
 {
     LockConfiguration = config;
     return(this);
 }
Example #8
0
        public static void Main(string[] args)
        {
            string endPoint    = null;
            string accessKey   = null;
            string secretKey   = null;
            bool   enableHTTPS = false;
            int    port        = 80;

            if (Environment.GetEnvironmentVariable("SERVER_ENDPOINT") != null)
            {
                endPoint = Environment.GetEnvironmentVariable("SERVER_ENDPOINT");
                int posColon = endPoint.LastIndexOf(':');
                if (posColon != -1)
                {
                    port     = Int32.Parse(endPoint.Substring(posColon + 1, (endPoint.Length - posColon - 1)));
                    endPoint = endPoint.Substring(0, posColon);
                }
                accessKey = Environment.GetEnvironmentVariable("ACCESS_KEY");
                secretKey = Environment.GetEnvironmentVariable("SECRET_KEY");
                if (Environment.GetEnvironmentVariable("ENABLE_HTTPS") != null)
                {
                    enableHTTPS = Environment.GetEnvironmentVariable("ENABLE_HTTPS").Equals("1");
                    if (enableHTTPS && port == 80)
                    {
                        port = 443;
                    }
                }
            }
            else
            {
                endPoint    = "play.min.io";
                accessKey   = "Q3AM3UQ867SPQQA43P2F";
                secretKey   = "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG";
                enableHTTPS = true;
                port        = 443;
            }

            ServicePointManager.ServerCertificateValidationCallback +=
                (sender, certificate, chain, sslPolicyErrors) => true;

            // WithSSL() enables SSL support in MinIO client
            MinioClient minioClient = null;

            if (enableHTTPS)
            {
                minioClient = new MinioClient()
                              .WithEndpoint(endPoint, port)
                              .WithCredentials(accessKey, secretKey)
                              .WithSSL()
                              .Build();
            }
            else
            {
                minioClient = new MinioClient()
                              .WithEndpoint(endPoint, port)
                              .WithCredentials(accessKey, secretKey)
                              .Build();
            }
            // Assign parameters before starting the test
            string        bucketName     = GetRandomName();
            string        smallFileName  = CreateFile(1 * UNIT_MB);
            string        bigFileName    = CreateFile(6 * UNIT_MB);
            string        objectName     = GetRandomName();
            string        destBucketName = GetRandomName();
            string        destObjectName = GetRandomName();
            string        lockBucketName = GetRandomName();
            List <string> objectsList    = new List <string>();

            for (int i = 0; i < 10; i++)
            {
                objectsList.Add(objectName + i.ToString());
            }
            // Set app Info
            minioClient.SetAppInfo("app-name", "app-version");

            // Set HTTP Tracing On
            // minioClient.SetTraceOn();

            // Set HTTP Tracing Off
            // minioClient.SetTraceOff();
            // Check if bucket exists
            Cases.BucketExists.Run(minioClient, bucketName).Wait();

            // Create a new bucket
            Cases.MakeBucket.Run(minioClient, bucketName).Wait();
            Cases.MakeBucket.Run(minioClient, destBucketName).Wait();

            // Bucket with Lock tests
            Cases.MakeBucketWithLock.Run(minioClient, lockBucketName).Wait();
            Cases.BucketExists.Run(minioClient, lockBucketName).Wait();
            Cases.RemoveBucket.Run(minioClient, lockBucketName).Wait();

            // Versioning tests
            Cases.GetVersioning.Run(minioClient, bucketName).Wait();
            Cases.EnableSuspendVersioning.Run(minioClient, bucketName).Wait();
            Cases.GetVersioning.Run(minioClient, bucketName).Wait();
            // List all the buckets on the server
            Cases.ListBuckets.Run(minioClient).Wait();

            // Start listening for bucket notifications
            Cases.ListenBucketNotifications.Run(minioClient, bucketName, new List <EventType> {
                EventType.ObjectCreatedAll
            });

            // Put an object to the new bucket
            Cases.PutObject.Run(minioClient, bucketName, objectName, smallFileName).Wait();

            // Get object metadata
            Cases.StatObject.Run(minioClient, bucketName, objectName).Wait();

            // List the objects in the new bucket
            Cases.ListObjects.Run(minioClient, bucketName);

            // Get the file and Download the object as file
            Cases.GetObject.Run(minioClient, bucketName, objectName, smallFileName).Wait();
            // Select content from object
            Cases.SelectObjectContent.Run(minioClient, bucketName, objectName).Wait();
            // Delete the file and Download partial object as file
            Cases.GetPartialObject.Run(minioClient, bucketName, objectName, smallFileName).Wait();

            // Server side copyObject
            Cases.CopyObject.Run(minioClient, bucketName, objectName, destBucketName, objectName).Wait();

            // Server side copyObject with metadata replacement
            Cases.CopyObjectMetadata.Run(minioClient, bucketName, objectName, destBucketName, objectName).Wait();

            // Upload a File with PutObject
            Cases.FPutObject.Run(minioClient, bucketName, objectName, smallFileName).Wait();

            // Delete the file and Download the object as file
            Cases.FGetObject.Run(minioClient, bucketName, objectName, smallFileName).Wait();

            // Automatic Multipart Upload with object more than 5Mb
            Cases.PutObject.Run(minioClient, bucketName, objectName, bigFileName).Wait();

            // Specify SSE-C encryption options
            var aesEncryption = Aes.Create();

            aesEncryption.KeySize = 256;
            aesEncryption.GenerateKey();

            var ssec = new SSEC(aesEncryption.Key);
            // Specify SSE-C source side encryption for Copy operations
            var sseCpy = new SSECopy(aesEncryption.Key);

            // Uncomment to specify SSE-S3 encryption option
            var sses3 = new SSES3();

            // Uncomment to specify SSE-KMS encryption option
            var sseKms = new SSEKMS("kms-key", new Dictionary <string, string> {
                { "kms-context", "somevalue" }
            });

            // Upload encrypted object
            string putFileName1 = CreateFile(1 * UNIT_MB);

            Cases.PutObject.Run(minioClient, bucketName, objectName, putFileName1, sse: ssec).Wait();
            // Copy SSE-C encrypted object to unencrypted object
            Cases.CopyObject.Run(minioClient, bucketName, objectName, destBucketName, objectName, sseSrc: sseCpy, sseDest: ssec).Wait();
            // Download SSE-C encrypted object
            Cases.FGetObject.Run(minioClient, destBucketName, objectName, bigFileName, sse: ssec).Wait();

            // List the incomplete uploads
            Cases.ListIncompleteUploads.Run(minioClient, bucketName);

            // Remove all the incomplete uploads
            Cases.RemoveIncompleteUpload.Run(minioClient, bucketName, objectName).Wait();

            // Set a policy for given bucket
            Cases.SetBucketPolicy.Run(minioClient, bucketName).Wait();
            // Get the policy for given bucket
            Cases.GetBucketPolicy.Run(minioClient, bucketName).Wait();

            // Set bucket notifications
            Cases.SetBucketNotification.Run(minioClient, bucketName).Wait();

            // Get bucket notifications
            Cases.GetBucketNotification.Run(minioClient, bucketName).Wait();

            // Remove all bucket notifications
            Cases.RemoveAllBucketNotifications.Run(minioClient, bucketName).Wait();

            // Object Lock Configuration operations
            lockBucketName = GetRandomName();
            Cases.MakeBucketWithLock.Run(minioClient, lockBucketName).Wait();
            ObjectLockConfiguration configuration = new ObjectLockConfiguration(RetentionMode.GOVERNANCE, 35);

            Cases.SetObjectLockConfiguration.Run(minioClient, lockBucketName, configuration).Wait();
            Cases.GetObjectLockConfiguration.Run(minioClient, lockBucketName).Wait();
            Cases.RemoveObjectLockConfiguration.Run(minioClient, lockBucketName).Wait();
            Cases.RemoveBucket.Run(minioClient, lockBucketName).Wait();

            // Bucket Replication operations
            string replicationCfgID = "myreplicationID-3333";

            Cases.SetBucketReplication.Run(minioClient, bucketName,
                                           destBucketName, replicationCfgID).Wait();
            Cases.GetBucketReplication.Run(minioClient, bucketName,
                                           replicationCfgID).Wait();
            // TODO: we can verify that the replication happens by checking
            // the content in the destination matches the source content.
            //     We also cannot remove the replication config immediately
            //     after running GetBucketReplication command, as
            //     replicating the source in the destination takes some time.
            Cases.RemoveBucketReplication.Run(minioClient, bucketName).Wait();

            // Get the presigned url for a GET object request
            Cases.PresignedGetObject.Run(minioClient, bucketName, objectName).Wait();

            // Get the presigned POST policy curl url
            Cases.PresignedPostPolicy.Run(minioClient, bucketName, objectName).Wait();

            // Get the presigned url for a PUT object request
            Cases.PresignedPutObject.Run(minioClient, bucketName, objectName).Wait();

            // Delete the list of objects
            Cases.RemoveObjects.Run(minioClient, bucketName, objectsList).Wait();

            // Delete the object
            Cases.RemoveObject.Run(minioClient, bucketName, objectName).Wait();

            // Delete the object
            Cases.RemoveObject.Run(minioClient, destBucketName, objectName).Wait();

            // Retry on failure
            Cases.RetryPolicyObject.Run(minioClient, destBucketName, objectName).Wait();

            // Tracing request with custom logger
            Cases.CustomRequestLogger.Run(minioClient).Wait();

            // Remove the buckets
            Cases.RemoveBucket.Run(minioClient, bucketName).Wait();
            Cases.RemoveBucket.Run(minioClient, destBucketName).Wait();

            // Remove the binary files created for test
            File.Delete(smallFileName);
            File.Delete(bigFileName);

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                Console.ReadLine();
            }
        }