blob: 275ca146304310010efdfb6e1dcdb3f15d00d40c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
@page "/"
@using System.Net.Http.Headers
@using Spacebar.AdminApi.TestClient.Services
@inject Config Config
@inject ILocalStorageService LocalStorage
<PageTitle>Home</PageTitle>
<span style="@($"color: {(IsApiUrlValid ? "green" : "red")};")">Spacebar API URL: </span>
<InputText @bind-Value:get="Config.ApiUrl" @bind-Value:set="@(async (v) => {
Config.ApiUrl = v!;
await ValidateAndSaveConfig();
})"/>
<br/>
<!-- <span style="@($"color: {(IsGatewayUrlValid ? "green" : "red")};")">Spacebar Gateway URL: </span> -->
<!-- <InputText @bind-Value="GatewayUrl" /> -->
<!-- <br /> -->
<span style="@($"color: {(IsCdnUrlValid ? "green" : "red")};")">Spacebar CDN URL: </span>
<InputText @bind-Value:get="Config.CdnUrl" @bind-Value:set="@(async (v) => {
Config.CdnUrl = v!;
await ValidateAndSaveConfig();
})"/>
<br/>
<span style="@($"color: {(IsAdminApiUrlValid ? "green" : "red")};")">Spacebar Admin API URL: </span>
<InputText @bind-Value:get="Config.AdminUrl" @bind-Value:set="@(async (v) => {
Config.AdminUrl = v!;
await ValidateAndSaveConfig();
})"/>
<br/>
<span style="@($"color: {(IsAccessTokenValid ? "green" : "red")};")">Access Token: </span>
<InputText @bind-Value:get="Config.AccessToken" @bind-Value:set="@(async (v) => {
Config.AccessToken = v!;
await ValidateAndSaveConfig();
})"/>
<a href="/login">New access token</a>
<br/>
@code {
private bool IsApiUrlValid { get; set; }
// private bool IsGatewayUrlValid { get; set; }
private bool IsCdnUrlValid { get; set; }
private bool IsAdminApiUrlValid { get; set; }
private bool IsAccessTokenValid { get; set; }
protected override async Task OnInitializedAsync() {
await ValidateAndSaveConfig();
}
private async Task ValidateAndSaveConfig() {
await LocalStorage.SetItemAsync("sb_admin_tc_config", Config);
using var hc = new HttpClient();
HttpResponseMessage response;
try {
response = await hc.GetAsync(Config.ApiUrl + "/api/v9/policies/instance/domains");
IsApiUrlValid = response.IsSuccessStatusCode;
}
catch {
IsApiUrlValid = false;
}
StateHasChanged();
// response = await hc.GetAsync(Config.GatewayUrl + "/api/v9/policies/instance");
// IsGatewayUrlValid = response.IsSuccessStatusCode;
// StateHasChanged();
try {
response = await hc.GetAsync(Config.CdnUrl + "/ping");
IsCdnUrlValid = response.IsSuccessStatusCode;
}
catch {
IsCdnUrlValid = false;
}
StateHasChanged();
try {
response = await hc.GetAsync(Config.AdminUrl + "/_spacebar/admin/ping");
IsAdminApiUrlValid = response.IsSuccessStatusCode;
}
catch {
IsAdminApiUrlValid = false;
}
StateHasChanged();
try {
var request = new HttpRequestMessage(HttpMethod.Get, Config.AdminUrl + "/_spacebar/admin/whoami");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Config.AccessToken);
response = await hc.SendAsync(request);
IsAccessTokenValid = response.IsSuccessStatusCode;
}
catch {
IsAccessTokenValid = false;
}
StateHasChanged();
}
}
|