Skip to content

Commit 0488d2b

Browse files
author
金山云SDK
authored
Merge pull request KscSDK#1 from liuyichen/master
README及安装包信息修正
2 parents 25d0d5d + b38255c commit 0488d2b

File tree

9 files changed

+139
-133
lines changed

9 files changed

+139
-133
lines changed

LICENSE.txt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
Copyright 2012-2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2-
3-
Licensed under the Apache License, Version 2.0 (the "License"). You
4-
may not use this file except in compliance with the License. A copy of
5-
the License is located at
6-
7-
http://aws.amazon.com/apache2.0/
8-
9-
or in the "license" file accompanying this file. This file is
10-
distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11-
ANY KIND, either express or implied. See the License for the specific
12-
language governing permissions and limitations under the License.
1+
# Copyright (c) 2012-2013 LiuYC https://github.com/liuyichen/
2+
# Copyright 2012-2014 ksyun.com, Inc. or its affiliates. All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"). You
5+
# may not use this file except in compliance with the License. A copy of
6+
# the License is located at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# or in the "license" file accompanying this file. This file is
11+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12+
# ANY KIND, either express or implied. See the License for the specific
13+
# language governing permissions and limitations under the License.

README.rst

Lines changed: 97 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,128 @@
1-
kscore
1+
SDK 使用文档
22
========
33

4-
A low-level interface to a growing number of KSC Web Services. Reference from botocore.
4+
A low-level interface to a growing number of KSC Web Services.
5+
56

6-
`Documentation <http://www.ksyun.com/doc/search?word=API>`__
77

88
----------------
9-
安装
9+
Install 安装
1010
----------------
1111

1212
+ pip 安装
1313
+ pip install kscore
14+
1415
+ github 安装
15-
+ https://github.com/KscSDK/ksc-sdk-python 下载
16-
+ python setup.py install
16+
+ 通过 `GitHub <https://github.com/liuyichen/kscore>`__ 下载
17+
+ 进入`kscore`目录通过命令 python setup.py install 安装
1718

1819
----------------
19-
Credentials 配置
20+
Config 配置
2021
----------------
2122

22-
+ 参考examples内示例
23+
+ 申请安全凭证:
24+
25+
在第一次使用云API之前,用户首先需要在金山云控制台IAM服务申请安全凭证,安全凭证包括access_key_id和secret_access_key,access_key_id 是用于标识API调用者的身份,secret_access_key是用于加密签名字符串和服务器端验证签名字符串的密钥。secret_access_key 必须严格保管,避免泄露。
2326

24-
+ 配置文件: ``.kscore.cfg``
27+
+ 通过文件配置及管理密钥,参考examples内示例:
2528

2629
+ 所在位置: '/etc/kscore.cfg' 或 './.kscore.cfg' 或 'C:\\kscore.cfg'
2730

2831
+ 注意: 使用相对路径时,需与运行目录保持一致。
2932
::
3033

31-
[Credentials]
32-
ks_access_key_id=AKLTyW1V6ZWET7aIvdCeIH1cwQ
33-
ks_secret_access_key=OEoTK4IgEBIq3rlFsbpcNDs87w513D6aOwdXxP6QHuvWlonSRYeKQyTzqc1XkUvpuQ==
34+
[Credentials]
35+
ks_access_key_id=AKLTyW1V6ZWET7aIvdeeIH1cwQ
36+
ks_secret_access_key=OEoTK4IgEBIq3rlFsbpcESs87w513D6aOwdXxP6QHuvWlonSRYeKQyTzqc1XkUvpuQ==
3437

38+
+ 或在程序运行时配置:
3539

36-
+ 或运行时配置
37-
+ session.set_credentials(access_key_id, secret_access_key, session_token=None)
40+
::
41+
42+
from kscore.session import get_session
43+
# 密钥
44+
ACCESS_KEY_ID = "AKLTyW1V6ZWET7aIvdeeIH1cwQ"
45+
SECRET_ACCESS_KEY = "OEoTK4IgEBIq3rlFsbpcESs87w513D6aOwdXxP6QHuvWlonSRYeKQyTzqc1XkUvpuQ=="
46+
47+
s = get_session()
48+
client = s.create_client("iam", ks_access_key_id=ACCESS_KEY_ID, ks_secret_access_key=SECRET_ACCESS_KEY)
3849

3950
----------------
40-
Service 使用
51+
Service 服务
4152
----------------
4253

43-
+ create_client 方法
44-
| service_name 服务,必须参数,例 iam
45-
| region_name=None 大区,必须参数,全局服务可以为None
46-
| api_version=None API版本,默认使用最近版本
47-
| use_ssl=True 是否使用HTTPS,如接口支持情况下,优先使用
48-
| verify=None 是否验证SSL证书
49-
| endpoint_url=None
50-
| ks_access_key_id=None
51-
| ks_secret_access_key=None
52-
| ks_session_token=None
54+
+ 已支持大区 region_name
55+
56+
+-------------------+------------+
57+
| region_name | 大区 |
58+
+===================+============+
59+
| cn-beijing-5 | 北京5区 |
60+
+-------------------+------------+
61+
| cn-beijing-6 | 北京6区 |
62+
+-------------------+------------+
63+
| cn-shanghai-2 | 上海2区 |
64+
+-------------------+------------+
65+
66+
+ 服务列表 service_name, `详情参考API手册 <http://docs.ksyun.com>`__
67+
68+
+-------------------+------------+
69+
| service_name | 服务名 |
70+
+===================+============+
71+
| iam | |
72+
+-------------------+------------+
73+
| eip | |
74+
+-------------------+------------+
75+
| kec | |
76+
+-------------------+------------+
77+
| slb | |
78+
+-------------------+------------+
79+
| vpc | |
80+
+-------------------+------------+
81+
| monitor | |
82+
+-------------------+------------+
5383

84+
----------------
85+
Method 方法
86+
----------------
5487

55-
+ 已支持大区 region_name 参考data/endpoints.yaml
56-
| cn-beijing-5 北京5区
57-
| cn-beijing-6 北京6区
58-
| cn-shanghai-2 上海2区
88+
+ 常用方法
89+
90+
+ get_session
91+
92+
+---------------------------+---------------------------------------+
93+
| 参数 | 说明 |
94+
+===========================+=======================================+
95+
| env_vars | 环境变量 |
96+
+---------------------------+---------------------------------------+
97+
98+
+ create_client
99+
100+
+---------------------------+---------------------------------------+
101+
| 参数 | 说明 |
102+
+===========================+=======================================+
103+
| service_name | 服务,必须参数,例:iam |
104+
+---------------------------+---------------------------------------+
105+
| region_name=None | 大区,必须参数,全局服务可以为None |
106+
+---------------------------+---------------------------------------+
107+
| api_version=None | API 版本,默认使用最近版本 |
108+
+---------------------------+---------------------------------------+
109+
| use_ssl=True | 是否使用HTTPS,优先使用 |
110+
+---------------------------+---------------------------------------+
111+
| verify=None | 是否验证SSL证书 |
112+
+---------------------------+---------------------------------------+
113+
| endpoint_url=None | |
114+
+---------------------------+---------------------------------------+
115+
| ks_access_key_id=None | |
116+
+---------------------------+---------------------------------------+
117+
| ks_secret_access_key=None | |
118+
+---------------------------+---------------------------------------+
119+
| ks_session_token=None | |
120+
+---------------------------+---------------------------------------+
121+
122+
123+
----------------
124+
Examples 示例
125+
----------------
59126

60127
+ IAM
61128

@@ -100,65 +167,8 @@ Service 使用
100167

101168
+ 更多
102169

103-
::
104-
105-
欢迎补充
106-
107-
------------------
108-
Data 更多服务配置
109-
------------------
110-
+ 参考 https://github.com/liuyichen/kscore/issues
111-
+ ENDPOINT 配置
112-
+ data\\endpoints.yaml
113-
114-
::
115-
116-
version: n
117-
partitions:
118-
- partition:
119-
...
120-
# REGION 列表
121-
regions:
122-
...
123-
# 服务列表
124-
- service:
125-
...
126-
127-
+ SERVICE 配置
128-
+ data\\[service]\\[version]\\service-2.yaml
129-
130-
::
131-
132-
version: n
133-
# API 配置
134-
metadata:
135-
...
136-
# 操作方法
137-
operations:
138-
...
139-
# 请求及返回的结构体
140-
shapes:
141-
...
142-
143-
+ 请参考IAM,KEC等配置
144-
145-
配置文件变更后请重新安装 python setup.py install
146-
147-
148-
--------------------
149-
TESTS 测试
150-
--------------------
151-
152-
+ 基本接口测试
153-
154-
\tests\acceptance> behave
155-
156-
+ 各服务测试用例
157-
158-
\tests>nosetests --with-xunit --cover-erase --with-coverage --cover-package kscore --cover-xml -v integration
159-
160170
--------------------
161171
Contact Information
162172
--------------------
163173

164-
邮 箱: ksc_sdk@kingsoft.com
174+
服 务 群 号: 580681922

kscore/data/endpoints.yaml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
---
22
version: 1
33
partitions:
4-
# available zone
5-
- partition: ksyun-cn
6-
partitionName: KS China
7-
# iam.cn-beijing-6.[dnsSuffix]
4+
- partition: ksc
5+
partitionName: KSC China
86
dnsSuffix: api.ksyun.com
97
regionRegex: "^cn\\-\\w+\\-\\d+$"
108
defaults:
@@ -13,13 +11,11 @@ partitions:
1311
protocols:
1412
- http
1513
- https
16-
# signature aws v4
1714
signatureVersions:
1815
- v4
19-
# regions with partition
2016
regions:
21-
ksc-global:
22-
description: KSC partition-global endpoint
17+
ksyun-global:
18+
description: KSYUN partition-global endpoint
2319

2420
cn-shanghai-2:
2521
description: China ShangHai (PengBoShi)
@@ -36,14 +32,16 @@ partitions:
3632
defaults:
3733
credentialScope:
3834
service: kog
39-
EndpointRegion: cn-beijing-6
40-
partitionEndpoint: cn-beijing-6
35+
partitionEndpoint: ksyun-global
36+
isRegionalized: false
4137
endpoints:
42-
cn-beijing-6:
38+
ksyun-global:
39+
hostname: kog.cn-beijing-6.api.ksyun.com
4340
protocols:
4441
- http
4542
- https
46-
43+
credentialScope:
44+
region: cn-beijing-6
4745
iam:
4846
defaults:
4947
protocols:

kscore/data/kog/2016-05-13/service-2.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ operations:
2020
name: AddProject
2121
http:
2222
method: POST
23-
requestUri: /
23+
2424
input:
2525
shape: Project
2626
output:
@@ -30,15 +30,13 @@ operations:
3030
name: DeleteProject
3131
http:
3232
method: DELETE
33-
requestUri: /
3433
input:
3534
shape: InstanceId
3635

3736
EditProject:
3837
name: EditProject
3938
http:
4039
method: PUT
41-
requestUri: /
4240
input:
4341
shape: Project
4442
output:
@@ -48,7 +46,6 @@ operations:
4846
name: GetProjectInfo
4947
http:
5048
method: GET
51-
requestUri: /
5249
input:
5350
shape: Id
5451
output:
@@ -58,7 +55,6 @@ operations:
5855
name: GetProjectList
5956
http:
6057
method: GET
61-
requestUri: /
6258
input:
6359
shape: Empty
6460
documentation: ""

kscore/session.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,27 +75,27 @@ class Session(object):
7575
#: found.
7676
SESSION_VARIABLES = {
7777
# logical: config_file, env_var, default_value, conversion_func
78-
'profile': (None, ['AWS_DEFAULT_PROFILE', 'AWS_PROFILE'], None, None),
79-
'region': ('region', 'AWS_DEFAULT_REGION', None, None),
80-
'data_path': ('data_path', 'AWS_DATA_PATH', None, None),
81-
'config_file': (None, 'AWS_CONFIG_FILE', '~/.ks/config', None),
82-
'ca_bundle': ('ca_bundle', 'AWS_CA_BUNDLE', None, None),
78+
'profile': (None, ['KS_DEFAULT_PROFILE', 'KS_PROFILE'], None, None),
79+
'region': ('region', 'KS_DEFAULT_REGION', None, None),
80+
'data_path': ('data_path', 'KS_DATA_PATH', None, None),
81+
'config_file': (None, 'KS_CONFIG_FILE', '~/.ks/config', None),
82+
'ca_bundle': ('ca_bundle', 'KS_CA_BUNDLE', None, None),
8383
'api_versions': ('api_versions', None, {}, None),
8484
'dynamic_loader': ("dynamic_loader", "KS_DYNAMIC_LOADER", "YAML", None),
8585
# This is the shared credentials file amongst sdks.
86-
'credentials_file': (None, 'AWS_SHARED_CREDENTIALS_FILE',
87-
'~/.aws/credentials', None),
86+
'credentials_file': (None, 'KS_SHARED_CREDENTIALS_FILE',
87+
'~/.ks/credentials', None),
8888

8989
# These variables only exist in the config file.
9090

9191
# This is the number of seconds until we time out a request to
9292
# the instance metadata service.
9393
'metadata_service_timeout': ('metadata_service_timeout',
94-
'AWS_METADATA_SERVICE_TIMEOUT', 1, int),
94+
'KS_METADATA_SERVICE_TIMEOUT', 1, int),
9595
# This is the number of request attempts we make until we give
9696
# up trying to retrieve data from the instance metadata service.
9797
'metadata_service_num_attempts': ('metadata_service_num_attempts',
98-
'AWS_METADATA_SERVICE_NUM_ATTEMPTS', 1, int),
98+
'KS_METADATA_SERVICE_NUM_ATTEMPTS', 1, int),
9999
}
100100

101101
#: The default format string to use when configuring the kscore logger.

0 commit comments

Comments
 (0)