예제 #1
0
        public SecureSearcherManager CreateSearcherManager()
        {
            SecureSearcherManager searcherManager;

            string luceneDirectory = _configurationService.Get("Local.Lucene.Directory");

            if (!string.IsNullOrEmpty(luceneDirectory))
            {
                string dataDirectory = _configurationService.Get("Local.Data.Directory");
                searcherManager = SecureSearcherManager.CreateLocal(luceneDirectory);
            }
            else
            {
                string storagePrimary       = _configurationService.Get("Storage.Primary");
                string searchIndexContainer = _configurationService.Get("Search.IndexContainer");

                searcherManager = SecureSearcherManager.CreateAzure(storagePrimary, searchIndexContainer);
            }

            string registrationBaseAddress = _configurationService.Get("Search.RegistrationBaseAddress");

            searcherManager.RegistrationBaseAddress["http"]  = MakeRegistrationBaseAddress("http", registrationBaseAddress);
            searcherManager.RegistrationBaseAddress["https"] = MakeRegistrationBaseAddress("https", registrationBaseAddress);
            return(searcherManager);
        }
예제 #2
0
 public void TryMaybeReopen()
 {
     try
     {
         _searcherManager.MaybeReopen();
     }
     catch (StorageException)
     {
         _searcherManager = null;
     }
 }
예제 #3
0
 public void TrySetSearcherManager()
 {
     try
     {
         _searcherManager = CreateSearcherManager();
         _searcherManager.Open();
     }
     catch (FileNotFoundException)
     {
         _searcherManager = null;
     }
 }
예제 #4
0
        public void Configuration(IAppBuilder app)
        {
            app.UseErrorPage();

            //  search test console

            app.Use(async(context, next) =>
            {
                if (String.Equals(context.Request.Path.Value, "/console", StringComparison.OrdinalIgnoreCase))
                {
                    // Redirect to trailing slash to maintain relative links
                    context.Response.Redirect(context.Request.PathBase + context.Request.Path + "/");
                    context.Response.StatusCode = 301;
                    return;
                }
                else if (String.Equals(context.Request.Path.Value, "/console/", StringComparison.OrdinalIgnoreCase))
                {
                    context.Request.Path = new PathString("/console/Index.html");
                }
                await next();
            });

            app.UseStaticFiles(new StaticFileOptions(new SharedOptions
            {
                RequestPath = new PathString("/console"),
                FileSystem  = new EmbeddedResourceFileSystem(typeof(Startup).Assembly, "NuGet.Services.Metadata.Console")
            }));

            //  AAD integration - adding this middleware gives us the claims

            string audience    = _configurationService.Get("ida.Audience");
            string tenant      = _configurationService.Get("ida.Tenant");
            string aadInstance = _configurationService.Get("ida.AADInstance");

            string metadataAddress = string.Format(aadInstance, tenant) + "/federationmetadata/2007-06/federationmetadata.xml";

            app.UseWindowsAzureActiveDirectoryBearerAuthentication(new WindowsAzureActiveDirectoryBearerAuthenticationOptions
            {
                TokenValidationParameters = new TokenValidationParameters
                {
                    ValidAudience   = audience,
                    ValidateIssuer  = true,
                    IssuerValidator = (string issuer, SecurityToken securityToken, TokenValidationParameters validationParameters) => issuer
                },
                Tenant          = tenant,
                MetadataAddress = metadataAddress
            });

            //  start the service running - the Lucene index needs to be reopened regularly on a background thread

            string searchIndexRefresh = _configurationService.Get("Search.IndexRefresh") ?? "15";
            int    seconds;

            if (!int.TryParse(searchIndexRefresh, out seconds))
            {
                seconds = 60;
            }

            _searcherManager = null;

            _gate  = 0;
            _timer = new Timer(ReopenCallback, 0, 10, seconds * 1000);

            app.Run(Invoke);
        }