Exemplo n.º 1
0
        private Bucket NewBucket(GcsPath gcsPath, NewGcsBucketDynamicParameters dynamicParams)
        {
            if (dynamicParams.Project == null)
            {
                var property = dynamicParams.GetType().GetProperty(nameof(Project));
                ConfigPropertyNameAttribute configPropertyName =
                    (ConfigPropertyNameAttribute)Attribute.GetCustomAttribute(
                        property, typeof(ConfigPropertyNameAttribute));
                configPropertyName.SetObjectConfigDefault(property, dynamicParams);
            }

            var bucket = new Bucket
            {
                Name         = gcsPath.Bucket,
                Location     = dynamicParams.Location,
                StorageClass = dynamicParams.StorageClass
            };

            BucketsResource.InsertRequest insertReq = Service.Buckets.Insert(bucket, dynamicParams.Project);
            insertReq.PredefinedAcl = dynamicParams.DefaultBucketAcl;
            insertReq.PredefinedDefaultObjectAcl = dynamicParams.DefaultObjectAcl;
            Bucket newBucket = insertReq.Execute();

            BucketCache.ForceRefresh();
            return(newBucket);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Deletes a Google Cloud Storage object or bucket. Used by Remove-Item.
        /// </summary>
        /// <param name="path">The path to the object or bucket to remove.</param>
        /// <param name="recurse">If true, will remove the desendants of the item as well. Required for a
        /// non-empty bucket.</param>
        protected override void RemoveItem(string path, bool recurse)
        {
            if (!ShouldProcess(path, "Remove-Item"))
            {
                return;
            }
            var gcsPath = GcsPath.Parse(path);

            switch (gcsPath.Type)
            {
            case GcsPath.GcsPathType.Drive:
                throw new InvalidOperationException("Use Remove-PSDrive to remove a drive.");

            case GcsPath.GcsPathType.Bucket:
                RemoveBucket(gcsPath, recurse);
                BucketCache.ForceRefresh();
                break;

            case GcsPath.GcsPathType.Object:
                if (IsItemContainer(path))
                {
                    RemoveFolder(GcsPath.Parse(path + "/"), recurse);
                }
                else
                {
                    Service.Objects.Delete(gcsPath.Bucket, gcsPath.ObjectPath).Execute();
                }
                BucketModels.Clear();
                break;

            default:
                throw new InvalidOperationException($"Unknown Path Type {gcsPath.Type}");
            }
            TelemetryReporter.ReportSuccess(nameof(GoogleCloudStorageProvider), nameof(RemoveItem));
        }