-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactoring: Server API service (#152)
* refactor: rename var `mysql*` to `sql*` The current variable name `mysqlStore` and `mysqlStoreCh` can generate confusion as it comes from a factory store that support multiple databases (MySQL and Postgres). Signed-off-by: Kairo de Araujo <kairo.araujo@testifysec.com> * refactor: simplify archivista, move API to server This commit simplifies the archivista cmd (`cmd/archivista`), removing the API logic to the server, where all handlers for HTTP requests are implemented. This also includes the API Swagger documentation. Signed-off-by: Kairo Araujo <kairo.araujo@testifysec.com> * refactoring: rename store APIs to upload This refactoring focuses on the code readability and maintainability easier for new contributors. `Store` -> `Upload` `StoreWithHeaders` -> `UploadWithHeaders` The `Store` will be exclusive for the Store method used by `metadataStore` and `objectStore`, causing less confusion. It renames the functions but keeps backward compatibility to allow the current users the possibility to migrate. Signed-off-by: Kairo Araujo <kairo.araujo@testifysec.com> * tests: Add unit tests for server.go This add unit tests for main functions for server.go Signed-off-by: Kairo Araujo <kairo.araujo@testifysec.com> * fix: Add more consistent HTTP errors This commit fixes some status codes that can cause misunderstanding. Some errors were returning Bad Request (400) even when the user sends a correct request. The errors originating from the infrastructure or error during operations should raise Internal Server Error (500) as they are not expected. Unit tests are included to avoid regression Signed-off-by: Kairo Araujo <kairo.araujo@testifysec.com> --------- Signed-off-by: Kairo de Araujo <kairo.araujo@testifysec.com> Signed-off-by: Kairo Araujo <kairo.araujo@testifysec.com>
- Loading branch information
1 parent
a059114
commit fe1b2b3
Showing
13 changed files
with
1,101 additions
and
55 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,230 @@ | ||
// Package docs Code generated by swaggo/swag. DO NOT EDIT | ||
package docs | ||
|
||
import "github.com/swaggo/swag" | ||
|
||
const docTemplate = `{ | ||
"schemes": {{ marshal .Schemes }}, | ||
"swagger": "2.0", | ||
"info": { | ||
"description": "{{escape .Description}}", | ||
"title": "{{.Title}}", | ||
"contact": { | ||
"name": "Archivista Contributors", | ||
"url": "https://github.com/in-toto/archivista/issues/new" | ||
}, | ||
"license": { | ||
"url": "https://opensource.org/licenses/Apache-2" | ||
}, | ||
"version": "{{.Version}}" | ||
}, | ||
"host": "{{.Host}}", | ||
"basePath": "{{.BasePath}}", | ||
"paths": { | ||
"/donwload/{gitoid}": { | ||
"post": { | ||
"description": "download an attestation", | ||
"produces": [ | ||
"application/json" | ||
], | ||
"summary": "Download", | ||
"deprecated": true, | ||
"responses": { | ||
"200": { | ||
"description": "OK", | ||
"schema": { | ||
"$ref": "#/definitions/dsse.Envelope" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"/upload": { | ||
"post": { | ||
"description": "stores an attestation", | ||
"produces": [ | ||
"application/json" | ||
], | ||
"summary": "Store", | ||
"deprecated": true, | ||
"responses": { | ||
"200": { | ||
"description": "OK", | ||
"schema": { | ||
"$ref": "#/definitions/api.StoreResponse" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"/v1/donwload/{gitoid}": { | ||
"post": { | ||
"description": "download an attestation", | ||
"produces": [ | ||
"application/json" | ||
], | ||
"tags": [ | ||
"attestation" | ||
], | ||
"summary": "Download", | ||
"responses": { | ||
"200": { | ||
"description": "OK", | ||
"schema": { | ||
"$ref": "#/definitions/dsse.Envelope" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"/v1/query": { | ||
"post": { | ||
"description": "GraphQL query", | ||
"produces": [ | ||
"application/json" | ||
], | ||
"tags": [ | ||
"graphql" | ||
], | ||
"summary": "Query GraphQL", | ||
"responses": { | ||
"200": { | ||
"description": "OK", | ||
"schema": { | ||
"$ref": "#/definitions/archivista.Resolver" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"/v1/upload": { | ||
"post": { | ||
"description": "stores an attestation", | ||
"produces": [ | ||
"application/json" | ||
], | ||
"tags": [ | ||
"attestation" | ||
], | ||
"summary": "Store", | ||
"responses": { | ||
"200": { | ||
"description": "OK", | ||
"schema": { | ||
"$ref": "#/definitions/api.StoreResponse" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"definitions": { | ||
"api.StoreResponse": { | ||
"type": "object", | ||
"properties": { | ||
"gitoid": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"archivista.Resolver": { | ||
"type": "object" | ||
}, | ||
"dsse.Envelope": { | ||
"type": "object", | ||
"properties": { | ||
"payload": { | ||
"type": "array", | ||
"items": { | ||
"type": "integer" | ||
} | ||
}, | ||
"payloadType": { | ||
"type": "string" | ||
}, | ||
"signatures": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/dsse.Signature" | ||
} | ||
} | ||
} | ||
}, | ||
"dsse.Signature": { | ||
"type": "object", | ||
"properties": { | ||
"certificate": { | ||
"type": "array", | ||
"items": { | ||
"type": "integer" | ||
} | ||
}, | ||
"intermediates": { | ||
"type": "array", | ||
"items": { | ||
"type": "array", | ||
"items": { | ||
"type": "integer" | ||
} | ||
} | ||
}, | ||
"keyid": { | ||
"type": "string" | ||
}, | ||
"sig": { | ||
"type": "array", | ||
"items": { | ||
"type": "integer" | ||
} | ||
}, | ||
"timestamps": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/dsse.SignatureTimestamp" | ||
} | ||
} | ||
} | ||
}, | ||
"dsse.SignatureTimestamp": { | ||
"type": "object", | ||
"properties": { | ||
"data": { | ||
"type": "array", | ||
"items": { | ||
"type": "integer" | ||
} | ||
}, | ||
"type": { | ||
"$ref": "#/definitions/dsse.SignatureTimestampType" | ||
} | ||
} | ||
}, | ||
"dsse.SignatureTimestampType": { | ||
"type": "string", | ||
"enum": [ | ||
"tsp" | ||
], | ||
"x-enum-varnames": [ | ||
"TimestampRFC3161" | ||
] | ||
} | ||
} | ||
}` | ||
|
||
// SwaggerInfo holds exported Swagger Info so clients can modify it | ||
var SwaggerInfo = &swag.Spec{ | ||
Version: "v1", | ||
Host: "", | ||
BasePath: "", | ||
Schemes: []string{}, | ||
Title: "Archivista API", | ||
Description: "Archivista API", | ||
InfoInstanceName: "swagger", | ||
SwaggerTemplate: docTemplate, | ||
LeftDelim: "{{", | ||
RightDelim: "}}", | ||
} | ||
|
||
func init() { | ||
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) | ||
} |
Oops, something went wrong.