feat(collector): app-owner vs M2M customer identity#70
Open
eliteprox wants to merge 1 commit into
Open
Conversation
Port the pymthouse collector identity contract: strip owner: wire subjects
to bare {users.id} CloudEvent subjects, keep M2M compound keys unchanged,
and teach bootstrap to provision shared owner customers.
There was a problem hiding this comment.
Pull request overview
This PR updates the OpenMeter collector + provisioning tooling to support two customer identity shapes: app-owner usage subjects that resolve to a shared bare user-id wallet, and M2M/managed-user usage subjects that remain compound client_id:external_user_id keys.
Changes:
- Update
openmeter-collector/collector.yamlto mapauth_id=app_…:owner:{users.id}to CloudEventsubject={users.id}(and addopenmeter_customer_key/eth_usd_price, plusceilfor USD micros). - Extend provisioning scripts (
bootstrap.sh/.ps1) with anownercommand and delegation fromcustomerwhenexternal_user_idstarts withowner:. - Add Go helpers + tests under
openmeter-collector/identitydocumenting/testing the customer key contract; update root + provision docs.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Documents the app-owner vs M2M subject/customer-key contract and provides example egress events. |
| openmeter-collector/provision/README.md | Updates provisioning instructions + documents the two customer shapes and their keys. |
| openmeter-collector/provision/bootstrap.sh | Adds owner provisioning and refactors customer creation to a key-based helper. |
| openmeter-collector/provision/bootstrap.ps1 | PowerShell parity for owner provisioning and key-based customer helper. |
| openmeter-collector/identity/go.mod | Introduces a small standalone Go module for identity contract helpers. |
| openmeter-collector/identity/customer_key.go | Implements owner vs M2M key derivation helpers. |
| openmeter-collector/identity/customer_key_test.go | Adds unit tests for owner vs M2M key behavior. |
| openmeter-collector/collector.yaml | Implements owner subject normalization and adds extra event fields + USD micros rounding behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+125
to
+136
| # Owner wallet: wire usage_subject is owner:{users.id}; CE subject = bare id. | ||
| # M2M end-users: meter subject = full compound auth_id. | ||
| let is_owner_subject = $usage_subject_parsed.index_of("owner:") == 0 | ||
| let usage_subject_type = if $is_owner_subject { "app_owner" } else { "external_user_id" } | ||
| let owner_bare_id = if $is_owner_subject { | ||
| $usage_subject_parsed.slice("owner:".length()) | ||
| } else { | ||
| $usage_subject_parsed | ||
| } | ||
| let openmeter_subject = if $is_owner_subject { $owner_bare_id } else { $auth_id } | ||
| let openmeter_customer_key = $openmeter_subject | ||
| let usage_subject_out = if $is_owner_subject { $owner_bare_id } else { $usage_subject_parsed } |
| "gateway_request_id": $data.request_id, | ||
| "auth_id": $auth_id, | ||
| "openmeter_customer_key": $openmeter_customer_key, | ||
| "eth_usd_price": $eth_usd.string(), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
app_…:owner:{users.id}map to CloudEventsubject/ customer key = bare{users.id}; M2M managed users keep compoundapp_…:external_user_idunchangedbootstrap.sh/bootstrap.ps1) gains anownercommand (andcustomerauto-delegates whenexternal_user_idstarts withowner:)openmeter-collector/identityGo helpers + unit tests for the customer-key contractCloses #69
Test plan
cd openmeter-collector/identity && go test ./... -count=1bash -n openmeter-collector/provision/bootstrap.shauth_id=app_x:owner:{uuid}→ CloudEventsubject={uuid},usage_subject_type=app_ownerauth_id=app_x:user-1→subject=app_x:user-1(unchanged)./bootstrap.sh owner <uuid> "App Owner"creates customer keyed by bare uuid./bootstrap.sh customer demo-client demo-userstill creates compound key