Skip to content

Commit

Permalink
Merge pull request #457 from ualbertalib/fix/expired_auth_token
Browse files Browse the repository at this point in the history
Fix problem with authentication token expiration
  • Loading branch information
lagoan authored Jul 17, 2024
2 parents cfe02af + 134d28b commit 4d39b5a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ PushmiPullyu is a Ruby application, whose primary job is to manage the flow of c
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and releases in PushmiPullyu adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
- Refresh authentication token after it expires [#311](https://github.com/ualbertalib/pushmi_pullyu/issues/311)

## [2.1.2]
- Simplify get entity code [#280](https://github.com/ualbertalib/pushmi_pullyu/issues/280)

Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ services:
# swift auth -v -U test:tester -K testing -A http://localhost:8080/auth/v1.0
# swift auth
# swift post ERA
image: openstackswift/saio
# image: openstackswift/saio
# The previously used image was getting connection problems
image: openstackswift/saio:change_846891_latest
ports:
- '8080:8080'
13 changes: 6 additions & 7 deletions lib/pushmi_pullyu/swift_depositer.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
require 'digest/md5'
require 'openstack'

class PushmiPullyu::SwiftDepositer

attr_reader :swift_connection

def initialize(connection)
# Generic authentication parameters
swift_connection_parameters = {
Expand All @@ -13,7 +10,11 @@ def initialize(connection)
auth_url: connection[:auth_url],
project_name: connection[:project_name],
auth_method: 'password',
service_type: 'object-store'
service_type: 'object-store',
# The retry_auth value should be true by default. It is currently set
# to nil which causes the connection to die without giving more error
# details.
retry_auth: true
}

if connection[:auth_version] == 'v3'
Expand All @@ -28,10 +29,8 @@ def initialize(connection)

def deposit_file(file_name, swift_container)
file_base_name = File.basename(file_name, '.*')

checksum = Digest::MD5.file(file_name).hexdigest

era_container = swift_connection.container(swift_container)
era_container = @swift_connection.container(swift_container)

# Add swift metadata with in accordance to AIP spec:
# https://docs.google.com/document/d/154BqhDPAdGW-I9enrqLpBYbhkF9exX9lV3kMaijuwPg/edit#
Expand Down
16 changes: 14 additions & 2 deletions spec/pushmi_pullyu/swift_depositer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

expect(first_deposit.name).to eq(second_deposit.name)
expect(first_deposit.container.name).to eq(second_deposit.container.name)
end.to change { swift_depositer.swift_connection.container('ERA').count.to_i }.by(1)
end.to change { swift_depositer.instance_variable_get('@swift_connection').container('ERA').count.to_i }.by(1)
end
end

Expand All @@ -59,9 +59,21 @@
)
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')
expect(swift_depositer.instance_variable_get('@swift_connection').connection.authtoken).to eq('gAAAAABl8hYAouKZJLkt8NDmuA2NjA1zOasGOAX-b2MfKpjiM_kf8sZHe42ipcs6Vb-57-aATajbTg54wIwhNhl2HKRfz5_rKfSJ0PnBQNFCVd4bKrdC0pHzoJMn9hkAa2tjBkqppBcMayvfqz-Ppxn0USnHw0z9zLLKDxGbRZwyhDJDhGOcIZg')
# rubocop:enable Layout/LineLength
end
end

it 'uses ruby-openstack gem behaviour to refresh authentication token' do
VCR.use_cassette('swift_new_deposit') do
swift_depositer = PushmiPullyu::SwiftDepositer.new(username: 'test:tester',
password: 'testing',
tenant: 'tester',
auth_url: 'http://127.0.0.1:8080/auth/v1.0',
retry_auth: true)

expect(swift_depositer.inspect).to include '@retry_auth=true' # retry_auth isn't exposed
end
end
end
end

0 comments on commit 4d39b5a

Please sign in to comment.