-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: munishchouhan <[email protected]>
- Loading branch information
1 parent
facbf99
commit b0c8bfb
Showing
16 changed files
with
364 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/groovy/io/seqera/wave/filter/MetricsQueryParamValidationFilter.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package io.seqera.wave.filter | ||
|
||
import java.util.regex.Pattern | ||
|
||
import groovy.transform.CompileStatic | ||
import io.micronaut.context.annotation.Requires | ||
import io.micronaut.http.HttpRequest | ||
import io.micronaut.http.MutableHttpResponse | ||
import io.micronaut.http.annotation.Filter | ||
import io.micronaut.http.filter.HttpServerFilter | ||
import io.micronaut.http.filter.ServerFilterChain | ||
import io.seqera.wave.core.ContainerPlatform | ||
import io.seqera.wave.exception.BadRequestException | ||
import org.reactivestreams.Publisher | ||
|
||
@CompileStatic | ||
@Filter(["/v1alpha2/metrics/**", "/v1alpha3/metrics/**/**"]) | ||
@Requires(property = 'wave.metrics.enabled', value = 'true') | ||
class MetricsQueryParamValidationFilter implements HttpServerFilter { | ||
|
||
static final private Pattern DATE_PATTERN = Pattern.compile("\\d{4}-\\d{2}-\\d{2}") | ||
|
||
@Override | ||
Publisher<MutableHttpResponse<?>> doFilter(HttpRequest<?> request, ServerFilterChain chain) { | ||
|
||
Map<String, List<String>> queryParams = request.getParameters().asMap() | ||
|
||
final String date = queryParams.get("date")?[0] | ||
final String arch = queryParams.get("arch")?[0] | ||
|
||
if(date && !DATE_PATTERN.matcher(date).matches()) { | ||
throw new BadRequestException('date format should be yyyy-MM-dd') | ||
} else if (arch && !ContainerPlatform.ALLOWED_ARCH.contains(arch)) { | ||
throw new BadRequestException('arch should be one of ' + ContainerPlatform.ALLOWED_ARCH) | ||
} | ||
|
||
return chain.proceed(request) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.