Uploaded image for project: 'Couchbase Gateway'
  1. Couchbase Gateway
  2. CBG-751

Improve REST-based sgcollect_info options validation

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Fixed
    • Major
    • 2.8.0
    • None
    • SyncGateway
    • Security Level: Public
    • None
    • CBG Sprint 43
    • 2

    Description

      The REST endpoint for sgcollect will accept the request for an invalid value of redact_level, and you don't know about it until the script exists and logs the error, which you may not see.

      $ curl -X POST http://localhost:4985/_sgcollect_info -H 'Content-Type: application/json' -d '{"redact_level":"test","output_dir":"/tmp"}'
      {"status":"started"}
      

      2020-03-04T16:48:12.393Z [INF] HTTP:  #003: POST /_sgcollect_info (as ADMIN)
      2020-03-04T16:48:12.397Z [INF] Admin: sgcollect_info started with args: [ --log-redaction-level test --sync-gateway-executable /Users/benbrooks/dev/sync_gateway/master/godeps/src/github.com/couchbase/sync_gateway/sync_gateway /tmp/sgcollectinfo-2020-03-04t164812-sg@10.100.196.152.zip ]
      2020-03-04T16:48:12.397Z [INF] HTTP+: #003:     --> 200   (3.5 ms)
      2020-03-04T16:48:12.717Z [INF] HTTP:  #004: GET / (as ADMIN)
      2020-03-04T16:48:12.717Z [INF] HTTP+: #004:     --> 200   (0.0 ms)
      2020-03-04T16:48:12.717Z [INF] sgcollect_info: Usage: sgcollect_info [options] output_file.zip
      2020-03-04T16:48:12.717Z [INF] sgcollect_info: 
      2020-03-04T16:48:12.717Z [INF] sgcollect_info: - Linux/Windows/OSX:
      2020-03-04T16:48:12.717Z [INF] sgcollect_info:     sgcollect_info output_file.zip
      2020-03-04T16:48:12.717Z [INF] sgcollect_info:     sgcollect_info -v output_file.zip
      2020-03-04T16:48:12.717Z [INF] sgcollect_info: 
      2020-03-04T16:48:12.717Z [INF] sgcollect_info: sgcollect_info: error: Invalid redaction level. Only 'none' and 'partial' are supported.
      2020-03-04T16:48:12.717Z [INF] sgcollect_info: Trying Sync Gateway URL: http://127.0.0.1:4985
      2020-03-04T16:48:12.723Z [ERR] sgcollect_info failed after 325.968987ms with reason: exit status 2. Check warning level logs for more information. -- rest.(*sgCollect).Start.func3() at sgcollect.go:138
      

       

      Do upfront validation on redact_level before we kick of sgcollect_info:

      $ curl -X POST http://localhost:4985/_sgcollect_info -H 'Content-Type: application/json' -d '{"redact_level":"test"}'
      {"error":"Bad Request","reason":"Invalid options used for sgcollect_info: []error{'redact_level' must be either 'none' or 'partial'}"} 

       

      Also return all validation errors at once, rather than only the first one:

      $ curl -X POST http://localhost:4985/_sgcollect_info -H 'Content-Type: application/json' -d '{"redact_level":"test","upload":true}'
      {"error":"Bad Request","reason":"Invalid options used for sgcollect_info: []error{'customer' must be set if upload is true, 'redact_level' must be either 'none' or 'partial'}"} 

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            ben.brooks Ben Brooks
            ben.brooks Ben Brooks
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty