github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/apigw/dedicated/v2/appauths/results.go (about)

     1  package appauths
     2  
     3  import "github.com/chnsz/golangsdk/pagination"
     4  
     5  type createResp struct {
     6  	// App authorization records.
     7  	Auths []Authorization `json:"auths"`
     8  }
     9  
    10  // Authorization is the struct that represents the application authorization records.
    11  type Authorization struct {
    12  	// The application ID.
    13  	ApiId string `json:"api_id"`
    14  	// The authorization result.
    15  	AuthResult AuthResult `json:"auth_result"`
    16  	// The authorization time.
    17  	AuthTime string `json:"auth_time"`
    18  	// The authorization record ID.
    19  	ID string `json:"id"`
    20  	// The ID of the application allowed to access the API.
    21  	AppId string `json:"app_id"`
    22  	// The authorizer.
    23  	// + PROVIDER: API provider
    24  	// + CONSUMER: API user
    25  	AuthRole string `json:"auth_role"`
    26  	// Authorization channel type.
    27  	// + NORMAL: normal channel
    28  	// + GREEN: green channel
    29  	// The default value is NORMAL.
    30  	AuthTunnel string `json:"auth_tunnel"`
    31  	// Whitelist for the green channel.
    32  	AuthWhitelist []string `json:"auth_whitelist"`
    33  	// Blacklist for the green channel.
    34  	AuthBlacklist []string `json:"auth_blacklist"`
    35  	// Access parameters.
    36  	VisitParams string `json:"visit_params"`
    37  }
    38  
    39  // AuthResult is the structure that represents the authorization details.
    40  type AuthResult struct {
    41  	// Authorization result.
    42  	// + SUCCESS
    43  	// + SKIPPED
    44  	// + FAILED
    45  	Status string `json:"status"`
    46  	// Error message.
    47  	ErrorMsg string `json:"error_msg"`
    48  	// Error code.
    49  	ErrorCode string `json:"error_code"`
    50  	// Name of the API for which authorization fails.
    51  	ApiName string `json:"api_name"`
    52  	// Name of the app that fails to be authorized.
    53  	AppName string `json:"app_name"`
    54  }
    55  
    56  // AuthorizedPage is a page structure that represents each page information.
    57  type AuthorizedPage struct {
    58  	pagination.OffsetPageBase
    59  }
    60  
    61  // IsEmpty checks whether a AuthorizedPage struct is empty.
    62  func (b AuthorizedPage) IsEmpty() (bool, error) {
    63  	arr, err := ExtractAuthorizedApis(b)
    64  	return len(arr) == 0, err
    65  }
    66  
    67  // ExtractAuthorizedApis is a method to extract the list of authorized APIs for specified application.
    68  func ExtractAuthorizedApis(r pagination.Page) ([]ApiAuthInfo, error) {
    69  	var s []ApiAuthInfo
    70  	err := r.(AuthorizedPage).Result.ExtractIntoSlicePtr(&s, "auths")
    71  	return s, err
    72  }
    73  
    74  // ApiAuthInfo is the structure that represents the authorized API information.
    75  type ApiAuthInfo struct {
    76  	// Authorization record ID.
    77  	ID string `json:"id"`
    78  	// The API ID.
    79  	ApiId string `json:"api_id"`
    80  	// The API name.
    81  	ApiName string `json:"api_name"`
    82  	// Name of the API group to which the API belongs.
    83  	GroupName string `json:"group_name"`
    84  	// API type.
    85  	ApiType int `json:"api_type"`
    86  	// API description.
    87  	ApiRemark string `json:"api_remark"`
    88  	// ID of the environment in which an app has been authorized to call the API.
    89  	EnvId string `json:"env_id"`
    90  	// Authorizer.
    91  	AuthRole string `json:"auth_role"`
    92  	// Authorization time.
    93  	AuthTime string `json:"auth_time"`
    94  	// Application name.
    95  	AppName string `json:"app_name"`
    96  	// Application description.
    97  	AppRemark string `json:"app_remark"`
    98  	// Application type.
    99  	AppType string `json:"app_type"`
   100  	// Creator of the app.
   101  	// + USER: The app is created by a tenant.
   102  	// + MARKET: The app is allocated by KooGallery.
   103  	AppCreator string `json:"app_creator"`
   104  	// API publication record ID.
   105  	PublishId string `json:"publish_id"`
   106  	// ID of the API group to which the API belongs.
   107  	GroupId string `json:"group_id"`
   108  	// Authorization channel type.
   109  	// + NORMAL: normal channel
   110  	// + GREEN: green channel
   111  	AuthTunnel string `json:"auth_tunnel"`
   112  	// Whitelist for the green channel.
   113  	AuthWhitelist []string `json:"auth_whitelist"`
   114  	// Blacklist for the green channel.
   115  	AuthBlacklist []string `json:"auth_blacklist"`
   116  	// Access parameters.
   117  	VisitParams string `json:"visit_params"`
   118  	// ROMA application type.
   119  	// + subscription: subscription application
   120  	// + integration: integration application
   121  	RomaAppType string `json:"roma_app_type"`
   122  	// Name of the environment in which the app has been authorized to call the API.
   123  	EnvName string `json:"env_name"`
   124  	// Application ID.
   125  	AppId string `json:"app_id"`
   126  }
   127  
   128  // UnauthorizedPage is a page structure that represents each page information.
   129  type UnauthorizedPage struct {
   130  	pagination.OffsetPageBase
   131  }
   132  
   133  // IsEmpty checks whether a UnauthorizedPage struct is empty.
   134  func (b UnauthorizedPage) IsEmpty() (bool, error) {
   135  	arr, err := ExtractUnauthorizedApis(b)
   136  	return len(arr) == 0, err
   137  }
   138  
   139  // ExtractUnauthorizedApis is a method to extract the list of unauthorized APIs for specified application.
   140  func ExtractUnauthorizedApis(r pagination.Page) ([]ApiOutlineInfo, error) {
   141  	var s []ApiOutlineInfo
   142  	err := r.(UnauthorizedPage).Result.ExtractIntoSlicePtr(&s, "apis")
   143  	return s, err
   144  }
   145  
   146  // ApiOutlineInfo is the structure that represents the unauthorized API information.
   147  type ApiOutlineInfo struct {
   148  	// API authentication mode.
   149  	AuthType string `json:"auth_type"`
   150  	// Name of the environment in which the API has been published.
   151  	RunEnvName string `json:"run_env_name"`
   152  	// Name of the API group to which the API belongs.
   153  	GroupName string `json:"group_name"`
   154  	// Publication record ID.
   155  	PublishId string `json:"publish_id"`
   156  	// ID of the API group to which the API belongs.
   157  	GroupId string `json:"group_id"`
   158  	// API name.
   159  	Name string `json:"name"`
   160  	// API description.
   161  	Remark string `json:"remark"`
   162  	// ID of the environment in which the API has been published.
   163  	RunEnvId string `json:"run_env_id"`
   164  	// Application ID.
   165  	ID string `json:"id"`
   166  	// API request address.
   167  	ReqUri string `json:"req_uri"`
   168  }