Skip to content

Add "connect list" command and HTTP library infra - #2

Merged
Cody A. Ray (codyaray) merged 19 commits into
masterfrom
connect-list
May 7, 2018
Merged

Add "connect list" command and HTTP library infra#2
Cody A. Ray (codyaray) merged 19 commits into
masterfrom
connect-list

Conversation

@codyaray

Copy link
Copy Markdown
Contributor

@confluentinc/caas

This PR adds the first end-to-end CLI command. It lists all the connectors in an account.

The core is a new HTTP package for our API.

authURL = "https://confluent.cloud"

client := confluent.NewClient(http.DefaultClient, authURL, logger)
token, err := client.Login(email, password)
check(err)

user, err := client.User()
check(err)

client := confluent.NewClientWithJWT(context.Background(), token, authURL, logger)
connectors, _, err := client.Connect.List(user.Account.ID)
check(err)

fmt.Println(connectors)

HTTP Library Details:

  • The http package is a standalone wrapper for all API requests & responses.
  • Each module has its own service object in the http package (client.Connect.List)
  • Flexible authentication: inject oauth2.Token into http.Client instead of hardcoding security mechanism inside http package
  • Use https://github.com/dghubble/sling to simplify all the HTTP request/response stuff

Related changes:

  • Refactor auth CLI commands to use HTTP library
  • A successful confluent login calls /api/me and adds user/account info to config file
  • A common CLI error-handling routine is used for standard outputs/responses for each error
  • Update connect plugin logs to append instead of truncate each call

Here's example CLI output from various scenarios:

$ go run main.go connect list 
You must login to access Confluent Cloud.

$ go run main.go login --url https://stag.cpdev.cloud
Enter your Confluent Cloud credentials:
Email: cody@confluent.io
Password: 
Logged in as cody@confluent.io

$ go run main.go connect list 
[id:"cp42" name:"Super-\342\233\204" physical_cluster_id:"cp2" ...]
# I'll format outputs and such soon... out of scope for this PR

// Wait til token expires

$ go run main.go connect list
Your access to Confluent Cloud has expired. Please login again.

// After logging in again

$ go run main.go logout
You are now logged out

// Example if you try hacking a token in ~/.confluent/config.hcl.

$ go run main.go connect list 
Error: malformed
Usage:
  confluent connect list [flags]

Flags:
  -h, --help   help for list

exit status 1

// Example if we missed handling an API error

$ go run main.go connect list 
Error: confluent (400): malformed token
Usage:
  confluent connect list [flags]

Flags:
  -h, --help   help for list

exit status 1

@chicagobuss Joshua Buss (chicagobuss) left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome, great work!

@codyaray
Cody A. Ray (codyaray) merged commit 7deb55e into master May 7, 2018
@codyaray
Cody A. Ray (codyaray) deleted the connect-list branch May 7, 2018 14:33
Comment thread http/errors.go
ErrMalformedToken = fmt.Errorf("malformed")
)

// TODO: reuse corev1.Error from cc-structs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on reusing corev1

@travisjeffery

Copy link
Copy Markdown
Contributor

👍

Prathibha Muralidharan (Prathibha-m) added a commit that referenced this pull request Sep 4, 2019
# This is the 1st commit message:

Add subject commands

# This is the commit message #2:

Docs

Unhide SR

make deps
Prathibha Muralidharan (Prathibha-m) added a commit that referenced this pull request Sep 12, 2019
# This is the 1st commit message:

Add subject commands

# This is the commit message #2:

Docs

Unhide SR

make deps
Prathibha Muralidharan (Prathibha-m) added a commit that referenced this pull request Sep 12, 2019
* Add --resource-id flag for create api key

Pass AccountID from environment to create API key

Mark current context API key in list of API keys

Revert changes to API key delete

Remove extra import

Pass account ID to retrieve SR correctly

update docs description

Error handling and Cleanup

fmt

Add parameter for flag in GetKafkaConfig

Address comments

Remove unnecessary err check

Modify integration test

lint

Locl commit

Clean up

Remove unit test (temp)

Fix tests

lint

Modify resource scoped commands

Add unit test

Cleanup

Integration test

Clean

fix

WIP

WIP Integration test

clean

wip

Fix IT

Clean up

Fix fixture

i

nit

Error test case

Fixture spacing

Remove ID check

address comments

Rebase on master

Address comments

Mock tests

Improve unit test validation

* Unhide SR

nits

Hide SR

* Fix lint errors from Schema Registry

* Cluster command updates

* # This is a combination of 2 commits.
# This is the 1st commit message:

Add subject commands

# This is the commit message #2:

Docs

Unhide SR

make deps

* More schema tests

* WIP integration test

Typo

* minor:import order

*  address comments

Address comments

Update comment

Mark geo flag required

* Add logger

* make fmt

* Add CLIName replacement to docs

* Error checks

* create variables for reuse

* rebase on master

fmt

Fmt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants