ITEM_HOST
This commit is contained in:
@@ -18,7 +18,7 @@ class APIService<T extends SerializerDeserializer> {
|
||||
|
||||
Dio _dio = Dio(
|
||||
BaseOptions(
|
||||
baseUrl: const String.fromEnvironment('HOST', defaultValue: 'http://localhost:8000'), // you can keep this blank
|
||||
baseUrl: AppConfig().get('HOST', defaultValue: 'http://localhost:8000'), // you can keep this blank
|
||||
headers: { 'Content-Type': 'application/json; charset=UTF-8', 'Access-Control-Allow-Origin': '*' },
|
||||
),
|
||||
)..interceptors.add(LogInterceptor(
|
||||
@@ -107,6 +107,7 @@ class APIService<T extends SerializerDeserializer> {
|
||||
try {
|
||||
_dio.options.headers["Authorization"] = "Bearer ${localStorage.getItem('accessToken') ?? ""}";
|
||||
_dio.interceptors.clear();
|
||||
print("${_dio.options.baseUrl}$url" );
|
||||
var response = await _request(url, method, body, options);
|
||||
if (response.statusCode != null && response.statusCode! < 400) {
|
||||
if (method == "delete") { cache.remove(url); return APIResponse<T>(); }
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
import 'package:localstorage/localstorage.dart';
|
||||
import 'package:oc_front/core/conf/conf_reader.dart';
|
||||
import 'package:oc_front/core/services/api_service.dart';
|
||||
import 'package:oc_front/core/services/perms_service.dart';
|
||||
import 'package:oc_front/main.dart';
|
||||
import 'package:oc_front/models/response.dart';
|
||||
|
||||
class AuthService {
|
||||
static var conf = AppConfig();
|
||||
static var isAuth = const bool.fromEnvironment('AUTH_MODE', defaultValue: true);
|
||||
static const _clientID = String.fromEnvironment('CLIENT_ID', defaultValue: 'test-client');
|
||||
static APIService<SimpleData> service = APIService(
|
||||
baseURL: const String.fromEnvironment('AUTH_HOST', defaultValue: 'http://localhost:8000/auth'),
|
||||
);
|
||||
static APIService<SimpleData>? service;
|
||||
|
||||
static Future<void> init() async {
|
||||
service ??= APIService<SimpleData>(baseURL:
|
||||
const String.fromEnvironment("HOST", defaultValue: "http://localhost:8000") + conf.get('AUTH_HOST', defaultValue: '/auth'));
|
||||
if (!isAuth) {
|
||||
return;
|
||||
}
|
||||
@@ -47,7 +49,7 @@ class AuthService {
|
||||
}
|
||||
|
||||
static Future<void> login(String username, String password) async {
|
||||
var token = await service.post("/login?client_id=$_clientID", <String, dynamic> {
|
||||
var token = await service!.post("/login?client_id=$_clientID", <String, dynamic> {
|
||||
"username": username,
|
||||
"password": password
|
||||
}, null);
|
||||
@@ -65,7 +67,7 @@ class AuthService {
|
||||
}
|
||||
|
||||
static Future<void> logout() async {
|
||||
var token = await service.delete("/logout?client_id=$_clientID", null);
|
||||
var token = await service!.delete("/logout?client_id=$_clientID", null);
|
||||
if (token.code == 200) {
|
||||
localStorage.setItem('accessToken', '');
|
||||
localStorage.setItem('username', '');
|
||||
@@ -79,14 +81,14 @@ class AuthService {
|
||||
return false;
|
||||
}
|
||||
// ignore: invalid_return_type_for_catch_error
|
||||
var isIntrospected = await service.get("/introspect", true, null).catchError((e) => mainKey?.currentState?.setState(() {}));
|
||||
var isIntrospected = await service!.get("/introspect", true, null).catchError((e) => mainKey?.currentState?.setState(() {}));
|
||||
return isIntrospected.code == 200;
|
||||
}
|
||||
|
||||
static Future<void> refresh(
|
||||
String accessToken, String username, Duration duration) async {
|
||||
Future.delayed(duration, () {
|
||||
service.post("/refresh?client_id=$_clientID", <String, dynamic> {
|
||||
service!.post("/refresh?client_id=$_clientID", <String, dynamic> {
|
||||
"access_token": accessToken,
|
||||
"username": username
|
||||
}, null).then((token) {
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import 'package:oc_front/core/conf/conf_reader.dart';
|
||||
import 'package:oc_front/models/response.dart';
|
||||
import 'package:oc_front/core/services/api_service.dart';
|
||||
|
||||
class EnumService {
|
||||
static final APIService<EnumData> _service = APIService<EnumData>(
|
||||
baseURL: const String.fromEnvironment('ITEM_HOST',
|
||||
defaultValue: 'http://localhost:8000/catalog')
|
||||
);
|
||||
static var conf = AppConfig();
|
||||
static APIService<EnumData>? _service;
|
||||
static String subPath = "/enum/";
|
||||
static Map<String, Map<String,dynamic>> enums = {};
|
||||
|
||||
@@ -24,6 +23,10 @@ class EnumService {
|
||||
}
|
||||
|
||||
static void init() {
|
||||
_service = _service ?? APIService<EnumData>(
|
||||
baseURL: const String.fromEnvironment("HOST", defaultValue: "http://localhost:8000") + conf.get('CATALOG_HOST',
|
||||
defaultValue: '/catalog')
|
||||
);
|
||||
_load("infrastructure");
|
||||
_load("storage/type");
|
||||
_load("storage/size");
|
||||
@@ -40,7 +43,7 @@ class EnumService {
|
||||
}
|
||||
|
||||
static void _load(String name) {
|
||||
_service.get("$subPath$name", false, null).then((response) {
|
||||
_service!.get("$subPath$name", false, null).then((response) {
|
||||
if (response.code == 200) {
|
||||
enums[name] = response.data!.value;
|
||||
}
|
||||
|
||||
@@ -5,9 +5,13 @@ import 'package:oc_front/models/response.dart';
|
||||
import 'package:oc_front/models/workflow.dart';
|
||||
|
||||
class BookingExecutionService extends AbstractService<WorkflowExecution> {
|
||||
@override APIService<WorkflowExecution> service = APIService<WorkflowExecution>(
|
||||
baseURL: const String.fromEnvironment('DATACENTER_HOST', defaultValue: 'http://localhost:8000/datacenter')
|
||||
);
|
||||
@override late final APIService<WorkflowExecution> service;
|
||||
|
||||
BookingExecutionService() {
|
||||
service = APIService<WorkflowExecution>(
|
||||
baseURL: const String.fromEnvironment("HOST", defaultValue: "http://localhost:8000") + super.conf.get('BOOKING_HOST',
|
||||
defaultValue: '/booking'));
|
||||
}
|
||||
@override String subPath = "/booking/";
|
||||
|
||||
@override Future<APIResponse<WorkflowExecution>> search(BuildContext? context, List<String> words, Map<String, dynamic> params) {
|
||||
|
||||
@@ -5,9 +5,13 @@ import 'package:oc_front/models/resources/resources.dart';
|
||||
import 'package:oc_front/models/response.dart';
|
||||
|
||||
class DatacenterService extends AbstractService<Resource> {
|
||||
@override APIService<Resource> service = APIService<Resource>(
|
||||
baseURL: const String.fromEnvironment('DATACENTER_HOST', defaultValue: 'http://localhost:8000/datacenter')
|
||||
);
|
||||
@override late final APIService<Resource> service;
|
||||
|
||||
DatacenterService() {
|
||||
service = APIService<Resource>(
|
||||
baseURL: const String.fromEnvironment("HOST", defaultValue: "http://localhost:8000") + super.conf.get('DATACENTER_HOST',
|
||||
defaultValue: '/datacenter'));
|
||||
}
|
||||
@override String subPath = "/";
|
||||
|
||||
@override Future<APIResponse<Resource>> search(BuildContext? context, List<String> words, Map<String, dynamic> params) {
|
||||
|
||||
@@ -9,24 +9,16 @@ class LogsService extends AbstractService<LogsResult> {
|
||||
late final APIService<LogsResult> service;
|
||||
|
||||
@override
|
||||
String subPath = "/loki/api/v1/";
|
||||
String subPath = "/loki";
|
||||
|
||||
LogsService() {
|
||||
service = APIService<LogsResult>(
|
||||
baseURL: super.conf.get('LOGS_HOST', defaultValue: 'http://localhost:8000/tools/loki'));
|
||||
baseURL: const String.fromEnvironment("HOST", defaultValue: "http://localhost:8000") + super.conf.get('SCHEDULER_HOST', defaultValue: '/scheduler'));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<APIResponse<LogsResult>> search(
|
||||
BuildContext? context, List<String> words, Map<String, dynamic> params) {
|
||||
List<String> v = [];
|
||||
for (var p in params.keys) {
|
||||
if (p == "start" || p == "end") {
|
||||
continue;
|
||||
}
|
||||
v.add("$p=\"${params[p]}\"");
|
||||
}
|
||||
return service.get("${subPath}query_range?query={${v.join(", ")}}&start=${params["start"].toString().substring(0, 10)}&end=${params["end"].toString().substring(0, 10)}", false, context);
|
||||
Future<APIResponse<LogsResult>> search(BuildContext? context, List<String> words, Map<String, dynamic> params) {
|
||||
return service.post(subPath, params, context);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -10,8 +10,8 @@ class PeerService extends AbstractService<Peer> {
|
||||
|
||||
PeerService() {
|
||||
service = APIService<Peer>(
|
||||
baseURL: super
|
||||
baseURL: const String.fromEnvironment("HOST", defaultValue: "http://localhost:8000") + super
|
||||
.conf
|
||||
.get('PEER_HOST', defaultValue: 'http://localhost:8000/peer'));
|
||||
.get('PEER_HOST', defaultValue: '/peer'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,9 @@ class ResourceService extends AbstractService<Resource> {
|
||||
|
||||
ResourceService() {
|
||||
service = APIService<Resource>(
|
||||
baseURL: super
|
||||
baseURL: const String.fromEnvironment("HOST", defaultValue: "http://localhost:8000") + super
|
||||
.conf
|
||||
.get('ITEM_HOST', defaultValue: 'http://localhost:8000/catalog'));
|
||||
.get('CATALOG_HOST', defaultValue: '/catalog'));
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -13,8 +13,8 @@ class SharedService extends AbstractService<CollaborativeArea> {
|
||||
|
||||
SharedService() {
|
||||
service = APIService<CollaborativeArea>(
|
||||
baseURL: super.conf.get('COLLABORATIVE_AREA_HOST',
|
||||
defaultValue: 'http://localhost:8000/shared'));
|
||||
baseURL: const String.fromEnvironment("HOST", defaultValue: "http://localhost:8000") + super.conf.get('COLLABORATIVE_AREA_HOST',
|
||||
defaultValue: '/shared'));
|
||||
}
|
||||
|
||||
Future<APIResponse<CollaborativeArea>> addWorkspace(
|
||||
|
||||
@@ -5,15 +5,13 @@ import 'package:oc_front/models/response.dart';
|
||||
import 'package:oc_front/models/workflow.dart';
|
||||
|
||||
class WorkflowExecutionService extends AbstractService<WorkflowExecutions> {
|
||||
@override APIService<WorkflowExecutions> service = APIService<WorkflowExecutions>(
|
||||
baseURL: const String.fromEnvironment('SCHEDULER_HOST', defaultValue: 'http://localhost:8000/scheduler')
|
||||
);
|
||||
@override late final APIService<WorkflowExecutions> service;
|
||||
@override String subPath = "/execution/";
|
||||
|
||||
WorkflowExecutionService() {
|
||||
service = APIService<WorkflowExecutions>(
|
||||
baseURL: super.conf.get('SCHEDULER_HOST',
|
||||
defaultValue: 'http://localhost:8000/scheduler'));
|
||||
baseURL: const String.fromEnvironment("HOST", defaultValue: "http://localhost:8000") + super.conf.get('SCHEDULER_HOST',
|
||||
defaultValue: '/scheduler'));
|
||||
}
|
||||
@override
|
||||
Future<APIResponse<WorkflowExecutions>> search(
|
||||
|
||||
@@ -5,9 +5,13 @@ import 'package:oc_front/models/response.dart';
|
||||
import 'package:oc_front/models/workflow.dart';
|
||||
|
||||
class SchedulerService extends AbstractService<WorkflowExecutions> {
|
||||
@override APIService<WorkflowExecutions> service = APIService<WorkflowExecutions>(
|
||||
baseURL: const String.fromEnvironment('SCHEDULER_HOST', defaultValue: 'http://localhost:8000/scheduler')
|
||||
);
|
||||
@override late final APIService<WorkflowExecutions> service;
|
||||
|
||||
SchedulerService() {
|
||||
service = APIService<WorkflowExecutions>(
|
||||
baseURL: const String.fromEnvironment("HOST", defaultValue: "http://localhost:8000") + super.conf.get('SCHEDULER_HOST',
|
||||
defaultValue: '/scheduler'));
|
||||
}
|
||||
@override String subPath = "/";
|
||||
|
||||
Future<APIResponse<WorkflowExecutions>> schedule(BuildContext? context, String id, Map<String, dynamic> body, Map<String, dynamic> params) {
|
||||
|
||||
@@ -13,11 +13,11 @@ class WorflowService extends AbstractService<Workflow> {
|
||||
|
||||
WorflowService() {
|
||||
service = APIService<Workflow>(
|
||||
baseURL: super.conf.get('WORKFLOW_HOST',
|
||||
defaultValue: 'http://localhost:8000/workflow'));
|
||||
baseURL: const String.fromEnvironment("HOST", defaultValue: "http://localhost:8000") + super.conf.get('WORKFLOW_HOST',
|
||||
defaultValue: '/workflow'));
|
||||
serviceCheck = APIService<Check>(
|
||||
baseURL: super.conf.get('WORKFLOW_HOST',
|
||||
defaultValue: 'http://localhost:8000/workflow'));
|
||||
baseURL: const String.fromEnvironment("HOST", defaultValue: "http://localhost:8000") + super.conf.get('WORKFLOW_HOST',
|
||||
defaultValue: '/workflow'));
|
||||
}
|
||||
|
||||
Future<APIResponse<Check>> check(
|
||||
|
||||
@@ -11,7 +11,7 @@ class WorkspaceService extends AbstractService<Workspace> {
|
||||
|
||||
WorkspaceService() {
|
||||
service = APIService<Workspace>(
|
||||
baseURL: super.conf.get('WORKSPACE_HOST',
|
||||
defaultValue: 'http://localhost:8000/workspace'));
|
||||
baseURL: const String.fromEnvironment("HOST", defaultValue: "http://localhost:8000") + super.conf.get('WORKSPACE_HOST',
|
||||
defaultValue: '/workspace'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,14 +14,8 @@ import 'package:oc_front/core/services/enum_service.dart';
|
||||
import 'package:oc_front/core/services/router.dart';
|
||||
import 'package:oc_front/core/sections/end_drawer.dart';
|
||||
import 'package:oc_front/widgets/dialog/login.dart';
|
||||
import 'package:oc_front/core/conf/conf_reader.dart';
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
// Load configuration before running the app
|
||||
final appConfig = AppConfig();
|
||||
await appConfig.loadConfig();
|
||||
|
||||
// Run `LinuxWebViewPlugin.initialize()` first before creating a WebView.
|
||||
await initLocalStorage();
|
||||
runApp(const MyApp());
|
||||
|
||||
Reference in New Issue
Block a user