Skip to content

Commit

Permalink
fix: fail to get the current IP address (SSLError: HTTPSConnectionPoo…
Browse files Browse the repository at this point in the history
…l) (#22)

- Use os.environmet.get to get project ID, cluster ID, and cluster password
- Close #21
  • Loading branch information
Oreoxmt authored Oct 2, 2023
1 parent 38e9d97 commit 944fc7f
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 112 deletions.
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ You can use this SDK to access [TiDB Cloud](https://tidbcloud.com) and manage yo

`tidbcloudy` is compatible with [TiDB Cloud API](https://docs.pingcap.com/tidbcloud/api/v1beta). **Endpoints added in [Release 20230228](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20230228) and [Release 20230328](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20230328) are not supported for now**. The following table lists the supported API versions:

| tidbcloudy | TiDB Cloud API |
|---|---|
| [1.0.5](https://github.com/Oreoxmt/tidbcloudy/releases/tag/v1.0.5) | v1beta [Release 20230602](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20230602), [Release 20230801](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20230801) |
| tidbcloudy | TiDB Cloud API |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [1.0.5](https://github.com/Oreoxmt/tidbcloudy/releases/tag/v1.0.5), [1.0.6](https://github.com/Oreoxmt/tidbcloudy/releases/tag/v1.0.6) | v1beta [Release 20230602](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20230602), [Release 20230801](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20230801) |
| [1.0.1](https://github.com/Oreoxmt/tidbcloudy/releases/tag/v1.0.1), [1.0.2](https://github.com/Oreoxmt/tidbcloudy/releases/tag/v1.0.2), [1.0.3](https://github.com/Oreoxmt/tidbcloudy/releases/tag/v1.0.3), [1.0.4](https://github.com/Oreoxmt/tidbcloudy/releases/tag/v1.0.4) | v1beta [Release 20220906](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20220906), [Release 20220920](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20220920), [Release 20221028](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20221028), [Release 20230104](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20230104), [Release 20230214](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20230214), [Release 20230321](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20230321) |
| [1.0.0](https://github.com/Oreoxmt/tidbcloudy/releases/tag/v1.0.0) | v1beta [Release 20220823](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20220823) |
| [0.2.1](https://github.com/Oreoxmt/tidbcloudy/releases/tag/v0.2.1) | v1beta [Release 20220809](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20220809) |
| [1.0.0](https://github.com/Oreoxmt/tidbcloudy/releases/tag/v1.0.0) | v1beta [Release 20220823](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20220823) |
| [0.2.1](https://github.com/Oreoxmt/tidbcloudy/releases/tag/v0.2.1) | v1beta [Release 20220809](https://docs.pingcap.com/tidbcloud/api/v1beta#section/API-Changelog/20220809) |

### Enhancements comparing to original [TiDB Cloud API](https://docs.pingcap.com/tidbcloud/api/v1beta)

Expand Down Expand Up @@ -165,7 +165,7 @@ from tidbcloudy.specification import CreateClusterConfig
public_key = os.environ.get("PUBLIC_KEY")
private_key = os.environ.get("PRIVATE_KEY")
debug_mode = os.environ.get("TIDBCLOUDY_LOG")
project_id = "1234567890123456789"
project_id = os.environ.get("PROJECT_ID", "1234567890123456789")
api = tidbcloudy.TiDBCloud(public_key=public_key, private_key=private_key)
project = api.get_project(project_id, update_from_server=True)
Expand Down Expand Up @@ -196,8 +196,8 @@ from tidbcloudy.specification import ClusterStatus
public_key = os.environ.get("PUBLIC_KEY")
private_key = os.environ.get("PRIVATE_KEY")
project_id = "1234567890123456789"
cluster_id = "1234567890123456789"
project_id = os.environ.get("PROJECT_ID", "1234567890123456789")
cluster_id = os.environ.get("CLUSTER_ID", "1234567890123456789")
print("Connecting to TiDB Cloud...")
api = tidbcloudy.TiDBCloud(public_key=public_key, private_key=private_key)
Expand All @@ -207,7 +207,7 @@ print(cluster)
if cluster.status.cluster_status == ClusterStatus.AVAILABLE:
connection_strings = cluster.status.connection_strings
connection = cluster.connect(type="standard", database="test", password="your_root_password")
connection = cluster.connect(type="standard", database="test", password=os.environ.get("CLUSTER_PWD", "your_root_password"))
print(connection)
with connection:
with connection.cursor() as cursor:
Expand All @@ -232,8 +232,8 @@ from tidbcloudy.specification import UpdateClusterConfig
public_key = os.environ.get("PUBLIC_KEY")
private_key = os.environ.get("PRIVATE_KEY")
project_id = "1234567890123456789"
cluster_id = "1234567890123456789"
project_id = os.environ.get("PROJECT_ID", "1234567890123456789")
cluster_id = os.environ.get("CLUSTER_ID", "1234567890123456789")
api = tidbcloudy.TiDBCloud(public_key=public_key, private_key=private_key)
project = api.get_project(project_id, update_from_server=True)
Expand Down Expand Up @@ -265,8 +265,8 @@ from tidbcloudy.specification import CreateClusterConfig
public_key = os.environ.get("PUBLIC_KEY")
private_key = os.environ.get("PRIVATE_KEY")
project_id = "1234567890123456789"
cluster_id = "1234567890123456789"
project_id = os.environ.get("PROJECT_ID", "1234567890123456789")
cluster_id = os.environ.get("CLUSTER_ID", "1234567890123456789")
backup_id = "1234567"
api = tidbcloudy.TiDBCloud(public_key=public_key, private_key=private_key)
Expand Down Expand Up @@ -307,8 +307,8 @@ from tidbcloudy.specification import ClusterStatus
public_key = os.environ.get("PUBLIC_KEY")
private_key = os.environ.get("PRIVATE_KEY")
project_id = "1234567890123456789"
cluster_id = "1234567890123456789"
project_id = os.environ.get("PROJECT_ID", "1234567890123456789")
cluster_id = os.environ.get("CLUSTER_ID", "1234567890123456789")
api = tidbcloudy.TiDBCloud(public_key=public_key, private_key=private_key)
project = api.get_project(project_id, update_from_server=True)
Expand Down Expand Up @@ -341,7 +341,7 @@ from tidbcloudy.specification import ClusterType
public_key = os.environ.get("PUBLIC_KEY")
private_key = os.environ.get("PRIVATE_KEY")
project_id = "1234567890123456789"
project_id = os.environ.get("PROJECT_ID", "1234567890123456789")
api = tidbcloudy.TiDBCloud(public_key=public_key, private_key=private_key)
project = api.get_project(project_id, update_from_server=True)
Expand Down
2 changes: 1 addition & 1 deletion examples/0_list_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public_key = os.environ.get("PUBLIC_KEY")
private_key = os.environ.get("PRIVATE_KEY")
debug_mode = os.environ.get("TIDBCLOUDY_LOG")
project_id = "1234567890123456789"
project_id = os.environ.get("PROJECT_ID", "1234567890123456789")

api = tidbcloudy.TiDBCloud(public_key=public_key, private_key=private_key)

Expand Down
4 changes: 2 additions & 2 deletions examples/2_1_create_serverless_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
public_key = os.environ.get("PUBLIC_KEY")
private_key = os.environ.get("PRIVATE_KEY")
debug_mode = os.environ.get("TIDBCLOUDY_LOG")
project_id = "1372813089206751385"
project_id = os.environ.get("PROJECT_ID", "1234567890123456789")

api = tidbcloudy.TiDBCloud(public_key=public_key, private_key=private_key)
project = api.get_project(project_id, update_from_server=True)

config = CreateClusterConfig()
config\
.set_name("serverless-test") \
.set_name("serverless-0") \
.set_cluster_type("DEVELOPER") \
.set_cloud_provider("AWS") \
.set_region("us-west-2") \
Expand Down
2 changes: 1 addition & 1 deletion examples/2_2_create_dedicated_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public_key = os.environ.get("PUBLIC_KEY")
private_key = os.environ.get("PRIVATE_KEY")
debug_mode = os.environ.get("TIDBCLOUDY_LOG")
project_id = "1372813089206751385"
project_id = os.environ.get("PROJECT_ID", "1234567890123456789")

api = tidbcloudy.TiDBCloud(public_key=public_key, private_key=private_key)
project = api.get_project(project_id, update_from_server=True)
Expand Down
6 changes: 3 additions & 3 deletions examples/3_connect_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
public_key = os.environ.get("PUBLIC_KEY")
private_key = os.environ.get("PRIVATE_KEY")
debug_mode = os.environ.get("TIDBCLOUDY_LOG")
project_id = "1372813089206751385"
cluster_id = "10912822641423447137"
project_id = os.environ.get("PROJECT_ID", "1234567890123456789")
cluster_id = os.environ.get("CLUSTER_ID", "1234567890123456789")

print("Connecting to TiDB Cloud...")
api = tidbcloudy.TiDBCloud(public_key=public_key, private_key=private_key)
Expand All @@ -17,7 +17,7 @@

if cluster.status.cluster_status == ClusterStatus.AVAILABLE:
connection_strings = cluster.status.connection_strings
connection = cluster.connect(type="standard", database="test", password="xQXacEZAoomvb9BN")
connection = cluster.connect(type="standard", database="test", password=os.environ.get("CLUSTER_PWD", "your_root_password"))
print(connection)
with connection:
with connection.cursor() as cursor:
Expand Down
4 changes: 2 additions & 2 deletions examples/4_scale_a_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
public_key = os.environ.get("PUBLIC_KEY")
private_key = os.environ.get("PRIVATE_KEY")
debug_mode = os.environ.get("TIDBCLOUDY_LOG")
project_id = "1234567890123456789"
cluster_id = "1234567890123456789"
project_id = os.environ.get("PROJECT_ID", "1234567890123456789")
cluster_id = os.environ.get("CLUSTER_ID", "1234567890123456789")

api = tidbcloudy.TiDBCloud(public_key=public_key, private_key=private_key)
project = api.get_project(project_id, update_from_server=True)
Expand Down
4 changes: 2 additions & 2 deletions examples/5_backup_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
public_key = os.environ.get("PUBLIC_KEY")
private_key = os.environ.get("PRIVATE_KEY")
debug_mode = os.environ.get("TIDBCLOUDY_LOG")
project_id = "1234567890123456789"
cluster_id = "1234567890123456789"
project_id = os.environ.get("PROJECT_ID", "1234567890123456789")
cluster_id = os.environ.get("CLUSTER_ID", "1234567890123456789")
backup_id = "1234567"

api = tidbcloudy.TiDBCloud(public_key=public_key, private_key=private_key)
Expand Down
4 changes: 2 additions & 2 deletions examples/6_pause_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
public_key = os.environ.get("PUBLIC_KEY")
private_key = os.environ.get("PRIVATE_KEY")
debug_mode = os.environ.get("TIDBCLOUDY_LOG")
project_id = "1372813089206751385"
cluster_id = "1379661944646412338"
project_id = os.environ.get("PROJECT_ID", "1234567890123456789")
cluster_id = os.environ.get("CLUSTER_ID", "1234567890123456789")

api = tidbcloudy.TiDBCloud(public_key=public_key, private_key=private_key)
project = api.get_project(project_id, update_from_server=True)
Expand Down
2 changes: 1 addition & 1 deletion examples/7_delete_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public_key = os.environ.get("PUBLIC_KEY")
private_key = os.environ.get("PRIVATE_KEY")
debug_mode = os.environ.get("TIDBCLOUDY_LOG")
project_id = "1234567890123456789"
project_id = os.environ.get("PROJECT_ID", "1234567890123456789")

api = tidbcloudy.TiDBCloud(public_key=public_key, private_key=private_key)
project = api.get_project(project_id, update_from_server=True)
Expand Down
Loading

0 comments on commit 944fc7f

Please sign in to comment.