promptDefaultURLs checks whether the application is SPA or WebApp and whether the app has already added the default quickstart url to allowed url lists. If not, it prompts the user to add the default url and updates the application if they accept.
(ctx context.Context, cli *cli, client *management.Client, qsType string, qsStack string)
| 270 | // If not, it prompts the user to add the default url and updates the application |
| 271 | // if they accept. |
| 272 | func promptDefaultURLs(ctx context.Context, cli *cli, client *management.Client, qsType string, qsStack string) error { |
| 273 | defaultURL := defaultURLFor(qsStack) |
| 274 | defaultCallbackURL := defaultCallbackURLFor(qsStack) |
| 275 | |
| 276 | if !strings.EqualFold(qsType, qsSpa) && !strings.EqualFold(qsType, qsWebApp) { |
| 277 | return nil |
| 278 | } |
| 279 | |
| 280 | a := &management.Client{ |
| 281 | Callbacks: client.Callbacks, |
| 282 | AllowedLogoutURLs: client.AllowedLogoutURLs, |
| 283 | AllowedOrigins: client.AllowedOrigins, |
| 284 | WebOrigins: client.WebOrigins, |
| 285 | } |
| 286 | |
| 287 | if !containsStr(client.GetCallbacks(), defaultCallbackURL) { |
| 288 | callbacks := append(client.GetCallbacks(), defaultCallbackURL) |
| 289 | a.Callbacks = &callbacks |
| 290 | } |
| 291 | |
| 292 | if !containsStr(client.GetAllowedLogoutURLs(), defaultURL) { |
| 293 | allowedLogoutURLs := append(a.GetAllowedLogoutURLs(), defaultURL) |
| 294 | a.AllowedLogoutURLs = &allowedLogoutURLs |
| 295 | } |
| 296 | |
| 297 | if strings.EqualFold(qsType, qsSpa) { |
| 298 | if !containsStr(client.GetAllowedOrigins(), defaultURL) { |
| 299 | allowedOrigins := append(a.GetAllowedOrigins(), defaultURL) |
| 300 | a.AllowedOrigins = &allowedOrigins |
| 301 | } |
| 302 | |
| 303 | if !containsStr(client.GetWebOrigins(), defaultURL) { |
| 304 | webOrigins := append(a.GetWebOrigins(), defaultURL) |
| 305 | a.WebOrigins = &webOrigins |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | callbackURLChanged := len(client.GetCallbacks()) != len(a.GetCallbacks()) |
| 310 | otherURLsChanged := len(client.GetAllowedLogoutURLs()) != len(a.GetAllowedLogoutURLs()) || |
| 311 | len(client.GetAllowedOrigins()) != len(a.GetAllowedOrigins()) || |
| 312 | len(client.GetWebOrigins()) != len(a.GetWebOrigins()) |
| 313 | |
| 314 | if !callbackURLChanged && !otherURLsChanged { |
| 315 | return nil |
| 316 | } |
| 317 | |
| 318 | if confirmed := prompt.Confirm(urlPromptFor(qsType, qsStack)); confirmed { |
| 319 | err := ansi.Waiting(func() error { |
| 320 | return cli.api.Client.Update(ctx, client.GetClientID(), a) |
| 321 | }) |
| 322 | if err != nil { |
| 323 | return err |
| 324 | } |
| 325 | cli.renderer.Infof("Application successfully updated") |
| 326 | } |
| 327 | return nil |
| 328 | } |
| 329 |
no test coverage detected