Skip to content

Commit

Permalink
Rename cli.{,Fallback}APIInitializer
Browse files Browse the repository at this point in the history
  • Loading branch information
dimroc committed Jul 20, 2018
1 parent 3d23112 commit 7de2fa0
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 54 deletions.
17 changes: 9 additions & 8 deletions cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ import (
// Config, AppFactory (the services application), KeyStoreAuthenticator, and Runner.
type Client struct {
Renderer
Config store.Config
AppFactory AppFactory
Auth KeyStoreAuthenticator
APIInitializer APIInitializer
Runner Runner
RemoteClient RemoteClient
CookieAuthenticator CookieAuthenticator
Config store.Config
AppFactory AppFactory
Auth KeyStoreAuthenticator
FallbackAPIInitializer APIInitializer
Runner Runner
RemoteClient RemoteClient
CookieAuthenticator CookieAuthenticator
}

func (cli *Client) errorOut(err error) error {
Expand Down Expand Up @@ -237,8 +237,9 @@ func (t *TerminalCookieAuthenticator) cookiePath() string {
}

// APIInitializer is the interface used to create the API User credentials
// needed to access the API.
// needed to access the API. Does nothing if API user already exists.
type APIInitializer interface {
// Initialize creates a new user for API access, or does nothing if one exists.
Initialize(store *store.Store) (models.User, error)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/local_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (cli *Client) RunNode(c *clipkg.Context) error {
if _, err = NewFileAPIInitializer(c.String("api")).Initialize(store); err != nil && err != errNoCredentialFile {
return cli.errorOut(fmt.Errorf("error starting app: %+v", err))
}
if user, err = cli.APIInitializer.Initialize(store); err != nil {
if user, err = cli.FallbackAPIInitializer.Initialize(store); err != nil {
return cli.errorOut(fmt.Errorf("error starting app: %+v", err))
}
logger.Info("API exposed for user ", user.Email)
Expand Down
30 changes: 15 additions & 15 deletions cmd/local_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ func TestClient_RunNodeShowsEnv(t *testing.T) {

auth := cltest.CallbackAuthenticator{Callback: func(*store.Store, string) error { return nil }}
client := cmd.Client{
Config: app.Store.Config,
AppFactory: cltest.InstanceAppFactory{App: app.ChainlinkApplication},
Auth: auth,
APIInitializer: &cltest.MockAPIInitializer{},
Runner: cltest.EmptyRunner{},
Config: app.Store.Config,
AppFactory: cltest.InstanceAppFactory{App: app.ChainlinkApplication},
Auth: auth,
FallbackAPIInitializer: &cltest.MockAPIInitializer{},
Runner: cltest.EmptyRunner{},
}

set := flag.NewFlagSet("test", 0)
Expand Down Expand Up @@ -88,11 +88,11 @@ func TestClient_RunNodeWithPasswords(t *testing.T) {
auth := cltest.CallbackAuthenticator{Callback: callback}
apiPrompt := &cltest.MockAPIInitializer{}
client := cmd.Client{
Config: app.Store.Config,
AppFactory: cltest.InstanceAppFactory{App: app},
Auth: auth,
APIInitializer: apiPrompt,
Runner: cltest.EmptyRunner{},
Config: app.Store.Config,
AppFactory: cltest.InstanceAppFactory{App: app},
Auth: auth,
FallbackAPIInitializer: apiPrompt,
Runner: cltest.EmptyRunner{},
}

set := flag.NewFlagSet("test", 0)
Expand Down Expand Up @@ -134,11 +134,11 @@ func TestClient_RunNodeWithAPICredentialsFile(t *testing.T) {
noauth := cltest.CallbackAuthenticator{Callback: func(*store.Store, string) error { return nil }}
apiPrompt := &cltest.MockAPIInitializer{}
client := cmd.Client{
Config: app.Config,
AppFactory: cltest.InstanceAppFactory{App: app},
Auth: noauth,
APIInitializer: apiPrompt,
Runner: cltest.EmptyRunner{},
Config: app.Config,
AppFactory: cltest.InstanceAppFactory{App: app},
Auth: noauth,
FallbackAPIInitializer: apiPrompt,
Runner: cltest.EmptyRunner{},
}

set := flag.NewFlagSet("test", 0)
Expand Down
16 changes: 8 additions & 8 deletions internal/cltest/cltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,14 @@ func (ta *TestApplication) NewClientAndRenderer() (*cmd.Client, *RendererMock) {
ta.MustSeedUserSession()
r := &RendererMock{}
client := &cmd.Client{
Renderer: r,
Config: ta.Config,
AppFactory: EmptyAppFactory{},
Auth: CallbackAuthenticator{func(*store.Store, string) error { return nil }},
APIInitializer: &MockAPIInitializer{},
Runner: EmptyRunner{},
RemoteClient: NewMockAuthenticatedRemoteClient(ta.Config),
CookieAuthenticator: MockCookieAuthenticator{},
Renderer: r,
Config: ta.Config,
AppFactory: EmptyAppFactory{},
Auth: CallbackAuthenticator{func(*store.Store, string) error { return nil }},
FallbackAPIInitializer: &MockAPIInitializer{},
Runner: EmptyRunner{},
RemoteClient: NewMockAuthenticatedRemoteClient(ta.Config),
CookieAuthenticator: MockCookieAuthenticator{},
}
return client, r
}
Expand Down
16 changes: 8 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ func NewProductionClient() *cmd.Client {
prompter := cmd.NewTerminalPrompter()
cookieAuth := cmd.NewTerminalCookieAuthenticator(cfg, prompter)
return &cmd.Client{
Renderer: cmd.RendererTable{Writer: os.Stdout},
Config: cfg,
AppFactory: cmd.ChainlinkAppFactory{},
Auth: cmd.TerminalAuthenticator{Prompter: prompter},
APIInitializer: cmd.NewPromptingAPIInitializer(prompter),
Runner: cmd.ChainlinkRunner{},
RemoteClient: cmd.NewAuthenticatedHTTPClient(cfg, cookieAuth),
CookieAuthenticator: cookieAuth,
Renderer: cmd.RendererTable{Writer: os.Stdout},
Config: cfg,
AppFactory: cmd.ChainlinkAppFactory{},
Auth: cmd.TerminalAuthenticator{Prompter: prompter},
FallbackAPIInitializer: cmd.NewPromptingAPIInitializer(prompter),
Runner: cmd.ChainlinkRunner{},
RemoteClient: cmd.NewAuthenticatedHTTPClient(cfg, cookieAuth),
CookieAuthenticator: cookieAuth,
}
}
28 changes: 14 additions & 14 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ func ExampleRun() {
tc, cleanup := cltest.NewConfig()
defer cleanup()
testClient := &cmd.Client{
Renderer: cmd.RendererTable{Writer: ioutil.Discard},
Config: tc.Config,
AppFactory: cmd.ChainlinkAppFactory{},
Auth: cmd.TerminalAuthenticator{Prompter: &cltest.MockCountingPrompter{}},
APIInitializer: &cltest.MockAPIInitializer{},
Runner: cmd.ChainlinkRunner{},
RemoteClient: cltest.NewMockAuthenticatedRemoteClient(tc.Config),
Renderer: cmd.RendererTable{Writer: ioutil.Discard},
Config: tc.Config,
AppFactory: cmd.ChainlinkAppFactory{},
Auth: cmd.TerminalAuthenticator{Prompter: &cltest.MockCountingPrompter{}},
FallbackAPIInitializer: &cltest.MockAPIInitializer{},
Runner: cmd.ChainlinkRunner{},
RemoteClient: cltest.NewMockAuthenticatedRemoteClient(tc.Config),
}

Run(testClient, "chainlink.test", "--help")
Expand Down Expand Up @@ -60,13 +60,13 @@ func ExampleVersion() {
tc, cleanup := cltest.NewConfig()
defer cleanup()
testClient := &cmd.Client{
Renderer: cmd.RendererTable{Writer: ioutil.Discard},
Config: tc.Config,
AppFactory: cmd.ChainlinkAppFactory{},
Auth: cmd.TerminalAuthenticator{Prompter: &cltest.MockCountingPrompter{}},
APIInitializer: &cltest.MockAPIInitializer{},
Runner: cmd.ChainlinkRunner{},
RemoteClient: cltest.NewMockAuthenticatedRemoteClient(tc.Config),
Renderer: cmd.RendererTable{Writer: ioutil.Discard},
Config: tc.Config,
AppFactory: cmd.ChainlinkAppFactory{},
Auth: cmd.TerminalAuthenticator{Prompter: &cltest.MockCountingPrompter{}},
FallbackAPIInitializer: &cltest.MockAPIInitializer{},
Runner: cmd.ChainlinkRunner{},
RemoteClient: cltest.NewMockAuthenticatedRemoteClient(tc.Config),
}

Run(testClient, "chainlink.test", "--version")
Expand Down

0 comments on commit 7de2fa0

Please sign in to comment.