func setDeadLetterPolicy(projectID string, p v1alpha1.SubscriptionParameters, s *pubsub.Subscription) {
	if p.DeadLetterPolicy != nil {
		s.DeadLetterPolicy = &pubsub.DeadLetterPolicy{
			DeadLetterTopic:     topic.GetFullyQualifiedName(projectID, p.DeadLetterPolicy.DeadLetterTopic),
			MaxDeliveryAttempts: p.DeadLetterPolicy.MaxDeliveryAttempts,
		}
	}
}
setDeadLetterPolicy sets DeadLetterPolicy of subscription based on SubscriptionParameters.
package subscription
import (
	"fmt"
	"strings"
	"github.com/crossplane/provider-gcp/apis/pubsub/v1alpha1"
	"github.com/crossplane/provider-gcp/pkg/clients/topic"
	"github.com/google/go-cmp/cmp"
	pubsub "google.golang.org/api/pubsub/v1"
)
const (
	subscriptionNameFormat = "projects/%s/subscriptions/%s"
)
func GetFullyQualifiedName(project string, name string) string {
	return fmt.Sprintf(subscriptionNameFormat, project, name)
}
func GenerateSubscription(projectID, name string, p v1alpha1.SubscriptionParameters) *pubsub.Subscription {
	s := &pubsub.Subscription{
		AckDeadlineSeconds:       p.AckDeadlineSeconds,
		Detached:                 p.Detached,
		EnableMessageOrdering:    p.EnableMessageOrdering,
		Filter:                   p.Filter,
		Labels:                   p.Labels,
		MessageRetentionDuration: p.MessageRetentionDuration,
		Name:                     name,
		RetainAckedMessages:      p.RetainAckedMessages,
		Topic:                    topic.GetFullyQualifiedName(projectID, p.Topic),
	}
	setDeadLetterPolicy(projectID, p, s)
	setExpirationPolicy(p, s)
	setPushConfig(p, s)
	setRetryPolicy(p, s)
	return s
}
func setRetryPolicy(p v1alpha1.SubscriptionParameters, s *pubsub.Subscription) {
	if p.RetryPolicy != nil {
		s.RetryPolicy = &pubsub.RetryPolicy{
			MaximumBackoff: p.RetryPolicy.MaximumBackoff,
			MinimumBackoff: p.RetryPolicy.MinimumBackoff,
		}
	}
}
func setPushConfig(p v1alpha1.SubscriptionParameters, s *pubsub.Subscription) {
	if p.PushConfig != nil {
		s.PushConfig = &pubsub.PushConfig{
			Attributes:   p.PushConfig.Attributes,
			PushEndpoint: p.PushConfig.PushEndpoint,
		}
		if p.PushConfig.OidcToken != nil {
			s.PushConfig.OidcToken = &pubsub.OidcToken{
				Audience:            p.PushConfig.OidcToken.Audience,
				ServiceAccountEmail: p.PushConfig.OidcToken.ServiceAccountEmail,
			}
		}
	}
}
func setExpirationPolicy(p v1alpha1.SubscriptionParameters, s *pubsub.Subscription) {
	if p.ExpirationPolicy != nil {
		s.ExpirationPolicy = &pubsub.ExpirationPolicy{
			Ttl: p.ExpirationPolicy.TTL,
		}
	}
}