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 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) } ); }
public void Configure(HttpConfiguration config) { NuGetV2WebApiEnabler.UseNuGetV2WebApiFeed(config, routeName: "NuGet", routeUrlRoot: "NuGet", oDatacontrollerName: "NuGetGateway"); config.Services.Replace(typeof(IHttpControllerActivator), new NuGetCompositionRoot()); }
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) } ); }
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) } ); }
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); } } }
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 }
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 }
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); }