Skip to content

Commit

Permalink
Migrated /rules/rule_id/revisions and /rules/rule_id/column
Browse files Browse the repository at this point in the history
  • Loading branch information
aksareen committed May 21, 2017
1 parent e3c83e6 commit 7ee41c3
Show file tree
Hide file tree
Showing 6 changed files with 285 additions and 76 deletions.
2 changes: 0 additions & 2 deletions auslib/web/admin/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
PermissionsRequiredSignoffScheduledChangeSignoffsView, \
PermissionsRequiredSignoffScheduledChangeHistoryView
from auslib.web.admin.views.rules import RuleScheduledChangeSignoffsView, \
RuleHistoryAPIView, \
RuleScheduledChangesView, RuleScheduledChangeView, \
EnactRuleScheduledChangeView, RuleScheduledChangeHistoryView
from auslib.dockerflow import create_dockerflow_endpoints
Expand Down Expand Up @@ -109,7 +108,6 @@ def add_security_headers(response):
app.add_url_rule("/users/<username>/roles/<role>", view_func=UserRoleView.as_view("user_role"))
# Normal operations (get/update/delete) on rules can be done by id or alias...
# ...but anything to do with history must be done by id, beacuse alias may change over time
app.add_url_rule("/rules/<int:rule_id>/revisions", view_func=RuleHistoryAPIView.as_view("rules_revisions"))
app.add_url_rule("/releases", view_func=ReleasesAPIView.as_view("releases"))
app.add_url_rule("/releases/<release>", view_func=SingleReleaseView.as_view("single_release"))
app.add_url_rule("/releases/<release>/read_only", view_func=ReleaseReadOnlyView.as_view("read_only"))
Expand Down
289 changes: 238 additions & 51 deletions auslib/web/admin/swagger/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ tags:
description: "Find out more about CSRF-Token"
url: "http://mozilla-balrog.readthedocs.io/en/latest/admin_api.html#csrf-token"

- name: "Releases"
description: "Balrog Releases Description"
externalDocs:
description: "Find out more about Releases"
url: "http://mozilla-balrog.readthedocs.io/en/latest/database.html#releases"

paths:
/csrf_token:
get:
Expand Down Expand Up @@ -131,46 +137,10 @@ paths:

responses:
'200':
description: Get all Rules
description: Get json object of list all Rules with their count
schema:
type: object
required:
- count
- rules
properties:
count:
description: count of total rules fetched
type: integer
minimum: 0
format: int32
example: 1
rules:
description: array where each element is a rule object
type: array
items:
$ref: '#/definitions/RulesBaseGET'
example:
- alias: "esr45-localtest"
backgroundRate: 100
buildID: null
buildTarget: null
channel: "esr-localtest"
comment: "esr45 esr-localtest rule"
data_version: 22
distVersion: null
distribution: null
fallbackMapping: null
headerArchitecture: null
locale: null
mapping: "Firefox-45.7.0esr-build1"
osVersion: null
priority: 43
product: "Firefox"
rule_id: 308
systemCapabilities: null
update_type: "minor"
version: null
whitelist: null
$ref: '#/definitions/RulesListGET'

post:
summary: creates a new Rule in Balrog's DB
description: >
Expand Down Expand Up @@ -451,6 +421,181 @@ paths:
application/json:
Error: "REMOTE_USERNAME required"

/rules/{rule_id}/revisions:
get:
summary: Fetches all revisions of a Rule
description: Fetches list and count of all the revisions of the rule given by rule_id
tags:
- Rules
operationId: auslib.web.admin.views.mapper.rules_revisions_get
consumes: []
produces:
- application/json
externalDocs:
url: "http://mozilla-balrog.readthedocs.io/en/latest/database.html#rules"
description: "Fetches list and count of all the revisions of the rule given by rule_id"
parameters:
- name: rule_id
in: path
description: Field value to uniquely identfiy the rule
type: integer
minimum: 0
required: true
- name: page
in: query
description: Variable value used pagination of response revisions.
type: integer
minimum: 1
x-nullable: true
required: false
- name: limit
in: query
description: Variable value used for calculating offset for pagination.
type: integer
minimum: 1
x-nullable: true
required: false

responses:
'200':
description: Returns JSON object of list of rules with their count
schema:
type: object
allOf:
- $ref: "#/definitions/RulesListGET"
- type: object
properties:
rules:
description: array where each element is a rule object plus timestamp, change_id and changed_by
type: array
items:
allOf:
- type: object
required:
- timestamp
- change_id
- changed_by
properties:
timestamp:
type: integer
minimum: 0
example: 1495308
change_id:
type: integer
minimum: 0
example: 10
changed_by:
type: string
minimum: 1
maximum: 100
example: "balrogadmin"
examples:
application/json:
count: 1
rules:
- alias: "esr45-localtest"
backgroundRate: 100
buildID: null
buildTarget: null
channel: "esr-localtest"
comment: "esr45 esr-localtest rule"
changed_by: "balrogadmin"
change_id: 10
timestamp: 149530544
data_version: 22
distVersion: null
distribution: null
fallbackMapping: null
headerArchitecture: null
locale: null
mapping: "Firefox-45.7.0esr-build1"
osVersion: null
priority: 43
product: "Firefox"
rule_id: 308
systemCapabilities: null
update_type: "minor"
version: null
whitelist: null

'404':
description: Requested rule revision did not exist
schema:
$ref: '#/definitions/4xxClientErrorResponseModel'
examples:
application/json:
title: Not Found
detail: Requested rule revision does not exist
status: 404
'400':
description: "Bad Request's Response"
schema:
$ref: '#/definitions/4xxClientErrorResponseModel'
examples:
application/json:
title: Bad Request
detail: Error when trying to fetch Rule revisions
status: 400
post:
summary: Reverts the rule to a previous revision
description: >
Updates the rule identified by the rule_id to a previous revision identified by change_id. [Docs](http://mozilla-balrog.readthedocs.io/en/latest/admin_api.html#history-view-object-change-id-field)
tags:
- Rules
operationId: auslib.web.admin.views.mapper.rules_revisions_post
consumes: []
produces:
- application/json
- text/html
externalDocs:
url: "http://mozilla-balrog.readthedocs.io/en/latest/admin_api.html#history-view-object-change-id-field"
description: "Updates the rule identified by the rule_id to a previous revision identified by change_id."
parameters:
- name: rule_id
in: path
description: Field value to uniquely identfiy the rule
type: integer
minimum: 0
required: true
- name: rule_change_id
in: body
description: change_id of the Rule to revert back to
required: true
schema:
allOf:
- $ref: '#/definitions/CSRFModel'
- type: object
required:
- change_id
properties:
change_id:
type: integer
description: change_id of the rule revision to revert to
minimum: 0
example: 85142

responses:
'200':
description: Successfully reverted back the Rule
'404':
description: Requested rule revision did not exist
schema:
$ref: '#/definitions/4xxClientErrorResponseModel'
examples:
application/json:
title: Not Found
detail: Requested rule revision does not exist
status: 404
'400':
description: "Bad Request's Response"
schema:
$ref: '#/definitions/4xxClientErrorResponseModel'
examples:
application/json:
title: Bad Request
detail: Error when trying to Revert to Rule revisions
status: 400

/rules/columns/{column}:
get:
summary: Returns previous versions of the rule.
Expand Down Expand Up @@ -544,7 +689,7 @@ definitions:

CSRFModel:
title: CSRF Token
description: CSRF Token in POST
description: CSRF Token in POST/PUT or UPDATE requests
type: object
required:
- csrf_token
Expand All @@ -555,7 +700,7 @@ definitions:

RulesBaseGET:
title: GET Operations on Rules Base
description: "Sample description for /rules GET"
description: "Operations on /rules GET"
allOf:
- $ref: "#/definitions/RulesBase"
required:
Expand All @@ -580,6 +725,49 @@ definitions:
- update_type
- version

RulesListGET:
title: Rules List
description: Returns JSON object of list of rules with their count
type: object
required:
- count
- rules
properties:
count:
description: count of total rules fetched
type: integer
minimum: 0
format: int32
example: 1
rules:
description: array where each element is a rule object
type: array
items:
$ref: '#/definitions/RulesBaseGET'
example:
- alias: "esr45-localtest"
backgroundRate: 100
buildID: null
buildTarget: null
channel: "esr-localtest"
comment: "esr45 esr-localtest rule"
data_version: 22
distVersion: null
distribution: null
fallbackMapping: null
headerArchitecture: null
locale: null
mapping: "Firefox-45.7.0esr-build1"
osVersion: null
priority: 43
product: "Firefox"
rule_id: 308
systemCapabilities: null
update_type: "minor"
version: null
whitelist: null


RulesBase:
title: Rules object definition
description: Balrog's Rule Attributes
Expand All @@ -591,8 +779,8 @@ definitions:
properties:
rule_id:
description: The id of the rule. This id is necessary to make changes to the rule through the REST API.
type: integer
format: int32
type: ["integer", "string"]
format: rule_id
readOnly: true
example: 10

Expand All @@ -615,6 +803,13 @@ definitions:
format: backgroundRate
example: 100

data_version:
description: the version number of rule
type: ["integer", "string"]
format: data_version
readOnly: true
example: 1

update_type:
description: "The update_type to use in the XML response. It's very rare for a rule to use anything other than 'minor' these days."
type: string
Expand Down Expand Up @@ -695,14 +890,6 @@ definitions:
maxLength: 10
example: 'PPC'

data_version:
description: the version number of rule
type: integer
format: int32
readOnly: true
minimum: 1
example: 1

comment:
description: A string describing the purpose of the rule. Not always necessary for obvious rules.
type: ["string", "null"]
Expand Down

0 comments on commit 7ee41c3

Please sign in to comment.