public static BMemoryQueryParameters MakeSSOQueryParameters(string _PasswordMD5_FromAccessToken) { return(new BMemoryQueryParameters() { Domain = Resources_DeploymentManager.Get().GetDeploymentBranchNameEscapedLoweredWithDash().ToUpper(), SubDomain = "SSO_ACCESS_TOKEN_VALIDATION", Identifier = _PasswordMD5_FromAccessToken }); }
private BWebServiceResponse OnRequest_Internal_Logic( JObject ParsedBody, Action <string> _ErrorMessageAction) { var ForUrlPath = (string)ParsedBody["forUrlPath"]; var RequestMethod = (string)ParsedBody["requestMethod"]; var SSOTokenRefreshStatus = Controller_SSOAccessToken.EPerformCheckAndRefreshSuccessStatus.None; var AccessTokenWithTokenType = (string)ParsedBody["authorization"]; string Method; if (AccessTokenWithTokenType.StartsWith("Basic")) { var QueryParameters = new BMemoryQueryParameters() { Domain = Resources_DeploymentManager.Get().GetDeploymentBranchNameEscapedLoweredWithDash().ToUpper(), SubDomain = "SELF_SIGNED_ACCESS_TOKEN_VALIDATION", Identifier = AccessTokenWithTokenType }; var MethodPrimitive = MemoryService.GetKeyValue(QueryParameters, "method", _ErrorMessageAction); if (MethodPrimitive == null) { return(BWebResponse.Unauthorized("Token is invalid. Please re-login.")); } Method = MethodPrimitive.AsString; } else { var AccessTokenManager = new Controller_SSOAccessToken(AccessTokenWithTokenType, DatabaseService, MemoryService, AzureAD_AppID, AzureAD_ClientSecret, SSOSuperAdmins, _ErrorMessageAction); if (AccessTokenManager.PerformCheckAndRefresh( out SSOTokenRefreshStatus, out AccessTokenWithTokenType, out _, out string _EmailAddressWithoutPostfix)) { ParsedBody["authorization"] = AccessTokenWithTokenType; }
public static string DBSERVICE_UNIQUEFILEFIELDS_TABLE() { return("unique-file-fields-" + Resources_DeploymentManager.Get().GetDeploymentBranchNameEscapedLoweredWithDash()); }
public static string DBSERVICE_FILE_CONVERSIONS_TABLE() { return("file-conversions-" + Resources_DeploymentManager.Get().GetDeploymentBranchNameEscapedLoweredWithDash()); }
public static string DBSERVICE_USERS_TABLE() { return("users-" + Resources_DeploymentManager.Get().GetDeploymentBranchNameEscapedLoweredWithDash()); }
static void Main() { System.Console.WriteLine("Initializing the service..."); //#if (Debug || DEBUG) // if (!ServicesDebugOnlyUtilities.CalledFromMain()) return; //#endif // In case of a cloud component dependency or environment variable is added/removed; /* * Common initialization step */ if (!BServiceInitializer.Initialize(out BServiceInitializer ServInit, new string[][] { new string[] { "GOOGLE_CLOUD_PROJECT_ID" }, new string[] { "GOOGLE_APPLICATION_CREDENTIALS", "GOOGLE_PLAIN_CREDENTIALS" }, new string[] { "DEPLOYMENT_BRANCH_NAME" }, new string[] { "DEPLOYMENT_BUILD_NUMBER" }, new string[] { "REDIS_ENDPOINT" }, new string[] { "REDIS_PORT" }, new string[] { "REDIS_PASSWORD" }, new string[] { "CAD_FILE_STORAGE_BUCKET" }, new string[] { "AUTH_SERVICE_ENDPOINT" }, new string[] { "CAD_PROCESS_SERVICE_ENDPOINT" }, new string[] { "INTERNAL_CALL_PRIVATE_KEY" } })) { return; } bool bInitSuccess = true; bInitSuccess &= ServInit.WithDatabaseService(); bInitSuccess &= ServInit.WithFileService(); bInitSuccess &= ServInit.WithPubSubService(); bInitSuccess &= ServInit.WithTracingService(); bInitSuccess &= ServInit.WithMemoryService(); if (!bInitSuccess) { return; } Resources_DeploymentManager.Get().SetDeploymentBranchNameAndBuildNumber(ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BRANCH_NAME"], ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BUILD_NUMBER"]); CommonData.MemoryQueryParameters = new BMemoryQueryParameters() { Domain = Resources_DeploymentManager.Get().GetDeploymentBranchNameEscapedLoweredWithDash().ToUpper(), SubDomain = "COMMON_DATA", Identifier = "MEMORY_SERVICE_DATA" }; var AuthServiceEndpoint = ServInit.RequiredEnvironmentVariables["AUTH_SERVICE_ENDPOINT"]; var CadFileStorageBucketName = ServInit.RequiredEnvironmentVariables["CAD_FILE_STORAGE_BUCKET"]; var CadProcessServiceEndpoint = ServInit.RequiredEnvironmentVariables["CAD_PROCESS_SERVICE_ENDPOINT"]; Controller_DeliveryEnsurer.Get().SetDatabaseService(ServInit.DatabaseService); Controller_DeliveryEnsurer.Get().SetFileService(ServInit.FileService); Controller_DeliveryEnsurer.Get().SetServiceIdentifier("cad-file-service", Actions.EAction.ACTION_CAD_FILE_SERVICE_DELIVERY_ENSURER); Controller_AtomicDBOperation.Get().SetMemoryService(ServInit.MemoryService, CommonData.MemoryQueryParameters); Manager_PubSubService.Get().Setup(ServInit.PubSubService); var InitializerThread = new Thread(() => { Thread.CurrentThread.IsBackground = true; ServInit.PubSubService.Subscribe(CommonData.MemoryQueryParameters, Manager_PubSubService.Get().OnMessageReceived_Internal, (string Message) => { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Error, Message), ServInit.ProgramID, "PubSubService"); }); Controller_AtomicDBOperation.Get().StartTimeoutCheckOperation(WebServiceBaseTimeoutableProcessor.OnTimeoutNotificationReceived); }); InitializerThread.Start(); var InternalCallPrivateKey = ServInit.RequiredEnvironmentVariables["INTERNAL_CALL_PRIVATE_KEY"]; /* * Web-http service initialization */ var WebServiceEndpoints = new List <BWebPrefixStructure>() { new BWebPrefixStructure(new string[] { "/3d/models/internal/pubsub*" }, () => new InternalCalls.PubSub_To_CadFileService(InternalCallPrivateKey, ServInit.DatabaseService, ServInit.FileService, CadFileStorageBucketName, CadProcessServiceEndpoint)), new BWebPrefixStructure(new string[] { "/3d/models/internal/cleanup*" }, () => new InternalCalls.CleanupCall(InternalCallPrivateKey, ServInit.DatabaseService, ServInit.MemoryService)), new BWebPrefixStructure(new string[] { "/3d/models/internal/globally_shared_models*" }, () => new ListGloballySharedModelIds.ForInternal(InternalCallPrivateKey, ServInit.DatabaseService)), new BWebPrefixStructure(new string[] { "/3d/models/internal/check_models_exist*" }, () => new InternalCalls.CheckModelsExist(InternalCallPrivateKey, ServInit.DatabaseService)), new BWebPrefixStructure(new string[] { "/3d/models/get_models_by/user_id/*/metadata_key/*/metadata_values/*" }, () => new GetModelsBy_MetadataKeyValueUserPair(ServInit.DatabaseService, "user_id", "metadata_key", "metadata_values")), new BWebPrefixStructure(new string[] { "/3d/models/get_models_by/user_id/*/metadata_key/*" }, () => new GetModelsBy_MetadataKeyUserPair(ServInit.DatabaseService, "user_id", "metadata_key")), new BWebPrefixStructure(new string[] { "/3d/models/*/revisions/*/unreal/hierarchy_geometry_metadata" }, () => new Model_GetUnrealHierarchyMetadataGeometry(ServInit.FileService, ServInit.DatabaseService, "models", "revisions", CadFileStorageBucketName)), new BWebPrefixStructure(new string[] { "/3d/models/*/revisions/*/unreal/hierarchy_geometry" }, () => new Model_GetUnrealHierarchyGeometry(ServInit.FileService, ServInit.DatabaseService, "models", "revisions", CadFileStorageBucketName)), new BWebPrefixStructure(new string[] { "/3d/models/*/revisions/*/unreal/hierarchy" }, () => new Model_GetUnrealHierarchy(ServInit.FileService, ServInit.DatabaseService, "models", "revisions", CadFileStorageBucketName)), new BWebPrefixStructure(new string[] { "/3d/models/*/revisions/*/unreal/geometry_files/*" }, () => new Model_GetUnrealGeometry(ServInit.FileService, ServInit.DatabaseService, "models", "revisions", "geometry_files", CadFileStorageBucketName)), new BWebPrefixStructure(new string[] { "/3d/models/*/revisions/*/raw" }, () => new Model_GetUpdateDeleteRaw_ForRevision(ServInit.FileService, ServInit.DatabaseService, "models", "revisions", CadFileStorageBucketName, CadProcessServiceEndpoint)), new BWebPrefixStructure(new string[] { "/3d/models/*/revisions/*/hierarchy/nodes/*" }, () => new Model_GetHierarchyNode_ForRevision(ServInit.FileService, ServInit.DatabaseService, "models", "revisions", "nodes", CadFileStorageBucketName)), new BWebPrefixStructure(new string[] { "/3d/models/*/revisions/*/hierarchy" }, () => new Model_GetHierarchyFile_ForRevision(ServInit.FileService, ServInit.DatabaseService, "models", "revisions", CadFileStorageBucketName)), new BWebPrefixStructure(new string[] { "/3d/models/*/revisions/*/geometry/nodes/*" }, () => new Model_GetGeometryNode_ForRevision(ServInit.FileService, ServInit.DatabaseService, "models", "revisions", "nodes", CadFileStorageBucketName)), new BWebPrefixStructure(new string[] { "/3d/models/*/revisions/*/geometry" }, () => new Model_GetGeometryFile_ForRevision(ServInit.FileService, ServInit.DatabaseService, "models", "revisions", CadFileStorageBucketName)), new BWebPrefixStructure(new string[] { "/3d/models/*/revisions/*/metadata/nodes/*" }, () => new Model_GetMetadataNode_ForRevision(ServInit.FileService, ServInit.DatabaseService, "models", "revisions", "keys", CadFileStorageBucketName)), new BWebPrefixStructure(new string[] { "/3d/models/*/revisions/*/metadata" }, () => new Model_GetMetadataFile_ForRevision(ServInit.FileService, ServInit.DatabaseService, "models", "revisions", CadFileStorageBucketName)), new BWebPrefixStructure(new string[] { "/3d/models/*/revisions/*" }, () => new Model_GetUpdateDeleteRevision(ServInit.DatabaseService, "models", "revisions", CadFileStorageBucketName)), new BWebPrefixStructure(new string[] { "/3d/models/*/revisions" }, () => new Model_AddListRevisions(ServInit.DatabaseService, "models")), new BWebPrefixStructure(new string[] { "/3d/models/*/sharing" }, () => new Model_ChangeSharingWithUsers(InternalCallPrivateKey, AuthServiceEndpoint, ServInit.DatabaseService, "models")), new BWebPrefixStructure(new string[] { "/3d/models/*/remove_sharing_from/user_id/*" }, () => new Model_RemoveModelShare(ServInit.DatabaseService, "models", "user_id")), new BWebPrefixStructure(new string[] { "/3d/models/globally_shared" }, () => new ListGloballySharedModelIds.ForUsers(ServInit.DatabaseService)), new BWebPrefixStructure(new string[] { "/3d/models/*" }, () => new Model_GetUpdateDeleteModel(ServInit.DatabaseService, "models")), new BWebPrefixStructure(new string[] { "/3d/models" }, () => new Model_AddListModels(ServInit.DatabaseService)) }; var BWebService = new BWebService(WebServiceEndpoints.ToArray(), ServInit.ServerPort /*, ServInit.TracingService*/); BWebService.Run((string Message) => { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Info, Message), ServInit.ProgramID, "WebService"); }); /* * Make main thread sleep forever */ Thread.Sleep(Timeout.Infinite); }
static int Main() { Console.WriteLine("Initializing the service..."); #if (Debug || DEBUG) if (!ServicesDebugOnlyUtilities.CalledFromMain()) { return(1); } #endif // In case of a cloud component dependency or environment variable is added/removed; // Relative terraform script and microservice-dependency-map.cs must be updated as well. if (!BUtility.GetEnvironmentVariables(out Dictionary <string, string> EnvironmentVariables, new string[][] { new string[] { "PORT" }, new string[] { "PROGRAM_ID" }, new string[] { "API_GATEWAY_SERVICE_BASE_URL" }, new string[] { "STATIC_STATE_BUCKET" }, //Currently set to ignore on local debugging sessions; since it is only used for maintenance check new string[] { "DEPLOYMENT_BRANCH_NAME" }, new string[] { "DEPLOYMENT_BUILD_NUMBER" } }, Console.WriteLine)) { return(1); } Resources_DeploymentManager.Get().SetDeploymentBranchNameAndBuildNumber(EnvironmentVariables["DEPLOYMENT_BRANCH_NAME"], EnvironmentVariables["DEPLOYMENT_BUILD_NUMBER"]); if (!int.TryParse(EnvironmentVariables["PORT"], out int ServerPort)) { Console.WriteLine("Invalid PORT environment variable; it must be an integer."); return(1); } string ApiGatewayServiceEndpoint = EnvironmentVariables["API_GATEWAY_SERVICE_BASE_URL"]; string MaintenanceModeCheckUrl = "https://storage.googleapis.com/" + EnvironmentVariables["STATIC_STATE_BUCKET"] + "/maintenance_mode_" + Resources_DeploymentManager.Get().GetDeploymentBranchName(); var DeploymentLoweredBranchName = Resources_DeploymentManager.Get().GetDeploymentBranchNameEscapedLoweredWithDash(); if (DeploymentLoweredBranchName == "master" || DeploymentLoweredBranchName == "development") { //If the branch is feature, bugfix, hotfix etc. do not check for maintenance. MaintenanceChecker.Get().Start(MaintenanceModeCheckUrl, Console.WriteLine); } /* * Web-http service initialization */ var WebServiceEndpoints = new List <BWebPrefixStructure>() { new BWebPrefixStructure(new string[] { "*" }, () => new PassThroughRequest(ApiGatewayServiceEndpoint)) }; var BWebService = new BWebService(WebServiceEndpoints.ToArray(), ServerPort); BWebService.Run((string Message) => { Console.WriteLine(Message); }); /* * Make main thread sleep forever */ Thread.Sleep(Timeout.Infinite); return(0); }
public static string DBSERVICE_GLOBALLY_SHARED_MODEL_IDS_TABLE() { return("globally-shared-model-ids-" + Resources_DeploymentManager.Get().GetDeploymentBranchNameEscapedLoweredWithDash()); }
public static string DBSERVICE_AUTHMETHODS_TABLE() { return("auth-methods-" + Resources_DeploymentManager.Get().GetDeploymentBranchNameEscapedLoweredWithDash()); }
static void Main() { Console.WriteLine("Initializing the service..."); #if (Debug || DEBUG) if (!ServicesDebugOnlyUtilities.CalledFromMain()) { return; } #endif // In case of a cloud component dependency or environment variable is added/removed; // Relative terraform script and microservice-dependency-map.cs must be updated as well. /* * Common initialization step */ if (!BServiceInitializer.Initialize(out BServiceInitializer ServInit, new string[][] { new string[] { "GOOGLE_CLOUD_PROJECT_ID" }, new string[] { "GOOGLE_APPLICATION_CREDENTIALS", "GOOGLE_PLAIN_CREDENTIALS" }, new string[] { "DEPLOYMENT_BRANCH_NAME" }, new string[] { "DEPLOYMENT_BUILD_NUMBER" }, new string[] { "REDIS_ENDPOINT" }, new string[] { "REDIS_PORT" }, new string[] { "REDIS_PASSWORD" }, new string[] { "SSO_SUPER_ADMINS" }, new string[] { "AZURE_AD_APP_ID" }, new string[] { "AZURE_AD_CLIENT_SECRET" }, new string[] { "AZURE_AD_FETCH_USERS_CLIENT_ID" }, new string[] { "AZURE_AD_FETCH_USERS_CLIENT_SECRET" }, new string[] { "AZURE_AD_FETCH_USERS_APP_OBJECT_ID" }, new string[] { "AZURE_OAUTH2_TOKEN_REQUEST_URL" }, new string[] { "INTERNAL_CALL_PRIVATE_KEY" } })) { return; } bool bInitSuccess = true; bInitSuccess &= ServInit.WithTracingService(); bInitSuccess &= ServInit.WithDatabaseService(); bInitSuccess &= ServInit.WithPubSubService(); bInitSuccess &= ServInit.WithMemoryService(); if (!bInitSuccess) { return; } Resources_DeploymentManager.Get().SetDeploymentBranchNameAndBuildNumber(ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BRANCH_NAME"], ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BUILD_NUMBER"]); Controller_SSOAccessToken.SetLocalServerPort(ServInit.ServerPort); Controller_Rights_Internal.Get().SetLocalServerPort(ServInit.ServerPort); CommonData.MemoryQueryParameters = new BMemoryQueryParameters() { Domain = Resources_DeploymentManager.Get().GetDeploymentBranchNameEscapedLoweredWithDash().ToUpper(), SubDomain = "COMMON_DATA", Identifier = "MEMORY_SERVICE_DATA" }; var InternalCallPrivateKey = ServInit.RequiredEnvironmentVariables["INTERNAL_CALL_PRIVATE_KEY"]; CommonData.INTERNAL_CALL_PRIVATE_KEY = InternalCallPrivateKey; Console.WriteLine(InternalCallPrivateKey); Controller_DeliveryEnsurer.Get().SetDatabaseService(ServInit.DatabaseService); Controller_DeliveryEnsurer.Get().SetServiceIdentifier("auth-service", Actions.EAction.ACTION_AUTH_SERVICE_DELIVERY_ENSURER); Controller_AtomicDBOperation.Get().SetMemoryService(ServInit.MemoryService, CommonData.MemoryQueryParameters); Controller_Rights_Internal.Get().SetMemoryService(ServInit.MemoryService); Manager_PubSubService.Get().Setup(ServInit.PubSubService); var InitializerThread = new Thread(() => { Thread.CurrentThread.IsBackground = true; ServInit.PubSubService.Subscribe(CommonData.MemoryQueryParameters, Manager_PubSubService.Get().OnMessageReceived_Internal, (string Message) => { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Error, Message), ServInit.ProgramID, "PubSubService"); }); Controller_AtomicDBOperation.Get().StartTimeoutCheckOperation(WebServiceBaseTimeoutableProcessor.OnTimeoutNotificationReceived); }); InitializerThread.Start(); var AzureAD_AppID = ServInit.RequiredEnvironmentVariables["AZURE_AD_APP_ID"]; var AzureAD_ClientSecret = ServInit.RequiredEnvironmentVariables["AZURE_AD_CLIENT_SECRET"]; var SSOSuperAdmins = new List <string>(); var SAsJsonString = ServInit.RequiredEnvironmentVariables["SSO_SUPER_ADMINS"]; try { var SAsJArray = JArray.Parse(SAsJsonString); foreach (var SAsToken in SAsJArray) { if (SAsToken.Type == JTokenType.String) { SSOSuperAdmins.Add(((string)SAsToken).ToLower()); } } } catch (Exception) { } var AzureFetchUsersClientID = ServInit.RequiredEnvironmentVariables["AZURE_AD_FETCH_USERS_CLIENT_ID"]; var AzureFetchUsersClientSecret = ServInit.RequiredEnvironmentVariables["AZURE_AD_FETCH_USERS_CLIENT_SECRET"]; var AzureFetchUsersAppObjectID = ServInit.RequiredEnvironmentVariables["AZURE_AD_FETCH_USERS_APP_OBJECT_ID"]; var AzureOAuth2TokenRequestUrl = ServInit.RequiredEnvironmentVariables["AZURE_OAUTH2_TOKEN_REQUEST_URL"]; /* * Web-http service initialization */ var WebServiceEndpoints = new List <BWebPrefixStructure>() { new BWebPrefixStructure(new string[] { "/auth/internal/pubsub*" }, () => new InternalCalls.PubSub_To_AuthService(InternalCallPrivateKey, ServInit.DatabaseService)), new BWebPrefixStructure(new string[] { "/auth/internal/cleanup*" }, () => new InternalCalls.CleanupCall(InternalCallPrivateKey, ServInit.DatabaseService, ServInit.MemoryService)), new BWebPrefixStructure(new string[] { "/auth/internal/fetch_user_ids_from_emails*" }, () => new InternalCalls.FetchUserIDsFromEmailsRequest(InternalCallPrivateKey, ServInit.DatabaseService)), new BWebPrefixStructure(new string[] { "/auth/internal/set*" }, () => new InternalCalls.SetCall(InternalCallPrivateKey, ServInit.MemoryService)), new BWebPrefixStructure(new string[] { "/auth/internal/create_test_user*" }, () => new InternalCalls.CreateTestUser(InternalCallPrivateKey, ServInit.DatabaseService, ServInit.ServerPort)), new BWebPrefixStructure(new string[] { "/auth/internal/delete_test_user*" }, () => new InternalCalls.DeleteTestUser(InternalCallPrivateKey, ServInit.ServerPort)), new BWebPrefixStructure(new string[] { "/auth/internal/synchronize_users_with_azure*" }, () => new InternalCalls.SynchronizeUsersWithAzureAD(InternalCallPrivateKey, AzureOAuth2TokenRequestUrl, AzureFetchUsersClientID, AzureFetchUsersClientSecret, AzureFetchUsersAppObjectID, ServInit.DatabaseService, SSOSuperAdmins)), new BWebPrefixStructure(new string[] { "/auth/login/azure/token_refresh" }, () => new SSOAzureTokenRefreshRequest(ServInit.DatabaseService, ServInit.MemoryService, AzureAD_AppID, AzureAD_ClientSecret, SSOSuperAdmins) /*For token refresh requests via Azure AD SSO Service*/), new BWebPrefixStructure(new string[] { "/auth/login/azure/*" }, () => new SSOAzureLoginCallback(ServInit.DatabaseService, ServInit.MemoryService, AzureAD_AppID, AzureAD_ClientSecret, SSOSuperAdmins) /*For auto-redirect from Azure AD SSO Service*/), new BWebPrefixStructure(new string[] { "/auth/login/azure*" }, () => new SSOAzureLoginRequest(ServInit.DatabaseService, ServInit.MemoryService, AzureAD_AppID, AzureAD_ClientSecret, SSOSuperAdmins) /*For login request via Azure AD SSO Service*/), new BWebPrefixStructure(new string[] { "/auth/login" }, () => new LoginRequest(ServInit.DatabaseService, ServInit.MemoryService)), new BWebPrefixStructure(new string[] { "/auth/access_check" }, () => new AccessCheckRequest(ServInit.DatabaseService, ServInit.MemoryService, AzureAD_AppID, AzureAD_ClientSecret, SSOSuperAdmins)), new BWebPrefixStructure(new string[] { "/auth/list_registered_email_addresses" }, () => new ListRegisteredUserEmails(ServInit.DatabaseService)), new BWebPrefixStructure(new string[] { "/auth/users/*/access_methods/*" }, () => new User_DeleteUserAccessMethod_ForUser(ServInit.DatabaseService, ServInit.MemoryService, "users", "access_methods")), new BWebPrefixStructure(new string[] { "/auth/users/*/access_methods" }, () => new User_CreateListAccessMethods_ForUser(ServInit.DatabaseService, ServInit.MemoryService, "users")), new BWebPrefixStructure(new string[] { "/auth/users/*/base_access_rights/*" }, () => new User_UpdateDeleteBaseRight_ForUser(ServInit.DatabaseService, ServInit.MemoryService, "users", "base_access_rights")), new BWebPrefixStructure(new string[] { "/auth/users/*/base_access_rights" }, () => new User_AddListBaseRights_ForUser(ServInit.DatabaseService, ServInit.MemoryService, "users")), new BWebPrefixStructure(new string[] { "/auth/users/*" }, () => new User_GetUpdateDeleteUser(ServInit.DatabaseService, ServInit.MemoryService, "users")), new BWebPrefixStructure(new string[] { "/auth/users" }, () => new User_CreateListUsers(ServInit.DatabaseService)) }; var BWebService = new BWebService(WebServiceEndpoints.ToArray(), ServInit.ServerPort, ServInit.TracingService); BWebService.Run((string Message) => { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Info, Message), ServInit.ProgramID, "WebService"); }); var ApiPassThroughEndpoint = Environment.GetEnvironmentVariable("API_PASSTHROUGH_ENDPOINT"); if (ApiPassThroughEndpoint != null) { //Needed by MicroserviceLocalRunner new InternalCalls.SetCall(InternalCallPrivateKey, ServInit.MemoryService).Process_SetApiPassthroughPublicEndpoint( (string Message) => { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Error, Message), ServInit.ProgramID, "WebService"); }, ApiPassThroughEndpoint); } var CadFileServiceEndpoint = Environment.GetEnvironmentVariable("CAD_FILE_SERVICE_ENDPOINT"); if (CadFileServiceEndpoint != null) { //Needed by MicroserviceLocalRunner new InternalCalls.SetCall(InternalCallPrivateKey, ServInit.MemoryService).Process_SetCADFileServicePublicEndpoint( (string Message) => { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Error, Message), ServInit.ProgramID, "WebService"); }, CadFileServiceEndpoint); } /* * Make main thread sleep forever */ Thread.Sleep(Timeout.Infinite); }
static void Main(string[] args) { Console.WriteLine("Initializing the service..."); // In case of a cloud component dependency or environment variable is added/removed; /* * Common initialization step */ if (!BServiceInitializer.Initialize(out BServiceInitializer ServInit, new string[][] { new string[] { "GOOGLE_CLOUD_PROJECT_ID" }, new string[] { "GOOGLE_APPLICATION_CREDENTIALS", "GOOGLE_PLAIN_CREDENTIALS" }, new string[] { "DEPLOYMENT_BRANCH_NAME" }, new string[] { "DEPLOYMENT_BUILD_NUMBER" }, new string[] { "REDIS_ENDPOINT" }, new string[] { "REDIS_PORT" }, new string[] { "REDIS_PASSWORD" }, new string[] { "UPLOAD_HIERARCHY_CF" }, new string[] { "UPLOAD_HIERARCHY_RAF" }, new string[] { "UPLOAD_GEOMETRY_CF" }, new string[] { "UPLOAD_GEOMETRY_RAF" }, new string[] { "UPLOAD_METADATA_CF" }, new string[] { "UPLOAD_METADATA_RAF" }, new string[] { "IS_FILE_WRITE" }, new string[] { "CAD_PROCESS_NOTIFY_URL" } })) { return; } bool IsFileWrite = bool.Parse(ServInit.RequiredEnvironmentVariables["IS_FILE_WRITE"]); bool bInitSuccess = true; if (!IsFileWrite) { bInitSuccess &= ServInit.WithFileService(); bInitSuccess &= ServInit.WithTracingService(); } //Wait for redis int RetryCount = 0; while (true) { try { bInitSuccess &= ServInit.WithMemoryService(true, new BPubSubServiceRedis(ServInit.RequiredEnvironmentVariables["REDIS_ENDPOINT"], int.Parse(ServInit.RequiredEnvironmentVariables["REDIS_PORT"]), ServInit.RequiredEnvironmentVariables["REDIS_PASSWORD"])); break; } catch (Exception ex) { RetryCount++; Thread.Sleep(1000); if (RetryCount >= 30) { break; } } } if (!bInitSuccess) { return; } if (!BatchProcessingService.Initialize(ServInit.MemoryService)) { //Exit with an error code so that health checker can pick up on it and take action Environment.Exit(1); } BatchProcessingService.Instance.SetUploadUrls( ServInit.RequiredEnvironmentVariables["UPLOAD_HIERARCHY_CF"], ServInit.RequiredEnvironmentVariables["UPLOAD_HIERARCHY_RAF"], ServInit.RequiredEnvironmentVariables["UPLOAD_METADATA_CF"], ServInit.RequiredEnvironmentVariables["UPLOAD_METADATA_RAF"], ServInit.RequiredEnvironmentVariables["UPLOAD_GEOMETRY_CF"], ServInit.RequiredEnvironmentVariables["UPLOAD_GEOMETRY_RAF"], ServInit.RequiredEnvironmentVariables["CAD_PROCESS_NOTIFY_URL"], IsFileWrite); BatchProcessingService.Instance.RunResetProcessLoop((Message) => { Console.WriteLine(Message); }); //if (!IsFileWrite) //{ Resources_DeploymentManager.Get().SetDeploymentBranchNameAndBuildNumber(ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BRANCH_NAME"], ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BUILD_NUMBER"]); var WebServiceEndpoints = new List <BWebPrefixStructure>() { new BWebPrefixStructure(new string[] { "/healthcheck" }, () => new HealthCheckRequest()), new BWebPrefixStructure(new string[] { "/endprocess" }, () => new CheckProcessCompleteRequest()) }; var BWebService = new BWebService(WebServiceEndpoints.ToArray(), ServInit.ServerPort, ServInit.TracingService); BWebService.Run((string Message) => { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Info, Message), ServInit.ProgramID, "WebService"); }); //} Thread.Sleep(Timeout.Infinite); }
public static string DBSERVICE_SCHEDULED_URL_TASKS_TABLE() { return("scheduled-url-tasks-" + Resources_DeploymentManager.Get().GetDeploymentBranchNameEscapedLoweredWithDash()); }
static void Main() { Console.WriteLine("Initializing the service..."); #if (Debug || DEBUG) if (!ServicesDebugOnlyUtilities.CalledFromMain()) { return; } #endif // In case of a cloud component dependency or environment variable is added/removed; /* * Common initialization step */ if (!BServiceInitializer.Initialize(out BServiceInitializer ServInit, new string[][] { new string[] { "GOOGLE_CLOUD_PROJECT_ID" }, new string[] { "GOOGLE_APPLICATION_CREDENTIALS", "GOOGLE_PLAIN_CREDENTIALS" }, new string[] { "DEPLOYMENT_BRANCH_NAME" }, new string[] { "DEPLOYMENT_BUILD_NUMBER" }, new string[] { "REDIS_ENDPOINT" }, new string[] { "REDIS_PORT" }, new string[] { "REDIS_PASSWORD" }, new string[] { "CAD_PROCESS_SERVICE_NAME" }, new string[] { "CAD_PROCESS_POD_NAME" }, new string[] { "CAD_PROCESS_PORT" }, new string[] { "CLUSTER_MASTER_ENDPOINT" }, new string[] { "CLUSTER_CLIENT_KEY" }, new string[] { "CLUSTER_CLIENT_CERTIFICATE" }, new string[] { "CAD_READER_IMAGE" }, new string[] { "FILE_WORKER_IMAGE" }, new string[] { "FILE_OPTIMIZER_IMAGE" }, new string[] { "FILE_OPTIMIZER_ENVIRONMENT_VARIABLES" } })) { return; } bool bInitSuccess = true; bInitSuccess &= ServInit.WithDatabaseService(); bInitSuccess &= ServInit.WithFileService(); bInitSuccess &= ServInit.WithTracingService(); bInitSuccess &= ServInit.WithPubSubService(); bInitSuccess &= ServInit.WithMemoryService(); if (!bInitSuccess) { return; } Resources_DeploymentManager.Get().SetDeploymentBranchNameAndBuildNumber(ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BRANCH_NAME"], ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BUILD_NUMBER"]); Manager_PubSubService.Get().Setup(ServInit.PubSubService); try { //Initialize kubernetes client credentials and init pixyz processing classes KubernetesClientManager.SetDefaultCredentials(ServInit.RequiredEnvironmentVariables["CLUSTER_MASTER_ENDPOINT"], ServInit.RequiredEnvironmentVariables["CLUSTER_CLIENT_KEY"], ServInit.RequiredEnvironmentVariables["CLUSTER_CLIENT_CERTIFICATE"]); K8sObjectManager.SetImageNames(ServInit.RequiredEnvironmentVariables["FILE_WORKER_IMAGE"], ServInit.RequiredEnvironmentVariables["CAD_READER_IMAGE"], ServInit.RequiredEnvironmentVariables["FILE_OPTIMIZER_IMAGE"]); if (!BatchProcessingStateService.Initialize(ServInit.MemoryService, (string Message) => { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Info, Message), ServInit.ProgramID, "WebService"); })) { return; } // Pass CadProcessService environment variables to FileOptimizer like Google, Azure, AWS Credentials etc. // For example: ['GOOGLE_CLOUD_PROJECT_ID', 'GOOGLE_PLAIN_CREDENTIALS'] var FileOptimizerEnvironmentVariables = new Dictionary <string, string>(); try { var FileOptimizerEnvVarsArray = JArray.Parse(ServInit.RequiredEnvironmentVariables["FILE_OPTIMIZER_ENVIRONMENT_VARIABLES"]); foreach (var item in FileOptimizerEnvVarsArray) { if (item.Type == JTokenType.String) { var key = (string)item; if (ServInit.RequiredEnvironmentVariables.ContainsKey(key)) { FileOptimizerEnvironmentVariables.Add(key, ServInit.RequiredEnvironmentVariables[key]); } } } } catch (Exception) { } BatchProcessingCreationService.Initialize( ServInit.DatabaseService, ServInit.FileService, ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BRANCH_NAME"], ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BUILD_NUMBER"], ServInit.RequiredEnvironmentVariables["CAD_PROCESS_SERVICE_NAME"], FileOptimizerEnvironmentVariables, () => { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Info, "Failed to initialize batch process. Exiting..."), ServInit.ProgramID, "WebService"); Environment.Exit(1); }, (string Message) => { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Info, Message), ServInit.ProgramID, "WebService"); }); } catch (Exception ex) { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Info, $"{ex.Message}\n{ ex.StackTrace}"), ServInit.ProgramID, "WebService"); return; } /* * Web-http service initialization */ var WebServiceEndpoints = new List <BWebPrefixStructure>() { new BWebPrefixStructure(new string[] { "/3d/process/start" }, () => new StartProcessRequest(ServInit.DatabaseService)), new BWebPrefixStructure(new string[] { "/3d/process/stop" }, () => new StopProcessRequest(ServInit.DatabaseService, ServInit.FileService)), new BWebPrefixStructure(new string[] { "/3d/process/internal/job-complete/*" }, () => new BatchJobCompleteRequest(ServInit.DatabaseService, ServInit.FileService, ServInit.MemoryService)), new BWebPrefixStructure(new string[] { "/3d/process/internal/get_signed_upload_url_for_unreal_file/*" }, () => new GetSignedUploadUrlRequest(ServInit.FileService)), new BWebPrefixStructure(new string[] { "/3d/process/internal/get_file_optimizer_parameters/*" }, () => new GetOptimizerParametersRequest(ServInit.DatabaseService)) }; var BWebService = new BWebService(WebServiceEndpoints.ToArray(), ServInit.ServerPort /*, ServInit.TracingService*/); BWebService.Run((string Message) => { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Info, Message), ServInit.ProgramID, "WebService"); }); /* * Make main thread sleep forever */ Thread.Sleep(Timeout.Infinite); }
private BWebServiceResponse OnRequest_Internal(HttpListenerContext _Context, Action <string> _ErrorMessageAction = null) { if (_Context.Request.HttpMethod != "POST") { _ErrorMessageAction?.Invoke("LoginRequest: POST method is accepted. But received request method: " + _Context.Request.HttpMethod); return(BWebResponse.MethodNotAllowed("POST method is accepted. But received request method: " + _Context.Request.HttpMethod)); } JObject ParsedBody; using (var InputStream = _Context.Request.InputStream) { using (var ResponseReader = new StreamReader(InputStream)) { try { ParsedBody = JObject.Parse(ResponseReader.ReadToEnd()); } catch (Exception e) { _ErrorMessageAction?.Invoke("LoginRequest-> Read request body stage has failed. Exception: " + e.Message + ", Trace: " + e.StackTrace); return(BWebResponse.BadRequest("Malformed request body. Request must be a valid json form.")); } } } if (!ParsedBody.ContainsKey(AuthMethod.API_KEY_PROPERTY) && ((!ParsedBody.ContainsKey(AuthMethod.USER_NAME_PROPERTY) && !ParsedBody.ContainsKey(AuthMethod.USER_EMAIL_PROPERTY)) || !ParsedBody.ContainsKey(AuthMethod.PASSWORD_MD5_PROPERTY))) { _ErrorMessageAction?.Invoke("LoginRequest-> Request does not have required fields."); return(BWebResponse.BadRequest("Request does not have required fields.")); } string Method; if (ParsedBody.ContainsKey(AuthMethod.API_KEY_PROPERTY)) { var ApiKey = (string)ParsedBody[AuthMethod.API_KEY_PROPERTY]; Method = ApiKey; } else { var PasswordMD5 = ((string)ParsedBody[AuthMethod.PASSWORD_MD5_PROPERTY]).ToLower(); if (ParsedBody.ContainsKey(UserDBEntry.USER_NAME_PROPERTY)) { Method = (string)ParsedBody[UserDBEntry.USER_NAME_PROPERTY] + PasswordMD5; } else { Method = ((string)ParsedBody[UserDBEntry.USER_EMAIL_PROPERTY]).ToLower() + PasswordMD5; } } if (!AuthenticationCommon.FetchUserInfoFromMemoryService_ByMethod(MemoryService, Method, out string UserID, out string _, out string _, _ErrorMessageAction)) { if (!AuthenticationCommon.FetchUserInfoFromDatabaseService_ByMethod(DatabaseService, MemoryService, Method, out UserID, out _, out _, out BWebServiceResponse FailureResponse, _ErrorMessageAction)) { return(FailureResponse); } } if (!BUtility.CalculateStringMD5(BUtility.RandomString(32, true), out string AccessTokenMD5, _ErrorMessageAction)) { return(BWebResponse.InternalError("Hash operation failed.")); } var AccessTokenMD5WithTokenType = "Basic " + AccessTokenMD5; var QueryParameters = new BMemoryQueryParameters() { Domain = Resources_DeploymentManager.Get().GetDeploymentBranchNameEscapedLoweredWithDash().ToUpper(), SubDomain = "SELF_SIGNED_ACCESS_TOKEN_VALIDATION", Identifier = AccessTokenMD5WithTokenType }; MemoryService.SetKeyValue(QueryParameters, new Tuple <string, BPrimitiveType>[] { new Tuple <string, BPrimitiveType>("method", new BPrimitiveType(Method)) }, _ErrorMessageAction); MemoryService.SetKeyExpireTime(QueryParameters, TimeSpan.FromHours(1), _ErrorMessageAction); return(BWebResponse.StatusOK("Login successful.", new JObject() { ["userId"] = UserID, ["token"] = AccessTokenMD5WithTokenType })); }
static void Main() { System.Console.WriteLine("Initializing the service..."); #if (Debug || DEBUG) if (!ServicesDebugOnlyUtilities.CalledFromMain()) { return; } #endif // In case of a cloud component dependency or environment variable is added/removed; // Relative terraform script and microservice-dependency-map.cs must be updated as well. /* * Common initialization step */ if (!BServiceInitializer.Initialize(out BServiceInitializer ServInit, new string[][] { new string[] { "GOOGLE_CLOUD_PROJECT_ID" }, new string[] { "GOOGLE_APPLICATION_CREDENTIALS", "GOOGLE_PLAIN_CREDENTIALS" }, new string[] { "DEPLOYMENT_BRANCH_NAME" }, new string[] { "DEPLOYMENT_BUILD_NUMBER" }, new string[] { "AUTH_SERVICE_BASE_URL" }, new string[] { "CAD_FILE_SERVICE_BASE_URL" }, new string[] { "CUSTOM_PROCEDURES_SERVICE_BASE_URL" }, new string[] { "SCHEDULER_SERVICE_BASE_URL" } })) { return; } bool bInitSuccess = true; bInitSuccess &= ServInit.WithTracingService(); if (!bInitSuccess) { return; } Resources_DeploymentManager.Get().SetDeploymentBranchNameAndBuildNumber(ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BRANCH_NAME"], ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BUILD_NUMBER"]); /* * Web-http service initialization */ var AuthServiceBaseUrl = ServInit.RequiredEnvironmentVariables["AUTH_SERVICE_BASE_URL"]; var CadFileServiceBaseUrl = ServInit.RequiredEnvironmentVariables["CAD_FILE_SERVICE_BASE_URL"]; var CustomProceduresServiceBaseUrl = ServInit.RequiredEnvironmentVariables["CUSTOM_PROCEDURES_SERVICE_BASE_URL"]; var SchedulerServiceBaseUrl = ServInit.RequiredEnvironmentVariables["SCHEDULER_SERVICE_BASE_URL"]; var WebServiceEndpoints = new List <BWebPrefixStructure>() { new BWebPrefixStructure(new string[] { "/auth/ping" }, () => new HandleRequest(AuthServiceBaseUrl) /*Ping-pong; for avoiding scale-down-to-zero*/), new BWebPrefixStructure(new string[] { "/auth/internal/*" }, () => new HandleRequest(AuthServiceBaseUrl) /*Internal services have secret based auth check, different than login mechanism*/), new BWebPrefixStructure(new string[] { "/auth/login*" }, () => new HandleRequest(AuthServiceBaseUrl) /*For login requests*/), new BWebPrefixStructure(new string[] { "/auth/*" }, () => new HandleRequest(AuthServiceBaseUrl).WithLoginRequirement(AuthServiceBaseUrl) /*Required from external*/), new BWebPrefixStructure(new string[] { "/3d/models/ping" }, () => new HandleRequest(CadFileServiceBaseUrl) /*Ping-pong; for avoiding scale-down-to-zero*/), new BWebPrefixStructure(new string[] { "/3d/models/internal/*" }, () => new HandleRequest(CadFileServiceBaseUrl) /*Internal services have secret based auth check, different than login mechanism*/), new BWebPrefixStructure(new string[] { "/3d/models*" }, () => new HandleRequest(CadFileServiceBaseUrl).WithLoginRequirement(AuthServiceBaseUrl)), new BWebPrefixStructure(new string[] { "/scheduler/internal/*" }, () => new HandleRequest(SchedulerServiceBaseUrl) /*Internal services have secret based auth check, different than login mechanism*/), }; var BWebService = new BWebService(WebServiceEndpoints.ToArray(), ServInit.ServerPort, ServInit.TracingService); BWebService.Run((string Message) => { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Info, Message), ServInit.ProgramID, "WebService"); }); /* * Make main thread sleep forever */ Thread.Sleep(Timeout.Infinite); }
static void Main() { Console.WriteLine("Initializing the service..."); #if (Debug || DEBUG) if (!ServicesDebugOnlyUtilities.CalledFromMain()) { return; } #endif // In case of a cloud component dependency or environment variable is added/removed; // Relative terraform script and microservice-dependency-map.cs must be updated as well. /* * Common initialization step */ if (!BServiceInitializer.Initialize(out BServiceInitializer ServInit, new string[][] { new string[] { "GOOGLE_CLOUD_PROJECT_ID" }, new string[] { "GOOGLE_APPLICATION_CREDENTIALS", "GOOGLE_PLAIN_CREDENTIALS" }, new string[] { "DEPLOYMENT_BRANCH_NAME" }, new string[] { "DEPLOYMENT_BUILD_NUMBER" }, new string[] { "INTERNAL_CALL_PRIVATE_KEY" } })) { return; } bool bInitSuccess = true; bInitSuccess &= ServInit.WithTracingService(); bInitSuccess &= ServInit.WithDatabaseService(); if (!bInitSuccess) { return; } Resources_DeploymentManager.Get().SetDeploymentBranchNameAndBuildNumber(ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BRANCH_NAME"], ServInit.RequiredEnvironmentVariables["DEPLOYMENT_BUILD_NUMBER"]); string InternalPrivateKey = ServInit.RequiredEnvironmentVariables["INTERNAL_CALL_PRIVATE_KEY"]; Console.WriteLine(InternalPrivateKey); /* * Web-http service initialization */ var WebServiceEndpoints = new List <BWebPrefixStructure>() { new BWebPrefixStructure(new string[] { "/scheduler/internal/schedule*" }, () => new ScheduleRequest(InternalPrivateKey, ServInit.DatabaseService)), new BWebPrefixStructure(new string[] { "/scheduler/internal/unschedule*" }, () => new UnscheduleRequest(InternalPrivateKey, ServInit.DatabaseService)), new BWebPrefixStructure(new string[] { "/scheduler/internal/on_minute_call*" }, () => new OnMinuteCallRequest(InternalPrivateKey, ServInit.DatabaseService)) }; var BWebService = new BWebService(WebServiceEndpoints.ToArray(), ServInit.ServerPort, ServInit.TracingService); BWebService.Run((string Message) => { ServInit.LoggingService.WriteLogs(BLoggingServiceMessageUtility.Single(EBLoggingServiceLogType.Info, Message), ServInit.ProgramID, "WebService"); }); /* * Make main thread sleep forever */ Thread.Sleep(Timeout.Infinite); }