Skip to content

Commit

Permalink
Make Exosphere configurable (at runtime) to pass all requests to Open…
Browse files Browse the repository at this point in the history
…Stack through proxy server
  • Loading branch information
c-mart committed May 31, 2019
1 parent 617083c commit 6b49d37
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 112 deletions.
3 changes: 2 additions & 1 deletion ports.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ var app = Elm.Main.init({
{
width: window.innerWidth,
height: window.innerHeight,
storedState: startingState
storedState: startingState,
proxyUrl: null
}
});

Expand Down
8 changes: 5 additions & 3 deletions src/OpenStack/ServerActions.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Json.Encode
import OpenStack.Types as OSTypes
import Rest.Helpers exposing (openstackCredentialedRequest)
import Rest.Rest as Rest
import Types.HelperTypes as HelperTypes
import Types.Types exposing (..)


Expand All @@ -16,7 +17,7 @@ type alias ServerAction =

-- Todo enforce uniqueness by using a different collection (something like a Set, except ServerAction types aren't "comparable")
, allowedStatus : List OSTypes.ServerStatus
, action : Project -> Server -> Cmd Msg
, action : Project -> Maybe HelperTypes.Url -> Server -> Cmd Msg
, selectMods : List Modifier.Modifier
, targetStatus : List OSTypes.ServerStatus
}
Expand Down Expand Up @@ -139,10 +140,11 @@ actions =
]


doAction : Json.Encode.Value -> Project -> Server -> Cmd Msg
doAction body project server =
doAction : Json.Encode.Value -> Project -> Maybe HelperTypes.Url -> Server -> Cmd Msg
doAction body project maybeProxyUrl server =
openstackCredentialedRequest
project
maybeProxyUrl
Post
(project.endpoints.nova ++ "/servers/" ++ server.osProps.uuid ++ "/action")
(Http.jsonBody body)
Expand Down
11 changes: 7 additions & 4 deletions src/OpenStack/ServerVolumes.elm
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import Json.Decode as Decode
import Json.Encode
import OpenStack.Types as OSTypes
import Rest.Helpers exposing (openstackCredentialedRequest)
import Types.HelperTypes as HelperTypes
import Types.Types exposing (..)


requestAttachVolume : Project -> OSTypes.ServerUuid -> OSTypes.VolumeUuid -> Cmd Msg
requestAttachVolume project serverUuid volumeUuid =
requestAttachVolume : Project -> Maybe HelperTypes.Url -> OSTypes.ServerUuid -> OSTypes.VolumeUuid -> Cmd Msg
requestAttachVolume project maybeProxyUrl serverUuid volumeUuid =
let
body =
Json.Encode.object
Expand All @@ -23,16 +24,18 @@ requestAttachVolume project serverUuid volumeUuid =
in
openstackCredentialedRequest
project
maybeProxyUrl
Post
(project.endpoints.nova ++ "/servers/" ++ serverUuid ++ "/os-volume_attachments")
(Http.jsonBody body)
(Http.expectJson (\result -> ProjectMsg (Helpers.getProjectId project) (ReceiveAttachVolume result)) (Decode.field "volumeAttachment" <| novaVolumeAttachmentDecoder))


requestDetachVolume : Project -> OSTypes.ServerUuid -> OSTypes.VolumeUuid -> Cmd Msg
requestDetachVolume project serverUuid volumeUuid =
requestDetachVolume : Project -> Maybe HelperTypes.Url -> OSTypes.ServerUuid -> OSTypes.VolumeUuid -> Cmd Msg
requestDetachVolume project maybeProxyUrl serverUuid volumeUuid =
openstackCredentialedRequest
project
maybeProxyUrl
Delete
(project.endpoints.nova ++ "/servers/" ++ serverUuid ++ "/os-volume_attachments/" ++ volumeUuid)
Http.emptyBody
Expand Down
16 changes: 10 additions & 6 deletions src/OpenStack/Volumes.elm
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import Json.Encode
import OpenStack.Types as OSTypes
import RemoteData
import Rest.Helpers exposing (openstackCredentialedRequest)
import Types.HelperTypes as HelperTypes
import Types.Types exposing (..)


requestCreateVolume : Project -> OSTypes.CreateVolumeRequest -> Cmd Msg
requestCreateVolume project createVolumeRequest =
requestCreateVolume : Project -> Maybe HelperTypes.Url -> OSTypes.CreateVolumeRequest -> Cmd Msg
requestCreateVolume project maybeProxyUrl createVolumeRequest =
let
body =
Json.Encode.object
Expand All @@ -30,26 +31,29 @@ requestCreateVolume project createVolumeRequest =
in
openstackCredentialedRequest
project
maybeProxyUrl
Post
(project.endpoints.cinder ++ "/volumes")
(Http.jsonBody body)
(Http.expectJson (\result -> ProjectMsg (Helpers.getProjectId project) (ReceiveCreateVolume result)) (Decode.field "volume" <| volumeDecoder))


requestVolumes : Project -> Cmd Msg
requestVolumes project =
requestVolumes : Project -> Maybe HelperTypes.Url -> Cmd Msg
requestVolumes project maybeProxyUrl =
openstackCredentialedRequest
project
maybeProxyUrl
Get
(project.endpoints.cinder ++ "/volumes/detail")
Http.emptyBody
(Http.expectJson (\result -> ProjectMsg (Helpers.getProjectId project) (ReceiveVolumes result)) (Decode.field "volumes" (Decode.list volumeDecoder)))


requestDeleteVolume : Project -> OSTypes.VolumeUuid -> Cmd Msg
requestDeleteVolume project volumeUuid =
requestDeleteVolume : Project -> Maybe HelperTypes.Url -> OSTypes.VolumeUuid -> Cmd Msg
requestDeleteVolume project maybeProxyUrl volumeUuid =
openstackCredentialedRequest
project
maybeProxyUrl
Delete
(project.endpoints.cinder ++ "/volumes/" ++ volumeUuid)
Http.emptyBody
Expand Down
17 changes: 11 additions & 6 deletions src/Rest/Helpers.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Http
import OpenStack.Types as OSTypes
import Task
import Time
import Types.HelperTypes as HelperTypes
import Types.Types as TT
import Url

Expand All @@ -22,8 +23,8 @@ httpRequestMethodStr method =
"DELETE"


openstackCredentialedRequest : TT.Project -> TT.HttpRequestMethod -> String -> Http.Body -> Http.Expect TT.Msg -> Cmd TT.Msg
openstackCredentialedRequest project method url requestBody expect =
openstackCredentialedRequest : TT.Project -> Maybe HelperTypes.Url -> TT.HttpRequestMethod -> String -> Http.Body -> Http.Expect TT.Msg -> Cmd TT.Msg
openstackCredentialedRequest project maybeProxyUrl method origUrl requestBody expect =
{-
In order to ensure request is made with a valid token, perform a task
which checks the time to see if our auth token is still valid or has
Expand All @@ -32,16 +33,20 @@ openstackCredentialedRequest project method url requestBody expect =
-}
let
( proxyUrl, headers ) =
-- TODO don't hard-code proxy server URL, specify it in global defaults or something
proxyifyRequest "https://dogfood.exosphere.app/proxy" url
( url, headers ) =
case maybeProxyUrl of
Just proxyUrl ->
proxyifyRequest proxyUrl origUrl

Nothing ->
( origUrl, [] )

tokenToRequestCmd : OSTypes.AuthTokenString -> Cmd TT.Msg
tokenToRequestCmd token =
Http.request
{ method = httpRequestMethodStr method
, headers = [ Http.header "X-Auth-Token" token ] ++ headers
, url = proxyUrl
, url = url
, body = requestBody
, expect = expect
, timeout = Nothing
Expand Down
Loading

0 comments on commit 6b49d37

Please sign in to comment.