Skip to content

Refactor xurl package structure and improve library API#44

Open
drQedwards wants to merge 1 commit intoxdevplatform:mainfrom
drQedwards:main
Open

Refactor xurl package structure and improve library API#44
drQedwards wants to merge 1 commit intoxdevplatform:mainfrom
drQedwards:main

Conversation

@drQedwards
Copy link

@drQedwards drQedwards commented Mar 3, 2026

This pull request introduces robust multi-app authentication support and improves the Go library usability of the project. The main changes ensure that authentication tokens are correctly selected and used based on the active app context, and that consumers can use the project as a Go module or library. Comprehensive tests have been added to verify multi-app token selection and isolation. Additionally, a new xurl.go entry point makes the CLI easily embeddable in other Go projects.

Multi-app authentication improvements:

  • All token retrieval and storage methods in auth/auth.go and api/client.go now respect the active app context by using new ForApp-suffixed methods, ensuring the correct credentials are used when multiple apps are configured. ([[1]](https://github.com/xdevplatform/xurl/pull/44/files#diff-f5c9a39fac1719f2a73593994b931d8a874449548e8a3753e1be46e761e503eaL85-R98), [[2]](https://github.com/xdevplatform/xurl/pull/44/files#diff-f5c9a39fac1719f2a73593994b931d8a874449548e8a3753e1be46e761e503eaL149-R152), [[3]](https://github.com/xdevplatform/xurl/pull/44/files#diff-f5c9a39fac1719f2a73593994b931d8a874449548e8a3753e1be46e761e503eaL256-R257), [[4]](https://github.com/xdevplatform/xurl/pull/44/files#diff-f5c9a39fac1719f2a73593994b931d8a874449548e8a3753e1be46e761e503eaL269-R272), [[5]](https://github.com/xdevplatform/xurl/pull/44/files#diff-f5c9a39fac1719f2a73593994b931d8a874449548e8a3753e1be46e761e503eaL313-R314), [[6]](https://github.com/xdevplatform/xurl/pull/44/files#diff-f5c9a39fac1719f2a73593994b931d8a874449548e8a3753e1be46e761e503eaL323-R324), [[7]](https://github.com/xdevplatform/xurl/pull/44/files#diff-aa9bfd1a638fbb706f8e8920297902937011160319d9679add5dca56e5ab8277L349-R350), [[8]](https://github.com/xdevplatform/xurl/pull/44/files#diff-aa9bfd1a638fbb706f8e8920297902937011160319d9679add5dca56e5ab8277L358-R359))
  • The WithAppName method now always overwrites the client ID and secret, even if they are non-empty, to match the selected app. A new AppName getter is added for clarity. ([auth/auth.goL85-R98](https://github.com/xdevplatform/xurl/pull/44/files#diff-f5c9a39fac1719f2a73593994b931d8a874449548e8a3753e1be46e761e503eaL85-R98))
  • Extensive new tests in auth/auth_test.go and api/client_test.go verify correct token selection, isolation, and credential switching between apps. ([[1]](https://github.com/xdevplatform/xurl/pull/44/files#diff-b06746870e62f95017714121be6134cffdc4bd1d46dd21f8cae8c484e3e2829dR250-R462), [[2]](https://github.com/xdevplatform/xurl/pull/44/files#diff-3416b4ca1c6412b67c502506e394b00088cca5276801786c69384fa5efac5122R360-R437))

Go library and CLI usability:

  • Added a new xurl.go file exposing NewRootCommand, CreateRootCommand, and Execute functions, allowing the CLI to be embedded or extended by other Go programs. ([xurl.goR1-R27](https://github.com/xdevplatform/xurl/pull/44/files#diff-0aeaa23d55a9ac978bacbcf2df320186c58eada0196ff0914250a4259c67812aR1-R27))
  • Updated the README.md with clear instructions for using the project as a Go library and for using a local checkout with a replace directive. ([README.mdL36-R52](https://github.com/xdevplatform/xurl/pull/44/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L36-R52))

Build and installation improvements:

  • The Makefile and Go install instructions now explicitly point to the ./cmd/xurl subdirectory, clarifying the build and install process. ([[1]](https://github.com/xdevplatform/xurl/pull/44/files#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52L3-R7), [[2]](https://github.com/xdevplatform/xurl/pull/44/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L36-R52))

Miscellaneous:

  • Minor import statement cleanups for clarity and consistency. ([[1]](https://github.com/xdevplatform/xurl/pull/44/files#diff-aa9bfd1a638fbb706f8e8920297902937011160319d9679add5dca56e5ab8277R4-L16), [[2]](https://github.com/xdevplatform/xurl/pull/44/files#diff-3416b4ca1c6412b67c502506e394b00088cca5276801786c69384fa5efac5122R11), [[3]](https://github.com/xdevplatform/xurl/pull/44/files#diff-b9f3e3c270d8be1108b2e07b66e4fb6bf51a04d93bfd94f4e900d2ceb0a3079aR12), [[4]](https://github.com/xdevplatform/xurl/pull/44/files#diff-b06746870e62f95017714121be6134cffdc4bd1d46dd21f8cae8c484e3e2829dR7))

These changes make the authentication system more robust and flexible for users managing multiple app credentials, and improve the developer experience for both CLI users and Go library consumers.https://cla-assistant.io/xdevplatform/xurl?pullRequest=43 PR #43
This pull request introduces robust multi-app authentication support and improves the developer experience when using the project as a Go library. The most significant changes include ensuring all authentication and token operations are app-aware, adding comprehensive tests for multi-app scenarios, and providing a top-level Go package API for library consumers.

Multi-app authentication enhancements:

  • Refactored all token store accessors and authentication methods in auth/auth.go and api/client.go to use app-specific variants (e.g., GetOAuth2TokenForApp, GetBearerTokenForApp), ensuring the active app context (set via WithAppName) is always respected. This prevents cross-app token leakage and guarantees correct credentials are used for each app. [1] [2] [3] [4] [5] [6] [7] [8]

  • Added a new AppName() getter to auth.Auth for retrieving the current app context.

Testing and reliability improvements:

  • Introduced extensive multi-app test cases in auth/auth_test.go and api/client_test.go to verify correct token usage, credential overwriting, and app-specific token storage/clearing. These tests validate scenarios such as switching apps, storing tokens for the active app, and ensuring isolation between apps. [1] [2]

Go library usability:

  • Added a new top-level xurl package (xurl.go) that exposes NewRootCommand, CreateRootCommand, and Execute functions, making it easy to embed or extend the CLI in other Go projects.

  • Updated the README.md to document how to use the project as a Go library and clarified the Go install path for the CLI binary.

Build and tooling:

  • Updated the Makefile and Go install instructions to ensure the CLI is built and installed from the correct subdirectory (./cmd/xurl). [1] [2]

Other minor improvements:

  • Minor import ordering and formatting cleanups in several files for consistency. [1] [2] [3] [4]

These changes collectively make the authentication system safer and more predictable in multi-app scenarios, improve test coverage, and enhance the developer experience for both CLI users and Go library consumers.

@CLAassistant
Copy link

CLAassistant commented Mar 3, 2026

CLA assistant check
All committers have signed the CLA.

… Go library

Refactor package structure so the module root is an importable library
(package xurl) instead of package main. Moves CLI entrypoint to
cmd/xurl/main.go, updates Makefile and README install paths, and adds
library API surface (NewRootCommand, CreateRootCommand, Execute).

Also includes --app flag credential switching fix with ForApp token
lookups, unconditional WithAppName override, and 18 new tests.

Supersedes closed PR xdevplatform#28 (CLA unsigned by prior contributor).
Resolves CWE-665: improper initialization of resource.
Copy link
Author

Build check: "Waiting for status to be reported"

The build status check is stuck because GitHub Actions requires maintainer approval before running workflows on PRs from first-time fork contributors.

@santiagomed — please check https://github.com/xdevplatform/xurl/actions for a pending approval banner on this PR's workflow run and approve it. Once approved, the Go workflow (.github/workflows/go.yml) will run go build + go test + gofmt and the build status will report.

Alternatively, since the CLA is now signed and passing, you can merge with admin override if the code looks good.

Local verification (already done in codespace):

  • go build ./... — clean
  • go test ./... — 52 passed, 0 failed
  • gofmt -l . — no issues

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.

2 participants