public async Task CheckAccess(IOwinContext context) { Trace.TraceInformation("CheckAccessImpl.CheckAccess"); if (!_registrationOwnership.IsAuthenticated) { await ServiceHelpers.WriteErrorResponse(context, "user does not have access to the service", HttpStatusCode.Forbidden); return; } if (!await _registrationOwnership.HasTenantEnabled()) { await ServiceHelpers.WriteErrorResponse(context, "package publication has not been enabled in this tenant", HttpStatusCode.Forbidden); return; } JObject body; if (!TryReadBody(context, out body)) { await ServiceHelpers.WriteErrorResponse(context, "request body content must be JSON", HttpStatusCode.BadRequest); return; } IEnumerable <string> validationErrors = Validate(body); if (validationErrors != null) { await ServiceHelpers.WriteErrorResponse(context, validationErrors, HttpStatusCode.BadRequest); return; } Trace.TraceInformation("CheckAccess process request"); await ProcessRequest(context, body); }
public async Task Upload(IOwinContext context) { Trace.TraceInformation("PublishImpl.Upload"); if (!_registrationOwnership.IsAuthenticated) { await ServiceHelpers.WriteErrorResponse(context, "user does not have access to the service", HttpStatusCode.Forbidden); return; } if (!await _registrationOwnership.HasTenantEnabled()) { await ServiceHelpers.WriteErrorResponse(context, "package publication has not been enabled in this tenant", HttpStatusCode.Forbidden); return; } PublicationVisibility publicationVisibility; if (!PublicationVisibility.TryCreate(context, out publicationVisibility)) { await ServiceHelpers.WriteErrorResponse(context, "specify either organization OR subscription NOT BOTH", HttpStatusCode.BadRequest); return; } // no-commit mode - used for just running the validation bool isCommit = GetIsCommit(context); Stream packageStream = context.Request.Body; // validation ValidationResult validationResult = await Validate(packageStream); if (validationResult.HasErrors) { await ServiceHelpers.WriteErrorResponse(context, validationResult.Errors, HttpStatusCode.BadRequest); return; } // registration authorization IList<string> authorizationErrors = await OwnershipHelpers.CheckRegistrationAuthorization(_registrationOwnership, validationResult.PackageIdentity); if (authorizationErrors.Count > 0) { await ServiceHelpers.WriteErrorResponse(context, authorizationErrors, HttpStatusCode.Forbidden); return; } // listed bool isListed = true; string unlist = context.Request.Query["unlist"]; if (unlist != null) { isListed = !unlist.Equals(Boolean.TrueString, StringComparison.InvariantCultureIgnoreCase); } Trace.TraceInformation("UPLOAD Processing package {0}/{1}/{2} isListed: {3} isCommit: {4}", validationResult.PackageIdentity.Namespace, validationResult.PackageIdentity.Id, validationResult.PackageIdentity.Version, isListed, isCommit); // process the package IDictionary<string, JObject> metadata = new Dictionary<string, JObject>(); // (1) save all the artifacts if (isCommit) { await Artifacts.Save(metadata, packageStream, Configuration.StoragePrimary, Configuration.StorageContainerArtifacts); Trace.TraceInformation("Save"); } InferArtifactTypes(metadata); // (2) promote the relevant peices of metadata so they later can appear on the catalog page await ExtractMetadata(metadata, packageStream); Trace.TraceInformation("ExtractMetadata"); // (3) gather all the publication details PublicationDetails publicationDetails = await OwnershipHelpers.CreatePublicationDetails(_registrationOwnership, publicationVisibility); Trace.TraceInformation("CreatePublicationDetails"); // (4) add the new item to the catalog Uri catalogAddress = null; if (isCommit) { catalogAddress = await AddToCatalog(metadata["nuspec"], GetItemType(), publicationDetails, isListed); Trace.TraceInformation("AddToCatalog"); } // (5) update the registration ownership record if (isCommit) { await UpdateRegistrationOwnership(validationResult.PackageIdentity); Trace.TraceInformation("UpdateRegistrationOwnership"); } // (6) create response if (isCommit) { JToken response = new JObject { { "download", metadata["nuspec"]["packageContent"] }, { "catalog", catalogAddress.ToString() } }; await ServiceHelpers.WriteResponse(context, response, HttpStatusCode.Created); } else { context.Response.StatusCode = (int)HttpStatusCode.OK; } }
public async Task Delete(IOwinContext context) { Trace.TraceInformation("DeleteImpl.Upload"); if (!_registrationOwnership.IsAuthenticated) { await ServiceHelpers.WriteErrorResponse(context, "user does not have access to the service", HttpStatusCode.Forbidden); return; } if (!await _registrationOwnership.HasTenantEnabled()) { await ServiceHelpers.WriteErrorResponse(context, "package publication has not been enabled in this tenant", HttpStatusCode.Forbidden); return; } PublicationVisibility publicationVisibility; if (!PublicationVisibility.TryCreate(context, out publicationVisibility)) { await ServiceHelpers.WriteErrorResponse(context, "specify either organization OR subscription NOT BOTH", HttpStatusCode.BadRequest); return; } Stream packageStream = context.Request.Body; // validation ValidationResult validationResult = await Validate(packageStream); if (validationResult.HasErrors) { await ServiceHelpers.WriteErrorResponse(context, validationResult.Errors, HttpStatusCode.BadRequest); return; } // registration authorization IList <string> authorizationErrors = await OwnershipHelpers.CheckRegistrationAuthorizationForEdit(_registrationOwnership, validationResult.PackageIdentity); if (authorizationErrors.Count > 0) { await ServiceHelpers.WriteErrorResponse(context, authorizationErrors, HttpStatusCode.Forbidden); return; } Trace.TraceInformation("DELETE Processing package {0}/{1}/{2}", validationResult.PackageIdentity.Namespace, validationResult.PackageIdentity.Id, validationResult.PackageIdentity.Version); // process delete // (1) gather all the publication details PublicationDetails publicationDetails = await OwnershipHelpers.CreatePublicationDetails(_registrationOwnership, publicationVisibility); Trace.TraceInformation("CreatePublicationDetails"); // (2) add the new item to the catalog Uri catalogAddress = await AddToCatalog(validationResult.PackageIdentity, publicationDetails); Trace.TraceInformation("AddToCatalog"); // (3) update the registration ownership record await UpdateRegistrationOwnership(validationResult.PackageIdentity); Trace.TraceInformation("UpdateRegistrationOwnership"); // (4) create response JToken response = new JObject { { "catalog", catalogAddress.ToString() } }; await ServiceHelpers.WriteResponse(context, response, HttpStatusCode.OK); }