-
Notifications
You must be signed in to change notification settings - Fork 0
fix: account/egress/get handler configuration #30
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
volmedo
wants to merge
1
commit into
main
Choose a base branch
from
vic/fix/account-egress-get-handler
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.
+56
−1
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ type config struct { | |
| clientEgressUSDPerTiB float64 | ||
| providerEgressUSDPerTiB float64 | ||
| principalResolver validator.PrincipalResolver | ||
| principalParser validator.PrincipalParserFunc | ||
| authProofs []delegation.Delegation | ||
| } | ||
|
|
||
|
|
@@ -56,6 +57,12 @@ func WithPrincipalResolver(resolver validator.PrincipalResolver) Option { | |
| } | ||
| } | ||
|
|
||
| func WithPrincipalParser(parser validator.PrincipalParserFunc) Option { | ||
| return func(c *config) { | ||
| c.principalParser = parser | ||
| } | ||
| } | ||
|
|
||
| func WithAuthorityProofs(authProofs ...delegation.Delegation) Option { | ||
| return func(c *config) { | ||
| c.authProofs = authProofs | ||
|
|
@@ -81,6 +88,10 @@ func New(id principal.Signer, svc service.Service, cons *consolidator.Consolidat | |
| ucantoOpts = append(ucantoOpts, ucanto.WithPrincipalResolver(cfg.principalResolver.ResolveDIDKey)) | ||
| } | ||
|
|
||
| if cfg.principalParser != nil { | ||
| ucantoOpts = append(ucantoOpts, ucanto.WithPrincipalParser(cfg.principalParser)) | ||
| } | ||
|
|
||
| ucantoOpts = append(ucantoOpts, ucanto.WithAuthorityProofs(cfg.authProofs...)) | ||
|
|
||
| ucantoSrv, err := ucanto.NewServer(id, ucantoOpts...) | ||
|
|
@@ -113,6 +124,28 @@ func (s *Server) ListenAndServe(addr string) error { | |
| log.Warnf("Metrics endpoint is disabled") | ||
| } | ||
|
|
||
| // Wrap with CORS middleware | ||
| corsHandler := corsMiddleware(mux) | ||
|
|
||
| log.Infof("Listening on %s", addr) | ||
| return http.ListenAndServe(addr, mux) | ||
| return http.ListenAndServe(addr, corsHandler) | ||
| } | ||
|
|
||
| // corsMiddleware adds CORS headers to allow cross-origin requests | ||
| func corsMiddleware(next http.Handler) http.Handler { | ||
| return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| // Allow all origins | ||
| w.Header().Set("Access-Control-Allow-Origin", "*") | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we'll want to restrict this once we know where the dashboard gets deployed |
||
| w.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS") | ||
| w.Header().Set("Access-Control-Allow-Headers", "*") | ||
| w.Header().Set("Access-Control-Max-Age", "86400") // 24 hours | ||
|
|
||
| // Handle preflight requests | ||
| if r.Method == "OPTIONS" { | ||
| w.WriteHeader(http.StatusOK) | ||
| return | ||
| } | ||
|
|
||
| next.ServeHTTP(w, r) | ||
| }) | ||
| } | ||
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'd love confirmation that it is expected that only Ed25519 keys are supported by default and this is the right approach.
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.
Not sure I underatand - you added RSA so I assume you've run into RSA keys?
Currenty in the browser RSA keys are generated by default, since ed25519 support did not exist when it was built.
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.
yes, I'm getting delegations signed with RSA keys from the web app. What I meant with my comment is that
go-ucantoverifiers, by default, only handle ed25519 keys.Are you saying I can set the client up in the browser to generate ed25519 keys instead? I think I'd prefer that, if ed25519 support is generally available across browsers now.