Skip to content

Commit b519396

Browse files
authored
Merge develop in master (#481)
* doc(IAM): Document changes for IAM support * Add support for IAM (#456) * Feat(IAM): Adding IAM feature * Update constructors for IAM support (#459) * :feat(iam): Generate service constructors to support IAM * fix(vr): Fix vr tests (#463) * fix(vr): Fix vr tests * chore(discovery): Update test for discovery * Regenerate discovery (#464) * new(discovery): Generate discovery * chore(discovery): Hand edits to discovery * test(discovery): Add test for delete_user_data * Regenerate language translator (#465) * new(language-translator): Generate language translator * Chore(lt): Hand edits to language translator and formatting * Regenerate Tone Analyzer (#468) * new(ta): Generate tone analyzer * chore(ta): Hand edits and formatting for tone analyzer * Regenerate conversation (#469) * new(convresation): Generate conversation * chore(conversation): Hand edits for conversation * test(conversation): Add test for delete_user_data * Regenerate Assistant (#470) * new(assistant): Generate assistant * chore(assistant): Hand edits and formatting * test(assistant): Add test for delete_user_data * chore(assistant): Add newline * Regenerate Text to Speech (#471) * new(tts): Generate tts * chore(tts): Hand edits and pylint complaints for tts * Regenerate natural language understanding (#466) * new(nlu): Generate natural language understanding * chore(nlu): hand edits for nlu * Regenerate Visual recognition (#473) * new(vr): Genetate visual recognition * chore(cr): Hand edits for visual recognition * Regenerate Persoanlity Insights (#467) * new(personality insights): Generate personality insights * chore(pi): hand edits for personality insights * chore(pi): Hand edits remove profile_as_csv * Regenerate Speech to text (#472) * new(stt): Generate stt * chore(stt): Hand edits for speech to text * chore(stt): Pylint * chore(deprecated): Use proper deprecation message * test(discovery): Update the discovery test (#474) * chore(pylint): Handle pylint issues (#476) * :docs(IAM): Update readme with IAM examples (#478) * :docs(IAM): Update readme with IAM examples * Adding <code> around the method * chore(readme): Update readme with IAM examples * Generated changes for python 1.3.5 (#480) * new(generator): Direct generator + formatting * new(codegen): generated sdk changes + formatting * new(codegen): generator + formatting * fix(manual): Handedits for all services * doc(readme): support set_iam_api_key * fix(readme): remove VR auth from readme
1 parent c8e8f23 commit b519396

18 files changed

+1212
-409
lines changed

README.md

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,80 @@ To create an instance of the service:
5959
1. Type a unique name for the service instance in the **Service name** field. For example, type `my-service-name`. Leave the default values for the other options.
6060
1. Click **Create**.
6161

62+
## Authentication
6263
To get your service credentials:
6364

6465
Copy your credentials from the **Manage** page. To find the Service details page for an existing service, navigate to your [IBM Cloud][ibm_cloud] dashboard and click the service name.
6566

6667
1. On the **Manage** page, you will see a **Credentials** pane
6768
1. Depending on the service you will see use either:
68-
* 2.a: `username`, `password`, and `url`(optional).
69+
* 2.a: `username`, `password`, and `url`(optional) or `apikey`(for Visual Recognition).
6970
* 2.b: `apikey` which is the value for parameter `iam_api_key` when initializing the constructor.
7071

72+
### Username and Password
73+
```python
74+
from watson_developer_cloud import DiscoveryV1
75+
# In the constructor
76+
discovery = DiscoveryV1(version='2017-10-16', username='<username>', password='<password>')
77+
```
78+
79+
```python
80+
# After instantiation
81+
discovery = DiscoveryV1(version='2017-10-16')
82+
discovery.set_username_and_password('<username>', '<password>')
83+
```
84+
85+
### API Key
86+
*Important: Instantiation with API key works only with Visual Recognition service instances created before May 23, 2018. Visual Recognition instances created after May 22 use IAM.*
87+
88+
```python
89+
from watson_developer_cloud import VisualRecognitionV3
90+
# In the constructor
91+
visual_recognition = VisualRecognitionV3(version='2018-05-22', api_key='<api_key>')
92+
```
93+
94+
```python
95+
# After instantiation
96+
visual_recognition = VisualRecognitionV3(version='2018-05-22')
97+
visual_recognition.set_api_key('<api_key>')
98+
```
99+
100+
### Using IAM
101+
102+
When authenticating with IAM, you have the option of passing in:
103+
104+
* the IAM API key and, optionally, the IAM service URL
105+
* an IAM access token
106+
107+
**Be aware that passing in an access token means that you're assuming responsibility for maintaining that token's lifecycle.** If you instead pass in an IAM API key, the SDK will manage it for you.
108+
109+
```python
110+
# In the constructor, letting the SDK manage the IAM token
111+
discovery = DiscoveryV1(version='2017-10-16',
112+
iam_api_key='<iam_api_key>',
113+
iam_url='<iam_url>') # optional - the default value is https://iam.ng.bluemix.net/identity/token
114+
```
115+
116+
```python
117+
# after instantiation, letting the SDK manage the IAM token
118+
discovery = DiscoveryV1(version='2017-10-16')
119+
discovery.set_iam_api_key('<iam_api_key>')
120+
```
121+
122+
```python
123+
# in the constructor, assuming control of managing IAM token
124+
discovery = DiscoveryV1(version='2017-10-16',
125+
iam_access_token='<iam_access_token>')
126+
```
127+
128+
```python
129+
# after instantiation, assuming control of managing IAM token
130+
discovery = DiscoveryV1(version='2017-10-16')
131+
discovery.set_iam_access_token('<access_token>')
132+
```
133+
134+
If at any time you would like to let the SDK take over managing your IAM token, simply override your stored IAM credentials with an IAM API key by calling the `set_token_manager()` method again.
135+
71136
## Python Version
72137

73138
Tested on Python 2.7, 3.4, 3.5, and 3.6.

test/unit/test_speech_to_text_v1.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,3 +493,18 @@ def test_custom_audio_resources():
493493

494494
speech_to_text.list_audio('custid')
495495
assert responses.calls[3].response.json() == {"get response all": "done"}
496+
497+
@responses.activate
498+
def test_delete_user_data():
499+
url = 'https://stream.watsonplatform.net/speech-to-text/api/v1/user_data'
500+
responses.add(
501+
responses.DELETE,
502+
url,
503+
body='{"description": "success" }',
504+
status=200,
505+
content_type='application_json')
506+
507+
speech_to_text = watson_developer_cloud.SpeechToTextV1(username="username", password="password")
508+
response = speech_to_text.delete_user_data('id')
509+
assert response is None
510+
assert len(responses.calls) == 1

test/unit/test_text_to_speech_v1.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,19 @@ def test_custom_words():
227227
text_to_speech.delete_word(customization_id="custid", word="word")
228228

229229
assert len(responses.calls) == 5
230+
231+
@responses.activate
232+
233+
def test_delete_user_data():
234+
url = 'https://stream.watsonplatform.net/text-to-speech/api/v1/user_data'
235+
responses.add(
236+
responses.DELETE,
237+
url,
238+
body='{"description": "success" }',
239+
status=200,
240+
content_type='application_json')
241+
242+
text_to_speech = watson_developer_cloud.TextToSpeechV1(username="username", password="password")
243+
response = text_to_speech.delete_user_data('id')
244+
assert response is None
245+
assert len(responses.calls) == 1

test/unit/test_visual_recognition_v3.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,18 @@ def test_detect_faces(self):
233233
with open(os.path.join(os.path.dirname(__file__), '../../resources/test.jpg'), 'rb') as image_file:
234234
vr_service.detect_faces(images_file=image_file)
235235
assert len(responses.calls) == 2
236+
237+
@responses.activate
238+
def test_delete_user_data():
239+
url = "{0}{1}".format(base_url, 'v3/user_data')
240+
responses.add(
241+
responses.DELETE,
242+
url,
243+
body='{"description": "success" }',
244+
status=200,
245+
content_type='application_json')
246+
247+
vr_service = watson_developer_cloud.VisualRecognitionV3('2016-10-20', api_key='bogusapikey')
248+
response = vr_service.delete_user_data('id')
249+
assert response is None
250+
assert len(responses.calls) == 1

test/unit/test_watson_service.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ class AnyServiceV1(WatsonService):
1414
default_url = 'https://gateway.watsonplatform.net/test/api'
1515

1616
def __init__(self, version, url=default_url, username=None, password=None,
17+
api_key=None,
1718
iam_api_key=None,
1819
iam_access_token=None,
1920
iam_url=None):
2021
WatsonService.__init__(
2122
self,
2223
vcap_services_name='test',
2324
url=url,
25+
api_key=api_key,
2426
username=username,
2527
password=password,
2628
use_vcap_services=True,
@@ -102,6 +104,12 @@ def test_iam():
102104
service = AnyServiceV1('2017-07-07', iam_api_key="iam_api_key")
103105
assert service.token_manager is not None
104106

107+
iam_url = "https://iam.bluemix.net/identity/token"
108+
service = AnyServiceV1('2017-07-07', username='xxx', password='yyy')
109+
assert service.token_manager is None
110+
service.set_iam_api_key('yyy')
111+
assert service.token_manager is not None
112+
105113
service.token_manager.token_info = {
106114
"access_token": "dummy",
107115
"token_type": "Bearer",

0 commit comments

Comments
 (0)