github.com/polarismesh/polaris@v1.17.8/common/utils/config_file.go (about)

     1  /**
     2   * Tencent is pleased to support the open source community by making Polaris available.
     3   *
     4   * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
     5   *
     6   * Licensed under the BSD 3-Clause License (the "License");
     7   * you may not use this file except in compliance with the License.
     8   * You may obtain a copy of the License at
     9   *
    10   * https://opensource.org/licenses/BSD-3-Clause
    11   *
    12   * Unless required by applicable law or agreed to in writing, software distributed
    13   * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
    14   * CONDITIONS OF ANY KIND, either express or implied. See the License for the
    15   * specific language governing permissions and limitations under the License.
    16   */
    17  
    18  package utils
    19  
    20  import "strings"
    21  
    22  const (
    23  	// ReleaseTypeNormal 发布类型,全量发布
    24  	ReleaseTypeNormal = "normal"
    25  	// ReleaseTypeDelete 发布类型,删除配置发布
    26  	ReleaseTypeDelete = "delete"
    27  	// ReleaseTypeRollback 发布类型 回滚
    28  	ReleaseTypeRollback = "rollback"
    29  	// ReleaseTypeClean 发布类型,清空配置发布
    30  	ReleaseTypeClean = "clean"
    31  
    32  	// ReleaseStatusSuccess 发布成功状态
    33  	ReleaseStatusSuccess = "success"
    34  	// ReleaseStatusFail 发布失败状态
    35  	ReleaseStatusFail = "failure"
    36  	// ReleaseStatusToRelease 待发布状态
    37  	ReleaseStatusToRelease = "to-be-released"
    38  
    39  	// 文件格式
    40  	FileFormatText       = "text"
    41  	FileFormatYaml       = "yaml"
    42  	FileFormatXml        = "xml"
    43  	FileFormatJson       = "json"
    44  	FileFormatHtml       = "html"
    45  	FileFormatProperties = "properties"
    46  
    47  	FileIdSeparator = "+"
    48  
    49  	// MaxRequestBodySize 导入配置文件请求体最大 4M
    50  	MaxRequestBodySize = 4 * 1024 * 1024
    51  	// ConfigFileFormKey 配置文件表单键
    52  	ConfigFileFormKey = "config"
    53  	// ConfigFileMetaFileName 配置文件元数据文件名
    54  	ConfigFileMetaFileName = "META"
    55  	// ConfigFileImportConflictSkip 导入配置文件发生冲突跳过
    56  	ConfigFileImportConflictSkip = "skip"
    57  	// ConfigFileImportConflictOverwrite 导入配置文件发生冲突覆盖原配置文件
    58  	ConfigFileImportConflictOverwrite = "overwrite"
    59  	// ConfigFileTagKeyUseEncrypted 配置加密开关标识,value 为 boolean
    60  	ConfigFileTagKeyUseEncrypted = "internal-encrypted"
    61  	// ConfigFileTagKeyDataKey 加密密钥 tag key
    62  	ConfigFileTagKeyDataKey = "internal-datakey"
    63  	// ConfigFileTagKeyEncryptAlgo 加密算法 tag key
    64  	ConfigFileTagKeyEncryptAlgo = "internal-encryptalgo"
    65  )
    66  
    67  // GenFileId 生成文件 Id
    68  func GenFileId(namespace, group, fileName string) string {
    69  	return namespace + FileIdSeparator + group + FileIdSeparator + fileName
    70  }
    71  
    72  // ParseFileId 解析文件 Id
    73  func ParseFileId(fileId string) (namespace, group, fileName string) {
    74  	fileInfo := strings.Split(fileId, FileIdSeparator)
    75  	return fileInfo[0], fileInfo[1], fileInfo[2]
    76  }
    77  
    78  // ConfigFileMeta 导入配置文件ZIP包中的元数据结构
    79  type ConfigFileMeta struct {
    80  	Tags    map[string]string `json:"tags"`
    81  	Comment string            `json:"comment"`
    82  }