LoadPolicyGroup loads a group (unmarshalls it) from a group attachment
(ctx context.Context, att *v1.PolicyGroupAttachment, opts *LoadPolicyGroupOptions)
| 240 | |
| 241 | // LoadPolicyGroup loads a group (unmarshalls it) from a group attachment |
| 242 | func LoadPolicyGroup(ctx context.Context, att *v1.PolicyGroupAttachment, opts *LoadPolicyGroupOptions) (*v1.PolicyGroup, *PolicyDescriptor, error) { |
| 243 | loader, err := getGroupLoader(att, opts) |
| 244 | if err != nil { |
| 245 | return nil, nil, fmt.Errorf("failed to get a loader for policy group: %w", err) |
| 246 | } |
| 247 | |
| 248 | group, ref, err := loader.Load(ctx, att) |
| 249 | if err != nil { |
| 250 | return nil, nil, fmt.Errorf("failed to load policy group: %w", err) |
| 251 | } |
| 252 | |
| 253 | // Validate just in case |
| 254 | if err = validateResource(group); err != nil { |
| 255 | return nil, nil, err |
| 256 | } |
| 257 | |
| 258 | return group, ref, nil |
| 259 | } |
| 260 | |
| 261 | // getGroupLoader creates a suitable group loader for a group attachment |
| 262 | func getGroupLoader(attachment *v1.PolicyGroupAttachment, opts *LoadPolicyGroupOptions) (GroupLoader, error) { |