-
Notifications
You must be signed in to change notification settings - Fork 24
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
rippling cli : Flux app command #6
Merged
Merged
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
9c13581
added .github directory & run_ruff & linter
vguptarippling 87c86b1
fixed run_ruff.sh & added dev dependencies
vguptarippling 68659f4
updated poetry.lock
vguptarippling f253695
updated poetry.lock
vguptarippling 4b155fd
updated poetry.lock
vguptarippling e02729d
changed git ignore
vguptarippling 41fd1a3
updated lint.yml
vguptarippling fca7d70
updated permissions
vguptarippling 9211ebb
linting fix
vguptarippling 68be957
linting fix
vguptarippling 9297105
permission fix
vguptarippling 54577c2
updated pyproject.toml and poetry.lock
vguptarippling 2777dcb
removed import
vguptarippling 143859e
fixed import
vguptarippling 7f0680e
added #type :ignore
vguptarippling 057ab1a
Fixed imports
vguptarippling 9d597c6
Merge branch 'main' into APPS-25575
vguptarippling 9fed554
fix imports
vguptarippling 3aad3e9
fixed lint typing
vguptarippling b03f83b
Update api_client.py
vguptarippling d83b0c8
fixed import
vguptarippling File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import os | ||
|
||
import click | ||
|
||
from rippling_cli.config.config import get_app_config, save_app_config | ||
from rippling_cli.constants import RIPPLING_API | ||
from rippling_cli.core.api_client import APIClient | ||
from rippling_cli.utils.login_utils import ensure_logged_in | ||
|
||
|
||
@click.group() | ||
@click.pass_context | ||
def app(ctx: click.Context) -> None: | ||
"""Manage flux apps""" | ||
ensure_logged_in(ctx) | ||
|
||
|
||
@app.command() | ||
def list() -> None: | ||
"""This command displays a list of all apps owned by the developer.""" | ||
ctx: click.Context = click.get_current_context() | ||
api_client = APIClient(base_url=RIPPLING_API, headers={"Authorization": f"Bearer {ctx.obj.oauth_token}"}) | ||
endpoint = "/apps/api/integrations" | ||
|
||
for page in api_client.find_paginated(endpoint): | ||
click.echo(f"Page: {len(page)} apps") | ||
|
||
for app in page: | ||
click.echo(f"- {app.get('displayName')} ({app.get('id')})") | ||
|
||
if not click.confirm("Continue"): | ||
break | ||
|
||
click.echo("End of apps list.") | ||
|
||
|
||
@app.command() | ||
@click.option("--app_id", required=True, type=str, help="The app id to set for the current directory.") | ||
def set(app_id: str) -> None: | ||
"""This command sets the current app within the app_config.json file located in the .rippling directory.""" | ||
ctx: click.Context = click.get_current_context() | ||
api_client = APIClient(base_url=RIPPLING_API, headers={"Authorization": f"Bearer {ctx.obj.oauth_token}"}) | ||
|
||
endpoint = "/apps/api/apps/?large_get_query=true" | ||
response = api_client.post(endpoint, data={"query": f"id={app_id}&limit=1"}) | ||
app_list = response.json() if response.status_code == 200 else [] | ||
|
||
if response.status_code != 200 or len(app_list) == 0: | ||
click.echo(f"Invalid app id: {app_id}") | ||
return | ||
|
||
app_name = app_list[0].get("displayName") | ||
|
||
save_app_config(app_id, app_name) | ||
click.echo(f"Current app set to {app_name} ({app_id})") | ||
|
||
|
||
@app.command() | ||
def current() -> None: | ||
"""This command indicates the current app selected by the developer within the directory.""" | ||
app_config_json = get_app_config() | ||
app_config = app_config_json.get(os.getcwd()) | ||
if not app_config: | ||
click.echo("No app selected.") | ||
return | ||
|
||
click.echo(f"{app_config.get('displayName')} ({app_config.get('id')})") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import click | ||
|
||
from rippling_cli.cli.commands.flux.app import app | ||
from rippling_cli.utils.login_utils import ensure_logged_in | ||
|
||
|
||
@click.group() | ||
@click.pass_context | ||
def flux(ctx: click.Context) -> None: | ||
"""Manage flux apps""" | ||
ensure_logged_in(ctx) | ||
|
||
|
||
flux.add_command(app) # type: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import requests # type: ignore | ||
|
||
|
||
class APIClient: | ||
def __init__(self, base_url, headers=None): | ||
self.base_url = base_url | ||
self.headers = headers or {} | ||
|
||
def make_request(self, method, endpoint, params=None, data=None): | ||
url = f"{self.base_url.rstrip('/')}/{endpoint.lstrip('/')}" | ||
response = requests.request(method, url, params=params, json=data, headers=self.headers) | ||
return response | ||
|
||
def get(self, endpoint, params=None): | ||
return self.make_request("GET", endpoint, params=params) | ||
|
||
def post(self, endpoint, data): | ||
return self.make_request("POST", endpoint, data=data) | ||
|
||
def put(self, endpoint, data): | ||
return self.make_request("PUT", endpoint, data=data) | ||
|
||
def delete(self, endpoint, params=None): | ||
return self.make_request("DELETE", endpoint, params=params) | ||
|
||
def find_paginated(self, endpoint, page=1, page_size=10, read_preference="SECONDARY_PREFERRED"): | ||
""" | ||
Fetch paginated data from the API. | ||
|
||
Args: | ||
endpoint (str): The API endpoint. | ||
headers (dict): The headers for the API request. | ||
page (int): The page number to fetch. | ||
per_page (int): The number of items to fetch per page. | ||
|
||
Yields: | ||
dict: The data from the API response. | ||
:param endpoint: | ||
:param page: | ||
:param page_size: | ||
:param read_preference: | ||
""" | ||
has_more = True | ||
cursor = None | ||
while has_more: | ||
payload = { | ||
"paginationParams": { | ||
"page": page, | ||
"cursor": cursor, | ||
"sortingMetadata": { | ||
"order": "DESC", | ||
"column": { | ||
"sortKey": "createdAt" | ||
} | ||
} | ||
}, | ||
"pageSize": page_size, | ||
"readPreference": read_preference | ||
} | ||
response = self.make_request("POST", f"{endpoint}/find_paginated", data=payload) | ||
|
||
if response.status_code == 200: | ||
data = response.json() | ||
cursor = data.get("cursor") | ||
has_more = False if not cursor else True | ||
items = data["data"] | ||
page += 1 | ||
yield items | ||
else: | ||
response.raise_for_status() | ||
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import click | ||
|
||
from rippling_cli.cli.commands.login import login | ||
from rippling_cli.core.oauth_token import OAuthToken | ||
|
||
|
||
def ensure_logged_in(ctx: click.Context): | ||
if OAuthToken.is_token_expired(): | ||
click.echo("You are not logged in. Please log in first.") | ||
ctx.invoke(login) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using common
make_request
to make api call 😅