func CreateBuild( atcRequester *deprecated.AtcRequester, client concourse.Client, privileged bool, inputs []Input, outputs []Output, config atc.TaskConfig, tags []string, target string, ) (atc.Build, error) { if err := config.Validate(); err != nil { return atc.Build{}, err } targetProps, err := rc.SelectTarget(target) if err != nil { return atc.Build{}, err } buildInputs := atc.AggregatePlan{} for i, input := range inputs { var getPlan atc.GetPlan if input.Path != "" { readPipe, err := atcRequester.CreateRequest( atc.ReadPipe, rata.Params{"pipe_id": input.Pipe.ID}, nil, ) if err != nil { return atc.Build{}, err } source := atc.Source{ "uri": readPipe.URL.String(), } if targetProps.Token != nil { source["authorization"] = targetProps.Token.Type + " " + targetProps.Token.Value } getPlan = atc.GetPlan{ Name: input.Name, Type: "archive", Source: source, } } else { getPlan = atc.GetPlan{ Name: input.Name, Type: input.BuildInput.Type, Source: input.BuildInput.Source, Version: input.BuildInput.Version, Params: input.BuildInput.Params, Tags: input.BuildInput.Tags, } } buildInputs = append(buildInputs, atc.Plan{ Location: &atc.Location{ // offset by 2 because aggregate gets parallelgroup ID 1 ID: uint(i) + 2, ParentID: 0, ParallelGroup: 1, }, Get: &getPlan, }) } taskPlan := atc.Plan{ Location: &atc.Location{ // offset by 1 because aggregate gets parallelgroup ID 1 ID: uint(len(inputs)) + 2, ParentID: 0, }, Task: &atc.TaskPlan{ Name: "one-off", Privileged: privileged, Config: &config, }, } if len(tags) != 0 { taskPlan.Task.Tags = tags } buildOutputs := atc.AggregatePlan{} for i, output := range outputs { writePipe, err := atcRequester.CreateRequest( atc.WritePipe, rata.Params{"pipe_id": output.Pipe.ID}, nil, ) if err != nil { return atc.Build{}, err } source := atc.Source{ "uri": writePipe.URL.String(), } params := atc.Params{ "directory": output.Name, } if targetProps.Token != nil { source["authorization"] = targetProps.Token.Type + " " + targetProps.Token.Value } buildOutputs = append(buildOutputs, atc.Plan{ Location: &atc.Location{ ID: taskPlan.Location.ID + 2 + uint(i), ParentID: 0, ParallelGroup: taskPlan.Location.ID + 1, }, Put: &atc.PutPlan{ Name: output.Name, Type: "archive", Source: source, Params: params, }, }) } var plan atc.Plan if len(buildOutputs) == 0 { plan = atc.Plan{ OnSuccess: &atc.OnSuccessPlan{ Step: atc.Plan{ Aggregate: &buildInputs, }, Next: taskPlan, }, } } else { plan = atc.Plan{ OnSuccess: &atc.OnSuccessPlan{ Step: atc.Plan{ Aggregate: &buildInputs, }, Next: atc.Plan{ Ensure: &atc.EnsurePlan{ Step: taskPlan, Next: atc.Plan{ Aggregate: &buildOutputs, }, }, }, }, } } return client.CreateBuild(plan) }
Describe("Insecure Flag", func() { Describe("when 'insecure' is set to false in the flyrc", func() { var targetName string BeforeEach(func() { targetName = "foo" err := rc.SaveTarget( targetName, "some api url", false, nil, ) Expect(err).ToNot(HaveOccurred()) }) It("returns the rc insecure flag as false", func() { returnedTarget, err := rc.SelectTarget(targetName) Expect(err).NotTo(HaveOccurred()) Expect(returnedTarget.Insecure).To(BeFalse()) }) }) Describe("when 'insecure' is set to true in the flyrc", func() { var targetName string BeforeEach(func() { targetName = "foo" err := rc.SaveTarget( targetName, "some api url", true, nil, )
func (command *HijackCommand) Execute(args []string) error { target, err := rc.SelectTarget(Fly.Target) if err != nil { log.Fatalln(err) return nil } containers := getContainerIDs(command) var id string if len(containers) == 0 { fmt.Fprintln(os.Stderr, "no containers matched your search parameters! they may have expired if your build hasn't recently finished") os.Exit(1) } else if len(containers) > 1 { var choices []interact.Choice for _, container := range containers { var infos []string if container.PipelineName != "" { infos = append(infos, fmt.Sprintf("pipeline: %s", container.PipelineName)) } if container.BuildID != 0 { infos = append(infos, fmt.Sprintf("build id: %d", container.BuildID)) } infos = append(infos, fmt.Sprintf("type: %s", container.Type)) infos = append(infos, fmt.Sprintf("name: %s", container.Name)) choices = append(choices, interact.Choice{ Display: strings.Join(infos, ", "), Value: container.ID, }) } err = interact.NewInteraction("choose a container", choices...).Resolve(&id) if err == io.EOF { os.Exit(0) } if err != nil { return err } } else { id = containers[0].ID } path, args := remoteCommand(args) privileged := true reqGenerator := rata.NewRequestGenerator(target.API, atc.Routes) tlsConfig := &tls.Config{InsecureSkipVerify: target.Insecure} var ttySpec *atc.HijackTTYSpec rows, cols, err := pty.Getsize(os.Stdin) if err == nil { ttySpec = &atc.HijackTTYSpec{ WindowSize: atc.HijackWindowSize{ Columns: cols, Rows: rows, }, } } spec := atc.HijackProcessSpec{ Path: path, Args: args, Env: []string{"TERM=" + os.Getenv("TERM")}, User: "******", Privileged: privileged, TTY: ttySpec, } hijackReq := constructRequest(reqGenerator, spec, id, target.Token) hijackResult := performHijack(hijackReq, tlsConfig) os.Exit(hijackResult) return nil }
func (command *HijackCommand) Execute(args []string) error { target, err := rc.SelectTarget(Fly.Target) if err != nil { return err } containers, err := getContainerIDs(command) if err != nil { return err } var chosenContainer atc.Container if len(containers) == 0 { displayhelpers.Failf("no containers matched your search parameters!\n\nthey may have expired if your build hasn't recently finished.") } else if len(containers) > 1 { var choices []interact.Choice for _, container := range containers { var infos []string if container.BuildID != 0 { if container.JobName != "" { infos = append(infos, fmt.Sprintf("build #%s", container.BuildName)) } else { infos = append(infos, fmt.Sprintf("build id: %d", container.BuildID)) } } if container.StepType != "" { infos = append(infos, fmt.Sprintf("step: %s", container.StepName)) infos = append(infos, fmt.Sprintf("type: %s", container.StepType)) } else if container.ResourceName != "" { infos = append(infos, fmt.Sprintf("resource: %s", container.ResourceName)) infos = append(infos, "type: check") } else { infos = append(infos, fmt.Sprintf("step: %s", container.StepName)) infos = append(infos, "type: check") } if len(container.Attempts) != 0 { attempt := SliceItoa(container.Attempts) infos = append(infos, fmt.Sprintf("attempt: %s", attempt)) } choices = append(choices, interact.Choice{ Display: strings.Join(infos, ", "), Value: container, }) } err = interact.NewInteraction("choose a container", choices...).Resolve(&chosenContainer) if err == io.EOF { return nil } if err != nil { return err } } else { chosenContainer = containers[0] } path, args := remoteCommand(args) privileged := true reqGenerator := rata.NewRequestGenerator(target.API, atc.Routes) tlsConfig := &tls.Config{InsecureSkipVerify: target.Insecure} var ttySpec *atc.HijackTTYSpec rows, cols, err := pty.Getsize(os.Stdin) if err == nil { ttySpec = &atc.HijackTTYSpec{ WindowSize: atc.HijackWindowSize{ Columns: cols, Rows: rows, }, } } envVariables := append(chosenContainer.EnvironmentVariables, "TERM="+os.Getenv("TERM")) spec := atc.HijackProcessSpec{ Path: path, Args: args, Env: envVariables, User: chosenContainer.User, Dir: chosenContainer.WorkingDirectory, Privileged: privileged, TTY: ttySpec, } result, err := func() (int, error) { // so the term.Restore() can run before the os.Exit() var in io.Reader term, err := pty.OpenRawTerm() if err == nil { defer term.Restore() in = term } else { in = os.Stdin } io := hijacker.ProcessIO{ In: in, Out: os.Stdout, Err: os.Stderr, } h := hijacker.New(tlsConfig, reqGenerator, target.Token) return h.Hijack(chosenContainer.ID, spec, io) }() if err != nil { return err } os.Exit(result) return nil }
func CreateBuild( client concourse.Client, privileged bool, inputs []Input, outputs []Output, config atc.TaskConfig, tags []string, target rc.TargetName, ) (atc.Build, error) { fact := atc.NewPlanFactory(time.Now().Unix()) if err := config.Validate(); err != nil { return atc.Build{}, err } targetProps, err := rc.SelectTarget(target) if err != nil { return atc.Build{}, err } buildInputs := atc.AggregatePlan{} for _, input := range inputs { var getPlan atc.GetPlan if input.Path != "" { source := atc.Source{ "uri": input.Pipe.ReadURL, } if auth, ok := targetAuthorization(targetProps.Token); ok { source["authorization"] = auth } getPlan = atc.GetPlan{ Name: input.Name, Type: "archive", Source: source, } } else { getPlan = atc.GetPlan{ Name: input.Name, Type: input.BuildInput.Type, Source: input.BuildInput.Source, Version: input.BuildInput.Version, Params: input.BuildInput.Params, Tags: input.BuildInput.Tags, } } buildInputs = append(buildInputs, fact.NewPlan(getPlan)) } taskPlan := fact.NewPlan(atc.TaskPlan{ Name: "one-off", Privileged: privileged, Config: &config, }) if len(tags) != 0 { taskPlan.Task.Tags = tags } buildOutputs := atc.AggregatePlan{} for _, output := range outputs { source := atc.Source{ "uri": output.Pipe.ReadURL, } params := atc.Params{ "directory": output.Name, } if auth, ok := targetAuthorization(targetProps.Token); ok { source["authorization"] = auth } buildOutputs = append(buildOutputs, fact.NewPlan(atc.PutPlan{ Name: output.Name, Type: "archive", Source: source, Params: params, })) } var plan atc.Plan if len(buildOutputs) == 0 { plan = fact.NewPlan(atc.DoPlan{ fact.NewPlan(buildInputs), taskPlan, }) } else { plan = fact.NewPlan(atc.EnsurePlan{ Step: fact.NewPlan(atc.DoPlan{ fact.NewPlan(buildInputs), taskPlan, }), Next: fact.NewPlan(buildOutputs), }) } return client.CreateBuild(plan) }
Describe("when 'insecure' is set to false in the flyrc", func() { var targetName rc.TargetName BeforeEach(func() { targetName = "foo" err := rc.SaveTarget( targetName, "some api url", false, nil, ) Expect(err).ToNot(HaveOccurred()) }) It("returns the rc insecure flag as false", func() { returnedTarget, err := rc.SelectTarget(targetName) Expect(err).ToNot(HaveOccurred()) Expect(returnedTarget.Insecure).To(BeFalse()) }) }) Describe("when 'insecure' is set to true in the flyrc", func() { var targetName rc.TargetName BeforeEach(func() { targetName = "foo" err := rc.SaveTarget( targetName, "some api url", true, nil,
func CreateBuild( atcRequester *deprecated.AtcRequester, client concourse.Client, privileged bool, inputs []Input, outputs []Output, config atc.TaskConfig, tags []string, target string, ) (atc.Build, error) { fact := atc.NewPlanFactory(time.Now().Unix()) if err := config.Validate(); err != nil { return atc.Build{}, err } targetProps, err := rc.SelectTarget(target) if err != nil { return atc.Build{}, err } buildInputs := atc.AggregatePlan{} for _, input := range inputs { var getPlan atc.GetPlan if input.Path != "" { readPipe, err := atcRequester.CreateRequest( atc.ReadPipe, rata.Params{"pipe_id": input.Pipe.ID}, nil, ) if err != nil { return atc.Build{}, err } source := atc.Source{ "uri": readPipe.URL.String(), } if targetProps.Token != nil { source["authorization"] = targetProps.Token.Type + " " + targetProps.Token.Value } getPlan = atc.GetPlan{ Name: input.Name, Type: "archive", Source: source, } } else { getPlan = atc.GetPlan{ Name: input.Name, Type: input.BuildInput.Type, Source: input.BuildInput.Source, Version: input.BuildInput.Version, Params: input.BuildInput.Params, Tags: input.BuildInput.Tags, } } buildInputs = append(buildInputs, fact.NewPlan(getPlan)) } taskPlan := fact.NewPlan(atc.TaskPlan{ Name: "one-off", Privileged: privileged, Config: &config, }) if len(tags) != 0 { taskPlan.Task.Tags = tags } buildOutputs := atc.AggregatePlan{} for _, output := range outputs { writePipe, err := atcRequester.CreateRequest( atc.WritePipe, rata.Params{"pipe_id": output.Pipe.ID}, nil, ) if err != nil { return atc.Build{}, err } source := atc.Source{ "uri": writePipe.URL.String(), } params := atc.Params{ "directory": output.Name, } if targetProps.Token != nil { source["authorization"] = targetProps.Token.Type + " " + targetProps.Token.Value } buildOutputs = append(buildOutputs, fact.NewPlan(atc.PutPlan{ Name: output.Name, Type: "archive", Source: source, Params: params, })) } var plan atc.Plan if len(buildOutputs) == 0 { plan = fact.NewPlan(atc.DoPlan{ fact.NewPlan(buildInputs), taskPlan, }) } else { plan = fact.NewPlan(atc.DoPlan{ fact.NewPlan(buildInputs), fact.NewPlan(atc.EnsurePlan{ Step: taskPlan, Next: fact.NewPlan(buildOutputs), }), }) } return client.CreateBuild(plan) }