#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ # @Version : Python 3.11.4 # @Software : Sublime Text 4 # @Author : StudentCWZ # @Email : StudentCWZ@outlook.com # @Date : 2023/10/28 15:06 # @File : consul.py # @Description : """ from typing import Any import consul import yaml class ConsulConfig: def __init__(self, host='localhost', port=8500, token=None, dc='dc1'): self.token = token self.dc = dc self.client = consul.Consul(host=host, port=port, token=token, dc=dc) def get(self, key: str) -> Any: _, data = self.client.kv.get(key=key, token=self.token, dc=self.dc) if data is None: raise KeyError(f'Key {key} not found in Consul.') return yaml.load(data['Value'], Loader=yaml.FullLoader)