Skip to content

[Customer Entity] Rename snclient package and align IntegrationService config field names with ServiceNow prefix - #857

Merged
Rashmika998 merged 1 commit into
wso2-open-operations:v2from
cloby99:task/entity-service
Jun 15, 2026
Merged

Rashmika998 merged 1 commit into
wso2-open-operations:v2from
cloby99:task/entity-service

Conversation

@cloby99

@cloby99 cloby99 commented Jun 15, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Renamed internal/snclient package directory to internal/servicenow-integration-service for clarity; added integrationservice import alias in all consuming files since Go identifiers cannot contain hyphens
  • Renamed all IntegrationService* fields in config.Config to ServiceNowIntegrationService* (e.g. IntegrationServiceBaseURL → ServiceNowIntegrationServiceBaseURL) to make the origin of these credentials unambiguous at the call site

Test plan

  • go build ./... passes with no errors
  • DATA_SOURCE=servicenow startup with all SERVICENOW_INTEGRATION_SERVICE_* env vars set boots without config validation errors
  • DATA_SOURCE=postgres startup is unaffected

Summary by CodeRabbit

Release Notes

  • Configuration

    • ServiceNow data source integration updated with OAuth2 authentication. Requires new configuration variables: service endpoint, token URL, client ID, client secret, and scopes. Previous authentication method no longer supported.
  • Refactor

    • Enhanced internal ServiceNow integration service architecture.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Replaces the snclient package with a new servicenow-integration-service client that implements OAuth2 client-credentials token caching. Config gains five new ServiceNow OAuth fields. All three ServiceNow service constructors are updated to accept the new client type, the router is rewired, and the old snclient package is deleted.

Changes

ServiceNow Integration Service Client Migration

Layer / File(s) Summary
New OAuth2 integration service client
entity-service/internal/servicenow-integration-service/client.go
Adds ClientCredentialsConfig, Client struct with mutex-protected token state, New constructor, accessToken for client-credentials grant with 30-second pre-expiry refresh, Get/Post helpers that inject Authorization and x-user-id-token headers, and do for HTTP status-to-apierror mapping.
Config struct, Load, Validate, and env example
entity-service/internal/config/config.go, entity-service/.env.example
Replaces SNBaseURL with ServiceNowIntegrationServiceBaseURL and adds TokenURL, ClientID, ClientSecret, Scopes fields; Load reads DATA_SOURCE and the new SERVICENOW_INTEGRATION_SERVICE_* env vars; Validate requires all five fields when DataSource is servicenow; env example reflects the new variables.
SN service constructors updated to integrationservice.Client
entity-service/internal/service/sn_project_service.go, entity-service/internal/service/sn_deployment_service.go, entity-service/internal/service/sn_case_service.go
Updates snProjectService, snDeploymentService, and snCaseService structs and exported constructors to accept *integrationservice.Client; renames NewSNProjectService to NewServiceNowProjectService.
Router wiring and snclient removal
entity-service/internal/server/routes.go, entity-service/internal/snclient/client.go
NewRouter constructs a shared serviceNowIntegrationServiceClient from the OAuth config fields and passes it to all three ServiceNow service constructors; replaces snclient import with integrationservice; the old snclient/client.go (137 lines) is fully deleted.

Sequence Diagram

sequenceDiagram
  participant NewRouter
  participant integrationservice.New
  participant accessToken as Client.accessToken
  participant TokenEndpoint
  participant IntegrationServiceAPI
  participant SNService as sn_*_service

  NewRouter->>integrationservice.New: New(baseURL, ClientCredentialsConfig)
  integrationservice.New-->>NewRouter: *Client
  NewRouter->>SNService: NewServiceNow*Service(*Client, ...)

  Note over SNService,IntegrationServiceAPI: At request time
  SNService->>accessToken: accessToken(ctx)
  accessToken->>TokenEndpoint: POST client-credentials grant
  TokenEndpoint-->>accessToken: access_token + expires_in
  accessToken-->>SNService: bearer token
  SNService->>IntegrationServiceAPI: GET/POST with Authorization + x-user-id-token
  IntegrationServiceAPI-->>SNService: HTTP response → json.RawMessage or apierror
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • wso2-open-operations/cs-tools#855: Directly related — adds ServiceNow case search using snclient, which this PR replaces with the new integrationservice.Client in sn_case_service.go and routes.go.

Suggested reviewers

  • Rashmika998

Poem

🐇 Hop hop, the old snclient is gone,
A shiny OAuth token leads us on!
With mutex guard and 30-second grace,
The bearer token caches into place.
Config fields bloom like clover in spring —
Five new env vars, what joy they bring! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning PR description provides clear summary and test plan, but lacks required template sections like Purpose, Goals, Approach, User stories, Release notes, Documentation, Training, Certification, and others. Complete the pull request description by filling out all required template sections from the repository standard template, including Purpose, Goals, Approach, and other required sections.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Title accurately describes the main changes: renaming snclient package to servicenow-integration-service and aligning IntegrationService config fields with ServiceNow prefix.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
entity-service/internal/servicenow-integration-service/client.go (1)

94-213: ⚡ Quick win

Standardize error prefixes to integrationservice across the new client.

The migrated package still emits "snclient:" in multiple error paths, which makes logs and alerts misleading post-migration.

Suggested cleanup
+const errPrefix = "integrationservice"
...
- return "", fmt.Errorf("snclient: build token request: %w", err)
+ return "", fmt.Errorf("%s: build token request: %w", errPrefix, err)
...
- return "", fmt.Errorf("snclient: read token response: %w", err)
+ return "", fmt.Errorf("%s: read token response: %w", errPrefix, err)
...
- return "", fmt.Errorf("snclient: parse token response: %w", err)
+ return "", fmt.Errorf("%s: parse token response: %w", errPrefix, err)
...
- return nil, fmt.Errorf("snclient: build request: %w", err)
+ return nil, fmt.Errorf("%s: build request: %w", errPrefix, err)

Apply the same replacement pattern to the remaining "snclient:" occurrences in this file.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@entity-service/internal/servicenow-integration-service/client.go` around
lines 94 - 213, Replace all error message prefixes from "snclient:" to
"integrationservice" throughout the client code to maintain consistency
post-migration. Update the error prefix in the accessToken method (including
"snclient: build token request", "snclient: read token response", "snclient:
parse token response", and "snclient: token endpoint returned empty
access_token"), in the Get method ("snclient: build request"), in the Post
method ("snclient: build request" and "snclient: marshal request"), and in the
do method ("snclient: %s: %v", "snclient: read response body", and "snclient:
%s: unexpected status"). This ensures all error logs emit the
"integrationservice" prefix consistently across all API operations.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@entity-service/internal/config/config.go`:
- Around line 96-109: The Validate() method is missing a required validation
check for the ServiceNow scopes configuration. Add a validation check for
ServiceNowIntegrationServiceScopes in the same conditional block where you check
DataSourceServiceNow. Follow the same pattern as the existing four ServiceNow
field validations by checking if ServiceNowIntegrationServiceScopes is empty and
returning an appropriate error message indicating that
SERVICENOW_INTEGRATION_SERVICE_SCOPES is required when DATA_SOURCE=servicenow.

---

Nitpick comments:
In `@entity-service/internal/servicenow-integration-service/client.go`:
- Around line 94-213: Replace all error message prefixes from "snclient:" to
"integrationservice" throughout the client code to maintain consistency
post-migration. Update the error prefix in the accessToken method (including
"snclient: build token request", "snclient: read token response", "snclient:
parse token response", and "snclient: token endpoint returned empty
access_token"), in the Get method ("snclient: build request"), in the Post
method ("snclient: build request" and "snclient: marshal request"), and in the
do method ("snclient: %s: %v", "snclient: read response body", and "snclient:
%s: unexpected status"). This ensures all error logs emit the
"integrationservice" prefix consistently across all API operations.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e74dd980-7612-4ebe-b45e-d0504faed99f

📥 Commits

Reviewing files that changed from the base of the PR and between 9a2375f and efe37c4.

📒 Files selected for processing (8)
  • entity-service/.env.example
  • entity-service/internal/config/config.go
  • entity-service/internal/server/routes.go
  • entity-service/internal/service/sn_case_service.go
  • entity-service/internal/service/sn_deployment_service.go
  • entity-service/internal/service/sn_project_service.go
  • entity-service/internal/servicenow-integration-service/client.go
  • entity-service/internal/snclient/client.go
💤 Files with no reviewable changes (1)
  • entity-service/internal/snclient/client.go

Comment thread entity-service/internal/config/config.go
@Rashmika998 Rashmika998 added Type/Improvement Marks enhancements or improvements to existing features Entity Service labels Jun 15, 2026
@Rashmika998
Rashmika998 merged commit 6c0cde9 into wso2-open-operations:v2 Jun 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Entity Service Type/Improvement Marks enhancements or improvements to existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants