Skip to content

Commit

Permalink
Add storage. (heroiclabs#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
mofirouz authored and zyro committed Apr 22, 2018
1 parent 97ac0c5 commit 093cf4a
Show file tree
Hide file tree
Showing 120 changed files with 25,955 additions and 448 deletions.
31 changes: 30 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@
[[constraint]]
name = "github.com/gobuffalo/packr"
revision = "6434a292ac52e6964adebfdce3f9ce6d9f16be01"

[[constraint]]
name = "github.com/stretchr/testify"
version = "~1.1.4"
512 changes: 227 additions & 285 deletions api/api.pb.go

Large diffs are not rendered by default.

14 changes: 6 additions & 8 deletions api/api.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 12 additions & 29 deletions api/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ service Nakama {

// Delete one or more objects by ID or username.
rpc DeleteStorageObjects (DeleteStorageObjectsRequest) returns (google.protobuf.Empty) {
option (google.api.http).delete = "/v2/storage";
option (google.api.http) = {
put: "/v2/storage/delete",
body: "*"
};
}

// Fetch the current user's account.
Expand Down Expand Up @@ -270,7 +273,7 @@ service Nakama {
option (google.api.http).get = "/v2/notification";
}

// List collections of storage objects.
// List publicly readable storage objects in a given collection.
rpc ListStorageObjects (ListStorageObjectsRequest) returns (StorageObjectList) {
option (google.api.http) = {
get: "/v2/storage/{collection}",
Expand Down Expand Up @@ -601,7 +604,7 @@ message DeleteStorageObjectId {
// Batch delete storage objects.
message DeleteStorageObjectsRequest {
// Batch of storage objects.
repeated DeleteStorageObjectId objectIds = 1;
repeated DeleteStorageObjectId object_ids = 1;
}

// A friend of a user.
Expand Down Expand Up @@ -711,7 +714,7 @@ message ListNotificationsRequest {
string cacheable_cursor = 2; // value from NotificationList.cacheable_cursor.
}

// List storage objects by user ID or collection or both.
// List publicly readable storage objects in a given collection.
message ListStorageObjectsRequest {
// ID of the user.
string user_id = 1;
Expand Down Expand Up @@ -780,7 +783,7 @@ message ReadStorageObjectId {
// Batch get storage objects.
message ReadStorageObjectsRequest {
// Batch of storage objects.
repeated ReadStorageObjectId objectIds = 1;
repeated ReadStorageObjectId object_ids = 1;
}

// Execute an Lua function on the server.
Expand All @@ -803,28 +806,6 @@ message Session {
string udp_token = 3; // TODO(zyro): will we remove it?
}

// The read access permissions for a storage object.
enum StoragePermissionRead {
// Default case. Assumed as OWNER_READ permission.
STORAGE_PERMISSION_READ_UNSPECIFIED = 0;
// The object does not have client read permissions.
NO_READ = 1;
// The object may be read by the user owner.
OWNER_READ = 2;
// The object may be read by any user.
PUBLIC_READ = 3;
}

// The write access permission for a storage object.
enum StoragePermissionWrite {
// Default case. Assumed as OWNER_WRITE permission.
STORAGE_PERMISSION_WRITE_UNSPECIFIED = 0;
// The object does not have client write permissions.
NO_WRITE = 1;
// The object may be written by the user owner.
OWNER_WRITE = 2;
}

// An object within the storage engine.
message StorageObject {
// The collection which stores the object.
Expand Down Expand Up @@ -855,6 +836,8 @@ message StorageObjectAck {
string key = 2;
// The version hash of the object.
string version = 3;
// The owner of the object.
string user_id = 4;
}

// Batch of acknowledgements for the storage object write.
Expand Down Expand Up @@ -946,9 +929,9 @@ message WriteStorageObject {
// The version hash of the object to check. Possible values are: ["", "*", "#hash#"].
string version = 4; // if-match and if-none-match
// The read access permissions for the object.
int32 permission_read = 5;
google.protobuf.Int32Value permission_read = 5;
// The write access permissions for the object.
int32 permission_write = 6;
google.protobuf.Int32Value permission_write = 6;
}

// Write objects to the storage engine.
Expand Down
63 changes: 46 additions & 17 deletions api/api.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -941,29 +941,39 @@
}
},
"/v2/storage": {
"delete": {
"summary": "Delete one or more objects by ID or username.",
"operationId": "DeleteStorageObjects",
"post": {
"summary": "Get storage objects.",
"operationId": "ReadStorageObjects",
"responses": {
"200": {
"description": "",
"schema": {
"$ref": "#/definitions/protobufEmpty"
"$ref": "#/definitions/apiStorageObjects"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/apiReadStorageObjectsRequest"
}
}
],
"tags": [
"Nakama"
]
},
"post": {
"summary": "Get storage objects.",
"operationId": "ReadStorageObjects",
"put": {
"summary": "Write objects into the storage engine.",
"operationId": "WriteStorageObjects",
"responses": {
"200": {
"description": "",
"schema": {
"$ref": "#/definitions/apiStorageObjects"
"$ref": "#/definitions/apiStorageObjectAcks"
}
}
},
Expand All @@ -973,22 +983,24 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/apiReadStorageObjectsRequest"
"$ref": "#/definitions/apiWriteStorageObjectsRequest"
}
}
],
"tags": [
"Nakama"
]
},
}
},
"/v2/storage/delete": {
"put": {
"summary": "Write objects into the storage engine.",
"operationId": "WriteStorageObjects",
"summary": "Delete one or more objects by ID or username.",
"operationId": "DeleteStorageObjects",
"responses": {
"200": {
"description": "",
"schema": {
"$ref": "#/definitions/apiStorageObjectAcks"
"$ref": "#/definitions/protobufEmpty"
}
}
},
Expand All @@ -998,7 +1010,7 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/apiWriteStorageObjectsRequest"
"$ref": "#/definitions/apiDeleteStorageObjectsRequest"
}
}
],
Expand All @@ -1009,7 +1021,7 @@
},
"/v2/storage/{collection}": {
"get": {
"summary": "List collections of storage objects.",
"summary": "List publicly readable storage objects in a given collection.",
"operationId": "ListStorageObjects",
"responses": {
"200": {
Expand Down Expand Up @@ -1056,7 +1068,7 @@
},
"/v2/storage/{collection}/{user_id}": {
"get": {
"summary": "List collections of storage objects.",
"summary": "List publicly readable storage objects in a given collection.",
"operationId": "ListStorageObjects2",
"responses": {
"200": {
Expand Down Expand Up @@ -1342,6 +1354,19 @@
},
"description": "Storage objects to delete."
},
"apiDeleteStorageObjectsRequest": {
"type": "object",
"properties": {
"object_ids": {
"type": "array",
"items": {
"$ref": "#/definitions/apiDeleteStorageObjectId"
},
"description": "Batch of storage objects."
}
},
"description": "Batch delete storage objects."
},
"apiFriend": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -1549,7 +1574,7 @@
"apiReadStorageObjectsRequest": {
"type": "object",
"properties": {
"objectIds": {
"object_ids": {
"type": "array",
"items": {
"$ref": "#/definitions/apiReadStorageObjectId"
Expand Down Expand Up @@ -1656,6 +1681,10 @@
"version": {
"type": "string",
"description": "The version hash of the object."
},
"user_id": {
"type": "string",
"description": "The owner of the object."
}
},
"description": "A storage acknowledgement."
Expand Down
2 changes: 1 addition & 1 deletion migrate/migrate-packr.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import "github.com/gobuffalo/packr"
// Go binary. You can use the "packr clean" command to clean up this,
// and any other packr generated files.
func init() {
packr.PackJSONBytes("./sql", "20180103142001_initial_schema.sql", "\"H4sIAAAAAAAA/7RX33PithZ+5684k4cbvNcBwm7m7mxud8YBZ9ddYlJsdjd9YYR9sNXYkisJCO30f+/IP8AGEtJOy1MiffrOD30657j7pgVvYMCzjaBRrKDfu3wPfozgkkeSErCWKuZCtiDHjWiATGIISxaiABUjWBkJYqx2TPiKQlLOoN/pQVsDzsqtM+NaU2z4ElKyAcYVLCWCiqmEBU0Q8CnATAFlEPA0SyhhAcKaqji3U7J0NMdDycHnilAGBAKebYAv6kAgqnQ6Vir70O2u1+sOyZ3tcBF1kwImuyNnYLuefdHv9MoDU5aglCDw1yUVGMJ8AyTLEhqQeYKQkDVwASQSiCEorh1eC6ooi0yQfKHWRKCmCalUgs6XqpGvyj0qGwDOgDA4szxwvDO4sTzHMzXJN8f/PJ768M2aTCzXd2wPxhMYjN2h4ztj14PxLVjuA3xx3KEJSFWMAvApEzoCLoDqTGKYp81DbLiw4IVLMsOALmgACWHRkkQIEV+hYJRFkKFIqdQ3KoGwUNMkNKWKqHzpIC5tqNtqXVzAf1MaCaIQpllrMLEt3wbfuhnZ4NyCO/bB/u54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JggkoQkvuDOr+vwf5XMw9G6314qpng9cChf0k1etXPmoMDblF2rdg08D40gYaXirT2msPysLKzyXalFJncmz4qrs3lQ1zZHn5hD9zYgfoiiQl4Yz33m0Pd96fPL/fvJZVGvjb8Aa/bKumYZatA5LGTruyP55JMPDvoUOe1Fu011iQcNXLZ29Uk91uW9zL7jTeq9/Q474lrVGs+nTQf5N6d+dX633qzcg+wnivfViWnoHIe9a/w0AAP//MUDbnEsRAAA=\"")
}
6 changes: 5 additions & 1 deletion migrate/sql/20180103142001_initial_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ CREATE TABLE IF NOT EXISTS users (
disable_time BIGINT DEFAULT 0 CHECK (disable_time >= 0) NOT NULL
);

INSERT INTO users (id, username, create_time, update_time)
VALUES ('00000000-0000-0000-0000-000000000000', '', 1, 1)
ON CONFLICT(id) DO NOTHING;

CREATE TABLE IF NOT EXISTS user_device (
PRIMARY KEY (id),
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE,
Expand Down Expand Up @@ -84,7 +88,7 @@ CREATE TABLE IF NOT EXISTS storage (

collection VARCHAR(128) NOT NULL,
key VARCHAR(128) NOT NULL,
user_id UUID,
user_id UUID NOT NULL,
value JSONB DEFAULT '{}' NOT NULL,
version VARCHAR(32) NOT NULL, -- md5 hash of value object.
read SMALLINT DEFAULT 1 CHECK (read >= 0) NOT NULL,
Expand Down
Loading

0 comments on commit 093cf4a

Please sign in to comment.