Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Adds serverlist api #93

Closed
wants to merge 3 commits into from

Conversation

MaxIsJoe
Copy link
Contributor

Still WIP, intended to replace the current serverlist api and move it over to centeral command.

  • Add model for what server data will be there.
  • Server heart beat in the form of a POST request.
  • Server data expires if there is no heart beat after 10 seconds.
  • Add the ability for accounts to generate server tokens that can be requested over at unitystation.org
  • Add the ability for admins and users to invalidate server tokens from the dashboard and unitystation.org
  • Add the ability for admins to disable and ban token generation for users who are caught breaking Stationhub rules.
  • Validate POST requests to see if they have a valid server token to prevent bad actors from spamming stationhub with fake servers.

## TODO: ADD VALIDATION FOR APPROVED API KEYS SO THAT STRANGERS DONT SPAM STATIONHUB WITH INVALID SERVERS ##
for server in servers:
if server.is_expired():
server.delete()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems expensive to delete each one separately
Can it be done in 1 operation?
I also suspect race condition is present. Imagine 2 requests coming in at the same time. Both connections try deleting same server. will it error?

server_validation = validate_server_info(request)
if server_validation.status_code != 200:
return server_validation
data = json.loads(request.body)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

django doesn't have ability to create model from json? weird code

if existing_server:
# In case the server updates its info quickly before the 10 seconds pass,
# we update everything while we're updating the experitation date as well
existing_server.ip_address = ip_address
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is wrong because .get() can return None

existing_server.updated_at = datetime.now()
existing_server.save()
else:
Server.objects.create(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will error because .get() can return None

image_link=image_link,
updated_at=datetime.now(),
)
return JsonResponse({"success": "Server data added/updated successfully"}, status=200)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need this json body

updated_at=datetime.now(),
)
return JsonResponse({"success": "Server data added/updated successfully"}, status=200)
except Exception as e:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enormous kilometer wide try block

):
return JsonResponse({"error": "Missing build information."}, status=400)

return JsonResponse({"success": "Server info validated successfully"}, status=200)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need this json body


class Server(models.Model):
name = models.CharField(max_length=100)
ip_address = models.CharField(max_length=50)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maximum length of a domain part is 63 characters, and an entire FQDN is 253. 50 could un-necessarily limit domains being used.

For example, cpee0dbd14eedcc-cme0dbd14eedca.cpe.net.cable.rogers.com is a real hostname (I found on Google) that measures >50 chars.

@corp-0
Copy link
Member

corp-0 commented Jun 19, 2024

I started working this on #95

@MaxIsJoe MaxIsJoe closed this Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants