@@ -24,6 +24,7 @@ import (
24
24
"github.com/bufbuild/buf/private/bufpkg/bufmodule"
25
25
"github.com/bufbuild/buf/private/bufpkg/bufparse"
26
26
"github.com/bufbuild/buf/private/bufpkg/bufplugin"
27
+ "github.com/bufbuild/buf/private/bufpkg/bufpolicy"
27
28
"github.com/bufbuild/buf/private/pkg/slicesext"
28
29
"github.com/bufbuild/buf/private/pkg/storage"
29
30
"github.com/bufbuild/buf/private/pkg/syserror"
@@ -44,11 +45,21 @@ type WorkspaceDepManager interface {
44
45
ExistingBufLockFileDepModuleKeys (ctx context.Context ) ([]bufmodule.ModuleKey , error )
45
46
// ExistingBufLockFileRemotePluginKeys returns the PluginKeys from the buf.lock file.
46
47
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 )
47
52
// UpdateBufLockFile updates the lock file that backs the Workspace to contain exactly
48
53
// the given ModuleKeys and PluginKeys.
49
54
//
50
55
// 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
52
63
// ConfiguredDepModuleRefs returns the configured dependencies of the Workspace as ModuleRefs.
53
64
//
54
65
// These come from buf.yaml files.
@@ -206,11 +217,39 @@ func (w *workspaceDepManager) ExistingBufLockFileRemotePluginKeys(ctx context.Co
206
217
return bufLockFile .RemotePluginKeys (), nil
207
218
}
208
219
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 {
210
243
var bufLockFile bufconfig.BufLockFile
211
244
var err error
212
245
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
+ )
214
253
if err != nil {
215
254
return err
216
255
}
@@ -227,7 +266,7 @@ func (w *workspaceDepManager) UpdateBufLockFile(ctx context.Context, depModuleKe
227
266
if len (remotePluginKeys ) > 0 {
228
267
return syserror .Newf ("remote plugins are not supported for v1 buf.yaml files" )
229
268
}
230
- bufLockFile , err = bufconfig .NewBufLockFile (fileVersion , depModuleKeys , nil )
269
+ bufLockFile , err = bufconfig .NewBufLockFile (fileVersion , depModuleKeys , nil , nil , nil )
231
270
if err != nil {
232
271
return err
233
272
}
0 commit comments