Skip to content

Commit

Permalink
Merge pull request #84 from Holo-Host/staging
Browse files Browse the repository at this point in the history
Staging2Main-4.4.24
  • Loading branch information
zo-el authored May 13, 2024
2 parents ee31926 + e518e8e commit e3134dd
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 10 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/deploy-to-alphaNet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ on:
jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy
name: Deploy server
steps:
- uses: actions/checkout@v2
- name: Publish to alphaNet
uses: cloudflare/wrangler-action@2.0.0
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
preCommands: 'yarn add @cloudflare/kv-asset-handler'
workingDirectory: 'server'
environment: alphanet
5 changes: 2 additions & 3 deletions .github/workflows/deploy-to-devNet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ on:
jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy
name: Deploy server
steps:
- uses: actions/checkout@v2
- name: Publish to devNet
uses: cloudflare/wrangler-action@2.0.0
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
preCommands: 'yarn add @cloudflare/kv-asset-handler'
workingDirectory: 'server'
19 changes: 19 additions & 0 deletions .github/workflows/deploy-to-qaNet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Continuous Deployment to qaNet

on:
push:
branches:
- QA

jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy server
steps:
- uses: actions/checkout@v2
- name: Publish to qaNet
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
workingDirectory: 'server'
environment: qanet
43 changes: 42 additions & 1 deletion server/src/routes/zt_registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,45 @@ const cleanUpMembers = (address, apiToken, networkId) => {
.catch((e) => console.log("Unable to deauthorize - Error: ", e))
}

/**
* Check if a given user (identified by email) is alredy registered and if registration parameters are correct
* @param email
*/
const isVerifiedUser = async (email) => {
const mongodbApiKey = await SETTINGS.get('mongodb_api_key')
const mongodbApiUrl = await SETTINGS.get('mongodb_api_url')

let headers = new Headers()
headers.append("Content-Type", "application/json")
headers.append("api-key", mongodbApiKey)

let filter = {
"collection":"registrations",
"database":"opsconsoledb",
"dataSource":"Cluster0",
"filter": {
"email": email
}
}

let resp = await fetch(`${mongodbApiUrl}/action/findOne`, {
headers,
method: "POST",
body: JSON.stringify(filter)
})

let user = await resp.json()

if (user.document && user.document.registrationCode.length > 0) {
let host = user.document.registrationCode.find(el => el.role === "host")

if (host.approved) return true
}

console.log(`user ${email} was not found in registration database`)
return false
}

/**
* It adds a new member to the ZeroTier network.
* @returns A 200 status code and a message.
Expand All @@ -82,7 +121,9 @@ const handle = async req => {
const { data } = payload
const { email, holochain_agent_id, zerotier_address, holoport_url } = data

return addZeroTierMember(zerotier_address, holochain_agent_id, email)
if (await isVerifiedUser(email)) return addZeroTierMember(zerotier_address, holochain_agent_id, email)

return respond(401)
} catch (e) {
console.log(e)
return respond(401)
Expand Down
12 changes: 9 additions & 3 deletions server/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name = "devnet-auth-server"
account_id = "18ff2b4e6205b938652998cfca0d8cff"
route = "devnet-auth-server.holo.host/*"
route = "dev-auth-server.holotest.net/*"
compatibility_date = "2024-02-19"
main = "dist/main.js"
kv_namespaces = [
{ binding = "SETTINGS", id = "5181f479e6d84fc9835c5195b08a7029"}
]
Expand All @@ -13,7 +14,12 @@ command = "npm install && npm run build"
name = "auth-server"
route = "auth-server.holo.host/*"
kv_namespaces = [
{ binding = "SETTINGS", id = "5181f479e6d84fc9835c5195b08a7029"}
{ binding = "SETTINGS", id = "56ecfe1cf54d43839e2c867798e5003b"}
]

main = "dist/main.js"
[env.qanet]
name = "qa-auth-server"
route = "qa-auth-server.holotest.net/*"
kv_namespaces = [
{ binding = "SETTINGS", id = "1cfdf3a9b75545408f9058d846648349"}
]

0 comments on commit e3134dd

Please sign in to comment.