2

So in every Azure Function we have that exposes an HTTP trigger at the top of every function we have the same code that validates the JWT for the incoming request. It looks something like this:

public static async Task<IActionResult> Run(...)
{
    if (authManager == null)
    {
        authManager = new AuthorizationManager(log);
    }

    if (!authManager.ValidateJWT(req.Headers, out awid, out error))
    {
        return new UnauthorizedResult();
    }
}

As we literally have dozens of these calls in each project, SonarCloud is calling out a lot of code duplication blocks. They aren't wrong. But its still a false positive, as this is by design and is actually a requirement on each HTTP trigger function.

I know there is //NOSONAR option for issues, but that doesn't work for code dupes. I don't want to ignore all files or change the code dupe rule in the quality gate profile because we do want to alert on dupes outside of this condition.

So how can I suppress code dupe validation for this block of code in every Azure Function we scan?

Dana Epp
  • 509
  • 1
  • 5
  • 13
  • What works for us is adding a pragma disable. Either on the top of the file, or around the piece of code with a pragma enable closing block. E.g. `#pragma warning disable S2743 // Static fields should not be used in generic types` Perhaps this works for you as well? – Bjorn De Rijcke Jun 11 '20 at 14:23

0 Answers0