Commit 125e71fa authored by David Fifield's avatar David Fifield
Browse files

Remove the now-unused appengine directory.

parent 2e9e8071
Loading
Loading
Loading
Loading
+0 −1
Original line number Original line Diff line number Diff line
@@ -28,7 +28,6 @@ install:
    - go get -u github.com/dchest/uniuri
    - go get -u github.com/dchest/uniuri
    - go get -u github.com/gorilla/websocket
    - go get -u github.com/gorilla/websocket
    - go get -u git.torproject.org/pluggable-transports/goptlib.git
    - go get -u git.torproject.org/pluggable-transports/goptlib.git
    - go get -u google.golang.org/appengine
    - go get -u golang.org/x/crypto/acme/autocert
    - go get -u golang.org/x/crypto/acme/autocert
    - go get -u golang.org/x/net/http2
    - go get -u golang.org/x/net/http2
    - pushd proxy
    - pushd proxy

appengine/.gcloudignore

deleted100644 → 0
+0 −25
Original line number Original line Diff line number Diff line
# This file specifies files that are *not* uploaded to Google Cloud Platform
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).
#
# For more information, run:
#   $ gcloud topic gcloudignore
#
.gcloudignore
# If you would like to upload your .git directory, .gitignore file or files
# from your .gitignore file, remove the corresponding line
# below:
.git
.gitignore

# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, build with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
 No newline at end of file

appengine/README

deleted100644 → 0
+0 −28
Original line number Original line Diff line number Diff line
This component runs on Google App Engine. It reflects domain-fronted
requests from a client to the Snowflake broker.

You need the Go App Engine SDK in order to deploy the app.
	https://cloud.google.com/sdk/docs/#linux
After unpacking, install the app-engine-go component:
	google-cloud-sdk/bin/gcloud components install app-engine-go

To test locally, run
	google-cloud-sdk/bin/dev_appserver.py app.yaml
The app will be running at http://127.0.0.1:8080/.

To deploy to App Engine, first create a new project and app. You have to
think of a unique name (marked as "<appname>" in the commands). You only
have to do the "create" step once; subsequent times you can go straight
to the "deploy" step. The "gcloud auth login" command will open a
browser window so you can log in to a Google account.
	google-cloud-sdk/bin/gcloud auth login
	google-cloud-sdk/bin/gcloud projects create <appname>
	google-cloud-sdk/bin/gcloud app create --project=<appname>
Then to deploy the project, run:
	google-cloud-sdk/bin/gcloud app deploy --project=<appname>

To configure the Snowflake client to talk to the App Engine app, provide
"https://<appname>.appspot.com/" as the --url option.
	UseBridges 1
	Bridge snowflake 0.0.2.0:1
	ClientTransportPlugin snowflake exec ./client -url https://<appname>.appspot.com/ -front www.google.com

appengine/app.yaml

deleted100644 → 0
+0 −6
Original line number Original line Diff line number Diff line
runtime: go111

handlers:
- url: /.*
  secure: always
  script: auto

appengine/reflect.go

deleted100644 → 0
+0 −111
Original line number Original line Diff line number Diff line
// A web app for Google App Engine that proxies HTTP requests and responses to
// the Snowflake broker.
package main

import (
	"context"
	"io"
	"net/http"
	"net/url"
	"time"

	"google.golang.org/appengine"
	"google.golang.org/appengine/log"
	"google.golang.org/appengine/urlfetch"
)

const (
	forwardURL = "https://snowflake-broker.bamsoftware.com/"
	// A timeout of 0 means to use the App Engine default (5 seconds).
	urlFetchTimeout = 20 * time.Second
)

var ctx context.Context

// Join two URL paths.
func pathJoin(a, b string) string {
	if len(a) > 0 && a[len(a)-1] == '/' {
		a = a[:len(a)-1]
	}
	if len(b) == 0 || b[0] != '/' {
		b = "/" + b
	}
	return a + b
}

// We reflect only a whitelisted set of header fields. Otherwise, we may copy
// headers like Transfer-Encoding that interfere with App Engine's own
// hop-by-hop headers.
var reflectedHeaderFields = []string{
	"Content-Type",
	"X-Session-Id",
}

// Make a copy of r, with the URL being changed to be relative to forwardURL,
// and including only the headers in reflectedHeaderFields.
func copyRequest(r *http.Request) (*http.Request, error) {
	u, err := url.Parse(forwardURL)
	if err != nil {
		return nil, err
	}
	// Append the requested path to the path in forwardURL, so that
	// forwardURL can be something like "https://example.com/reflect".
	u.Path = pathJoin(u.Path, r.URL.Path)
	c, err := http.NewRequest(r.Method, u.String(), r.Body)
	if err != nil {
		return nil, err
	}
	for _, key := range reflectedHeaderFields {
		values, ok := r.Header[key]
		if ok {
			for _, value := range values {
				c.Header.Add(key, value)
			}
		}
	}
	return c, nil
}

func handler(w http.ResponseWriter, r *http.Request) {
	ctx = appengine.NewContext(r)
	fr, err := copyRequest(r)
	if err != nil {
		log.Errorf(ctx, "copyRequest: %s", err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	if urlFetchTimeout != 0 {
		var cancel context.CancelFunc
		ctx, cancel = context.WithTimeout(ctx, urlFetchTimeout)
		defer cancel()
	}
	// Use urlfetch.Transport directly instead of urlfetch.Client because we
	// want only a single HTTP transaction, not following redirects.
	transport := urlfetch.Transport{
		Context: ctx,
	}
	resp, err := transport.RoundTrip(fr)
	if err != nil {
		log.Errorf(ctx, "RoundTrip: %s", err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	defer resp.Body.Close()
	for _, key := range reflectedHeaderFields {
		values, ok := resp.Header[key]
		if ok {
			for _, value := range values {
				w.Header().Add(key, value)
			}
		}
	}
	w.WriteHeader(resp.StatusCode)
	n, err := io.Copy(w, resp.Body)
	if err != nil {
		log.Errorf(ctx, "io.Copy after %d bytes: %s", n, err)
	}
}

func init() {
	http.HandleFunc("/", handler)
}