-
-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from pengweiqhca/master
添加OpenApi客户端实现
- Loading branch information
Showing
60 changed files
with
1,358 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
*.sln.docstates | ||
.vs | ||
|
||
*.cmd | ||
|
||
#Auto Generate files | ||
__ConfigTemp/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 14 additions & 14 deletions
28
Apollo.Configuration.Demo/Apollo.Configuration.Demo.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.2</TargetFramework> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.2</TargetFramework> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.1.1" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" /> | ||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.1.1" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.1.1" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" /> | ||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.1.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Apollo.ConfigAdapter.Yaml\Apollo.ConfigAdapter.Yaml.csproj" /> | ||
<ProjectReference Include="..\Apollo.Configuration\Apollo.Configuration.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Apollo.ConfigAdapter.Yaml\Apollo.ConfigAdapter.Yaml.csproj" /> | ||
<ProjectReference Include="..\Apollo.Configuration\Apollo.Configuration.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
Apollo.OpenApi.DependencyInjection/Apollo.OpenApi.DependencyInjection.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<AssemblyName>Com.Ctrip.Framework.Apollo.OpenApi.DependencyInjection</AssemblyName> | ||
<PackageReleaseNotes></PackageReleaseNotes> | ||
<Nullable>enable</Nullable> | ||
<LangVersion>preview</LangVersion> | ||
<Description>携程Apollo的OpenApi客户端,入口接口IOpenApiFactory</Description> | ||
<PackageIconUrl>https://raw.githubusercontent.com/ctripcorp/apollo/master/apollo-portal/src/main/resources/static/img/config.png</PackageIconUrl> | ||
<PackageProjectUrl>$(RepositoryUrl)/$(AssemblyName)</PackageProjectUrl> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<Version>2.0.0</Version> | ||
<RootNamespace>Com.Ctrip.Framework.Apollo.OpenApi</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Http" Version="2.2.0" /> | ||
|
||
<ProjectReference Include="..\Apollo.OpenApi\Apollo.OpenApi.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
25 changes: 25 additions & 0 deletions
25
Apollo.OpenApi.DependencyInjection/ServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Com.Ctrip.Framework.Apollo.OpenApi; | ||
using JetBrains.Annotations; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
using Microsoft.Extensions.Options; | ||
using System; | ||
using System.Net.Http; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
public static class ServiceCollectionExtensions | ||
{ | ||
public static IServiceCollection AddApolloOpenApi([NotNull] this IServiceCollection services) | ||
{ | ||
if (services == null) throw new ArgumentNullException(nameof(services)); | ||
|
||
services.AddOptions().AddHttpClient() | ||
.TryAddSingleton<IOpenApiFactory>(provider => new OpenApiFactory( | ||
provider.GetRequiredService<IOptions<OpenApiOptions>>().Value, | ||
provider.GetRequiredService<IHttpMessageHandlerFactory>().CreateHandler)); | ||
|
||
return services; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net461;netcoreapp2.2</TargetFrameworks> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="2.*" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.*" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.*" /> | ||
<PackageReference Include="xunit" Version="2.*" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.*" /> | ||
|
||
<ProjectReference Include="..\Apollo.OpenApi.DependencyInjection\Apollo.OpenApi.DependencyInjection.csproj" /> | ||
|
||
<ProjectReference Include="..\Apollo\Apollo.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using Com.Ctrip.Framework.Apollo.Core; | ||
using Com.Ctrip.Framework.Apollo.OpenApi; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Com.Ctrip.Framework.Apollo | ||
{ | ||
public class AppClusterTest : BaseTest | ||
{ | ||
public AppClusterTest(ITestOutputHelper output) : base(output) { } | ||
|
||
[Fact] | ||
public async Task GetEnvClusterInfo() | ||
{ | ||
var result = await CreateAppClusterClient().GetEnvClusterInfo().ConfigureAwait(false); | ||
|
||
Dump(result); | ||
|
||
Assert.NotNull(result); | ||
|
||
var @default = result.FirstOrDefault(ec => ec.Env == "DEV"); | ||
|
||
Assert.NotNull(@default); | ||
|
||
Assert.Contains(ConfigConsts.ClusterNameDefault, @default.Clusters); | ||
} | ||
|
||
[Fact] | ||
public async Task GetAppInfo() | ||
{ | ||
var result = await CreateAppClusterClient().GetAppInfo().ConfigureAwait(false); | ||
|
||
Dump(result); | ||
|
||
Assert.NotNull(result); | ||
|
||
Assert.Equal(AppIds[0], result.AppId); | ||
} | ||
|
||
[Fact] | ||
public async Task GetAppsInfo() | ||
{ | ||
var result = await CreateAppClusterClient().GetAppsInfo().ConfigureAwait(false); | ||
|
||
Assert.NotNull(result); | ||
Assert.NotEmpty(result); result = await CreateAppClusterClient().GetAppsInfo(AppIds).ConfigureAwait(false); | ||
|
||
Dump(result); | ||
|
||
Assert.NotNull(result); | ||
Assert.Equal(2, result.Count); | ||
} | ||
|
||
[Fact] | ||
public async Task GetNamespaces() | ||
{ | ||
var result = await CreateAppClusterClient().GetNamespaces(Env).ConfigureAwait(false); | ||
|
||
Dump(result); | ||
|
||
Assert.NotNull(result); | ||
Assert.Contains(result, ns => ns.NamespaceName == ConfigConsts.NamespaceApplication); | ||
Assert.NotEmpty(result.First(ns => ns.NamespaceName == ConfigConsts.NamespaceApplication).Items); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Com.Ctrip.Framework.Apollo.OpenApi; | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Collections.Generic; | ||
using Com.Ctrip.Framework.Apollo.Core; | ||
using Xunit.Abstractions; | ||
|
||
namespace Com.Ctrip.Framework.Apollo | ||
{ | ||
public abstract class BaseTest | ||
{ | ||
private readonly ITestOutputHelper _output; | ||
|
||
public static IOpenApiFactory Factory { get; } = new OpenApiFactory(new OpenApiOptions | ||
{ | ||
PortalUrl = new Uri("http://106.12.25.204:8070"), | ||
Token = "19419f7d3e5a1b0b0cfe3e238b36e09718fb8e94" | ||
}); | ||
|
||
public static IReadOnlyList<string> AppIds = new List<string> { "apollo-client", "apollo-demo" }; | ||
|
||
public static string Env => "DEV"; | ||
|
||
public static IAppClusterClient CreateAppClusterClient() => Factory.CreateAppClusterClient(AppIds[0]); | ||
|
||
public static INamespaceClient CreateNamespaceClient() => Factory.CreateNamespaceClient(AppIds[0], Env); | ||
|
||
protected BaseTest(ITestOutputHelper output) => _output = output; | ||
|
||
protected void Dump(object obj) => _output.WriteLine(JsonConvert.SerializeObject(obj, Formatting.Indented)); | ||
} | ||
} |
Oops, something went wrong.