func ToResourceInfo()

in tools/resource-gen/genutils/util.go [76:141]


func ToResourceInfo(desc protoreflect.MessageDescriptor) ResourceInfo {
	r := DubboResourceForMessage(desc)

	out := ResourceInfo{
		ResourceType:             r.Type,
		ResourceName:             r.Name,
		ProtoType:                string(desc.Name()),
		Selectors:                SelectorsForMessage(desc),
		SkipRegistration:         r.SkipRegistration,
		SkipKubernetesWrappers:   r.SkipKubernetesWrappers,
		Global:                   r.Global,
		ScopeNamespace:           r.ScopeNamespace,
		AllowToInspect:           r.AllowToInspect,
		StorageVersion:           r.StorageVersion,
		SingularDisplayName:      core_model.DisplayName(r.Type),
		PluralDisplayName:        r.PluralDisplayName,
		IsExperimental:           r.IsExperimental,
		AdditionalPrinterColumns: r.AdditionalPrinterColumns,
		HasInsights:              r.HasInsights,
	}
	if r.Ws != nil {
		pluralResourceName := r.Ws.Plural
		if pluralResourceName == "" {
			pluralResourceName = r.Ws.Name + "s"
		}
		out.WsReadOnly = r.Ws.ReadOnly
		out.WsAdminOnly = r.Ws.AdminOnly
		out.WsPath = pluralResourceName
		if !r.Ws.ReadOnly {
			out.DubboctlSingular = r.Ws.Name
			out.DubboctlPlural = pluralResourceName
			// Keep the typo to preserve backward compatibility
			if out.DubboctlSingular == "health-check" {
				out.DubboctlSingular = "healthcheck"
				out.DubboctlPlural = "healthchecks"
			}
		}
	}
	if out.PluralDisplayName == "" {
		out.PluralDisplayName = core_model.PluralType(core_model.DisplayName(r.Type))
	}
	// Working around the fact we don't really differentiate policies from the rest of resources:
	// Anything global can't be a policy as it need to be on a mesh. Anything with locked Ws config is something internal and therefore not a policy
	out.IsPolicy = !out.SkipRegistration && !out.Global && !out.WsAdminOnly && !out.WsReadOnly && out.ResourceType != "Dataplane" && out.ResourceType != "ExternalService"
	switch {
	case r.Dds == nil || (!r.Dds.SendToZone && !r.Dds.SendToGlobal):
		out.DdsDirection = ""
	case r.Dds.SendToGlobal && r.Dds.SendToZone:
		out.DdsDirection = "model.ZoneToGlobalFlag | model.GlobalToAllButOriginalZoneFlag"
	case r.Dds.SendToGlobal:
		out.DdsDirection = "model.ZoneToGlobalFlag"
	case r.Dds.SendToZone:
		out.DdsDirection = "model.GlobalToAllZonesFlag"
	}

	if out.ResourceType == "MeshGateway" {
		out.DdsDirection = "model.ZoneToGlobalFlag | model.GlobalToAllZonesFlag"
	}

	if p := desc.Parent(); p != nil {
		if _, ok := p.(protoreflect.MessageDescriptor); ok {
			out.ProtoType = fmt.Sprintf("%s_%s", p.Name(), desc.Name())
		}
	}
	return out
}