Exemple #1
0
// New creates a new instance of an ES client for interaction
// with an AWS provied ES server
func New(host, scheme, index, namespace, awsKey, awsSecret string) (ElasticSearch, error) {
	var e ElasticSearch

	signingTransport := awsSigningTransport{
		Credentials: awsauth.Credentials{
			AccessKeyID:     awsKey,
			SecretAccessKey: awsSecret,
		},
		HTTPClient: http.DefaultClient,
	}

	signingClient := http.Client{Transport: http.RoundTripper(signingTransport)}

	client, err := elastic.NewClient(
		elastic.SetURL(host),
		elastic.SetMaxRetries(10),
		elastic.SetScheme(scheme),
		elastic.SetHttpClient(&signingClient),
	)

	if err != nil {
		return e, err
	}

	// the namespace becomes the doctype for ease of use
	e.client = client
	e.index = index
	e.namespace = namespace

	return e, err
}
Exemple #2
0
func createAWSClient() (*http.Client, error) {
	id := os.Getenv("AWS_ACCESS_KEY_ID")
	if id == "" {
		id = os.Getenv("AWS_ACCESS_KEY")
	}

	secret := os.Getenv("AWS_SECRET_ACCESS_KEY")
	if secret == "" {
		secret = os.Getenv("AWS_SECRET_KEY")
	}

	if id == "" || secret == "" {
		return nil, fmt.Errorf("Failed to configure AWS authentication. Both `AWS_ACCESS_KEY_ID` and " +
			"`AWS_SECRET_ACCESS_KEY` environment veriables required")
	}

	signingTransport := AWSSigningTransport{
		Credentials: awsauth.Credentials{
			AccessKeyID:     id,
			SecretAccessKey: secret,
		},
		HTTPClient: http.DefaultClient,
	}
	return &http.Client{Transport: http.RoundTripper(signingTransport)}, nil
}
// NewStreamExecutor upgrades the request so that it supports multiplexed bidirectional
// streams. This method takes a stream upgrader and an optional function that is invoked
// to wrap the round tripper. This method may be used by clients that are lower level than
// Kubernetes clients or need to provide their own upgrade round tripper.
func NewStreamExecutor(upgrader httpstream.UpgradeRoundTripper, fn func(http.RoundTripper) http.RoundTripper, method string, url *url.URL) (StreamExecutor, error) {
	rt := http.RoundTripper(upgrader)
	if fn != nil {
		rt = fn(rt)
	}
	return &streamExecutor{
		upgrader:  upgrader,
		transport: rt,
		method:    method,
		url:       url,
	}, nil
}
Exemple #4
0
func handleInit() {
	pool := thumbnail.NewPool(*maxImageThreads, 1)

	transport := &http.Transport{Proxy: http.ProxyFromEnvironment}
	if *localImageDirectory != "" {
		transport.RegisterProtocol("file", http.NewFileTransport(http.Dir(*localImageDirectory)))
	}

	client := &http.Client{Transport: http.RoundTripper(transport), Timeout: *fetchTimeout}

	http.Handle("/", thumbnail.NewProxy(director, pool, *maxPrefetch+*maxImageThreads, client))
}
Exemple #5
0
// newAPIClient creates a new Sourcegraph API client for the endpoint
// given by endpointURL (a global) and that is authenticated using the
// credentials in ua (if non-nil) and perm grant ticket (if one is
// provided in SRCLIB_TICKET).
func newAPIClient(ua *userEndpointAuth, cache bool) *sourcegraph.Client {
	endpointURL := getEndpointURL()

	var transport http.RoundTripper
	if cache {
		tempDir := filepath.Join(os.TempDir(), "srclib-cache")
		transport = http.RoundTripper(httpcache.NewTransport(diskcache.New(tempDir)))
	} else {
		transport = http.DefaultTransport
	}

	if tickets := getPermGrantTickets(); len(tickets) > 0 {
		log.Println("# Using perm grant ticket from SRCLIB_TICKET.")
		transport = &auth.TicketAuthedTransport{SignedTicketStrings: tickets, Transport: transport}
	}

	if ua == nil {
		// Unauthenticated API client.
		if GlobalOpt.Verbose {
			log.Printf("# Using unauthenticated API client for endpoint %s.", endpointURL)
		}
	} else {
		// Authenticated API client.
		if GlobalOpt.Verbose {
			log.Printf("# Using authenticated API client for endpoint %s (UID %d).", endpointURL, ua.UID)
		}
		transport = &auth.BasicAuthTransport{Username: strconv.Itoa(ua.UID), Password: ua.Key, Transport: transport}
	}

	if v, _ := strconv.ParseBool(os.Getenv("SRC_TRACE")); v {
		transport = &tracingTransport{Writer: os.Stderr, Transport: transport}
	}

	c := sourcegraph.NewClient(&http.Client{Transport: transport})
	c.BaseURL = endpointURL
	return c
}
Exemple #6
0
	"io/ioutil"
	"net/http"
	"net/url"
	"regexp"
	"strconv"
	"time"
)

var (
	maxOutputDimension    = flag.Int("max_output_dimension", 2048, "Maximum width or height of an image response.")
	maxBufferPixels       = flag.Uint("max_buffer_pixels", 6500000, "Maximum number of pixels to allocate for an intermediate image buffer.")
	maxProcessingDuration = flag.Duration("max_processing_duration", time.Minute, "Maximum duration we can be processing an image before assuming we crashed (0 = disable).")
	localImageDirectory   = flag.String("local_image_directory", "", "Enable local image serving from this path (\"\" = proxy instead).")
	pool                  chan bool
	transport             http.Transport = http.Transport{Proxy: http.ProxyFromEnvironment}
	client                               = http.Client{Transport: http.RoundTripper(&transport)}
)

func init() {
	http.HandleFunc("/", imageProxyHandler)
	http.HandleFunc("/albums/crop", albumsCropHandler)
}

func imageProxyHandler(w http.ResponseWriter, r *http.Request) {
	if r.Method != "GET" && r.Method != "HEAD" {
		sendError(w, nil, http.StatusMethodNotAllowed)
		return
	}

	path, preview, crop, width, height, ok := parsePath(r.URL.Path)
	if !ok {