Skip to content

Commit

Permalink
Refactored and tested SerializeForLogging
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobht committed Oct 31, 2024
1 parent 40003fc commit e8cda72
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 719 deletions.
22 changes: 22 additions & 0 deletions common/authorization/authorizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,28 @@ type FilteredRequestBody interface {
SerializeForLogging() (string, error)
}

type simpleRequestLogWrapper struct {
request interface{}
}

func (f *simpleRequestLogWrapper) SerializeForLogging() (string, error) {
return types.SerializeRequest(f.request)
}

type nullRequestLogWrapper struct{}

func (f *nullRequestLogWrapper) SerializeForLogging() (string, error) {
return "", nil
}

func NewFilteredRequestBody(request interface{}) FilteredRequestBody {
if request == nil {
return &nullRequestLogWrapper{}
}

return &simpleRequestLogWrapper{request}
}

func validatePermission(claims *JWTClaims, attributes *Attributes, data domainData) error {
if (attributes.Permission < PermissionRead) || (attributes.Permission > PermissionAdmin) {
return fmt.Errorf("permission %v is not supported", attributes.Permission)
Expand Down
105 changes: 0 additions & 105 deletions common/types/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ type AddSearchAttributeRequest struct {
SecurityToken string `json:"securityToken,omitempty"`
}

func (v *AddSearchAttributeRequest) SerializeForLogging() (string, error) {
if v == nil {
return "", nil
}
return SerializeRequest(v)
}

// GetSearchAttribute is an internal getter (TBD...)
func (v *AddSearchAttributeRequest) GetSearchAttribute() (o map[string]IndexedValueType) {
if v != nil && v.SearchAttribute != nil {
Expand All @@ -56,13 +49,6 @@ type AdminDescribeWorkflowExecutionRequest struct {
Execution *WorkflowExecution `json:"execution,omitempty"`
}

func (v *AdminDescribeWorkflowExecutionRequest) SerializeForLogging() (string, error) {
if v == nil {
return "", nil
}
return SerializeRequest(v)
}

// GetDomain is an internal getter (TBD...)
func (v *AdminDescribeWorkflowExecutionRequest) GetDomain() (o string) {
if v != nil {
Expand Down Expand Up @@ -107,13 +93,6 @@ type GetWorkflowExecutionRawHistoryV2Request struct {
NextPageToken []byte `json:"nextPageToken,omitempty"`
}

func (v *GetWorkflowExecutionRawHistoryV2Request) SerializeForLogging() (string, error) {
if v == nil {
return "", nil
}
return SerializeRequest(v)
}

// GetDomain is an internal getter (TBD...)
func (v *GetWorkflowExecutionRawHistoryV2Request) GetDomain() (o string) {
if v != nil {
Expand Down Expand Up @@ -229,13 +208,6 @@ type ResendReplicationTasksRequest struct {
EndVersion *int64 `json:"endVersion,omitempty"`
}

func (v *ResendReplicationTasksRequest) SerializeForLogging() (string, error) {
if v == nil {
return "", nil
}
return SerializeRequest(v)
}

// GetWorkflowID is an internal getter (TBD...)
func (v *ResendReplicationTasksRequest) GetWorkflowID() (o string) {
if v != nil {
Expand Down Expand Up @@ -272,13 +244,6 @@ type GetDynamicConfigRequest struct {
Filters []*DynamicConfigFilter `json:"filters,omitempty"`
}

func (v *GetDynamicConfigRequest) SerializeForLogging() (string, error) {
if v == nil {
return "", nil
}
return SerializeRequest(v)
}

type GetDynamicConfigResponse struct {
Value *DataBlob `json:"value,omitempty"`
}
Expand All @@ -288,39 +253,18 @@ type UpdateDynamicConfigRequest struct {
ConfigValues []*DynamicConfigValue `json:"configValues,omitempty"`
}

func (v *UpdateDynamicConfigRequest) SerializeForLogging() (string, error) {
if v == nil {
return "", nil
}
return SerializeRequest(v)
}

type RestoreDynamicConfigRequest struct {
ConfigName string `json:"configName,omitempty"`
Filters []*DynamicConfigFilter `json:"filters,omitempty"`
}

func (v *RestoreDynamicConfigRequest) SerializeForLogging() (string, error) {
if v == nil {
return "", nil
}
return SerializeRequest(v)
}

// AdminDeleteWorkflowRequest is an internal type (TBD...)
type AdminDeleteWorkflowRequest struct {
Domain string `json:"domain,omitempty"`
Execution *WorkflowExecution `json:"execution,omitempty"`
SkipErrors bool `json:"skipErrors,omitempty"`
}

func (v *AdminDeleteWorkflowRequest) SerializeForLogging() (string, error) {
if v == nil {
return "", nil
}
return SerializeRequest(v)
}

func (v *AdminDeleteWorkflowRequest) GetDomain() (o string) {
if v != nil {
return v.Domain
Expand Down Expand Up @@ -356,13 +300,6 @@ type ListDynamicConfigRequest struct {
ConfigName string `json:"configName,omitempty"`
}

func (v *ListDynamicConfigRequest) SerializeForLogging() (string, error) {
if v == nil {
return "", nil
}
return SerializeRequest(v)
}

type ListDynamicConfigResponse struct {
Entries []*DynamicConfigEntry `json:"entries,omitempty"`
}
Expand Down Expand Up @@ -434,13 +371,6 @@ func FromIsolationGroupPartitionList(in []IsolationGroupPartition) IsolationGrou

type GetGlobalIsolationGroupsRequest struct{}

func (v *GetGlobalIsolationGroupsRequest) SerializeForLogging() (string, error) {
if v == nil {
return "", nil
}
return SerializeRequest(v)
}

type GetGlobalIsolationGroupsResponse struct {
IsolationGroups IsolationGroupConfiguration
}
Expand All @@ -449,26 +379,12 @@ type UpdateGlobalIsolationGroupsRequest struct {
IsolationGroups IsolationGroupConfiguration
}

func (v *UpdateGlobalIsolationGroupsRequest) SerializeForLogging() (string, error) {
if v == nil {
return "", nil
}
return SerializeRequest(v)
}

type UpdateGlobalIsolationGroupsResponse struct{}

type GetDomainIsolationGroupsRequest struct {
Domain string
}

func (v *GetDomainIsolationGroupsRequest) SerializeForLogging() (string, error) {
if v == nil {
return "", nil
}
return SerializeRequest(v)
}

type GetDomainIsolationGroupsResponse struct {
IsolationGroups IsolationGroupConfiguration
}
Expand All @@ -478,26 +394,12 @@ type UpdateDomainIsolationGroupsRequest struct {
IsolationGroups IsolationGroupConfiguration
}

func (v *UpdateDomainIsolationGroupsRequest) SerializeForLogging() (string, error) {
if v == nil {
return "", nil
}
return SerializeRequest(v)
}

type UpdateDomainIsolationGroupsResponse struct{}

type GetDomainAsyncWorkflowConfiguratonRequest struct {
Domain string
}

func (v *GetDomainAsyncWorkflowConfiguratonRequest) SerializeForLogging() (string, error) {
if v == nil {
return "", nil
}
return SerializeRequest(v)
}

type GetDomainAsyncWorkflowConfiguratonResponse struct {
Configuration *AsyncWorkflowConfiguration
}
Expand Down Expand Up @@ -525,12 +427,5 @@ type UpdateDomainAsyncWorkflowConfiguratonRequest struct {
Configuration *AsyncWorkflowConfiguration
}

func (v *UpdateDomainAsyncWorkflowConfiguratonRequest) SerializeForLogging() (string, error) {
if v == nil {
return "", nil
}
return SerializeRequest(v)
}

type UpdateDomainAsyncWorkflowConfiguratonResponse struct {
}
Loading

0 comments on commit e8cda72

Please sign in to comment.