public FilesRepository(IAmazonS3 s3Client,
                               IOptions <SessionAwsCredentialsOptions> sessionAwsCredentialsOptions)
        {
            var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

            _sessionAwsCredentialsOptions = sessionAwsCredentialsOptions.Value;
            if (env.Contains("Local"))
            {
                // TODO: we must improve this client initialization, this code commented is just to test in the local environment. create a temporal session to test locally, use SSO temporal keys, update these keys in app settings
                SessionAWSCredentials tempCredentials = new SessionAWSCredentials(_sessionAwsCredentialsOptions.AwsAccessKeyId,
                                                                                  _sessionAwsCredentialsOptions.AwsSecretAccessKey,
                                                                                  _sessionAwsCredentialsOptions.Token);
                _s3Client = new AmazonS3Client(tempCredentials, RegionEndpoint.APSoutheast1);
            }
            else
            {
                // TODO: example using IAM keys
                // IAM
                //var credentials = new BasicAWSCredentials(_sessionAwsCredentialsOptions.AwsAccessKeyId, _sessionAwsCredentialsOptions.AwsSecretAccessKey);
                //_s3Client = new AmazonS3Client(RegionEndpoint.APSoutheast1);

                // TODO: using IAM role, deployed to development, staging or production
                _s3Client = s3Client;
            }
        }
Exemple #2
0
        public BucketRepository(IAmazonS3 s3Client,
                                IOptions <SessionAwsCredentialsOptions> sessionAwsCredentialsOptions)
        {
            _sessionAwsCredentialsOptions = sessionAwsCredentialsOptions.Value;
            // TODO: we must improve this client initialization, this code commented is just to test in the local environment
            // create a temporal session to test locally, use SSO temporal keys, update these keys in app settings
            //   SessionAWSCredentials tempCredentials = new SessionAWSCredentials(_sessionAwsCredentialsOptions.AwsAccessKeyId,
            // _sessionAwsCredentialsOptions.AwsSecretAccessKey,
            // _sessionAwsCredentialsOptions.Token);
            //_s3Client = new AmazonS3Client(tempCredentials, RegionEndpoint.APSoutheast1);

            _s3Client = s3Client;
        }