diff --git a/.github/workflows/upm-subtree-split.yml b/.github/workflows/upm-subtree-split.yml index 2b485bb..a75ddc7 100644 --- a/.github/workflows/upm-subtree-split.yml +++ b/.github/workflows/upm-subtree-split.yml @@ -8,7 +8,7 @@ jobs: upm-subtree-split: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: upm subtree split diff --git a/BlockadeLabs/Packages/com.rest.blockadelabs/Documentation~/README.md b/BlockadeLabs/Packages/com.rest.blockadelabs/Documentation~/README.md index d2e4b1b..d777aaa 100644 --- a/BlockadeLabs/Packages/com.rest.blockadelabs/Documentation~/README.md +++ b/BlockadeLabs/Packages/com.rest.blockadelabs/Documentation~/README.md @@ -42,16 +42,16 @@ The recommended installation method is though the unity package manager and [Ope ### Table of Contents -- [Authentication](#authentication) -- [Editor Dashboard](#editor-dashboard) :new: - - [Skybox Dashboard](#skybox-dashboard) :new: - - [History Dashboard](#history-dashboard) :new: +- [Authentication](#authentication) :construction: +- [Editor Dashboard](#editor-dashboard) + - [Skybox Dashboard](#skybox-dashboard) + - [History Dashboard](#history-dashboard) - [Skyboxes](#skyboxes) - [Get Skybox Styles](#get-skybox-styles) - - [Get Skybox Export Options](#get-skybox-export-options) :new: + - [Get Skybox Export Options](#get-skybox-export-options) - [Generate Skybox](#generate-skybox) - [Get Skybox by Id](#get-skybox) - - [Request Skybox Export](#request-skybox-export) :new: + - [Request Skybox Export](#request-skybox-export) - [Delete Skybox by Id](#delete-skybox) - [Get Skybox History](#get-skybox-history) - [Cancel Skybox Generation](#cancel-skybox-generation) @@ -61,8 +61,10 @@ The recommended installation method is though the unity package manager and [Ope There are 4 ways to provide your API keys, in order of precedence: -1. [Pass keys directly with constructor](#pass-keys-directly-with-constructor) -2. [Unity Scriptable Object](#unity-scriptable-object) +:warning: We recommended using the environment variables to load the API key instead of having it hard coded in your source. It is not recommended use this method in production, but only for accepting user credentials, local testing and quick start scenarios. + +1. [Pass keys directly with constructor](#pass-keys-directly-with-constructor) :warning: +2. [Unity Scriptable Object](#unity-scriptable-object) :warning: 3. [Load key from configuration file](#load-key-from-configuration-file) 4. [Use System Environment Variables](#use-system-environment-variables) @@ -103,7 +105,7 @@ To create a configuration file, create a new text file named `.blockadelabs` and You can also load the file directly with known path by calling a static method in Authentication: ```csharp -var api = new BlockadeLabsClient(BlockadeLabsAuthentication.Default.LoadFromDirectory("your/path/to/.blockadelabs"));; +var api = new BlockadeLabsClient(new BlockadeLabsAuthentication().LoadFromDirectory("your/path/to/.blockadelabs"));; ``` #### Use System Environment Variables @@ -113,7 +115,7 @@ Use your system's environment variables specify an api key to use. - Use `BLOCKADE_LABS_API_KEY` for your api key. ```csharp -var api = new BlockadeLabsClient(BlockadeLabsAuthentication.Default.LoadFromEnvironment()); +var api = new BlockadeLabsClient(new BlockadeLabsAuthentication().LoadFromEnvironment()); ``` ### Editor Dashboard diff --git a/BlockadeLabs/Packages/com.rest.blockadelabs/Runtime/BlockadeLabsAuthentication.cs b/BlockadeLabs/Packages/com.rest.blockadelabs/Runtime/BlockadeLabsAuthentication.cs index db1aaa8..c613797 100644 --- a/BlockadeLabs/Packages/com.rest.blockadelabs/Runtime/BlockadeLabsAuthentication.cs +++ b/BlockadeLabs/Packages/com.rest.blockadelabs/Runtime/BlockadeLabsAuthentication.cs @@ -8,7 +8,7 @@ namespace BlockadeLabs { - public sealed class BlockadeLabsAuthentication : AbstractAuthentication + public sealed class BlockadeLabsAuthentication : AbstractAuthentication { internal const string CONFIG_FILE = ".blockadelabs"; private const string BLOCKADE_LABS_API_KEY = nameof(BLOCKADE_LABS_API_KEY); @@ -16,33 +16,35 @@ public sealed class BlockadeLabsAuthentication : AbstractAuthentication new BlockadeLabsAuthentication(apiKey); /// - /// Instantiates a new Authentication object that will load the default config. + /// Instantiates an empty Authentication object. /// - public BlockadeLabsAuthentication() - { - if (cachedDefault != null) - { - return; - } - - cachedDefault = (LoadFromAsset() ?? - LoadFromDirectory()) ?? - LoadFromDirectory(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)) ?? - LoadFromEnvironment(); - Info = cachedDefault?.Info; - } + public BlockadeLabsAuthentication() { } /// /// Instantiates a new Authentication object with the given , which may be . /// /// The API key, required to access the API endpoint. - public BlockadeLabsAuthentication(string apiKey) => Info = new BlockadeLabsAuthInfo(apiKey); + public BlockadeLabsAuthentication(string apiKey) + { + Info = new BlockadeLabsAuthInfo(apiKey); + cachedDefault = this; + } /// /// Instantiates a new Authentication object with the given , which may be . /// /// - public BlockadeLabsAuthentication(BlockadeLabsAuthInfo authInfo) => Info = authInfo; + public BlockadeLabsAuthentication(BlockadeLabsAuthInfo authInfo) + { + Info = authInfo; + cachedDefault = this; + } + + /// + /// Instantiates a new Authentication object with the given . + /// + /// . + public BlockadeLabsAuthentication(BlockadeLabsConfiguration configuration) : this(configuration.ApiKey) { } /// public override BlockadeLabsAuthInfo Info { get; } @@ -56,20 +58,20 @@ public BlockadeLabsAuthentication() /// public static BlockadeLabsAuthentication Default { - get => cachedDefault ??= new BlockadeLabsAuthentication(); - internal set => cachedDefault = value; + get => cachedDefault ??= new BlockadeLabsAuthentication().LoadDefault(); + set => cachedDefault = value; } - /// - public override BlockadeLabsAuthentication LoadFromAsset() - => Resources.LoadAll(string.Empty) - .Where(asset => asset != null) - .Where(asset => asset is BlockadeLabsConfiguration config && - !string.IsNullOrWhiteSpace(config.ApiKey)) - .Select(asset => asset is BlockadeLabsConfiguration config - ? new BlockadeLabsAuthentication(config.ApiKey) - : null) - .FirstOrDefault(); + public override BlockadeLabsAuthentication LoadFromAsset(BlockadeLabsConfiguration configuration = null) + { + if (configuration == null) + { + Debug.LogWarning($"This can be speed this up by passing a {nameof(BlockadeLabsConfiguration)} to the {nameof(BlockadeLabsAuthentication)}.ctr"); + configuration = Resources.LoadAll(string.Empty).FirstOrDefault(o => o != null); + } + + return configuration != null ? new BlockadeLabsAuthentication(configuration) : null; + } /// public override BlockadeLabsAuthentication LoadFromEnvironment() @@ -87,6 +89,11 @@ public override BlockadeLabsAuthentication LoadFromDirectory(string directory = directory = Environment.CurrentDirectory; } + if (string.IsNullOrWhiteSpace(filename)) + { + filename = CONFIG_FILE; + } + BlockadeLabsAuthInfo tempAuthInfo = null; var currentDirectory = new DirectoryInfo(directory); @@ -119,12 +126,11 @@ public override BlockadeLabsAuthentication LoadFromDirectory(string directory = var part = parts[i]; var nextPart = parts[i + 1]; - switch (part) + apiKey = part switch { - case BLOCKADE_LABS_API_KEY: - apiKey = nextPart.Trim(); - break; - } + BLOCKADE_LABS_API_KEY => nextPart.Trim(), + _ => apiKey + }; } } @@ -141,13 +147,7 @@ public override BlockadeLabsAuthentication LoadFromDirectory(string directory = } } - if (tempAuthInfo == null || - string.IsNullOrEmpty(tempAuthInfo.ApiKey)) - { - return null; - } - - return new BlockadeLabsAuthentication(tempAuthInfo); + return string.IsNullOrEmpty(tempAuthInfo?.ApiKey) ? null : new BlockadeLabsAuthentication(tempAuthInfo); } } } diff --git a/BlockadeLabs/Packages/com.rest.blockadelabs/Runtime/BlockadeLabsClient.cs b/BlockadeLabs/Packages/com.rest.blockadelabs/Runtime/BlockadeLabsClient.cs index 2d9c9ec..9d9a0c3 100644 --- a/BlockadeLabs/Packages/com.rest.blockadelabs/Runtime/BlockadeLabsClient.cs +++ b/BlockadeLabs/Packages/com.rest.blockadelabs/Runtime/BlockadeLabsClient.cs @@ -10,6 +10,14 @@ namespace BlockadeLabs { public sealed class BlockadeLabsClient : BaseClient { + /// + /// Creates a new client for the BlockadeLabs API, handling auth and allowing for access to various API endpoints. + /// + /// The API authentication information to use for API calls, + /// or to attempt to use the , + /// potentially loading from environment vars or from a config file. + /// Optional, for specifying a proxy domain. + /// Raised when authentication details are missing or invalid. public BlockadeLabsClient(BlockadeLabsAuthentication authentication = null, BlockadeLabsSettings settings = null) : base(authentication ?? BlockadeLabsAuthentication.Default, settings ?? BlockadeLabsSettings.Default) { @@ -18,6 +26,11 @@ public BlockadeLabsClient(BlockadeLabsAuthentication authentication = null, Bloc protected override void ValidateAuthentication() { + if (Authentication?.Info == null) + { + throw new InvalidCredentialException($"Invalid {nameof(BlockadeLabsAuthentication)}"); + } + if (!HasValidAuthentication) { throw new AuthenticationException("You must provide API authentication. Please refer to https://github.com/RageAgainstThePixel/com.rest.blockadelabs#authentication for details."); diff --git a/BlockadeLabs/Packages/com.rest.blockadelabs/Runtime/BlockadeLabsSettings.cs b/BlockadeLabs/Packages/com.rest.blockadelabs/Runtime/BlockadeLabsSettings.cs index c37df37..d861f24 100644 --- a/BlockadeLabs/Packages/com.rest.blockadelabs/Runtime/BlockadeLabsSettings.cs +++ b/BlockadeLabs/Packages/com.rest.blockadelabs/Runtime/BlockadeLabsSettings.cs @@ -8,36 +8,61 @@ namespace BlockadeLabs { public sealed class BlockadeLabsSettings : ISettings { + /// + /// Creates a new instance of with default . + /// public BlockadeLabsSettings() { - if (cachedDefault != null) { return; } - - var config = Resources.LoadAll(string.Empty) - .FirstOrDefault(asset => asset != null); + Info = new BlockadeLabsSettingsInfo(); + cachedDefault = this; + } - if (config != null) + /// + /// Creates a new instance of with provided . + /// + /// . + public BlockadeLabsSettings(BlockadeLabsConfiguration configuration) + { + if (configuration == null) { - Info = new BlockadeLabsSettingsInfo(config.ProxyDomain); - Default = new BlockadeLabsSettings(Info); + Debug.LogWarning($"This can be speed up by directly passing a {nameof(BlockadeLabsConfiguration)} to the {nameof(BlockadeLabsSettings)}.ctr"); + configuration = Resources.LoadAll(string.Empty).FirstOrDefault(asset => asset != null); } - else + + if (configuration == null) { - Info = new BlockadeLabsSettingsInfo(); - Default = new BlockadeLabsSettings(Info); + throw new MissingReferenceException($"Failed to find a valid {nameof(BlockadeLabsConfiguration)}!"); } + + Info = new BlockadeLabsSettingsInfo(configuration.ProxyDomain); + cachedDefault = this; } + /// + /// Creates a new instance of with the provided . + /// + /// . public BlockadeLabsSettings(BlockadeLabsSettingsInfo settingsInfo) - => Info = settingsInfo; + { + Info = settingsInfo; + cachedDefault = this; + } + /// + /// Creates a new instance of . + /// + /// Base api domain. public BlockadeLabsSettings(string domain) - => Info = new BlockadeLabsSettingsInfo(domain); + { + Info = new BlockadeLabsSettingsInfo(domain); + cachedDefault = this; + } private static BlockadeLabsSettings cachedDefault; public static BlockadeLabsSettings Default { - get => cachedDefault ??= new BlockadeLabsSettings(); + get => cachedDefault ??= new BlockadeLabsSettings(configuration: null); internal set => cachedDefault = value; } diff --git a/BlockadeLabs/Packages/com.rest.blockadelabs/Tests/AbstractTestFixture.cs b/BlockadeLabs/Packages/com.rest.blockadelabs/Tests/AbstractTestFixture.cs new file mode 100644 index 0000000..6fdaaf2 --- /dev/null +++ b/BlockadeLabs/Packages/com.rest.blockadelabs/Tests/AbstractTestFixture.cs @@ -0,0 +1,17 @@ +// Licensed under the MIT License. See LICENSE in the project root for license information. + +namespace BlockadeLabs.Tests +{ + internal abstract class AbstractTestFixture + { + protected readonly BlockadeLabsClient BlockadeLabsClient; + + protected AbstractTestFixture() + { + var auth = new BlockadeLabsAuthentication().LoadDefaultsReversed(); + var settings = new BlockadeLabsSettings(); + BlockadeLabsClient = new BlockadeLabsClient(auth, settings); + //BlockadeLabsClient.EnableDebug = true; + } + } +} diff --git a/BlockadeLabs/Packages/com.rest.blockadelabs/Tests/AbstractTestFixture.cs.meta b/BlockadeLabs/Packages/com.rest.blockadelabs/Tests/AbstractTestFixture.cs.meta new file mode 100644 index 0000000..f18a7b2 --- /dev/null +++ b/BlockadeLabs/Packages/com.rest.blockadelabs/Tests/AbstractTestFixture.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d80bda258fbc8934289bf0e8c1a1653b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/BlockadeLabs/Packages/com.rest.blockadelabs/Tests/TestFixture_00_Authentication.cs b/BlockadeLabs/Packages/com.rest.blockadelabs/Tests/TestFixture_00_Authentication.cs index 7d9e650..1501ba1 100644 --- a/BlockadeLabs/Packages/com.rest.blockadelabs/Tests/TestFixture_00_Authentication.cs +++ b/BlockadeLabs/Packages/com.rest.blockadelabs/Tests/TestFixture_00_Authentication.cs @@ -22,7 +22,7 @@ public void Setup() [Test] public void Test_01_GetAuthFromEnv() { - var auth = BlockadeLabsAuthentication.Default.LoadFromEnvironment(); + var auth = new BlockadeLabsAuthentication().LoadFromEnvironment(); Assert.IsNotNull(auth); Assert.IsNotNull(auth.Info.ApiKey); Assert.IsNotEmpty(auth.Info.ApiKey); @@ -31,7 +31,7 @@ public void Test_01_GetAuthFromEnv() [Test] public void Test_02_GetAuthFromFile() { - var auth = BlockadeLabsAuthentication.Default.LoadFromPath(Path.GetFullPath(BlockadeLabsAuthentication.CONFIG_FILE)); + var auth = new BlockadeLabsAuthentication().LoadFromPath(Path.GetFullPath(BlockadeLabsAuthentication.CONFIG_FILE)); Assert.IsNotNull(auth); Assert.IsNotNull(auth.Info.ApiKey); Assert.AreEqual("key-test12", auth.Info.ApiKey); @@ -40,7 +40,7 @@ public void Test_02_GetAuthFromFile() [Test] public void Test_03_GetAuthFromNonExistentFile() { - var auth = BlockadeLabsAuthentication.Default.LoadFromDirectory(filename: "bad.config"); + var auth = new BlockadeLabsAuthentication().LoadFromDirectory(filename: "bad.config"); Assert.IsNull(auth); } @@ -63,13 +63,14 @@ public void Test_04_GetAuthFromConfiguration() cleanup = true; } - var config = AssetDatabase.LoadAssetAtPath(configPath); - var auth = BlockadeLabsAuthentication.Default.LoadFromAsset(); + var configuration = AssetDatabase.LoadAssetAtPath(configPath); + Assert.IsNotNull(configuration); + var auth = new BlockadeLabsAuthentication().LoadFromAsset(configuration); Assert.IsNotNull(auth); Assert.IsNotNull(auth.Info.ApiKey); Assert.IsNotEmpty(auth.Info.ApiKey); - Assert.AreEqual(auth.Info.ApiKey, config.ApiKey); + Assert.AreEqual(auth.Info.ApiKey, configuration.ApiKey); if (cleanup) { @@ -82,13 +83,12 @@ public void Test_04_GetAuthFromConfiguration() public void Test_05_Authentication() { var defaultAuth = BlockadeLabsAuthentication.Default; - var manualAuth = new BlockadeLabsAuthentication("key-testAA"); Assert.IsNotNull(defaultAuth); Assert.IsNotNull(defaultAuth.Info.ApiKey); Assert.AreEqual(defaultAuth.Info.ApiKey, BlockadeLabsAuthentication.Default.Info.ApiKey); - BlockadeLabsAuthentication.Default = new BlockadeLabsAuthentication("key-testAA"); + var manualAuth = new BlockadeLabsAuthentication("key-testAA"); Assert.IsNotNull(manualAuth); Assert.IsNotNull(manualAuth.Info.ApiKey); Assert.AreEqual(manualAuth.Info.ApiKey, BlockadeLabsAuthentication.Default.Info.ApiKey); @@ -154,6 +154,10 @@ public void TearDown() { File.Delete(BlockadeLabsAuthentication.CONFIG_FILE); } + + + BlockadeLabsSettings.Default = null; + BlockadeLabsAuthentication.Default = null; } } } diff --git a/BlockadeLabs/Packages/com.rest.blockadelabs/Tests/TestFixture_00_Skyboxes.cs b/BlockadeLabs/Packages/com.rest.blockadelabs/Tests/TestFixture_00_Skyboxes.cs index ac65250..08c0a82 100644 --- a/BlockadeLabs/Packages/com.rest.blockadelabs/Tests/TestFixture_00_Skyboxes.cs +++ b/BlockadeLabs/Packages/com.rest.blockadelabs/Tests/TestFixture_00_Skyboxes.cs @@ -9,16 +9,15 @@ namespace BlockadeLabs.Tests { - public class TestFixture_01_Skyboxes + internal class TestFixture_01_Skyboxes : AbstractTestFixture { - private static SkyboxInfo testSkyboxInfo; + private SkyboxInfo testSkyboxInfo; [Test] public async Task Test_01_GetSkyboxStyles() { - var api = new BlockadeLabsClient(BlockadeLabsAuthentication.Default.LoadFromEnvironment()); - Assert.IsNotNull(api.SkyboxEndpoint); - var skyboxStyles = await api.SkyboxEndpoint.GetSkyboxStylesAsync(); + Assert.IsNotNull(BlockadeLabsClient.SkyboxEndpoint); + var skyboxStyles = await BlockadeLabsClient.SkyboxEndpoint.GetSkyboxStylesAsync(); Assert.IsNotNull(skyboxStyles); foreach (var skyboxStyle in skyboxStyles) @@ -30,11 +29,9 @@ public async Task Test_01_GetSkyboxStyles() [Test] public async Task Test_02_GenerateSkybox() { - var api = new BlockadeLabsClient(BlockadeLabsAuthentication.Default.LoadFromEnvironment()); - Assert.IsNotNull(api.SkyboxEndpoint); - + Assert.IsNotNull(BlockadeLabsClient.SkyboxEndpoint); var request = new SkyboxRequest("mars", enhancePrompt: true); - var skyboxInfo = await api.SkyboxEndpoint.GenerateSkyboxAsync(request); + var skyboxInfo = await BlockadeLabsClient.SkyboxEndpoint.GenerateSkyboxAsync(request); Assert.IsNotNull(skyboxInfo); Debug.Log($"Successfully created skybox: {skyboxInfo.Id}"); @@ -59,10 +56,10 @@ public async Task Test_02_GenerateSkybox() [Test] public async Task Test_03_GetSkyboxInfo() { - var api = new BlockadeLabsClient(BlockadeLabsAuthentication.Default.LoadFromEnvironment()); - Assert.IsNotNull(api.SkyboxEndpoint); + Assert.IsNotNull(BlockadeLabsClient.SkyboxEndpoint); + Assert.IsNotNull(testSkyboxInfo); var skyboxId = testSkyboxInfo.Id; - var skyboxInfo = await api.SkyboxEndpoint.GetSkyboxInfoAsync(skyboxId); + var skyboxInfo = await BlockadeLabsClient.SkyboxEndpoint.GetSkyboxInfoAsync(skyboxId); Assert.IsNotNull(skyboxInfo); await skyboxInfo.LoadAssetsAsync(); Assert.IsNotEmpty(skyboxInfo.Exports); @@ -83,9 +80,8 @@ public async Task Test_03_GetSkyboxInfo() [Test] public async Task Test_04_GetHistory() { - var api = new BlockadeLabsClient(BlockadeLabsAuthentication.Default.LoadFromEnvironment()); - Assert.IsNotNull(api.SkyboxEndpoint); - var history = await api.SkyboxEndpoint.GetSkyboxHistoryAsync(); + Assert.IsNotNull(BlockadeLabsClient.SkyboxEndpoint); + var history = await BlockadeLabsClient.SkyboxEndpoint.GetSkyboxHistoryAsync(); Assert.IsNotNull(history); Assert.IsNotEmpty(history.Skyboxes); Debug.Log($"Found {history.TotalCount} skyboxes"); @@ -99,14 +95,13 @@ public async Task Test_04_GetHistory() [Test] public async Task Test_05_CancelPendingGeneration() { - var api = new BlockadeLabsClient(BlockadeLabsAuthentication.Default.LoadFromEnvironment()); - Assert.IsNotNull(api.SkyboxEndpoint); + Assert.IsNotNull(BlockadeLabsClient.SkyboxEndpoint); var request = new SkyboxRequest("mars", enhancePrompt: true); var cts = new CancellationTokenSource(TimeSpan.FromSeconds(1.5)); try { - await api.SkyboxEndpoint.GenerateSkyboxAsync(request, pollingInterval: 1, cancellationToken: cts.Token); + await BlockadeLabsClient.SkyboxEndpoint.GenerateSkyboxAsync(request, pollingInterval: 1, cancellationToken: cts.Token); } catch (OperationCanceledException) { @@ -121,24 +116,22 @@ public async Task Test_05_CancelPendingGeneration() [Test] public async Task Test_06_CancelAllPendingGenerations() { - var api = new BlockadeLabsClient(BlockadeLabsAuthentication.Default.LoadFromEnvironment()); - Assert.IsNotNull(api.SkyboxEndpoint); - var result = await api.SkyboxEndpoint.CancelAllPendingSkyboxGenerationsAsync(); + Assert.IsNotNull(BlockadeLabsClient.SkyboxEndpoint); + var result = await BlockadeLabsClient.SkyboxEndpoint.CancelAllPendingSkyboxGenerationsAsync(); Debug.Log(result ? "All pending generations successfully cancelled" : "No pending generations"); } [Test] public async Task Test_07_DeleteSkybox() { - var api = new BlockadeLabsClient(BlockadeLabsAuthentication.Default.LoadFromEnvironment()); - Assert.IsNotNull(api.SkyboxEndpoint); - var history = await api.SkyboxEndpoint.GetSkyboxHistoryAsync(new SkyboxHistoryParameters { StatusFilter = Status.Abort }); + Assert.IsNotNull(BlockadeLabsClient.SkyboxEndpoint); + var history = await BlockadeLabsClient.SkyboxEndpoint.GetSkyboxHistoryAsync(new SkyboxHistoryParameters { StatusFilter = Status.Abort }); Assert.IsNotNull(history); foreach (var skybox in history.Skyboxes) { Debug.Log($"Deleting {skybox.Id} {skybox.Title}"); - var result = await api.SkyboxEndpoint.DeleteSkyboxAsync(skybox); + var result = await BlockadeLabsClient.SkyboxEndpoint.DeleteSkyboxAsync(skybox); Assert.IsTrue(result); } } @@ -146,9 +139,8 @@ public async Task Test_07_DeleteSkybox() [Test] public async Task Test_08_GetSkyboxExportOptions() { - var api = new BlockadeLabsClient(BlockadeLabsAuthentication.Default.LoadFromEnvironment()); - Assert.IsNotNull(api.SkyboxEndpoint); - var exportOptions = await api.SkyboxEndpoint.GetAllSkyboxExportOptionsAsync(); + Assert.IsNotNull(BlockadeLabsClient.SkyboxEndpoint); + var exportOptions = await BlockadeLabsClient.SkyboxEndpoint.GetAllSkyboxExportOptionsAsync(); Assert.IsNotNull(exportOptions); Assert.IsNotEmpty(exportOptions); @@ -161,12 +153,12 @@ public async Task Test_08_GetSkyboxExportOptions() [Test] public async Task Test_09_ExportSkybox_All_Options() { - var api = new BlockadeLabsClient(BlockadeLabsAuthentication.Default.LoadFromEnvironment()); - Assert.IsNotNull(api.SkyboxEndpoint); + Assert.IsNotNull(BlockadeLabsClient.SkyboxEndpoint); + Assert.IsNotNull(testSkyboxInfo); var skyboxId = testSkyboxInfo.Id; - var skyboxInfo = await api.SkyboxEndpoint.GetSkyboxInfoAsync(skyboxId); + var skyboxInfo = await BlockadeLabsClient.SkyboxEndpoint.GetSkyboxInfoAsync(skyboxId); Assert.IsNotNull(skyboxInfo); - var exportOptions = await api.SkyboxEndpoint.GetAllSkyboxExportOptionsAsync(); + var exportOptions = await BlockadeLabsClient.SkyboxEndpoint.GetAllSkyboxExportOptionsAsync(); Assert.IsNotNull(exportOptions); Assert.IsNotEmpty(exportOptions); @@ -174,7 +166,7 @@ public async Task Test_09_ExportSkybox_All_Options() { Debug.Log(exportOption.Key); Assert.IsNotNull(exportOption); - skyboxInfo = await api.SkyboxEndpoint.ExportSkyboxAsync(skyboxInfo, exportOption); + skyboxInfo = await BlockadeLabsClient.SkyboxEndpoint.ExportSkyboxAsync(skyboxInfo, exportOption); Assert.IsNotNull(skyboxInfo); Assert.IsTrue(skyboxInfo.Exports.ContainsKey(exportOption.Key)); skyboxInfo.Exports.TryGetValue(exportOption.Key, out var exportUrl); diff --git a/BlockadeLabs/Packages/com.rest.blockadelabs/package.json b/BlockadeLabs/Packages/com.rest.blockadelabs/package.json index 7acb084..f09801e 100644 --- a/BlockadeLabs/Packages/com.rest.blockadelabs/package.json +++ b/BlockadeLabs/Packages/com.rest.blockadelabs/package.json @@ -3,7 +3,7 @@ "displayName": "BlockadeLabs", "description": "A Non-Official Blockade Labs Rest Client for Unity (UPM)", "keywords": [], - "version": "1.1.0", + "version": "1.2.0", "unity": "2021.3", "documentationUrl": "https://github.com/RageAgainstThePixel/com.rest.blockadelabs#documentation", "changelogUrl": "https://github.com/RageAgainstThePixel/com.rest.blockadelabs/releases", @@ -17,7 +17,7 @@ "url": "https://github.com/StephenHodgson" }, "dependencies": { - "com.utilities.rest": "2.2.5", + "com.utilities.rest": "2.3.1", "com.unity.modules.video": "1.0.0", "com.unity.sharp-zip-lib": "1.3.4-preview" }, diff --git a/BlockadeLabs/Packages/manifest.json b/BlockadeLabs/Packages/manifest.json index ffed069..5271e56 100644 --- a/BlockadeLabs/Packages/manifest.json +++ b/BlockadeLabs/Packages/manifest.json @@ -4,7 +4,7 @@ "com.unity.ide.visualstudio": "2.0.22", "com.unity.test-framework": "1.1.33", "com.unity.textmeshpro": "3.0.6", - "com.utilities.buildpipeline": "1.1.8" + "com.utilities.buildpipeline": "1.1.9" }, "scopedRegistries": [ { diff --git a/BlockadeLabs/ProjectSettings/ProjectVersion.txt b/BlockadeLabs/ProjectSettings/ProjectVersion.txt index e4eac15..da67189 100644 --- a/BlockadeLabs/ProjectSettings/ProjectVersion.txt +++ b/BlockadeLabs/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 2022.3.12f1 -m_EditorVersionWithRevision: 2022.3.12f1 (4fe6e059c7ef) +m_EditorVersion: 2022.3.14f1 +m_EditorVersionWithRevision: 2022.3.14f1 (eff2de9070d8) diff --git a/README.md b/README.md index ba72c71..57a5827 100644 --- a/README.md +++ b/README.md @@ -42,16 +42,16 @@ The recommended installation method is though the unity package manager and [Ope ### Table of Contents -- [Authentication](#authentication) -- [Editor Dashboard](#editor-dashboard) :new: - - [Skybox Dashboard](#skybox-dashboard) :new: - - [History Dashboard](#history-dashboard) :new: +- [Authentication](#authentication) :construction: +- [Editor Dashboard](#editor-dashboard) + - [Skybox Dashboard](#skybox-dashboard) + - [History Dashboard](#history-dashboard) - [Skyboxes](#skyboxes) - [Get Skybox Styles](#get-skybox-styles) - - [Get Skybox Export Options](#get-skybox-export-options) :new: + - [Get Skybox Export Options](#get-skybox-export-options) - [Generate Skybox](#generate-skybox) - [Get Skybox by Id](#get-skybox) - - [Request Skybox Export](#request-skybox-export) :new: + - [Request Skybox Export](#request-skybox-export) - [Delete Skybox by Id](#delete-skybox) - [Get Skybox History](#get-skybox-history) - [Cancel Skybox Generation](#cancel-skybox-generation) @@ -61,8 +61,10 @@ The recommended installation method is though the unity package manager and [Ope There are 4 ways to provide your API keys, in order of precedence: -1. [Pass keys directly with constructor](#pass-keys-directly-with-constructor) -2. [Unity Scriptable Object](#unity-scriptable-object) +:warning: We recommended using the environment variables to load the API key instead of having it hard coded in your source. It is not recommended use this method in production, but only for accepting user credentials, local testing and quick start scenarios. + +1. [Pass keys directly with constructor](#pass-keys-directly-with-constructor) :warning: +2. [Unity Scriptable Object](#unity-scriptable-object) :warning: 3. [Load key from configuration file](#load-key-from-configuration-file) 4. [Use System Environment Variables](#use-system-environment-variables) @@ -103,7 +105,7 @@ To create a configuration file, create a new text file named `.blockadelabs` and You can also load the file directly with known path by calling a static method in Authentication: ```csharp -var api = new BlockadeLabsClient(BlockadeLabsAuthentication.Default.LoadFromDirectory("your/path/to/.blockadelabs"));; +var api = new BlockadeLabsClient(new BlockadeLabsAuthentication().LoadFromDirectory("your/path/to/.blockadelabs"));; ``` #### Use System Environment Variables @@ -113,7 +115,7 @@ Use your system's environment variables specify an api key to use. - Use `BLOCKADE_LABS_API_KEY` for your api key. ```csharp -var api = new BlockadeLabsClient(BlockadeLabsAuthentication.Default.LoadFromEnvironment()); +var api = new BlockadeLabsClient(new BlockadeLabsAuthentication().LoadFromEnvironment()); ``` ### Editor Dashboard