Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions flixpy/examples/revision_a_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
from __future__ import annotations

import asyncio
import os
from pathlib import Path

import flix

# Authentication data
HOSTNAME = "localhost"
PORT = 8080
USERNAME = "admin"
PASSWORD = "admin"
API_KEY = os.getenv("FLIX_API_KEY")
API_SECRET = os.getenv("FLIX_API_SECRET")

# Flix IDs
SHOW_ID = 1
Expand All @@ -28,9 +29,7 @@


async def main() -> None:
async with flix.Client(HOSTNAME, PORT) as client:
# Log into the Flix server
await client.authenticate(USERNAME, PASSWORD)
async with flix.Client(HOSTNAME, PORT, api_key=API_KEY, api_secret=API_SECRET) as client:
# Get the show from the server
show = await client.get_show(SHOW_ID)
# Create an 'artwork' media object with the file and transcode it to create a thumbnail
Expand Down
11 changes: 6 additions & 5 deletions flixpy/examples/shotgrid_create_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import asyncio
import logging
import os
import re
from typing import TypedDict, cast

Expand All @@ -31,8 +32,8 @@
# Flix server and credentials for creating the new show
FLIX_HOSTNAME = "localhost"
FLIX_PORT = 8080
FLIX_USERNAME = "admin"
FLIX_PASSWORD = "admin"
FLIX_API_KEY = os.getenv("FLIX_API_KEY")
FLIX_API_SECRET = os.getenv("FLIX_API_SECRET")


# optional statically typed schemas for our ShotGrid data,
Expand Down Expand Up @@ -83,9 +84,9 @@ async def import_sg_show() -> None:
finally:
sg.close()

async with flix.Client(FLIX_HOSTNAME, FLIX_PORT) as client:
await client.authenticate(FLIX_USERNAME, FLIX_PASSWORD)

async with flix.Client(
FLIX_HOSTNAME, FLIX_PORT, api_key=FLIX_API_KEY, api_secret=FLIX_API_SECRET
) as client:
# create a new show with the appropriate tracking code,
# title and description; default values will be used for
# the frame rate (24 fps) and aspect ratio (1.77)
Expand Down
9 changes: 5 additions & 4 deletions flixpy/examples/shotgrid_version_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import asyncio
import contextlib
import logging
import os
import tempfile
from typing import TYPE_CHECKING, Literal, TypedDict, cast

Expand All @@ -40,8 +41,8 @@
# Flix server and credentials for exporting the QuickTime
FLIX_HOSTNAME = "localhost"
FLIX_PORT = 8080
FLIX_USERNAME = "admin"
FLIX_PASSWORD = "admin"
FLIX_API_KEY = os.getenv("FLIX_API_KEY")
FLIX_API_SECRET = os.getenv("FLIX_API_SECRET")

# create long-lived ShotGrid client so we don't need
# to create a new one for each event
Expand Down Expand Up @@ -172,8 +173,8 @@ async def run_publish_webhook() -> None:
client_options={
"hostname": FLIX_HOSTNAME,
"port": FLIX_PORT,
"username": FLIX_USERNAME,
"password": FLIX_PASSWORD,
"api_key": FLIX_API_KEY,
"api_secret": FLIX_API_SECRET,
},
)

Expand Down
10 changes: 4 additions & 6 deletions flixpy/examples/update_sequence_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,22 @@

import asyncio
import datetime
import os

import flix

HOSTNAME = "localhost"
PORT = 8080
USERNAME = "admin"
PASSWORD = "admin"
API_KEY = os.getenv("FLIX_API_KEY")
API_SECRET = os.getenv("FLIX_API_SECRET")

SHOW_ID = 478
SEQUENCE_ID = 415


async def update_sequence_metadata() -> None:
"""Updates metadata for an existing sequence."""
async with flix.Client(HOSTNAME, PORT) as client:
# authenticate with the Flix server
await client.authenticate(USERNAME, PASSWORD)

async with flix.Client(HOSTNAME, PORT, api_key=API_KEY, api_secret=API_SECRET) as client:
# fetch show and sequence
show = await client.get_show(SHOW_ID)
sequence = await show.get_sequence(SEQUENCE_ID)
Expand Down
9 changes: 7 additions & 2 deletions flixpy/examples/webhook_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@
from __future__ import annotations

import asyncio
import os

import flix

HOSTNAME = "localhost"
PORT = 8080
API_KEY = os.getenv("FLIX_API_KEY")
API_SECRET = os.getenv("FLIX_API_SECRET")


async def register_webhook() -> None:
"""Register a webhook with Flix."""
async with flix.Client("localhost", 8080) as client:
await client.authenticate("admin", "admin")
async with flix.Client(HOSTNAME, PORT, api_key=API_KEY, api_secret=API_SECRET) as client:
webhook = await client.post(
"/webhook",
body={
Expand Down
27 changes: 10 additions & 17 deletions flixpy/flix/cli/interactive_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

from __future__ import annotations

import contextlib
from typing import TYPE_CHECKING, Any

import asyncclick as click

from ..lib import client, errors
from ..lib import client, errors, models

if TYPE_CHECKING:
import aiohttp
Expand All @@ -31,33 +30,27 @@ def __init__(
config: dict[str, Any],
username: str | None = None,
password: str | None = None,
access_key: models.AccessKey | None = None,
) -> None:
try:
access_key = client.AccessKey(config["access_key"])
except KeyError:
access_key = None

super().__init__(
hostname,
port,
ssl=ssl,
access_key=access_key,
access_key=client.AccessKey(access_key) if access_key else None,
disable_ssl_validation=config.get("disable_ssl_validation", False),
)
self._config = config
self._username = username
self._password = password
self.__config = config
self.__username = username
self.__password = password

async def _sign_in(self) -> None:
click.echo("Not signed in, attempting to authenticate...", err=True)
self.__config.pop("access_key", None)

with contextlib.suppress(KeyError):
del self._config["access_key"]

username = self._username or click.prompt("Username", type=str, err=True)
password = self._password or click.prompt("Password", type=str, hide_input=True, err=True)
username = self.__username or click.prompt("Username", type=str, err=True)
password = self.__password or click.prompt("Password", type=str, hide_input=True, err=True)
access_key = await self.authenticate(username, password)
self._config["access_key"] = access_key.to_json()
self.__config["access_key"] = access_key.to_json()

async def request(self, *args: Any, **kwargs: Any) -> aiohttp.ClientResponse:
try:
Expand Down
34 changes: 29 additions & 5 deletions flixpy/flix/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,37 @@ async def get_client(ctx: click.Context, server: str | None = None) -> client.Cl
config=ctx.obj["config"],
username=ctx.obj.get("username"),
password=ctx.obj.get("password"),
access_key=ctx.obj.get("access_key"),
)


@click.group()
@click.option("-s", "--server", type=str, help="The URL of the Flix server.")
@click.option("-u", "--username", type=str, help="The username to authenticate with.")
@click.option("-p", "--password", type=str, help="The password to authenticate with.")
@click.option("--key", type=str, help="The API key to authenticate with.")
@click.option("--secret", type=str, help="The API key secret to authenticate with.")
@click.option("-u", "--username", type=str, help="The username to authenticate with (deprecated).")
@click.option("-p", "--password", type=str, help="The password to authenticate with (deprecated).")
@click.pass_context
async def flix_cli(
ctx: click.Context, server: str | None, username: str | None, password: str | None
ctx: click.Context,
server: str | None,
username: str | None,
password: str | None,
key: str | None,
secret: str | None,
) -> None:
cfg = read_config()
ctx.ensure_object(dict)
ctx.obj["config"] = cfg
ctx.obj["server"] = server or cfg.get("server")
ctx.obj["username"] = username or cfg.get("username")
ctx.obj["password"] = password or cfg.get("password")
if key or secret:
if not key or not secret:
raise click.ClickException("Must provide both --key and --secret.")
ctx.obj["access_key"] = models.AccessKey(id=key, secret_access_key=secret)
else:
ctx.obj["access_key"] = cfg.get("access_key")


@flix_cli.result_callback()
Expand All @@ -79,8 +93,10 @@ def save_config(ctx: click.Context, /, *_args: Any, **_kwargs: Any) -> None:

@flix_cli.command("config", help="Set default configuration values.")
@click.option("-s", "--server", type=str, help="The default server URL.")
@click.option("-u", "--username", type=str, help="The default username.")
@click.option("-p", "--password", type=str, help="The default password.")
@click.option("--key", type=str, help="The API key to authenticate with.")
@click.option("--secret", type=str, help="The API key secret to authenticate with.")
@click.option("-u", "--username", type=str, help="The default username (deprecated).")
@click.option("-p", "--password", type=str, help="The default password (deprecated).")
@click.option(
"--disable-ssl-validation",
type=bool,
Expand All @@ -91,6 +107,8 @@ def save_config(ctx: click.Context, /, *_args: Any, **_kwargs: Any) -> None:
def config(
ctx: click.Context,
server: str | None,
key: str | None,
secret: str | None,
username: str | None,
password: str | None,
disable_ssl_validation: bool,
Expand All @@ -104,6 +122,12 @@ def config(
cfg["username"] = username
if password:
cfg["password"] = password
if key or secret:
if not key or not secret:
raise click.ClickException("Must provide both --key and --secret.")
cfg["access_key"] = models.AccessKey(id=key, secret_access_key=secret)
cfg.pop("username", None)
cfg.pop("password", None)
if clear:
cfg = {}
ctx.obj["config"] = cfg
Expand Down
Loading