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

     1  /*
     2  Copyright 2018 BlackRock, Inc.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  	http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package hdfs
    18  
    19  import (
    20  	"context"
    21  	"fmt"
    22  	"time"
    23  
    24  	"github.com/argoproj/argo-events/common"
    25  	"github.com/argoproj/argo-events/eventsources/common/fsevent"
    26  	"github.com/argoproj/argo-events/pkg/apis/eventsource/v1alpha1"
    27  )
    28  
    29  // ValidateEventSource validates hdfs event source
    30  func (listener *EventListener) ValidateEventSource(ctx context.Context) error {
    31  	return validate(&listener.HDFSEventSource)
    32  }
    33  
    34  func validate(eventSource *v1alpha1.HDFSEventSource) error {
    35  	if eventSource == nil {
    36  		return common.ErrNilEventSource
    37  	}
    38  	if eventSource.Type == "" {
    39  		return fmt.Errorf("type is required")
    40  	}
    41  	op := fsevent.NewOp(eventSource.Type)
    42  	if op == 0 {
    43  		return fmt.Errorf("type is invalid")
    44  	}
    45  	if eventSource.CheckInterval != "" {
    46  		_, err := time.ParseDuration(eventSource.CheckInterval)
    47  		if err != nil {
    48  			return fmt.Errorf("failed to parse interval")
    49  		}
    50  	}
    51  	err := eventSource.WatchPathConfig.Validate()
    52  	if err != nil {
    53  		return err
    54  	}
    55  	if len(eventSource.Addresses) == 0 {
    56  		return fmt.Errorf("addresses is required")
    57  	}
    58  
    59  	hasKrbCCache := eventSource.KrbCCacheSecret != nil
    60  	hasKrbKeytab := eventSource.KrbKeytabSecret != nil
    61  
    62  	if eventSource.HDFSUser == "" && !hasKrbCCache && !hasKrbKeytab {
    63  		return fmt.Errorf("either hdfsUser, krbCCacheSecret or krbKeytabSecret is required")
    64  	}
    65  	if hasKrbKeytab && (eventSource.KrbServicePrincipalName == "" || eventSource.KrbConfigConfigMap == nil || eventSource.KrbUsername == "" || eventSource.KrbRealm == "") {
    66  		return fmt.Errorf("krbServicePrincipalName, krbConfigConfigMap, krbUsername and krbRealm are required with krbKeytabSecret")
    67  	}
    68  	if hasKrbCCache && (eventSource.KrbServicePrincipalName == "" || eventSource.KrbConfigConfigMap == nil) {
    69  		return fmt.Errorf("krbServicePrincipalName and krbConfigConfigMap are required with krbCCacheSecret")
    70  	}
    71  	return err
    72  }