コード例 #1
0
ファイル: client.go プロジェクト: davidwadden/lattice-release
func (c *client) SubscribeToEvents() (EventSource, error) {
	eventSource, err := sse.Connect(c.streamingHTTPClient, time.Second, func() *http.Request {
		request, err := c.reqGen.CreateRequest(EventStream, nil, nil)
		if err != nil {
			panic(err) // totally shouldn't happen
		}

		return request
	})
	if err != nil {
		return nil, err
	}

	return NewEventSource(eventSource), nil
}
コード例 #2
0
ファイル: client.go プロジェクト: trainchou/gorouter
func (c *client) SubscribeToEvents() (EventSource, error) {
	eventSource, err := sse.Connect(c.streamingHTTPClient, time.Second, func() *http.Request {
		request, err := c.reqGen.CreateRequest(EventStreamRoute, nil, nil)
		request.Header.Add("Authorization", "bearer "+c.authToken)
		if err != nil {
			panic(err) // totally shouldn't happen
		}

		return request
	})
	if err != nil {
		return nil, err
	}

	return NewEventSource(eventSource), nil
}
コード例 #3
0
ファイル: client.go プロジェクト: drnic/noop-cf-boshrelease
func (c *client) doSubscribe(routeName string) (RawEventSource, error) {
	eventSource, err := sse.Connect(c.streamingHTTPClient, time.Second, func() *http.Request {
		request, err := c.reqGen.CreateRequest(routeName, nil, nil)
		request.Header.Add("Authorization", "bearer "+c.authToken)
		if err != nil {
			panic(err) // totally shouldn't happen
		}

		trace.DumpRequest(request)
		return request
	})
	if err != nil {
		return nil, err
	}

	return eventSource, nil
}
コード例 #4
0
ファイル: connection.go プロジェクト: xoebus/checkin
func (connection *connection) ConnectToEventStream(passedRequest Request) (*sse.EventSource, error) {
	source, err := sse.Connect(connection.httpClient, time.Second, func() *http.Request {
		request, reqErr := connection.createHTTPRequest(passedRequest)
		if reqErr != nil {
			panic("unexpected error creating request: " + reqErr.Error())
		}

		return request
	})
	if err != nil {
		if brErr, ok := err.(sse.BadResponseError); ok {
			if brErr.Response.StatusCode == http.StatusUnauthorized {
				return nil, ErrUnauthorized
			}
		}

		return nil, err
	}

	return source, nil
}
コード例 #5
0
ファイル: watch.go プロジェクト: simonjjones/fly
func Watch(c *cli.Context) {
	target := returnTarget(c.GlobalString("target"))
	insecure := c.GlobalBool("insecure")

	pipelineName := c.String("pipeline")
	jobName := c.String("job")
	buildName := c.String("build")

	atcRequester := newAtcRequester(target, insecure)

	build := getBuild(atcRequester.httpClient, atcRequester.RequestGenerator, jobName, buildName, pipelineName)

	eventSource, err := sse.Connect(atcRequester.httpClient, time.Second, func() *http.Request {
		logOutput, err := atcRequester.CreateRequest(
			atc.BuildEvents,
			rata.Params{"build_id": strconv.Itoa(build.ID)},
			nil,
		)
		if err != nil {
			log.Fatalln(err)
		}

		return logOutput
	})
	if err != nil {
		log.Println("failed to attach to stream:", err)
		os.Exit(1)
	}

	exitCode, err := eventstream.RenderStream(eventSource)
	if err != nil {
		log.Println("failed to render stream:", err)
		os.Exit(1)
	}

	eventSource.Close()

	os.Exit(exitCode)
}
コード例 #6
0
ファイル: client.go プロジェクト: shashankmjain/gorouter
func (c *client) doSubscribe(routeName string) (RawEventSource, error) {
	eventSource, err := sse.Connect(c.streamingHTTPClient, time.Second, func() *http.Request {
		request, err := c.reqGen.CreateRequest(routeName, nil, nil)
		c.tokenMutex.RLock()
		defer c.tokenMutex.RUnlock()
		request.Header.Add("Authorization", "bearer "+c.authToken)
		if err != nil {
			panic(err) // totally shouldn't happen
		}

		trace.DumpRequest(request)
		return request
	})
	if err != nil {
		bre, ok := err.(sse.BadResponseError)
		if ok && bre.Response.StatusCode == http.StatusUnauthorized {
			return nil, Error{Type: "unauthorized", Message: "unauthorized"}
		}
		return nil, err
	}

	return eventSource, nil
}
コード例 #7
0
ファイル: execute.go プロジェクト: simonjjones/fly
func Execute(c *cli.Context) {
	target := returnTarget(c.GlobalString("target"))
	buildConfig := c.String("config")
	insecure := c.GlobalBool("insecure")
	excludeIgnored := c.Bool("exclude-ignored")

	atcRequester := newAtcRequester(target, insecure)

	inputMappings := c.StringSlice("input")
	if len(inputMappings) == 0 {
		wd, err := os.Getwd()
		if err != nil {
			log.Fatalln(err)
		}

		inputMappings = append(inputMappings, filepath.Base(wd)+"="+wd)
	}

	inputs := []Input{}
	for _, i := range inputMappings {
		segs := strings.SplitN(i, "=", 2)
		if len(segs) < 2 {
			log.Println("malformed input:", i)
			os.Exit(1)
		}

		inputName := segs[0]

		absPath, err := filepath.Abs(segs[1])
		if err != nil {
			log.Printf("could not locate input %s: %s\n", inputName, err)
			os.Exit(1)
		}

		pipe := createPipe(atcRequester)

		inputs = append(inputs, Input{
			Name: inputName,
			Path: absPath,
			Pipe: pipe,
		})
	}

	absConfig, err := filepath.Abs(buildConfig)
	if err != nil {
		log.Println("could not locate config file:", err)
		os.Exit(1)
	}

	build := createBuild(
		atcRequester,
		c.Bool("privileged"),
		inputs,
		config.LoadTaskConfig(absConfig, c.Args()),
	)

	fmt.Fprintf(os.Stdout, "executing build %d\n", build.ID)

	terminate := make(chan os.Signal, 1)

	go abortOnSignal(atcRequester, terminate, build)

	signal.Notify(terminate, syscall.SIGINT, syscall.SIGTERM)

	eventSource, err := sse.Connect(atcRequester.httpClient, time.Second, func() *http.Request {
		logOutput, err := atcRequester.CreateRequest(
			atc.BuildEvents,
			rata.Params{"build_id": strconv.Itoa(build.ID)},
			nil,
		)
		if err != nil {
			log.Fatalln(err)
		}

		return logOutput
	})
	if err != nil {
		log.Println("failed to connect to event stream:", err)
		os.Exit(1)
	}

	go func() {
		for _, i := range inputs {
			upload(i, excludeIgnored, atcRequester)
		}
	}()

	exitCode, err := eventstream.RenderStream(eventSource)
	if err != nil {
		log.Println("failed to render stream:", err)
		os.Exit(1)
	}

	eventSource.Close()

	os.Exit(exitCode)
}