Skip to content

Commit

Permalink
moved runbook endpoints to runbook.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Mubashirshariq committed Oct 7, 2024
1 parent 27d38cf commit 12bdd12
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 70 deletions.
2 changes: 1 addition & 1 deletion keep-ui/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
/// <reference types="next/navigation-types/compat/navigation" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
// see https://nextjs.org/docs/basic-features/typescript for more information.
4 changes: 2 additions & 2 deletions keep-ui/utils/hooks/useRunbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const useRunBookTriggers = (values: any, refresh: number) => {
return setRepoData([]);
}
const data = await fetcher(
`${baseApiurl}/providers/${provider?.type}/${provider?.id}/repositories`,
`${baseApiurl}/runbooks/${provider?.type}/${provider?.id}/repositories`,
session?.accessToken
);
setRepoData(data);
Expand Down Expand Up @@ -69,7 +69,7 @@ export const useRunBookTriggers = (values: any, refresh: number) => {
}
//TO DO backend runbook records needs to be created.
const response = await fetcher(
`${baseApiurl}/providers/${provider?.type}/${
`${baseApiurl}/runbooks/${provider?.type}/${
provider?.id
}/runbook?${params.toString()}`,
session?.accessToken
Expand Down
4 changes: 4 additions & 0 deletions keep/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
topology,
whoami,
workflows,
runbooks,
)
from keep.api.routes.auth import groups as auth_groups
from keep.api.routes.auth import permissions, roles, users
Expand Down Expand Up @@ -243,6 +244,9 @@ def get_app(
app.include_router(
deduplications.router, prefix="/deduplications", tags=["deduplications"]
)
app.include_router(
runbooks.router, prefix="/runbooks", tags=["runbooks"]
)
# if its single tenant with authentication, add signin endpoint
logger.info(f"Starting Keep with authentication type: {AUTH_TYPE}")
# If we run Keep with SINGLE_TENANT auth type, we want to add the signin endpoint
Expand Down
68 changes: 1 addition & 67 deletions keep/api/routes/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,71 +732,5 @@ def get_webhook_settings(
keep_webhook_api_url_with_auth=keep_webhook_api_url_with_auth,
),
webhookMarkdown=webhookMarkdown,
)

@router.get("/{provider_type}/{provider_id}/repositories")
def get_repositories(
provider_type: str,
provider_id: str,
authenticated_entity: AuthenticatedEntity = Depends(
IdentityManagerFactory.get_auth_verifier(["read:providers"])
),
session: Session = Depends(get_session),
):
tenant_id = authenticated_entity.tenant_id
logger.info("Getting respositories", extra={"provider_type": provider_type, "provider_id": provider_id})
tenant_id = authenticated_entity.tenant_id
logger.info(
"Getting provider alerts",
extra={
"tenant_id": tenant_id,
"provider_type": provider_type,
"provider_id": provider_id,
},
)
context_manager = ContextManager(tenant_id=tenant_id)
secret_manager = SecretManagerFactory.get_secret_manager(context_manager)
provider_config = secret_manager.read_secret(
f"{tenant_id}_{provider_type}_{provider_id}", is_json=True
)
provider = ProvidersFactory.get_provider(
context_manager, provider_id, provider_type, provider_config
)

return provider.pull_repositories()


@router.get("/{provider_type}/{provider_id}/runbook")
def get_repositories(
provider_type: str,
provider_id: str,
authenticated_entity: AuthenticatedEntity = Depends(
IdentityManagerFactory.get_auth_verifier(["read:providers"])
),
session: Session = Depends(get_session),
repo: str = Query(None),
branch: str = Query(None),
md_path: str = Query(None),
):
tenant_id = authenticated_entity.tenant_id
logger.info("Getting runbook", extra={"provider_type": provider_type, "provider_id": provider_id})
tenant_id = authenticated_entity.tenant_id
logger.info(
"Getting provider alerts",
extra={
"tenant_id": tenant_id,
"provider_type": provider_type,
"provider_id": provider_id,
},
)
context_manager = ContextManager(tenant_id=tenant_id)
secret_manager = SecretManagerFactory.get_secret_manager(context_manager)
provider_config = secret_manager.read_secret(
f"{tenant_id}_{provider_type}_{provider_id}", is_json=True
)
provider = ProvidersFactory.get_provider(
context_manager, provider_id, provider_type, provider_config
)

return provider.pull_runbook(repo=repo, branch=branch, md_path=md_path)
)

79 changes: 79 additions & 0 deletions keep/api/routes/runbooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import logging
from fastapi import APIRouter, Depends, Query
from sqlmodel import Session
from keep.api.core.db import get_session
from keep.contextmanager.contextmanager import ContextManager
from keep.identitymanager.authenticatedentity import AuthenticatedEntity
from keep.identitymanager.identitymanagerfactory import IdentityManagerFactory
from keep.providers.providers_factory import ProvidersFactory
from keep.secretmanager.secretmanagerfactory import SecretManagerFactory

logger = logging.getLogger(__name__)

router = APIRouter()


@router.get("/{provider_type}/{provider_id}/repositories")
def get_repositories(
provider_type: str,
provider_id: str,
authenticated_entity: AuthenticatedEntity = Depends(
IdentityManagerFactory.get_auth_verifier(["read:providers"])
),
session: Session = Depends(get_session),
):
tenant_id = authenticated_entity.tenant_id
logger.info("Getting respositories", extra={"provider_type": provider_type, "provider_id": provider_id})
tenant_id = authenticated_entity.tenant_id
logger.info(
"Getting provider alerts",
extra={
"tenant_id": tenant_id,
"provider_type": provider_type,
"provider_id": provider_id,
},
)
context_manager = ContextManager(tenant_id=tenant_id)
secret_manager = SecretManagerFactory.get_secret_manager(context_manager)
provider_config = secret_manager.read_secret(
f"{tenant_id}_{provider_type}_{provider_id}", is_json=True
)
provider = ProvidersFactory.get_provider(
context_manager, provider_id, provider_type, provider_config
)

return provider.pull_repositories()


@router.get("/{provider_type}/{provider_id}/runbook")
def get_repositories(
provider_type: str,
provider_id: str,
authenticated_entity: AuthenticatedEntity = Depends(
IdentityManagerFactory.get_auth_verifier(["read:providers"])
),
session: Session = Depends(get_session),
repo: str = Query(None),
branch: str = Query(None),
md_path: str = Query(None),
):
tenant_id = authenticated_entity.tenant_id
logger.info("Getting runbook", extra={"provider_type": provider_type, "provider_id": provider_id})
logger.info(
"Getting provider alerts",
extra={
"tenant_id": tenant_id,
"provider_type": provider_type,
"provider_id": provider_id,
},
)
context_manager = ContextManager(tenant_id=tenant_id)
secret_manager = SecretManagerFactory.get_secret_manager(context_manager)
provider_config = secret_manager.read_secret(
f"{tenant_id}_{provider_type}_{provider_id}", is_json=True
)
provider = ProvidersFactory.get_provider(
context_manager, provider_id, provider_type, provider_config
)

return provider.pull_runbook(repo=repo, branch=branch, md_path=md_path)

0 comments on commit 12bdd12

Please sign in to comment.