Skip to content

Commit

Permalink
create RequestBody struct, implement it using requests, add requestbo…
Browse files Browse the repository at this point in the history
…dy into Attribute for auditing (uber#5124)

* Revert "CDNC-2088 (uber#5094) Add attempt-count to task processing logs"

This reverts commit fbe72b3.

* experiment on adding audit info (has errorsgit status)

* move AuditInfo into Attr

* implement requestBody Struct, implement it using requests, add it into Attribute to use this field for auditing manual accesses

* change struct name to be ManualRequestBody to avoid conflict

* change any to interface to solve a compiling error

* rerun make go-generate && make fmt && make lint && make copyright for auto generated code

* change the PII-filtered request to still be a requset instead of a map

* add a utility function to check if access is manual, add request body into Attribute

* update with make go-generate && make fmt && make lint && make copyright

* update comments and naming

* change Sprintf to marshal

* add error handling for json.marshal, pass it to the caller of SerializeForLogging function

* add a new log tag for actor email address

* update interface function error handling

* pass in a pointer for serialization instead of a struct

* delete the isManual checks when creating Attributes
  • Loading branch information
bowenxia committed Mar 6, 2023
1 parent 87c91bd commit c462ec0
Show file tree
Hide file tree
Showing 8 changed files with 601 additions and 131 deletions.
38 changes: 38 additions & 0 deletions common/authorization/authority_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions common/authorization/authorizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type (
WorkflowType *types.WorkflowType
TaskList *types.TaskList
Permission Permission
RequestBody FilteredRequestBody // request object except for data inputs (PII)
}

// Result is result from authority.
Expand Down Expand Up @@ -97,3 +98,8 @@ func GetAuthProviderClient(privateKey string) (clientworker.AuthorizationProvide
}
return clientworker.NewAdminJwtAuthorizationProvider(pk), nil
}

// FilteredRequestBody request object except for data inputs (PII)
type FilteredRequestBody interface {
SerializeForLogging() (string, error)
}
10 changes: 10 additions & 0 deletions common/log/tag/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,11 +469,21 @@ func ActorID(actorID string) Tag {
return newStringTag("actor-id", actorID)
}

// ActorEmail returns tag for the actor's email address
func ActorEmail(actorEmail string) Tag {
return newStringTag("actor-email", actorEmail)
}

// HandlerCall returns tag for the API name of a request
func HandlerCall(handlerCall string) Tag {
return newStringTag("handler-call", handlerCall)
}

// RequestBody returns the tag for the API request body
func RequestBody(requestBody string) Tag {
return newStringTag("request-body", requestBody)
}

// history engine shard

// ShardID returns tag for ShardID
Expand Down
36 changes: 36 additions & 0 deletions common/types/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ type AddSearchAttributeRequest struct {
SecurityToken string `json:"securityToken,omitempty"`
}

func (v *AddSearchAttributeRequest) SerializeForLogging() (string, error) {
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 @@ -47,6 +51,10 @@ type AdminDescribeWorkflowExecutionRequest struct {
Execution *WorkflowExecution `json:"execution,omitempty"`
}

func (v *AdminDescribeWorkflowExecutionRequest) SerializeForLogging() (string, error) {
return SerializeRequest(v)
}

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

func (v *GetWorkflowExecutionRawHistoryV2Request) SerializeForLogging() (string, error) {
return SerializeRequest(v)
}

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

func (v *ResendReplicationTasksRequest) SerializeForLogging() (string, error) {
return SerializeRequest(v)
}

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

func (v *GetDynamicConfigRequest) SerializeForLogging() (string, error) {
return SerializeRequest(v)
}

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

func (v *UpdateDynamicConfigRequest) SerializeForLogging() (string, error) {
return SerializeRequest(v)
}

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

func (v *RestoreDynamicConfigRequest) SerializeForLogging() (string, error) {
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) {
return SerializeRequest(v)
}

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

func (v *ListDynamicConfigRequest) SerializeForLogging() (string, error) {
return SerializeRequest(v)
}

type ListDynamicConfigResponse struct {
Entries []*DynamicConfigEntry `json:"entries,omitempty"`
}
24 changes: 24 additions & 0 deletions common/types/replicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ type GetDLQReplicationMessagesRequest struct {
TaskInfos []*ReplicationTaskInfo `json:"taskInfos,omitempty"`
}

func (v *GetDLQReplicationMessagesRequest) SerializeForLogging() (string, error) {
return SerializeRequest(v)
}

// GetTaskInfos is an internal getter (TBD...)
func (v *GetDLQReplicationMessagesRequest) GetTaskInfos() (o []*ReplicationTaskInfo) {
if v != nil && v.TaskInfos != nil {
Expand All @@ -249,6 +253,10 @@ type GetDomainReplicationMessagesRequest struct {
ClusterName string `json:"clusterName,omitempty"`
}

func (v *GetDomainReplicationMessagesRequest) SerializeForLogging() (string, error) {
return SerializeRequest(v)
}

// GetLastRetrievedMessageID is an internal getter (TBD...)
func (v *GetDomainReplicationMessagesRequest) GetLastRetrievedMessageID() (o int64) {
if v != nil && v.LastRetrievedMessageID != nil {
Expand Down Expand Up @@ -284,6 +292,10 @@ type GetReplicationMessagesRequest struct {
ClusterName string `json:"clusterName,omitempty"`
}

func (v *GetReplicationMessagesRequest) SerializeForLogging() (string, error) {
return SerializeRequest(v)
}

// GetClusterName is an internal getter (TBD...)
func (v *GetReplicationMessagesRequest) GetClusterName() (o string) {
if v != nil {
Expand Down Expand Up @@ -393,6 +405,10 @@ type MergeDLQMessagesRequest struct {
NextPageToken []byte `json:"nextPageToken,omitempty"`
}

func (v *MergeDLQMessagesRequest) SerializeForLogging() (string, error) {
return SerializeRequest(v)
}

// GetType is an internal getter (TBD...)
func (v *MergeDLQMessagesRequest) GetType() (o DLQType) {
if v != nil && v.Type != nil {
Expand Down Expand Up @@ -454,6 +470,10 @@ type PurgeDLQMessagesRequest struct {
InclusiveEndMessageID *int64 `json:"inclusiveEndMessageID,omitempty"`
}

func (v *PurgeDLQMessagesRequest) SerializeForLogging() (string, error) {
return SerializeRequest(v)
}

// GetType is an internal getter (TBD...)
func (v *PurgeDLQMessagesRequest) GetType() (o DLQType) {
if v != nil && v.Type != nil {
Expand Down Expand Up @@ -496,6 +516,10 @@ type ReadDLQMessagesRequest struct {
NextPageToken []byte `json:"nextPageToken,omitempty"`
}

func (v *ReadDLQMessagesRequest) SerializeForLogging() (string, error) {
return SerializeRequest(v)
}

// GetType is an internal getter (TBD...)
func (v *ReadDLQMessagesRequest) GetType() (o DLQType) {
if v != nil && v.Type != nil {
Expand Down
Loading

0 comments on commit c462ec0

Please sign in to comment.