Skip to content

Commit

Permalink
get_place function, profile connection related functions, untested
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaz87 committed Jan 28, 2019
1 parent c9437e2 commit c8c22ef
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 2 deletions.
25 changes: 25 additions & 0 deletions helpers/get_place.lua
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
36 changes: 36 additions & 0 deletions keys/connect_profile.lua
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
24 changes: 24 additions & 0 deletions keys/get_profile_data.lua
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
2 changes: 2 additions & 0 deletions keys/mod.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ require "keys.get_private_key"
require "keys.verify_http_signature"
require "keys.sign_http_message"
require "keys.witness_document"
require "keys.connect_profile"
require "keys.get_profile_data"

return keys
5 changes: 3 additions & 2 deletions mod.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ _G.keys = require "keys.mod"
require "loaders.package"
theme_loader = require "loaders.themes"
class_loader = require "loaders.styles"
require "helpers/render"
require "helpers/send_request"
require "helpers.render"
require "helpers.send_request"
require "helpers.get_place"

0 comments on commit c8c22ef

Please sign in to comment.