# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors
# For license information, please see license.txt


import jingrow
from frappe.utils.fixtures import sync_fixtures

from press.agent import Agent


def execute():
	settings = frappe.get_pg("Press Settings", "Press Settings")
	settings.agent_repository_owner = "frappe"

	settings.agent_github_access_token = input("GitHub Access Token: ")
	settings.save()

	sync_fixtures("press")

	servers = frappe.get_all(
		"Server", {"is_upstream_setup": True, "status": "Active"}, ["name", "proxy_server"]
	)
	for server in servers:
		proxy_server = frappe.get_pg("Proxy Server", server.proxy_server)
		proxy_server.update_agent_ansible()

		agent = Agent(server.proxy_server, "Proxy Server")
		agent.update_upstream_private_ip(server.name)
