2024-03-12 18:12:45 +04:00
|
|
|
// Copyright (c) 2024 Sidero Labs, Inc.
|
2021-10-28 23:13:26 +03:00
|
|
|
//
|
|
|
|
// Use of this software is governed by the Business Source License
|
|
|
|
// included in the LICENSE file.
|
2021-09-22 23:08:22 +03:00
|
|
|
|
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2021-09-23 17:47:12 +03:00
|
|
|
"time"
|
|
|
|
|
2021-09-22 23:08:22 +03:00
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
|
|
2022-08-25 20:29:58 +04:00
|
|
|
"github.com/siderolabs/discovery-service/pkg/limits"
|
2021-09-22 23:08:22 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func validateClusterID(id string) error {
|
|
|
|
if len(id) < 1 {
|
|
|
|
return status.Errorf(codes.InvalidArgument, "cluster ID can't be empty")
|
|
|
|
}
|
|
|
|
|
2021-09-23 17:47:12 +03:00
|
|
|
if len(id) > limits.ClusterIDMax {
|
2021-09-22 23:08:22 +03:00
|
|
|
return status.Errorf(codes.InvalidArgument, "cluster ID is too long")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func validateAffiliateID(id string) error {
|
|
|
|
if len(id) < 1 {
|
|
|
|
return status.Errorf(codes.InvalidArgument, "affiliate ID can't be empty")
|
|
|
|
}
|
|
|
|
|
2021-09-23 17:47:12 +03:00
|
|
|
if len(id) > limits.AffiliateIDMax {
|
2021-09-22 23:08:22 +03:00
|
|
|
return status.Errorf(codes.InvalidArgument, "affiliate ID is too long")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2021-09-23 17:47:12 +03:00
|
|
|
|
|
|
|
func validateAffiliateData(data []byte) error {
|
|
|
|
if len(data) > limits.AffiliateDataMax {
|
|
|
|
return status.Error(codes.InvalidArgument, "affiliate data is too big")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func validateAffiliateEndpoints(endpoints [][]byte) error {
|
|
|
|
for _, endpoint := range endpoints {
|
|
|
|
if len(endpoint) > limits.AffiliateEndpointMax {
|
|
|
|
return status.Errorf(codes.InvalidArgument, "affiliate endpoint is too big")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func validateTTL(ttl time.Duration) error {
|
|
|
|
if ttl > limits.TTLMax {
|
|
|
|
return status.Errorf(codes.InvalidArgument, "ttl is too large")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|