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

Add new redirect APIs #121

Merged
merged 6 commits into from
Jun 20, 2024
Merged

Add new redirect APIs #121

merged 6 commits into from
Jun 20, 2024

Conversation

fformica
Copy link
Contributor

Adding new redirect APIs

@fformica fformica marked this pull request as ready for review January 31, 2024 11:54
@fformica fformica requested a review from a team January 31, 2024 12:23
@fformica
Copy link
Contributor Author

Hi, this is what I used to test:

# Note: to run this test change endpoint, API key and domain to an existing server / zone
def test_rest_live():
    redirect_config = ns1.config.Config()
    redirect_config.loadFromDict(
        {
            "endpoint": "XXX",
            "default_key": "default",
            "keys": {
                "default": {
                    "key": "XXX",
                    "desc": "live env",
                    "writeLock": True,
                }
            },
            "follow_pagination": True
        }
    )
    domain="pytest.fformica.com"
    path="/"
    existing=listRedirects(redirect_config)
    for c in existing:
        if c["domain"] == domain and c["path"] == path:
            c.delete()
            print("deleted ",c)

    # Assuming we already have a zone here
    myCfg = Redirect(redirect_config).create(
        domain=domain,
        path=path,
        target="https://www.google.com",
        tags=["test","me"],
    )
    assert myCfg.__getitem__("tags") == ["test","me"]
    assert myCfg is not None
    assert isinstance(myCfg, Redirect)
    print(myCfg, myCfg["tags"], myCfg["https_enabled"])
    myCfg.update(target="http://localhost",tags=[])
    myCfg = myCfg.reload()
    assert myCfg.__getitem__("target") == "http://localhost"
    assert myCfg.__getitem__("tags") == []
    print(myCfg, myCfg["tags"], myCfg["https_enabled"])
    cert = myCfg.retrieveCertificate()
    assert cert is not None
    assert isinstance(cert, RedirectCertificate)
    print(cert)
    existing=listRedirects(redirect_config)
    assert len(existing)>0
    found=None
    for c in existing:
        if c["domain"] == domain and c["path"] == path:
            print(c, c["tags"], c["https_enabled"])
            assert isinstance(c, Redirect)
            found=c
            break
    assert found is not None
    existing=listRedirectCertificates(redirect_config)
    assert len(existing)>0
    found=None
    for c in existing:
        if c["domain"] == domain:
            print(c, c["valid_until"])
            assert isinstance(c, RedirectCertificate)
            found=c
            break
    assert found is not None
    myCfg.delete()

@fformica fformica merged commit 65954a7 into master Jun 20, 2024
8 checks passed
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.

2 participants