@@ -25,6 +25,7 @@ import (
2525 "github.com/bufbuild/buf/private/bufpkg/bufmodule"
2626 "github.com/bufbuild/buf/private/bufpkg/bufparse"
2727 "github.com/bufbuild/buf/private/bufpkg/bufplugin"
28+ "github.com/bufbuild/buf/private/bufpkg/bufpolicy"
2829 "github.com/bufbuild/buf/private/pkg/storage"
2930 "github.com/bufbuild/buf/private/pkg/syserror"
3031)
@@ -44,11 +45,21 @@ type WorkspaceDepManager interface {
4445 ExistingBufLockFileDepModuleKeys (ctx context.Context ) ([]bufmodule.ModuleKey , error )
4546 // ExistingBufLockFileRemotePluginKeys returns the PluginKeys from the buf.lock file.
4647 ExistingBufLockFileRemotePluginKeys (ctx context.Context ) ([]bufplugin.PluginKey , error )
48+ // ExistingBufLockFileRemotePolicyKeys returns the PolicyKeys from the buf.lock file.
49+ ExistingBufLockFileRemotePolicyKeys (ctx context.Context ) ([]bufpolicy.PolicyKey , error )
50+ // ExistingBufLockFilePolicyNameToRemotePluginKeys returns the PluginKeys for each Policy name from the buf.lock file.
51+ ExistingBufLockFilePolicyNameToRemotePluginKeys (ctx context.Context ) (map [string ][]bufplugin.PluginKey , error )
4752 // UpdateBufLockFile updates the lock file that backs the Workspace to contain exactly
4853 // the given ModuleKeys and PluginKeys.
4954 //
5055 // If a buf.lock does not exist, one will be created.
51- UpdateBufLockFile (ctx context.Context , depModuleKeys []bufmodule.ModuleKey , remotePluginKeys []bufplugin.PluginKey ) error
56+ UpdateBufLockFile (
57+ ctx context.Context ,
58+ depModuleKeys []bufmodule.ModuleKey ,
59+ remotePluginKeys []bufplugin.PluginKey ,
60+ remotePolicyKeys []bufpolicy.PolicyKey ,
61+ policyNameToRemotePluginKeys map [string ][]bufplugin.PluginKey ,
62+ ) error
5263 // ConfiguredDepModuleRefs returns the configured dependencies of the Workspace as ModuleRefs.
5364 //
5465 // These come from buf.yaml files.
@@ -206,11 +217,39 @@ func (w *workspaceDepManager) ExistingBufLockFileRemotePluginKeys(ctx context.Co
206217 return bufLockFile .RemotePluginKeys (), nil
207218}
208219
209- func (w * workspaceDepManager ) UpdateBufLockFile (ctx context.Context , depModuleKeys []bufmodule.ModuleKey , remotePluginKeys []bufplugin.PluginKey ) error {
220+ func (w * workspaceDepManager ) ExistingBufLockFileRemotePolicyKeys (ctx context.Context ) ([]bufpolicy.PolicyKey , error ) {
221+ bufLockFile , err := bufconfig .GetBufLockFileForPrefix (ctx , w .bucket , w .targetSubDirPath )
222+ if err != nil {
223+ if errors .Is (err , fs .ErrNotExist ) {
224+ return nil , nil
225+ }
226+ return nil , err
227+ }
228+ return bufLockFile .RemotePolicyKeys (), nil
229+ }
230+
231+ func (w * workspaceDepManager ) ExistingBufLockFilePolicyNameToRemotePluginKeys (ctx context.Context ) (map [string ][]bufplugin.PluginKey , error ) {
232+ bufLockFile , err := bufconfig .GetBufLockFileForPrefix (ctx , w .bucket , w .targetSubDirPath )
233+ if err != nil {
234+ if errors .Is (err , fs .ErrNotExist ) {
235+ return nil , nil
236+ }
237+ return nil , err
238+ }
239+ return bufLockFile .PolicyNameToRemotePluginKeys (), nil
240+ }
241+
242+ func (w * workspaceDepManager ) UpdateBufLockFile (ctx context.Context , depModuleKeys []bufmodule.ModuleKey , remotePluginKeys []bufplugin.PluginKey , remotePolicyKeys []bufpolicy.PolicyKey , policyNameToRemotePolicyKeys map [string ][]bufplugin.PluginKey ) error {
210243 var bufLockFile bufconfig.BufLockFile
211244 var err error
212245 if w .isV2 {
213- bufLockFile , err = bufconfig .NewBufLockFile (bufconfig .FileVersionV2 , depModuleKeys , remotePluginKeys )
246+ bufLockFile , err = bufconfig .NewBufLockFile (
247+ bufconfig .FileVersionV2 ,
248+ depModuleKeys ,
249+ remotePluginKeys ,
250+ remotePolicyKeys ,
251+ policyNameToRemotePolicyKeys ,
252+ )
214253 if err != nil {
215254 return err
216255 }
@@ -227,7 +266,7 @@ func (w *workspaceDepManager) UpdateBufLockFile(ctx context.Context, depModuleKe
227266 if len (remotePluginKeys ) > 0 {
228267 return syserror .Newf ("remote plugins are not supported for v1 buf.yaml files" )
229268 }
230- bufLockFile , err = bufconfig .NewBufLockFile (fileVersion , depModuleKeys , nil )
269+ bufLockFile , err = bufconfig .NewBufLockFile (fileVersion , depModuleKeys , nil , nil , nil )
231270 if err != nil {
232271 return err
233272 }
0 commit comments