-
Notifications
You must be signed in to change notification settings - Fork 20
Migrate Forge bridge to @forge/kvs and add /confluence forge reset command #231
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8ee76da
Migrate Forge bridge to @forge/kvs and add /confluence forge reset co…
fbad9f0
coderabbit ai feedbac
e20a6b9
Add small fix for mising reset url
8286908
lint
1f5840c
update readme
14cd363
remove redundant regenerate button
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 |
|---|---|---|
|
|
@@ -847,12 +847,25 @@ func (fm *FlowManager) submitForgeBridgeURLs(_ *flow.Flow, submitted map[string] | |
| return "", nil, nil, errors.New("Forge Bridge Shared Secret is not set on this plugin; reload the plugin to regenerate it") | ||
| } | ||
|
|
||
| if err := postForgeRegister(registerURL, cfg.ForgeSharedSecret); err != nil { | ||
| urls, err := postForgeRegister(registerURL, cfg.ForgeSharedSecret) | ||
| if err != nil { | ||
| errorList["register_url"] = err.Error() | ||
| return "", nil, errorList, nil | ||
| } | ||
|
|
||
| cfg.ForgeDrainURL = drainURL | ||
| cfg.ForgeRegisterURL = registerURL | ||
| if urls != nil { | ||
| if isForgeWebtriggerURL(urls.Reset) { | ||
| cfg.ForgeResetURL = urls.Reset | ||
| } | ||
| if isForgeWebtriggerURL(urls.Drain) { | ||
| cfg.ForgeDrainURL = urls.Drain | ||
| } | ||
| if isForgeWebtriggerURL(urls.Register) { | ||
| cfg.ForgeRegisterURL = urls.Register | ||
| } | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| cfg.Sanitize() | ||
| configMap, err := cfg.ToMap() | ||
| if err != nil { | ||
|
|
@@ -885,18 +898,29 @@ func isForgeWebtriggerURL(raw string) bool { | |
| return strings.HasPrefix(u.Path, "/public/") | ||
| } | ||
|
|
||
| func postForgeRegister(registerURL, secret string) error { | ||
| type ForgeWebtriggerURLs struct { | ||
| Drain string `json:"drain"` | ||
| Register string `json:"register"` | ||
| Reset string `json:"reset"` | ||
| } | ||
|
|
||
| type forgeRegisterResponse struct { | ||
| OK bool `json:"ok"` | ||
| URLs ForgeWebtriggerURLs `json:"urls"` | ||
| } | ||
|
|
||
| func postForgeRegister(registerURL, secret string) (*ForgeWebtriggerURLs, error) { | ||
| body, err := json.Marshal(map[string]string{"secret": secret}) | ||
| if err != nil { | ||
| return errors.Wrap(err, "failed to encode register payload") | ||
| return nil, errors.Wrap(err, "failed to encode register payload") | ||
| } | ||
|
|
||
| ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) | ||
| defer cancel() | ||
|
|
||
| req, err := http.NewRequestWithContext(ctx, http.MethodPost, registerURL, bytes.NewReader(body)) | ||
| if err != nil { | ||
| return errors.Wrap(err, "failed to build register request") | ||
| return nil, errors.Wrap(err, "failed to build register request") | ||
| } | ||
| req.Header.Set("Content-Type", "application/json") | ||
|
|
||
|
|
@@ -909,21 +933,24 @@ func postForgeRegister(registerURL, secret string) error { | |
| } | ||
| resp, err := client.Do(req) | ||
| if err != nil { | ||
| return errors.Wrap(err, "failed to reach register URL") | ||
| return nil, errors.Wrap(err, "failed to reach register URL") | ||
| } | ||
| defer resp.Body.Close() | ||
|
|
||
| switch resp.StatusCode { | ||
| case http.StatusOK, http.StatusNoContent: | ||
| return nil | ||
| respBody, _ := io.ReadAll(io.LimitReader(resp.Body, 4096)) | ||
| var parsed forgeRegisterResponse | ||
|
Member
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. nit: Might be nice to also do the same check for |
||
| _ = json.Unmarshal(respBody, &parsed) // tolerate older bridges with no urls field | ||
| return &parsed.URLs, nil | ||
| case http.StatusConflict: | ||
| return errors.New("Forge bridge is already registered with a different shared secret. Have the Forge admin delete the `mm.registered` and `mm.drainSecret` storage keys (`forge storage delete mm.registered && forge storage delete mm.drainSecret`), then re-run this wizard.") | ||
| return nil, errors.New("Forge bridge is already registered with a different shared secret. Run `/confluence forge reset` to rotate, or if that fails ask your Forge admin to run `forge invoke -f wipeRegistrationFn -e <env>`, then re-run this wizard.") | ||
| default: | ||
| respBody, _ := io.ReadAll(io.LimitReader(resp.Body, 512)) | ||
| snippet := strings.TrimSpace(string(respBody)) | ||
| if snippet == "" { | ||
| snippet = resp.Status | ||
| } | ||
| return errors.Errorf("bridge rejected registration (%d): %s", resp.StatusCode, snippet) | ||
| return nil, errors.Errorf("bridge rejected registration (%d): %s", resp.StatusCode, snippet) | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.