func()

in coverage/coverage.go [40:120]


func (m *Model) CredScan(root interface{}, secrets map[string]string) {
	if root == nil || m == nil || m.IsReadOnly {
		return
	}

	// https://pkg.go.dev/encoding/json#Unmarshal
	switch value := root.(type) {
	case string:

	case bool:

	case float64:

	case []interface{}:
		if m.Item == nil {
			logrus.Errorf("unexpected array in %s", m.Identifier)
		}

		for _, item := range value {
			m.Item.CredScan(item, secrets)
		}

	case map[string]interface{}:
		isMatchProperty := true
		if m.Discriminator != nil && m.Variants != nil {
		Loop:
			for k, v := range value {
				if k == *m.Discriminator {
					if m.ModelName == v.(string) {
						break
					}
					if m.VariantType != nil && *m.VariantType == v.(string) {
						break
					}
					if variant, ok := (*m.Variants)[v.(string)]; ok {
						isMatchProperty = false
						variant.CredScan(value, secrets)

						break
					}
					for _, variant := range *m.Variants {
						if variant.VariantType != nil && *variant.VariantType == v.(string) {
							isMatchProperty = false
							variant.CredScan(value, secrets)

							break Loop
						}
					}
					logrus.Errorf("unexpected variant %s in %s", v.(string), m.Identifier)
				}
			}
		}

		if isMatchProperty {
			for k, v := range value {
				if m.Properties == nil {
					// some objects has no properties defined
					// https://github.com/Azure/azure-rest-api-specs/blob/3519c80fe510a268f6e59a29ccac8a53fdec15b6/specification/monitor/resource-manager/Microsoft.Insights/stable/2023-03-11/dataCollectionRules_API.json#L724

					logrus.Warnf("unexpected key %s in %s", k, m.Identifier)
					continue
				}
				if _, ok := (*m.Properties)[k]; !ok {
					if !m.HasAdditionalProperties && m.Discriminator == nil {
						logrus.Errorf("unexpected key %s in %s", k, m.Identifier)
						continue
					}
				}
				if (*m.Properties)[k].IsSecret {
					secrets[fmt.Sprintf("%v.%v", m.Identifier, k)] = fmt.Sprintf("%v", v)
				}
				(*m.Properties)[k].CredScan(v, secrets)
			}
		}

	case nil:

	default:
		logrus.Errorf("unexpect type %T for json unmarshaled value", value)
	}
}