github.com/argoproj/argo-events@v1.9.1/eventsources/sources/gerrit/validate.go (about)

     1  /*
     2  Copyright 2018 BlackRock, Inc.
     3  Licensed under the Apache License, Version 2.0 (the "License");
     4  you may not use this file except in compliance with the License.
     5  You may obtain a copy of the License at
     6  	http://www.apache.org/licenses/LICENSE-2.0
     7  Unless required by applicable law or agreed to in writing, software
     8  distributed under the License is distributed on an "AS IS" BASIS,
     9  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    10  See the License for the specific language governing permissions and
    11  limitations under the License.
    12  */
    13  
    14  package gerrit
    15  
    16  import (
    17  	"context"
    18  	"fmt"
    19  
    20  	"github.com/argoproj/argo-events/common"
    21  	"github.com/argoproj/argo-events/eventsources/common/webhook"
    22  	"github.com/argoproj/argo-events/pkg/apis/eventsource/v1alpha1"
    23  )
    24  
    25  // ValidateEventSource validates gerrit event source
    26  func (listener *EventListener) ValidateEventSource(ctx context.Context) error {
    27  	return validate(&listener.GerritEventSource)
    28  }
    29  
    30  func validate(eventSource *v1alpha1.GerritEventSource) error {
    31  	if eventSource == nil {
    32  		return common.ErrNilEventSource
    33  	}
    34  	if len(eventSource.Projects) == 0 {
    35  		return fmt.Errorf("projects cannot be empty")
    36  	}
    37  	if eventSource.Events == nil {
    38  		return fmt.Errorf("events can't be empty")
    39  	}
    40  	if eventSource.GerritBaseURL == "" {
    41  		return fmt.Errorf("gerrit base url can't be empty")
    42  	}
    43  	if eventSource.Auth == nil {
    44  		return fmt.Errorf("username and password can't be empty")
    45  	}
    46  	return webhook.ValidateWebhookContext(eventSource.Webhook)
    47  }