Skip to content

Push scraps to yard via CLI #253

@surprisetalk

Description

@surprisetalk

The following serves a directory of scraps over the network:

echo "123" > /var/scrap/yard/example.scrap
scrap yard serve /var/scrap/yard

But we also want to enable folks to remotely (and securely) push scraps to a yard:

cat fib.scrap \
  | scrap yard push sarah/fib \
      --yard yard.scrap.land \
      --key ~/.ssh/id_scrap

We could implement the CLI command like so:

def yard_push(): 
    input = sys.stdin.read()
    flat = to_flat(input)
    with open(args.key, encoding="utf-8") as f:
        key = f.read()
    requests.post(
        f"https://yard.scrap.land/{args.dir}", 
        data=to_flat({
            "sig": sign(flat, key),
            "data": input,
        })
    )

On the server side, we can start out by storing a directory of public keys like so:

mkdir -p /var/scrap/keys
cp ~/.ssh/id_scrap.pub /var/scrap/keys/sarah
scrap yard serve /var/scrap/yard --keys /var/scrap/keys --port 8080 &
scrap yard push sarah/fib --yard :8080 --key ~/.ssh/id_scrap < fib.scrap

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions