brightbox-cli 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +18 -0
- data/Gemfile.lock +18 -19
- data/bin/_brightbox-bash-completer +42 -0
- data/brightbox-cli.gemspec +5 -5
- data/lib/brightbox-cli/accounts.rb +1 -3
- data/lib/brightbox-cli/api.rb +27 -8
- data/lib/brightbox-cli/cloud_ips.rb +11 -15
- data/lib/brightbox-cli/collaborating_account.rb +23 -26
- data/lib/brightbox-cli/collaboration.rb +1 -1
- data/lib/brightbox-cli/commands/{accounts-accept-invite.rb → accounts/accept-invite.rb} +2 -3
- data/lib/brightbox-cli/commands/{accounts-default.rb → accounts/default.rb} +1 -3
- data/lib/brightbox-cli/commands/{accounts-list.rb → accounts/list.rb} +1 -1
- data/lib/brightbox-cli/commands/{accounts-remove.rb → accounts/remove.rb} +1 -2
- data/lib/brightbox-cli/commands/{accounts-reset-ftp-password.rb → accounts/reset-ftp-password.rb} +10 -5
- data/lib/brightbox-cli/commands/{accounts-show.rb → accounts/show.rb} +14 -6
- data/lib/brightbox-cli/commands/{cloudips-create.rb → cloudips/create.rb} +4 -4
- data/lib/brightbox-cli/commands/{cloudips-destroy.rb → cloudips/destroy.rb} +1 -1
- data/lib/brightbox-cli/commands/{cloudips-list.rb → cloudips/list.rb} +2 -10
- data/lib/brightbox-cli/commands/{cloudips-map.rb → cloudips/map.rb} +2 -8
- data/lib/brightbox-cli/commands/{cloudips-show.rb → cloudips/show.rb} +13 -3
- data/lib/brightbox-cli/commands/{cloudips-unmap.rb → cloudips/unmap.rb} +1 -1
- data/lib/brightbox-cli/commands/{cloudips-update.rb → cloudips/update.rb} +5 -6
- data/lib/brightbox-cli/commands/collaborations.rb +3 -9
- data/lib/brightbox-cli/commands/{config-client-add.rb → config/client-add.rb} +2 -2
- data/lib/brightbox-cli/commands/{config-client-default.rb → config/client-default.rb} +1 -1
- data/lib/brightbox-cli/commands/{config-client-list.rb → config/client-list.rb} +3 -3
- data/lib/brightbox-cli/commands/{config-client-remove.rb → config/client-remove.rb} +4 -1
- data/lib/brightbox-cli/commands/{config-user-add.rb → config/user-add.rb} +1 -1
- data/lib/brightbox-cli/commands/{firewall-policies-apply.rb → firewall/policies-apply.rb} +3 -4
- data/lib/brightbox-cli/commands/{firewall-policies-create.rb → firewall/policies-create.rb} +3 -4
- data/lib/brightbox-cli/commands/{firewall-policies-destroy.rb → firewall/policies-destroy.rb} +2 -3
- data/lib/brightbox-cli/commands/{firewall-policies-list.rb → firewall/policies-list.rb} +2 -9
- data/lib/brightbox-cli/commands/{firewall-policies-remove.rb → firewall/policies-remove.rb} +2 -3
- data/lib/brightbox-cli/commands/{firewall-policies-show.rb → firewall/policies-show.rb} +11 -3
- data/lib/brightbox-cli/commands/{firewall-policies-update.rb → firewall/policies-update.rb} +3 -3
- data/lib/brightbox-cli/commands/{firewall-rules-create.rb → firewall/rules-create.rb} +4 -4
- data/lib/brightbox-cli/commands/{firewall-rules-destroy.rb → firewall/rules-destroy.rb} +2 -4
- data/lib/brightbox-cli/commands/{firewall-rules-list.rb → firewall/rules-list.rb} +2 -2
- data/lib/brightbox-cli/commands/{firewall-rules-show.rb → firewall/rules-show.rb} +10 -4
- data/lib/brightbox-cli/commands/{firewall-rules-update.rb → firewall/rules-update.rb} +3 -3
- data/lib/brightbox-cli/commands/{groups-add-server.rb → groups/add-server.rb} +2 -2
- data/lib/brightbox-cli/commands/{groups-create.rb → groups/create.rb} +3 -3
- data/lib/brightbox-cli/commands/{groups-destroy.rb → groups/destroy.rb} +2 -2
- data/lib/brightbox-cli/commands/groups/list.rb +14 -0
- data/lib/brightbox-cli/commands/{groups-move_servers.rb → groups/move_servers.rb} +1 -2
- data/lib/brightbox-cli/commands/{groups-remove-servers.rb → groups/remove-servers.rb} +1 -1
- data/lib/brightbox-cli/commands/{groups-show.rb → groups/show.rb} +1 -1
- data/lib/brightbox-cli/commands/{groups-update.rb → groups/update.rb} +5 -10
- data/lib/brightbox-cli/commands/{images-destroy.rb → images/destroy.rb} +2 -2
- data/lib/brightbox-cli/commands/{images-list.rb → images/list.rb} +2 -10
- data/lib/brightbox-cli/commands/{images-register.rb → images/register.rb} +6 -6
- data/lib/brightbox-cli/commands/{images-show.rb → images/show.rb} +2 -11
- data/lib/brightbox-cli/commands/{images-update.rb → images/update.rb} +8 -8
- data/lib/brightbox-cli/commands/{lbs-add-nodes.rb → lbs/add-nodes.rb} +2 -2
- data/lib/brightbox-cli/commands/{lbs-create.rb → lbs/create.rb} +16 -10
- data/lib/brightbox-cli/commands/{lbs-destroy.rb → lbs/destroy.rb} +1 -1
- data/lib/brightbox-cli/commands/{lbs-list.rb → lbs/list.rb} +2 -10
- data/lib/brightbox-cli/commands/{lbs-remove-nodes.rb → lbs/remove-nodes.rb} +2 -2
- data/lib/brightbox-cli/commands/{lbs-show.rb → lbs/show.rb} +4 -7
- data/lib/brightbox-cli/commands/{lbs-update.rb → lbs/update.rb} +16 -10
- data/lib/brightbox-cli/commands/{servers-activate-console.rb → servers/activate-console.rb} +3 -3
- data/lib/brightbox-cli/commands/{servers-create.rb → servers/create.rb} +4 -4
- data/lib/brightbox-cli/commands/{servers-destroy.rb → servers/destroy.rb} +2 -2
- data/lib/brightbox-cli/commands/{servers-list.rb → servers/list.rb} +7 -8
- data/lib/brightbox-cli/commands/{servers-show.rb → servers/show.rb} +1 -6
- data/lib/brightbox-cli/commands/{servers-shutdown.rb → servers/shutdown.rb} +1 -1
- data/lib/brightbox-cli/commands/{servers-snapshot.rb → servers/snapshot.rb} +1 -1
- data/lib/brightbox-cli/commands/{servers-start.rb → servers/start.rb} +1 -1
- data/lib/brightbox-cli/commands/{servers-stop.rb → servers/stop.rb} +1 -1
- data/lib/brightbox-cli/commands/{servers-update.rb → servers/update.rb} +2 -2
- data/lib/brightbox-cli/commands/sql/instances_create.rb +66 -0
- data/lib/brightbox-cli/commands/sql/instances_destroy.rb +28 -0
- data/lib/brightbox-cli/commands/sql/instances_list.rb +27 -0
- data/lib/brightbox-cli/commands/sql/instances_reset_password.rb +33 -0
- data/lib/brightbox-cli/commands/sql/instances_show.rb +26 -0
- data/lib/brightbox-cli/commands/sql/instances_snapshot.rb +25 -0
- data/lib/brightbox-cli/commands/sql/instances_update.rb +45 -0
- data/lib/brightbox-cli/commands/sql/snapshots_destroy.rb +31 -0
- data/lib/brightbox-cli/commands/sql/snapshots_list.rb +25 -0
- data/lib/brightbox-cli/commands/sql/snapshots_show.rb +26 -0
- data/lib/brightbox-cli/commands/sql/snapshots_update.rb +37 -0
- data/lib/brightbox-cli/commands/sql/types.rb +53 -0
- data/lib/brightbox-cli/commands/types.rb +1 -1
- data/lib/brightbox-cli/commands/users/list.rb +17 -0
- data/lib/brightbox-cli/commands/{users-show.rb → users/show.rb} +5 -13
- data/lib/brightbox-cli/commands/{users-update.rb → users/update.rb} +3 -3
- data/lib/brightbox-cli/config.rb +4 -7
- data/lib/brightbox-cli/config/accounts.rb +3 -6
- data/lib/brightbox-cli/config/api_client.rb +12 -4
- data/lib/brightbox-cli/config/authentication_tokens.rb +8 -14
- data/lib/brightbox-cli/config/clients.rb +6 -7
- data/lib/brightbox-cli/config/section_name_deduplicator.rb +4 -5
- data/lib/brightbox-cli/config/sections.rb +7 -10
- data/lib/brightbox-cli/config/user_application.rb +15 -7
- data/lib/brightbox-cli/connection_manager.rb +1 -2
- data/lib/brightbox-cli/database_server.rb +100 -0
- data/lib/brightbox-cli/database_snapshot.rb +36 -0
- data/lib/brightbox-cli/database_type.rb +44 -0
- data/lib/brightbox-cli/detailed_server.rb +8 -7
- data/lib/brightbox-cli/error_parser.rb +8 -4
- data/lib/brightbox-cli/firewall_rule.rb +5 -5
- data/lib/brightbox-cli/firewall_rules.rb +2 -3
- data/lib/brightbox-cli/gli_global_hooks.rb +7 -7
- data/lib/brightbox-cli/images.rb +13 -14
- data/lib/brightbox-cli/legacy/args_adjuster.rb +5 -6
- data/lib/brightbox-cli/load_balancers.rb +10 -13
- data/lib/brightbox-cli/logging.rb +3 -3
- data/lib/brightbox-cli/nilable_hash.rb +1 -1
- data/lib/brightbox-cli/ruby_core_ext.rb +1 -2
- data/lib/brightbox-cli/server_groups.rb +5 -5
- data/lib/brightbox-cli/servers.rb +9 -9
- data/lib/brightbox-cli/tables.rb +24 -25
- data/lib/brightbox-cli/types.rb +6 -5
- data/lib/brightbox-cli/user_collaboration.rb +2 -3
- data/lib/brightbox-cli/users.rb +3 -3
- data/lib/brightbox-cli/version.rb +1 -1
- data/lib/brightbox_cli.rb +10 -2
- data/locales/en.yml +205 -0
- data/spec/cassettes/Brightbox_Account/_all/when_connected_using_an_application/returns_a_collection_of_Accounts.yml +10 -10
- data/spec/cassettes/Brightbox_Account/_all/when_connected_using_an_application/returns_resources_on_the_same_connection.yml +4 -4
- data/spec/cassettes/Brightbox_Account/_all/when_connected_using_an_client/returns_a_collection_of_Accounts.yml +8 -8
- data/spec/cassettes/Brightbox_Account/_all/when_connected_using_an_client/returns_resources_on_the_same_connection.yml +4 -4
- data/spec/cassettes/Brightbox_BBConfig/_add_section/when_first_and_only_client/saves_changes_to_the_config_file.yml +4 -4
- data/spec/cassettes/Brightbox_BBConfig/_add_section/when_first_and_only_client/saves_the_default_account.yml +4 -4
- data/spec/cassettes/Brightbox_BBConfig/_add_section/when_first_and_only_client/saves_the_new_client_as_the_default.yml +4 -4
- data/spec/cassettes/Brightbox_BBConfig/_find_or_set_default_account/when_client_is_not_authenticated/does_not_raise_an_error.yml +176 -176
- data/spec/cassettes/Brightbox_BBConfig/_find_or_set_default_account/when_client_may_access_one_account/updates_the_setting.yml +176 -176
- data/spec/cassettes/Brightbox_BBConfig/_renew_tokens/when_config_in_use_is_not_the_default/uses_correct_credentials.yml +2 -2
- data/spec/cassettes/Brightbox_BBConfig/_renew_tokens/when_using_a_user_app_with_a_cached_refresh_token/caches_the_new_tokens.yml +2 -2
- data/spec/cassettes/Brightbox_BBConfig/_renew_tokens/when_using_a_user_app_with_an_expired_refresh_token/caches_the_new_tokens.yml +4 -4
- data/spec/cassettes/Brightbox_BBConfig/_renew_tokens/when_using_a_user_app_with_no_tokens/caches_the_new_tokens.yml +2 -2
- data/spec/cassettes/Brightbox_BBConfig/_renew_tokens/when_using_a_user_app_with_no_tokens/prompts_user_to_retry_command.yml +2 -2
- data/spec/cassettes/Brightbox_BBConfig/_renew_tokens/when_using_an_API_client_with_no_tokens/caches_a_new_access_token.yml +2 -2
- data/spec/cassettes/Brightbox_CloudIP/_find_all_/when_a_Cloud_IP_exists/returns_a_suitable.yml +28 -28
- data/spec/cassettes/Brightbox_FirewallPolicy/_apply_to/should_apply_firewall_policy.yml +24 -24
- data/spec/cassettes/Brightbox_FirewallPolicy/_create/should_create_firewall_policy.yml +24 -24
- data/spec/cassettes/Brightbox_FirewallPolicy/_destroy/should_destroy_firewall_policy.yml +28 -28
- data/spec/cassettes/Brightbox_FirewallPolicy/_find_all_/when_a_policy_exists/should_list_firewall_policy.yml +24 -24
- data/spec/cassettes/Brightbox_FirewallPolicy/_find_or_call/when_a_policy_exists/should_show_firewall_policy.yml +20 -20
- data/spec/cassettes/Brightbox_FirewallRule/_create/when_policy_exists/creates_the_rule_successfully.yml +24 -24
- data/spec/cassettes/Brightbox_FirewallRule/_destroy/when_rule_exists/destroys_a_rule.yml +20 -20
- data/spec/cassettes/Brightbox_FirewallRule/_find/when_rule_exists/can_display_the_result.yml +24 -24
- data/spec/cassettes/Brightbox_FirewallRule/_from_policy/when_policy_exists_with_a_rule/lists_all_rules.yml +32 -32
- data/spec/cassettes/Brightbox_Server/_destroy/when_server_exists/should_work.yml +20 -20
- data/spec/cassettes/Brightbox_Server/_find_all_/when_a_server_exists/should_print_server_list.yml +28 -28
- data/spec/cassettes/Brightbox_Server/_show/when_server_exists/shows_detailed_attributes_of_a_server.yml +32 -32
- data/spec/cassettes/Brightbox_Server/_shutdown/should_work.yml +32 -32
- data/spec/cassettes/Brightbox_Server/_start/should_work.yml +44 -44
- data/spec/cassettes/Brightbox_Server/_stop/should_work.yml +32 -32
- data/spec/cassettes/Brightbox_Server/_update/when_passing_new_group_membership/should_update_with_group.yml +40 -40
- data/spec/cassettes/Brightbox_ServerGroup/_find_all_/when_a_group_exists/list_server_groups.yml +24 -24
- data/spec/cassettes/Firewall_policies/update/when_the_policy_does_not_exist/prints_error_to_STDERR.yml +6 -6
- data/spec/cassettes/brightbox_accounts/list/_when_access_token_expired_/does_not_report_invalid_token_errors.yml +18 -18
- data/spec/cassettes/brightbox_accounts/list/_when_both_tokens_expired_/does_not_report_invalid_token_errors.yml +18 -18
- data/spec/cassettes/brightbox_accounts/list/_when_invalid_tokens_/does_not_report_invalid_token_errors.yml +18 -18
- data/spec/cassettes/brightbox_accounts/list/_when_no_tokens_/does_not_report_invalid_token_errors.yml +16 -16
- data/spec/cassettes/brightbox_accounts/list/_when_no_tokens_/reports_they_were_updated.yml +14 -14
- data/spec/cassettes/brightbox_accounts/list/_when_no_tokens_and_password_incorrect_/does_not_report_invalid_token_errors.yml +14 -14
- data/spec/cassettes/brightbox_accounts/list/_when_no_tokens_and_password_incorrect_/reports_unable_to_authenticate.yml +12 -12
- data/spec/cassettes/brightbox_accounts/list/does_not_error.yml +6 -6
- data/spec/cassettes/brightbox_cloudips/map/when_destination_is_a_server_ID/passes_the_interface_identifier_to_the_API.yml +542 -0
- data/spec/cassettes/brightbox_cloudips/map/when_destination_is_another_value/passes_the_identifier_to_the_API.yml +317 -0
- data/spec/cassettes/brightbox_config/client_add/when_adding_a_new_client/does_not_error.yml +154 -154
- data/spec/cassettes/brightbox_config/client_add/when_adding_a_new_client/sets_up_the_config.yml +154 -154
- data/spec/cassettes/brightbox_config/client_add/when_new_client_is_first_and_only_client/does_not_change_the_default_client.yml +154 -154
- data/spec/cassettes/brightbox_config/client_add/when_new_client_is_first_and_only_client/does_not_error.yml +154 -154
- data/spec/cassettes/brightbox_config/client_add/when_new_client_is_first_and_only_client/sets_this_as_the_default_client.yml +154 -154
- data/spec/cassettes/brightbox_config/client_add/when_new_client_is_first_and_only_client/sets_up_the_config.yml +154 -154
- data/spec/cassettes/brightbox_config/user_add/when_NO_config_file_on_disk/sets_up_the_config.yml +10 -10
- data/spec/cassettes/brightbox_config/user_add/when_a_default_client_is_already_set/does_not_change_the_default_client.yml +4 -4
- data/spec/cassettes/brightbox_config/user_add/when_application_details_in_config/does_not_error.yml +4 -4
- data/spec/cassettes/brightbox_config/user_add/when_application_details_in_config/sets_up_the_config.yml +4 -4
- data/spec/cassettes/brightbox_config/user_add/when_application_has_access_only_one_active_account/display_an_warning_about_preselected_default.yml +4 -4
- data/spec/cassettes/brightbox_config/user_add/when_application_has_access_only_one_active_account/does_not_error.yml +4 -4
- data/spec/cassettes/brightbox_config/user_add/when_application_has_access_only_one_active_account/selects_the_active_account_for_the_default.yml +4 -4
- data/spec/cassettes/brightbox_config/user_add/when_application_has_access_only_one_active_account/sets_up_the_config.yml +4 -4
- data/spec/cassettes/brightbox_config/user_add/when_application_has_access_to_multiple_accounts/display_an_warning_about_preselected_default.yml +4 -4
- data/spec/cassettes/brightbox_config/user_add/when_application_has_access_to_multiple_accounts/does_not_error.yml +4 -4
- data/spec/cassettes/brightbox_config/user_add/when_application_has_access_to_multiple_accounts/sets_up_the_config.yml +4 -4
- data/spec/cassettes/brightbox_config/user_add/when_new_client_is_first_and_only_client/does_not_error.yml +4 -4
- data/spec/cassettes/brightbox_config/user_add/when_new_client_is_first_and_only_client/does_not_prompt_to_rerun_the_command.yml +4 -4
- data/spec/cassettes/brightbox_config/user_add/when_new_client_is_first_and_only_client/requests_access_tokens.yml +4 -4
- data/spec/cassettes/brightbox_config/user_add/when_new_client_is_first_and_only_client/sets_this_as_the_default_client.yml +4 -4
- data/spec/cassettes/brightbox_config/user_add/when_new_client_is_first_and_only_client/sets_up_the_config.yml +10 -10
- data/spec/cassettes/brightbox_config/user_add/when_passing_in_required_arguments/does_not_error.yml +4 -4
- data/spec/cassettes/brightbox_config/user_add/when_passing_in_required_arguments/does_not_prompt_to_rerun_the_command.yml +4 -4
- data/spec/cassettes/brightbox_config/user_add/when_passing_in_required_arguments/requests_access_tokens.yml +4 -4
- data/spec/cassettes/brightbox_config/user_add/when_passing_in_required_arguments/sets_up_the_config.yml +6 -6
- data/spec/cassettes/brightbox_config/user_add/when_passing_in_required_arguments_and_api_url/does_not_error.yml +4 -4
- data/spec/cassettes/brightbox_config/user_add/when_passing_in_required_arguments_and_api_url/requests_access_tokens.yml +4 -4
- data/spec/cassettes/brightbox_config/user_add/when_passing_in_required_arguments_and_api_url/sets_up_the_config.yml +4 -4
- data/spec/cassettes/brightbox_database-servers/create/--allow-access_10_0_0_0/correctly_sends_API_parameters.yml +93 -0
- data/spec/cassettes/brightbox_database-servers/create/--allow-access_srv-12345_grp-12345/correctly_sends_API_parameters.yml +93 -0
- data/spec/cassettes/brightbox_database-servers/create/--engine_mysql/correctly_sends_API_parameters.yml +93 -0
- data/spec/cassettes/brightbox_database-servers/create/--engine_mysql_--engine-version_5_6/correctly_sends_API_parameters.yml +93 -0
- data/spec/cassettes/brightbox_database-servers/create/without_arguments/reports_the_new_admin_password.yml +93 -0
- data/spec/cassettes/brightbox_database-servers/create/without_arguments/reports_the_new_admin_username.yml +93 -0
- data/spec/cassettes/brightbox_database-servers/snapshot/when_database_server_active/correctly_sends_API_parameters.yml +181 -0
- data/spec/cassettes/brightbox_database-servers/snapshot/when_database_server_can_not_be_snapshotted/reports_an_error_to_the_user.yml +91 -0
- data/spec/cassettes/brightbox_database-snapshots/list/when_resources_are_available/does_not_output_to_stderr.yml +93 -0
- data/spec/cassettes/brightbox_database-snapshots/list/when_resources_are_available/outputs_table_details_to_stdout.yml +93 -0
- data/spec/cassettes/brightbox_database-snapshots/show/when_resource_exists/does_not_output_to_stderr.yml +93 -0
- data/spec/commands/accounts/list_spec.rb +1 -1
- data/spec/commands/cloudips/map_spec.rb +23 -4
- data/spec/commands/config/user_add_spec.rb +1 -1
- data/spec/commands/sql/instances/create_spec.rb +69 -0
- data/spec/commands/sql/instances/snapshot_spec.rb +36 -0
- data/spec/commands/sql/snapshots/list_spec.rb +29 -0
- data/spec/commands/sql/snapshots/show_spec.rb +29 -0
- data/spec/commands/sql/types/list_spec.rb +18 -0
- data/spec/spec_helper.rb +1 -3
- data/spec/support/vcr.rb +1 -1
- data/spec/unit/brightbox/api/conn_spec.rb +1 -1
- data/spec/unit/brightbox/bb_config/add_section_spec.rb +1 -1
- data/spec/unit/brightbox/bb_config/renew_tokens_spec.rb +1 -1
- data/spec/unit/brightbox/database_server_spec.rb +9 -0
- data/spec/unit/brightbox/database_snapshot_spec.rb +9 -0
- data/spec/unit/brightbox/database_type_spec.rb +9 -0
- data/spec/unit/brightbox/firewall_policy/create_spec.rb +1 -1
- data/spec/unit/brightbox/firewall_policy/destroy_spec.rb +1 -1
- data/spec/unit/brightbox/firewall_rule/create_spec.rb +1 -1
- data/spec/unit/brightbox/firewall_rule/destroy_spec.rb +1 -1
- data/spec/unit/brightbox/firewall_rule/find_spec.rb +1 -1
- data/spec/unit/brightbox/firewall_rule/from_policy_spec.rb +1 -1
- data/spec/unit/brightbox/server/destroy_spec.rb +1 -1
- data/spec/unit/brightbox/server/find_or_call_spec.rb +1 -1
- data/spec/unit/brightbox/server/shutdown_spec.rb +1 -1
- data/spec/unit/brightbox/server/start_spec.rb +1 -1
- data/spec/unit/brightbox/server/stop_spec.rb +1 -1
- data/spec/unit/brightbox/server/update_spec.rb +1 -1
- data/spec/unit/brightbox/server_group/find_spec.rb +1 -1
- data/spec/unit/brightbox/user_collaboration/get_for_account_spec.rb +3 -3
- metadata +160 -115
- data/lib/brightbox-cli/commands/groups-list.rb +0 -21
- data/lib/brightbox-cli/commands/users-list.rb +0 -25
data/lib/brightbox-cli/config.rb
CHANGED
@@ -69,9 +69,7 @@ module Brightbox
|
|
69
69
|
return @config_file if @config_file
|
70
70
|
return {} if @config_file == false
|
71
71
|
|
72
|
-
unless config_directory_exists?
|
73
|
-
create_directory
|
74
|
-
end
|
72
|
+
create_directory unless config_directory_exists?
|
75
73
|
|
76
74
|
@config_file ||= Ini.new(config_filename)
|
77
75
|
@config_file
|
@@ -79,7 +77,6 @@ module Brightbox
|
|
79
77
|
raise BBConfigError, "Config problem in #{config_filename}: #{e}"
|
80
78
|
end
|
81
79
|
|
82
|
-
|
83
80
|
# Write out the configuration file to disk
|
84
81
|
def save
|
85
82
|
if dirty? && config.respond_to?(:write)
|
@@ -111,14 +108,14 @@ module Brightbox
|
|
111
108
|
config["core"][key] = value
|
112
109
|
end
|
113
110
|
|
114
|
-
|
111
|
+
private
|
115
112
|
|
116
113
|
def default_config_dir
|
117
|
-
File.join(ENV['HOME'],'.brightbox')
|
114
|
+
File.join(ENV['HOME'], '.brightbox')
|
118
115
|
end
|
119
116
|
|
120
117
|
def configured?
|
121
|
-
configured = client_name
|
118
|
+
configured = !client_name.nil? && !clients.empty?
|
122
119
|
if configured && (selected_config.nil? || selected_config.empty?)
|
123
120
|
raise BBConfigError, "client id or alias #{client_name.inspect} not defined in config"
|
124
121
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Brightbox
|
2
2
|
module Config
|
3
3
|
module Accounts
|
4
|
-
|
5
4
|
def save_default_account(account_id)
|
6
5
|
dirty! unless account_id == selected_config["default_account"]
|
7
6
|
selected_config['default_account'] = account_id
|
@@ -38,17 +37,15 @@ module Brightbox
|
|
38
37
|
# excess traffic for certain use cases on all commands.
|
39
38
|
#
|
40
39
|
def find_or_set_default_account
|
41
|
-
# FIXME API clients are scoped to their account so this code should
|
40
|
+
# FIXME: API clients are scoped to their account so this code should
|
42
41
|
# never need to run for them.
|
43
42
|
unless default_account
|
44
43
|
begin
|
45
44
|
service = Fog::Compute.new(to_fog)
|
46
45
|
accounts = service.accounts
|
47
46
|
|
48
|
-
@account = accounts.select {|acc|
|
49
|
-
if @account
|
50
|
-
save_default_account(@account)
|
51
|
-
end
|
47
|
+
@account = accounts.select { |acc| %w{pending active}.include?(acc.status) }.first.id
|
48
|
+
save_default_account(@account) if @account
|
52
49
|
rescue Brightbox::BBConfigError
|
53
50
|
# We can't get a suitable fog connection so we can't select an
|
54
51
|
# account
|
@@ -18,22 +18,30 @@ module Brightbox
|
|
18
18
|
:brightbox_auth_url => selected_config['auth_url'] || selected_config['api_url'],
|
19
19
|
:brightbox_client_id => selected_config['client_id'],
|
20
20
|
:brightbox_secret => selected_config['secret'],
|
21
|
-
:persistent =>
|
21
|
+
:persistent => persistent?
|
22
22
|
}
|
23
23
|
end
|
24
24
|
|
25
25
|
def valid?
|
26
26
|
NON_BLANK_KEYS.all? do |key|
|
27
|
-
selected_config.
|
27
|
+
selected_config.key?(key) && !selected_config[key].to_s.empty?
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
private
|
32
|
+
|
33
|
+
def persistent?
|
34
|
+
if selected_config["persistent"]
|
35
|
+
selected_config["persistent"]
|
36
|
+
else
|
37
|
+
true
|
38
|
+
end
|
39
|
+
end
|
32
40
|
|
33
41
|
def check_required_params
|
34
42
|
unless valid?
|
35
43
|
NON_BLANK_KEYS.each do |key|
|
36
|
-
unless selected_config.
|
44
|
+
unless selected_config.key?(key) && !selected_config[key].to_s.empty?
|
37
45
|
raise Brightbox::BBConfigError, "#{key} option missing from config in section #{client_name}"
|
38
46
|
end
|
39
47
|
end
|
@@ -103,16 +103,13 @@ module Brightbox
|
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
-
#
|
107
106
|
def update_stored_tokens(new_access_token, new_refresh_token = nil)
|
108
107
|
save_access_token(new_access_token)
|
109
|
-
unless new_refresh_token.nil?
|
110
|
-
save_refresh_token(new_refresh_token)
|
111
|
-
end
|
108
|
+
save_refresh_token(new_refresh_token) unless new_refresh_token.nil?
|
112
109
|
debug_tokens
|
113
110
|
end
|
114
111
|
|
115
|
-
|
112
|
+
private
|
116
113
|
|
117
114
|
# This stores the access token for the Fog service currently in use to
|
118
115
|
# authenticate with the API.
|
@@ -170,7 +167,7 @@ module Brightbox
|
|
170
167
|
user_application = Brightbox::Config::UserApplication.new(selected_config, client_name)
|
171
168
|
|
172
169
|
fog_options = user_application.to_fog
|
173
|
-
# FIXME UserApplication#to_fog should include refresh token but does not
|
170
|
+
# FIXME: UserApplication#to_fog should include refresh token but does not
|
174
171
|
# have the correct scope to it
|
175
172
|
fog_options.merge!(:brightbox_refresh_token => refresh_token)
|
176
173
|
|
@@ -185,18 +182,16 @@ module Brightbox
|
|
185
182
|
require "highline"
|
186
183
|
highline = HighLine.new
|
187
184
|
highline.say("Your API credentials have expired, enter your password to update them.")
|
188
|
-
# FIXME Capture interupts if user aborts
|
185
|
+
# FIXME: Capture interupts if user aborts
|
189
186
|
highline.ask("Enter your password : ") { |q| q.echo = false }
|
190
187
|
end
|
191
188
|
|
192
189
|
def update_tokens_with_user_credentials(password = nil)
|
193
190
|
user_application = Brightbox::Config::UserApplication.new(selected_config, client_name)
|
194
191
|
|
195
|
-
unless password
|
196
|
-
password = prompt_for_password
|
197
|
-
end
|
192
|
+
password = prompt_for_password unless password
|
198
193
|
|
199
|
-
# FIXME options are required to work
|
194
|
+
# FIXME: options are required to work
|
200
195
|
options = {
|
201
196
|
:client_id => client_name,
|
202
197
|
:email => selected_config["username"],
|
@@ -218,18 +213,17 @@ module Brightbox
|
|
218
213
|
# Blanks access token in memory and on disk
|
219
214
|
def flush_access_token!
|
220
215
|
@access_token = nil
|
221
|
-
#persist_token(oauth_token_filename, nil)
|
222
216
|
end
|
223
217
|
|
224
218
|
# Saves
|
225
219
|
def persist_token(filename, token)
|
226
220
|
token = "" if token.nil?
|
227
221
|
# Write out a token file for this process
|
228
|
-
File.open(filename + ".#{
|
222
|
+
File.open(filename + ".#{$PID}", "w") do |f|
|
229
223
|
f.write token
|
230
224
|
end
|
231
225
|
# Move process version into place
|
232
|
-
FileUtils.mv filename + ".#{
|
226
|
+
FileUtils.mv filename + ".#{$PID}", filename
|
233
227
|
end
|
234
228
|
|
235
229
|
def cached_access_token
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Brightbox
|
2
2
|
module Config
|
3
3
|
module Clients
|
4
|
-
|
5
4
|
# Is the currently selected config using API client details?
|
6
5
|
def using_api_client?
|
7
6
|
config_identifier_match_prefix?("cli")
|
@@ -28,14 +27,14 @@ module Brightbox
|
|
28
27
|
#
|
29
28
|
def client_alias
|
30
29
|
return nil if selected_config.nil?
|
31
|
-
# FIXME The 'alias' field is redundant because we are using the section
|
30
|
+
# FIXME: The 'alias' field is redundant because we are using the section
|
32
31
|
# heading for the not ID value but we worry about it for now
|
33
32
|
selected_config["alias"] || client_name
|
34
33
|
end
|
35
34
|
|
36
35
|
# Returns a client name or raises depending on a number of factors.
|
37
36
|
#
|
38
|
-
# FIXME This combines too much decision making into what appears to be a
|
37
|
+
# FIXME: This combines too much decision making into what appears to be a
|
39
38
|
# getter.
|
40
39
|
#
|
41
40
|
# If a default_client is not set and there are more than one client it
|
@@ -55,7 +54,7 @@ module Brightbox
|
|
55
54
|
@client_name
|
56
55
|
else
|
57
56
|
# If we do not require a default client do not error if one is not set
|
58
|
-
# TODO Remove when certain unused
|
57
|
+
# TODO: Remove when certain unused
|
59
58
|
if @options[:force_default_config] == false
|
60
59
|
@client_name = default_client
|
61
60
|
else
|
@@ -76,7 +75,7 @@ module Brightbox
|
|
76
75
|
# @todo Account for "core" section
|
77
76
|
# @return [Boolean] +true+ if a client (section) has that name
|
78
77
|
def client_named?(name)
|
79
|
-
raw_sections.any? {|k,v| v["alias"] == name || k == name }
|
78
|
+
raw_sections.any? { |k, v| v["alias"] == name || k == name }
|
80
79
|
end
|
81
80
|
|
82
81
|
# @param [String] client_alias the name of the client to make the default
|
@@ -98,14 +97,14 @@ module Brightbox
|
|
98
97
|
end
|
99
98
|
|
100
99
|
def clear_default_client
|
101
|
-
if config["core"].
|
100
|
+
if config["core"].key?("default_client")
|
102
101
|
config["core"].delete("default_client")
|
103
102
|
dirty!
|
104
103
|
end
|
105
104
|
@default_client = nil
|
106
105
|
end
|
107
106
|
|
108
|
-
|
107
|
+
private
|
109
108
|
|
110
109
|
# If the prefix is in the client ID (identifier not alias) be +true+
|
111
110
|
def config_identifier_match_prefix?(prefix)
|
@@ -7,7 +7,6 @@ module Brightbox
|
|
7
7
|
# If the name is not in use then it is returned unchanged.
|
8
8
|
#
|
9
9
|
class SectionNameDeduplicator
|
10
|
-
|
11
10
|
# @param [String] name The name to deduplicate
|
12
11
|
# @param [Array<String>] in_use The names already in use in the config
|
13
12
|
#
|
@@ -22,7 +21,7 @@ module Brightbox
|
|
22
21
|
def next
|
23
22
|
# Sanity check. If the name is not in use, offer it back
|
24
23
|
if @in_use.include?(@name)
|
25
|
-
|
24
|
+
@in_use.sort.select do |name|
|
26
25
|
name == @name
|
27
26
|
end
|
28
27
|
|
@@ -32,7 +31,7 @@ module Brightbox
|
|
32
31
|
end
|
33
32
|
end
|
34
33
|
|
35
|
-
|
34
|
+
private
|
36
35
|
|
37
36
|
# Returns name with no numerical suffix (_\d+)
|
38
37
|
def normalised_name
|
@@ -42,12 +41,12 @@ module Brightbox
|
|
42
41
|
# Find any names in use fitting the name_suffix pattern to determine which
|
43
42
|
# suffix values are in use
|
44
43
|
def related_names_in_use
|
45
|
-
@in_use.map {|n| /\A#{normalised_name}_(\d+)\z/.match(n) }.compact
|
44
|
+
@in_use.map { |n| /\A#{normalised_name}_(\d+)\z/.match(n) }.compact
|
46
45
|
end
|
47
46
|
|
48
47
|
# Find the largest number suffix used
|
49
48
|
def max_suffix_value
|
50
|
-
related_names_in_use.map {|match| match.captures.first.to_i }.max
|
49
|
+
related_names_in_use.map { |match| match.captures.first.to_i }.max
|
51
50
|
end
|
52
51
|
|
53
52
|
# Find and increment the suffix
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Brightbox
|
2
2
|
module Config
|
3
3
|
module Sections
|
4
|
-
|
5
4
|
#
|
6
5
|
# @param [String] client_alias
|
7
6
|
# @param [String] client_id
|
@@ -14,7 +13,9 @@ module Brightbox
|
|
14
13
|
#
|
15
14
|
def add_section(client_alias, client_id, secret, options)
|
16
15
|
client_config = config[client_alias]
|
17
|
-
|
16
|
+
if client_config.empty?
|
17
|
+
info "Creating new client config #{client_alias}"
|
18
|
+
else
|
18
19
|
old_calias = client_alias
|
19
20
|
|
20
21
|
deduplicator = Brightbox::Config::SectionNameDeduplicator.new(client_alias, clients)
|
@@ -23,8 +24,6 @@ module Brightbox
|
|
23
24
|
client_config = config[client_alias]
|
24
25
|
|
25
26
|
info "A client config named #{old_calias} already exists using #{client_alias} instead"
|
26
|
-
else
|
27
|
-
info "Creating new client config #{client_alias}"
|
28
27
|
end
|
29
28
|
|
30
29
|
client_config["alias"] = client_alias
|
@@ -46,14 +45,12 @@ module Brightbox
|
|
46
45
|
end
|
47
46
|
|
48
47
|
# Try to determine a default account
|
49
|
-
|
48
|
+
unless default_account == find_or_set_default_account
|
50
49
|
info "The default account of #{default_account} has been selected"
|
51
50
|
end
|
52
51
|
|
53
52
|
# If only client then set it as the default
|
54
|
-
unless default_client
|
55
|
-
set_default_client(client_alias)
|
56
|
-
end
|
53
|
+
set_default_client(client_alias) unless default_client
|
57
54
|
|
58
55
|
# Ensure all our config changes are now saved
|
59
56
|
save
|
@@ -94,10 +91,10 @@ module Brightbox
|
|
94
91
|
#
|
95
92
|
def clients
|
96
93
|
# Exclude the global "core" section
|
97
|
-
config.sections.
|
94
|
+
config.sections.select { |s| s != 'core' }
|
98
95
|
end
|
99
96
|
|
100
|
-
|
97
|
+
private
|
101
98
|
|
102
99
|
# To compensate for Ini gem, this gets the hash it holds because it's
|
103
100
|
# #each interface isn't much use
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Brightbox
|
2
2
|
module Config
|
3
3
|
class UserApplication
|
4
|
-
# FIXME api_url should use fog's underlying default
|
4
|
+
# FIXME: api_url should use fog's underlying default
|
5
5
|
#
|
6
6
|
NON_BLANK_KEYS = %w{api_url client_id secret username}
|
7
7
|
|
@@ -21,7 +21,7 @@ module Brightbox
|
|
21
21
|
:brightbox_auth_url => selected_config['auth_url'] || selected_config['api_url'],
|
22
22
|
:brightbox_client_id => selected_config['client_id'],
|
23
23
|
:brightbox_secret => selected_config['secret'],
|
24
|
-
:persistent =>
|
24
|
+
:persistent => persistent?
|
25
25
|
}
|
26
26
|
end
|
27
27
|
|
@@ -31,11 +31,11 @@ module Brightbox
|
|
31
31
|
#
|
32
32
|
def valid?
|
33
33
|
NON_BLANK_KEYS.all? do |key|
|
34
|
-
selected_config.
|
34
|
+
selected_config.key?(key) && !selected_config[key].to_s.empty?
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
# FIXME This calls the underlying fog methods which also resets the access
|
38
|
+
# FIXME: This calls the underlying fog methods which also resets the access
|
39
39
|
# token but this method does not expose that token.
|
40
40
|
#
|
41
41
|
def fetch_refresh_token(options)
|
@@ -53,7 +53,15 @@ module Brightbox
|
|
53
53
|
connection
|
54
54
|
end
|
55
55
|
|
56
|
-
|
56
|
+
private
|
57
|
+
|
58
|
+
def persistent?
|
59
|
+
if selected_config["persistent"]
|
60
|
+
selected_config["persistent"]
|
61
|
+
else
|
62
|
+
true
|
63
|
+
end
|
64
|
+
end
|
57
65
|
|
58
66
|
def password_auth_params
|
59
67
|
{
|
@@ -63,14 +71,14 @@ module Brightbox
|
|
63
71
|
:brightbox_client_id => selected_config['client_id'],
|
64
72
|
:brightbox_secret => selected_config['secret'],
|
65
73
|
:brightbox_username => selected_config["username"],
|
66
|
-
:persistent =>
|
74
|
+
:persistent => persistent?
|
67
75
|
}
|
68
76
|
end
|
69
77
|
|
70
78
|
def check_required_params
|
71
79
|
unless valid?
|
72
80
|
NON_BLANK_KEYS.each do |key|
|
73
|
-
unless selected_config.
|
81
|
+
unless selected_config.key?(key) && !selected_config[key].to_s.empty?
|
74
82
|
raise Brightbox::BBConfigError, "#{key} option missing from config in section #{client_name}"
|
75
83
|
end
|
76
84
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Brightbox
|
2
2
|
class ConnectionManager
|
3
|
-
|
4
3
|
def initialize(connection_options)
|
5
4
|
@connection_options = connection_options
|
6
5
|
@connection = nil
|
@@ -14,7 +13,7 @@ module Brightbox
|
|
14
13
|
end
|
15
14
|
end
|
16
15
|
|
17
|
-
|
16
|
+
private
|
18
17
|
|
19
18
|
def connection_with_account
|
20
19
|
if @connection
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module Brightbox
|
2
|
+
class DatabaseServer < Api
|
3
|
+
def self.require_account?
|
4
|
+
true
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.create(options)
|
8
|
+
new(conn.database_servers.create(options))
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.all
|
12
|
+
conn.database_servers.all
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.get(id)
|
16
|
+
conn.database_servers.get(id)
|
17
|
+
end
|
18
|
+
|
19
|
+
def update(options)
|
20
|
+
self.class.conn.update_database_server(id, options)
|
21
|
+
reload
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def reset_password
|
26
|
+
fog_model.reset_password
|
27
|
+
end
|
28
|
+
|
29
|
+
def destroy
|
30
|
+
fog_model.destroy
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.default_field_order
|
34
|
+
[
|
35
|
+
:id,
|
36
|
+
:status,
|
37
|
+
:type,
|
38
|
+
:db_engine,
|
39
|
+
:zone,
|
40
|
+
:created_on,
|
41
|
+
:cloud_ip_ids,
|
42
|
+
:name
|
43
|
+
]
|
44
|
+
end
|
45
|
+
|
46
|
+
# These are all the fields show in the longer table form
|
47
|
+
def self.detailed_fields
|
48
|
+
[
|
49
|
+
:id, :name, :description, :status,
|
50
|
+
:type, :engine, :version,
|
51
|
+
:zone,
|
52
|
+
:created_on,
|
53
|
+
:admin_username, :admin_password,
|
54
|
+
:allow_access,
|
55
|
+
:cloud_ip_ids, :cloud_ips
|
56
|
+
]
|
57
|
+
end
|
58
|
+
|
59
|
+
def type_identifier
|
60
|
+
if fog_model.attributes.key?("database_server_type")
|
61
|
+
fog_model.attributes["database_server_type"]["id"]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def zone_handle
|
66
|
+
if fog_model.attributes.key?("zone")
|
67
|
+
fog_model.attributes["zone"]["handle"]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def to_row
|
72
|
+
a = fog_model.attributes
|
73
|
+
a[:status] = fog_model.state
|
74
|
+
a[:type] = type_identifier
|
75
|
+
a[:db_engine] = engine_version
|
76
|
+
a[:engine] = database_engine
|
77
|
+
a[:version] = database_version
|
78
|
+
a[:zone] = zone_handle
|
79
|
+
a[:created_on] = created_on
|
80
|
+
a[:allow_access] = allow_access
|
81
|
+
a[:cloud_ip_ids] = cloud_ip_ids
|
82
|
+
a[:cloud_ips] = cloud_ip_addresses
|
83
|
+
a
|
84
|
+
end
|
85
|
+
|
86
|
+
def engine_version
|
87
|
+
[database_engine, database_version].join("-")
|
88
|
+
end
|
89
|
+
|
90
|
+
# Lists the CIP identifiers (cip-12345)
|
91
|
+
def cloud_ip_ids
|
92
|
+
cloud_ips.map { |cip| cip["id"] }
|
93
|
+
end
|
94
|
+
|
95
|
+
# Lists the CIP IP addresses
|
96
|
+
def cloud_ip_addresses
|
97
|
+
cloud_ips.map { |cip| cip["public_ip"] }
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|