Skip to content

Commit

Permalink
feat(auth): Enable/disable authentication for READ apis via env variable
Browse files Browse the repository at this point in the history
Signed-off-by: deo002 <[email protected]>
  • Loading branch information
deo002 committed Aug 13, 2024
1 parent b56de6e commit 82b0c32
Show file tree
Hide file tree
Showing 11 changed files with 595 additions and 87 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
TOKEN_HOUR_LIFESPAN=24
# Secret key to sign tokens (openssl rand -hex 32)
API_SECRET=some-random-string
READ_API_AUTHENTICATION_ENABLED=false
131 changes: 125 additions & 6 deletions cmd/laas/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,42 @@ const docTemplate = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/apiCollection": {
"get": {
"description": "Returns the apis which require authentication and which do not",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"API Collection"
],
"summary": "Returns the apis which require authentication and which do not",
"operationId": "getAPICollection",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.APICollectionResponse"
}
},
"500": {
"description": "Unable to parse swagger docs",
"schema": {
"$ref": "#/definitions/models.LicenseError"
}
}
}
}
},
"/audits": {
"get": {
"security": [
{
"ApiKeyAuth": []
"ApiKeyAuth": [],
"{}": []
}
],
"description": "Get all audit records from the server",
Expand Down Expand Up @@ -76,7 +107,8 @@ const docTemplate = `{
"get": {
"security": [
{
"ApiKeyAuth": []
"ApiKeyAuth": [],
"{}": []
}
],
"description": "Get a specific audit records by ID",
Expand Down Expand Up @@ -126,7 +158,8 @@ const docTemplate = `{
"get": {
"security": [
{
"ApiKeyAuth": []
"ApiKeyAuth": [],
"{}": []
}
],
"description": "Get changelogs of an audit record",
Expand Down Expand Up @@ -182,7 +215,8 @@ const docTemplate = `{
"get": {
"security": [
{
"ApiKeyAuth": []
"ApiKeyAuth": [],
"{}": []
}
],
"description": "Get a specific changelog of an audit record by its ID",
Expand Down Expand Up @@ -267,6 +301,12 @@ const docTemplate = `{
},
"/licenses": {
"get": {
"security": [
{
"ApiKeyAuth": [],
"{}": []
}
],
"description": "Filter licenses based on different parameters",
"consumes": [
"application/json"
Expand Down Expand Up @@ -452,7 +492,8 @@ const docTemplate = `{
"get": {
"security": [
{
"ApiKeyAuth": []
"ApiKeyAuth": [],
"{}": []
}
],
"description": "Export all licenses as a json file",
Expand Down Expand Up @@ -550,6 +591,12 @@ const docTemplate = `{
},
"/licenses/preview": {
"get": {
"security": [
{
"ApiKeyAuth": [],
"{}": []
}
],
"description": "Get shortnames of all active licenses from the service",
"consumes": [
"application/json"
Expand Down Expand Up @@ -595,6 +642,12 @@ const docTemplate = `{
},
"/licenses/{shortname}": {
"get": {
"security": [
{
"ApiKeyAuth": [],
"{}": []
}
],
"description": "Get a single license by its shortname",
"consumes": [
"application/json"
Expand Down Expand Up @@ -743,6 +796,12 @@ const docTemplate = `{
},
"/obligation_maps/license/{license}": {
"get": {
"security": [
{
"ApiKeyAuth": [],
"{}": []
}
],
"description": "Get obligation maps for a given license shortname",
"consumes": [
"application/json"
Expand Down Expand Up @@ -782,6 +841,12 @@ const docTemplate = `{
},
"/obligation_maps/topic/{topic}": {
"get": {
"security": [
{
"ApiKeyAuth": [],
"{}": []
}
],
"description": "Get obligation maps for a given obligation topic",
"consumes": [
"application/json"
Expand Down Expand Up @@ -943,6 +1008,12 @@ const docTemplate = `{
},
"/obligations": {
"get": {
"security": [
{
"ApiKeyAuth": [],
"{}": []
}
],
"description": "Get all active obligations from the service",
"consumes": [
"application/json"
Expand Down Expand Up @@ -1061,6 +1132,12 @@ const docTemplate = `{
},
"/obligations/export": {
"get": {
"security": [
{
"ApiKeyAuth": [],
"{}": []
}
],
"description": "Export all obligations as a json file",
"produces": [
"application/json"
Expand Down Expand Up @@ -1156,6 +1233,12 @@ const docTemplate = `{
},
"/obligations/preview": {
"get": {
"security": [
{
"ApiKeyAuth": [],
"{}": []
}
],
"description": "Get topic and type of all active obligations from the service",
"consumes": [
"application/json"
Expand Down Expand Up @@ -1189,6 +1272,12 @@ const docTemplate = `{
},
"/obligations/{topic}": {
"get": {
"security": [
{
"ApiKeyAuth": [],
"{}": []
}
],
"description": "Get an active based on given topic",
"consumes": [
"application/json"
Expand Down Expand Up @@ -1332,7 +1421,8 @@ const docTemplate = `{
"get": {
"security": [
{
"ApiKeyAuth": []
"ApiKeyAuth": [],
"{}": []
}
],
"description": "Fetches audits corresponding to an obligation",
Expand Down Expand Up @@ -1392,6 +1482,12 @@ const docTemplate = `{
},
"/search": {
"post": {
"security": [
{
"ApiKeyAuth": [],
"{}": []
}
],
"description": "Search licenses on different filters and algorithms",
"consumes": [
"application/json"
Expand Down Expand Up @@ -1591,6 +1687,29 @@ const docTemplate = `{
"datatypes.JSONType-models_LicenseDBSchemaExtension": {
"type": "object"
},
"models.APICollection": {
"type": "object",
"properties": {
"authenticated": {
"type": "object"
},
"unAuthenticated": {
"type": "object"
}
}
},
"models.APICollectionResponse": {
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/models.APICollection"
},
"status": {
"type": "integer",
"example": 200
}
}
},
"models.Audit": {
"type": "object",
"properties": {
Expand Down
Loading

0 comments on commit 82b0c32

Please sign in to comment.