public static void Start()
        {
            ServiceResolver.SetServiceResolver(new DefaultServiceResolver());

            var config = GlobalConfiguration.Configuration;

            NuGetV2WebApiEnabler.UseNuGetV2WebApiFeed(
                config,
                "NuGetDefault",
                "nuget",
                "PackagesOData",
                enableLegacyPushRoute: true);

            config.Services.Replace(typeof(IExceptionLogger), new TraceExceptionLogger());

            // Trace.Listeners.Add(new TextWriterTraceListener(HostingEnvironment.MapPath("~/NuGet.Server.log")));
            // Trace.AutoFlush = true;

            config.Routes.MapHttpRoute(
                name: "NuGetDefault_ClearCache",
                routeTemplate: "nuget/clear-cache",
                defaults: new { controller = "PackagesOData", action = "ClearCache" },
                constraints: new { httpMethod = new HttpMethodConstraint(HttpMethod.Get) }
                );
        }
        public static IAppBuilder UseLightNuGetServer(
            this IAppBuilder app,
            HttpConfiguration config,
            LightNuGetServerSettings settings,
            Action <LightNuGetFeed[]> cfg = null)
        {
            Ensure.Any.IsNotNull(app, nameof(app));
            Ensure.Any.IsNotNull(config, nameof(config));
            Ensure.Any.IsNotNull(settings, nameof(settings));

            var logger = new SerilogProxyLogger(Log.Logger);

            foreach (var repo in settings.Repositories)
            {
                var feeds = repo.Feeds
                            .Select(fs => new LightNuGetFeed(fs, NuGetV2WebApiEnabler.CreatePackageRepository(Path.Combine(repo.PackagesDirPath, fs.Name), fs, logger)))
                            .ToArray();

                cfg?.Invoke(feeds);

                foreach (var feed in feeds)
                {
                    config.UseNuGetV2WebApiFeed(
                        routeName: feed.Name,
                        routeUrlRoot: feed.Slug,
                        oDatacontrollerName: "LightNuGetFeed");
                }
            }

            return(app);
        }
예제 #3
0
        static void Main(string[] args)
        {
            var baseAddress = "http://*****:*****@"d:\omnishopcentraldata\Packages\Private", settingsProvider, logger);
            NuGetPublicRepository     = NuGetV2WebApiEnabler.CreatePackageRepository(@"d:\omnishopcentraldata\Packages\Public", settingsProvider, logger);
            NuGetVeryPublicRepository = NuGetV2WebApiEnabler.CreatePackageRepository(@"d:\omnishopcentraldata\Packages\VeryPublic", settingsProvider, logger);

            // Start OWIN host, which in turn will create a new instance of Startup class, and execute its Configuration method.
            using (WebApp.Start <Startup>(url: baseAddress))
            {
                Console.WriteLine("Server listening at baseaddress: " + baseAddress);
                Console.WriteLine("[ENTER] to close server");
                Console.ReadLine();
            }
        }
예제 #4
0
        public static void Start()
        {
            ServiceResolver.SetServiceResolver(new DefaultServiceResolver());

            var config = GlobalConfiguration.Configuration;

            config.Routes.MapHttpRoute(
                name: "download_chocolatey_install_script",
                routeTemplate: "install.ps1",
                defaults: new { controller = "Install", action = "DownloadPowerShellInstallScript" },
                constraints: new { httpMethod = new HttpMethodConstraint(HttpMethod.Get) }
                );

            NuGetV2WebApiEnabler.UseNuGetV2WebApiFeed(config, "ChocolateyDefault", "chocolatey", "PackagesOData");

            config.Routes.MapHttpRoute(
                name: "NuGetDefault_ClearCache",
                routeTemplate: "chocolatey/clear-cache",
                defaults: new { controller = "PackagesOData", action = "ClearCache" },
                constraints: new { httpMethod = new HttpMethodConstraint(HttpMethod.Get) }
                );

            config.Routes.MapHttpRoute(
                name: "root_upload",
                routeTemplate: "api/v2/package",
                defaults: new { controller = "PackagesOData", action = "UploadPackage" },
                constraints: new { httpMethod = new HttpMethodConstraint(HttpMethod.Put) }
                );
        }
예제 #5
0
 public void Configure(HttpConfiguration config)
 {
     NuGetV2WebApiEnabler.UseNuGetV2WebApiFeed(config,
                                               routeName: "NuGet",
                                               routeUrlRoot: "NuGet",
                                               oDatacontrollerName: "NuGetGateway");
     config.Services.Replace(typeof(IHttpControllerActivator), new NuGetCompositionRoot());
 }
예제 #6
0
        public static void Initialize(HttpConfiguration config, string controllerName)
        {
            NuGetV2WebApiEnabler.UseNuGetV2WebApiFeed(config, "NuGetDefault", "nuget", controllerName);

            config.Routes.MapHttpRoute(
                name: "NuGetDefault_ClearCache",
                routeTemplate: "nuget/clear-cache",
                defaults: new { controller = controllerName, action = nameof(PackagesODataController.ClearCache) },
                constraints: new { httpMethod = new HttpMethodConstraint(HttpMethod.Get) }
                );
        }
    public static void Start() 
		{
      ServiceResolver.SetServiceResolver(new DefaultServiceResolver());
      var config = GlobalConfiguration.Configuration;
      NuGetV2WebApiEnabler.UseNuGetV2WebApiFeed(config, "NuGetDefault", "nuget", "PackagesOData");
      config.Routes.MapHttpRoute(
        name: "NuGetDefault_ClearCache",
        routeTemplate: "nuget/clear-cache",
        defaults: new { controller = "PackagesOData", action = "ClearCache" },
        constraints: new { httpMethod = new HttpMethodConstraint(HttpMethod.Get) }
      );
    }
예제 #8
0
        private static IContainer CreateContainer()
        {
            string apiKey = ConfigurationManager.AppSettings["APIKEY"];
            string publishPackageRepository = ConfigurationManager.AppSettings["REPOSITORY"];
            string nuGetPublic = "NuGetPublic";

            // Set up a common settingsProvider to be used by all repositories.
            // If a setting is not present in dictionary default value will be used.
            var settings = new Dictionary <string, object>();

            settings.Add("enableDelisting", false);                         //default=false
            settings.Add("enableFrameworkFiltering", false);                //default=false
            settings.Add("ignoreSymbolsPackages", true);                    //default=false
            settings.Add("allowOverrideExistingPackageOnPush", true);       //default=true
            var settingsProvider = new DictionarySettingsProvider(settings);

            var logger = new ConsoleLogger();


            ContainerBuilder builder = new ContainerBuilder();

            Assembly assembly = Assembly.GetExecutingAssembly();

            // Enable Interceptor Logger you can use Class Attribute in  Controller such as [Intercept(typeof(InterceptLogger))]
            builder.RegisterApiControllers(assembly);

            //Sets up three repositories with seperate packages in each feed. These repositories are used by our controllers.
            //In a real world application the repositories will probably be inserted through DI framework, or created in the controllers constructor.
            //builder.Register(c => NuGetV2WebApiEnabler.CreatePackageRepository(PrivatePackageRepository, settingsProvider, logger))
            //    .Keyed<IServerPackageRepository>(NugetPrivate);
            builder.Register(c => NuGetV2WebApiEnabler.CreatePackageRepository(publishPackageRepository, settingsProvider, logger))
            .Keyed <IServerPackageRepository>(nuGetPublic);
            //builder.Register(c => NuGetV2WebApiEnabler.CreatePackageRepository(VeryPublishPackageRepository, settingsProvider, logger))
            //   .Keyed<IServerPackageRepository>(NuGetVeryPublic);

            builder.Register(c => new ApiKeyPackageAuthenticationService(true, apiKey)).As <IPackageAuthenticationService>()
            .InstancePerDependency();

            builder.RegisterType <NugetService>();


            // You can register controllers all at once using assembly scanning...
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

            var container = builder.Build();


            return(container);
        }
예제 #9
0
        public static void Initialize(HttpConfiguration config, string controllerName)
        {
            NuGetV2WebApiEnabler.UseNuGetV2WebApiFeed(config, "NuGetDefault", "nuget", controllerName);

            config.Services.Replace(typeof(IExceptionLogger), new TraceExceptionLogger());

            // Trace.Listeners.Add(new TextWriterTraceListener(HostingEnvironment.MapPath("~/NuGet.Server.log")));
            // Trace.AutoFlush = true;

            config.Routes.MapHttpRoute(
                name: "NuGetDefault_ClearCache",
                routeTemplate: "nuget/clear-cache",
                defaults: new { controller = controllerName, action = nameof(PackagesODataController.ClearCache) },
                constraints: new { httpMethod = new HttpMethodConstraint(HttpMethod.Get) }
                );
        }
예제 #10
0
        public async Task CanSupportMultipleSetsOfRoutes()
        {
            // Arrange
            using (var tc = new TestContext(_output))
            {
                // Enable another set of routes.
                NuGetV2WebApiEnabler.UseNuGetV2WebApiFeed(
                    tc.Config,
                    "NuGetDefault2",
                    "nuget2",
                    TestablePackagesODataController.Name);

                string apiKey = "foobar";
                tc.SetApiKey(apiKey);

                var packagePath = Path.Combine(tc.TemporaryDirectory, "package.nupkg");
                TestData.CopyResourceToPath(TestData.PackageResource, packagePath);

                // Act & Assert
                // 1. Push to the legacy route.
                await tc.PushPackageAsync(apiKey, packagePath, "/api/v2/package");

                // 2. Make a request to the first set of routes.
                using (var request = new HttpRequestMessage(HttpMethod.Get, "/nuget/Packages()"))
                    using (var response = await tc.Client.SendAsync(request))
                    {
                        Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                        var content = await response.Content.ReadAsStringAsync();

                        Assert.Contains(TestData.PackageId, content);
                    }

                // 3. Make a request to the second set of routes.
                using (var request = new HttpRequestMessage(HttpMethod.Get, "/nuget2/Packages()"))
                    using (var response = await tc.Client.SendAsync(request))
                    {
                        Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                        var content = await response.Content.ReadAsStringAsync();

                        Assert.Contains(TestData.PackageId, content);
                    }
            }
        }
예제 #11
0
        public static void ConfigureWebApi(IAppBuilder appBuilder, HttpConfiguration config)
        {
            // Configure Web API Routes:
            // - Enable Attribute Mapping
            // - Enable Default routes at /api.
            config.MapHttpAttributeRoutes();
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            var jsonFormatter = config.Formatters.OfType <JsonMediaTypeFormatter>().First();

            jsonFormatter.SerializerSettings.Formatting       = Formatting.Indented;
            jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

            //Simple authenticator that authorizes all users that supply a username and password. Only meant for demonstration purposes.
            appBuilder.Use(typeof(BasicAuthentication));


            //Feed that allows  read/download access for authenticated users, delete/upload is disabled (configured in controller's constructor).
            //User authentication is done by hosting environment, typical Owin pipeline or IIS (configured by attribute on controller).
            //NuGetV2WebApiEnabler.UseNuGetV2WebApiFeed(config,
            //    routeName: "NuGetAdmin",
            //    routeUrlRoot: "NuGet/admin",
            //    oDatacontrollerName: "NuGetPrivateOData");            //NuGetPrivateODataController.cs, located in Controllers\ folder

            //Feed that allows unauthenticated read/download access, delete/upload requires ApiKey (configured in controller's constructor).
            NuGetV2WebApiEnabler.UseNuGetV2WebApiFeed(config,
                                                      routeName: "NuGetPublic",
                                                      routeUrlRoot: "NuGet/public",
                                                      oDatacontrollerName: "NuGetPublicOData"); //NuGetPublicODataController.cs, located in Controllers\ folder


            //Feed that allows unauthenticated read/download/delete/upload (configured in controller's constructor).
            //NuGetV2WebApiEnabler.UseNuGetV2WebApiFeed(config,
            //    routeName: "NuGetVeryPublic",
            //    routeUrlRoot: "NuGet/verypublic",
            //    oDatacontrollerName: "NuGetVeryPublicOData");        //NuGetVeryPublicODataController.cs, located in Controllers\ folder
        }
예제 #12
0
        public void Configuration(IAppBuilder appBuilder)
        {
            //Simple authenticator that authorizes all users that supply a username and password. Only meant for demonstration purposes.
            appBuilder.Use(typeof(BasicAuthentication));

            // Configure Web API for self-host.
            var config = new HttpConfiguration();

            appBuilder.UseWebApi(config);

            //Map route for ordinary controllers, this is not neccessary for the NuGet feed.
            //It is just included as an example of combining ordinary controllers with NuGet OData Controllers.
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            //Feed that allows  read/download access for authenticated users, delete/upload is disabled (configured in controller's constructor).
            //User authentication is done by hosting environment, typical Owin pipeline or IIS (configured by attribute on controller).
            NuGetV2WebApiEnabler.UseNuGetV2WebApiFeed(config,
                                                      routeName: "NuGetAdmin",
                                                      routeUrlRoot: "NuGet/admin",
                                                      oDatacontrollerName: "NuGetPrivateOData"); //NuGetPrivateODataController.cs, located in Controllers\ folder

            //Feed that allows unauthenticated read/download access, delete/upload requires ApiKey (configured in controller's constructor).
            NuGetV2WebApiEnabler.UseNuGetV2WebApiFeed(config,
                                                      routeName: "NuGetPublic",
                                                      routeUrlRoot: "NuGet/public",
                                                      oDatacontrollerName: "NuGetPublicOData"); //NuGetPublicODataController.cs, located in Controllers\ folder


            //Feed that allows unauthenticated read/download/delete/upload (configured in controller's constructor).
            NuGetV2WebApiEnabler.UseNuGetV2WebApiFeed(config,
                                                      routeName: "NuGetVeryPublic",
                                                      routeUrlRoot: "NuGet/verypublic",
                                                      oDatacontrollerName: "NuGetVeryPublicOData"); //NuGetVeryPublicODataController.cs, located in Controllers\ folder
        }
예제 #13
0
        public static IAppBuilder UseNuGetServerWebApi(this IAppBuilder app)
        {
            ServiceResolver.SetServiceResolver(new DefaultServiceResolver());

            var config = new HttpConfiguration();

            NuGetV2WebApiEnabler.UseNuGetV2WebApiFeed(config, "NuGetDefault", "nuget", "PackagesOData");

            config.Services.Replace(typeof(IExceptionLogger), new TraceExceptionLogger());

            Trace.Listeners.Add(new TextWriterTraceListener(HostingEnvironment.MapPath("~/NuGet.Server.log")));
            Trace.AutoFlush = true;

            config.Routes.MapHttpRoute(
                name: "NuGetDefault_ClearCache",
                routeTemplate: "nuget/clear-cache",
                defaults: new { controller = "PackagesOData", action = "ClearCache" },
                constraints: new { httpMethod = new HttpMethodConstraint(HttpMethod.Get) }
                );

            app.UseWebApi(config);

            return(app);
        }
예제 #14
0
 public NuGetGatewayController() :
     base(NuGetV2WebApiEnabler.CreatePackageRepository("NuGetRepository"), new ApiKeyPackageAuthenticationService(false, null))
 {
 }