-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introducing Client::Connect as a top-level entry point for producing
a Session.
- Loading branch information
Showing
7 changed files
with
112 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module Trailblazer | ||
module Pro | ||
# Provides a valid JWT to authenticate against the PRO API. | ||
# | ||
# We always require an input {:session} and output a {:session}. | ||
# Internally, {Signin} and {Refresh} don't know about session, only kwargs. | ||
module Client | ||
module_function | ||
# session_initialized? --> <> --> valid? --> <> -----------------------------------> (o) | ||
# | | --> Refresh --V ^ | ||
# | --> Signin ---------------------> rebuild_session --> | | ||
# | ||
class Connect < Trailblazer::Activity::Railway | ||
step :session_signedin?, | ||
Output(:failure) => Path(track_color: :signin, connect_to: Track(:rebuild)) do # FIXME: move to after {valid?} | ||
# Signin only consumes {:api_key} and friends and doesn't know about {:session}. | ||
step Subprocess(Signin), | ||
In() => :session_to_args#, | ||
# Out() => Trace::Signin::SESSION_VARIABLE_NAMES | ||
end | ||
|
||
step Client.method(:valid?), In() => :session_to_args, Inject() => [:now], | ||
Output(:failure) => Path(track_color: :refresh, connect_to: Track(:rebuild)) do | ||
step Subprocess(Refresh), In() => :session_to_args | ||
end | ||
|
||
step :rebuild_session, magnetic_to: :rebuild # TODO: assert that success/failure go to right Track. | ||
|
||
def session_signedin?(ctx, session:, **) | ||
session.is_a?(Session) | ||
end | ||
|
||
def rebuild_session(ctx, session:, **) | ||
session_params = ctx.to_h.slice(*Signin::SESSION_VARIABLE_NAMES) | ||
|
||
session = Session.new( | ||
**session.to_h, # old data | ||
**session_params, # new input | ||
) | ||
|
||
ctx[:session] = session | ||
ctx[:session_updated] = true | ||
end | ||
|
||
def session_to_args(ctx, session:, **) | ||
session.to_h | ||
end | ||
end | ||
end # Client | ||
end | ||
end |
8 changes: 4 additions & 4 deletions
8
lib/trailblazer/pro/trace/refresh.rb → lib/trailblazer/pro/client/refresh.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require "test_helper" | ||
|
||
class ClientTest < Minitest::Spec | ||
let(:session_static_options) do | ||
{ | ||
api_key: api_key, | ||
trailblazer_pro_host: trailblazer_pro_host, | ||
firebase_upload_url: "https://firestore.googleapis.com/v1/projects/trb-pro-dev/databases/(default)/documents/traces", | ||
firestore_fields_template: {"version"=>{"stringValue"=>"1"}, "uid"=>{"stringValue"=>"8KwCOTLeK3QdmgtVNUPwr0ukJJc2"}}, | ||
firebase_refresh_url: "https://securetoken.googleapis.com/v1/token?key=AIzaSyDVZOdUrI6wOji774hGU0yY_cQw9OAVwzs", | ||
} | ||
end # FIXME: do we need this? | ||
|
||
|
||
it "Client.() maintains a valid session/JWT for us" do | ||
initial_session = Trailblazer::Pro::Session::Uninitialized.new(trailblazer_pro_host: trailblazer_pro_host, api_key: api_key) | ||
|
||
signal, (ctx, _) = Trailblazer::Developer.wtf?(Trailblazer::Pro::Client::Connect, [{session: initial_session}, {}]) | ||
|
||
assert_session ctx[:session], **session_static_options | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters