Skip to content

Commit 732afe7

Browse files
duoctranthduoctt
andauthored
feat: Add support for NoOp lock implementation (diggerhq#278)
Co-authored-by: duoctt <duoctt@vng.com.vn>
1 parent 6a56c28 commit 732afe7

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ inputs:
6464
description: Checkov version
6565
required: false
6666
default: '2.3.245'
67+
disable-locking:
68+
description: Disable locking
69+
required: false
70+
default: 'false'
6771

6872
outputs:
6973
output:
@@ -150,6 +154,7 @@ runs:
150154
env:
151155
PLAN_UPLOAD_DESTINATION: ${{ inputs.upload-plan-destination }}
152156
ACTIVATE_VENV: ${{ inputs.setup-checkov == 'true' }}
157+
DISABLE_LOCKING: ${{ inputs.disable-locking == 'true' }}
153158
run: |
154159
cd ${{ github.action_path }}
155160
go build -o digger ./cmd/digger
@@ -162,6 +167,7 @@ runs:
162167
env:
163168
actionref: ${{ github.action_ref }}
164169
PLAN_UPLOAD_DESTINATION: ${{ inputs.upload-plan-destination }}
170+
DISABLE_LOCKING: ${{ inputs.disable-locking == 'true' }}
165171
id: digger
166172
shell: bash
167173
run: |

pkg/utils/locking.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ type Lock interface {
3636
GetLock(resource string) (*int, error)
3737
}
3838

39+
type NoOpLock struct {
40+
}
41+
42+
func (noOpLock *NoOpLock) Lock(transactionId int, resource string) (bool, error) {
43+
return true, nil
44+
}
45+
46+
func (noOpLock *NoOpLock) Unlock(resource string) (bool, error) {
47+
return true, nil
48+
}
49+
50+
func (noOpLock *NoOpLock) GetLock(resource string) (*int, error) {
51+
return nil, nil
52+
}
53+
3954
type ProjectLock interface {
4055
Lock(prNumber int) (bool, error)
4156
Unlock(prNumber int) (bool, error)
@@ -77,7 +92,9 @@ func (projectLock *ProjectLockImpl) Lock(prNumber int) (bool, error) {
7792
return false, err
7893
}
7994

80-
if lockAcquired {
95+
_, isNoOpLock := projectLock.InternalLock.(*NoOpLock)
96+
97+
if lockAcquired && !isNoOpLock {
8198
comment := "Project " + projectLock.projectId() + " has been locked by PR #" + strconv.Itoa(prNumber)
8299
projectLock.CIService.PublishComment(prNumber, comment)
83100
println("project " + projectLock.projectId() + " locked successfully. PR # " + strconv.Itoa(prNumber))
@@ -178,6 +195,11 @@ func GetLock() (Lock, error) {
178195
awsRegion := strings.ToLower(os.Getenv("AWS_REGION"))
179196
awsProfile := strings.ToLower(os.Getenv("AWS_PROFILE"))
180197
lockProvider := strings.ToLower(os.Getenv("LOCK_PROVIDER"))
198+
disableLocking := strings.ToLower(os.Getenv("DISABLE_LOCKING")) == "true"
199+
if disableLocking {
200+
log.Println("Using NoOp lock provider.")
201+
return &NoOpLock{}, nil
202+
}
181203
if lockProvider == "" || lockProvider == "aws" {
182204
log.Println("Using AWS lock provider.")
183205
sess, err := session.NewSessionWithOptions(session.Options{

0 commit comments

Comments
 (0)