Ejemplo n.º 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}");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Generates name of module's private bucket
        /// </summary>
        /// <param name="context">The context.</param>
        private void GeneratePrivateBucketName(ICloudFormationContext context)
        {
            using (var sts = this.clientFactory.CreateSTSClient())
            {
                var account    = sts.GetCallerIdentityAsync(new GetCallerIdentityRequest()).Result.Account;
                var bucketName = $"cf-templates-pscloudformation-{context.Region.SystemName}-{account}";

                this.cloudFormationBucket = new CloudFormationBucket
                {
                    BucketName  = bucketName,
                    BucketUri   = new Uri($"https://{bucketName}.s3.amazonaws.com"),
                    Initialized = false
                };
            }
        }