def domain_renew(user, password, domain, period): freenom = Freenom() if not freenom.login(user, password): click.secho('Unable to login with the given credential', fg='red', bold=True) sys.exit(6) # search the domain domains = freenom.list_domains() domain_obj = next((d for d in domains if d.name.upper() == domain.upper()), None) if domain_obj is None: click.secho(f'Unable to find domain with name "{domain}"', fg='red', bold=True) sys.exit(6) if not freenom.need_renew(domain_obj): click.secho(f'No need to renew domain "{domain_obj.name}"', fg='yellow', bold=True) sys.exit(7) if freenom.renew(domain_obj, period): click.echo(f'Renewed "{domain_obj.name}" for {period} months') else: click.secho(f'Unable to renew domain "{domain_obj.name}"', fg='red', bold=True) sys.exit(6)
def domain_ls(user, password, format): freenom = Freenom() if not freenom.login(user, password): click.secho('Unable to login with the given credential', fg='red', bold=True) sys.exit(6) domains = freenom.list_domains() click.echo(format_data(domains, format))
def setUp(self): self.freenom = Freenom() if self.config_file: self.config = Config(str(self.config_file)) self.login = os.getenv("FREENOM_LOGIN", self.config.login) self.password = os.getenv("FREENOM_PASSWORD", self.config.password) else: self.config = None self.login = os.getenv("FREENOM_LOGIN", None) self.password = os.getenv("FREENOM_PASSWORD", None)
def domain_action(action: Callable[[Freenom, Domain], None], config: Config, ignore_errors: bool): records = config.records if not records: click.secho('There is no record configured', fg='yellow', bold=True) freenom = Freenom() if not freenom.login(config.login, config.password): click.secho('Unable to login with the given credential', fg='red', bold=True) sys.exit(6) domains = freenom.list_domains() domains_mapping = {d.name: d for d in domains} ok_count = 0 err_count = 0 to_process = set() for rec in records: domain_name = rec.domain.name rec_domain = domains_mapping.get(domain_name) if rec_domain is None: click.secho(f"You don't own the domain \"{domain_name}\"", fg='yellow', bold=True) if ignore_errors: continue else: sys.exit(7) rec.domain = rec_domain to_process.add(rec_domain) for domain in to_process: try: action(freenom, domain) except Exception: if not ignore_errors: raise warnings.warn(traceback.format_exc()) err_count += 1 else: ok_count += 1 return ok_count, err_count