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: sasl.go
    path of file: ./repos/benthos/internal/impl/kafka
    
    the code of the file until where you have to start completion: package kafka

import (
	"context"
	"errors"
	"fmt"

	"github.com/IBM/sarama"

	"github.com/benthosdev/benthos/v4
    
func ApplySaramaSASLFromParsed(pConf *service.ParsedConfig, mgr *service.Resources, conf *sarama.Config) error {
	pConf = pConf.Namespace(saramaFieldSASL)

	mechanism, err := pConf.FieldString(saramaFieldSASLMechanism)
	if err != nil {
		return err
	}

	username, err := pConf.FieldString(saramaFieldSASLUser)
	if err != nil {
		return nil
	}

	password, err := pConf.FieldString(saramaFieldSASLPassword)
	if err != nil {
		return nil
	}

	accessToken, err := pConf.FieldString(saramaFieldSASLAccessToken)
	if err != nil {
		return nil
	}

	tokenCache, err := pConf.FieldString(saramaFieldSASLTokenCache)
	if err != nil {
		return nil
	}

	tokenKey, err := pConf.FieldString(saramaFieldSASLTokenKey)
	if err != nil {
		return nil
	}

	switch mechanism {
	case sarama.SASLTypeOAuth:
		var tp sarama.AccessTokenProvider
		var err error

		if tokenCache != "" {
			if tp, err = newCacheAccessTokenProvider(mgr, tokenCache, tokenKey); err != nil {
				return err
			}
		} else {
			if tp, err = newStaticAccessTokenProvider(accessToken); err != nil {
				return err
			}
		}
		conf.Net.SASL.TokenProvider = tp
	case sarama.SASLTypeSCRAMSHA256:
		conf.Net.SASL.SCRAMClientGeneratorFunc = func() sarama.SCRAMClient {
			return &XDGSCRAMClient{HashGeneratorFcn: SHA256}
		}
		conf.Net.SASL.User = username
		conf.Net.SASL.Password = password
	case sarama.SASLTypeSCRAMSHA512:
		conf.Net.SASL.SCRAMClientGeneratorFunc = func() sarama.SCRAMClient {
			return &XDGSCRAMClient{HashGeneratorFcn: SHA512}
		}
		conf.Net.SASL.User = username
		conf.Net.SASL.Password = password
	case sarama.SASLTypePlaintext:
		conf.Net.SASL.User = username
		conf.Net.SASL.Password = password
	case "", "none":
		return nil
	default:
		return ErrUnsupportedSASLMechanism
	}

	conf.Net.SASL.Enable = true
	conf.Net.SASL.Mechanism = sarama.SASLMechanism(mechanism)

	return nil
}