Skip to content
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

Merged
merged 3 commits into from
Oct 1, 2018
Merged

Conversation

kbrock
Copy link
Member

@kbrock kbrock commented Sep 24, 2018

This will allow customers to upload files to support sites like dropbox.redhat.com

To add this option, add to en.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,}-..*"

https://bugzilla.redhat.com/show_bug.cgi?id=1632433

@miq-bot miq-bot added the wip label Sep 24, 2018
Copy link
Member

@NickLaMuro NickLaMuro left a 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?
Copy link
Member

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.

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') }
Copy link
Member

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)")
Copy link
Member

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?

Copy link
Member Author

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]
Copy link
Member

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....

Copy link
Member

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.

Copy link
Member Author

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)
Copy link
Member

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
@kbrock kbrock force-pushed the localized_file_locs branch 3 times, most recently from d6171f9 to 8bec73f Compare September 25, 2018 14:33
@kbrock kbrock changed the title [WIP] Anonymous FTP upload Anonymous FTP upload Sep 25, 2018
@miq-bot miq-bot removed the wip label Sep 25, 2018
Copy link
Member

@carbonin carbonin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good to me. @kbrock can you provide a sample of what the anonymous case might look like in the I18n file? I understand we shouldn't edit the file in this repo, but I'm curious to see what it would look like now that I've seen #ask_custom_prompt

Lol read the damn description @carbonin

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 }
Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member

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?://([^/]*)/}
Copy link
Member

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.

@kbrock kbrock force-pushed the localized_file_locs branch 6 times, most recently from 24842e7 to 9c6a1e6 Compare September 28, 2018 23:14
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,}-..*"
```
@kbrock kbrock force-pushed the localized_file_locs branch from 9c6a1e6 to 51eb422 Compare September 29, 2018 16:13
@miq-bot
Copy link
Member

miq-bot commented Sep 29, 2018

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
4 files checked, 0 offenses detected
Everything looks fine. 👍

@carbonin carbonin self-assigned this Oct 1, 2018
@carbonin carbonin added the bug label Oct 1, 2018
@carbonin carbonin merged commit 6d4379d into ManageIQ:master Oct 1, 2018
@carbonin carbonin added this to the Sprint 96 Ending Oct 8, 2018 milestone Oct 1, 2018
@kbrock kbrock deleted the localized_file_locs branch October 1, 2018 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants