Skip to content

Commit 6d4754a

Browse files
authored
Merge pull request #313 from watson-developer-cloud/feature-credential-service
Feature credential service
2 parents 68199e8 + d8d93f0 commit 6d4754a

23 files changed

+1480
-1359
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ README.md.meta
5353
Travis.meta
5454
exclude-filter.txt
5555
exclude-filter.txt.meta
56+
etc.meta
5657
/Travis/UnityTestProject/Assets/StreamingAssets/Config.json
5758
/Travis/UnityTestProject/Assets/StreamingAssets/Config.json.meta
5859
/Travis/UnityTestProject/Assets/StreamingAssets/Config.json.enc.meta

Config.json.enc

-8.56 KB
Binary file not shown.

Scripts/Services/DocumentConversion/v1/DocumentConversion.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public Credentials Credentials
7171
#region Constructor
7272
public DocumentConversion(Credentials credentials)
7373
{
74+
Log.Warning("DocumentConversion", "The Document Conversion service has been deprecated. Please use the Discovery service.");
75+
7476
if (credentials.HasCredentials() || credentials.HasAuthorizationToken())
7577
{
7678
Credentials = credentials;

Scripts/Services/DocumentConversion/v1/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Document Conversion
22

3+
Important: Starting on 11-03-2017, it will no longer be possible to create a new instance of Document Conversion on Bluemix. Existing service instances will be supported until 10-03-2018. To continue using features, you will need to [migrate](https://console.bluemix.net/docs/services/discovery/migrate-dcs-rr.html#migrating-from-watson-document-conversion-and-retrieve-and-rank). Note: May not apply in select Dedicated environments.
4+
35
The IBM Watson™ [Document conversion][document_conversion] service converts a single HTML, PDF, or Microsoft Word™ document into a normalized HTML, plain text, or a set of JSON-formatted Answer units that can be used with other Watson services. Carefully inspect output to make sure that it contains all elements and metadata required by the security standards of you or your organization.
46

57
## Usage

Scripts/UnitTests/TestAlchemyLanguage.cs

Lines changed: 780 additions & 779 deletions
Large diffs are not rendered by default.

Scripts/UnitTests/TestConversation.cs

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -47,42 +47,45 @@ public class TestConversation : UnitTest
4747
public override IEnumerator RunTest()
4848
{
4949
LogSystem.InstallDefaultReactors();
50-
try
51-
{
52-
VcapCredentials vcapCredentials = new VcapCredentials();
53-
fsData data = null;
54-
55-
// Get credentials from a credential file defined in environmental variables in the VCAP_SERVICES format.
56-
// See https://console.bluemix.net/docs/services/watson/getting-started-variables.html.
57-
var environmentalVariable = Environment.GetEnvironmentVariable("VCAP_SERVICES");
58-
var fileContent = File.ReadAllText(environmentalVariable);
59-
60-
// Add in a parent object because Unity does not like to deserialize root level collection types.
61-
fileContent = Utility.AddTopLevelObjectToJson(fileContent, "VCAP_SERVICES");
62-
63-
// Convert json to fsResult
64-
fsResult r = fsJsonParser.Parse(fileContent, out data);
65-
if (!r.Succeeded)
66-
throw new WatsonException(r.FormattedMessages);
67-
68-
// Convert fsResult to VcapCredentials
69-
object obj = vcapCredentials;
70-
r = _serializer.TryDeserialize(data, obj.GetType(), ref obj);
71-
if (!r.Succeeded)
72-
throw new WatsonException(r.FormattedMessages);
73-
74-
// Set credentials from imported credntials
75-
Credential credential = vcapCredentials.VCAP_SERVICES["conversation"][TestCredentialIndex].Credentials;
76-
_username = credential.Username.ToString();
77-
_password = credential.Password.ToString();
78-
_url = credential.Url.ToString();
79-
_workspaceId = credential.WorkspaceId.ToString();
80-
}
81-
catch
50+
51+
VcapCredentials vcapCredentials = new VcapCredentials();
52+
fsData data = null;
53+
54+
string result = null;
55+
56+
var vcapUrl = Environment.GetEnvironmentVariable("VCAP_URL");
57+
var vcapUsername = Environment.GetEnvironmentVariable("VCAP_USERNAME");
58+
var vcapPassword = Environment.GetEnvironmentVariable("VCAP_PASSWORD");
59+
60+
using (SimpleGet simpleGet = new SimpleGet(vcapUrl, vcapUsername, vcapPassword))
8261
{
83-
Log.Debug("TestConversation.RunTest()", "Failed to get credentials from VCAP_SERVICES file. Please configure credentials to run this test. For more information, see: https://github.com/watson-developer-cloud/unity-sdk/#authentication");
62+
while (!simpleGet.IsComplete)
63+
yield return null;
64+
65+
result = simpleGet.Result;
8466
}
8567

68+
// Add in a parent object because Unity does not like to deserialize root level collection types.
69+
result = Utility.AddTopLevelObjectToJson(result, "VCAP_SERVICES");
70+
71+
// Convert json to fsResult
72+
fsResult r = fsJsonParser.Parse(result, out data);
73+
if (!r.Succeeded)
74+
throw new WatsonException(r.FormattedMessages);
75+
76+
// Convert fsResult to VcapCredentials
77+
object obj = vcapCredentials;
78+
r = _serializer.TryDeserialize(data, obj.GetType(), ref obj);
79+
if (!r.Succeeded)
80+
throw new WatsonException(r.FormattedMessages);
81+
82+
// Set credentials from imported credntials
83+
Credential credential = vcapCredentials.VCAP_SERVICES["conversation"];
84+
_username = credential.Username.ToString();
85+
_password = credential.Password.ToString();
86+
_url = credential.Url.ToString();
87+
_workspaceId = credential.WorkspaceId.ToString();
88+
8689
// Create credential and instantiate service
8790
Credentials credentials = new Credentials(_username, _password, _url);
8891

Scripts/UnitTests/TestDiscovery.cs

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -76,41 +76,43 @@ public override IEnumerator RunTest()
7676
{
7777
LogSystem.InstallDefaultReactors();
7878

79-
try
80-
{
81-
VcapCredentials vcapCredentials = new VcapCredentials();
82-
fsData data = null;
83-
84-
// Get credentials from a credential file defined in environmental variables in the VCAP_SERVICES format.
85-
// See https://console.bluemix.net/docs/services/watson/getting-started-variables.html.
86-
var environmentalVariable = System.Environment.GetEnvironmentVariable("VCAP_SERVICES");
87-
var fileContent = File.ReadAllText(environmentalVariable);
88-
89-
// Add in a parent object because Unity does not like to deserialize root level collection types.
90-
fileContent = Utility.AddTopLevelObjectToJson(fileContent, "VCAP_SERVICES");
91-
92-
// Convert json to fsResult
93-
fsResult r = fsJsonParser.Parse(fileContent, out data);
94-
if (!r.Succeeded)
95-
throw new WatsonException(r.FormattedMessages);
96-
97-
// Convert fsResult to VcapCredentials
98-
object obj = vcapCredentials;
99-
r = _serializer.TryDeserialize(data, obj.GetType(), ref obj);
100-
if (!r.Succeeded)
101-
throw new WatsonException(r.FormattedMessages);
102-
103-
// Set credentials from imported credntials
104-
Credential credential = vcapCredentials.VCAP_SERVICES["discovery"][TestCredentialIndex].Credentials;
105-
_username = credential.Username.ToString();
106-
_password = credential.Password.ToString();
107-
_url = credential.Url.ToString();
108-
}
109-
catch
79+
VcapCredentials vcapCredentials = new VcapCredentials();
80+
fsData data = null;
81+
82+
string result = null;
83+
84+
var vcapUrl = System.Environment.GetEnvironmentVariable("VCAP_URL");
85+
var vcapUsername = System.Environment.GetEnvironmentVariable("VCAP_USERNAME");
86+
var vcapPassword = System.Environment.GetEnvironmentVariable("VCAP_PASSWORD");
87+
88+
using (SimpleGet simpleGet = new SimpleGet(vcapUrl, vcapUsername, vcapPassword))
11089
{
111-
Log.Debug("TestDiscovery.RunTest()", "Failed to get credentials from VCAP_SERVICES file. Please configure credentials to run this test. For more information, see: https://github.com/watson-developer-cloud/unity-sdk/#authentication");
90+
while (!simpleGet.IsComplete)
91+
yield return null;
92+
93+
result = simpleGet.Result;
11294
}
11395

96+
// Add in a parent object because Unity does not like to deserialize root level collection types.
97+
result = Utility.AddTopLevelObjectToJson(result, "VCAP_SERVICES");
98+
99+
// Convert json to fsResult
100+
fsResult r = fsJsonParser.Parse(result, out data);
101+
if (!r.Succeeded)
102+
throw new WatsonException(r.FormattedMessages);
103+
104+
// Convert fsResult to VcapCredentials
105+
object obj = vcapCredentials;
106+
r = _serializer.TryDeserialize(data, obj.GetType(), ref obj);
107+
if (!r.Succeeded)
108+
throw new WatsonException(r.FormattedMessages);
109+
110+
// Set credentials from imported credntials
111+
Credential credential = vcapCredentials.VCAP_SERVICES["discovery"];
112+
_username = credential.Username.ToString();
113+
_password = credential.Password.ToString();
114+
_url = credential.Url.ToString();
115+
114116
// Create credential and instantiate service
115117
Credentials credentials = new Credentials(_username, _password, _url);
116118

@@ -464,7 +466,7 @@ private void OnDeleteCollection(DeleteCollectionResponse resp, Dictionary<string
464466
{
465467
Log.Debug("TestDiscovery.OnDeleteCollection()", "Discovery - Delete collection Response: deleted:{0}", customData["json"].ToString());
466468

467-
_createdCollectionID = default(string);
469+
_createdCollectionID = default(string);
468470
Test(resp != null);
469471

470472
_deleteCollectionTested = true;
@@ -474,9 +476,9 @@ private void OnDeleteConfiguration(DeleteConfigurationResponse resp, Dictionary<
474476
{
475477
Log.Debug("TestDiscovery.OnDeleteConfiguration()", "Discovery - Delete configuration Response: deleted:{0}", customData["json"].ToString());
476478

477-
_createdConfigurationID = default(string);
479+
_createdConfigurationID = default(string);
478480
Test(resp != null);
479-
481+
480482
_deleteConfigurationTested = true;
481483
}
482484

Scripts/UnitTests/TestDocumentConversion.cs

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -44,41 +44,43 @@ public override IEnumerator RunTest()
4444
{
4545
LogSystem.InstallDefaultReactors();
4646

47-
try
48-
{
49-
VcapCredentials vcapCredentials = new VcapCredentials();
50-
fsData data = null;
51-
52-
// Get credentials from a credential file defined in environmental variables in the VCAP_SERVICES format.
53-
// See https://console.bluemix.net/docs/services/watson/getting-started-variables.html.
54-
var environmentalVariable = Environment.GetEnvironmentVariable("VCAP_SERVICES");
55-
var fileContent = File.ReadAllText(environmentalVariable);
56-
57-
// Add in a parent object because Unity does not like to deserialize root level collection types.
58-
fileContent = Utility.AddTopLevelObjectToJson(fileContent, "VCAP_SERVICES");
59-
60-
// Convert json to fsResult
61-
fsResult r = fsJsonParser.Parse(fileContent, out data);
62-
if (!r.Succeeded)
63-
throw new WatsonException(r.FormattedMessages);
64-
65-
// Convert fsResult to VcapCredentials
66-
object obj = vcapCredentials;
67-
r = _serializer.TryDeserialize(data, obj.GetType(), ref obj);
68-
if (!r.Succeeded)
69-
throw new WatsonException(r.FormattedMessages);
70-
71-
// Set credentials from imported credntials
72-
Credential credential = vcapCredentials.VCAP_SERVICES["document_conversion"][TestCredentialIndex].Credentials;
73-
_username = credential.Username.ToString();
74-
_password = credential.Password.ToString();
75-
_url = credential.Url.ToString();
76-
}
77-
catch
47+
VcapCredentials vcapCredentials = new VcapCredentials();
48+
fsData data = null;
49+
50+
string result = null;
51+
52+
var vcapUrl = Environment.GetEnvironmentVariable("VCAP_URL");
53+
var vcapUsername = Environment.GetEnvironmentVariable("VCAP_USERNAME");
54+
var vcapPassword = Environment.GetEnvironmentVariable("VCAP_PASSWORD");
55+
56+
using (SimpleGet simpleGet = new SimpleGet(vcapUrl, vcapUsername, vcapPassword))
7857
{
79-
Log.Debug("TestDocumentConversion.RunTest()", "Failed to get credentials from VCAP_SERVICES file. Please configure credentials to run this test. For more information, see: https://github.com/watson-developer-cloud/unity-sdk/#authentication");
58+
while (!simpleGet.IsComplete)
59+
yield return null;
60+
61+
result = simpleGet.Result;
8062
}
8163

64+
// Add in a parent object because Unity does not like to deserialize root level collection types.
65+
result = Utility.AddTopLevelObjectToJson(result, "VCAP_SERVICES");
66+
67+
// Convert json to fsResult
68+
fsResult r = fsJsonParser.Parse(result, out data);
69+
if (!r.Succeeded)
70+
throw new WatsonException(r.FormattedMessages);
71+
72+
// Convert fsResult to VcapCredentials
73+
object obj = vcapCredentials;
74+
r = _serializer.TryDeserialize(data, obj.GetType(), ref obj);
75+
if (!r.Succeeded)
76+
throw new WatsonException(r.FormattedMessages);
77+
78+
// Set credentials from imported credntials
79+
Credential credential = vcapCredentials.VCAP_SERVICES["document_conversion"];
80+
_username = credential.Username.ToString();
81+
_password = credential.Password.ToString();
82+
_url = credential.Url.ToString();
83+
8284
// Create credential and instantiate service
8385
Credentials credentials = new Credentials(_username, _password, _url);
8486

Scripts/UnitTests/TestLanguageTranslator.cs

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -54,41 +54,43 @@ public override IEnumerator RunTest()
5454
{
5555
LogSystem.InstallDefaultReactors();
5656

57-
try
58-
{
59-
VcapCredentials vcapCredentials = new VcapCredentials();
60-
fsData data = null;
61-
62-
// Get credentials from a credential file defined in environmental variables in the VCAP_SERVICES format.
63-
// See https://console.bluemix.net/docs/services/watson/getting-started-variables.html.
64-
var environmentalVariable = Environment.GetEnvironmentVariable("VCAP_SERVICES");
65-
var fileContent = File.ReadAllText(environmentalVariable);
66-
67-
// Add in a parent object because Unity does not like to deserialize root level collection types.
68-
fileContent = Utility.AddTopLevelObjectToJson(fileContent, "VCAP_SERVICES");
69-
70-
// Convert json to fsResult
71-
fsResult r = fsJsonParser.Parse(fileContent, out data);
72-
if (!r.Succeeded)
73-
throw new WatsonException(r.FormattedMessages);
74-
75-
// Convert fsResult to VcapCredentials
76-
object obj = vcapCredentials;
77-
r = _serializer.TryDeserialize(data, obj.GetType(), ref obj);
78-
if (!r.Succeeded)
79-
throw new WatsonException(r.FormattedMessages);
80-
81-
// Set credentials from imported credntials
82-
Credential credential = vcapCredentials.VCAP_SERVICES["language_translator"][TestCredentialIndex].Credentials;
83-
_username = credential.Username.ToString();
84-
_password = credential.Password.ToString();
85-
_url = credential.Url.ToString();
86-
}
87-
catch
57+
VcapCredentials vcapCredentials = new VcapCredentials();
58+
fsData data = null;
59+
60+
string result = null;
61+
62+
var vcapUrl = Environment.GetEnvironmentVariable("VCAP_URL");
63+
var vcapUsername = Environment.GetEnvironmentVariable("VCAP_USERNAME");
64+
var vcapPassword = Environment.GetEnvironmentVariable("VCAP_PASSWORD");
65+
66+
using (SimpleGet simpleGet = new SimpleGet(vcapUrl, vcapUsername, vcapPassword))
8867
{
89-
Log.Debug("TestLanguageTranslator.RunTest()", "Failed to get credentials from VCAP_SERVICES file. Please configure credentials to run this test. For more information, see: https://github.com/watson-developer-cloud/unity-sdk/#authentication");
68+
while (!simpleGet.IsComplete)
69+
yield return null;
70+
71+
result = simpleGet.Result;
9072
}
9173

74+
// Add in a parent object because Unity does not like to deserialize root level collection types.
75+
result = Utility.AddTopLevelObjectToJson(result, "VCAP_SERVICES");
76+
77+
// Convert json to fsResult
78+
fsResult r = fsJsonParser.Parse(result, out data);
79+
if (!r.Succeeded)
80+
throw new WatsonException(r.FormattedMessages);
81+
82+
// Convert fsResult to VcapCredentials
83+
object obj = vcapCredentials;
84+
r = _serializer.TryDeserialize(data, obj.GetType(), ref obj);
85+
if (!r.Succeeded)
86+
throw new WatsonException(r.FormattedMessages);
87+
88+
// Set credentials from imported credntials
89+
Credential credential = vcapCredentials.VCAP_SERVICES["language_translator"];
90+
_username = credential.Username.ToString();
91+
_password = credential.Password.ToString();
92+
_url = credential.Url.ToString();
93+
9294
// Create credential and instantiate service
9395
Credentials credentials = new Credentials(_username, _password, _url);
9496

0 commit comments

Comments
 (0)