github.com/qiniu/go-sdk/v7@v7.27.0/iam/apis/get_group_service_action_resources/api.go (about)

     1  // THIS FILE IS GENERATED BY api-generator, DO NOT EDIT DIRECTLY!
     2  
     3  // 列举用户分组指定服务操作下的可访问资源
     4  package get_group_service_action_resources
     5  
     6  import (
     7  	"encoding/json"
     8  
     9  	credentials "github.com/qiniu/go-sdk/v7/storagev2/credentials"
    10  	errors "github.com/qiniu/go-sdk/v7/storagev2/errors"
    11  )
    12  
    13  // 调用 API 所用的请求
    14  type Request struct {
    15  	GroupAlias  string                          // 用户分组别名
    16  	Service     string                          // 资源操作关联的服务
    17  	ActionAlias string                          // 资源操作别名
    18  	Credentials credentials.CredentialsProvider // 鉴权参数,用于生成鉴权凭证,如果为空,则使用 HTTPClientOptions 中的 CredentialsProvider
    19  }
    20  
    21  // 获取 API 所用的响应
    22  type Response struct {
    23  	Data GetGroupServiceActionResources // 用户分组指定服务操作下的可访问资源列表信息
    24  }
    25  
    26  // 可用资源列表
    27  type AllowedResources = []string
    28  
    29  // 禁用资源列表
    30  type DeniedResources = []string
    31  
    32  // 用户分组指定服务操作下的可访问资源列表信息
    33  type Data struct {
    34  	AllowedResources AllowedResources // 可用资源
    35  	DeniedResources  DeniedResources  // 禁用资源
    36  }
    37  
    38  // 返回的用户分组指定服务操作下的可访问资源列表信息
    39  type (
    40  	GetGroupServiceActionResources = Data
    41  	jsonData                       struct {
    42  		AllowedResources AllowedResources `json:"allow"` // 可用资源
    43  		DeniedResources  DeniedResources  `json:"deny"`  // 禁用资源
    44  	}
    45  )
    46  
    47  func (j *Data) MarshalJSON() ([]byte, error) {
    48  	if err := j.validate(); err != nil {
    49  		return nil, err
    50  	}
    51  	return json.Marshal(&jsonData{AllowedResources: j.AllowedResources, DeniedResources: j.DeniedResources})
    52  }
    53  
    54  func (j *Data) UnmarshalJSON(data []byte) error {
    55  	var nj jsonData
    56  	if err := json.Unmarshal(data, &nj); err != nil {
    57  		return err
    58  	}
    59  	j.AllowedResources = nj.AllowedResources
    60  	j.DeniedResources = nj.DeniedResources
    61  	return nil
    62  }
    63  
    64  func (j *Data) validate() error {
    65  	if len(j.AllowedResources) == 0 {
    66  		return errors.MissingRequiredFieldError{Name: "AllowedResources"}
    67  	}
    68  	if len(j.DeniedResources) == 0 {
    69  		return errors.MissingRequiredFieldError{Name: "DeniedResources"}
    70  	}
    71  	return nil
    72  }
    73  
    74  // 返回的用户分组指定服务操作下的可访问资源列表响应
    75  type (
    76  	GetGroupServiceActionResourcesResp = Response
    77  	jsonResponse                       struct {
    78  		Data GetGroupServiceActionResources `json:"data"` // 用户分组指定服务操作下的可访问资源列表信息
    79  	}
    80  )
    81  
    82  func (j *Response) MarshalJSON() ([]byte, error) {
    83  	if err := j.validate(); err != nil {
    84  		return nil, err
    85  	}
    86  	return json.Marshal(&jsonResponse{Data: j.Data})
    87  }
    88  
    89  func (j *Response) UnmarshalJSON(data []byte) error {
    90  	var nj jsonResponse
    91  	if err := json.Unmarshal(data, &nj); err != nil {
    92  		return err
    93  	}
    94  	j.Data = nj.Data
    95  	return nil
    96  }
    97  
    98  func (j *Response) validate() error {
    99  	if err := j.Data.validate(); err != nil {
   100  		return err
   101  	}
   102  	return nil
   103  }