Skip to content

Commit

Permalink
Merge pull request #8 from mspnp/main
Browse files Browse the repository at this point in the history
Synced latest main branch to dev
  • Loading branch information
BryanSoltis authored Aug 8, 2023
2 parents 73b09d0 + 688b95c commit 1fed207
Show file tree
Hide file tree
Showing 34 changed files with 721 additions and 238 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ready
working-directory: src
outputs:
secrets-valid: ${{ steps.secrets-valid.outputs.isvalid }}
steps:
Expand All @@ -57,7 +57,7 @@ jobs:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ready/AzNamingTool
working-directory: src
needs: [check-secrets]
if: needs.check-secrets.outputs.secrets-valid == 'true'
steps:
Expand Down
4 changes: 2 additions & 2 deletions src/Attributes/ApiKeyAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionE
context.Result = new ContentResult()
{
StatusCode = 401,
Content = "Api Key was not provided"
Content = "Api Key was not provided!"
};
return;
}
Expand All @@ -28,7 +28,7 @@ public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionE
context.Result = new ContentResult()
{
StatusCode = 401,
Content = "Api Key is not valid"
Content = "Api Key is not valid!"
};
return;
}
Expand Down
107 changes: 86 additions & 21 deletions src/Controllers/AdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ namespace AzureNamingTool.Controllers
[ApiKey]
public class AdminController : ControllerBase
{
private ServiceResponse serviceResponse = new();
private readonly SiteConfiguration config = ConfigurationHelper.GetConfigurationData();

// POST api/<AdminController>
Expand All @@ -34,14 +33,15 @@ public class AdminController : ControllerBase
[Route("[action]")]
public async Task<IActionResult> UpdatePassword([BindRequired][FromHeader(Name = "AdminPassword")] string adminpassword, [FromBody] string password)
{
ServiceResponse serviceResponse = new();
try
{
if (!String.IsNullOrEmpty(adminpassword))
if (GeneralHelper.IsNotNull(adminpassword))
{
if (adminpassword == GeneralHelper.DecryptString(config.AdminPassword!, config.SALTKey!))
{
serviceResponse = await AdminService.UpdatePassword(password);
return (serviceResponse.Success ? Ok("SUCCESS"): Ok("FAILURE - There was a problem updating the password."));
return (serviceResponse.Success ? Ok("SUCCESS") : Ok("FAILURE - There was a problem updating the password."));
}
else
{
Expand Down Expand Up @@ -72,9 +72,10 @@ public async Task<IActionResult> UpdatePassword([BindRequired][FromHeader(Name =
[Route("[action]")]
public async Task<IActionResult> UpdateAPIKey([BindRequired][FromHeader(Name = "AdminPassword")] string adminpassword, [FromBody] string apikey)
{
ServiceResponse serviceResponse = new();
try
{
if (!String.IsNullOrEmpty(adminpassword))
if (GeneralHelper.IsNotNull(adminpassword))
{
if (adminpassword == GeneralHelper.DecryptString(config.AdminPassword!, config.SALTKey!))
{
Expand Down Expand Up @@ -110,9 +111,10 @@ public async Task<IActionResult> UpdateAPIKey([BindRequired][FromHeader(Name = "
[Route("[action]")]
public async Task<IActionResult> GenerateAPIKey([BindRequired][FromHeader(Name = "AdminPassword")] string adminpassword)
{
ServiceResponse serviceResponse = new();
try
{
if (!String.IsNullOrEmpty(adminpassword))
if (GeneralHelper.IsNotNull(adminpassword))
{
if (adminpassword == GeneralHelper.DecryptString(config.AdminPassword!, config.SALTKey!))
{
Expand Down Expand Up @@ -145,16 +147,32 @@ public async Task<IActionResult> GenerateAPIKey([BindRequired][FromHeader(Name =
[Route("[action]")]
public async Task<IActionResult> GetAdminLog([BindRequired][FromHeader(Name = "AdminPassword")] string adminpassword)
{
ServiceResponse serviceResponse = new();
try
{
serviceResponse = await AdminLogService.GetItems();
if (serviceResponse.Success)
if (GeneralHelper.IsNotNull(adminpassword))
{
return Ok(serviceResponse.ResponseObject);
if (adminpassword == GeneralHelper.DecryptString(config.AdminPassword!, config.SALTKey!))
{
serviceResponse = await AdminLogService.GetItems();
if (serviceResponse.Success)
{
return Ok(serviceResponse.ResponseObject);
}
else
{
return BadRequest(serviceResponse.ResponseObject);
}
}
else
{
return Ok("FAILURE - Incorrect Global Admin Password.");
}

}
else
{
return BadRequest(serviceResponse.ResponseObject);
return Ok("FAILURE - You must provide the Global Admin Password.");
}
}
catch (Exception ex)
Expand All @@ -172,16 +190,32 @@ public async Task<IActionResult> GetAdminLog([BindRequired][FromHeader(Name = "A
[Route("[action]")]
public async Task<IActionResult> PurgeAdminLog([BindRequired][FromHeader(Name = "AdminPassword")] string adminpassword)
{
ServiceResponse serviceResponse = new();
try
{
serviceResponse = await AdminLogService.DeleteAllItems();
if (serviceResponse.Success)
if (GeneralHelper.IsNotNull(adminpassword))
{
return Ok(serviceResponse.ResponseObject);
if (adminpassword == GeneralHelper.DecryptString(config.AdminPassword!, config.SALTKey!))
{
serviceResponse = await AdminLogService.DeleteAllItems();
if (serviceResponse.Success)
{
return Ok(serviceResponse.ResponseObject);
}
else
{
return BadRequest(serviceResponse.ResponseObject);
}
}
else
{
return Ok("FAILURE - Incorrect Global Admin Password.");
}

}
else
{
return BadRequest(serviceResponse.ResponseObject);
return Ok("FAILURE - You must provide the Global Admin Password.");
}
}
catch (Exception ex)
Expand All @@ -199,6 +233,7 @@ public async Task<IActionResult> PurgeAdminLog([BindRequired][FromHeader(Name =
[Route("[action]")]
public async Task<IActionResult> GetGeneratedNamesLog()
{
ServiceResponse serviceResponse = new();
try
{
serviceResponse = await GeneratedNamesService.GetItems();
Expand Down Expand Up @@ -226,16 +261,32 @@ public async Task<IActionResult> GetGeneratedNamesLog()
[Route("[action]")]
public async Task<IActionResult> PurgeGeneratedNamesLog([BindRequired][FromHeader(Name = "AdminPassword")] string adminpassword)
{
ServiceResponse serviceResponse = new();
try
{
serviceResponse = await GeneratedNamesService.DeleteAllItems();
if (serviceResponse.Success)
if (GeneralHelper.IsNotNull(adminpassword))
{
return Ok(serviceResponse.ResponseObject);
if (adminpassword == GeneralHelper.DecryptString(config.AdminPassword!, config.SALTKey!))
{
serviceResponse = await GeneratedNamesService.DeleteAllItems();
if (serviceResponse.Success)
{
return Ok(serviceResponse.ResponseObject);
}
else
{
return BadRequest(serviceResponse.ResponseObject);
}
}
else
{
return Ok("FAILURE - Incorrect Global Admin Password.");
}

}
else
{
return BadRequest(serviceResponse.ResponseObject);
return Ok("FAILURE - You must provide the Global Admin Password.");
}
}
catch (Exception ex)
Expand All @@ -253,16 +304,30 @@ public async Task<IActionResult> PurgeGeneratedNamesLog([BindRequired][FromHeade
[Route("[action]")]
public IActionResult ResetSiteConfiguration([BindRequired][FromHeader(Name = "AdminPassword")] string adminpassword)
{
ServiceResponse serviceResponse = new();
try
{

if (ConfigurationHelper.ResetSiteConfiguration())
if (GeneralHelper.IsNotNull(adminpassword))
{
return Ok("Site configuration reset suceeded!");
if (adminpassword == GeneralHelper.DecryptString(config.AdminPassword!, config.SALTKey!))
{
if (ConfigurationHelper.ResetSiteConfiguration())
{
return Ok("Site configuration reset suceeded!");
}
else
{
return BadRequest("Site configuration reset failed!");
}
}
else
{
return Ok("FAILURE - Incorrect Global Admin Password.");
}
}
else
{
return BadRequest("Site configuration reset failed!");
return Ok("FAILURE - You must provide the Global Admin Password.");
}
}
catch (Exception ex)
Expand Down
31 changes: 27 additions & 4 deletions src/Controllers/CustomComponentsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ namespace AzureNamingTool.Controllers
[ApiKey]
public class CustomComponentsController : ControllerBase
{
private ServiceResponse serviceResponse = new();
// GET: api/<CustomComponentsController>
/// <summary>
/// This function will return the custom components data.
Expand All @@ -28,6 +27,7 @@ public class CustomComponentsController : ControllerBase
[HttpGet]
public async Task<IActionResult> Get()
{
ServiceResponse serviceResponse = new();
try
{
// Get list of items
Expand Down Expand Up @@ -58,6 +58,7 @@ public async Task<IActionResult> Get()
[HttpGet]
public async Task<IActionResult> GetByParentType(string parenttype)
{
ServiceResponse serviceResponse = new();
try
{
// Get list of items
Expand Down Expand Up @@ -87,6 +88,7 @@ public async Task<IActionResult> GetByParentType(string parenttype)
[HttpGet("{id:int}")]
public async Task<IActionResult> Get(int id)
{
ServiceResponse serviceResponse = new();
try
{
// Get list of items
Expand Down Expand Up @@ -116,11 +118,14 @@ public async Task<IActionResult> Get(int id)
[HttpPost]
public async Task<IActionResult> Post([FromBody] CustomComponent item)
{
ServiceResponse serviceResponse = new();
try
{
serviceResponse = await CustomComponentService.PostItem(item);
if (serviceResponse.Success)
{
AdminLogService.PostItem(new AdminLogMessage() { Source = "API", Title = "INFORMATION", Message = "Custom Component (" + item.Name + ") updated." });
CacheHelper.InvalidateCacheObject("CustomComponent");
return Ok(serviceResponse.ResponseObject);
}
else
Expand All @@ -145,11 +150,14 @@ public async Task<IActionResult> Post([FromBody] CustomComponent item)
[Route("[action]")]
public async Task<IActionResult> PostConfig([FromBody] List<CustomComponent> items)
{
ServiceResponse serviceResponse = new();
try
{
serviceResponse = await CustomComponentService.PostConfig(items);
if (serviceResponse.Success)
{
AdminLogService.PostItem(new AdminLogMessage() { Source = "API", Title = "INFORMATION", Message = "Custom Components updated." });
CacheHelper.InvalidateCacheObject("CustomComponent");
return Ok(serviceResponse.ResponseObject);
}
else
Expand All @@ -174,6 +182,7 @@ public async Task<IActionResult> PostConfig([FromBody] List<CustomComponent> ite
[Route("[action]")]
public async Task<IActionResult> PostConfigWithParentData([FromBody] CustomComponmentConfig config)
{
ServiceResponse serviceResponse = new();
try
{
List<ResourceComponent> currentresourcecomponents = new();
Expand Down Expand Up @@ -238,7 +247,8 @@ public async Task<IActionResult> PostConfigWithParentData([FromBody] CustomCompo
}
}
}

AdminLogService.PostItem(new AdminLogMessage() { Source = "API", Title = "INFORMATION", Message = "Custom Components updated." });
CacheHelper.InvalidateCacheObject("CustomComponent");
return Ok("Custom Component configuration updated!");
}
else
Expand All @@ -262,12 +272,25 @@ public async Task<IActionResult> PostConfigWithParentData([FromBody] CustomCompo
[HttpDelete("{id}")]
public async Task<IActionResult> Delete(int id)
{
ServiceResponse serviceResponse = new();
try
{
serviceResponse = await CustomComponentService.DeleteItem(id);
// Get the item details
serviceResponse = await CustomComponentService.GetItem(id);
if (serviceResponse.Success)
{
return Ok(serviceResponse.ResponseObject);
CustomComponent item = (CustomComponent)serviceResponse.ResponseObject!;
serviceResponse = await CustomComponentService.DeleteItem(id);
if (serviceResponse.Success)
{
AdminLogService.PostItem(new AdminLogMessage() { Source = "API", Title = "INFORMATION", Message = "Custom Component (" + item.Name + ") deleted." });
CacheHelper.InvalidateCacheObject("GeneratedName");
return Ok("Custom Component (" + item.Name + ") deleted.");
}
else
{
return BadRequest(serviceResponse.ResponseObject);
}
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion src/Controllers/ImportExportController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace AzureNamingTool.Controllers
[ApiKey]
public class ImportExportController : ControllerBase
{
private ServiceResponse serviceResponse = new();
// GET: api/<ImportExportController>
/// <summary>
/// This function will export the current configuration data (all components) as a single JSON file.
Expand All @@ -28,6 +27,7 @@ public class ImportExportController : ControllerBase
[Route("[action]")]
public async Task<IActionResult> ExportConfiguration(bool includeAdmin = false)
{
ServiceResponse serviceResponse = new();
try
{
serviceResponse = await ImportExportService.ExportConfig(includeAdmin);
Expand Down Expand Up @@ -57,6 +57,7 @@ public async Task<IActionResult> ExportConfiguration(bool includeAdmin = false)
[Route("[action]")]
public async Task<IActionResult> ImportConfiguration([FromBody] ConfigurationData configdata)
{
ServiceResponse serviceResponse = new();
try
{
serviceResponse = await ImportExportService.PostConfig(configdata);
Expand Down
Loading

0 comments on commit 1fed207

Please sign in to comment.