sparse-intern-71089
04/30/2022, 3:26 PMgreat-arm-54759
04/30/2022, 3:28 PM ~ ❯ pulumi login "<s3://project-gaia?endpoint=http://localhost:4566&disableSSL=true&s3ForcePathStyle=true>" ✘ INT 11:59:49
Logged in to xpto as romulofranca (<s3://project-gaia?endpoint=http://localhost:4566&disableSSL=true&s3ForcePathStyle=true>)
great-arm-54759
04/30/2022, 3:30 PMpulumi new
:billowy-army-68599
pulumi whoami
- you need to login to a backend firstgreat-arm-54759
04/30/2022, 8:20 PMLogged in to xpto as romulofranca (<s3://project-gaia?endpoint=http://localhost:4566&disableSSL=true&s3ForcePathStyle=true>)
great-arm-54759
04/30/2022, 8:22 PMgreat-arm-54759
04/30/2022, 8:25 PMgreat-arm-54759
04/30/2022, 8:28 PMfunc CreateHandler(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json")
var createReq CreatePolicyReq
err := json.NewDecoder(req.Body).Decode(&createReq)
if err != nil {
w.WriteHeader(400)
fmt.Fprintf(w, "failed to parse create request")
return
}
ctx := context.Background()
stackName := createReq.Name
program := services.CreateStack("gaia-test-policy", "gaia-test-role")
opts := []auto.LocalWorkspaceOption{
auto.Project(workspace.Project{
Name: tokens.PackageName(stackName),
Runtime: workspace.NewProjectRuntimeInfo("go", nil),
Backend: &workspace.ProjectBackend{
URL: "<s3://project-gaia?endpoint=http://localhost:4566&disableSSL=true&s3ForcePathStyle=true>",
},
}),
}
s, err := auto.UpsertStackInlineSource(ctx, stackName, stackName, program, opts...)
//s, err := auto.NewStackInlineSource(ctx, stackName, stackName, program)
if err != nil {
if auto.IsCreateStack409Error(err) {
w.WriteHeader(409)
fmt.Fprintf(w, fmt.Sprintf("stack %q already exists", stackName))
return
}
w.WriteHeader(500)
fmt.Fprintf(w, err.Error())
return
}
s.SetConfig(ctx, "aws:region", auto.ConfigValue{Value: "eu-west-1"})
upRes, err := s.Up(ctx, optup.ProgressStreams(os.Stdout))
if err != nil {
w.WriteHeader(500)
fmt.Fprintf(w, err.Error())
return
}
response := &PolicyResponse{
Name: stackName,
PolicyArn: upRes.Outputs["policyArn"].Value.(string),
RoleArn: upRes.Outputs["roleArn"].Value.(string),
}
err = json.NewEncoder(w).Encode(&response)
if err != nil {
return
}
}
great-arm-54759
04/30/2022, 8:28 PM