Skip to content

Commit f3f16b9

Browse files
committed
feat(indico-ingestor): API token auth
1 parent 5979514 commit f3f16b9

3 files changed

Lines changed: 6 additions & 2 deletions

File tree

config/secrets.example.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ external_api_keys: &external_api_keys
3838
password:
3939
gpt_api_key:
4040
willma_api_key:
41+
indico_api_token: # begins by 'indp_', cf. https://docs.getindico.io/en/stable/http-api/access/#api-token-authentication
4142

4243
#Internal config
4344
development:

lib/ingestors/ical_ingestor.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def self.config
1919
end
2020

2121
def read(source_url)
22+
@token << Rails.application.config.secrets.indico_api_token
2223
@verbose = false
2324
sources = get_sources(source_url)
2425
return if sources.nil?
@@ -35,7 +36,8 @@ def read(source_url)
3536
# Note: One .ics file can have multiple Ical events.
3637
def process_url(url)
3738
export_url = to_export(url)
38-
events = Icalendar::Event.parse(open_url(export_url, raise: true).set_encoding('utf-8'))
39+
content = open_url(export_url, token: @token, raise: true).set_encoding('utf-8')
40+
events = Icalendar::Event.parse(content)
3941
raise 'Not found' if events.nil? || events.empty?
4042

4143
events.each do |e|

lib/ingestors/ingestor.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,14 @@ def stats_summary(type)
5050
summary
5151
end
5252

53-
def open_url(url, raise: false)
53+
def open_url(url, token: '', raise: false)
5454
options = {
5555
redirect: false, # We're doing redirects manually below, since open-uri can't handle http -> https redirection
5656
read_timeout: 5
5757
}
5858
options[:ssl_verify_mode] = config[:ssl_verify_mode] if config.key?(:ssl_verify_mode)
5959
redirect_attempts = 5
60+
options['Authorization'] = "Bearer #{token}" if token
6061
begin
6162
URI(url).open(options)
6263
rescue OpenURI::HTTPRedirect => e

0 commit comments

Comments
 (0)