Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ inputs:
description: Checkov version
required: false
default: '2.3.245'
disable-locking:
description: Disable locking
required: false
default: 'false'

outputs:
output:
Expand Down Expand Up @@ -150,6 +154,7 @@ runs:
env:
PLAN_UPLOAD_DESTINATION: ${{ inputs.upload-plan-destination }}
ACTIVATE_VENV: ${{ inputs.setup-checkov == 'true' }}
DISABLE_LOCKING: ${{ inputs.disable-locking == 'true' }}
run: |
cd ${{ github.action_path }}
go build -o digger ./cmd/digger
Expand All @@ -162,6 +167,7 @@ runs:
env:
actionref: ${{ github.action_ref }}
PLAN_UPLOAD_DESTINATION: ${{ inputs.upload-plan-destination }}
DISABLE_LOCKING: ${{ inputs.disable-locking == 'true' }}
id: digger
shell: bash
run: |
Expand Down
24 changes: 23 additions & 1 deletion pkg/utils/locking.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ type Lock interface {
GetLock(resource string) (*int, error)
}

type NoOpLock struct {
}

func (noOpLock *NoOpLock) Lock(transactionId int, resource string) (bool, error) {
return true, nil
}

func (noOpLock *NoOpLock) Unlock(resource string) (bool, error) {
return true, nil
}

func (noOpLock *NoOpLock) GetLock(resource string) (*int, error) {
return nil, nil
}

type ProjectLock interface {
Lock(prNumber int) (bool, error)
Unlock(prNumber int) (bool, error)
Expand Down Expand Up @@ -77,7 +92,9 @@ func (projectLock *ProjectLockImpl) Lock(prNumber int) (bool, error) {
return false, err
}

if lockAcquired {
_, isNoOpLock := projectLock.InternalLock.(*NoOpLock)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this kinda defeats the purpose of having polymorphic lock if we need to do a type check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your feedback. Regarding the NoOpLock, would it be possible to add an additional return parameter called lockIgnored to the Lock interface instead of using this alternative approach?
I'm open to exploring other ideas as well. Please let me know if you have any suggestions or recommendations.


if lockAcquired && !isNoOpLock {
comment := "Project " + projectLock.projectId() + " has been locked by PR #" + strconv.Itoa(prNumber)
projectLock.CIService.PublishComment(prNumber, comment)
println("project " + projectLock.projectId() + " locked successfully. PR # " + strconv.Itoa(prNumber))
Expand Down Expand Up @@ -178,6 +195,11 @@ func GetLock() (Lock, error) {
awsRegion := strings.ToLower(os.Getenv("AWS_REGION"))
awsProfile := strings.ToLower(os.Getenv("AWS_PROFILE"))
lockProvider := strings.ToLower(os.Getenv("LOCK_PROVIDER"))
disableLocking := strings.ToLower(os.Getenv("DISABLE_LOCKING")) == "true"
if disableLocking {
log.Println("Using NoOp lock provider.")
return &NoOpLock{}, nil
}
if lockProvider == "" || lockProvider == "aws" {
log.Println("Using AWS lock provider.")
sess, err := session.NewSessionWithOptions(session.Options{
Expand Down