-
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 upload #65
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.
This looks cool so far, and definitely along the lines of what I was considering. Most of the comments are more describing where I was differing how I envisioned it in my head, but are definitely open for debate and rejection based on personal preference and technical limitations.
Great start, and will be keeping an eye on this!
|
||
params = { :uri => uri } | ||
params[:uri_username] = "anonymous" | ||
params[:uri_password] = pass if pass.present? |
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.
These can be left blank. Net::FTP
will just assume "anonymous"
when nil
is passed.
spec/database_admin_spec.rb
Outdated
let(:uri) { File.dirname(subject.sample_url('s3')) } | ||
let(:filename) { File.basename(subject.sample_url('s3')) } | ||
let(:example_uri) { File.join(uri, filename) } | ||
let(:example_uri) { subject.send(:sample_url, 's3') } |
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.
You monster! You best be aligning those curly braces!!!1! 😡
validator = ->(x) { x.to_s =~ /#{prompt_regex}/ } if prompt_regex | ||
uri_filename = just_ask(prompt_text, nil, validator) | ||
@uri = uri.gsub(sample_case, uri_filename) | ||
pass = just_ask("email address (to use as the anonymous ftp password)") |
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 this necessary for all cases? Can we make this as part of the config options?
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 the standard anonymous ftp thing. But I think skipping username/password makes things easier
require 'uri' | ||
hostname = URI(uri).host | ||
prompt_text = I18n.t("database_admin.prompt")[hostname.to_sym] || "Target filename (e.g.: #{sample_case})" | ||
prompt_regex = I18n.t("database_admin.validator")[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.
Curious if we could have different names for this, or they could be nested under a key so they are a little more contextual:
database_admin:
custom_formats:
ftp.example.com:
filename_question:
prompt: "The case number dash (-) filename. (e.g.: CASENUMBER-db.backup)"
validator: "^[0-9]{4,}-..*"
custom_questions:
uri_password:
prompt: "foo"
validator: "blahblahblah" # I ran out of mojo partway through....
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.
In addition, I always saw the "CASENUMER" as being a separate questions, and then we would munge the case number into the filename. Not sure how this would work with what you have here, so that might be more of a "nice to have" than anything, but thought I would bring it up.
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.
Spoke with @jcarter12 and he felt this level of education was better handled by documentation.
I did take a stab at the different hierarchy
menu.choice(CANCEL) { |_| raise MiqSignalError } | ||
end | ||
if backup_type =~ %r{^ftps?://} | ||
ask_anonymous_file_options(backup_type) |
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 regexp and method name seem very specific to FTP, but I could see this being used for protocols that aren't FTP. Could we possibly make this a little more generic? ask_custom_file_options
or something (pick a better name... please 😩 )?
The next move is to localize these. But first step, get them out of prompts and into database_admin.rb
This allows the file types to be customized via localization downside, the name of the file_option types are now using send
d6171f9
to
8bec73f
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.
when FTP_FILE then ask_ftp_file_options | ||
when CANCEL then raise MiqSignalError | ||
@backup_type = ask_with_menu(*file_menu_args) do |menu| | ||
menu.choice(CANCEL) { |_| raise MiqSignalError } |
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 wonder if this is something we should just add to the end of every menu? Unlikely that it should be added to this PR, but this made me think of it.
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.
@kbrock When I was typing this I was thinking of modifying ask_with_menu to add that as an option
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.
Maybe just make an issue for this? I agree, that would definitely make this cleaner. Maybe also have it as an option to opt of ( something like ask_with_menu(*file_menu_args, :cancel_option => false)
maybe?).
...which reminds me... I really need to add an issue for the "UI stuff" I have wanted to refactor in this...
def file_options | ||
@file_options ||= I18n.t("database_admin.menu_order").each_with_object({}) do |file_option, h| | ||
# special anonymous ftp sites | ||
if file_option =~ %r{^ftps?://([^/]*)/} |
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 might be easier to read without the regex. None of the other file options are uri formatted right? How about something like this:
if %w(ftp ftps).include?(URI(file_option).scheme)
Then we can also avoid the global match variable by using the host in the URI.
24842e7
to
9c6a1e6
Compare
https://bugzilla.redhat.com/show_bug.cgi?id=1535345 https://bugzilla.redhat.com/show_bug.cgi?id=1632433 This will allow customers to upload files to support sites To add this option, add to `en.yml`: ```yml database_admin: menu_order: - local - ftp://ftp.example.com/incoming/999999-db.backup local: Local file prompts: ftp.example.com: filename_text: "The case number dash (-) filename. (e.g.: 12345-db.backup)" filename_validator: "^[0-9]{4,}-..*" ```
9c6a1e6
to
51eb422
Compare
Checked commits kbrock/manageiq-appliance_console@463c79b~...51eb422 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
This will allow customers to upload files to support sites like
dropbox.redhat.com
To add this option, add to
en.yml
:https://bugzilla.redhat.com/show_bug.cgi?id=1632433