diff --git a/api/schema.go b/api/schema.go new file mode 100644 index 0000000..b9fe6d4 --- /dev/null +++ b/api/schema.go @@ -0,0 +1,231 @@ +package api + +import "encoding/json" + +// Fallback Schema, Only to be used if we encounter a Broken Server (v5.0), Not API Stable! +var ResourceSchemas = map[string]json.RawMessage{ + "v5-default": json.RawMessage(` +{ + "resource": { + "type": "object", + "required": ["name"], + "properties": { + "name": { + "type": "string", + "maxLength": 255 + }, + "username": { + "type": "string", + "maxLength": 255, + "nullable": true + }, + "uris": { + "type": "array", + "items": { + "type": "string", + "maxLength": 1024, + "nullable": true + } + }, + "description": { + "type": "string", + "maxLength": 10000, + "nullable": true + } + } + }, + "secret": { + "type": "object", + "required": ["password"], + "properties": { + "object_type": { + "type": "string", + "enum": ["PASSBOLT_SECRET_DATA"] + }, + "password": { + "type": "string", + "maxLength": 4096, + "nullable": true + }, + "description": { + "type": "string", + "maxLength": 10000, + "nullable": true + } + } + } +}`), + "v5-password-string": json.RawMessage(` +{ + "resource": { + "type": "object", + "required": ["name"], + "properties": { + "name": { + "type": "string", + "maxLength": 255 + }, + "username": { + "type": "string", + "maxLength": 255, + "nullable": true + }, + "uris": { + "type": "array", + "items": { + "type": "string", + "maxLength": 1024, + "nullable": true + } + }, + "description": { + "type": "string", + "maxLength": 10000, + "nullable": true + } + } + }, + "secret": { + "type": "string", + "maxLength": 4096 + } +}`), + "v5-default-with-totp": json.RawMessage(` +{ + "resource": { + "type": "object", + "required": ["name"], + "properties": { + "name": { + "type": "string", + "maxLength": 255 + }, + "username": { + "type": "string", + "maxLength": 255, + "nullable": true + }, + "uris": { + "type": "array", + "items": { + "type": "string", + "maxLength": 1024, + "nullable": true + } + }, + "description": { + "type": "string", + "maxLength": 10000, + "nullable": true + } + } + }, + "secret": { + "type": "object", + "required": ["totp"], + "properties": { + "object_type": { + "type": "string", + "enum": ["PASSBOLT_SECRET_DATA"] + }, + "password": { + "type": "string", + "maxLength": 4096, + "nullable": true + }, + "description": { + "type": "string", + "maxLength": 10000, + "nullable": true + }, + "totp": { + "type": "object", + "required": ["secret_key", "digits", "algorithm"], + "properties": { + "algorithm": { + "type": "string", + "minLength": 4, + "maxLength": 6 + }, + "secret_key": { + "type": "string", + "maxLength": 1024 + }, + "digits": { + "type": "number", + "minimum": 6, + "maximum": 8 + }, + "period": { + "type": "number" + } + } + } + } + } +}`), + "v5-totp-standalone": json.RawMessage(` +{ + "resource": { + "type": "object", + "required": ["name"], + "properties": { + "name": { + "type": "string", + "maxLength": 255 + }, + "username": { + "type": "string", + "maxLength": 255, + "nullable": true + }, + "uris": { + "type": "array", + "items": { + "type": "string", + "maxLength": 1024, + "nullable": true + } + }, + "description": { + "type": "string", + "maxLength": 10000, + "nullable": true + } + } + }, + "secret": { + "type": "object", + "required": ["totp"], + "properties": { + "object_type": { + "type": "string", + "enum": ["PASSBOLT_SECRET_DATA"] + }, + "totp": { + "type": "object", + "required": ["secret_key", "digits", "algorithm"], + "properties": { + "algorithm": { + "type": "string", + "minLength": 4, + "maxLength": 6 + }, + "secret_key": { + "type": "string", + "maxLength": 1024 + }, + "digits": { + "type": "number", + "minimum": 6, + "maximum": 8 + }, + "period": { + "type": "number" + } + } + } + } + } +}`), +} diff --git a/api/schema_test.go b/api/schema_test.go new file mode 100644 index 0000000..a9069e4 --- /dev/null +++ b/api/schema_test.go @@ -0,0 +1,18 @@ +package api + +import ( + "encoding/json" + "testing" +) + +func TestResourceJsonSchema(t *testing.T) { + for slug, schema := range ResourceSchemas { + var schemaDefinition ResourceTypeSchema + err := json.Unmarshal(schema, &schemaDefinition) + if err != nil { + t.Errorf("Error While Parsing Resource Schema %v: %v", slug, err) + } else { + t.Logf("Schema for type %v is ok", slug) + } + } +}