Skip to content

Commit

Permalink
Release v1.0.0-beta.3
Browse files Browse the repository at this point in the history
  • Loading branch information
operate-services-sdk-bot authored and XiangGuoUnity committed Mar 17, 2023
1 parent afc7d57 commit ef12dd4
Show file tree
Hide file tree
Showing 237 changed files with 9,087 additions and 1,925 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -399,5 +399,8 @@ FodyWeavers.xsd
*.sln.iml
.idea/

# VS Code
.vscode/

# macOS
.DS_Store
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ All notable changes to UGS CLI will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.0.0-beta.3] - 2023-03-17

### Added

- Player Management Service commands. Run `ugs player -h` to show usage.
- Access Module Service commands. Run `ugs access -h` to show usage.
- Cloud Code C# Modules subcommands. Run `ugs cloud-code modules -h` to show usage.
- `ugs deploy` now supports Cloud Code C# modules.
- Reconcile option for Deploy command
- Added dry-run option for Deploy command
- This allows to check what the expected outcome of a given deploy will be

### Changed

- Updated environment name validation to prevent using uppercase
- Documentation is now hosted on https://services.docs.unity.com/guides/ugs-cli/latest/general/overview
- Tweaked memory and cpu usage restrictions for Cloud Code parsing related commands

## [1.0.0-beta.2] - 2023-02-03

### Added
Expand Down
40 changes: 3 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
# UGS CLI
For installing the UGS CLI and getting started, see [Getting Started](docs/getting-started.md).

For information regarding services or UGS CLI commands, see [Base Modules](#base-modules) and [Service Modules](#service-modules).
For installing the UGS CLI and getting started, see [Getting Started](https://services.docs.unity.com/guides/ugs-cli/latest/general/get-started/install-the-cli).

The source code project is for reference only. You may not be able to build it due to lack of access to internal dependencies.

Jump to section:
- [Basic Commands](#basic-commands)
- [Base Modules](#base-modules)
- [Service Modules](#service-modules)
- [Examples](#examples)
- [System Compatibility](#system-compatibility)
- [Getting Help](#getting-help)
## Documentation
To see the full list of services and commands available in the UGS CLI, visit the documentation on https://services.docs.unity.com/guides/ugs-cli/latest/general/overview

## Basic Commands
An UGS CLI command has the following format:
Expand All @@ -29,33 +22,6 @@ To get the version of the CLI:
ugs --version
```

## Base Modules
[Configuration](docs/module-configuration.md)

[Environment](docs/module-environment.md)

[Authentication](docs/module-authentication.md)

[Deploy](docs/deploy-command.md)

## Service Modules
[Cloud-Code](docs/module-cloud-code.md)

[Lobby](docs/module-lobby.md)

## Samples

[Samples](Samples) are provided to demonstrate how to use CLI.

## Examples
[Example of the CLI in Unity Cloud Build](docs/ci-cd-recipes.md#unity-cloud-build)

[Example of the CLI in Github Actions](docs/ci-cd-recipes.md#github-actions)

[Example of the CLI in Jenkins](docs/ci-cd-recipes.md#jenkins)

[Example of the CLI in Docker](docs/ci-cd-recipes.md#docker)

## System Compatibility

### Windows
Expand Down
8 changes: 4 additions & 4 deletions Samples/Deploy/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ ugs deploy .
You will find all the contents deployed in your dashboard for the configured project and environment. The command deploys all the samples in current (`Deploy`) directory for supported services.

---
[`deploy`]: /docs/deploy-command.md
[`deploy`]: https://services.docs.unity.com/guides/ugs-cli/latest/general/base-commands/deploy
[Remote Config files]: https://docs.unity3d.com/Packages/[email protected]/manual/Authoring/remote_config_files.html
[Declare parameters in the script]: https://docs.unity.com/cloud-code/authoring-scripts-editor.html#Declare_parameters_in_the_script
[Script.js]: /Samples/Deploy/CloudCode/Script.js
[configuration.rc]: /Samples/Deploy/RemoteConfig/configuration.rc
[Samples/Deploy]: /Samples/Deploy
[Deploy Command]: /docs/project-roles.md#deploy-command
[Deploy Command]: https://services.docs.unity.com/guides/ugs-cli/latest/general/troubleshooting/project-roles#deploy-command
[Service Account]: https://services.docs.unity.com/docs/service-account-auth/index.html
[Login]: /docs/module-authentication.md#login
[configuration]: /docs/module-configuration.md#configuration-module
[Login]: https://services.docs.unity.com/guides/ugs-cli/latest/general/base-commands/authentication/login
[configuration]: https://services.docs.unity.com/guides/ugs-cli/latest/general/base-commands/configuration/configuration-keys
22 changes: 22 additions & 0 deletions Third Party Notices.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,28 @@ limitations under the License.

<hr>

Component Name: wiremock-net

License Type: Apache License 2.0

Copyright (c) 2023 Stef Heyenrath

https://github.com/WireMock-Net/WireMock.Net/blob/master/LICENSE

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

<hr>

Component Name: SonarQube

License Type: GNU Lesser General Public License v3.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
using System.CommandLine.Builder;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
using Unity.Services.Cli.Access.Input;
using Unity.Services.Cli.Access.Service;
using Unity.Services.Cli.Common;
using Unity.Services.Cli.Common.Input;
using Unity.Services.Cli.Common.Networking;
using Unity.Services.Cli.TestUtils;
using Unity.Services.Gateway.AccessApiV1.Generated.Api;

namespace Unity.Services.Cli.Access.UnitTest;

[TestFixture]
public class AccessModuleTests
{
private readonly AccessModule k_AccessModule = new();

[Test]
public void BuildCommands_CreateCommands()
{
var commandLineBuilder = new CommandLineBuilder();
commandLineBuilder.AddModule(k_AccessModule);
TestsHelper.AssertContainsCommand(commandLineBuilder.Command, k_AccessModule.ModuleRootCommand!.Name, out var resultCommand);
Assert.Multiple(() =>
{
Assert.That(resultCommand, Is.EqualTo(k_AccessModule.ModuleRootCommand));
Assert.That(k_AccessModule.GetPlayerPolicyCommand!.Handler, Is.Not.Null);
Assert.That(k_AccessModule.GetProjectPolicyCommand!.Handler, Is.Not.Null);
Assert.That(k_AccessModule.GetAllPlayerPoliciesCommand!.Handler, Is.Not.Null);
Assert.That(k_AccessModule.UpsertProjectPolicyCommand!.Handler, Is.Not.Null);
Assert.That(k_AccessModule.UpsertPlayerPolicyCommand!.Handler, Is.Not.Null);
Assert.That(k_AccessModule.DeleteProjectPolicyStatementsCommand!.Handler, Is.Not.Null);
Assert.That(k_AccessModule.ModuleRootCommand!.Aliases, Does.Contain("ac"));
Assert.That(k_AccessModule.DeletePlayerPolicyStatementsCommand!.Handler, Is.Not.Null);
});
}

[Test]
public void GetProjectPolicyCommand_ContainsRequiredInputs()
{
Assert.Multiple(() =>
{
Assert.That(k_AccessModule.GetProjectPolicyCommand!.Options, Does.Contain(CommonInput.CloudProjectIdOption));
Assert.That(k_AccessModule.GetProjectPolicyCommand!.Options, Does.Contain(CommonInput.EnvironmentNameOption));
});
}

[Test]
public void GetPlayerPolicyCommand_ContainsRequiredInputs()
{
Assert.Multiple(() =>
{
Assert.That(k_AccessModule.GetPlayerPolicyCommand!.Options, Does.Contain(CommonInput.CloudProjectIdOption));
Assert.That(k_AccessModule.GetPlayerPolicyCommand!.Options, Does.Contain(CommonInput.EnvironmentNameOption));
Assert.That(k_AccessModule.GetPlayerPolicyCommand.Arguments, Does.Contain(AccessInput.PlayerIdArgument));
});
}

[Test]
public void GetAllPlayerPoliciesCommand_ContainsRequiredInputs()
{
Assert.Multiple(() =>
{
Assert.That(k_AccessModule.GetAllPlayerPoliciesCommand!.Options, Does.Contain(CommonInput.CloudProjectIdOption));
Assert.That(k_AccessModule.GetAllPlayerPoliciesCommand!.Options, Does.Contain(CommonInput.EnvironmentNameOption));
});
}

[Test]
public void UpsertProjectPolicyCommand_ContainsRequiredInputs()
{
Assert.Multiple(() =>
{
Assert.That(k_AccessModule.UpsertProjectPolicyCommand!.Options, Does.Contain(CommonInput.CloudProjectIdOption));
Assert.That(k_AccessModule.UpsertProjectPolicyCommand!.Options, Does.Contain(CommonInput.EnvironmentNameOption));
Assert.That(k_AccessModule.UpsertProjectPolicyCommand!.Arguments, Does.Contain(AccessInput.FilePathArgument));
});
}

[Test]
public void UpsertPlayerPolicyCommand_ContainsRequiredInputs()
{
Assert.Multiple(() =>
{
Assert.That(k_AccessModule.UpsertPlayerPolicyCommand!.Options, Does.Contain(CommonInput.CloudProjectIdOption));
Assert.That(k_AccessModule.UpsertPlayerPolicyCommand!.Options, Does.Contain(CommonInput.EnvironmentNameOption));
Assert.That(k_AccessModule.UpsertPlayerPolicyCommand!.Arguments, Does.Contain(AccessInput.PlayerIdArgument));
Assert.That(k_AccessModule.UpsertPlayerPolicyCommand!.Arguments, Does.Contain(AccessInput.FilePathArgument));
});
}

[Test]
public void DeleteProjectPolicyStatements_ContainsRequiredInputs()
{
Assert.Multiple(() =>
{
Assert.That(k_AccessModule.DeleteProjectPolicyStatementsCommand!.Options, Does.Contain(CommonInput.CloudProjectIdOption));
Assert.That(k_AccessModule.DeleteProjectPolicyStatementsCommand!.Options, Does.Contain(CommonInput.EnvironmentNameOption));
Assert.That(k_AccessModule.DeleteProjectPolicyStatementsCommand!.Arguments, Does.Contain(AccessInput.FilePathArgument));
});
}

[Test]
public void DeletePlayerPolicyStatements_ContainsRequiredInputs()
{
Assert.Multiple(() =>
{
Assert.That(k_AccessModule.DeletePlayerPolicyStatementsCommand!.Options, Does.Contain(CommonInput.CloudProjectIdOption));
Assert.That(k_AccessModule.DeletePlayerPolicyStatementsCommand!.Options, Does.Contain(CommonInput.EnvironmentNameOption));
Assert.That(k_AccessModule.DeletePlayerPolicyStatementsCommand!.Arguments, Does.Contain(AccessInput.PlayerIdArgument));
Assert.That(k_AccessModule.DeletePlayerPolicyStatementsCommand!.Arguments, Does.Contain(AccessInput.FilePathArgument));
});
}

[TestCase(typeof(IProjectPolicyApi))]
[TestCase(typeof(IPlayerPolicyApi))]
[TestCase(typeof(IAccessService))]
public void AccessModuleModuleRegistersServices(Type serviceType)
{
EndpointHelper.InitializeNetworkTargetEndpoints(new[]
{
typeof(AccessEndpoints).GetTypeInfo()
});
var services = new List<ServiceDescriptor>();
var hostBuilder = TestsHelper.CreateAndSetupMockHostBuilder(services);
hostBuilder.ConfigureServices(AccessModule.RegisterServices);
Assert.That(services.FirstOrDefault(c => c.ServiceType == serviceType), Is.Not.Null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
using Spectre.Console;
using Unity.Services.Cli.Access.Handlers;
using Unity.Services.Cli.Access.Input;
using Unity.Services.Cli.Access.Service;
using Unity.Services.Cli.Access.UnitTest.Utils;
using Unity.Services.Cli.Common.Console;
using Unity.Services.Cli.Common.Utils;
using Unity.Services.Cli.TestUtils;
using ILogger = Microsoft.Extensions.Logging.ILogger;

namespace Unity.Services.Cli.Access.UnitTest.Handlers;

[TestFixture]
public class DeletePlayerPolicyStatementsHandlerTests
{
readonly Mock<IAccessService> m_MockAccessService = new();
readonly Mock<ILogger> m_MockLogger = new();
readonly Mock<IUnityEnvironment> m_MockUnityEnvironment = new();

[SetUp]
public void SetUp()
{
m_MockAccessService.Reset();
m_MockLogger.Reset();
m_MockUnityEnvironment.Reset();
}

[Test]
public async Task DeletePlayerPolicyStatementsAsync_CallsLoadingIndicator()
{
Mock<ILoadingIndicator> mockLoadingIndicator = new Mock<ILoadingIndicator>();
await DeletePlayerPolicyStatementsHandler.DeletePlayerPolicyStatementsAsync(null!, null!, null!, null!,
mockLoadingIndicator.Object, CancellationToken.None);
mockLoadingIndicator.Verify(ex => ex
.StartLoadingAsync(It.IsAny<string>(), It.IsAny<Func<StatusContext?,Task>>()), Times.Once);
}

[Test]
public async Task DeletePlayerPolicyStatementsHandler_valid()
{
AccessInput input = new()
{
CloudProjectId = TestValues.ValidProjectId,
PlayerId = TestValues.ValidPlayerId,
FilePath = new FileInfo(TestValues.FilePath)
};

m_MockUnityEnvironment.Setup(x => x.FetchIdentifierAsync()).ReturnsAsync(TestValues.ValidEnvironmentId);
m_MockAccessService?.Setup(x =>
x.DeletePlayerPolicyStatementsAsync(TestValues.ValidProjectId, TestValues.ValidEnvironmentId, TestValues.ValidPlayerId, It.IsAny<FileInfo>(), CancellationToken.None));

await DeletePlayerPolicyStatementsHandler.DeletePlayerPolicyStatementsAsync(input, m_MockUnityEnvironment.Object,
m_MockAccessService!.Object, m_MockLogger!.Object, CancellationToken.None);

m_MockUnityEnvironment.Verify(x => x.FetchIdentifierAsync(), Times.Once);
m_MockAccessService.Verify(x => x.DeletePlayerPolicyStatementsAsync(TestValues.ValidProjectId, TestValues.ValidEnvironmentId, TestValues.ValidPlayerId, It.IsAny<FileInfo>(), CancellationToken.None), Times.Once);
TestsHelper.VerifyLoggerWasCalled(m_MockLogger, LogLevel.Information, expectedTimes: Times.Once);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
using Spectre.Console;
using Unity.Services.Cli.Access.Handlers;
using Unity.Services.Cli.Access.Input;
using Unity.Services.Cli.Access.Service;
using Unity.Services.Cli.Access.UnitTest.Utils;
using Unity.Services.Cli.Common.Console;
using Unity.Services.Cli.Common.Utils;
using Unity.Services.Cli.TestUtils;
using ILogger = Microsoft.Extensions.Logging.ILogger;

namespace Unity.Services.Cli.Access.UnitTest.Handlers;

[TestFixture]
public class DeleteProjectPolicyStatementsHandlerTests
{
readonly Mock<IAccessService> m_MockAccessService = new();
readonly Mock<ILogger> m_MockLogger = new();
readonly Mock<IUnityEnvironment> m_MockUnityEnvironment = new();

[SetUp]
public void SetUp()
{
m_MockAccessService.Reset();
m_MockLogger.Reset();
m_MockUnityEnvironment.Reset();
}

[Test]
public async Task DeleteProjectPolicyStatementsAsync_CallsLoadingIndicator()
{
Mock<ILoadingIndicator> mockLoadingIndicator = new Mock<ILoadingIndicator>();
await DeleteProjectPolicyStatementsHandler.DeleteProjectPolicyStatementsAsync(null!, null!, null!, null!,
mockLoadingIndicator.Object, CancellationToken.None);
mockLoadingIndicator.Verify(ex => ex
.StartLoadingAsync(It.IsAny<string>(), It.IsAny<Func<StatusContext?,Task>>()), Times.Once);
}

[Test]
public async Task DeleteProjectPolicyStatementsHandler_valid()
{
AccessInput input = new()
{
CloudProjectId = TestValues.ValidProjectId,
FilePath = new FileInfo(TestValues.FilePath)
};

m_MockUnityEnvironment.Setup(x => x.FetchIdentifierAsync()).ReturnsAsync(TestValues.ValidEnvironmentId);
m_MockAccessService?.Setup(x =>
x.DeletePolicyStatementsAsync(TestValues.ValidProjectId, TestValues.ValidEnvironmentId, It.IsAny<FileInfo>(), CancellationToken.None));

await DeleteProjectPolicyStatementsHandler.DeleteProjectPolicyStatementsAsync(input, m_MockUnityEnvironment.Object,
m_MockAccessService!.Object, m_MockLogger!.Object, CancellationToken.None);

m_MockUnityEnvironment.Verify(x => x.FetchIdentifierAsync(), Times.Once);
m_MockAccessService.Verify(x => x.DeletePolicyStatementsAsync(TestValues.ValidProjectId, TestValues.ValidEnvironmentId, It.IsAny<FileInfo>(), CancellationToken.None), Times.Once);
TestsHelper.VerifyLoggerWasCalled(m_MockLogger, LogLevel.Information, expectedTimes: Times.Once);
}
}
Loading

0 comments on commit ef12dd4

Please sign in to comment.