You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: rbac_rules_marshal.go
    path of file: ./repos/corteza/server/pkg/envoy/yaml
    
    the code of the file until where you have to start completion: package yaml

import (
	"context"
	"fmt"
	"strconv"
	"strings"

	automationTypes "github.com/cortezaproject/corteza/server/automation/types"
	composeTypes "github.com/cortezaproject/corteza/server/compose/types"
	federationTypes "gith
    
func (n *rbacRule) Prepare(ctx context.Context, state *envoy.ResourceState) (err error) {
	rl, ok := state.Res.(*resource.RbacRule)
	if !ok {
		return encoderErrInvalidResource(resource.RbacResourceType, state.Res.ResourceType())
	}

	// Get the related role
	n.role = resource.FindRole(state.ParentResources, rl.RefRole.Identifiers)
	if n.role == nil {
		return resource.RoleErrUnresolved(rl.RefRole.Identifiers)
	}

	refRes := n.refRbacRes
	if refRes == nil {
		return
	}

	// For now we will only allow resource specific RBAC rules if that resource is
	// also present.
	// Here we check if we can find it in case we're handling a resource specific rule.
	found := false
	switch refRes.ResourceType {
	case composeTypes.RecordResourceType:
		if found = n.handleComposeRecord(state.ParentResources); !found {
			return resource.RbacResourceErrNotFound(refRes.Identifiers)
		}

	case composeTypes.ModuleFieldResourceType:
		if found = n.handleComposeModuleField(state.ParentResources); !found {
			return resource.RbacResourceErrNotFound(refRes.Identifiers)
		}

	default:
		for _, r := range state.ParentResources {
			if refRes.ResourceType == r.ResourceType() && r.Identifiers().HasAny(refRes.Identifiers) {
				return
			}
		}
		// We couldn't find it...
		return resource.RbacResourceErrNotFound(refRes.Identifiers)
	}

	return nil
}