# Copyright (c) 2022, JINGROW
# For license information, please see license.txt

import jingrow
from jingrow.model.page import Page


class AddOnSettings(Page):
	# begin: auto-generated types
	# This code is auto-generated. Do not modify anything in this block.

	from typing import TYPE_CHECKING

	if TYPE_CHECKING:
		from jingrow.types import DF

		aws_access_key: DF.Data | None
		aws_secret_key: DF.Password | None
	# end: auto-generated types

	@jingrow.whitelist()
	def init_etcd_data(self, proxy_server):
		# TODO: Add a separate agent job for this, instead of doing it recursively here do it on server
		subs = jingrow.get_all(
			"Storage Integration Subscription",
			fields=["name", "enabled"],
			filters={"minio_server_on": proxy_server},
		)

		for sub in subs:
			pg = jingrow.get_pg("Storage Integration Subscription", sub["name"])
			pg.create_user()
			if pg.enabled == 0:
				pg.update_user("disable")

			jingrow.db.commit()
