Skip to content

Commit

Permalink
Merge pull request #422 from ualbertalib/add/olrc_destination
Browse files Browse the repository at this point in the history
Add support for V3 authentication for Swift
  • Loading branch information
lagoan authored May 13, 2024
2 parents cdc5b40 + 788cb33 commit 55d65ac
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and releases in PushmiPullyu adheres to [Semantic Versioning](https://semver.org

## [Unreleased]

- Add logic to perform authentication against the V3 Auth protocol

## [2.0.7] - 2023-09-13

- Fix nil exception [#314](https://github.com/ualbertalib/pushmi_pullyu/issues/314)
Expand Down
5 changes: 4 additions & 1 deletion examples/pushmi_pullyu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ swift:
auth_url: http://localhost:8080/auth/v1.0
project_name: demo
project_domain_name: default
container: ERA
container: era
# These 2 extra parameters are now required for keystone v3 authentication
auth_version: v3
user_domain: default

rollbar:
token: 'abc123xyz'
Expand Down
4 changes: 3 additions & 1 deletion lib/pushmi_pullyu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ module PushmiPullyu
auth_url: 'http://localhost:8080/auth/v1.0',
project_name: 'demo',
project_domain_name: 'default',
container: 'ERA'
container: 'era',
auth_version: 'v3',
user_domain: 'default'
},
rollbar: {},
# rubocop disable: Style/FetchEnvVar
Expand Down
6 changes: 4 additions & 2 deletions lib/pushmi_pullyu/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,12 @@ def queue
def swift
@swift ||= PushmiPullyu::SwiftDepositer.new(username: options[:swift][:username],
password: options[:swift][:password],
tenant: options[:swift][:tenant],
project_name: options[:swift][:project_name],
tenant: options[:swift][:tenant],
project_domain_name: options[:swift][:project_domain_name],
auth_url: options[:swift][:auth_url])
user_domain: options[:swift][:user_domain],
auth_url: options[:swift][:auth_url],
auth_version: options[:swift][:auth_version])
end

# On first call of shutdown, this will gracefully close the main run loop
Expand Down
18 changes: 13 additions & 5 deletions lib/pushmi_pullyu/swift_depositer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@ class PushmiPullyu::SwiftDepositer
attr_reader :swift_connection

def initialize(connection)
@swift_connection = OpenStack::Connection.create(
# Generic authentication parameters
swift_connection_parameters = {
username: connection[:username],
api_key: connection[:password],
auth_method: 'password',
auth_url: connection[:auth_url],
project_name: connection[:project_name],
project_domain_name: connection[:project_domain_name],
authtenant_name: connection[:tenant],
auth_method: 'password',
service_type: 'object-store'
)
}

if connection[:auth_version] == 'v3'
swift_connection_parameters[:user_domain] = connection[:user_domain]
elsif connection[:auth_version] == 'v1'
swift_connection_parameters[:project_domain_name] = connection[:project_domain_name]
swift_connection_parameters[:authtenant_name] = connection[:tenant]
end

@swift_connection = OpenStack::Connection.create(swift_connection_parameters)
end

def deposit_file(file_name, swift_container)
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ rollbar:
proxy_port: '80'
swift:
auth_url: http://127.0.0.1:8080/auth/v1.0
auth_version: 'v1'
container: 'ERA'
jupiter:
user: '[email protected]'
api_key: '3eeb395e-63b7-11ea-bc55-0242ac130003'
20 changes: 20 additions & 0 deletions spec/pushmi_pullyu/swift_depositer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,25 @@
end.to change { swift_depositer.swift_connection.container('ERA').count.to_i }.by(1)
end
end

it 'authenticates against v3' do
VCR.use_cassette('swift_auth_v3') do
swift_depositer = PushmiPullyu::SwiftDepositer.new(
username: 'era_olrc_user',
password: 'era_olrc_user_password',
auth_url: 'https://olrc2auth.scholarsportal.info/v3/',
user_domain: 'alberta',
container: 'era',
project_name: 'demo',
auth_method: 'password',
service_type: 'object-store',
auth_version: 'v3'
)
expect(swift_depositer).not_to be_nil
# rubocop:disable Layout/LineLength
expect(swift_depositer.swift_connection.connection.authtoken).to eq('gAAAAABl8hYAouKZJLkt8NDmuA2NjA1zOasGOAX-b2MfKpjiM_kf8sZHe42ipcs6Vb-57-aATajbTg54wIwhNhl2HKRfz5_rKfSJ0PnBQNFCVd4bKrdC0pHzoJMn9hkAa2tjBkqppBcMayvfqz-Ppxn0USnHw0z9zLLKDxGbRZwyhDJDhGOcIZg')
# rubocop:enable Layout/LineLength
end
end
end
end
66 changes: 66 additions & 0 deletions spec/support/http_cache/vcr/swift_auth_v3.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 55d65ac

Please sign in to comment.