public static void SetLogClient(string key, JdCloudNativeConfig nativeConfig) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key)); } if (nativeConfig == null) { throw new ArgumentNullException(nameof(nativeConfig)); } nativeConfig.Check(); if (key == Constants.GeneralClientKey) { throw new ArgumentException($"Key cannot be same as '{Constants.GeneralClientKey}'."); } var credentialsProvider = new StaticCredentialsProvider(nativeConfig.AccessKey, nativeConfig.SecretKey); var instance = new JDCloudSDK.Logs.Client.LogsClient.DefaultBuilder() .CredentialsProvider(credentialsProvider) .HttpRequestConfig(new HttpRequestConfig(nativeConfig.Security ? Protocol.HTTPS : Protocol.HTTP, nativeConfig.RequestTimeout)) .Build(); SetLogClient(key, nativeConfig.LogStreamName, instance, nativeConfig.IsGeneralClient); }
public void TestStopInstance() { string accessKeyId = "your jdcloud ak"; string secretAccessKey = "you jdcloud sk"; CredentialsProvider credentialsProvider = new StaticCredentialsProvider(accessKeyId, secretAccessKey); HttpRequestConfig httpRequestConfig = new HttpRequestConfig(); DatastarClient dataClient = new DatastarClient.DefaultBuilder() .CredentialsProvider(credentialsProvider) .HttpRequestConfig(new HttpRequestConfig(Protocol.HTTPS, 10)) .Build(); //3. 设置请求参数 //GetLargeScreenDataRequest GetLargeScreenDataRequest lsRequest = new GetLargeScreenDataRequest(); lsRequest.RegionId = "cn-south-1"; lsRequest.EndDate = "2019-02-18"; lsRequest.StartDate = "2019-02-10"; lsRequest.Version = "v1"; lsRequest.Region = "福清县"; lsRequest.Industry = "食品"; lsRequest.FirstIndex = "食品"; lsRequest.SecondIndex = "价格指数"; //4. 执行请求 var response1 = dataClient.GetLargeScreenData(lsRequest).Result; Console.WriteLine(JsonConvert.SerializeObject(response1)); }
public void AlibabaCloudCredentialsInstance() { var mock = new Mock <AlibabaCloudCredentials>(); var credentials = mock.Object; var instance = new StaticCredentialsProvider(credentials); }
public static void SetLogClient(string key, string logStreamName, string accessKey, string secretKey, bool security, int requestTimeout, bool asGeneral = false) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key)); } if (string.IsNullOrWhiteSpace(secretKey)) { throw new ArgumentNullException(nameof(secretKey)); } if (string.IsNullOrWhiteSpace(accessKey)) { throw new ArgumentNullException(nameof(accessKey)); } if (key == Constants.GeneralClientKey) { throw new ArgumentException($"Key cannot be same as '{Constants.GeneralClientKey}'."); } var credentialsProvider = new StaticCredentialsProvider(accessKey, secretKey); var instance = new JDCloudSDK.Logs.Client.LogsClient.DefaultBuilder() .CredentialsProvider(credentialsProvider) .HttpRequestConfig(new HttpRequestConfig(security ? Protocol.HTTPS : Protocol.HTTP, requestTimeout)) .Build(); SetLogClient(key, logStreamName, instance, asGeneral); }
public void IsExpired() { IClientProfile profile = DefaultProfile.GetProfile("cn-shanghai", "accessKeyId", "accessKeySecret"); DefaultAcsClient client = new DefaultAcsClient(profile); var provider = new StaticCredentialsProvider(profile); CredentialsBackupCompatibilityAdaptor instance = new CredentialsBackupCompatibilityAdaptor(provider); Assert.False(instance.IsExpired()); }
public void GetAccessKeySecret() { IClientProfile profile = DefaultProfile.GetProfile("cn-shanghai", "accessKeyId", "accessKeySecret"); var client = new DefaultAcsClient(profile); var provider = new StaticCredentialsProvider(profile); var instance = new CredentialsBackupCompatibilityAdaptor(provider); Assert.Equal("accessKeySecret", instance.GetAccessSecret()); }
public void AlibabaCloudCredentialsInstance() { var mock = new Mock <AlibabaCloudCredentials>(); AlibabaCloudCredentials credentials = mock.Object; StaticCredentialsProvider instance = new StaticCredentialsProvider(credentials); // 无回调 // DONE WITH NO EXCEPTION }
public void Get() { IClientProfile profile = DefaultProfile.GetProfile("cn-shanghai", "accessKeyId", "accessKeySecret"); DefaultAcsClient client = new DefaultAcsClient(profile); var provider = new StaticCredentialsProvider(profile); CredentialsBackupCompatibilityAdaptor instance = new CredentialsBackupCompatibilityAdaptor(provider);; Assert.IsType<int>(instance.GetHashCode()); instance.GetType(); Assert.IsType<Aliyun.Acs.Core.Auth.CredentialsBackupCompatibilityAdaptor>(instance); }
/// <summary> /// Construct a SignalServiceMessageSender /// </summary> /// <param name="token">A CancellationToken to cancel the sender's operations</param> /// <param name="urls">The URL of the Signal Service.</param> /// <param name="user">The Signal Service username (eg phone number).</param> /// <param name="password">The Signal Service user password</param> /// <param name="deviceId">Tbe Signal Service device id</param> /// <param name="store">The SignalProtocolStore.</param> /// <param name="pipe">An optional SignalServiceMessagePipe</param> /// <param name="eventListener">An optional event listener, which fires whenever sessions are /// setup or torn down for a recipient.</param> /// <param name="userAgent"></param> public SignalServiceMessageSender(CancellationToken token, SignalServiceConfiguration urls, string user, string password, int deviceId, SignalProtocolStore store, SignalServiceMessagePipe pipe, IEventListener eventListener, string userAgent) { Token = token; CredentialsProvider = new StaticCredentialsProvider(user, password, null, deviceId); this.socket = new PushServiceSocket(urls, CredentialsProvider, userAgent); this.store = store; this.localAddress = new SignalServiceAddress(user); this.pipe = pipe; this.eventListener = eventListener; }
public VmClient GetVmClient() { //1. 设置accessKey和secretKey string accessKeyId = ""; string secretAccessKey = ""; CredentialsProvider credentialsProvider = new StaticCredentialsProvider(accessKeyId, secretAccessKey); //2. 创建XXXClient VmClient vmClient = new VmClient.DefaultBuilder() .CredentialsProvider(credentialsProvider) .HttpRequestConfig(new HttpRequestConfig(Protocol.HTTP, 50)) .Build(); return(vmClient); }
public void GetSecurityToken() { IClientProfile profile = DefaultProfile.GetProfile("cn-shanghai", "accessKeyId", "accessKeySecret"); DefaultAcsClient client = new DefaultAcsClient(profile); var provider = new StaticCredentialsProvider(profile); CredentialsBackupCompatibilityAdaptor instance = new CredentialsBackupCompatibilityAdaptor(provider); Assert.Null(instance.GetSecurityToken()); profile = DefaultProfile.GetProfile("cn-shanghai", "accessKeyId", "accessKeySecret"); profile.GetCredential().SecurityToken = "some string"; client = new DefaultAcsClient(profile); provider = new StaticCredentialsProvider(profile); instance = new CredentialsBackupCompatibilityAdaptor(provider); Assert.NotNull(instance.GetSecurityToken()); }
public DiskClient GetDiskClient() { //1. 设置accessKey和secretKey string accessKeyId = ""; string secretAccessKey = ""; CredentialsProvider credentialsProvider = new StaticCredentialsProvider(accessKeyId, secretAccessKey); //2. 创建XXXClient DiskClient diskClient = new DiskClient.DefaultBuilder() .CredentialsProvider(credentialsProvider) .HttpRequestConfig(new HttpRequestConfig(Protocol.HTTP, 50)) // .Environment(env) .Build(); return(diskClient); }
public JdCloudSmsClient(JdCloudSmsConfig config, Action <Exception> exceptionHandler = null) { _config = config ?? throw new ArgumentNullException(nameof(config)); _jdcloudAccount = config.Account ?? throw new ArgumentNullException(nameof(config.Account)); CredentialsProvider credentialsProvider = new StaticCredentialsProvider(_jdcloudAccount.AccessKey, _jdcloudAccount.SecretKey); _client = new SmsClient.DefaultBuilder() .CredentialsProvider(credentialsProvider) .HttpRequestConfig(new HttpRequestConfig(_config.Security ? Protocol.HTTPS : Protocol.HTTP, _config.RequestTimeout)) .Build(); var globalHandle = ExceptionHandleResolver.ResolveHandler(); globalHandle += exceptionHandler; _exceptionHandler = globalHandle; }
/// <summary> /// Construct a SignalServiceMessageSender /// </summary> /// <param name="token">A CancellationToken to cancel the sender's operations</param> /// <param name="urls">The URL of the Signal Service.</param> /// <param name="user">The Signal Service username (eg phone number).</param> /// <param name="password">The Signal Service user password</param> /// <param name="deviceId">Tbe Signal Service device id</param> /// <param name="store">The SignalProtocolStore.</param> /// <param name="pipe">An optional SignalServiceMessagePipe</param> /// <param name="unidentifiedPipe"></param> /// <param name="eventListener">An optional event listener, which fires whenever sessions are /// setup or torn down for a recipient.</param> /// <param name="userAgent"></param> /// <param name="isMultiDevice"></param> public SignalServiceMessageSender(CancellationToken token, SignalServiceConfiguration urls, string user, string password, int deviceId, SignalProtocolStore store, string userAgent, bool isMultiDevice, SignalServiceMessagePipe?pipe, SignalServiceMessagePipe?unidentifiedPipe, IEventListener eventListener) { Token = token; CredentialsProvider = new StaticCredentialsProvider(user, password, null, deviceId); Socket = new PushServiceSocket(urls, CredentialsProvider, userAgent); Store = store; LocalAddress = new SignalServiceAddress(user); Pipe = pipe; UnidentifiedPipe = unidentifiedPipe; IsMultiDevice = isMultiDevice; EventListener = eventListener; }
/// <summary> /// Initializes a new instance of the <see cref="VehicleInventoryDbEventProcessor" /> class. /// </summary> /// <param name="client">The client.</param> /// <param name="dynamoDbContext">The dynamo database context.</param> public VehicleInventoryDbEventProcessor(IElasticClient client, IDynamoDBContext dynamoDbContext) { var config = new DynamoDBContextConfig { ConsistentRead = true, TableNamePrefix = $"dev_" }; // this is used for more integratin level testing. if (client == null) { var creds = new StaticCredentialsProvider( new AwsCredentials { AccessKey = string.Empty, SecretKey = string.Empty, }); var node = new SingleNodeConnectionPool( new Uri(string.Empty)); this.awsHttpConnection = new AwsHttpConnection(RegionEndpoint.USEast1.SystemName, creds); // setup index settings for each strongly typed object var settings = new ConnectionSettings(node, this.awsHttpConnection) .DisableDirectStreaming() .InferMappingFor <InventoryItem>(m => m.IdProperty(p => p.VIN)) .MapDefaultTypeIndices(m => m.Add(typeof(InventoryItem), "dev_vehicle_inventory")); this.elasticClient = new ElasticClient(settings); IAmazonDynamoDB dynamoDbClient = new AmazonDynamoDBClient(RegionEndpoint.USEast1); this.indexer = new ElasticSearchIndexer <InventoryItem>(dynamoDbClient, Environment.GetEnvironmentVariable("environment"), this.elasticClient); this.dynamoDbContext = new DynamoDBContext(dynamoDbClient, config); } else { this.elasticClient = client; this.dynamoDbContext = dynamoDbContext; } }
public void ConsumerMessage() { //事件基本消费者 EventingBasicConsumer consumer = new EventingBasicConsumer(_channel); //接收到消息事件 consumer.Received += (ch, ea) => { string message = Encoding.UTF8.GetString(ea.Body.ToArray()); Console.WriteLine($"{DateTime.Now}收到电话号码消息: {message}"); #region 此时发送短信 //1. 设置accessKey和secretKey string accessKeyId = "C564128C0E7ABE1C28FB04F509B56817"; string secretAccessKey = "94198297B855778C3677EF564EA50CBD"; CredentialsProvider credentialsProvider = new StaticCredentialsProvider(accessKeyId, secretAccessKey); //2. 创建XXXClient SmsClient smsClient = new SmsClient.DefaultBuilder() .CredentialsProvider(credentialsProvider) .HttpRequestConfig(new HttpRequestConfig(Protocol.HTTP, 10)) .Build(); JDClouldTextMsgHelper helper = new JDClouldTextMsgHelper(); //发送短信 helper.testBatchSend(smsClient); //获取状态报告 // p.testStatusReport(smsClient); //获取回复 // p.testReply(smsClient); #endregion //确认该消息已被消费 _channel.BasicAck(ea.DeliveryTag, false); }; //启动消费者 设置为手动应答消息 _channel.BasicConsume("hello", false, consumer); Console.WriteLine("消费者已启动"); Console.ReadKey(); //阻塞 }
public void IClientProfileInstance() { // when securityToken is not null var mock = new Mock <IClientProfile>(); Credential credential = new Credential("accessKeyId", "accessKeySecret", "securityToken"); mock.Setup(foo => foo.GetCredential()).Returns(credential); IClientProfile profile = mock.Object; StaticCredentialsProvider instance = new StaticCredentialsProvider(profile); Assert.IsType <BasicSessionCredentials>(instance.GetCredentials()); // when securityToken is null var mock2 = new Mock <IClientProfile>(); Credential credential2 = new Credential("accessKeyId", "accessKeySecret"); mock2.Setup(foo => foo.GetCredential()).Returns(credential2); IClientProfile profile2 = mock2.Object; StaticCredentialsProvider instance2 = new StaticCredentialsProvider(profile2); Assert.IsType <LegacyCredentials>(instance2.GetCredentials()); }