1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-05 21:18:13 -05:00
bitwarden/src/Api/Utilities/SecretsManagerAttribute.cs
Thomas Avery 8c0996efec
[SM-82] Add HttpController Attribute to protect secrets manager controllers during development (#2117)
* Adding development only attribute for sm API

* dotnet format changes

* Swapping attribute name to SecretsManager
2022-07-18 09:05:26 -05:00

23 lines
645 B
C#

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
namespace Bit.Api.Utilities
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class SecretsManagerAttribute : Attribute, IResourceFilter
{
public void OnResourceExecuting(ResourceExecutingContext context)
{
var env = context.HttpContext.RequestServices.GetService<IHostEnvironment>();
if (!env.IsDevelopment())
{
context.Result = new NotFoundResult();
}
}
public void OnResourceExecuted(ResourceExecutedContext context) { }
}
}