コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="S3Util"/> class.
        /// </summary>
        /// <param name="clientFactory">The client factory.</param>
        /// <param name="context">The context.</param>
        /// <param name="rootTemplate">The root template.</param>
        /// <param name="bucketName">Name of the bucket.</param>
        /// <param name="keyPrefix">Key prefix to use when packaging.</param>
        /// <param name="metadata">Metadata to use when packaging.</param>
        /// <exception cref="ArgumentNullException">rootTemplate is null</exception>
        public S3Util(
            IPSAwsClientFactory clientFactory,
            IPSCloudFormationContext context,
            string rootTemplate,
            string bucketName,
            string keyPrefix,
            IDictionary metadata)
            : this(clientFactory, context)
        {
            this.Metadata  = metadata;
            this.KeyPrefix = keyPrefix;
            if (bucketName != null)
            {
                // We assume the user has provided a valid bucket
                this.cloudFormationBucket = new CloudFormationBucket
                {
                    BucketName  = bucketName,
                    BucketUri   = new Uri($"https://{bucketName}.s3.amazonaws.com"),
                    Initialized = true
                };
            }

            // Generate a hash of the root template filename to use as part of uploaded file keys
            // to identify this package 'project'
            this.ProjectId = GenerateProjectId(rootTemplate ?? throw new ArgumentNullException(nameof(rootTemplate)));
            this.logger?.LogDebug($"Project ID for this template is {this.ProjectId}");
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="S3Util"/> class using the
 /// library's private bucket which will be created if it doesn't exist and a 7 day lifecycle rule
 /// applied to prevent build-up of temporary objects.
 /// </summary>
 /// <param name="clientFactory">The AWS client factory.</param>
 /// <param name="context">The context.</param>
 public S3Util(IPSAwsClientFactory clientFactory, IPSCloudFormationContext context)
 {
     this.logger             = context.Logger;
     this.clientFactory      = clientFactory ?? throw new ArgumentNullException(nameof(clientFactory));
     this.timestampGenerator = context.TimestampGenerator ?? new TimestampGenerator();
     this.s3 = this.clientFactory.CreateS3Client();
     this.GeneratePrivateBucketName(context);
 }