git.frostfs.info/TrueCloudLab/frostfs-sdk-go@v0.0.0-20241022124111-5361f0ecebd3/client/status/apemanager.go (about)

     1  package apistatus
     2  
     3  import (
     4  	"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/apemanager"
     5  	"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status"
     6  )
     7  
     8  // APEManagerAccessDenied describes status of the failure because of the access control violation.
     9  // Instances provide Status and StatusV2 interfaces.
    10  type APEManagerAccessDenied struct {
    11  	v2 status.Status
    12  }
    13  
    14  const defaultAPEManagerAccessDeniedMsg = "apemanager access denied"
    15  
    16  func (x *APEManagerAccessDenied) Error() string {
    17  	msg := x.v2.Message()
    18  	if msg == "" {
    19  		msg = defaultAPEManagerAccessDeniedMsg
    20  	}
    21  
    22  	return errMessageStatusV2(
    23  		globalizeCodeV2(apemanager.StatusAPEManagerAccessDenied, apemanager.GlobalizeFail),
    24  		msg,
    25  	)
    26  }
    27  
    28  func (x *APEManagerAccessDenied) fromStatusV2(st *status.Status) {
    29  	x.v2 = *st
    30  }
    31  
    32  // ToStatusV2 converts APEManagerAccessDenied to v2's Status.
    33  // If the value was returned by FromStatusV2, returns the source message.
    34  // Otherwise, returns message with
    35  //   - code: APE_MANAGER_ACCESS_DENIED;
    36  //   - string message: "apemanager access denied";
    37  //   - details: empty.
    38  func (x APEManagerAccessDenied) ToStatusV2() *status.Status {
    39  	x.v2.SetCode(globalizeCodeV2(apemanager.StatusAPEManagerAccessDenied, apemanager.GlobalizeFail))
    40  	x.v2.SetMessage(defaultAPEManagerAccessDeniedMsg)
    41  	return &x.v2
    42  }
    43  
    44  // WriteReason writes human-readable access rejection reason.
    45  func (x *APEManagerAccessDenied) WriteReason(reason string) {
    46  	apemanager.WriteAccessDeniedDesc(&x.v2, reason)
    47  }
    48  
    49  // Reason returns human-readable access rejection reason returned by the server.
    50  // Returns empty value is reason is not presented.
    51  func (x APEManagerAccessDenied) Reason() string {
    52  	return apemanager.ReadAccessDeniedDesc(x.v2)
    53  }