Refactor Atlantis server
This commit is contained in:
@@ -1,33 +1,35 @@
|
||||
module Main
|
||||
|
||||
open System
|
||||
open System.Text.Json
|
||||
open System.Text.Json.Serialization
|
||||
open System.Net.Http
|
||||
|
||||
open Microsoft.AspNetCore.Authentication
|
||||
open Microsoft.AspNetCore.Builder
|
||||
open Microsoft.AspNetCore.Cors.Infrastructure
|
||||
open Microsoft.AspNetCore.Hosting
|
||||
open Microsoft.AspNetCore.Http
|
||||
open Microsoft.AspNetCore.SignalR
|
||||
open Microsoft.Extensions.DependencyInjection
|
||||
open Microsoft.Extensions.FileProviders
|
||||
open Microsoft.Extensions.Hosting
|
||||
open Microsoft.Extensions.Logging
|
||||
|
||||
open Argu
|
||||
open Dapr.Actors
|
||||
open Dapr.Actors.Client
|
||||
open Dapr.Client
|
||||
open FSharp.Data
|
||||
open FsToolkit.ErrorHandling
|
||||
open Fable.SignalR
|
||||
open Giraffe
|
||||
open Microsoft.AspNetCore.Authentication
|
||||
open Microsoft.AspNetCore.Builder
|
||||
open Microsoft.AspNetCore.Hosting
|
||||
open Microsoft.AspNetCore.Cors.Infrastructure
|
||||
open Microsoft.AspNetCore.Http
|
||||
open Microsoft.AspNetCore.SignalR
|
||||
open Microsoft.Extensions.DependencyInjection
|
||||
open Microsoft.Extensions.Logging
|
||||
open Microsoft.Extensions.FileProviders
|
||||
open Microsoft.Extensions.Hosting
|
||||
open System.Net.Http
|
||||
open Oceanbox.DataAgent
|
||||
open Polly
|
||||
open Prometheus
|
||||
open Saturn
|
||||
open Saturn.Dapr
|
||||
open Saturn.OpenTelemetry
|
||||
open Saturn.Observer
|
||||
open Saturn.OpenTelemetry
|
||||
open Sentry
|
||||
open Sentry.AspNetCore
|
||||
open Sentry.Extensibility
|
||||
@@ -37,6 +39,7 @@ open Serilog.Sinks.OpenTelemetry
|
||||
|
||||
open Atlantis
|
||||
open Atlantis.Shared
|
||||
open Oceanbox.DataAgent
|
||||
open Oceanbox.ServerPack.MultiAuth
|
||||
open Saturn.OpenFga
|
||||
open Settings
|
||||
@@ -82,7 +85,8 @@ let configureSerilog () =
|
||||
let configureLogging (builder: ILoggingBuilder) =
|
||||
builder
|
||||
.ClearProviders()
|
||||
.AddSerilog() |> ignore
|
||||
.AddSerilog()
|
||||
|> ignore
|
||||
|
||||
let corsPolicy (policy: CorsPolicyBuilder) =
|
||||
policy
|
||||
@@ -91,7 +95,7 @@ let corsPolicy (policy: CorsPolicyBuilder) =
|
||||
.AllowAnyMethod()
|
||||
.WithOrigins(appsettings.file.allowedOrigins)
|
||||
.SetIsOriginAllowedToAllowWildcardSubdomains()
|
||||
|> ignore
|
||||
|> ignore
|
||||
|
||||
type UserIdProvider() =
|
||||
interface IUserIdProvider with
|
||||
@@ -254,12 +258,12 @@ let stopImpersonating (next: HttpFunc) (ctx: HttpContext) =
|
||||
let getBarentsWatchToken (next: HttpFunc) (ctx: HttpContext) =
|
||||
task {
|
||||
let! tokenRes =
|
||||
tryGetEnv "BARENTSWATCH_CLIENT_ID"
|
||||
|> Option.bind (fun id ->
|
||||
tryGetEnv "BARENTSWATCH_SECRET"
|
||||
|> Option.map (BarentsWatch.getToken appsettings.redis id))
|
||||
|> Option.defaultValue (Error "Secret or client id missing" |> async.Return)
|
||||
|> Async.StartAsTask
|
||||
taskResult {
|
||||
let! id = tryGetEnv "BARENTSWATCH_CLIENT_ID" |> Result.requireSome "Missing barentswatch client id"
|
||||
let! secret = tryGetEnv "BARENTSWATCH_SECRET" |> Result.requireSome "Missing barentswatch secret"
|
||||
let! token = BarentsWatch.getToken appsettings.redis id secret
|
||||
return token
|
||||
}
|
||||
|
||||
match tokenRes with
|
||||
| Error err ->
|
||||
|
||||
Reference in New Issue
Block a user