github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/api/types/plugin_responses.go (about)

     1  package types
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  )
     7  
     8  // PluginsListResponse contains the response for the Engine API
     9  type PluginsListResponse []*Plugin
    10  
    11  const (
    12  	authzDriver   = "AuthzDriver"
    13  	graphDriver   = "GraphDriver"
    14  	ipamDriver    = "IpamDriver"
    15  	networkDriver = "NetworkDriver"
    16  	volumeDriver  = "VolumeDriver"
    17  )
    18  
    19  // UnmarshalJSON implements json.Unmarshaler for PluginInterfaceType
    20  func (t *PluginInterfaceType) UnmarshalJSON(p []byte) error {
    21  	versionIndex := len(p)
    22  	prefixIndex := 0
    23  	if len(p) < 2 || p[0] != '"' || p[len(p)-1] != '"' {
    24  		return fmt.Errorf("%q is not a plugin interface type", p)
    25  	}
    26  	p = p[1 : len(p)-1]
    27  loop:
    28  	for i, b := range p {
    29  		switch b {
    30  		case '.':
    31  			prefixIndex = i
    32  		case '/':
    33  			versionIndex = i
    34  			break loop
    35  		}
    36  	}
    37  	t.Prefix = string(p[:prefixIndex])
    38  	t.Capability = string(p[prefixIndex+1 : versionIndex])
    39  	if versionIndex < len(p) {
    40  		t.Version = string(p[versionIndex+1:])
    41  	}
    42  	return nil
    43  }
    44  
    45  // MarshalJSON implements json.Marshaler for PluginInterfaceType
    46  func (t *PluginInterfaceType) MarshalJSON() ([]byte, error) {
    47  	return json.Marshal(t.String())
    48  }
    49  
    50  // String implements fmt.Stringer for PluginInterfaceType
    51  func (t PluginInterfaceType) String() string {
    52  	return fmt.Sprintf("%s.%s/%s", t.Prefix, t.Capability, t.Version)
    53  }
    54  
    55  // PluginPrivilege describes a permission the user has to accept
    56  // upon installing a plugin.
    57  type PluginPrivilege struct {
    58  	Name        string
    59  	Description string
    60  	Value       []string
    61  }
    62  
    63  // PluginPrivileges is a list of PluginPrivilege
    64  type PluginPrivileges []PluginPrivilege