mirror of
https://github.com/seejohnrun/haste-client.git
synced 2025-12-12 23:05:56 +00:00
[UTI-2583] Adapt haste-client to the new API usage rules
This commit is contained in:
8
LICENSE.txt
Normal file
8
LICENSE.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
Copyright 2022 Toptal LLC
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
165
README.md
165
README.md
@@ -1,14 +1,12 @@
|
||||
# Haste Client
|
||||
|
||||
[](http://travis-ci.org/seejohnrun/haste-client)
|
||||
|
||||
haste-client is a simple client for uploading data to haste-server. All you do it pipe data in STDIN:
|
||||
Haste-client is a simple client for uploading data to `Haste` server. All you need to do is to pipe data in STDIN:
|
||||
|
||||
`cat file | haste`
|
||||
|
||||
And once the output makes it to the server, it will print the URL to STDOUT.
|
||||
And once the output makes it to the server, it will print the `Haste` share page URL to STDOUT.
|
||||
|
||||
This can be really really cool in combination with `pbcopy`, like:
|
||||
This can be combined with `pbcopy`, like:
|
||||
|
||||
* mac osx: `cat file | haste | pbcopy`
|
||||
* linux: `cat file | haste | xsel`
|
||||
@@ -21,39 +19,37 @@ after which the contents of `file` will be accessible at a URL which has been co
|
||||
gem install haste
|
||||
```
|
||||
|
||||
## Making uploading file contents easier
|
||||
## Configuration
|
||||
|
||||
If you supply a valid file path as argument #1 to the client, it will be uploaded:
|
||||
Most of the configuration is controlled by env variables. Here is the all environment variables that you can use.
|
||||
|
||||
``` bash
|
||||
# equivalent
|
||||
cat file | haste
|
||||
haste file
|
||||
```
|
||||
HASTE_SERVER
|
||||
HASTE_SERVER_TOKEN
|
||||
HASTE_SHARE_SERVER
|
||||
HASTE_USER
|
||||
HASTE_PASS
|
||||
HASTE_SSL_CERTS
|
||||
```
|
||||
|
||||
## You can get the raw version
|
||||
To add these environment variables, you should simply add them to your ~.bash_profile:
|
||||
|
||||
Want the raw URL returned instead? (a plain-text version)?
|
||||
|
||||
``` bash
|
||||
cat file | haste --raw # or
|
||||
haste file --raw
|
||||
```bash
|
||||
export VARIABLE="value"
|
||||
```
|
||||
|
||||
## Changing the location of your haste server
|
||||
|
||||
By default, haste will point at `https://hastebin.com`. You can change this by setting the value of `ENV['HASTE_SERVER']` to the URL of your haste server. You can also use `alias` to make easy shortcuts if you commonly use a few hastes intermingled with each other. To do that, you'd put something like this into ~.bash_profile:
|
||||
|
||||
``` bash
|
||||
alias work_haste="HASTE_SERVER=https://something.com haste"
|
||||
```
|
||||
|
||||
After which you can use `work_haste` to send hastes to that server instead.
|
||||
|
||||
### Authentication
|
||||
|
||||
If your haste installation requires http authentication,
|
||||
add the following to your ~.bash_profile:
|
||||
If you are using default `HASTE_SERVER`, you need to have an authentication token.
|
||||
You can get the information about authentication and how to generate token here. `https://www.toptal.com/developers/hastebin/documentation`
|
||||
|
||||
After you have generated your token, you should add the token to your ~.bash_profile:
|
||||
|
||||
```bash
|
||||
export HASTE_SERVER_TOKEN="mytoken"
|
||||
```
|
||||
|
||||
If your `Haste` installation requires http authentication, add the following to your ~.bash_profile:
|
||||
|
||||
```bash
|
||||
export HASTE_USER="myusername"
|
||||
@@ -66,7 +62,70 @@ if you are using SSL, you will need to supply your certs path
|
||||
export HASTE_SSL_CERTS="/System/Library/OpenSSL/certs"
|
||||
```
|
||||
|
||||
## Use as a library
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
If you supply a valid file path as an argument to the client, it will be uploaded:
|
||||
|
||||
``` bash
|
||||
# equivalent
|
||||
cat file | haste
|
||||
haste file
|
||||
```
|
||||
|
||||
### Share page
|
||||
|
||||
Once you have run `haste` command and your bin is uploaded, `Haste` share page URL will be printed to STDOUT.
|
||||
|
||||
In share page:
|
||||
|
||||
- You can see the content of the bin
|
||||
- You can download bin as a raw file
|
||||
- You can create a new bin
|
||||
- You can duplicate the bin
|
||||
|
||||
|
||||
By default, `Haste` share page will point at `https://hastebin.com`.
|
||||
You can change this by setting the value of `ENV['HASTE_SHARE_SERVER']` to the URL of your `Haste` server.
|
||||
|
||||
To set the value of share server, you can add the following to your ~.bash_profile:
|
||||
|
||||
```bash
|
||||
export HASTE_SHARE_SERVER="myshareserver"
|
||||
```
|
||||
|
||||
|
||||
### Different Haste server
|
||||
|
||||
By default, haste server will point at `https://hastebin.com`.
|
||||
You can change this by setting the value of `ENV['HASTE_SERVER']` to the URL of your `Haste` server.
|
||||
|
||||
To set the value of server, you can add the following to your ~.bash_profile:
|
||||
|
||||
```bash
|
||||
export HASTE_SERVER="myserver"
|
||||
```
|
||||
|
||||
### Use with alias
|
||||
|
||||
You can also use `alias` to make easy shortcuts if you commonly use a few hastes intermingled with each other.
|
||||
To do that, you'd put something like this into ~.bash_profile:
|
||||
|
||||
``` bash
|
||||
alias work_haste="HASTE_SERVER=https://something.com HASTE_SERVER_TOKEN=mytoken haste"
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
``` bash
|
||||
alias work_haste="HASTE_SERVER_TOKEN=mytoken haste"
|
||||
```
|
||||
|
||||
After which you can use `work_haste` to send hastes to that server or with different tokens instead.
|
||||
|
||||
|
||||
### Use as a library
|
||||
|
||||
You can also use `Haste` as a library to upload hastes:
|
||||
|
||||
@@ -77,48 +136,6 @@ uploader.upload_raw 'this is my data' # key
|
||||
uploader.upload_path '/tmp/whaaaa' # key
|
||||
```
|
||||
|
||||
## Windows Support
|
||||
## Contributor License Agreement
|
||||
|
||||
If you'd like an alternative on Windows that supports functionality similar to `pbcopy`, check out Aidan Ryan's [WinHaste](https://github.com/ajryan/WinHaste) project.
|
||||
|
||||
## Lightweight Alternative
|
||||
|
||||
Han Boetes and @nickthename have contributed a simple shell-script alternative for those not interested in installing a RubyGem:
|
||||
|
||||
``` bash
|
||||
haste() {
|
||||
local S="https" H="hastebin.com" P="" L="$1"
|
||||
local SHP="${S}://${H}${P}/"
|
||||
curl -X POST -s --data-binary @- "${SHP}documents" \
|
||||
| awk -F '"' 'b{ b="."b }; {print a$4b}' a="${SHP}" b="${L}"
|
||||
}
|
||||
```
|
||||
|
||||
Where `S` is the scheme, `H` is the host, `P` is the port, and `L` is the language. Requires `curl`
|
||||
|
||||
Usage:
|
||||
|
||||
``` bash
|
||||
cat file.txt | haste # cat file into hate, output url
|
||||
haste sh < script.sh # Same as above, but ensure shell syntax highlighting
|
||||
xsel -b | haste txt # Output clipboard buffer into haste, ensure no highlighting
|
||||
```
|
||||
|
||||
And a more expansive BASH option by @diethnis can be found at:
|
||||
https://github.com/diethnis/standalones/blob/master/hastebin.sh
|
||||
|
||||
## Author
|
||||
|
||||
John Crepezzi <john.crepezzi@gmail.com>
|
||||
|
||||
## License
|
||||
|
||||
(The MIT License)
|
||||
|
||||
Copyright © 2011 John Crepezzi
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
||||
Licensed under the [MIT](https://github.com/toptal/haste-client/blob/main/LICENSE.txt 'https://github.com/toptal/haste-client/blob/main/LICENSE.txt') license.
|
||||
|
||||
@@ -6,6 +6,8 @@ module Haste
|
||||
def initialize
|
||||
@uploader = Uploader.new(
|
||||
ENV['HASTE_SERVER'],
|
||||
ENV['HASTE_SERVER_TOKEN'],
|
||||
ENV['HASTE_SHARE_SERVER'],
|
||||
ENV['HASTE_USER'],
|
||||
ENV['HASTE_PASS'],
|
||||
ENV['HASTE_SSL_CERTS'])
|
||||
@@ -20,11 +22,7 @@ module Haste
|
||||
key = @uploader.upload_raw STDIN.readlines.join
|
||||
end
|
||||
# Put together a URL
|
||||
if ARGV.include?('--raw')
|
||||
url = "#{@uploader.server_url}/raw/#{key}"
|
||||
else
|
||||
url = "#{@uploader.server_url}/#{key}"
|
||||
end
|
||||
url = "#{@uploader.share_server_url}/share/#{key}"
|
||||
# And write data out
|
||||
if STDOUT.tty?
|
||||
STDOUT.puts url
|
||||
|
||||
@@ -4,22 +4,29 @@ require 'uri'
|
||||
|
||||
module Haste
|
||||
|
||||
DEFAULT_URL = 'https://hastebin.com'
|
||||
SERVER_URL = 'https://hastebin.com'
|
||||
SHARE_SERVER_URL = 'https://hastebin.com'
|
||||
|
||||
class Uploader
|
||||
|
||||
attr_reader :server_url, :server_user, :server_pass, :ssl_certs
|
||||
|
||||
def initialize(server_url = nil, server_user = nil, server_pass = nil, ssl_certs = nil)
|
||||
@server_url = server_url || Haste::DEFAULT_URL
|
||||
@server_url = @server_url.dup
|
||||
@server_url = @server_url.chop if @server_url.end_with?('/')
|
||||
attr_reader :server_url, :server_token, :share_server_url, :server_user, :server_pass, :ssl_certs
|
||||
|
||||
def initialize(server_url = nil, server_token = nil, share_server_url = nil, server_user = nil, server_pass = nil, ssl_certs = nil)
|
||||
@server_url = generate_url(server_url || Haste::SERVER_URL)
|
||||
@share_server_url = generate_url(share_server_url || Haste::SHARE_SERVER_URL)
|
||||
|
||||
@server_user = server_user
|
||||
@server_token = server_token
|
||||
@server_pass = server_pass
|
||||
@ssl_certs = ssl_certs
|
||||
end
|
||||
|
||||
def generate_url(url)
|
||||
url = url.dup
|
||||
url = url.chop if url.end_with?('/')
|
||||
return url
|
||||
end
|
||||
|
||||
# Take in a path and return a key
|
||||
def upload_path(path)
|
||||
fail_with 'No input file given' unless path
|
||||
@@ -76,6 +83,7 @@ module Haste
|
||||
end
|
||||
|
||||
def connection_config(config)
|
||||
config.request :authorization, 'Bearer', @server_token if @server_token
|
||||
config.basic_auth(@server_user, @server_pass) if @server_user
|
||||
config.adapter Faraday.default_adapter
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user