go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/swarming/proto/api/validation.go (about)

     1  // Copyright 2019 The LUCI Authors.
     2  //
     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  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package apipb
    16  
    17  import (
    18  	"errors"
    19  	"fmt"
    20  )
    21  
    22  // Validate returns an error if r is invalid.
    23  func (r *NotifyTasksRequest) Validate() error {
    24  	if r.SchedulerId == "" {
    25  		return errors.New("SchedulerId is required")
    26  	}
    27  	for i, n := range r.Notifications {
    28  		if n.Time == nil {
    29  			return fmt.Errorf("notification time is required (item %d)", i)
    30  		}
    31  		if n.Task == nil {
    32  			return fmt.Errorf("notification task is required (item %d)", i)
    33  		}
    34  		if n.Task.EnqueuedTime == nil {
    35  			return fmt.Errorf("notification task enqueued time is required (item %d)", i)
    36  		}
    37  	}
    38  	return nil
    39  }
    40  
    41  // Validate returns an error if r is invalid.
    42  func (r *AssignTasksRequest) Validate() error {
    43  	if r.SchedulerId == "" {
    44  		return errors.New("SchedulerId is required")
    45  	}
    46  	if r.Time == nil {
    47  		return errors.New("Time is required")
    48  	}
    49  	return nil
    50  }
    51  
    52  // Validate returns an error if r is invalid.
    53  func (r *GetCancellationsRequest) Validate() error {
    54  	if r.SchedulerId == "" {
    55  		return errors.New("SchedulerId is required")
    56  	}
    57  	return nil
    58  }