Skip to content

Commit 02dba53

Browse files
committed
Change the format of documents
1 parent d789762 commit 02dba53

File tree

2 files changed

+80
-68
lines changed

2 files changed

+80
-68
lines changed

README.rst

Lines changed: 79 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ modifications. The instructions assume that is stored as quickstart.py, but you
8787
can use any name you like. The quickstart example supports 3 environments:
8888

8989
1. Oracle NoSQL Database Cloud Service
90-
2. Oracle NoSQL Cloud Simulator
91-
3. Oracle NoSQL Database on-premise, using the proxy server
90+
2. Oracle NoSQL Cloud Simulator
91+
3. Oracle NoSQL Database on-premise, using the proxy server
9292

9393
See `Running Quickstart <#run-quickstart>`_ for instructions on how to edit and
9494
run the quickstart program in different environments. The instructions assume
@@ -106,117 +106,120 @@ that the *borneo* package has been installed.
106106
#
107107
108108
#
109-
# This is a simple quickstart to demonstrate use of the Python driver for the
110-
# Oracle NoSQL Database. It can be used to run against the Oracle NoSQL Database
111-
# Cloud Service, against the Cloud Simulator, or against an on-premise Oracle
112-
# NoSQL database.
109+
# This is a simple quickstart to demonstrate use of the Python driver for
110+
# the Oracle NoSQL Database. It can be used to run against the Oracle NoSQL
111+
# Database Cloud Service, against the Cloud Simulator, or against an
112+
# on-premise Oracle NoSQL database.
113113
#
114114
# Usage:
115-
# python quickstart.py <cloud|cloudsim|kvstore>
115+
# python quickstart.py <cloud | cloudsim | kvstore>
116116
#
117117
# Use cloud for the Cloud Service
118118
# Use cloudsim for the Cloud Simulator
119119
# Use kvstore for the on-premise database
120120
#
121-
# This example is not intended to be an exhaustive overview of the API, which
122-
# has a number of additional operations.
121+
# This example is not intended to be an exhaustive overview of the API,
122+
# which has a number of additional operations.
123123
#
124124
# Requirements:
125125
# 1. Python 2.7 or 3.5+
126126
# 2. Python dependencies (install using pip or other mechanism):
127127
# o requests
128128
# o oci (only if running against the Cloud Service)
129-
# 3. If running against the Cloud Simulator, it can be downloaded from here:
129+
# 3. If running against the Cloud Simulator, it can be downloaded from
130+
# here:
130131
# http://www.oracle.com/technetwork/topics/cloud/downloads/index.html
131132
# It requires Java
132-
# 4. If running against the Oracle NoSQL Database Cloud Service an account must
133-
# be used.
133+
# 4. If running against the Oracle NoSQL Database Cloud Service an account
134+
# must be used.
134135
#
135136
136137
import sys
137138
138139
from borneo import (
139-
AuthorizationProvider, DeleteRequest, GetRequest, IllegalArgumentException,
140-
NoSQLHandle, NoSQLHandleConfig, PutRequest, QueryRequest, Regions,
141-
TableLimits, TableRequest)
142-
from borneo.iam import(SignatureProvider)
143-
from borneo.kv import(StoreAccessTokenProvider)
140+
AuthorizationProvider, DeleteRequest, GetRequest,
141+
IllegalArgumentException, NoSQLHandle, NoSQLHandleConfig, PutRequest,
142+
QueryRequest, Regions, TableLimits, TableRequest)
143+
from borneo.iam import SignatureProvider
144+
from borneo.kv import StoreAccessTokenProvider
144145
145146
146147
#
147-
# EDIT: these values based on desired region and/or endpoint for a local server
148+
# EDIT: these values based on desired region and/or endpoint for a local
149+
# server
148150
#
149151
cloud_region = Regions.EU_ZURICH_1
150152
cloudsim_endpoint = 'localhost:8080'
151153
kvstore_endpoint = 'localhost:80'
152-
cloudsim_id = 'cloudsim' # a fake user id/namespace for the Cloud Simulator
154+
cloudsim_id = 'cloudsim' # a fake user id/namespace for the Cloud Simulator
153155
154156
# Cloud Service Only
155157
#
156158
# EDIT: set these variables to the credentials to use if you are not using
157159
# a configuration file in ~/.oci/config
158-
# Use of these credentials vs a file is determined by a value of
159-
# tenancy other than None.
160+
# Use of these credentials vs a file is determined by a value of tenancy
161+
# other than None.
160162
#
161-
tenancy = None # tenancy'd OCID (string)
162-
user = None # user's OCID (string)
163+
tenancy = None # tenancy'd OCID (string)
164+
user = None # user's OCID (string)
163165
private_key = 'path-to-private-key-or-private-key-content'
164166
fingerprint = 'fingerprint for uploaded public key'
165-
pass_phrase = None # pass phrase (string) for private key, or None if not set
167+
# pass phrase (string) for private key, or None if not set
168+
pass_phrase = None
169+
166170
167171
class CloudsimAuthorizationProvider(AuthorizationProvider):
168172
"""
169173
Cloud Simulator Only.
170174
171175
This class is used as an AuthorizationProvider when using the Cloud
172176
Simulator, which has no security configuration. It accepts a string
173-
id that is used as a simple namespace for tables.
177+
tenant_id that is used as a simple namespace for tables.
174178
"""
175179
176-
def __init__(self, id):
180+
def __init__(self, tenant_id):
177181
super(CloudsimAuthorizationProvider, self).__init__()
178-
self._id = id
182+
self._tenant_id = tenant_id
179183
180184
def close(self):
181185
pass
182186
183187
def get_authorization_string(self, request=None):
184-
return 'Bearer ' + self._id
188+
return 'Bearer ' + self._tenant_id
185189
186190
187191
def get_handle(nosql_env):
188192
"""
189-
Returns a NoSQLHandle based on the requested environment. The differences
190-
among the supported environments are encapsulated in this method.
193+
Returns a NoSQLHandle based on the requested environment. The
194+
differences among the supported environments are encapsulated in this
195+
method.
191196
"""
192-
provider = None
193-
endpoint = None
194-
195197
if nosql_env == 'cloud':
196198
endpoint = cloud_region
197199
#
198-
# Get credentials using SignatureProvider. SignatureProvider
199-
# has several ways to accept credentials. See the documentation:
200+
# Get credentials using SignatureProvider. SignatureProvider has
201+
# several ways to accept credentials. See the documentation:
200202
# https://nosql-python-sdk.readthedocs.io/en/latest/api/borneo.iam.SignatureProvider.html
201203
#
202204
if tenancy is not None:
203205
print('Using directly provided credentials')
204206
#
205207
# Credentials are provided directly
206208
#
207-
provider = SignatureProvider(tenant_id = tenancy,
208-
user_id = user,
209-
fingerprint = fingerprint,
210-
private_key = private_key,
211-
pass_phrase = pass_phrase)
209+
provider = SignatureProvider(tenant_id=tenancy,
210+
user_id=user,
211+
fingerprint=fingerprint,
212+
private_key=private_key,
213+
pass_phrase=pass_phrase)
212214
else:
213215
#
214216
# Credentials will come from a file.
215217
#
216218
# By default the file is ~/.oci/config. A config_file = <path>
217219
# argument can be passed to specify a different file.
218220
#
219-
print('Using credentials and DEFAULT profile from ~/.oci/config')
221+
print('Using credentials and DEFAULT profile from ' +
222+
'~/.oci/config')
220223
provider = SignatureProvider()
221224
elif nosql_env == 'cloudsim':
222225
print('Using cloud simulator endpoint ' + cloudsim_endpoint)
@@ -233,12 +236,13 @@ that the *borneo* package has been installed.
233236
234237
return NoSQLHandle(NoSQLHandleConfig(endpoint, provider))
235238
239+
236240
def main():
237241
238242
table_name = 'PythonQuickstart'
239243
240244
if len(sys.argv) != 2:
241-
print('Usage: python quickstart.py <cloud|cloudsim|kvstore>')
245+
print('Usage: python quickstart.py <cloud | cloudsim | kvstore>')
242246
raise SystemExit
243247
244248
nosql_env = sys.argv[1:][0]
@@ -255,8 +259,9 @@ that the *borneo* package has been installed.
255259
#
256260
# Create a table
257261
#
258-
statement = ('Create table if not exists {} (id integer, ' +
259-
'sid integer, name string, primary key(shard(sid), id))').format(table_name)
262+
statement = (
263+
'Create table if not exists {} (id integer, sid integer, ' +
264+
'name string, primary key(shard(sid), id))').format(table_name)
260265
request = TableRequest().set_statement(statement).set_table_limits(
261266
TableLimits(30, 10, 1))
262267
handle.do_table_request(request, 50000, 3000)
@@ -283,7 +288,8 @@ that the *borneo* package has been installed.
283288
#
284289
# Query, using a range
285290
#
286-
statement = 'select * from ' + table_name + ' where id > 2 and id < 8'
291+
statement = (
292+
'select * from ' + table_name + ' where id > 2 and id < 8')
287293
request = QueryRequest().set_statement(statement)
288294
result = handle.query(request)
289295
print('Query results for: ' + statement)
@@ -293,8 +299,8 @@ that the *borneo* package has been installed.
293299
#
294300
# Delete the row
295301
#
296-
request = DeleteRequest().set_key({'id': 1, 'sid': 0}).set_table_name(
297-
table_name)
302+
request = DeleteRequest().set_table_name(table_name).set_key(
303+
{'id': 1, 'sid': 0})
298304
result = handle.delete(request)
299305
print('After delete: ' + str(result))
300306
@@ -341,8 +347,9 @@ Run Against the Oracle NoSQL Database Cloud Service
341347
===================================================
342348

343349
Running against the Cloud Service requires an Oracle Cloud account. See
344-
`Configure for the Cloud Service <https://nosql-python-sdk.readthedocs.io/en/latest/installation.html#configure-for-the-cloud-service>`_ for information on getting
345-
an account and acquiring required credentials.
350+
`Configure for the Cloud Service <https://nosql-python-sdk.readthedocs.io/en/
351+
latest/installation.html#configure-for-the-cloud-service>`_ for information on
352+
getting an account and acquiring required credentials.
346353

347354
1. Collect the following information:
348355

@@ -352,15 +359,18 @@ an account and acquiring required credentials.
352359
* Fingerprint for the public key uploaded to the user's account
353360
* Private key pass phrase, needed only if the private key is encrypted
354361

355-
2. Edit *quickstart.py* and add your information. There are 2 ways to supply
362+
2. Edit *quickstart.py* and add your information. There are 2 ways to supply
356363
credentials in the program:
357364

358365
* Directly provide the credential information. To use this method, modify the
359366
values of the variables at the top of the program: *tenancy*, *user*,
360367
*private_key*, *fingerprint*, and *pass_phrase*, setting them to the
361368
corresponding information you've collected.
362369
* Using a configuration file. In this case the information you've collected
363-
goes into a file, ~/.oci/config. `Configure for the Cloud Service <https://nosql-python-sdk.readthedocs.io/en/latest/installation.html#configure-for-the-cloud-service>`_ describes the contents of the file. It will look like this::
370+
goes into a file, ~/.oci/config. `Configure for the Cloud Service <https://
371+
nosql-python-sdk.readthedocs.io/en/latest/installation.html#configure-for-
372+
the-cloud-service>`_ describes the contents of the file. It will look like
373+
this::
364374

365375
[DEFAULT]
366376
tenancy=<your-tenancy-id>
@@ -370,22 +380,23 @@ an account and acquiring required credentials.
370380
pass_phrase=<optional-pass-phrase-for-key-file>
371381

372382
3. Decide which region you want to use and modify the *cloud_region* variable to
373-
the desired region. See `Regions documentation <https://nosql-python-sdk.readthedocs.io/en/latest/api/borneo.Regions.html>`_ for possible regions. Not all support
374-
the Oracle NoSQL Database Cloud Service.
383+
the desired region. See `Regions documentation <https://nosql-python-sdk.
384+
readthedocs.io/en/latest/api/borneo.Regions.html>`_ for possible regions. Not
385+
all support the Oracle NoSQL Database Cloud Service.
375386

376387
4. Run the program:
377388

378389
.. code-block:: pycon
379390
380391
python quickstart.py cloud
381392
382-
383393
Run Against the Oracle NoSQL Cloud Simulator
384394
============================================
385395

386396
Running against the Oracle NoSQL Cloud Simulator requires a running Cloud
387-
Simulator instance. See `Using the Cloud Simulator <https://oracle.github.io/nosql-node-sdk/tutorial-connect-cloud.html#cloudsim>`_ for information on how to download
388-
and start the Cloud Simulator.
397+
Simulator instance. See `Using the Cloud Simulator <https://oracle.github.io/
398+
nosql-node-sdk/tutorial-connect-cloud.html#cloudsim>`_ for information on how to
399+
download and start the Cloud Simulator.
389400

390401
1. Start the Cloud Simulator based on instructions above. Note the HTTP port
391402
used. By default it is *8080* on *localhost*.
@@ -402,21 +413,22 @@ and start the Cloud Simulator.
402413
Run Against Oracle NoSQL on-premise
403414
===================================
404415

405-
Running against the Oracle NoSQL Database on-premise requires a running
406-
Oracle NoSQL Database instance as well as a running NoSQL Proxy server instance.
407-
The program will connect to the proxy server.
416+
Running against the Oracle NoSQL Database on-premise requires a running Oracle
417+
NoSQL Database instance as well as a running NoSQL Proxy server instance. The
418+
program will connect to the proxy server.
408419

409-
See `Connecting to an On-Premise Oracle NoSQL Database <https://oracle.github.io/nosql-node-sdk/tutorial-connect-on-prem.html>`_ for information on how to download
410-
and start the database instance and proxy server. The database and proxy should
411-
be started without security enabled for this quickstart program to operate
412-
correctly. A secure configuration requires a secure proxy and more complex
413-
configuration.
420+
See `Connecting to an On-Premise Oracle NoSQL Database <https://oracle.github.io
421+
/nosql-node-sdk/tutorial-connect-on-prem.html>`_ for information on how to
422+
download and start the database instance and proxy server. The database and
423+
proxy should be started without security enabled for this quickstart program to
424+
operate correctly. A secure configuration requires a secure proxy and more
425+
complex configuration.
414426

415-
1. Start the Oracle NoSQL Database and proxy server based on instructions above.
427+
1. Start the Oracle NoSQL Database and proxy server based on instructions above.
416428
Note the HTTP port used. By default the endpoint is *localhost:80*.
417429

418-
2. The *quickstart.py* program defaults to *localhost:80*. If the proxy was started
419-
using a different host or port edit the settings accordingly.
430+
2. The *quickstart.py* program defaults to *localhost:80*. If the proxy was
431+
started using a different host or port edit the settings accordingly.
420432

421433
3. Run the program:
422434

src/borneo/iam/iam.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def __init__(self, provider=None, config_file=None, profile_name=None,
157157
# Use user profile with default profile name and private key
158158
# from specified configuration file.
159159
config = oci.config.from_file(file_location=config_file)
160-
elif config_file is not None and profile_name is not None:
160+
else: # config_file is not None and profile_name is not None
161161
# Use user profile with given profile name and private key
162162
# from specified configuration file.
163163
config = oci.config.from_file(

0 commit comments

Comments
 (0)