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

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