コード例 #1
0
        /// <summary>
        ///     Initializes a new instance of the RestService class.
        /// </summary>
        public RestService(string schemaRegistryUrl,  int timeoutMs, IAuthenticationHeaderValueProvider authenticationHeaderValueProvider,  List <X509Certificate2>  certificates, bool enableSslCertificateVerification)
        {
            this.authenticationHeaderValueProvider = authenticationHeaderValueProvider;

            this.clients = schemaRegistryUrl
                           .Split(',')
                           .Select(SanitizeUri)// need http or https - use http if not present.
                           .Select(uri =>
            {
                HttpClient client;
                                    if (certificates.Count  >  0)
                                     {
                                            client  =  new HttpClient(CreateHandler(certificates, enableSslCertificateVerification))   {
                         BaseAddress  =  new Uri(uri,  UriKind.Absolute),  Timeout  =  TimeSpan.FromMilliseconds(timeoutMs)  
                    };
                                        
                }
                                    else
                                     {
                                            client  =  new HttpClient()   {
                         BaseAddress  =  new Uri(uri,  UriKind.Absolute),  Timeout  =  TimeSpan.FromMilliseconds(timeoutMs)  
                    };
                                        
                }
                return(client);
            })
                           .ToList();
        }
コード例 #2
0
 public static int TestFile(string path, IAuthenticationHeaderValueProvider authenticationHeaderValueProvider = null)
 {
     using (var drp = new DebugReaderProvider(path))
     {
         return(TestFile(drp, authenticationHeaderValueProvider));
     }
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: tong20082009/SourceLink
        public static int TestFile(DebugReaderProvider drp, IAuthenticationHeaderValueProvider authenticationHeaderValueProvider = null)
        {
            var missingDocs = new List <Document>();
            var erroredDocs = new List <Document>();
            var documents   = GetDocumentsWithUrlHashes(drp, authenticationHeaderValueProvider).GetAwaiter().GetResult();

            foreach (var doc in documents)
            {
                if (doc.IsEmbedded)
                {
                    //Console.WriteLine("{0} {1} {2} {3}", doc.Hash.ToHex(), HashAlgorithmGuids.GetName(doc.HashAlgorithm), LanguageGuids.GetName(doc.Language), doc.Name);
                    //Console.WriteLine("embedded");
                }
                else if (doc.Url != null)
                {
                    if (doc.Error == null)
                    {
                        //Console.WriteLine("{0} {1} {2} {3}", doc.Hash.ToHex(), HashAlgorithmGuids.GetName(doc.HashAlgorithm), LanguageGuids.GetName(doc.Language), doc.Name);
                        //Console.WriteLine(doc.Url);
                    }
                    else
                    {
                        erroredDocs.Add(doc);
                    }
                }
                else
                {
                    missingDocs.Add(doc);
                }
            }
            if (missingDocs.Count > 0)
            {
                Console.WriteLine("" + missingDocs.Count + " Documents without URLs:");
                foreach (var doc in missingDocs)
                {
                    Console.WriteLine("{0} {1} {2} {3}", doc.Hash.ToHex(), HashAlgorithmGuids.GetName(doc.HashAlgorithm), LanguageGuids.GetName(doc.Language), doc.Name);
                }
            }
            if (erroredDocs.Count > 0)
            {
                Console.WriteLine("" + erroredDocs.Count + " Documents with errors:");
                foreach (var doc in erroredDocs)
                {
                    Console.WriteLine("{0} {1} {2} {3}", doc.Hash.ToHex(), HashAlgorithmGuids.GetName(doc.HashAlgorithm), LanguageGuids.GetName(doc.Language), doc.Name);
                    Console.WriteLine(doc.Url);
                    Console.WriteLine("error: " + doc.Error);
                }
            }
            if (missingDocs.Count > 0 || erroredDocs.Count > 0)
            {
                Console.WriteLine("sourcelink test failed");
                return(4);
            }

            Console.WriteLine("sourcelink test passed: " + drp.Path);
            return(0);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: tong20082009/SourceLink
 public static int TestFile(string path, IAuthenticationHeaderValueProvider authenticationHeaderValueProvider = null)
 {
     using (var drp = DebugReaderProvider.Create(path))
     {
         if (drp == null)
         {
             Console.Error.WriteLine("unable to read debug info: " + path);
             return(5);
         }
         return(TestFile(drp, authenticationHeaderValueProvider));
     }
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: tong20082009/SourceLink
        public static int TestNupkg(string path, List <string> files, IAuthenticationHeaderValueProvider authenticationHeaderValueProvider = null)
        {
            var errors = 0;

            using (var p = new PackageArchiveReader(File.OpenRead(path)))
            {
                var dlls = new List <string>();
                var pdbs = new HashSet <string>();

                foreach (var f in p.GetFiles())
                {
                    switch (Path.GetExtension(f))
                    {
                    case ".dll":
                        dlls.Add(f);
                        break;

                    case ".pdb":
                        pdbs.Add(f);
                        break;
                    }
                }

                if (files.Count == 0)
                {
                    foreach (var dll in dlls)
                    {
                        var pdb = Path.ChangeExtension(dll, ".pdb");
                        if (pdbs.Contains(pdb))
                        {
                            files.Add(pdb);
                        }
                        else if (!IsSatelliteAssembly(dll, dlls))
                        {
                            files.Add(dll);
                        }
                    }
                }

                foreach (var file in files)
                {
                    try
                    {
                        using (var stream = p.GetStream(file))
                            using (var ms = new MemoryStream()) // seek required
                            {
                                stream.CopyTo(ms);
                                ms.Position = 0;
                                using (var drp = DebugReaderProvider.Create(file, ms))
                                {
                                    if (drp == null)
                                    {
                                        Console.Error.WriteLine("unable to read debug info: " + path);
                                        return(5);
                                    }
                                    if (TestFile(drp, authenticationHeaderValueProvider) != 0)
                                    {
                                        Console.WriteLine("failed for " + file);
                                        errors++;
                                    }
                                }
                            }
                    }
                    catch (FileNotFoundException)
                    {
                        Console.WriteLine("file not found: " + file);
                        errors++;
                    }
                }
            }
            return(errors);
        }
コード例 #6
0
 public ZipContentStorageHelper(AxSecureUrlConfiguration axSecureUrlConfiguration, IAuthenticationHeaderValueProvider authenticationHeaderValueProvider, IHttpClientFactory httpClientFactory)
 {
     AxSecureUrlConfiguration          = axSecureUrlConfiguration;
     AuthenticationHeaderValueProvider = authenticationHeaderValueProvider;
     HttpClientFactory = httpClientFactory;
 }
コード例 #7
0
        /// <summary>
        ///     Initialize a new instance of the SchemaRegistryClient class with a custom <see cref="IAuthenticationHeaderValueProvider"/>
        /// </summary>
        /// <param name="config">
        ///     Configuration properties.
        /// </param>
        /// <param name="authenticationHeaderValueProvider">
        ///     The authentication header value provider
        /// </param>
        public CachedSchemaRegistryClient(IEnumerable <KeyValuePair <string, string> > config, IAuthenticationHeaderValueProvider authenticationHeaderValueProvider)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config properties must be specified.");
            }

            keySubjectNameStrategy   = GetKeySubjectNameStrategy(config);
            valueSubjectNameStrategy = GetValueSubjectNameStrategy(config);

            var schemaRegistryUrisMaybe = config.FirstOrDefault(prop => prop.Key.ToLower() == SchemaRegistryConfig.PropertyNames.SchemaRegistryUrl);

            if (schemaRegistryUrisMaybe.Value == null)
            {
                throw new ArgumentException($"{SchemaRegistryConfig.PropertyNames.SchemaRegistryUrl} configuration property must be specified.");
            }
            var schemaRegistryUris = (string)schemaRegistryUrisMaybe.Value;

            var timeoutMsMaybe = config.FirstOrDefault(prop => prop.Key.ToLower() == SchemaRegistryConfig.PropertyNames.SchemaRegistryRequestTimeoutMs);
            int timeoutMs;

            try { timeoutMs = timeoutMsMaybe.Value == null ? DefaultTimeout : Convert.ToInt32(timeoutMsMaybe.Value); }
            catch (FormatException) { throw new ArgumentException($"Configured value for {SchemaRegistryConfig.PropertyNames.SchemaRegistryRequestTimeoutMs} must be an integer."); }

            var identityMapCapacityMaybe = config.FirstOrDefault(prop => prop.Key.ToLower() == SchemaRegistryConfig.PropertyNames.SchemaRegistryMaxCachedSchemas);

            try { this.identityMapCapacity = identityMapCapacityMaybe.Value == null ? DefaultMaxCachedSchemas : Convert.ToInt32(identityMapCapacityMaybe.Value); }
            catch (FormatException) { throw new ArgumentException($"Configured value for {SchemaRegistryConfig.PropertyNames.SchemaRegistryMaxCachedSchemas} must be an integer."); }

            var basicAuthSource = config.FirstOrDefault(prop => prop.Key.ToLower() == SchemaRegistryConfig.PropertyNames.SchemaRegistryBasicAuthCredentialsSource).Value ?? "";
            var basicAuthInfo   = config.FirstOrDefault(prop => prop.Key.ToLower() == SchemaRegistryConfig.PropertyNames.SchemaRegistryBasicAuthUserInfo).Value ?? "";

            string username = null;
            string password = null;

            if (basicAuthSource == "USER_INFO" || basicAuthSource == "")
            {
                if (basicAuthInfo != "")
                {
                    var userPass = (basicAuthInfo).Split(':');
                    if (userPass.Length != 2)
                    {
                        throw new ArgumentException($"Configuration property {SchemaRegistryConfig.PropertyNames.SchemaRegistryBasicAuthUserInfo} must be of the form 'username:password'.");
                    }
                    username = userPass[0];
                    password = userPass[1];
                }
            }
            else if (basicAuthSource == "SASL_INHERIT")
            {
                if (basicAuthInfo != "")
                {
                    throw new ArgumentException($"{SchemaRegistryConfig.PropertyNames.SchemaRegistryBasicAuthCredentialsSource} set to 'SASL_INHERIT', but {SchemaRegistryConfig.PropertyNames.SchemaRegistryBasicAuthUserInfo} as also specified.");
                }
                var saslUsername = config.FirstOrDefault(prop => prop.Key == "sasl.username");
                var saslPassword = config.FirstOrDefault(prop => prop.Key == "sasl.password");
                if (saslUsername.Value == null)
                {
                    throw new ArgumentException($"{SchemaRegistryConfig.PropertyNames.SchemaRegistryBasicAuthCredentialsSource} set to 'SASL_INHERIT', but 'sasl.username' property not specified.");
                }
                if (saslPassword.Value == null)
                {
                    throw new ArgumentException($"{SchemaRegistryConfig.PropertyNames.SchemaRegistryBasicAuthCredentialsSource} set to 'SASL_INHERIT', but 'sasl.password' property not specified.");
                }
                username = saslUsername.Value;
                password = saslPassword.Value;
            }
            else
            {
                throw new ArgumentException($"Invalid value '{basicAuthSource}' specified for property '{SchemaRegistryConfig.PropertyNames.SchemaRegistryBasicAuthCredentialsSource}'");
            }

            if (authenticationHeaderValueProvider != null)
            {
                if (username != null || password != null)
                {
                    throw new ArgumentException($"Invalid authentication header value provider configuration: Cannot specify both custom provider and username/password");
                }
            }
            else
            {
                if (username != null && password == null)
                {
                    throw new ArgumentException($"Invalid authentication header value provider configuration: Basic authentication username specified, but password not specified");
                }
                if (username == null && password != null)
                {
                    throw new ArgumentException($"Invalid authentication header value provider configuration: Basic authentication password specified, but username not specified");
                }
                else if (username != null && password != null)
                {
                    authenticationHeaderValueProvider = new BasicAuthenticationHeaderValueProvider(username, password);
                }
            }

            foreach (var property in config)
            {
                if (!property.Key.StartsWith("schema.registry."))
                {
                    continue;
                }

                if (property.Key != SchemaRegistryConfig.PropertyNames.SchemaRegistryUrl &&
                    property.Key != SchemaRegistryConfig.PropertyNames.SchemaRegistryRequestTimeoutMs &&
                    property.Key != SchemaRegistryConfig.PropertyNames.SchemaRegistryMaxCachedSchemas &&
                    property.Key != SchemaRegistryConfig.PropertyNames.SchemaRegistryBasicAuthCredentialsSource &&
                    property.Key != SchemaRegistryConfig.PropertyNames.SchemaRegistryBasicAuthUserInfo &&
                    property.Key != SchemaRegistryConfig.PropertyNames.SchemaRegistryKeySubjectNameStrategy &&
                    property.Key != SchemaRegistryConfig.PropertyNames.SchemaRegistryValueSubjectNameStrategy &&
                    property.Key  !=  SchemaRegistryConfig.PropertyNames.SslCaLocation  &&
                                        property.Key  !=  SchemaRegistryConfig.PropertyNames.SslKeystoreLocation  &&
                                        property.Key  !=  SchemaRegistryConfig.PropertyNames.SslKeystorePassword &&
                    property.Key  !=  SchemaRegistryConfig.PropertyNames.EnableSslCertificateVerification)
                {
                    throw new ArgumentException($"Unknown configuration parameter {property.Key}");
                }
            }

            var  sslVerificationMaybe = config.FirstOrDefault(prop => prop.Key.ToLower() == SchemaRegistryConfig.PropertyNames.EnableSslCertificateVerification);
            bool sslVerify;

            try { sslVerify = sslVerificationMaybe.Value == null ? DefaultEnableSslCertificateVerification : bool.Parse(sslVerificationMaybe.Value); }
            catch (FormatException) { throw new ArgumentException($"Configured value for {SchemaRegistryConfig.PropertyNames.EnableSslCertificateVerification} must be a bool."); }

            this.restService  =  new RestService(schemaRegistryUris,  timeoutMs,  authenticationHeaderValueProvider,  SetSslConfig(config), sslVerify);
        }