-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
get_place function, profile connection related functions, untested
- Loading branch information
Showing
5 changed files
with
90 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
function _G.get_place () | ||
--[[ | ||
-- Doesn't work for https stuff | ||
local response = send_request({ | ||
method = "GET", | ||
uri = "https://ifconfig.me/", | ||
headers = { | ||
["accept"] = "text/plain", | ||
}, | ||
body = "" | ||
}) | ||
local place = response.body | ||
]] | ||
|
||
-- Ideally, this would be a raw request, like above | ||
local cmd = "curl ifconfig.me" | ||
local file = assert(io.popen(cmd, 'r')) | ||
local place = assert(file:read('*a')) | ||
file:close() | ||
|
||
log.info("Current place: " .. place) | ||
|
||
return place | ||
end |
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,36 @@ | ||
function keys.connect_profile (data) | ||
|
||
local result = {} | ||
|
||
local profile_uuid = data.uuid | ||
result.profile = profile_uuid | ||
|
||
content.write_file(profile_uuid, profile_uuid, { | ||
type = "profile", | ||
name = data.name | ||
}) | ||
|
||
if data.sign_public_key then | ||
local sign_pub_id = uuid.v4() | ||
|
||
content.write_file(profile_uuid, uuid.v4(), { | ||
type = "key", | ||
kind = "sign_public", | ||
}, data.sign_public_key) | ||
|
||
result.sign_public_key = sign_pub_id | ||
end | ||
|
||
if data.place then | ||
local place_id = uuid.v4() | ||
|
||
content.write_file(profile_uuid, uuid.v4(), { | ||
type = "place", | ||
host = data.place, | ||
}) | ||
|
||
result.place = place_id | ||
end | ||
|
||
return result | ||
end |
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,24 @@ | ||
function keys.get_profile_data () | ||
|
||
local data = {} | ||
local uuid, name = keys.get_profile() | ||
log.debug("UUID: " .. tostring(uuid)) | ||
|
||
data.sign_public_key = content.walk_documents(uuid, | ||
function (file_uuid, header, body) | ||
if header.model == "key" | ||
and header.kind == "sign_private" | ||
then return body end | ||
end | ||
) | ||
|
||
data.place = content.walk_documents(uuid, | ||
function (file_uuid, header, body) | ||
if header.model == "place" then | ||
return header.host | ||
end | ||
end | ||
) | ||
|
||
return data | ||
end |
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