feat: Implement API client and token models with hashing and JWT authentication
- Added ApiClientModel and ApiTokenModel for managing API clients and tokens. - Introduced ConfigurationDefinitionModel and ConfigurationValueModel for configuration management. - Created CredentialSecretModel for storing credential secrets. - Developed DeploymentArtifactModel and DeploymentBatchModel for deployment management. - Enhanced DeploymentTargetModel and DeploymentTemplateSelectionModel to support template revisions. - Added TemplateRevisionModel and TemplateVersionModel for versioning templates. - Implemented ApiClientSecretHasher for secure secret hashing. - Created ApiTokenService for generating and validating JWT tokens. - Updated QueueJobService to handle deployment requests with artifacts. - Configured authentication settings in appsettings.json for JWT and Negotiate authentication.
This commit is contained in:
@@ -3,6 +3,9 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.SelfService.Portal.Core.API.Dto.Template.Add;
|
||||
using Microsoft.SelfService.Portal.Core.API.Dto.Template.Edit;
|
||||
using Microsoft.SelfService.Portal.Core.API.Dto.Template.Get;
|
||||
using Microsoft.SelfService.Portal.Core.API.Dto.ConfigurationDefinition.Get;
|
||||
using Microsoft.SelfService.Portal.Core.API.Dto.TemplateRevision.Add;
|
||||
using Microsoft.SelfService.Portal.Core.API.Dto.TemplateRevision.Get;
|
||||
using Microsoft.SelfService.Portal.Core.API.Dto.TemplateVersion.Add;
|
||||
using Microsoft.SelfService.Portal.Core.API.Dto.TemplateVersion.Get;
|
||||
using Microsoft.SelfService.Portal.Core.API.Interfaces;
|
||||
@@ -223,6 +226,77 @@ namespace Microsoft.SelfService.Portal.Core.API.Controllers
|
||||
return Ok(version.Id);
|
||||
}
|
||||
|
||||
[HttpGet("{Id}/Versions/{VersionId}/Revisions")]
|
||||
[ProducesResponseType(200, Type = typeof(IEnumerable<GetTemplateRevisionDto>))]
|
||||
[ProducesResponseType(404)]
|
||||
public IActionResult GetTemplateRevisions(Guid Id, Guid VersionId)
|
||||
{
|
||||
if (!_templateInterface.CheckTemplateVersionById(Id, VersionId))
|
||||
return NotFound();
|
||||
|
||||
return Ok(_mapper.Map<List<GetTemplateRevisionDto>>(_templateInterface.GetTemplateRevisions(Id, VersionId)));
|
||||
}
|
||||
|
||||
[HttpGet("{Id}/Versions/{VersionId}/Revisions/{RevisionId}")]
|
||||
[ProducesResponseType(200, Type = typeof(GetTemplateRevisionDto))]
|
||||
[ProducesResponseType(404)]
|
||||
public IActionResult GetTemplateRevisionById(Guid Id, Guid VersionId, Guid RevisionId)
|
||||
{
|
||||
var revision = _templateInterface.GetTemplateRevisionById(Id, VersionId, RevisionId);
|
||||
if (revision == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(_mapper.Map<GetTemplateRevisionDto>(revision));
|
||||
}
|
||||
|
||||
[HttpGet("{Id}/Versions/{VersionId}/Revisions/{RevisionId}/Definitions")]
|
||||
[ProducesResponseType(200, Type = typeof(IEnumerable<GetConfigurationDefinitionDto>))]
|
||||
[ProducesResponseType(404)]
|
||||
public IActionResult GetTemplateRevisionDefinitions(Guid Id, Guid VersionId, Guid RevisionId)
|
||||
{
|
||||
var revision = _templateInterface.GetTemplateRevisionById(Id, VersionId, RevisionId);
|
||||
if (revision == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(_mapper.Map<List<GetConfigurationDefinitionDto>>(revision.ConfigurationDefinitions));
|
||||
}
|
||||
|
||||
[HttpPost("{Id}/Versions/{VersionId}/Revisions")]
|
||||
[ProducesResponseType(200, Type = typeof(Guid))]
|
||||
[ProducesResponseType(400)]
|
||||
[ProducesResponseType(404)]
|
||||
public IActionResult AddTemplateRevision(Guid Id, Guid VersionId, [FromBody] AddTemplateRevisionDto templateRevision)
|
||||
{
|
||||
if (templateRevision == null)
|
||||
return BadRequest(ModelState);
|
||||
|
||||
if (!_templateInterface.CheckTemplateVersionById(Id, VersionId))
|
||||
return NotFound();
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState);
|
||||
|
||||
var revision = _mapper.Map<TemplateRevisionModel>(templateRevision);
|
||||
revision.PublishedBy = templateRevision.PublishedBy ?? User?.Identity?.Name ?? "System";
|
||||
|
||||
try
|
||||
{
|
||||
if (!_templateInterface.AddTemplateRevision(Id, VersionId, revision, templateRevision.Publish))
|
||||
{
|
||||
ModelState.AddModelError("", "Something went wrong while saving template revision");
|
||||
return StatusCode(500, ModelState);
|
||||
}
|
||||
}
|
||||
catch (ConfigurationDocumentValidationException ex)
|
||||
{
|
||||
ModelState.AddModelError(nameof(templateRevision.JsonData), ex.Message);
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
var savedRevision = _templateInterface.GetCurrentTemplateRevision(VersionId);
|
||||
return Ok(savedRevision?.Id ?? revision.Id);
|
||||
}
|
||||
|
||||
[HttpPost("{Id}/Versions/{VersionId}/Publish")]
|
||||
[ProducesResponseType(204)]
|
||||
[ProducesResponseType(404)]
|
||||
|
||||
Reference in New Issue
Block a user