github.com/vmware/govmomi@v0.51.0/vapi/library/security_policy.go (about)

     1  // © Broadcom. All Rights Reserved.
     2  // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package library
     6  
     7  import (
     8  	"context"
     9  	"errors"
    10  	"net/http"
    11  
    12  	"github.com/vmware/govmomi/vapi/internal"
    13  )
    14  
    15  const (
    16  	OvfDefaultSecurityPolicy = "OVF default policy"
    17  )
    18  
    19  // ContentSecurityPoliciesInfo contains information on security policies that can
    20  // be used to describe security for content library items.
    21  type ContentSecurityPoliciesInfo struct {
    22  	// ItemTypeRules are rules governing the policy.
    23  	ItemTypeRules map[string]string `json:"item_type_rules"`
    24  	// Name is a human-readable identifier identifying the policy.
    25  	Name string `json:"name"`
    26  	// Policy is the unique identifier for a policy.
    27  	Policy string `json:"policy"`
    28  }
    29  
    30  // ListSecurityPolicies lists security policies
    31  func (c *Manager) ListSecurityPolicies(ctx context.Context) ([]ContentSecurityPoliciesInfo, error) {
    32  	url := c.Resource(internal.SecurityPoliciesPath)
    33  	var res []ContentSecurityPoliciesInfo
    34  	return res, c.Do(ctx, url.Request(http.MethodGet), &res)
    35  }
    36  
    37  func (c *Manager) DefaultOvfSecurityPolicy(ctx context.Context) (string, error) {
    38  	res, err := c.ListSecurityPolicies(ctx)
    39  
    40  	if err != nil {
    41  		return "", err
    42  	}
    43  
    44  	for _, policy := range res {
    45  		if policy.Name == OvfDefaultSecurityPolicy {
    46  			return policy.Policy, nil
    47  		}
    48  	}
    49  
    50  	return "", errors.New("failed to find default ovf security policy")
    51  }