github.com/databricks/cli@v0.203.0/bundle/deploy/lock/release.go (about) 1 package lock 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/databricks/cli/bundle" 8 "github.com/databricks/cli/libs/locker" 9 "github.com/databricks/cli/libs/log" 10 ) 11 12 type Goal string 13 14 const ( 15 GoalDeploy = Goal("deploy") 16 GoalDestroy = Goal("destroy") 17 ) 18 19 type release struct { 20 goal Goal 21 } 22 23 func Release(goal Goal) bundle.Mutator { 24 return &release{goal} 25 } 26 27 func (m *release) Name() string { 28 return "lock:release" 29 } 30 31 func (m *release) Apply(ctx context.Context, b *bundle.Bundle) error { 32 // Return early if locking is disabled. 33 if !b.Config.Bundle.Lock.IsEnabled() { 34 log.Infof(ctx, "Skipping; locking is disabled") 35 return nil 36 } 37 38 // Return early if the locker is not set. 39 // It is likely an error occurred prior to initialization of the locker instance. 40 if b.Locker == nil { 41 log.Warnf(ctx, "Unable to release lock if locker is not configured") 42 return nil 43 } 44 45 log.Infof(ctx, "Releasing deployment lock") 46 switch m.goal { 47 case GoalDeploy: 48 return b.Locker.Unlock(ctx) 49 case GoalDestroy: 50 return b.Locker.Unlock(ctx, locker.AllowLockFileNotExist) 51 default: 52 return fmt.Errorf("unknown goal for lock release: %s", m.goal) 53 } 54 }