-
Notifications
You must be signed in to change notification settings - Fork 7
feat(refid): generate agency reference IDs on application inject #307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sthanikan2000
wants to merge
5
commits into
main
Choose a base branch
from
feat/refid-generation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5aad621
feat(refid): generate agency reference IDs on application inject
sthanikan2000 0a662e8
chore(deps): point refid at the merged core module
sthanikan2000 0c5d9bf
fix(refid): address review feedback on reference ID generation
sthanikan2000 b822f14
refactor(refid): trim redundant tests and commentary
sthanikan2000 af54389
refactor(refid): generateRefID returns the ID, not a document
sthanikan2000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package application | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| "github.com/OpenNSW/agency/backend/internal/taskconfig" | ||
| "github.com/OpenNSW/agency/backend/pkg/jsonpointer" | ||
| "github.com/OpenNSW/core/refid" | ||
| ) | ||
|
|
||
| // generateRefID mints this task's reference ID. | ||
| // | ||
| // A params pointer that doesn't resolve to a string is skipped rather than | ||
| // rejected: refid ignores params the configured format doesn't consume, so a | ||
| // task may declare more than any one format needs. Whether an absent value | ||
| // matters is refid's call — it returns ErrInvalidParam for a param a segment | ||
| // requires, and for an unresolved scope-key placeholder. | ||
| // | ||
| // ErrInvalidParam maps to a 400; every other failure stays unwrapped and | ||
| // surfaces as a 500. | ||
| func generateRefID(ctx context.Context, reg refid.Registry, cfg *taskconfig.TaskRefID, data map[string]any) (string, error) { | ||
| params := make(map[string]string, len(cfg.Params)) | ||
| for param, pointer := range cfg.Params { | ||
| value, ok := jsonpointer.Get(data, pointer) | ||
| if !ok { | ||
| continue | ||
| } | ||
| if str, ok := value.(string); ok { | ||
| params[param] = str | ||
| } | ||
| } | ||
|
|
||
| id, err := reg.Generate(ctx, cfg.Issuer, cfg.IDType, params) | ||
| if err != nil { | ||
| if errors.Is(err, refid.ErrInvalidParam) { | ||
| return "", fmt.Errorf("%w: %v", ErrInvalidInjectRequest, err) | ||
| } | ||
| return "", fmt.Errorf("failed to generate reference ID for issuer %q idType %q: %w", cfg.Issuer, cfg.IDType, err) | ||
| } | ||
| return id, nil | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should tightly couple the regid generation with the jsonforms structure. These should be decoupled, where the refid generation writes to our global state, and the form picks it up from there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewer_responseis the task's global state rather than a form structure:applicationshas only two task-scoped JSON documents,data(injected from NSW) andreviewer_response. There is no third store to write into.datais not a candidate either. It is replaced wholesale on every inject — set fromreq.Datawith no carry-forward, and rewritten by the feedback-resubmission path — so anything we wrote there would be gone on the next one. And a reference number for the NSW-injected submission is NSW's to issue on its own side with its own config;refidis a shared library precisely so it can.So
pathtargets the only slot that fits, and the form reads it from there.