Skip to content

Commit 87d9edb

Browse files
authored
Fix convert PolicyConfig for empty Lint and Breaking (#3902)
1 parent 43574fc commit 87d9edb

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

private/bufpkg/bufpolicy/bufpolicyapi/convert.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ func newPolicyConfig(
8686
registry string,
8787
policyConfigV1Beta1 *policyv1beta1.PolicyConfig,
8888
) (*policyConfig, error) {
89+
if policyConfigV1Beta1 == nil {
90+
return nil, fmt.Errorf("policyConfigV1Beta1 must not be nil")
91+
}
8992
lintConfig, err := getLintConfigForV1Beta1LintConfig(policyConfigV1Beta1.Lint)
9093
if err != nil {
9194
return nil, err
@@ -130,8 +133,8 @@ func getLintConfigForV1Beta1LintConfig(
130133
) (bufconfig.LintConfig, error) {
131134
checkConfig, err := bufconfig.NewEnabledCheckConfig(
132135
bufconfig.FileVersionV2,
133-
lintConfigV1Beta1.Use,
134-
lintConfigV1Beta1.Except,
136+
lintConfigV1Beta1.GetUse(),
137+
lintConfigV1Beta1.GetExcept(),
135138
nil,
136139
nil,
137140
false,
@@ -141,11 +144,11 @@ func getLintConfigForV1Beta1LintConfig(
141144
}
142145
return bufconfig.NewLintConfig(
143146
checkConfig,
144-
lintConfigV1Beta1.EnumZeroValueSuffix,
145-
lintConfigV1Beta1.RpcAllowSameRequestResponse,
146-
lintConfigV1Beta1.RpcAllowGoogleProtobufEmptyRequests,
147-
lintConfigV1Beta1.RpcAllowGoogleProtobufEmptyResponses,
148-
lintConfigV1Beta1.ServiceSuffix,
147+
lintConfigV1Beta1.GetEnumZeroValueSuffix(),
148+
lintConfigV1Beta1.GetRpcAllowSameRequestResponse(),
149+
lintConfigV1Beta1.GetRpcAllowGoogleProtobufEmptyRequests(),
150+
lintConfigV1Beta1.GetRpcAllowGoogleProtobufEmptyResponses(),
151+
lintConfigV1Beta1.GetServiceSuffix(),
149152
false, // Comment ignores are not allowed in Policy files.
150153
), nil
151154
}
@@ -155,8 +158,8 @@ func getBreakingConfigForV1Beta1BreakingConfig(
155158
) (bufconfig.BreakingConfig, error) {
156159
checkConfig, err := bufconfig.NewEnabledCheckConfig(
157160
bufconfig.FileVersionV2,
158-
breakingConfigV1Beta1.Use,
159-
breakingConfigV1Beta1.Except,
161+
breakingConfigV1Beta1.GetUse(),
162+
breakingConfigV1Beta1.GetExcept(),
160163
nil,
161164
nil,
162165
false,
@@ -166,25 +169,25 @@ func getBreakingConfigForV1Beta1BreakingConfig(
166169
}
167170
return bufconfig.NewBreakingConfig(
168171
checkConfig,
169-
breakingConfigV1Beta1.IgnoreUnstablePackages,
172+
breakingConfigV1Beta1.GetIgnoreUnstablePackages(),
170173
), nil
171174
}
172175

173176
func getPluginConfigForV1Beta1PluginConfig(
174177
registry string,
175178
pluginConfigV1Beta1 *policyv1beta1.PolicyConfig_CheckPluginConfig,
176179
) (bufconfig.PluginConfig, error) {
177-
nameV1Beta1 := pluginConfigV1Beta1.Name
180+
nameV1Beta1 := pluginConfigV1Beta1.GetName()
178181
pluginRef, err := bufparse.NewRef(
179182
registry,
180-
nameV1Beta1.Owner,
181-
nameV1Beta1.Plugin,
182-
nameV1Beta1.Ref,
183+
nameV1Beta1.GetOwner(),
184+
nameV1Beta1.GetPlugin(),
185+
nameV1Beta1.GetRef(),
183186
)
184187
if err != nil {
185188
return nil, err
186189
}
187-
options, err := option.OptionsForProtoOptions(pluginConfigV1Beta1.Options)
190+
options, err := option.OptionsForProtoOptions(pluginConfigV1Beta1.GetOptions())
188191
if err != nil {
189192
return nil, err
190193
}
@@ -195,6 +198,6 @@ func getPluginConfigForV1Beta1PluginConfig(
195198
return bufconfig.NewRemoteWasmPluginConfig(
196199
pluginRef,
197200
optionsMap,
198-
pluginConfigV1Beta1.Args,
201+
pluginConfigV1Beta1.GetArgs(),
199202
)
200203
}

0 commit comments

Comments
 (0)