Skip to content

Conversation

@au-phiware
Copy link

@au-phiware au-phiware commented Dec 10, 2018

Thanks for your quick response to #9. This PR implements the kind of thing I had in mind.

It makes this possible:

$ slack-cli -s au-phiware -l 1 -o >(gpg -d)
[@au-phiware 2018-12-10 15:13:06] au-phiware: 
    stdin: https://files.slack.com/files-pri/T40QQHKDE-FEPB666BM/stdin
gpg: encrypted with 4096-bit RSA key, ID DEADBEEF0D19D828, created 2018-04-15
      "au-phiware"
This is secret...

Please note, this is my first time write any python and I am unaware of its idiosyncrasies, please feel free to make edits. Also, I wasn't sure if that was the best way to get hold of the token.

Corin Lawson added 2 commits December 10, 2018 14:55
Prior to this change, any files attached to a message are printed to the
standard output as
```
    name: private_url
```
It is then the user's choice to decide how to access the file at the
provided URL.

This change introduces a --output (-o) option that allows the user to
specify a file to download and write all files or named files.  By
default nothing is done and the behaviour is the same when the option is
not specified.  Otherwise, the string passed to the option is
interpreted as name-value pairs separated by a colon (:), where the name
is the same as reported in slack the slack message and the value is a
file to write the attachment to.  If a bare value is specified then it
will match all attachments.

Signed-off-by: Corin Lawson <corin@responsight.com>
@regisb
Copy link
Owner

regisb commented Dec 10, 2018

Thanks for the PR @au-phiware!
This is an interesting proposition, but I see a few cases where the change is going to be inconvenient:

  1. When there is a binary file upload, dumping to stdout is unreadable.
  2. When the file is very large (> 1 Mb) the console becomes unreadable, too.
  3. When reading a long history (-l 1000) this makes the user download many (potentially large) files.

Can you please tell me what is your use case, so that we can improve on your solution? Maybe you just want to view the last uploaded file? In such case, would you be ok with saving to disk, with something like:

slack-cli -s au-phiware -l 1 -o /tmp/mybackup/ && cat /tmp/mybackup/stdin | gpg -d

?

@au-phiware
Copy link
Author

Those are valid points, I guess in those situations the user would just not use the --output option.

Another feature might be an --output-dir option that operates more like a download manager.

Regarding specific use cases, I've only just starting using this and the 'pipe into gpg' was certainly the first use case that I came across.

@regisb
Copy link
Owner

regisb commented Dec 13, 2018

@au-phiware Note that the --output-dir solution you are suggesting corresponds to what I suggested, too :)

slack-cli -s au-phiware -l 1 -o /tmp/mybackup/ && cat /tmp/mybackup/stdin | gpg -d

In this example the -o option corresponds to your --output-dir.

I like the idea of having a download manager. We could save files automatically to <output-dir>/<channel name>/<datetime><file name>. Your PR does almost that -- would you have the time (and interest) to modify it to match these requirements<

Regarding output to stdout, there are some cases where it might be useful. However, the gpg example is hard to achieve: for this to work, the command would need to output only the file content, and no extra indication, such as the file url, the content of other conversations, etc. AFAIK if we pipe anything else to gpg, then decryption will fail with gpg: [don't know]: invalid packet errors. So I'm not sure it's a practical scenario. What do you think?

@au-phiware
Copy link
Author

@regisb, yes, I thought your -o and my --output-dir were the same thing (but you can never be sure 😉).

I don't have a lot of time to spare, but I think a "download to directory" would be a fairly simple change, so I'll try and give it a shot.

Also, that gpg example in my OP is the real output when building slack-cli from this PR, so it is working and practical. But it relies on the user to get the option right... Here's a more fuller example:

$ gpg -e --armor <<<'This is secret...' | slack-cli -d au-phiware --file /dev/stdin
...gpg promts...
slack-cli -s au-phiware -l 1 -o "stdin:">(gpg -d)
[@au-phiware 2018-12-17 16:32:29] au-phiware: 
    stdin: https://files.slack.com/files-pri/T04QQHKDE-FEWDYAQF9/stdin
gpg: encrypted with 4096-bit RSA key, ID DEADBEEF0D19D828, created 2018-04-15
      "au-phiware"
This is secret...

@regisb
Copy link
Owner

regisb commented Dec 18, 2018

Looks good! The important thing is that we agree on the right CLI options. I'll implement this feature, using your PR as a starting point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants