Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,23 @@ Usage of gcsproxy:
The path to the keyfile. If not present, client will use your default application credentials.
-i string
The default index file to serve.
-s string
The source bucket name. If not present, bucket name will be extracted from the path.
-v Show access log

```

The gcsproxy routing configuration is shown below.
The default gcsproxy routing configuration is shown below.

`"/{bucket:[0-9a-zA-Z-_.] +}/{object:. *}"`
`"/{bucket:[0-9a-zA-Z-_.]+}/{object:.*}"`

If you are running gcsproxy on localhost:8080 and you want to access the file `gs://test-bucket/your/file/path.txt` in GCS via gcsproxy,
you can use the URL You can access the file via gcsproxy at the URL `http://localhost:8080/test-bucket/your/file/path.txt`.

Specifying the `-s` option fixes the bucket name to the given value and following routing configuration is used instead.

`"/{object:.*}"`

If a default index file is specified and the target object does not exist, an attempt is made to retrieve the object specified in the default index file.

```
Expand Down
12 changes: 11 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (
verbose = flag.Bool("v", false, "Show access log")
credentials = flag.String("c", "", "The path to the keyfile. If not present, client will use your default application credentials.")
defaultIndex = flag.String("i", "", "The default index file to serve.")
sourceBucket = flag.String("s", "", "The source bucket name. If not present, bucket name will be extracted from the path.")
)

var client *storage.Client
Expand Down Expand Up @@ -179,7 +180,16 @@ func main() {

r := mux.NewRouter()
r.HandleFunc("/_health", wrapper(healthCheck)).Methods("GET", "HEAD")
r.HandleFunc("/{bucket:[0-9a-zA-Z-_.]+}/{object:.*}", wrapper(proxy)).Methods("GET", "HEAD")
if *sourceBucket != "" {
w := func(writer http.ResponseWriter, request *http.Request) {
params := mux.Vars(request)
params["bucket"] = *sourceBucket
wrapper(proxy)(writer, request)
}
r.HandleFunc("/{object:.*}", w).Methods("GET", "HEAD")
} else {
r.HandleFunc("/{bucket:[0-9a-zA-Z-_.]+}/{object:.*}", wrapper(proxy)).Methods("GET", "HEAD")
}

log.Printf("[service] listening on %s", *bind)
if err := http.ListenAndServe(*bind, r); err != nil {
Expand Down