cacheControls caches the catalog controls for the given catalog.
(catalogId string)
| 843 | |
| 844 | // cacheControls caches the catalog controls for the given catalog. |
| 845 | func (svc *Service) cacheControls(catalogId string) error { |
| 846 | var ( |
| 847 | err error |
| 848 | tag string |
| 849 | controls []*orchestrator.Control |
| 850 | ) |
| 851 | |
| 852 | if catalogId == "" { |
| 853 | return ErrCatalogIdIsMissing |
| 854 | } |
| 855 | |
| 856 | // Get controls for given catalog |
| 857 | controls, err = api.ListAllPaginated[*orchestrator.ListControlsResponse](&orchestrator.ListControlsRequest{ |
| 858 | CatalogId: catalogId, |
| 859 | }, svc.orchestrator.Client.ListControls, func(res *orchestrator.ListControlsResponse) []*orchestrator.Control { |
| 860 | return res.Controls |
| 861 | }) |
| 862 | if err != nil { |
| 863 | return err |
| 864 | } |
| 865 | |
| 866 | if len(controls) == 0 { |
| 867 | return fmt.Errorf("no controls for catalog '%s' available", catalogId) |
| 868 | } |
| 869 | |
| 870 | // Store controls in map |
| 871 | svc.catalogControls[catalogId] = make(map[string]*orchestrator.Control) |
| 872 | for _, control := range controls { |
| 873 | tag = fmt.Sprintf("%s-%s", control.GetCategoryName(), control.GetId()) |
| 874 | svc.catalogControls[catalogId][tag] = control |
| 875 | } |
| 876 | |
| 877 | return nil |
| 878 | } |
| 879 | |
| 880 | // getControl returns the control for the given catalogID, CategoryName and controlID. |
| 881 | func (svc *Service) getControl(catalogId, categoryName, controlId string) (control *orchestrator.Control, err error) { |