Пример #1
0
        public void ModifyRequest_MatchNotMatchConflicts()
        {
            var request = new RewriteRequest(null, null, "sourceBucket", "sourceObject", "destBucket", "destObject");

            Assert.Throws <ArgumentException>(() =>
            {
                var options = new CopyObjectOptions {
                    IfGenerationMatch = 1L, IfGenerationNotMatch = 2L
                };
                options.ModifyRequest(request);
            });
            Assert.Throws <ArgumentException>(() =>
            {
                var options = new CopyObjectOptions {
                    IfMetagenerationMatch = 1L, IfMetagenerationNotMatch = 2L
                };
                options.ModifyRequest(request);
            });
            Assert.Throws <ArgumentException>(() =>
            {
                var options = new CopyObjectOptions {
                    IfSourceGenerationMatch = 1L, IfSourceGenerationNotMatch = 2L
                };
                options.ModifyRequest(request);
            });
            Assert.Throws <ArgumentException>(() =>
            {
                var options = new CopyObjectOptions {
                    IfSourceMetagenerationMatch = 1L, IfSourceMetagenerationNotMatch = 2L
                };
                options.ModifyRequest(request);
            });
        }
Пример #2
0
        public void ModifyRequest_AllOptions_NegativeMatch()
        {
            var request = new RewriteRequest(null, null, "sourceBucket", "sourceObject", "destBucket", "destObject");
            var options = new CopyObjectOptions
            {
                DestinationPredefinedAcl       = PredefinedObjectAcl.Private,
                IfGenerationNotMatch           = 1L,
                IfMetagenerationNotMatch       = 2L,
                IfSourceGenerationNotMatch     = 3L,
                IfSourceMetagenerationNotMatch = 4L,
                Projection       = Projection.Full,
                SourceGeneration = 5L
            };

            options.ModifyRequest(request);
            Assert.Equal(RewriteRequest.DestinationPredefinedAclEnum.Private__, request.DestinationPredefinedAcl);
            Assert.Null(request.IfGenerationMatch);
            Assert.Equal(1L, request.IfGenerationNotMatch);
            Assert.Null(request.IfMetagenerationMatch);
            Assert.Equal(2L, request.IfMetagenerationNotMatch);
            Assert.Null(request.IfSourceGenerationMatch);
            Assert.Equal(3L, request.IfSourceGenerationNotMatch);
            Assert.Null(request.IfSourceMetagenerationMatch);
            Assert.Equal(4L, request.IfSourceMetagenerationNotMatch);
            Assert.Equal(5L, request.SourceGeneration);
        }
Пример #3
0
        public void ModifyRequest_DefaultOptions()
        {
            var request = new RewriteRequest(null, null, "sourceBucket", "sourceObject", "destBucket", "destObject");
            var options = new CopyObjectOptions();

            options.ModifyRequest(request);
            Assert.Null(request.DestinationPredefinedAcl);
            Assert.Null(request.IfGenerationMatch);
            Assert.Null(request.IfGenerationNotMatch);
            Assert.Null(request.IfMetagenerationMatch);
            Assert.Null(request.IfMetagenerationNotMatch);
            Assert.Null(request.IfSourceGenerationMatch);
            Assert.Null(request.IfSourceGenerationNotMatch);
            Assert.Null(request.IfSourceMetagenerationMatch);
            Assert.Null(request.IfSourceMetagenerationNotMatch);
            Assert.Null(request.Projection);
            Assert.Null(request.SourceGeneration);
        }
Пример #4
0
        internal void ModifyRequest(RewriteRequest request)
        {
            // Note the use of ArgumentException here, as this will basically be the result of invalid
            // options being passed to a public method.
            if (IfGenerationMatch != null && IfGenerationNotMatch != null)
            {
                throw new ArgumentException($"Cannot specify {nameof(IfGenerationMatch)} and {nameof(IfGenerationNotMatch)} in the same options", "options");
            }
            if (IfMetagenerationMatch != null && IfMetagenerationNotMatch != null)
            {
                throw new ArgumentException($"Cannot specify {nameof(IfMetagenerationMatch)} and {nameof(IfMetagenerationNotMatch)} in the same options", "options");
            }
            if (IfSourceGenerationMatch != null && IfSourceGenerationNotMatch != null)
            {
                throw new ArgumentException($"Cannot specify {nameof(IfSourceGenerationMatch)} and {nameof(IfSourceGenerationNotMatch)} in the same options", "options");
            }
            if (IfSourceMetagenerationMatch != null && IfSourceMetagenerationNotMatch != null)
            {
                throw new ArgumentException($"Cannot specify {nameof(IfSourceMetagenerationMatch)} and {nameof(IfSourceMetagenerationNotMatch)} in the same options", "options");
            }

            if (DestinationPredefinedAcl != null)
            {
                request.DestinationPredefinedAcl =
                    GaxRestPreconditions.CheckEnumValue((DestinationPredefinedAclEnum)DestinationPredefinedAcl, nameof(DestinationPredefinedAcl));
            }
            if (SourceGeneration != null)
            {
                request.SourceGeneration = SourceGeneration;
            }
            if (Projection != null)
            {
                request.Projection = GaxRestPreconditions.CheckEnumValue((ProjectionEnum)Projection, nameof(Projection));
            }

            if (IfGenerationMatch != null)
            {
                request.IfGenerationMatch = IfGenerationMatch;
            }
            if (IfGenerationNotMatch != null)
            {
                request.IfGenerationNotMatch = IfGenerationNotMatch;
            }
            if (IfMetagenerationMatch != null)
            {
                request.IfMetagenerationMatch = IfMetagenerationMatch;
            }
            if (IfMetagenerationNotMatch != null)
            {
                request.IfMetagenerationNotMatch = IfMetagenerationNotMatch;
            }

            if (IfSourceGenerationMatch != null)
            {
                request.IfSourceGenerationMatch = IfSourceGenerationMatch;
            }
            if (IfSourceGenerationNotMatch != null)
            {
                request.IfSourceGenerationNotMatch = IfSourceGenerationNotMatch;
            }
            if (IfSourceMetagenerationMatch != null)
            {
                request.IfSourceMetagenerationMatch = IfSourceMetagenerationMatch;
            }
            if (IfSourceMetagenerationNotMatch != null)
            {
                request.IfSourceMetagenerationNotMatch = IfSourceMetagenerationNotMatch;
            }
        }
Пример #5
0
        internal void ModifyRequest(RewriteRequest request)
        {
            // Note the use of ArgumentException here, as this will basically be the result of invalid
            // options being passed to a public method.
            if (IfGenerationMatch != null && IfGenerationNotMatch != null)
            {
                throw new ArgumentException($"Cannot specify {nameof(IfGenerationMatch)} and {nameof(IfGenerationNotMatch)} in the same options", "options");
            }
            if (IfMetagenerationMatch != null && IfMetagenerationNotMatch != null)
            {
                throw new ArgumentException($"Cannot specify {nameof(IfMetagenerationMatch)} and {nameof(IfMetagenerationNotMatch)} in the same options", "options");
            }
            if (IfSourceGenerationMatch != null && IfSourceGenerationNotMatch != null)
            {
                throw new ArgumentException($"Cannot specify {nameof(IfSourceGenerationMatch)} and {nameof(IfSourceGenerationNotMatch)} in the same options", "options");
            }
            if (IfSourceMetagenerationMatch != null && IfSourceMetagenerationNotMatch != null)
            {
                throw new ArgumentException($"Cannot specify {nameof(IfSourceMetagenerationMatch)} and {nameof(IfSourceMetagenerationNotMatch)} in the same options", "options");
            }

            if (DestinationPredefinedAcl != null)
            {
                request.DestinationPredefinedAcl =
                    GaxPreconditions.CheckEnumValue((DestinationPredefinedAclEnum)DestinationPredefinedAcl, nameof(DestinationPredefinedAcl));
            }
            if (SourceGeneration != null)
            {
                request.SourceGeneration = SourceGeneration;
            }
            if (Projection != null)
            {
                request.Projection = GaxPreconditions.CheckEnumValue((ProjectionEnum)Projection, nameof(Projection));
            }

            if (IfGenerationMatch != null)
            {
                request.IfGenerationMatch = IfGenerationMatch;
            }
            if (IfGenerationNotMatch != null)
            {
                request.IfGenerationNotMatch = IfGenerationNotMatch;
            }
            if (IfMetagenerationMatch != null)
            {
                request.IfMetagenerationMatch = IfMetagenerationMatch;
            }
            if (IfMetagenerationNotMatch != null)
            {
                request.IfMetagenerationNotMatch = IfMetagenerationNotMatch;
            }

            if (IfSourceGenerationMatch != null)
            {
                request.IfSourceGenerationMatch = IfSourceGenerationMatch;
            }
            if (IfSourceGenerationNotMatch != null)
            {
                request.IfSourceGenerationNotMatch = IfSourceGenerationNotMatch;
            }
            if (IfSourceMetagenerationMatch != null)
            {
                request.IfSourceMetagenerationMatch = IfSourceMetagenerationMatch;
            }
            if (IfSourceMetagenerationNotMatch != null)
            {
                request.IfSourceMetagenerationNotMatch = IfSourceMetagenerationNotMatch;
            }
            if (UserProject != null)
            {
                request.UserProject = UserProject;
            }

            // Note: specifying this and EncryptionKey as non-null/non-None is invalid, but that's checked in StorageClientImpl.
            if (KmsKeyName != null)
            {
                request.DestinationKmsKeyName = KmsKeyName;
            }
        }