Permalink
Browse files

Allow specifying FIG_REMOTE_URL in ~/.figrc.

  • Loading branch information...
clonezone committed Jun 15, 2012
1 parent 9bf09a1 commit d0f48a9e5c8686c56151af9e74d2877ab2be0be0
View
@@ -1,5 +1,13 @@
v0.1.xxx
+ New features:
+
+ - Can specify the location of the remote repository via ~/.figrc or the value
+ of the --figrc parameter by specifying a value for "default
+ FIG_REMOTE_URL", e.g.
+
+ { "default FIG_REMOTE_URL" : "file:///some/path" }
+
Bug fixes:
- Warns on ignored --archive/--resource statements.
@@ -2,11 +2,11 @@ module Fig; end
# Configuration for the Fig program, as opposed to a config in a package.
class Fig::ApplicationConfiguration
- attr_reader :remote_repository_url
+ attr_accessor :base_whitelisted_url
+ attr_accessor :remote_repository_url
- def initialize(remote_repository_url)
+ def initialize()
@data = []
- @remote_repository_url = remote_repository_url
clear_cached_data
end
@@ -15,8 +15,12 @@ def ensure_url_whitelist_initialized()
whitelist = self['url whitelist']
if whitelist.nil?
@whitelist = []
+ elsif @base_whitelisted_url
+ @whitelist = [@base_whitelisted_url, whitelist].flatten
+ elsif whitelist.is_a? Array
+ @whitelist = whitelist
else
- @whitelist = [@remote_repository_url, whitelist].flatten
+ @whitelist = [whitelist]
end
end
@@ -33,8 +37,8 @@ def push_dataset(dataset)
@data.push(dataset)
end
- # after push_dataset or unshift_dataset, call clear_cached, and lazy
- # initialize as far as the list of things to exclude
+ # After push_dataset, call clear_cached, and lazy initialize as far as the
+ # list of things to exclude
def clear_cached_data()
@whitelist = nil
end
View
@@ -133,17 +133,6 @@ def initialize()
:package_source_description
)
- def derive_remote_url()
- if remote_operation_necessary?()
- if ENV['FIG_REMOTE_URL'].nil?
- raise Fig::UserInputError.new('Please define the FIG_REMOTE_URL environment variable.')
- end
- return ENV['FIG_REMOTE_URL']
- end
-
- return nil
- end
-
def check_include_statements_versions?()
return false if @options.suppress_warning_include_statement_missing_version?
@@ -186,12 +175,21 @@ def set_up_update_lock()
def set_up_application_configuration()
@application_configuration = Fig::FigRC.find(
@options.figrc(),
- derive_remote_url(),
+ ENV['FIG_REMOTE_URL'],
@options.login?,
@options.home(),
@options.no_figrc?
)
+ if \
+ remote_operation_necessary? \
+ && @application_configuration.remote_repository_url.nil?
+
+ raise Fig::UserInputError.new(
+ 'Please define the FIG_REMOTE_URL environment variable.'
+ )
+ end
+
return
end
View
@@ -14,12 +14,23 @@ class Fig::FigRC
"#{Fig::Repository::METADATA_SUBDIRECTORY}/figrc"
def self.find(
- override_path, repository_url, login, fig_home, disable_figrc = false
+ override_path,
+ specified_repository_url,
+ login,
+ fig_home,
+ disable_figrc = false
)
- configuration = Fig::ApplicationConfiguration.new(repository_url)
+ configuration = Fig::ApplicationConfiguration.new()
handle_override_configuration(configuration, override_path)
handle_figrc(configuration) if not disable_figrc
+
+ repository_url =
+ derive_repository_url(specified_repository_url, configuration)
+
+ configuration.base_whitelisted_url = repository_url
+ configuration.remote_repository_url = repository_url
+
handle_repository_configuration(
configuration, repository_url, login, fig_home
)
@@ -58,6 +69,12 @@ def self.handle_figrc(configuration)
return
end
+ def self.derive_repository_url(specified_repository_url, configuration)
+ return specified_repository_url if specified_repository_url
+
+ return configuration['default FIG_REMOTE_URL']
+ end
+
def self.handle_repository_configuration(
configuration, repository_url, login, fig_home
)
@@ -77,7 +94,7 @@ def self.handle_repository_configuration(
repo_config_exists = false
end
- return configuration if not repo_config_exists
+ return if not repo_config_exists
begin
configuration.push_dataset(
@@ -6,55 +6,64 @@
WHITELIST_TEST_URL = 'http://foo.com'
describe 'ApplicationConfiguration' do
+ def new_configuration()
+ config = Fig::ApplicationConfiguration.new
+
+ config.base_whitelisted_url = REPOSITORY_TEST_URL
+ config.remote_repository_url = REPOSITORY_TEST_URL
+
+ return config
+ end
+
it 'allows arbitrary urls when there is no whitelist' do
- config = Fig::ApplicationConfiguration.new(REPOSITORY_TEST_URL)
+ config = new_configuration
config.url_access_allowed?('').should == true
end
it 'allows the repo url when whitelist is empty' do
- config = Fig::ApplicationConfiguration.new(REPOSITORY_TEST_URL)
+ config = new_configuration
config.push_dataset({'url whitelist' => []})
config.url_access_allowed?(REPOSITORY_TEST_URL).should == true
end
it 'disallows a non-repo url when whitelist is empty' do
- config = Fig::ApplicationConfiguration.new(REPOSITORY_TEST_URL)
+ config = new_configuration
config.push_dataset({'url whitelist' => []})
config.url_access_allowed?('').should == false
end
it 'disallows a url that starts with a whitelisted url that is a hostname only' do
- config = Fig::ApplicationConfiguration.new(REPOSITORY_TEST_URL)
+ config = new_configuration
config.push_dataset({'url whitelist' => []})
config.url_access_allowed?(REPOSITORY_TEST_URL + 'x').should == false
end
it 'allows a full url with empty whitelist' do
- config = Fig::ApplicationConfiguration.new(REPOSITORY_TEST_URL)
+ config = new_configuration
config.push_dataset({'url whitelist' => []})
config.url_access_allowed?(REPOSITORY_TEST_URL + '/x').should == true
end
it 'allows a url when it\'s on the whitelist' do
- config = Fig::ApplicationConfiguration.new(REPOSITORY_TEST_URL)
+ config = new_configuration
config.push_dataset({'url whitelist' => [REPOSITORY_TEST_URL]})
config.url_access_allowed?(REPOSITORY_TEST_URL + '/x').should == true
end
it 'disallows a url when it\'s not on the whitelist' do
- config = Fig::ApplicationConfiguration.new(REPOSITORY_TEST_URL)
+ config = new_configuration
config.push_dataset({'url whitelist' => [WHITELIST_TEST_URL]})
config.url_access_allowed?('http://bar.com' + '/x').should == false
end
it 'disallows a non-repo url when whitelist is not empty' do
- config = Fig::ApplicationConfiguration.new(REPOSITORY_TEST_URL)
+ config = new_configuration
config.push_dataset({'url whitelist' => [WHITELIST_TEST_URL]})
config.url_access_allowed?('').should == false
end
it 'disallows a url with a different port (but the first part matches)' do
- config = Fig::ApplicationConfiguration.new(REPOSITORY_TEST_URL)
+ config = new_configuration
config.push_dataset({'url whitelist' => [WHITELIST_TEST_URL+':2000']})
config.url_access_allowed?(WHITELIST_TEST_URL+':20001').should == false
end
View
@@ -18,7 +18,7 @@
command.add_post_set_up_action(action)
command.run_fig(
- %w<--log-level off --set VARIABLE=VALUE --get VARIABLE>
+ %w<--log-level off --set VARIABLE=VALUE --get UNDEFINED_VARIABLE>
)
end
View
@@ -7,7 +7,8 @@
require 'fig/repository'
require 'fig/working_directory_maintainer'
-def create_override_file(foo, bar = nil)
+describe 'FigRC' do
+ def create_override_file(foo, bar = nil)
tempfile = Tempfile.new('some_json_tempfile')
tempfile << %Q< { "foo" : "#{foo}" >
if not bar.nil?
@@ -16,9 +17,16 @@ def create_override_file(foo, bar = nil)
tempfile << %Q< } >
tempfile.close
return tempfile
-end
+ end
+
+ def create_override_file_with_repository_url()
+ tempfile = Tempfile.new('some_json_tempfile')
+ tempfile << %Q< { "default FIG_REMOTE_URL" : "#{FIG_REMOTE_URL}" } >
+ tempfile.close
+ return tempfile
+ end
-def create_remote_config(foo, bar = nil)
+ def create_remote_config(foo, bar = nil)
FileUtils.mkdir_p(
File.join(FIG_REMOTE_DIR, Fig::Repository::METADATA_SUBDIRECTORY)
)
@@ -31,9 +39,8 @@ def create_remote_config(foo, bar = nil)
file_handle.write( %Q< } > )
file_handle.close
return
-end
+ end
-describe 'FigRC' do
before(:all) do
set_up_test_environment
end
@@ -46,41 +53,50 @@ def create_remote_config(foo, bar = nil)
tempfile = create_override_file('loaded as override')
create_remote_config("loaded from repository (shouldn't be)")
- configuration = Fig::FigRC.find(tempfile.path, ENV['FIG_REMOTE_URL'], true, ENV['FIG_HOME'], true)
+ configuration =
+ Fig::FigRC.find(tempfile.path, FIG_REMOTE_URL, true, FIG_HOME, true)
tempfile.unlink
configuration['foo'].should == 'loaded as override'
end
it 'handles no override, no repository (full stop)' do
- configuration = Fig::FigRC.find(nil, nil, true, ENV['FIG_HOME'], true)
+ configuration = Fig::FigRC.find(nil, nil, true, FIG_HOME, true)
configuration['foo'].should == nil
end
it 'handles no repository config and no override specified, and config does NOT exist on server' do
- configuration = Fig::FigRC.find(nil, %Q<file:///does_not_exist/>, true, ENV['FIG_HOME'], true)
+ configuration = Fig::FigRC.find(nil, %Q<file:///does_not_exist/>, true, FIG_HOME, true)
configuration['foo'].should == nil
end
it 'retrieves configuration from repository with no override' do
create_remote_config('loaded from repository')
- configuration = Fig::FigRC.find(nil, ENV['FIG_REMOTE_URL'], true, ENV['FIG_HOME'], true)
+ configuration = Fig::FigRC.find(nil, FIG_REMOTE_URL, true, FIG_HOME, true)
configuration['foo'].should == 'loaded from repository'
end
it 'has a remote config but gets its config from the override file provided' do
create_remote_config('loaded from remote repository')
tempfile = create_override_file('loaded as override to override remote config')
- configuration = Fig::FigRC.find(tempfile.path, ENV['FIG_REMOTE_URL'], true, ENV['FIG_HOME'], true)
+ configuration = Fig::FigRC.find(tempfile.path, FIG_REMOTE_URL, true, FIG_HOME, true)
configuration['foo'].should == 'loaded as override to override remote config'
end
it 'merges override file config over remote config' do
- create_remote_config('loaded from remote repository','should not be overwritten')
+ create_remote_config('loaded from remote repository', 'should not be overwritten')
tempfile = create_override_file('loaded as override to override remote config')
- configuration = Fig::FigRC.find(tempfile.path, ENV['FIG_REMOTE_URL'], true, ENV['FIG_HOME'], true)
+ configuration = Fig::FigRC.find(tempfile.path, FIG_REMOTE_URL, true, FIG_HOME, true)
configuration['foo'].should == 'loaded as override to override remote config'
configuration['bar'].should == 'should not be overwritten'
end
+
+ it 'retrieves configuration from repository specified by override file' do
+ tempfile = create_override_file_with_repository_url
+ create_remote_config('loaded from repository')
+
+ configuration = Fig::FigRC.find(tempfile, nil, true, FIG_HOME, true)
+ configuration['foo'].should == 'loaded from repository'
+ end
end
View
@@ -6,9 +6,17 @@
require 'fig/parser'
describe 'Parser' do
+ def new_configuration
+ application_configuration = Fig::ApplicationConfiguration.new
+
+ application_configuration.base_whitelisted_url = 'http://example/'
+ application_configuration.remote_repository_url = 'http://example/'
+
+ return application_configuration
+ end
+
def test_no_parse_exception(fig_input)
- application_configuration =
- Fig::ApplicationConfiguration.new('http://example/')
+ application_configuration = new_configuration
Fig::Parser.new(application_configuration, false).parse_package(
Fig::PackageDescriptor.new('package_name', '0.1.1', nil),
'foo_directory',
@@ -21,8 +29,7 @@ def test_no_parse_exception(fig_input)
end
def test_user_input_error(fig_input)
- application_configuration =
- Fig::ApplicationConfiguration.new('http://example/')
+ application_configuration = new_configuration
expect {
Fig::Parser.new(application_configuration, false).parse_package(
@@ -44,7 +51,7 @@ def test_user_input_error(fig_input)
this is invalid syntax
END
- application_configuration = Fig::ApplicationConfiguration.new('http://example/')
+ application_configuration = new_configuration
expect {
Fig::Parser.new(application_configuration, false).parse_package(
@@ -78,7 +85,7 @@ def test_user_input_error(fig_input)
end
FIG_PACKAGE
- application_configuration = Fig::ApplicationConfiguration.new(nil)
+ application_configuration = new_configuration
package = Fig::Parser.new(application_configuration, false).parse_package(
Fig::PackageDescriptor.new('package_name', 'version', nil),
'foo_directory',
@@ -117,7 +124,7 @@ def test_user_input_error(fig_input)
archive http://svpsvn/my/repo/is/cool.jar
FIG_PACKAGE
- application_configuration = Fig::ApplicationConfiguration.new('http://example/')
+ application_configuration = new_configuration
application_configuration.push_dataset( { 'url whitelist' => 'http://svpsvn/' } )
package = Fig::Parser.new(application_configuration, false).parse_package(
@@ -135,7 +142,7 @@ def test_user_input_error(fig_input)
archive http://evil_repo/my/repo/is/bad.jar
FIG_PACKAGE
- application_configuration = Fig::ApplicationConfiguration.new('http://example/')
+ application_configuration = new_configuration
application_configuration.push_dataset( { 'url whitelist' => 'http://svpsvn/' } )
exception = nil
Oops, something went wrong.

0 comments on commit d0f48a9

Please sign in to comment.