-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Anonymous FTP request single file prompt (vs 2) #69
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will have to look over this more in a bit, but this should be enough to get you started.
uri_filename = ask_custom_prompt(hostname, 'filename', "Target filename (e.g.: #{sample_case})") | ||
@uri = server_uri.gsub(sample_case, uri_filename) | ||
hostname = URI(server_uri).host | ||
@filename = ask_custom_prompt(hostname, 'filename', "Target filename for backup") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize this was added in the previous PR, and I wasn't really the reviewer, but why are we "passing" the default prompt if this method is only used in one spot?
I was reviewing a similar PR that @carbonin was (where he asked to axe some constants), but this seems like it makes more sense to just have this as a constant, or a frozen string in the method itself instead of passing it from here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also (not part of this line of code), but I think you can delete the constants at the top of this file for LOCAL_FILE
, NFS_FILE
, etc. since we don't use them any more (as of #65).
Separate commit/PR maybe? I think you would have a lot of tests that would need to be updated, for what it is worth.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, will make the prompt less generic.
Those constants are used all over the specs :( They have been simplified quite a bit (now just have 'ftp'
vs the full text of the ftp string) -- we can hardcode phrases like "ftp" in the specs.
efbac8b
to
d07b9f4
Compare
ok
keep 'em comin' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got a few things I need to look into yet (I think...), but a few more things I noticed.
@@ -38,6 +32,10 @@ def initialize(action = :restore, input = $stdin, output = $stdout) | |||
@task_params = [] | |||
end | |||
|
|||
def local_backup? | |||
backup_type == "local" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pendantic: "local".freeze
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But yes, I like this change. 👍
prompt_regex = prompts && prompts["#{prompt_name}_validator".to_sym] | ||
def ask_custom_file_prompt(hostname) | ||
# hostname has a period in it, so we need to look it up by [] instead of the traditional i18n method | ||
prompts = I18n.t("database_admin.prompts", :default => nil).try(:[], hostname.to_sym) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the .try(:[], ...)
necessary? I figured the .to_sym
would handle and case you would be concerned about, and return a nil
if nothing exists for it. Right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you would have to change the :default
to {}
, but I think this would work after that:
prompts = I18n.t("database_admin.prompts", :default => {})[hostname.to_sym]
d07b9f4
to
4dab261
Compare
@NickLaMuro thanks - got in the |
We were prompting for a local data filename and a remote url. But since this is streaming, it does not make sense. this now properly populates the :remote_file_name value
4dab261
to
1710eb3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. That spec file is getting hard to read, but too many tests is a good problem to have IMO 😄
@NickLaMuro anything more to add here?
@NickLaMuro What I used to configure the appliance console in local development to act like the appliance vm and pickup my localization changes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these comments are best left for another PR, if at all, but tossing them out there anyway.
Feel free to merge without the changes.
params[:remote_file_name] = filename if filename | ||
params = { | ||
:uri => uri, | ||
:skip_directory => true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine with this for now, but I think in the end, this should be part of the configuration, and not hard coded in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Along with this, I really feel we should be hiding this option, or allowing it to be configured to do so, for the restore options since this is ultimately being implemented for an endpoint you won't be able to restore from.
Might need a follow up, but just my two cents.
WIPping to find a more configurable way of adding flags for specific backup options |
Further clarifying this comment: For our current use case, this option should be displayed for the dry solution <== winner@NickLaMuro suggests dry. It is no fun to have duplicate lists - duplication tends to go wrong quickly. We display ---
database_admin:
menu_order:
- local
- ftp://ftp.example.com/incoming/
local: Local file
prompts:
ftp.example.com:
enabled_for: [dump, backup] ###### NEW FEATURE
filename_text: "The case number dash (-) filename. (e.g.: 12345-db.backup)"
filename_validator: "^[0-9]{4,}-.+" the less logic solution@kbrock suggests duplicating but removing special parameters that negate the list. Duplication stinks, but conditional logic is worse. If ---
database_admin:
menu_order:
- local
- ftp://ftp.example.com/incoming/
restore_menu_order: ###### NEW FEATURE
- local
- ftp://ftp.example.com/incoming/
local: Local file
prompts:
ftp.example.com:
filename_text: "The case number dash (-) filename. (e.g.: 12345-db.backup)"
filename_validator: "^[0-9]{4,}-.+" |
call it ask_custom_file_prompts and don't pretend that we are going to extend this
1710eb3
to
c8df718
Compare
c8df718
to
933c04e
Compare
These constants were useful at a time, but are currently only used in tests. so they have been removed
some options are only available for restore vs backup This allows an options to be available for only one of them
933c04e
to
28ca993
Compare
added rake_options and made custom endpoints enabled for various options (backup, dump, restore) Does this work for you now @NickLaMuro ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks good. Thanks for taking the extra time on this!
Comments left are minor, and not required... unless you want to be shamed for merging in a typo 😉
hostname = URI(server_uri).host | ||
uri_filename = ask_custom_prompt(hostname, 'filename', "Target filename (e.g.: #{sample_case})") | ||
@uri = server_uri.gsub(sample_case, uri_filename) | ||
hostname = URI(server_uri).host |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is minor:
I found this a bit confusing to me for a bit since I saw you parsing out the host
from the server_uri
, and thought that was being being assigned to @uri
. Turns out that wasn't the case, but we also aren't using the hostname
in any meaningful fashion except as a key. Seems like we could just as easily do this:
database_admin:
menu_order:
- local
- ftp://ftp.example.com/incoming/
local: Local file
prompts:
ftp://ftp.example.com/incoming/:
enabled_for: ["backup", "dump"]
...
And achieve the same affect by just passing around server_uri
as the key.
Again, this is minor, just thought it was a bit confusing from both a code and configuration perspective since there is two different "keys" being passed around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets keep this as the host for now.
Using the full path would simplify the code and may be more clear
But I like reading the configuration for the host version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me.
If the above wasn't clear to on lookers, my above critique is pretty subjective, and I don't hold a hard opinion on this.
spec/database_admin_spec.rb
Outdated
it "displays custom ftp option with enabled array" do | ||
expect(I18n).to receive(:t).with("database_admin.menu_order").and_return(%w(local ftp://example.com/inbox/filename.txt)) | ||
expect(I18n).to receive(:t).with("database_admin.local").and_return("The Local file") | ||
expect(I18n).to receive(:t).with("database_admin.prompts", :default => {}).at_least(:once).and_return(:"example.com" => { :enabled_for => %w(restore backup) }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pedantic: Wouldn't this be a known quantity of .once
or .twice
? Would save some characters and would be more explicit with those since this shouldn't be a variable number of calls as far as I can tell.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, since this line is pretty long, could the prompt options be saved in a let(:prompt_options)
to allow this to be more visable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The actual value for enabled_for
are different for most tests. I'll make a helper for this.
I'll make the twice
more explicit
spec/database_admin_spec.rb
Outdated
|
||
it "displays custom ftp option with enabled array" do | ||
expect(I18n).to receive(:t).with("database_admin.menu_order").and_return(%w(local ftp://example.com/inbox/filename.txt)) | ||
expect(I18n).to receive(:t).with("database_admin.local").and_return("The Local file") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pedantic: These above two seem like they could be tossed in a before
hook to save them being defined twice.
spec/database_admin_spec.rb
Outdated
PROMPT | ||
end | ||
|
||
it "hids custom ftp option with disabled string" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: s/hids/hides
spec/database_admin_spec.rb
Outdated
end | ||
|
||
it "cancels when CANCEL option is choosen" do | ||
say "6" | ||
expect { subject.ask_file_location }.to raise_error signal_error | ||
end | ||
|
||
# this is the complete implementation. the other 2 are paired down version of this | ||
context "with localized file upload" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pedantic: maybe "with I18n custom menu configs"?
If changed, make sure to change in the other two spots.
some prompts need custom options. --skip-directory=true is one option. We had it hardcoded before. this PR extracts it into its own configuration option
738ba47
to
b60b334
Compare
b60b334
to
542178a
Compare
Checked commits kbrock/manageiq-appliance_console@e26f76d~...542178a with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
@miq-bot tag hammer/yes |
@kbrock unrecognized command 'tag', ignoring... Accepted commands are: add_label, add_reviewer, assign, close_issue, move_issue, remove_label, rm_label, set_milestone |
@kbrock The console is actually a released gem so at some point when the backup/dump work stabilizes, we'll cut a release and include that in the hammer branch of manageiq-appliance |
We were prompting for a local data filename and a remote url.
But since this is streaming, it does not make sense.
This now:
:remote_file_name value
related to:
configuration has been tweaked: