Skip to content

Commit

Permalink
Remove redundant pub-sub mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-laa committed Dec 6, 2024
1 parent 3d2295e commit aec1d0f
Show file tree
Hide file tree
Showing 29 changed files with 10 additions and 559 deletions.
1 change: 0 additions & 1 deletion .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ POSTGRES_NAME=laa_crime_application_store

# Authentication requirements when authentication enabled
APP_CLIENT_ID=not-a-real-secret
ENTRA_CLIENT_SECRET=not-a-real-secret
TENANT_ID=not-a-real-secret

SIDEKIQ_WEB_UI_USERNAME=not-a-real-secret
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,16 @@ b) `rails server` - will only run the rails server, which is fine if you are not

### Authenticating Requests

When running locally you can switch off authentication for message sending to subscribers by providing the following env var:
When running locally you can switch off authentication for messages received from clients by providing the following env var:

```
AUTHENTICATION_REQUIRED=false
```

To authenticate messages sent to subscribers you will need to provide these env vars with values. The values can be retrieved from the relevant namespace's kubernetes secret, named `azure-secret`. *Do no use the production secret's values*
To authenticate messages sent by clients you will need to provide these env vars with values. The values can be retrieved from the relevant namespace's kubernetes secret, named `azure-secret`. *Do no use the production secret's values*

```sh
APP_CLIENT_ID=app-store-application-identifier
ENTRA_CLIENT_SECRET=app-store-application-secret
TENANT_ID=app-store-application-entra-tenant
```

Expand Down
5 changes: 1 addition & 4 deletions app/controllers/V1/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@ def create
end

def update
::Submissions::UpdateService.call(current_submission, params, current_client_role)
::Submissions::UpdateService.call(current_submission, params)
render json: current_submission, status: :created
rescue ActiveRecord::RecordInvalid => e
render json: { errors: e.message }, status: :unprocessable_entity
rescue NotifySubscriber::ClientResponseError => e
Sentry.capture_exception(e)
render json: { errors: e.message }, status: :internal_server_error
end

def metadata
Expand Down
29 changes: 0 additions & 29 deletions app/controllers/V1/subscribers_controller.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/jobs/expire_sendbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ def expire(submission)
version: submission.current_version,
)
end

NotificationService.call(submission, :app_store)
end

def build_expiry_event(now, current_version)
Expand Down
72 changes: 0 additions & 72 deletions app/jobs/notify_subscriber.rb

This file was deleted.

6 changes: 0 additions & 6 deletions app/models/subscriber.rb

This file was deleted.

4 changes: 0 additions & 4 deletions app/services/authorization/rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ module Authorization
module Rules
PERMISSIONS = {
provider: {
subscribers: {
create: true,
destroy: ->(object, _) { !object || object.subscriber_type == "provider" },
},
submissions: {
index: true,
show: true,
Expand Down
9 changes: 0 additions & 9 deletions app/services/notification_service.rb

This file was deleted.

3 changes: 1 addition & 2 deletions app/services/submissions/update_service.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Submissions
class UpdateService
class << self
def call(submission, params, role)
def call(submission, params)
submission.with_lock do
submission.current_version += 1
EventAdditionService.call(submission, params)
Expand All @@ -10,7 +10,6 @@ def call(submission, params, role)
submission.save!
submission.ordered_submission_versions.where(pending: true).destroy_all
add_new_version(submission, params)
NotificationService.call(submission, role)
end
end

Expand Down
44 changes: 0 additions & 44 deletions app/services/tokens/generation_service.rb

This file was deleted.

4 changes: 0 additions & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
member { patch :metadata }
collection { post :auto_assignments }
end
resources :subscribers, only: %i[create]
delete :subscribers, to: "subscribers#destroy"

namespace :submissions do
resource :searches, only: %[create]
Expand All @@ -36,8 +34,6 @@
post :application, to: "submissions#create"
get "application/:id", to: "submissions#show"
put "application/:id", to: "submissions#update"
post :subscriber, to: "subscribers#create"
delete :subscriber, to: "subscribers#destroy"
end

root to: "v1/submissions#index"
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20241206171615_delete_subscriber.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class DeleteSubscriber < ActiveRecord::Migration[8.0]
def change
drop_table :subscriber
end
end
9 changes: 1 addition & 8 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.2].define(version: 2024_11_25_171006) do
ActiveRecord::Schema[7.2].define(version: 2024_12_06_171615) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
enable_extension "postgis"
Expand Down Expand Up @@ -44,13 +44,6 @@
t.index ["search_fields"], name: "index_application_version_on_search_fields", using: :gin
end

create_table "subscriber", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.string "subscriber_type", limit: 50, null: false
t.text "webhook_url", null: false
t.integer "failed_attempts", default: 0
t.index ["webhook_url", "subscriber_type"], name: "unique_subcribers", unique: true
end

create_table "translations", force: :cascade do |t|
t.string "key"
t.string "translation"
Expand Down
7 changes: 0 additions & 7 deletions helm_deploy/templates/deployment-worker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,6 @@ spec:
secretKeyRef:
name: azure-secret
key: tenant_id
- name: ENTRA_CLIENT_SECRET
valueFrom:
secretKeyRef:
name: azure-secret
key: client_secret
{{- if not (eq .Values.environment "prod") }}
- name: AUTHENTICATION_REQUIRED
value: {{ .Values.envVars.authenticationRequired | quote}}
Expand Down Expand Up @@ -161,8 +156,6 @@ spec:
name: crm-elasticache
key: auth_token
{{ end }}
- name: SUBSCRIBER_FAILED_ATTEMPT_DELETION_THRESHOLD
value: '{{ .Values.envVars.subscriberFailedAttemptDeletionThreshold }}'
- name: ENABLE_PROMETHEUS_EXPORTER
value: 'true'
{{- with .Values.nodeSelector }}
Expand Down
7 changes: 0 additions & 7 deletions helm_deploy/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,6 @@ spec:
secretKeyRef:
name: azure-secret
key: tenant_id
- name: ENTRA_CLIENT_SECRET
valueFrom:
secretKeyRef:
name: azure-secret
key: client_secret
{{- if not (eq .Values.environment "prod") }}
- name: AUTHENTICATION_REQUIRED
value: {{ .Values.envVars.authenticationRequired | quote}}
Expand Down Expand Up @@ -180,8 +175,6 @@ spec:
name: crm-elasticache
key: auth_token
{{ end }}
- name: SUBSCRIBER_FAILED_ATTEMPT_DELETION_THRESHOLD
value: '{{ .Values.envVars.subscriberFailedAttemptDeletionThreshold }}'
- name: ENABLE_PROMETHEUS_EXPORTER
value: 'true'
{{- with .Values.nodeSelector }}
Expand Down
1 change: 0 additions & 1 deletion helm_deploy/values-development.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ envVars:
environment: development
swaggerEndpoint: /docs
authenticationRequired: True
subscriberFailedAttemptDeletionThreshold: '100'
# This is used to configure the temporary non-RDS postgres DB
postgresql:
enabled: true
Expand Down
1 change: 0 additions & 1 deletion helm_deploy/values-production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ envVars:
environment: production
swaggerEndpoint:
authenticationRequired: True
subscriberFailedAttemptDeletionThreshold: ''

# Instead of a temporary postgres pod we use RDS
postgresql:
Expand Down
1 change: 0 additions & 1 deletion helm_deploy/values-uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ envVars:
environment: uat
swaggerEndpoint: /docs
authenticationRequired: True
subscriberFailedAttemptDeletionThreshold: ''

# Instead of a temporary postgres pod we use RDS
postgresql:
Expand Down
6 changes: 0 additions & 6 deletions lib/tasks/adjust.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ namespace :adjust do
task :status, [:submission_id, :status, :role_to_notify] => :environment do |_, args|
submission = Submission.find(args.submission_id)
submission.update!(state: args.status)

next if args.role_to_notify.blank?

Subscriber.where(subscriber_type: args.role_to_notify).find_each do |subscriber|
NotifySubscriber.new.perform(subscriber.id, submission.id)
end
end

desc "Set the updated at on historical caseworker versions"
Expand Down
6 changes: 0 additions & 6 deletions spec/factories/subscribers.rb

This file was deleted.

5 changes: 0 additions & 5 deletions spec/jobs/expire_sendbacks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

before do
submission.latest_version.update!(application: { resubmission_deadline: deadline })
allow(NotificationService).to receive(:call)
described_class.new.perform
end

Expand All @@ -21,10 +20,6 @@
it "creates an event" do
expect(submission.reload.events.first).to include("event_type" => "expiry")
end

it "updates subscribers" do
expect(NotificationService).to have_received(:call).with(submission, :app_store)
end
end

context "when an submission is not sent back" do
Expand Down
Loading

0 comments on commit aec1d0f

Please sign in to comment.