/
zhendosina
/
obshell-sdk-python
Обзор
Документация
Войти
/
zhendosina
/
obshell-sdk-python
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
obshell/info.py
55 строк
2 KB
禹梁
PullRequest: 75 feat: support https
13 апр 2026, 06:32
13 апр 2026, 06:32
58e55bf
Код
Авторство
О чём код?
# coding: utf-8 # Copyright (c) 2024 OceanBase. # # 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 requests from obshell.model.info import AgentInfo from obshell.request import ProtocolOptions DEFAULT_TIMEOUT = 1000 def get_info(server: str, protocol_options: ProtocolOptions = ProtocolOptions.http()): url = f"{protocol_options.protocol}://{server}/api/v1/info" resp = requests.get(url, timeout=DEFAULT_TIMEOUT, verify=protocol_options.verify_cert, cert=protocol_options.client_cert) if resp.status_code != 200: raise Exception(f"Failed to get info from {server}, url: {url}, " f"status code: {resp.status_code}") data = resp.json().get("data", {}) if not data: raise Exception(f"Failed to get info from {server}, no data") identity = data.get("identity") version = data.get("version") supported_auth = data.get("supportedAuth", []) hold_obproxy = data.get("security", False) is_obproxy_agent = data.get("isObproxyAgent", False) info = AgentInfo(identity, version, supported_auth, hold_obproxy, is_obproxy_agent) return info def get_public_key(server: str, protocol_options: ProtocolOptions = ProtocolOptions.http()): url = f"{protocol_options.protocol}://{server}/api/v1/secret" resp = requests.get(url, timeout=DEFAULT_TIMEOUT, verify=protocol_options.verify_cert, cert=protocol_options.client_cert) if resp.status_code != 200: raise Exception(f"Failed to get public key from {server}, " f"status code: {resp.status_code}") data = resp.json().get("data", {}) if not data: raise Exception(f"Failed to get info from {server}, no data") return data.get("public_key")