• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Runtime.ImmutableCredentials类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Amazon.Runtime.ImmutableCredentials的典型用法代码示例。如果您正苦于以下问题:C# ImmutableCredentials类的具体用法?C# ImmutableCredentials怎么用?C# ImmutableCredentials使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ImmutableCredentials类属于Amazon.Runtime命名空间,在下文中一共展示了ImmutableCredentials类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: CalculateSignature

        /// <summary>
        /// Calculates the AWS4 signature using the supplied request parameters and AWS account credentials.
        /// </summary>
        /// <param name="parameters">Request header parameters to be included in the signature</param>
        /// <param name="serviceURL">Service endpoint URL</param>
        /// <param name="authenticationServiceName">
        /// The short-form name of the target service for inclusion in the signature; only needed if this 
        /// cannot be determined by parsing the endpoint.
        /// </param>
        /// <param name="authenticationRegion">
        /// Region name for inclusion in the signature; only needed if this  cannot be determined by parsing 
        /// the endpoint.
        /// </param>
        /// <param name="httpMethod">The HTTP method used to make the request.</param>
        /// <param name="credentials">User credentials</param>
        /// <returns>The signature string to be added as header 'Authorization' on the eventual request</returns>
        /// <exception cref="Amazon.Runtime.SignatureException">If any problems are encountered while signing the request</exception>
        public static string CalculateSignature(IDictionary<string, string> parameters,
                                                string serviceURL,
                                                string httpMethod,
                                                string authenticationServiceName,
                                                string authenticationRegion,
                                                ImmutableCredentials credentials)
        {
            string signingAlgorithm = SigningAlgorithm.HmacSHA256.ToString().ToUpper();

            DateTime dt = DateTime.UtcNow;
            string dateTime = dt.ToString(AWSSDKUtils.ISO8601BasicDateTimeFormat, CultureInfo.InvariantCulture);
            string dateStamp = dt.ToString("yyyyMMdd", CultureInfo.InvariantCulture);

            string region;
            if (!string.IsNullOrEmpty(authenticationRegion))
                region = authenticationRegion;
            else
                region = AWSSDKUtils.DetermineRegion(serviceURL).ToLower();
            string service = authenticationServiceName.Trim().ToLower();

            if (!parameters.ContainsKey("Host"))
                parameters.Add("Host", serviceURL);
            parameters.Add("X-Amz-Date", dateTime);

            string scope = string.Format("{0}/{1}/{2}/{3}", dateStamp, region, service, TERMINATOR);

            List<string> headersToSign = GetHeadersForSigning(parameters);
            string canonicalRequest = GetCanonicalRequest(headersToSign,
                                                          new Uri(serviceURL),
                                                          "",
                                                          parameters,
                                                          AWSSDKUtils.GetParametersAsString(parameters),
                                                          null, // No support for binary request body yet here.
                                                          httpMethod);

            StringBuilder stringToSign = new StringBuilder();
            stringToSign.AppendFormat("{0}-{1}\n{2}\n{3}\n", SCHEME, ALGORITHM, dateTime, scope);

            HashAlgorithm ha = HashAlgorithm.Create("SHA-256");
            byte[] canonicalRequestHashBytes = ha.ComputeHash(Encoding.UTF8.GetBytes(canonicalRequest));
            stringToSign.Append(AWSSDKUtils.ToHex(canonicalRequestHashBytes, true));

            KeyedHashAlgorithm kha = KeyedHashAlgorithm.Create(signingAlgorithm);
            kha.Key = ComposeSigningKey(signingAlgorithm, credentials.ClearSecretKey, credentials.SecureSecretKey, region, dateStamp, service);
            byte[] signature = kha.ComputeHash(Encoding.UTF8.GetBytes(stringToSign.ToString()));

            StringBuilder authorizationHeader = new StringBuilder();
            authorizationHeader.AppendFormat("{0}-{1} ", SCHEME, ALGORITHM);
            authorizationHeader.AppendFormat("Credential={0}/{1}, ", credentials.AccessKey, scope);
            authorizationHeader.AppendFormat("SignedHeaders={0}, ", GetSignedHeaders(headersToSign));
            authorizationHeader.AppendFormat("Signature={0}", AWSSDKUtils.ToHex(signature, true));

            return authorizationHeader.ToString();
        }
开发者ID:thecloudbook,项目名称:amazon,代码行数:71,代码来源:AWS4Signer.cs


示例2: TestCredentialsFile

 public void TestCredentialsFile()
 {
     var ic = new ImmutableCredentials("access-key", "secret-key", null);
     TestCredentialsFile(ic);
     ic = new ImmutableCredentials("access-key", "secret-key", "token");
     TestCredentialsFile(ic);
 }
开发者ID:Nangal,项目名称:aws-sdk-net,代码行数:7,代码来源:CredentialsTests.cs


示例3: LoadSettings

        private static void LoadSettings(string settingsResourcePartialName = "settings.json")
        {
            SetDefaults();

            var storedSettings = GetStoredSettings(settingsResourcePartialName);
            if (storedSettings == null)
                return;

            try
            {
                var ic = new ImmutableCredentials(storedSettings.AccessKeyId, storedSettings.SecretAccessKey, storedSettings.SessionToken);
                Credentials = new StoredCredentials(ic);
            }
            catch(Exception e)
            {
                Console.WriteError("Unable to parse get credentials from settings file, defaulting to anonymous credentials. Exception: {0}", e.ToString());
                Credentials = new AnonymousAWSCredentials();
            }

            try
            {
                RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName(storedSettings.RegionEndpoint);
            }
            catch(Exception e)
            {
                Console.WriteError("Unable to parse RegionEndpoint from settings file, defaulting to {0}. Exception: {1}", DefaultRegion, e.ToString());
                RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName(DefaultRegion);
            }
            ResultsBucket = storedSettings.ResultsBucket;
            ResultsTopic = storedSettings.ResultsTopic;
        }
开发者ID:lawandeneel,项目名称:Fashion,代码行数:31,代码来源:Settings.cs


示例4: GetBucketRegionNoPipelineAsync

 /// <summary>
 /// Use a HEAD bucket request to get the region for the given bucket.
 ///
 /// This method creates an AmazonS3Client from the credentials passed in.
 /// It's critical that the AmazonS3Client is not used to make any requests that will
 /// be routed through the pipeline.
 /// </summary>
 /// <param name="bucketName"></param>
 /// <param name="credentials"></param>
 /// <returns>the value of the x-amz-bucket-region header from the response</returns>
 private static async Task<string> GetBucketRegionNoPipelineAsync(string bucketName, ImmutableCredentials credentials)
 {
     var headBucketPreSignedUrl = GetHeadBucketPreSignedUrl(bucketName, credentials);
     using (var s3Client = GetUsEast1ClientFromCredentials(credentials))
     {
         return (await AmazonS3HttpUtil.GetHeadAsync(s3Client, s3Client.Config, headBucketPreSignedUrl,
             HeaderKeys.XAmzBucketRegion).ConfigureAwait(false)).HeaderValue;
     }
 }
开发者ID:aws,项目名称:aws-sdk-net,代码行数:19,代码来源:BucketRegionDetector.cs


示例5: GetBucketRegionNoPipeline

 /// <summary>
 /// Use a HEAD bucket request to get the region for the given bucket.
 ///
 /// This method creates an AmazonS3Client from the credentials passed in.
 /// It's critical that the AmazonS3Client is not used to make any requests that will
 /// be routed through the pipeline.
 /// </summary>
 /// <param name="bucketName"></param>
 /// <param name="credentials"></param>
 /// <returns>the value of the x-amz-bucket-region header from the response</returns>
 private static string GetBucketRegionNoPipeline(string bucketName, ImmutableCredentials credentials)
 {
     var headBucketPreSignedUrl = GetHeadBucketPreSignedUrl(bucketName, credentials);
     using (var s3Client = GetUsEast1ClientFromCredentials(credentials))
     {
         var response = AmazonS3HttpUtil.GetHead(s3Client, s3Client.Config, headBucketPreSignedUrl, HeaderKeys.XAmzBucketRegion);
         return response.HeaderValue;
     }
 }
开发者ID:aws,项目名称:aws-sdk-net,代码行数:19,代码来源:BucketRegionDetector.cs


示例6: SystemEnvironmentAWSCredentials

        public SystemEnvironmentAWSCredentials()
        {
            string accessKey = Environment.GetEnvironmentVariable("AWS_ACCESS_KEY_ID");
            string secretKey = Environment.GetEnvironmentVariable("AWS_SECRET_KEY");

            if (String.IsNullOrEmpty(accessKey) || String.IsNullOrEmpty(secretKey))
            {
                throw new Exception("No credentials found in the system environment.");
            }
            _credentials = new ImmutableCredentials(accessKey, secretKey, "");
        }
开发者ID:jfaerman,项目名称:devonaws-labs-csharp,代码行数:11,代码来源:SystemEnvironmentAWSCredentials.cs


示例7: EnvironmentAWSCredentials

        /// <summary>
        /// Constructs an instance of EnvironmentAWSCredentials and attempts to load AccessKey and SecretKey from ConfigurationManager.AppSettings
        /// </summary>
        public EnvironmentAWSCredentials()
        {
            string accessKey = ConfigurationManager.GetAccessKey();
            string secretKey = ConfigurationManager.GetSecretKey();

            if (string.IsNullOrEmpty(accessKey))
            {
                throw new ArgumentException(string.Format("Access Key could not be found.  Add an appsetting to your App.config with the name {0} with a value of your access key.", "AWSAccessKey"));
            }

            if (string.IsNullOrEmpty(secretKey))
            {
                throw new ArgumentException(string.Format("Secret Key could not be found.  Add an appsetting to your App.config with the name {0} with a value of your secret key.", "AWSSecretKey"));
            }

            this.wrappedCredentials = new ImmutableCredentials(accessKey, secretKey);
        }
开发者ID:infopete,项目名称:AWS-SDK-NETCF,代码行数:20,代码来源:AWSCredentials.cs


示例8: TestCredentialsFile

        private static void TestCredentialsFile(ImmutableCredentials ic)
        {
            var profileName = "testProfile";
            var profilesLocation = WriteCreds(profileName, ic);
            var creds = new StoredProfileAWSCredentials(profileName, profilesLocation);
            var rc = creds.GetCredentials();
            Assert.AreEqual(ic.SecretKey, rc.SecretKey);
            Assert.AreEqual(ic.AccessKey, rc.AccessKey);
            Assert.AreEqual(ic.UseToken, rc.UseToken);
            Assert.AreEqual(ic.Token, rc.Token);

            for (int i = 0; i < 4; i++)
            {
                creds = new StoredProfileAWSCredentials(profileName + i, profilesLocation);
                Assert.IsNotNull(creds);
                rc = creds.GetCredentials();
                Assert.IsNotNull(rc.AccessKey);
                Assert.IsNotNull(rc.SecretKey);
                var shouldHaveToken = (i % 2 == 1);
                Assert.AreEqual(shouldHaveToken, rc.UseToken);
            }
        }
开发者ID:yridesconix,项目名称:aws-sdk-net,代码行数:22,代码来源:CredentialsTests.cs


示例9: EnvironmentVariablesAWSCredentials

        /// <summary>
        /// Constructs an instance of EnvironmentVariablesAWSCredentials. If no credentials are found in the environment variables 
        /// then an InvalidOperationException.
        /// </summary>
        public EnvironmentVariablesAWSCredentials()
        {
            string accessKeyId = Environment.GetEnvironmentVariable(ENVIRONMENT_VARIABLE_ACCESSKEY);
            string secretKey = Environment.GetEnvironmentVariable(ENVIRONMENT_VARIABLE_SECRETKEY);
            if (string.IsNullOrEmpty(accessKeyId) || string.IsNullOrEmpty(secretKey))
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
                    "The environment variables {0} and {1} were not set with AWS credentials.", ENVIRONMENT_VARIABLE_ACCESSKEY, ENVIRONMENT_VARIABLE_SECRETKEY));
            }

            string sessionToken = Environment.GetEnvironmentVariable(ENVIRONMENT_VARIABLE_SESSION_TOKEN);

            this._wrappedCredentials = new ImmutableCredentials(accessKeyId, secretKey, sessionToken);
            var logger = Logger.GetLogger(typeof(EnvironmentVariablesAWSCredentials));
            logger.InfoFormat("Credentials found using environment variables.");
        }
开发者ID:NathanSDunn,项目名称:aws-sdk-unity-samples,代码行数:20,代码来源:AWSCredentials.cs


示例10: SessionAWSCredentials

        /// <summary>
        /// Constructs a SessionAWSCredentials object for the specified accessKey, secretKey.
        /// </summary>
        /// <param name="awsAccessKeyId"></param>
        /// <param name="awsSecretAccessKey"></param>
        /// <param name="token"></param>
        public SessionAWSCredentials(string awsAccessKeyId, string awsSecretAccessKey, string token)
        {
            if (string.IsNullOrEmpty(awsAccessKeyId)) throw new ArgumentNullException("awsAccessKeyId");
            if (string.IsNullOrEmpty(awsSecretAccessKey)) throw new ArgumentNullException("awsSecretAccessKey");
            if (string.IsNullOrEmpty(token)) throw new ArgumentNullException("token");

            _lastCredentials = new ImmutableCredentials(awsAccessKeyId, awsSecretAccessKey, token);
        }
开发者ID:NathanSDunn,项目名称:aws-sdk-unity-samples,代码行数:14,代码来源:AWSCredentials.cs


示例11: Copy

 /// <summary>
 /// Returns a copy of the current credentials.
 /// </summary>
 /// <returns></returns>
 public ImmutableCredentials Copy()
 {
     ImmutableCredentials credentials2 = new ImmutableCredentials();
     credentials2.AccessKey = this.AccessKey;
     credentials2.SecretKey = this.SecretKey;
     return credentials2;
 }
开发者ID:infopete,项目名称:AWS-SDK-NETCF,代码行数:11,代码来源:AWSCredentials.cs


示例12: StoredCredentials

 public StoredCredentials(ImmutableCredentials ic)
 {
     credentials = ic;
 }
开发者ID:lawandeneel,项目名称:Fashion,代码行数:4,代码来源:Settings.cs


示例13: Copy

 /// <summary>
 /// Returns a copy of the current credentials.
 /// </summary>
 /// <returns></returns>
 public ImmutableCredentials Copy()
 {
     ImmutableCredentials credentials = new ImmutableCredentials
     {
         AccessKey = this.AccessKey,
         SecretKey = this.SecretKey,
         Token = this.Token,
     };
     return credentials;
 }
开发者ID:NathanSDunn,项目名称:aws-sdk-unity-samples,代码行数:14,代码来源:AWSCredentials.cs


示例14: BasicAWSCredentials

 /// <summary>
 /// Constructs a BasicAWSCredentials object for the specified accessKey and secretKey
 /// SecretKey is stored in SecureString
 /// </summary>
 /// <param name="accessKey"></param>
 /// <param name="secretKey"></param>
 public BasicAWSCredentials(string accessKey, SecureString secretKey)
 {
     _credentials = new ImmutableCredentials(accessKey, secretKey, null);
 }
开发者ID:rguarino4,项目名称:aws-sdk-net,代码行数:10,代码来源:AWSCredentials.cs


示例15: GetHeadBucketPreSignedUrl

 private static string GetHeadBucketPreSignedUrl(string bucketName, ImmutableCredentials credentials)
 {
     // IMPORTANT:
     // This method is called as part of the request pipeline.
     // If the pipeline were to be invoked here it would cause
     // unwanted recursion.
     // As such, the only reason it's OK to use an S3Client here
     // is because this code is using a method that doesn't go
     // through the request pipeline: GetPreSignedURLInternal
     var request = new GetPreSignedUrlRequest
     {
         BucketName = bucketName,
         Expires = DateTime.Now.AddDays(1),
         Verb = HttpVerb.HEAD,
         Protocol = Protocol.HTTP
     };
     // all buckets accessible via USEast1
     using (var s3Client = GetUsEast1ClientFromCredentials(credentials))
     {
         return s3Client.GetPreSignedURLInternal(request, false);
     }
 }
开发者ID:aws,项目名称:aws-sdk-net,代码行数:22,代码来源:BucketRegionDetector.cs


示例16: GetUsEast1ClientFromCredentials

 private static AmazonS3Client GetUsEast1ClientFromCredentials(ImmutableCredentials credentials)
 {
     if (credentials.UseToken)
     {
         return new AmazonS3Client(credentials.AccessKey, credentials.SecretKey, credentials.Token, RegionEndpoint.USEast1);
     }
     else
     {
         return new AmazonS3Client(credentials.AccessKey, credentials.SecretKey, RegionEndpoint.USEast1);
     }
 }
开发者ID:aws,项目名称:aws-sdk-net,代码行数:11,代码来源:BucketRegionDetector.cs


示例17: AppendCredentialsSet

 private static void AppendCredentialsSet(StreamWriter writer, string profileName, ImmutableCredentials ic)
 {
     writer.WriteLine();
     writer.WriteLine("; profile {0} and its credentials", profileName);
     writer.WriteLine("# alternative comment marker");
     writer.WriteLine("[{0}]", profileName);
     writer.WriteLine("aws_access_key_id = {0}", ic.AccessKey);
     writer.WriteLine("aws_secret_access_key={0}", ic.SecretKey);
     if (ic.UseToken)
         writer.WriteLine("aws_session_token= {0}", ic.Token);
     writer.WriteLine();
 }
开发者ID:Nangal,项目名称:aws-sdk-net,代码行数:12,代码来源:CredentialsTests.cs


示例18: WriteCreds

        private static string WriteCreds(string profileName, ImmutableCredentials ic)
        {
            string configPath = Path.GetFullPath("credentials");
            using (var stream = File.Open(configPath, FileMode.Create, FileAccess.Write, FileShare.None))
            using (var writer = new StreamWriter(stream))
            {
                AppendCredentialsSet(writer, profileName + "0", basicCreds);
                AppendCredentialsSet(writer, profileName + "1", sessionCreds);
                AppendCredentialsSet(writer, profileName, ic);
                AppendCredentialsSet(writer, profileName + "2", basicCreds);
                AppendCredentialsSet(writer, profileName + "3", sessionCreds);
            }

            return configPath;
        }
开发者ID:Nangal,项目名称:aws-sdk-net,代码行数:15,代码来源:CredentialsTests.cs


示例19: EnvironmentAWSCredentials

        /// <summary>
        /// Constructs an instance of EnvironmentAWSCredentials and attempts
        /// to load AccessKey and SecretKey from ConfigurationManager.AppSettings
        /// </summary>
        public EnvironmentAWSCredentials()
        {
            NameValueCollection appConfig = ConfigurationManager.AppSettings;

            // Use hardcoded credentials
            if (!string.IsNullOrEmpty(appConfig[ACCESSKEY]) && !string.IsNullOrEmpty(appConfig[SECRETKEY]))
            {
                var accessKey = appConfig[ACCESSKEY];
                var secretKey = appConfig[SECRETKEY];
                this._wrappedCredentials = new ImmutableCredentials(accessKey, secretKey, null);
                var logger = Logger.GetLogger(typeof(EnvironmentAWSCredentials));
                logger.InfoFormat("Credentials found with {0} and {1} app settings", ACCESSKEY, SECRETKEY);
            }
            // Fallback to the StoredProfileAWSCredentials provider
            else
            {
                this._wrappedCredentials = new StoredProfileAWSCredentials().GetCredentials();
            }
        }
开发者ID:NathanSDunn,项目名称:aws-sdk-unity-samples,代码行数:23,代码来源:AWSCredentials.cs


示例20: CredentialsRefreshState

 public CredentialsRefreshState(ImmutableCredentials credentials, DateTime expiration)
 {
     Credentials = credentials;
     Expiration = expiration;
 }
开发者ID:NathanSDunn,项目名称:aws-sdk-unity-samples,代码行数:5,代码来源:AWSCredentials.cs



注:本文中的Amazon.Runtime.ImmutableCredentials类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Internal.AsyncResult类代码示例发布时间:2022-05-24
下一篇:
C# Runtime.AsyncOptions类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap