Skip to content

Commit

Permalink
Remove RS_ prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Mar 3, 2025
1 parent bd5c9a9 commit 3973bb3
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
18 changes: 9 additions & 9 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ The rageshake server will respond with a specific JSON payload when encountering
```json
{
"error": "A human readable error string.",
"errcode": "RS_UNKNOWN",
"errcode": "UNKNOWN",
"policy_url": "https://github.com/matrix-org/rageshake/blob/master/docs/blocked_rageshake.md"
}
```
Expand All @@ -100,16 +100,16 @@ Where the fields are as follows:

### Error codes

- `RS_UNKNOWN` is a catch-all error when the appliation does not have a specific error.
- `RS_METHOD_NOT_ALLOWED` is reported when you have used the wrong method for an endpoint. E.g. GET instead of POST.
- `RS_DISALLOWED_APP` is reported when a report was rejected due to the report being sent from an unsupported
- `UNKNOWN` is a catch-all error when the appliation does not have a specific error.
- `METHOD_NOT_ALLOWED` is reported when you have used the wrong method for an endpoint. E.g. GET instead of POST.
- `DISALLOWED_APP` is reported when a report was rejected due to the report being sent from an unsupported
app (see the `allowed_app_names` config option).
- `RS_BAD_HEADER` is reported when a header was not able to be parsed, such as `Content-Length`.
- `RS_CONTENT_TOO_LARGE` is reported when the reported content size is too large.
- `RS_BAD_CONTENT` is reported when the reports content could not be parsed.
- `RS_REJECTED` is reported when the submission could be understood but was rejected by `rejection_conditions`.
- `BAD_HEADER` is reported when a header was not able to be parsed, such as `Content-Length`.
- `CONTENT_TOO_LARGE` is reported when the reported content size is too large.
- `BAD_CONTENT` is reported when the reports content could not be parsed.
- `REJECTED` is reported when the submission could be understood but was rejected by `rejection_conditions`.
This is the default value, see below for more information.

In addition to these error codes, the configuration allows application developers to specify specific error codes
for report rejection under the `RS_REJECTED_*` namespace. (see the `rejection_conditions` config option). Consult the
for report rejection under the `REJECTED_*` namespace. (see the `rejection_conditions` config option). Consult the
administrator of your rageshake server in order to determine what error codes may be presented.
14 changes: 7 additions & 7 deletions errors.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package main
const (
// ErrCodeBadContent is reported when the reports content could not be parsed.
ErrCodeBadContent = "RS_BAD_CONTENT";
ErrCodeBadContent = "BAD_CONTENT";
// ErrCodeBadHeader is reported when a header was not able to be parsed.
ErrCodeBadHeader = "RS_BAD_HEADER";
ErrCodeBadHeader = "BAD_HEADER";
// ErrCodeContentTooLarge is reported when the reported content size is too large.
ErrCodeContentTooLarge = "RS_CONTENT_TOO_LARGE";
ErrCodeContentTooLarge = "CONTENT_TOO_LARGE";
// ErrCodeDisallowedApp is reported when a report was rejected due to the report being sent from an unsupported
ErrCodeDisallowedApp = "RS_DISALLOWED_APP";
ErrCodeDisallowedApp = "DISALLOWED_APP";
// ErrCodeMethodNotAllowed is reported when you have used the wrong method for an endpoint.
ErrCodeMethodNotAllowed = "RS_METHOD_NOT_ALLOWED";
ErrCodeMethodNotAllowed = "METHOD_NOT_ALLOWED";
// ErrCodeRejected is reported when the submission could be understood but was rejected by RejectionConditions.
ErrCodeRejected = "RS_REJECTED";
ErrCodeRejected = "REJECTED";
// ErrCodeUnknown is a catch-all error when the appliation does not have a specific error.
ErrCodeUnknown = "RS_UNKNOWN";
ErrCodeUnknown = "UNKNOWN";
)
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ type RejectionCondition struct {
UserTextMatch string `yaml:"usertext"`
// Send this text to the client-side to inform the user why the server rejects the rageshake. Uses a default generic value if empty.
Reason string `yaml:"reason"`
// Send this text to the client-side to inform the user why the server rejects the rageshake. Uses a default error code RS_REJECTED if empty.
// Send this text to the client-side to inform the user why the server rejects the rageshake. Uses a default error code REJECTED if empty.
ErrorCode string `yaml:"errorcode"`
}

Expand Down Expand Up @@ -355,8 +355,8 @@ func loadConfig(configPath string) (*config, error) {
}

for idx, condition := range cfg.RejectionConditions {
if condition.ErrorCode != "" && !strings.HasPrefix(condition.ErrorCode, "RS_REJECTED_") {
return nil, fmt.Errorf("Rejected condition %d was invalid. `errorcode` must be use the namespace RS_REJECTED_", idx);
if condition.ErrorCode != "" && !strings.HasPrefix(condition.ErrorCode, "REJECTED_") {
return nil, fmt.Errorf("Rejected condition %d was invalid. `errorcode` must be use the namespace REJECTED_", idx);
}
}
return &cfg, nil
Expand Down
8 changes: 4 additions & 4 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ func TestConfigRejectionCondition(t *testing.T) {
Version: "0.1.2",
Label: "nightly",
Reason: "no nightlies",
ErrorCode: "RS_BAD_VERSION",
ErrorCode: "BAD_VERSION",
},
{
App: "block-my-app",
},
{
UserTextMatch: "(\\w{4}\\s){11}\\w{4}",
Reason: "it matches a recovery key and recovery keys are private",
ErrorCode: "RS_EXPOSED_RECOVERY_KEY",
ErrorCode: "EXPOSED_RECOVERY_KEY",
},
},
}
Expand Down Expand Up @@ -55,7 +55,7 @@ func TestConfigRejectionCondition(t *testing.T) {
Data: map[string]string{
"Version": "0.1.2",
"ExpectedRejectReason": "no nightlies",
"ExpectedErrorCode": "RS_BAD_VERSION",
"ExpectedErrorCode": "BAD_VERSION",
},
},
{
Expand Down Expand Up @@ -95,7 +95,7 @@ func TestConfigRejectionCondition(t *testing.T) {
UserText: "Looks like a recover key abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd",
Data: map[string]string{
"ExpectedRejectReason": "it matches a recovery key and recovery keys are private",
"ExpectedErrorCode": "RS_EXPOSED_RECOVERY_KEY",
"ExpectedErrorCode": "EXPOSED_RECOVERY_KEY",
},
},
}
Expand Down
8 changes: 4 additions & 4 deletions rageshake.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ allowed_app_names: []
# If any submission matches one of these rejection conditions, the submission is rejected.
# A condition is made by an union of optional fields: app, version, labels, user text. They all need to match for rejecting the rageshake
# It can also contain an optional reason to explain why this server is rejecting a user's submission.
# An errorcode can be provided to give a precise machine-readable error description under the `RS_REJECTED_` namespace.
# Otherwise, this defaults to RS_REJECTED.
# An errorcode can be provided to give a precise machine-readable error description under the `REJECTED_` namespace.
# Otherwise, this defaults to REJECTED.
rejection_conditions:
- app: my-app
version: "0.4.9" # if the submission has a Version which is exactly this value, reject the submission.
Expand All @@ -24,10 +24,10 @@ rejection_conditions:
version: "0.4.9"
label: "nightly" # both label and Version must match for this condition to be true
reason: "this server does not accept rageshakes from nightlies"
errorcode: "RS_REJECTED_BAD_VERSION"
errorcode: "REJECTED_BAD_VERSION"
- usertext: "(\\w{4}\\s){11}\\w{4}" # reject text containing possible recovery keys
reason: "it matches a recovery key and recovery keys are private"
errorcode: "RS_REJECTED_UNEXPECTED_RECOVERY_KEY"
errorcode: "REJECTED_UNEXPECTED_RECOVERY_KEY"

# a GitHub personal access token (https://github.com/settings/tokens), which
# will be used to create a GitHub issue for each report. It requires
Expand Down
2 changes: 1 addition & 1 deletion submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (s *submitServer) handleSubmission(w http.ResponseWriter, req *http.Request
log.Printf("Unable to remove report dir %s after rejected upload: %v\n",
reportDir, err)
}
writeError(w, 400, submitErrorResponse{"This server does not accept rageshakes from your application.", "RS_DISALLOWED_APP", "https://github.com/matrix-org/rageshake/blob/master/docs/blocked_rageshake.md"})
writeError(w, 400, submitErrorResponse{"This server does not accept rageshakes from your application.", ErrCodeDisallowedApp, "https://github.com/matrix-org/rageshake/blob/master/docs/blocked_rageshake.md"})
return
}
rejection, code := s.cfg.matchesRejectionCondition(p)
Expand Down

0 comments on commit 3973bb3

Please sign in to comment.