-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
904 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
# Folders | ||
_obj | ||
_test | ||
pkg | ||
|
||
# Architecture specific extensions/prefixes | ||
*.[568vq] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
## 0.1.0 (2014-08-18) | ||
|
||
Initial release | ||
|
||
### Added | ||
|
||
- Add Fundamental features | ||
|
||
### Deprecated | ||
|
||
- Nothing | ||
|
||
### Removed | ||
|
||
- Nothing | ||
|
||
### Fixed | ||
|
||
- Nothing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
aurl | ||
==== | ||
|
||
## Description | ||
|
||
HTTP CLI client with OAuth2 authentication | ||
|
||
curl is powerful command line tool and you can make any complex HTTP request to every servers. But the target web | ||
server is secured by OAuth2, you must request another HTTP request to the authorization server before making | ||
principal request. And more, you should to manage issued access tokens for every resources. | ||
|
||
aurl is auto processing OAuth dance and manage access/refresh tokens. | ||
|
||
## Install | ||
|
||
To install, use `go get`: | ||
|
||
```bash | ||
$ go get -d github.com/classmethod-aws/aurl | ||
``` | ||
|
||
## Usage | ||
|
||
### Profile configuration | ||
|
||
First, you MUST create profile setting file `~/.aurl/profiles` file which format is described below. | ||
Profile setting file format is typically called [INI file](http://en.wikipedia.org/wiki/INI_file). | ||
Each section name is used as profile name. | ||
|
||
``` | ||
[default] | ||
auth_server_auth_endpoint = https://api.example.com/oauth/authorize | ||
auth_server_token_endpoint = https://api.example.com/oauth/token | ||
redirect = https://api.example.com/oauth/oob | ||
[foobar] | ||
grant_type = password | ||
auth_server_token_endpoint = https://api.example.com/oauth/token | ||
username = john | ||
password = pass1234 | ||
``` | ||
|
||
### Token store file | ||
|
||
Token store file `~/.aurl/tokens` is used by acurl internally. Retrieved access/refresh token is stored in this file. | ||
You SHOULD NOT edit this file manually because this file is overwritten every time curl is executed. | ||
You MAY lose comment and another extra data. | ||
|
||
Just for information, token sotore file example is following: | ||
|
||
``` | ||
[default] | ||
expiry = 1424049169 | ||
access_token = xxxx | ||
token_type = bearer | ||
refresh_token = yyyy | ||
[foobar] | ||
expiry = 1424141030 | ||
access_token = zzzz | ||
token_type = bearer | ||
``` | ||
|
||
### Execution | ||
|
||
###### SYNOPSIS | ||
|
||
```bash | ||
$ aurl [global options] command [command options] [arguments...] | ||
``` | ||
|
||
`command` is every http method (e.g. `get`, `post`, `delete`) and first argument is target url. | ||
|
||
###### EXAMPLE | ||
|
||
```bash | ||
$ aurl get http://api.example.com/path/to/resource | ||
$ aurl post http://api.example.com/path/to/resource --data "foobar" | ||
``` | ||
|
||
aurl make request with access token in `Authorization` header of `default` profile. | ||
You can specify profile name with `--profile` option. | ||
|
||
```bash | ||
$ aurl --profile foobar get http://api.example.com/path/to/resource | ||
``` | ||
|
||
By default aurl prints response body in stdout. When an error occured the detail is printed in stderr. | ||
You may want not response body but response header, then you can use `--no-body` and `--print-headers` option. | ||
|
||
```bash | ||
$ aurl --no-body --print-headers options http://api.example.com/path/to/resource | ||
{"Content-Type":["application/json;charset=UTF-8"],"Date":["Tue, 17 Feb 2015 08:16:41 GMT"],"Server":["nginx/1.6.2"], "...": "..."} | ||
``` | ||
|
||
## Contribution | ||
|
||
1. Fork ([https://github.com/classmethod-aws/oauthttp/fork](https://github.com/classmethod-aws/aurl/fork)) | ||
1. Create a feature branch named like `feature/something_awesome_feature` from `development` branch | ||
1. Commit your changes | ||
1. Rebase your local changes against the `develop` branch | ||
1. Run test suite with the `go test ./...` command and confirm that it passes | ||
1. Run `gofmt -s` | ||
1. Create new Pull Request | ||
|
||
## Author | ||
|
||
[Daisuke Miyamoto](https://github.com/miyamoto-daisuke) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/codegangsta/cli" | ||
"log" | ||
"os" | ||
) | ||
|
||
var CurrentOptions Options | ||
|
||
// Options provides a nice container to hold the values of command line options | ||
type Options struct { | ||
ProfileName string | ||
Verbose bool | ||
ProfileDict map[string]map[string]string | ||
} | ||
|
||
// extract an Options instance from the command line arguments | ||
func Opts(c *cli.Context) (Options, error) { | ||
if dict, err := LoadConfig(); err == nil { | ||
return Options{ | ||
ProfileName: c.GlobalString("profile"), | ||
Verbose: c.GlobalBool("verbose"), | ||
ProfileDict: dict, | ||
}, nil | ||
} else { | ||
return Options{}, err | ||
} | ||
|
||
} | ||
|
||
func main() { | ||
app := cli.NewApp() | ||
app.Name = "aurl" | ||
app.Version = Version | ||
app.Usage = "HTTP CLI client with OAuth2 authentication" | ||
app.Author = "Daisuke Miyamoto" | ||
app.Email = "[email protected]" | ||
app.Flags = []cli.Flag{ | ||
cli.StringFlag{ | ||
Name: "profile, P", | ||
Value: "default", | ||
Usage: "profile name", | ||
EnvVar: "OAUTHTTP_PROFILE", | ||
}, | ||
|
||
cli.BoolFlag{ | ||
Name: "insecure, k", | ||
Usage: "Disable SSL certificate verification", | ||
}, | ||
cli.BoolFlag{ | ||
Name: "no-body, B", | ||
Usage: "Disable the body printing to stdout", | ||
}, | ||
cli.BoolFlag{ | ||
Name: "print-headers, H", | ||
Usage: "Enable the response header printing to stdout (comma separated names)", | ||
}, | ||
cli.BoolFlag{ | ||
Name: "verbose, V", | ||
Usage: "Run in Verbose mode (logs to stderr)", | ||
}, | ||
} | ||
app.Commands = Commands | ||
|
||
app.Run(os.Args) | ||
} | ||
|
||
func Tracef(format string, args ...interface{}) { | ||
if CurrentOptions.Verbose { | ||
log.Printf(format, args...) | ||
} | ||
} |
Oops, something went wrong.