Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/activity_pub/inbox_resolver_service.rb')
-rw-r--r--app/services/activity_pub/inbox_resolver_service.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/app/services/activity_pub/inbox_resolver_service.rb b/app/services/activity_pub/inbox_resolver_service.rb
new file mode 100644
index 00000000000..c2bd2112b16
--- /dev/null
+++ b/app/services/activity_pub/inbox_resolver_service.rb
@@ -0,0 +1,50 @@
+# frozen_string_literal: true
+
+module ActivityPub
+ class InboxResolverService
+ attr_reader :subscription
+
+ def initialize(subscription)
+ @subscription = subscription
+ end
+
+ def execute
+ profile = subscriber_profile
+ unless profile.has_key?('inbox') && profile['inbox'].is_a?(String)
+ raise ThirdPartyError, 'Inbox parameter absent or invalid'
+ end
+
+ subscription.subscriber_inbox_url = profile['inbox']
+ subscription.shared_inbox_url = profile.dig('entrypoints', 'sharedInbox')
+ subscription.save!
+ end
+
+ private
+
+ def subscriber_profile
+ raw_data = download_subscriber_profile
+
+ begin
+ profile = Gitlab::Json.parse(raw_data)
+ rescue JSON::ParserError => e
+ raise ThirdPartyError, e.message
+ end
+
+ profile
+ end
+
+ def download_subscriber_profile
+ begin
+ response = Gitlab::HTTP.get(subscription.subscriber_url,
+ headers: {
+ 'Accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
+ }
+ )
+ rescue StandardError => e
+ raise ThirdPartyError, e.message
+ end
+
+ response.body
+ end
+ end
+end