Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }