Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implementing an endpoint for triggering workspace synchronizations
- Loading branch information
Showing
8 changed files
with
158 additions
and
1 deletion.
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
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
45 changes: 45 additions & 0 deletions
45
...configurationserver/src/main/java/rocks/inspectit/ocelot/filters/WebhookAccessFilter.java
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,45 @@ | ||
package rocks.inspectit.ocelot.filters; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.NonNull; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import javax.servlet.*; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
/** | ||
* Filter for handling token authentication of the webhook endpoints. In case no token or only blank tokens are defined, | ||
* access will always be denied. | ||
*/ | ||
@Slf4j | ||
@AllArgsConstructor | ||
public class WebhookAccessFilter implements Filter { | ||
|
||
/** | ||
* The name of the query parameter containing the token. | ||
*/ | ||
private static final String TOKEN_PARAMETER = "token"; | ||
|
||
/** | ||
* A list of valid tokens. | ||
*/ | ||
@NonNull | ||
private final List<String> validTokens; | ||
|
||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { | ||
String secret = request.getParameter(TOKEN_PARAMETER); | ||
|
||
if (StringUtils.isNotBlank(secret) && validTokens.contains(secret)) { | ||
chain.doFilter(request, response); | ||
} else { | ||
String requestUrl = ((HttpServletRequest) request).getRequestURL().toString(); | ||
log.warn("Access has been denied for '{}' because of an invalid or missing token.", requestUrl); | ||
((HttpServletResponse) response).sendError(HttpServletResponse.SC_UNAUTHORIZED); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...configurationserver/src/main/java/rocks/inspectit/ocelot/rest/hook/WebhookController.java
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,29 @@ | ||
package rocks.inspectit.ocelot.rest.hook; | ||
|
||
import io.swagger.annotations.ApiImplicitParam; | ||
import io.swagger.annotations.ApiOperation; | ||
import org.eclipse.jgit.api.errors.GitAPIException; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import rocks.inspectit.ocelot.file.FileManager; | ||
import rocks.inspectit.ocelot.rest.AbstractBaseController; | ||
|
||
import java.io.IOException; | ||
|
||
@RestController | ||
public class WebhookController extends AbstractBaseController { | ||
|
||
@Autowired | ||
private FileManager fileManager; | ||
|
||
@ApiOperation(value = "Triggers a synchronization of the workspace branch with a configured remote configuration source.") | ||
@ApiImplicitParam(name = "token", type = "string", value = "Token for authenticating the request.") | ||
@GetMapping(value = "hook/synchronize-workspace") | ||
public ResponseEntity<?> synchronizeWorkspace() throws GitAPIException, IOException { | ||
fileManager.synchronizeWorkspace(); | ||
|
||
return ResponseEntity.ok().build(); | ||
} | ||
} |
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