Ejemplo n.º 1
0
    // Enable Versioning on a bucket
    public static async Task Run(MinioClient minio,
                                 string bucketName = "my-bucket-name")
    {
        try
        {
            Console.WriteLine("Running example for API: EnableSuspendVersioning, ");
            // First Enable the Versioning.
            var setArgs = new SetVersioningArgs()
                          .WithBucket(bucketName)
                          .WithVersioningEnabled();
            await minio.SetVersioningAsync(setArgs);

            Console.WriteLine("Versioning Enable operation called for bucket " + bucketName);
            // Next Suspend the Versioning.
            setArgs = setArgs.WithVersioningSuspended();
            await minio.SetVersioningAsync(setArgs);

            Console.WriteLine("Versioning Suspend operation called for bucket " + bucketName);
        }
        catch (Exception e)
        {
            Console.WriteLine($"[Bucket]  Exception: {e}");
        }
    }
Ejemplo n.º 2
0
        // Set Replication configuration for the bucket
        public async static Task Run(MinioClient minio,
                                     string bucketName       = "my-bucket-name",
                                     string destBucketName   = "dest-bucket-name",
                                     string replicationCfgID = "my-replication-ID")
        {
            var setArgs = new SetVersioningArgs()
                          .WithBucket(bucketName)
                          .WithVersioningEnabled();
            await minio.SetVersioningAsync(setArgs);

            setArgs = new SetVersioningArgs()
                      .WithBucket(destBucketName)
                      .WithVersioningEnabled();
            await minio.SetVersioningAsync(setArgs);

            string serverEndPoint = "";
            string schema         = "http://";
            string accessKey      = "";
            string secretKey      = "";

            if (Environment.GetEnvironmentVariable("SERVER_ENDPOINT") != null)
            {
                serverEndPoint = Environment.GetEnvironmentVariable("SERVER_ENDPOINT");
                accessKey      = Environment.GetEnvironmentVariable("ACCESS_KEY");
                secretKey      = Environment.GetEnvironmentVariable("SECRET_KEY");
                if (Environment.GetEnvironmentVariable("ENABLE_HTTPS") != null)
                {
                    if (Environment.GetEnvironmentVariable("ENABLE_HTTPS").Equals("1"))
                    {
                        schema = "https://";
                    }
                }
            }
            else
            {
                serverEndPoint = "play.min.io";
                accessKey      = "Q3AM3UQ867SPQQA43P2F";
                secretKey      = "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG";
                schema         = "http://";
            }

            var cmdFullPathMC = Bash("which mc").TrimEnd('\r', '\n', ' ');
            var cmdAlias      = cmdFullPathMC + " alias list | egrep -B1 \"" +
                                schema + serverEndPoint + "\" | grep -v URL";
            var alias = Bash(cmdAlias).TrimEnd('\r', '\n', ' ');

            var cmdRemoteAdd = cmdFullPathMC + " admin bucket remote add " +
                               alias + "/" + bucketName + "/ " + schema +
                               accessKey + ":" + secretKey + "@" +
                               serverEndPoint + "/" + destBucketName +
                               " --service replication --region us-east-1";

            var arn = Bash(cmdRemoteAdd).Replace("Remote ARN = `", "").Replace("`.", "");

            ReplicationRule rule =
                new ReplicationRule(
                    new DeleteMarkerReplication(DeleteMarkerReplication.StatusDisabled),
                    new ReplicationDestination(null, null,
                                               "arn:aws:s3:::" + destBucketName,
                                               null, null, null, null),
                    new ExistingObjectReplication(ExistingObjectReplication.StatusEnabled),
                    new RuleFilter(null, null, null),
                    new DeleteReplication(DeleteReplication.StatusDisabled),
                    1,
                    replicationCfgID,
                    "",
                    new SourceSelectionCriteria(new SseKmsEncryptedObjects(
                                                    SseKmsEncryptedObjects.StatusEnabled)),
                    ReplicationRule.StatusEnabled
                    );
            List <ReplicationRule> rules = new List <ReplicationRule>();

            rules.Add(rule);
            ReplicationConfiguration repl = new ReplicationConfiguration(arn, rules);

            await minio.SetBucketReplicationAsync(
                new SetBucketReplicationArgs()
                .WithBucket(bucketName)
                .WithConfiguration(repl)
                );
        }