(ctx context.Context, role permission.Role, contextValue string)
| 642 | } |
| 643 | |
| 644 | func validateContextValue(ctx context.Context, role permission.Role, contextValue string) error { |
| 645 | if contextValue == "" && role.ContextType != permTypes.CtxGlobal { |
| 646 | return &errors.ValidationError{ |
| 647 | Message: fmt.Sprintf("Global context value is not valid for role with context type %s", role.ContextType), |
| 648 | } |
| 649 | } |
| 650 | |
| 651 | switch role.ContextType { |
| 652 | case permTypes.CtxApp: |
| 653 | if _, err := app.GetByName(ctx, contextValue); err != nil { |
| 654 | return &errors.ValidationError{Message: err.Error()} |
| 655 | } |
| 656 | case permTypes.CtxTeam: |
| 657 | if _, err := servicemanager.Team.FindByName(ctx, contextValue); err != nil { |
| 658 | return &errors.ValidationError{Message: err.Error()} |
| 659 | } |
| 660 | case permTypes.CtxUser: |
| 661 | if _, err := auth.GetUserByEmail(ctx, contextValue); err != nil { |
| 662 | return &errors.ValidationError{Message: err.Error()} |
| 663 | } |
| 664 | case permTypes.CtxPool: |
| 665 | if _, err := pool.GetPoolByName(ctx, contextValue); err != nil { |
| 666 | return &errors.ValidationError{Message: err.Error()} |
| 667 | } |
| 668 | case permTypes.CtxService: |
| 669 | if _, err := service.Get(ctx, contextValue); err != nil { |
| 670 | return &errors.ValidationError{Message: err.Error()} |
| 671 | } |
| 672 | case permTypes.CtxServiceInstance: |
| 673 | sInstances, err := service.GetServicesInstancesByTeamsAndNames(ctx, nil, []string{contextValue}, "", "", []string{}) |
| 674 | if err != nil { |
| 675 | return &errors.ValidationError{Message: err.Error()} |
| 676 | } |
| 677 | if len(sInstances) == 0 { |
| 678 | return &errors.ValidationError{Message: fmt.Sprintf("service instance %s, not found", contextValue)} |
| 679 | } |
| 680 | case permTypes.CtxVolume: |
| 681 | if _, err := servicemanager.Volume.Get(ctx, contextValue); err != nil { |
| 682 | return &errors.ValidationError{Message: err.Error()} |
| 683 | } |
| 684 | case permTypes.CtxRouter: |
| 685 | if _, err := router.Get(ctx, contextValue); err != nil { |
| 686 | return &errors.ValidationError{Message: err.Error()} |
| 687 | } |
| 688 | case permTypes.CtxJob: |
| 689 | if _, err := servicemanager.Job.GetByName(ctx, contextValue); err != nil { |
| 690 | return &errors.ValidationError{Message: err.Error()} |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | return nil |
| 695 | } |
| 696 | |
| 697 | // title: assign role to token |
| 698 | // path: /roles/{name}/token |
no test coverage detected