Skip to content

Feature credential service #313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jan 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ README.md.meta
Travis.meta
exclude-filter.txt
exclude-filter.txt.meta
etc.meta
/Travis/UnityTestProject/Assets/StreamingAssets/Config.json
/Travis/UnityTestProject/Assets/StreamingAssets/Config.json.meta
/Travis/UnityTestProject/Assets/StreamingAssets/Config.json.enc.meta
Expand Down
Binary file removed Config.json.enc
Binary file not shown.
2 changes: 2 additions & 0 deletions Scripts/Services/DocumentConversion/v1/DocumentConversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public Credentials Credentials
#region Constructor
public DocumentConversion(Credentials credentials)
{
Log.Warning("DocumentConversion", "The Document Conversion service has been deprecated. Please use the Discovery service.");

if (credentials.HasCredentials() || credentials.HasAuthorizationToken())
{
Credentials = credentials;
Expand Down
2 changes: 2 additions & 0 deletions Scripts/Services/DocumentConversion/v1/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Document Conversion

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.

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.

## Usage
Expand Down
1,559 changes: 780 additions & 779 deletions Scripts/UnitTests/TestAlchemyLanguage.cs

Large diffs are not rendered by default.

69 changes: 36 additions & 33 deletions Scripts/UnitTests/TestConversation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,42 +47,45 @@ public class TestConversation : UnitTest
public override IEnumerator RunTest()
{
LogSystem.InstallDefaultReactors();
try
{
VcapCredentials vcapCredentials = new VcapCredentials();
fsData data = null;

// Get credentials from a credential file defined in environmental variables in the VCAP_SERVICES format.
// See https://console.bluemix.net/docs/services/watson/getting-started-variables.html.
var environmentalVariable = Environment.GetEnvironmentVariable("VCAP_SERVICES");
var fileContent = File.ReadAllText(environmentalVariable);

// Add in a parent object because Unity does not like to deserialize root level collection types.
fileContent = Utility.AddTopLevelObjectToJson(fileContent, "VCAP_SERVICES");

// Convert json to fsResult
fsResult r = fsJsonParser.Parse(fileContent, out data);
if (!r.Succeeded)
throw new WatsonException(r.FormattedMessages);

// Convert fsResult to VcapCredentials
object obj = vcapCredentials;
r = _serializer.TryDeserialize(data, obj.GetType(), ref obj);
if (!r.Succeeded)
throw new WatsonException(r.FormattedMessages);

// Set credentials from imported credntials
Credential credential = vcapCredentials.VCAP_SERVICES["conversation"][TestCredentialIndex].Credentials;
_username = credential.Username.ToString();
_password = credential.Password.ToString();
_url = credential.Url.ToString();
_workspaceId = credential.WorkspaceId.ToString();
}
catch

VcapCredentials vcapCredentials = new VcapCredentials();
fsData data = null;

string result = null;

var vcapUrl = Environment.GetEnvironmentVariable("VCAP_URL");
var vcapUsername = Environment.GetEnvironmentVariable("VCAP_USERNAME");
var vcapPassword = Environment.GetEnvironmentVariable("VCAP_PASSWORD");

using (SimpleGet simpleGet = new SimpleGet(vcapUrl, vcapUsername, vcapPassword))
{
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");
while (!simpleGet.IsComplete)
yield return null;

result = simpleGet.Result;
}

// Add in a parent object because Unity does not like to deserialize root level collection types.
result = Utility.AddTopLevelObjectToJson(result, "VCAP_SERVICES");

// Convert json to fsResult
fsResult r = fsJsonParser.Parse(result, out data);
if (!r.Succeeded)
throw new WatsonException(r.FormattedMessages);

// Convert fsResult to VcapCredentials
object obj = vcapCredentials;
r = _serializer.TryDeserialize(data, obj.GetType(), ref obj);
if (!r.Succeeded)
throw new WatsonException(r.FormattedMessages);

// Set credentials from imported credntials
Credential credential = vcapCredentials.VCAP_SERVICES["conversation"];
_username = credential.Username.ToString();
_password = credential.Password.ToString();
_url = credential.Url.ToString();
_workspaceId = credential.WorkspaceId.ToString();

// Create credential and instantiate service
Credentials credentials = new Credentials(_username, _password, _url);

Expand Down
72 changes: 37 additions & 35 deletions Scripts/UnitTests/TestDiscovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,41 +76,43 @@ public override IEnumerator RunTest()
{
LogSystem.InstallDefaultReactors();

try
{
VcapCredentials vcapCredentials = new VcapCredentials();
fsData data = null;

// Get credentials from a credential file defined in environmental variables in the VCAP_SERVICES format.
// See https://console.bluemix.net/docs/services/watson/getting-started-variables.html.
var environmentalVariable = System.Environment.GetEnvironmentVariable("VCAP_SERVICES");
var fileContent = File.ReadAllText(environmentalVariable);

// Add in a parent object because Unity does not like to deserialize root level collection types.
fileContent = Utility.AddTopLevelObjectToJson(fileContent, "VCAP_SERVICES");

// Convert json to fsResult
fsResult r = fsJsonParser.Parse(fileContent, out data);
if (!r.Succeeded)
throw new WatsonException(r.FormattedMessages);

// Convert fsResult to VcapCredentials
object obj = vcapCredentials;
r = _serializer.TryDeserialize(data, obj.GetType(), ref obj);
if (!r.Succeeded)
throw new WatsonException(r.FormattedMessages);

// Set credentials from imported credntials
Credential credential = vcapCredentials.VCAP_SERVICES["discovery"][TestCredentialIndex].Credentials;
_username = credential.Username.ToString();
_password = credential.Password.ToString();
_url = credential.Url.ToString();
}
catch
VcapCredentials vcapCredentials = new VcapCredentials();
fsData data = null;

string result = null;

var vcapUrl = System.Environment.GetEnvironmentVariable("VCAP_URL");
var vcapUsername = System.Environment.GetEnvironmentVariable("VCAP_USERNAME");
var vcapPassword = System.Environment.GetEnvironmentVariable("VCAP_PASSWORD");

using (SimpleGet simpleGet = new SimpleGet(vcapUrl, vcapUsername, vcapPassword))
{
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");
while (!simpleGet.IsComplete)
yield return null;

result = simpleGet.Result;
}

// Add in a parent object because Unity does not like to deserialize root level collection types.
result = Utility.AddTopLevelObjectToJson(result, "VCAP_SERVICES");

// Convert json to fsResult
fsResult r = fsJsonParser.Parse(result, out data);
if (!r.Succeeded)
throw new WatsonException(r.FormattedMessages);

// Convert fsResult to VcapCredentials
object obj = vcapCredentials;
r = _serializer.TryDeserialize(data, obj.GetType(), ref obj);
if (!r.Succeeded)
throw new WatsonException(r.FormattedMessages);

// Set credentials from imported credntials
Credential credential = vcapCredentials.VCAP_SERVICES["discovery"];
_username = credential.Username.ToString();
_password = credential.Password.ToString();
_url = credential.Url.ToString();

// Create credential and instantiate service
Credentials credentials = new Credentials(_username, _password, _url);

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

_createdCollectionID = default(string);
_createdCollectionID = default(string);
Test(resp != null);

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

_createdConfigurationID = default(string);
_createdConfigurationID = default(string);
Test(resp != null);

_deleteConfigurationTested = true;
}

Expand Down
66 changes: 34 additions & 32 deletions Scripts/UnitTests/TestDocumentConversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,41 +44,43 @@ public override IEnumerator RunTest()
{
LogSystem.InstallDefaultReactors();

try
{
VcapCredentials vcapCredentials = new VcapCredentials();
fsData data = null;

// Get credentials from a credential file defined in environmental variables in the VCAP_SERVICES format.
// See https://console.bluemix.net/docs/services/watson/getting-started-variables.html.
var environmentalVariable = Environment.GetEnvironmentVariable("VCAP_SERVICES");
var fileContent = File.ReadAllText(environmentalVariable);

// Add in a parent object because Unity does not like to deserialize root level collection types.
fileContent = Utility.AddTopLevelObjectToJson(fileContent, "VCAP_SERVICES");

// Convert json to fsResult
fsResult r = fsJsonParser.Parse(fileContent, out data);
if (!r.Succeeded)
throw new WatsonException(r.FormattedMessages);

// Convert fsResult to VcapCredentials
object obj = vcapCredentials;
r = _serializer.TryDeserialize(data, obj.GetType(), ref obj);
if (!r.Succeeded)
throw new WatsonException(r.FormattedMessages);

// Set credentials from imported credntials
Credential credential = vcapCredentials.VCAP_SERVICES["document_conversion"][TestCredentialIndex].Credentials;
_username = credential.Username.ToString();
_password = credential.Password.ToString();
_url = credential.Url.ToString();
}
catch
VcapCredentials vcapCredentials = new VcapCredentials();
fsData data = null;

string result = null;

var vcapUrl = Environment.GetEnvironmentVariable("VCAP_URL");
var vcapUsername = Environment.GetEnvironmentVariable("VCAP_USERNAME");
var vcapPassword = Environment.GetEnvironmentVariable("VCAP_PASSWORD");

using (SimpleGet simpleGet = new SimpleGet(vcapUrl, vcapUsername, vcapPassword))
{
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");
while (!simpleGet.IsComplete)
yield return null;

result = simpleGet.Result;
}

// Add in a parent object because Unity does not like to deserialize root level collection types.
result = Utility.AddTopLevelObjectToJson(result, "VCAP_SERVICES");

// Convert json to fsResult
fsResult r = fsJsonParser.Parse(result, out data);
if (!r.Succeeded)
throw new WatsonException(r.FormattedMessages);

// Convert fsResult to VcapCredentials
object obj = vcapCredentials;
r = _serializer.TryDeserialize(data, obj.GetType(), ref obj);
if (!r.Succeeded)
throw new WatsonException(r.FormattedMessages);

// Set credentials from imported credntials
Credential credential = vcapCredentials.VCAP_SERVICES["document_conversion"];
_username = credential.Username.ToString();
_password = credential.Password.ToString();
_url = credential.Url.ToString();

// Create credential and instantiate service
Credentials credentials = new Credentials(_username, _password, _url);

Expand Down
66 changes: 34 additions & 32 deletions Scripts/UnitTests/TestLanguageTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,41 +54,43 @@ public override IEnumerator RunTest()
{
LogSystem.InstallDefaultReactors();

try
{
VcapCredentials vcapCredentials = new VcapCredentials();
fsData data = null;

// Get credentials from a credential file defined in environmental variables in the VCAP_SERVICES format.
// See https://console.bluemix.net/docs/services/watson/getting-started-variables.html.
var environmentalVariable = Environment.GetEnvironmentVariable("VCAP_SERVICES");
var fileContent = File.ReadAllText(environmentalVariable);

// Add in a parent object because Unity does not like to deserialize root level collection types.
fileContent = Utility.AddTopLevelObjectToJson(fileContent, "VCAP_SERVICES");

// Convert json to fsResult
fsResult r = fsJsonParser.Parse(fileContent, out data);
if (!r.Succeeded)
throw new WatsonException(r.FormattedMessages);

// Convert fsResult to VcapCredentials
object obj = vcapCredentials;
r = _serializer.TryDeserialize(data, obj.GetType(), ref obj);
if (!r.Succeeded)
throw new WatsonException(r.FormattedMessages);

// Set credentials from imported credntials
Credential credential = vcapCredentials.VCAP_SERVICES["language_translator"][TestCredentialIndex].Credentials;
_username = credential.Username.ToString();
_password = credential.Password.ToString();
_url = credential.Url.ToString();
}
catch
VcapCredentials vcapCredentials = new VcapCredentials();
fsData data = null;

string result = null;

var vcapUrl = Environment.GetEnvironmentVariable("VCAP_URL");
var vcapUsername = Environment.GetEnvironmentVariable("VCAP_USERNAME");
var vcapPassword = Environment.GetEnvironmentVariable("VCAP_PASSWORD");

using (SimpleGet simpleGet = new SimpleGet(vcapUrl, vcapUsername, vcapPassword))
{
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");
while (!simpleGet.IsComplete)
yield return null;

result = simpleGet.Result;
}

// Add in a parent object because Unity does not like to deserialize root level collection types.
result = Utility.AddTopLevelObjectToJson(result, "VCAP_SERVICES");

// Convert json to fsResult
fsResult r = fsJsonParser.Parse(result, out data);
if (!r.Succeeded)
throw new WatsonException(r.FormattedMessages);

// Convert fsResult to VcapCredentials
object obj = vcapCredentials;
r = _serializer.TryDeserialize(data, obj.GetType(), ref obj);
if (!r.Succeeded)
throw new WatsonException(r.FormattedMessages);

// Set credentials from imported credntials
Credential credential = vcapCredentials.VCAP_SERVICES["language_translator"];
_username = credential.Username.ToString();
_password = credential.Password.ToString();
_url = credential.Url.ToString();

// Create credential and instantiate service
Credentials credentials = new Credentials(_username, _password, _url);

Expand Down
Loading