/**
 * Copyright 2021 Opstrace, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */ import * as yup from "yup" ; import { CLUSTER_NAME_REGEX , KNOWN_AWS_REGIONS } from "@opstrace/config" ; import { BUILD_INFO } from "@opstrace/utils" ; export const AWSInfraConfigSchemaV1 = yup . object ( { instance_type : yup . string ( ) . default ( "t3.xlarge" ) , region : yup . string ( ) . oneOf ( KNOWN_AWS_REGIONS ) . default ( "us-west-2" ) , zone_suffix : yup . string ( ) . default ( "a" ) , eks_admin_roles : yup . array ( ) . of ( yup . string ( ) ) . default ( [ ] ) } ) . noUnknown ( true , err => { return `unexpected key(s): ${ err . unknown }` ; } ) . defined ( ) ; export const GCPInfraConfigSchemaV1 = yup . object ( { machine_type : yup . string ( ) . default ( "n1-standard-4" ) , region : yup . string ( ) . default ( "us-west2" ) , zone_suffix : yup . string ( ) . default ( "a" ) } ) . noUnknown ( true , err => { return `unexpected key(s): ${ err . unknown }` ; } ) . defined ( ) ; export const ClusterConfigFileSchemaV1 = yup . object ( { node_count : yup . number ( ) . positive ( ) . integer ( ) . required ( ) , controller_image : yup . string ( ) . default ( `opstrace/controller:${ BUILD_INFO . VERSION_STRING }` ) , tenants : yup . array ( ) . of ( yup . string ( ) ) . min ( 1 , "`tenants` needs to contain at least one tenant name" ) . defined ( ) , env_label : yup . string ( ) , cert_issuer : yup . string ( ) . oneOf ( [ "letsencrypt-prod" , "letsencrypt-staging" ] ) . default ( "letsencrypt-staging" ) , log_retention : yup . number ( ) . positive ( ) . integer ( ) . default ( 7 ) , metric_retention : yup . number ( ) . positive ( ) . integer ( ) . default ( 7 ) , data_api_authentication_disabled : yup . boolean ( ) . default ( false ) , data_api_authorized_ip_ranges : yup . array ( ) . of ( yup . string ( ) ) . default ( [ "0.0.0.0/0" ] ) , aws : yup . object ( ) . notRequired ( ) , gcp : yup . object ( ) . notRequired ( ) } ) . noUnknown ( true , err => { return `unexpected key(s): ${ err . unknown }` ; } ) . defined ( ) ; export const RenderedClusterConfigSchemaV1 = ClusterConfigFileSchemaV1 . concat ( yup . object ( ) . shape ( { cluster_name : yup . string ( ) . required ( ) . matches ( CLUSTER_NAME_REGEX ) . min ( 2 ) . max ( 23 ) , cloud_provider : yup . mixed < "gcp" | "aws" > ( ) . oneOf ( [ "aws" , "gcp" ] ) . required ( ) , data_api_authn_pubkey_pem : yup . string ( ) } ) . noUnknown ( ) . defined ( ) ) ; export type RenderedClusterConfigSchemaTypeV1 = yup . InferType < typeof RenderedClusterConfigSchemaV1 > ; export type ClusterConfigFileSchemaTypeV1 = yup . InferType < typeof ClusterConfigFileSchemaV1 > ;