-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'github-bk-bcs/master'
* github-bk-bcs/master: bcs-webconsole解决遗留问题 (#2710) 解决trace报错的问题 (#2709) feat:bscp 添加dal/vault (#2719) fix:修复部分空间样式交互问题 (#2726)
- Loading branch information
Showing
27 changed files
with
468 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making Blueking Container Service available. | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* Licensed under the MIT License (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* http://opensource.org/licenses/MIT | ||
* 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. | ||
*/ | ||
|
||
package vault | ||
|
||
import ( | ||
"fmt" | ||
|
||
"bscp.io/pkg/kit" | ||
"bscp.io/pkg/types" | ||
) | ||
|
||
const ( | ||
// MountPath mount path | ||
MountPath = "bk_bscp" | ||
// kvPath kv path | ||
kvPath = "biz/%d/apps/%d/kv/key/%s" | ||
) | ||
|
||
// UpsertKv 创建|更新kv | ||
func (s *set) UpsertKv(kit *kit.Kit, opt *types.UpsertKvOption) (int, error) { | ||
|
||
if err := opt.Validate(); err != nil { | ||
return 0, err | ||
} | ||
|
||
data := map[string]interface{}{ | ||
"type": opt.KvType, | ||
"value": opt.Value, | ||
} | ||
secret, err := s.cli.KVv2(MountPath).Put(kit.Ctx, fmt.Sprintf(kvPath, opt.BizID, opt.AppID, opt.Key), data) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
return secret.VersionMetadata.Version, nil | ||
|
||
} | ||
|
||
// GetLastKv 获取最新的kv | ||
func (s *set) GetLastKv(kit *kit.Kit, opt *types.GetLastKvOpt) (string, error) { | ||
|
||
kv, err := s.cli.KVv2(MountPath).Get(kit.Ctx, fmt.Sprintf(kvPath, opt.BizID, opt.AppID, opt.Key)) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
value, ok := kv.Data["data"].(string) | ||
if !ok { | ||
return "", fmt.Errorf("value type assertion failed: err : %v", err) | ||
} | ||
|
||
return value, nil | ||
|
||
} | ||
|
||
// GetKvByVersion 根据版本获取kv | ||
func (s *set) GetKvByVersion(kit *kit.Kit, bizID, appID uint32, key string, version int) (string, error) { | ||
|
||
kv, err := s.cli.KVv2(MountPath).GetVersion(kit.Ctx, fmt.Sprintf(kvPath, bizID, appID, key), version) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
value, ok := kv.Data["data"].(string) | ||
if !ok { | ||
return "", fmt.Errorf("value type assertion failed: err : %v", err) | ||
} | ||
|
||
return value, nil | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making Blueking Container Service available. | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* Licensed under the MIT License (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* http://opensource.org/licenses/MIT | ||
* 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. | ||
*/ | ||
|
||
package vault | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/vault/api" | ||
) | ||
|
||
// CreateMountPath 创建挂载目录 | ||
func (s *set) CreateMountPath(path string, config *api.MountInput) error { | ||
return s.cli.Sys().Mount(path, config) | ||
} | ||
|
||
// IsMountPathExists 挂载目录是否存在 | ||
func (s *set) IsMountPathExists(path string) (bool, error) { | ||
// 列出所有的挂载路径 | ||
mounts, err := s.cli.Sys().ListMounts() | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
// 检查要创建的挂载路径是否已存在 | ||
_, exists := mounts[fmt.Sprintf("%s/", path)] | ||
return exists, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making Blueking Container Service available. | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* Licensed under the MIT License (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* http://opensource.org/licenses/MIT | ||
* 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. | ||
*/ | ||
|
||
// Package vault NOTES | ||
package vault | ||
|
||
import ( | ||
vault "github.com/hashicorp/vault/api" | ||
|
||
"bscp.io/pkg/cc" | ||
"bscp.io/pkg/kit" | ||
"bscp.io/pkg/types" | ||
) | ||
|
||
// Set ... | ||
type Set interface { | ||
// IsMountPathExists 挂载目录是否存在 | ||
IsMountPathExists(path string) (bool, error) | ||
// CreateMountPath 创建挂载目录 | ||
CreateMountPath(path string, config *vault.MountInput) error | ||
// UpsertKv 创建|更新kv | ||
UpsertKv(kit *kit.Kit, opt *types.UpsertKvOption) (int, error) | ||
// GetLastKv 获取最新的kv | ||
GetLastKv(kit *kit.Kit, opt *types.GetLastKvOpt) (string, error) | ||
// GetKvByVersion 根据版本获取kv | ||
GetKvByVersion(kit *kit.Kit, bizID, appID uint32, key string, version int) (string, error) | ||
} | ||
|
||
type set struct { | ||
cli *vault.Client | ||
} | ||
|
||
// NewSet ... | ||
func NewSet(opt cc.Vault) (Set, error) { | ||
|
||
config := vault.DefaultConfig() | ||
config.Address = opt.Address | ||
|
||
client, err := vault.NewClient(config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
client.SetToken(opt.Token) | ||
|
||
s := &set{ | ||
cli: client, | ||
} | ||
|
||
return s, nil | ||
} |
Oops, something went wrong.