Skip to content

Commit

Permalink
Merge pull request #17 from SpectralOps/gitlab-bot
Browse files Browse the repository at this point in the history
add valid gitlab handler fn name + alignment api gateway api
  • Loading branch information
eladbash authored Sep 1, 2024
2 parents ecb9297 + 096e9ae commit 0d7d6e8
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/basic-gitlab-integration.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module "spectral_lambda_integration" {
# Required environment variables
SPECTRAL_DSN = "MySpectralDSN"
CHECK_POLICY = "Fail on any issue" # (Fail on any issue / Fail on warnings and above / Fail on errors only / Always Pass)
GITLAB_TOKEN = "MyGitlabToken"
GITLAB_ACCESS_TOKEN = "MyGitlabToken"
GITLAB_WEBHOOK_SECRET = "MyGitlabWebhookSecret"
# Optional environment variables
# STRICT_MODE = false / true
Expand Down
8 changes: 4 additions & 4 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ locals {
single_lambda_integration = contains(["jira", "terraform"], var.integration_type) ? true : false
multiple_lambda_integration = contains(["gitlab", "github"], var.integration_type) ? true : false
api_triggered_function_arn = local.single_lambda_integration ? module.lambda_function[0].lambda_function_arn : module.frontend_lambda_function[0].lambda_function_arn
frontend_lambda_handler = contains(["github"], var.integration_type) ? "index.handler" : "frontend.app"
backend_lambda_handler = contains(["github"], var.integration_type) ? "index.handler" : "backend.app"
frontend_lambda_handler = contains(["github", "gitlab"], var.integration_type) ? "index.handler" : "frontend.app"
backend_lambda_handler = contains(["github", "gitlab"], var.integration_type) ? "index.handler" : "backend.app"
shared_default_secrets_names = ["Spectral_Dsn"]
default_secrets_names = {
"github" = coalesce(var.secrets_names, concat(local.shared_default_secrets_names, ["Spectral_GithubBot_PrivateKey", "Spectral_GithubBot_WebhookSecret"])),
"gitlab" = coalesce(var.secrets_names, concat(local.shared_default_secrets_names, ["Spectral_GitlabBot_GitlabToken", "Spectral_GitlabBot_WebhookSecret"]))
"gitlab" = coalesce(var.secrets_names, concat(local.shared_default_secrets_names, ["Spectral_GitlabBot_AccesToken", "Spectral_GitlabBot_WebhookSecret"]))
}
# Please do not change or replace the 'frontend' suffix since there a logic in the bot based in it
api_triggered_function_name = local.single_lambda_integration ? local.resource_name_pattern : "${local.resource_name_pattern}-frontend"
# Merge user env vars with env vars which are not based on user input
env_vars = merge(var.env_vars, { HOME = "/tmp" })
blacklist_file_arn = contains(keys(var.env_vars), "S3_BLACK_LIST_OBJECT_KEY") && contains(keys(var.env_vars), "S3_BLACK_LIST_BUCKET_NAME") ? "arn:aws:s3:::${var.env_vars.S3_BLACK_LIST_BUCKET_NAME}/${var.env_vars.S3_BLACK_LIST_OBJECT_KEY}" : null
}
}
18 changes: 15 additions & 3 deletions modules/api_gateway/rest_api.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,22 @@ resource "aws_api_gateway_rest_api" "gateway_rest_api" {
)
}

resource "aws_api_gateway_resource" "event_resource" {
resource "aws_api_gateway_resource" "api_resource" {
rest_api_id = aws_api_gateway_rest_api.gateway_rest_api.id
parent_id = aws_api_gateway_rest_api.gateway_rest_api.root_resource_id
path_part = "spectral_${var.integration_type}_event"
path_part = "api"
}

resource "aws_api_gateway_resource" "bot_resource" {
rest_api_id = aws_api_gateway_rest_api.gateway_rest_api.id
parent_id = aws_api_gateway_resource.api_resource.id
path_part = var.integration_type
}

resource "aws_api_gateway_resource" "event_resource" {
rest_api_id = aws_api_gateway_rest_api.gateway_rest_api.id
parent_id = aws_api_gateway_resource.bot_resource.id
path_part = "event"
}

resource "aws_api_gateway_method" "get_method" {
Expand Down Expand Up @@ -74,4 +86,4 @@ resource "aws_api_gateway_stage" "rest_api_stage" {
var.global_tags,
lookup(var.tags, "api_gateway", {}),
)
}
}
Binary file modified modules/lambda/source_code/github/backend.zip
Binary file not shown.
Binary file modified modules/lambda/source_code/github/frontend.zip
Binary file not shown.
Binary file modified modules/lambda/source_code/gitlab/backend.zip
Binary file not shown.
Binary file modified modules/lambda/source_code/gitlab/frontend.zip
Binary file not shown.

0 comments on commit 0d7d6e8

Please sign in to comment.