Skip to content

Commit

Permalink
Editor API endpoint and controller so webhook/projects repo can speak…
Browse files Browse the repository at this point in the history
… to one another (#120)

closes #115
  • Loading branch information
loiswells97 authored Feb 9, 2023
2 parents a4db32d + 1807fa5 commit 5112ae6
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ AWS_S3_ACTIVE_STORAGE_BUCKET=changeme
AWS_S3_REGION=changeme
AWS_SECRET_ACCESS_KEY=changeme

GITHUB_WEBHOOK_SECRET=test_token

POSTGRES_HOST=changeme
POSTGRES_USER=changeme
POSTGRES_PASSWORD=changeme

HYDRA_ADMIN_URL=http://host.docker.internal:9002
HYDRA_SECRET=

SMEE_TUNNEL=https://smee.io/MLq0n9kvAes2vydX

# Add the below to bypass token authentication with hyrdra
# BYPASS_AUTH=true
# AUTH_USER_ID=<<set to match user_id for desired user>>
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem 'aws-sdk-s3', require: false
gem 'bootsnap', require: false
gem 'cancancan', '~> 3.3'
gem 'faraday'
gem 'github_webhook', '~> 1.4'
gem 'importmap-rails'
gem 'jbuilder'
gem 'kaminari'
Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ GEM
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-net_http (3.0.2)
github_webhook (1.4.2)
activesupport (>= 4)
rack (>= 1.3)
railties (>= 4)
globalid (1.0.0)
activesupport (>= 5.0)
hashdiff (1.0.1)
Expand Down Expand Up @@ -292,6 +296,7 @@ DEPENDENCIES
factory_bot_rails
faker
faraday
github_webhook (~> 1.4)
importmap-rails
jbuilder
kaminari
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ Add a comma separated list to the relevant enviroment settings. E.g for developm

```
ALLOWED_ORIGINS=localhost:3002,localhost:3000
```

# Webhooks

This API receives push event data from the [Raspberry Pi Learning](https://github.com/raspberrypilearning) organisation via webhooks. These webhooks are mediated locally through `smee`, which runs in a Docker container. The webhook data is processed using the `github_webhooks` gem in the `github_webhooks_controller`.
16 changes: 16 additions & 0 deletions app/controllers/github_webhooks_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

class GithubWebhooksController < ActionController::API
include GithubWebhook::Processor

def github_push(_payload)
# TODO: handle push webhook
head :ok
end

private

def webhook_secret(_payload)
ENV.fetch('GITHUB_WEBHOOK_SECRET')
end
end
1 change: 1 addition & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Ability

def initialize(user)
can :show, Project, user_id: nil
can :upload, Project, user_id: nil

return if user.blank?

Expand Down
3 changes: 3 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,7 @@

# Uncomment if you wish to allow Action Cable access from any origin.
# config.action_cable.disable_request_forgery_protection = true

# Allow smee requests
config.hosts << 'smee.io'
end
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
resource :images, only: %i[create], controller: 'projects/images'
end
end

resource :github_webhooks, only: :create, defaults: { formats: :json }
end
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ services:
- POSTGRES_DB
- POSTGRES_PASSWORD
- POSTGRES_USER
smee:
image: deltaprojects/smee-client
command: -u $SMEE_TUNNEL -t http://api:3009/github_webhooks

0 comments on commit 5112ae6

Please sign in to comment.