Skip to content

Commit

Permalink
Add IAP_CURL_BIN variable
Browse files Browse the repository at this point in the history
  • Loading branch information
babarot committed Oct 17, 2017
1 parent 6c8530a commit 203cae6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,39 @@ $ iap_curl http://iap-protected.webapp.com

The option of iap_curl is fully compatible with curl one.

If you want to use [httpstat](https://github.com/b4b4r07/httpstat), please specify the `IAP_CURL_BIN` environment variable:

```console
$ export IAP_CURL_BIN="httpstat.sh"
$ iap_curl https://tellme.tokyo
Connected to 104.31.70.103:443

HTTP/2.0 200 OK
Server: cloudflare-nginx
Access-Control-Allow-Origin: *
Cache-Control: max-age=600
Cf-Ray: 3af48c40aa3694cf-NRT
Content-Type: text/html; charset=utf-8
Date: Tue, 17 Oct 2017 16:13:54 GMT
Expires: Tue, 17 Oct 2017 16:23:54 GMT
Last-Modified: Mon, 16 Oct 2017 04:33:46 GMT
Set-Cookie: __cfduid=db7e1d73f138bcb26e0d6a040e9f5df491508256834; expires=Wed, 17-Oct-18 16:13:54 GMT; path=/; domain=.tellme.tokyo; HttpOnly; Secure
Strict-Transport-Security: max-age=15552000; preload
X-Content-Type-Options: nosniff
X-Github-Request-Id: 2A8B:16E6:10351CA:186074E:59E62C3F

Body discarded

DNS Lookup TCP Connection TLS Handshake Server Processing Content Transfer
[ 2ms | 57ms | 320ms | 303ms | 0ms ]
| | | | |
namelookup:2ms | | | |
connect:60ms | | |
pretransfer:381ms | |
starttransfer:684ms |
total:684ms
```

## Installation

```
Expand Down
4 changes: 2 additions & 2 deletions curl.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"runtime"
)

func doCurl(args []string) error {
func doCurl(binary string, args []string) error {
// Check if you have curl command
command := "curl"
command := binary
if _, err := exec.LookPath(command); err != nil {
return err
}
Expand Down
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const (

GoogleApplicationCredentials = "GOOGLE_APPLICATION_CREDENTIALS"
IAPClientID = "IAP_CLIENT_ID"
IAPCurlBinary = "IAP_CURL_BIN"
)

var helpText string = `Usage: curl
Expand All @@ -23,6 +24,7 @@ func run(args []string) int {
var (
creds = os.Getenv(GoogleApplicationCredentials)
clientID = os.Getenv(IAPClientID)
binary = os.Getenv(IAPCurlBinary)
)

if len(args) > 0 {
Expand All @@ -42,6 +44,10 @@ func run(args []string) int {
return 1
}

if binary == "" {
binary = "curl"
}

token, err := getToken(creds, clientID)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err.Error())
Expand All @@ -56,7 +62,7 @@ func run(args []string) int {
args...,
)

if err := doCurl(curlArgs); err != nil {
if err := doCurl(binary, curlArgs); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err.Error())
return 1
}
Expand Down

0 comments on commit 203cae6

Please sign in to comment.