Exemplo n.º 1
0
def get_sandbox_id(templates, manifests, all_experiments, auto):
    # Generate a sandbox name and ask the user what they want theirs to be called.
    manifest_hash = hashlib.md5(manifests.encode()).digest()
    manifest_hash = anybase32.encode(manifest_hash, anybase32.ZBASE32).decode()
    pr_ids = "-".join(
        [
            f"{repo}{opts.ref}"
            for repo, opts in templates.items()
            if opts.ref != DEFAULT_BRANCH
        ]
    )

    # if we are in auto mode (non interactive) just generate a random sandbox ID name
    if auto:
        return random_name.generate_name()

    fragments = (
        re.sub(r"[^\w\s]", "", os.getenv("BIOMAGE_NICK", os.getenv("USER", ""))),
        pr_ids if pr_ids else manifest_hash,
    )
    sandbox_id = "-".join([bit for bit in fragments if bit]).lower()[:26]

    # Ask the user to provide one if they want
    click.echo()
    click.echo(click.style("Give a sandbox ID.", fg="yellow", bold=True))
    click.echo(
        "The sandbox ID must be no more than 26 characters long, consist of "
        "lower case alphanumeric characters, or `-`, and must\n"
        "start and end with an alphanumeric character. A unique ID generated from "
        "the contents of the deployments and your pinning\n"
        "choices has been provided as a default."
    )
    while True:
        questions = [
            {
                "type": "input",
                "name": "sandbox_id",
                "message": "Provide an ID:",
                "default": sandbox_id,
            }
        ]

        click.echo()
        sandbox_id = prompt(questions)
        sandbox_id = sandbox_id["sandbox_id"]

        if sandbox_id in [experiment["experimentId"] for experiment in all_experiments]:
            click.echo(
                click.style(
                    "Your ID is the same with the name of an experiment. "
                    "Please use another name",
                    fg="red",
                )
            )
        elif SANDBOX_NAME_REGEX.match(sandbox_id) and len(sandbox_id) <= 26:
            return sandbox_id
        else:
            click.echo(click.style("Please, verify the syntax of your ID", fg="red"))
Exemplo n.º 2
0
from __future__ import print_function
import anybase32

data = b"The **quick** brown fox jumps over the (lazy) dog!"

print("Crockford modified:",
      anybase32.encode(data, anybase32.CROCKFORD_MODIFIED))
print("Crockford:", anybase32.encode(data, anybase32.CROCKFORD))
print("Zbase32:", anybase32.encode(data, anybase32.ZBASE32))
print("RFC 3548:", anybase32.encode(data, anybase32.RFC_3548))
print("RFC 2938:", anybase32.encode(data, anybase32.RFC_2938))
print("RFC 4648:", anybase32.encode(data, anybase32.RFC_4648))
print("Nightmare:", anybase32.encode(data, anybase32.NIGHTMARE))
enc = anybase32.encode(data, b"0123456789`~!@#$%^&*()-_=+[]{}\/")
print("Arbitrary:", enc)
dec = anybase32.decode(enc, b"0123456789`~!@#$%^&*()-_=+[]{}\/")
print(dec)

with open("tests/icon.png", "rb") as icon:
    icon_bytes = icon.read()

icon = anybase32.encode(icon_bytes, anybase32.ZBASE32)
while icon:
    if len(icon) > 77:
        print("{0}".format(icon[:77]))
        icon = icon[77:]
    else:
        print("{0}".format(icon))
        icon = None
Exemplo n.º 3
0
def test_binary():
    with open("tests/icon.png", "rb") as icon_file:
        icon_bytes = icon_file.read()

    encoded = anybase32.encode(icon_bytes, anybase32.ZBASE32)
    assert (encoded == ICON_ZBASE32)
Exemplo n.º 4
0
import anybase32

data = "The **quick** brown fox jumps over the (lazy) dog!"

print "Crockford modified", anybase32.encode(data, anybase32.CROCKFORD_MODIFIED)
print "Crockford", anybase32.encode(data, anybase32.CROCKFORD)
print "Zbase32", anybase32.encode(data, anybase32.ZBASE32)
print "RFC 3548", anybase32.encode(data, anybase32.RFC_3548)
print "RFC 2938", anybase32.encode(data, anybase32.RFC_2938)
print "RFC 4648", anybase32.encode(data, anybase32.RFC_4648)
print "Nightmare", anybase32.encode(data, anybase32.NIGHTMARE)
enc = anybase32.encode(data, "0123456789`~!@#$%^&*()-_=+[]{}\/")
print "Arbitrary", enc
dec = anybase32.decode(enc, "0123456789`~!@#$%^&*()-_=+[]{}\/")
print dec

with open("tests/icon.png", "rb") as icon:
    icon_bytes = icon.read()

icon = anybase32.encode(icon_bytes, anybase32.ZBASE32)
while len(icon) > 74:
    print '"%s"' % icon[:74]
    icon = icon[74:]
Exemplo n.º 5
0
def test_crockford_modified():
    encoded = anybase32.encode(SAMPLE_TEXT, anybase32.CROCKFORD_MODIFIED)
    assert (encoded == CROCKFORD_MODIFIED)
Exemplo n.º 6
0
def test_repeat_character_alphabet():
    with pytest.raises(ValueError) as e:
        anybase32.encode(SAMPLE_TEXT, REPEAT_CHARACTER_ALPHABET)
    assert ("Invalid base32 alphabet" in str(e))
Exemplo n.º 7
0
def test_too_long_alphabet():
    with pytest.raises(ValueError) as e:
        anybase32.encode(SAMPLE_TEXT, TOO_LONG_ALPHABET)
    assert ("Invalid base32 alphabet" in str(e))
Exemplo n.º 8
0
def test_arbitrary():
    encoded = anybase32.encode(SAMPLE_TEXT, ARBITRARY_ALPHABET)
    assert (encoded == ARBITRARY)
Exemplo n.º 9
0
def test_rfc_46488():
    encoded = anybase32.encode(SAMPLE_TEXT, anybase32.RFC_4648)
    assert (encoded == RFC_4648)
Exemplo n.º 10
0
def test_zbase32():
    encoded = anybase32.encode(SAMPLE_TEXT, anybase32.ZBASE32)
    assert (encoded == ZBASE32)
Exemplo n.º 11
0
def test_crockford():
    encoded = anybase32.encode(SAMPLE_TEXT, anybase32.CROCKFORD)
    assert (encoded == CROCKFORD)