MCPcopy Create free account
hub / github.com/rilldata/rill / applyMetricsViewSecurity

Method applyMetricsViewSecurity

runtime/resources.go:220–250  ·  view source on GitHub ↗

applyMetricsViewSecurity rewrites a metrics view based on the field access conditions of a security policy.

(res *runtimev1.Resource, security *ResolvedSecurity)

Source from the content-addressed store, hash-verified

218
219// applyMetricsViewSecurity rewrites a metrics view based on the field access conditions of a security policy.
220func (r *Runtime) applyMetricsViewSecurity(res *runtimev1.Resource, security *ResolvedSecurity) *runtimev1.Resource {
221 if security.CanAccessAllFields() {
222 return res
223 }
224
225 mv := res.GetMetricsView()
226 specDims, specMeasures, specChanged := r.applyMetricsViewSpecSecurity(mv.Spec, security)
227 validSpecDims, validSpecMeasures, validSpecChanged := r.applyMetricsViewSpecSecurity(mv.State.ValidSpec, security)
228
229 if !specChanged && !validSpecChanged {
230 return res
231 }
232
233 mv = proto.Clone(mv).(*runtimev1.MetricsView)
234
235 if specChanged {
236 mv.Spec.Dimensions = specDims
237 mv.Spec.Measures = specMeasures
238 }
239
240 if validSpecChanged {
241 mv.State.ValidSpec.Dimensions = validSpecDims
242 mv.State.ValidSpec.Measures = validSpecMeasures
243 }
244
245 // We mustn't modify the resource in-place
246 return &runtimev1.Resource{
247 Meta: res.Meta,
248 Resource: &runtimev1.Resource_MetricsView{MetricsView: mv},
249 }
250}
251
252// applyMetricsViewSpecSecurity rewrites a metrics view spec based on the field access conditions of a security policy.
253func (r *Runtime) applyMetricsViewSpecSecurity(spec *runtimev1.MetricsViewSpec, security *ResolvedSecurity) ([]*runtimev1.MetricsViewSpec_Dimension, []*runtimev1.MetricsViewSpec_Measure, bool) {

Callers 1

ApplySecurityPolicyMethod · 0.95

Calls 4

CanAccessAllFieldsMethod · 0.80
CloneMethod · 0.80
GetMetricsViewMethod · 0.45

Tested by

no test coverage detected