| 14 | } |
| 15 | |
| 16 | func MongoConsole(ctx context.Context, opts MongoConsoleOpts) error { |
| 17 | if opts.VariableName == "" { |
| 18 | opts.VariableName = "SCALINGO_MONGO" |
| 19 | } |
| 20 | mongoURL, _, _, err := dbURL(ctx, opts.App, opts.VariableName, []string{"mongodb"}) |
| 21 | if err != nil { |
| 22 | return errors.Wrapf(ctx, err, "resolve MongoDB URL from %s", opts.VariableName) |
| 23 | } |
| 24 | |
| 25 | command := []string{"dbclient-fetcher", "mongo", "&&", "mongo"} |
| 26 | if mongoURL.Query().Get("ssl") == "true" { |
| 27 | command = append(command, "--ssl", "--sslAllowInvalidCertificates") |
| 28 | } |
| 29 | |
| 30 | err = apps.Run(ctx, apps.RunOpts{ |
| 31 | DisplayCmd: "mongo-console", |
| 32 | App: opts.App, |
| 33 | Cmd: append(command, "'"+mongoURL.String()+"'"), |
| 34 | Size: opts.Size, |
| 35 | }) |
| 36 | if err != nil { |
| 37 | return errors.Newf(ctx, "fail to run MongoDB console: %v", err) |
| 38 | } |
| 39 | |
| 40 | return nil |
| 41 | } |