createEnvironment creates a new environment. The created environment will be appended to the existing environments. It returns the created environment.
(ctx context.Context, id, title string)
| 32 | // The created environment will be appended to the existing environments. |
| 33 | // It returns the created environment. |
| 34 | func (ctl *controller) createEnvironment(ctx context.Context, id, title string) (*v1pb.EnvironmentSetting_Environment, error) { |
| 35 | resp, err := ctl.settingServiceClient.GetSetting(ctx, |
| 36 | connect.NewRequest(&v1pb.GetSettingRequest{ |
| 37 | Name: "settings/" + v1pb.Setting_ENVIRONMENT.String(), |
| 38 | })) |
| 39 | if err != nil { |
| 40 | return nil, err |
| 41 | } |
| 42 | environments := resp.Msg.Value.GetEnvironment().GetEnvironments() |
| 43 | environments = append(environments, &v1pb.EnvironmentSetting_Environment{ |
| 44 | Id: id, |
| 45 | Title: title, |
| 46 | }) |
| 47 | _, err = ctl.settingServiceClient.UpdateSetting(ctx, |
| 48 | connect.NewRequest(&v1pb.UpdateSettingRequest{ |
| 49 | Setting: &v1pb.Setting{ |
| 50 | Name: "settings/" + v1pb.Setting_ENVIRONMENT.String(), |
| 51 | Value: &v1pb.SettingValue{ |
| 52 | Value: &v1pb.SettingValue_Environment{ |
| 53 | Environment: &v1pb.EnvironmentSetting{ |
| 54 | Environments: environments, |
| 55 | }, |
| 56 | }, |
| 57 | }, |
| 58 | }, |
| 59 | UpdateMask: &fieldmaskpb.FieldMask{ |
| 60 | Paths: []string{"environment"}, |
| 61 | }, |
| 62 | })) |
| 63 | if err != nil { |
| 64 | return nil, err |
| 65 | } |
| 66 | return ctl.getEnvironment(ctx, id) |
| 67 | } |