Skip to content

Commit

Permalink
expose manifest via endpoint/template
Browse files Browse the repository at this point in the history
  • Loading branch information
fzumstein committed Apr 29, 2024
1 parent 3311fe8 commit fb2dd99
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 29 deletions.
1 change: 1 addition & 0 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Settings(BaseSettings):
# Set to False if you have users from external organizations
entraid_validate_issuer: bool = True
environment: Literal["development", "staging", "production"] = "development"
hostname: Optional[str] = None
log_level: str = "INFO"
public_addin_store: bool = False
static_dir: Path = base_dir / "static"
Expand Down
2 changes: 2 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from . import settings
from .routers import socketio as socketio_router
from .routers.macros.router import router as macros_router
from .routers.manifest import router as manifest_router
from .routers.taskpane import router as taskpane_router
from .routers.xlwings import router as xlwings_router

Expand Down Expand Up @@ -42,6 +43,7 @@
app.include_router(xlwings_router)
app.include_router(macros_router)
app.include_router(taskpane_router)
app.include_router(manifest_router)


# Security headers
Expand Down
41 changes: 41 additions & 0 deletions app/routers/manifest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import logging
import os

from fastapi import APIRouter, Request

from ..config import settings
from ..templates import TemplateResponse

router = APIRouter()

logger = logging.getLogger(__name__)


@router.get("/manifest")
async def manifest(request: Request):
logger.info(os.environ)
logger.info(os.getenv("RENDER_EXTERNAL_URL"))
if settings.hostname:
# Settings
if settings.hostname.startswith("https://"):
hostname = settings.hostname[8:]
else:
hostname = settings.hostname
base_url = f"https://{hostname}"
elif os.getenv("RENDER_EXTERNAL_URL"):
# Render
base_url = os.getenv("RENDER_EXTERNAL_URL")
logger.info(base_url)
elif os.getenv("WEBSITE_HOSTNAME"):
# Azure Functions
base_url = os.getenv("WEBSITE_HOSTNAME")
else:
# Mostly localhost
base_url = request.base_url

return TemplateResponse(
request=request,
name="/manifest.xml",
context={"settings": settings, "base_url": str(base_url).rstrip("/")},
media_type="text/plain",
)
59 changes: 30 additions & 29 deletions manifest.xml → app/templates/manifest.xml
Original file line number Diff line number Diff line change
@@ -1,62 +1,64 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1"
<OfficeApp
xmlns="http://schemas.microsoft.com/office/appforoffice/1.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0"
xmlns:ov="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="TaskPaneApp">
xmlns:ov="http://schemas.microsoft.com/office/taskpaneappversionoverrides"
xsi:type="TaskPaneApp">
<!-- TODO: Create your own ID via https://www.guidgen.com or by running in Python: import uuid;print(uuid.uuid4()) -->
<Id>0a856eb1-91ab-4f38-b757-23fbe1f73130</Id>
<Version>1.0.0</Version>
<ProviderName>xlwings</ProviderName>
<DefaultLocale>en-US</DefaultLocale>
<DisplayName DefaultValue="xlwings Server" />
<Description DefaultValue="xlwings Server" />
<IconUrl DefaultValue="https://127.0.0.1:8000/static/images/examples/xlwings-32.png" />
<HighResolutionIconUrl DefaultValue="https://127.0.0.1:8000/static/images/examples/xlwings-64.png" />
<IconUrl DefaultValue="{{ base_url }}/static/images/examples/xlwings-32.png" />
<HighResolutionIconUrl DefaultValue="{{ base_url }}/static/images/examples/xlwings-64.png" />
<SupportUrl DefaultValue="https://www.xlwings.org/contact" />
<AppDomains>
<AppDomain>https://127.0.0.1:8000</AppDomain>
<AppDomain>{{ base_url }}</AppDomain>
</AppDomains>
<Hosts>
<Host Name="Workbook" />
</Hosts>
<!-- SharedRuntime for Custom Functions -->
<Requirements>
<Sets DefaultMinVersion="1.1">
<Set Name="SharedRuntime" MinVersion="1.1"/>
<Set Name="SharedRuntime" MinVersion="1.1" />
</Sets>
</Requirements>
<DefaultSettings>
<SourceLocation DefaultValue="https://127.0.0.1:8000/taskpane" />
<SourceLocation DefaultValue="{{ base_url }}/taskpane" />
</DefaultSettings>
<Permissions>ReadWriteDocument</Permissions>
<VersionOverrides xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="VersionOverridesV1_0">
<VersionOverrides
xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides"
xsi:type="VersionOverridesV1_0">
<Hosts>
<Host xsi:type="Workbook">

<!-- Custom Functions -->
<Runtimes>
<Runtime resid="Taskpane.Url" lifetime="long"/>
<Runtime resid="Taskpane.Url" lifetime="long" />
</Runtimes>
<AllFormFactors>
<ExtensionPoint xsi:type="CustomFunctions">
<Script>
<SourceLocation resid="Functions.Script.Url"/>
<SourceLocation resid="Functions.Script.Url" />;
</Script>
<Page>
<SourceLocation resid="Taskpane.Url"/>
<SourceLocation resid="Taskpane.Url" />
</Page>
<Metadata>
<SourceLocation resid="Functions.Metadata.Url"/>
<SourceLocation resid="Functions.Metadata.Url" />
</Metadata>
<Namespace resid="Functions.Namespace"/>
<Namespace resid="Functions.Namespace" />
</ExtensionPoint>
</AllFormFactors>

<DesktopFormFactor>
<!-- FunctionFile is used to bind functions directly to Ribbon buttons -->
<FunctionFile resid="Taskpane.Url" />
<ExtensionPoint xsi:type="PrimaryCommandSurface">

<CustomTab id="MyTab">
<Group id="MyCommandsGroup">
<Label resid="MyCommandsGroup.Label" />
Expand Down Expand Up @@ -107,31 +109,29 @@
<SourceLocation resid="Taskpane.Url" />
</Action>
</Control>

</Group>
<Label resid="MyTab.TabLabel" />
</CustomTab>

</ExtensionPoint>
</DesktopFormFactor>
</Host>
</Hosts>

<Resources>
<bt:Images>
<bt:Image id="Icon.16x16" DefaultValue="https://127.0.0.1:8000/static/images/examples/xlwings-16.png" />
<bt:Image id="Icon.32x32" DefaultValue="https://127.0.0.1:8000/static/images/examples/xlwings-32.png" />
<bt:Image id="Icon.80x80" DefaultValue="https://127.0.0.1:8000/static/images/examples/xlwings-80.png" />
<bt:Image id="Icon.16x16" DefaultValue="{{ base_url }}/static/images/examples/xlwings-16.png" />
<bt:Image id="Icon.32x32" DefaultValue="{{ base_url }}/static/images/examples/xlwings-32.png" />
<bt:Image id="Icon.80x80" DefaultValue="{{ base_url }}/static/images/examples/xlwings-80.png" />
</bt:Images>
<bt:Urls>
<!-- This must point to the HTML document with the task pane -->
<bt:Url id="Taskpane.Url" DefaultValue="https://127.0.0.1:8000/taskpane" />
<bt:Url id="Functions.Script.Url" DefaultValue="https://127.0.0.1:8000/xlwings/custom-functions-code"/>
<bt:Url id="Functions.Metadata.Url" DefaultValue="https://127.0.0.1:8000/xlwings/custom-functions-meta"/>
<bt:Url id="Taskpane.Url" DefaultValue="{{ base_url }}/taskpane" />
<bt:Url id="Functions.Script.Url" DefaultValue="{{ base_url }}/xlwings/custom-functions-code" />
<bt:Url id="Functions.Metadata.Url" DefaultValue="{{ base_url }}/xlwings/custom-functions-meta" />
</bt:Urls>
<bt:ShortStrings>
<!-- Uncomment the next line to use a global Namespace. It can also be set per function via xw.func(namespace="...") -->
<bt:String id="Functions.Namespace" DefaultValue="XLWINGS"/>
<bt:String id="Functions.Namespace" DefaultValue="XLWINGS" />
<bt:String id="MyTab.TabLabel" DefaultValue="xlwings Server" />
<bt:String id="MyCommandsGroup.Label" DefaultValue="MyGroup" />
<bt:String id="MyFunctionButton.Label" DefaultValue="Hello World" />
Expand All @@ -143,14 +143,15 @@
</bt:LongStrings>
</Resources>

<!-- <WebApplicationInfo>
<Id>CLIENT_ID</Id>
<Resource>api://127.0.0.1:8000/CLIENT_ID</Resource>
{% if settings.entraid_tenant_id or settings.entraid_client_id %}
<WebApplicationInfo>
<Id>{{ settings.entraid_client_id }}</Id>
<Resource>api://{{ base_url | replace("https://", "") }}/{{ settings.entraid_client_id }}</Resource>
<Scopes>
<Scope>openid</Scope>
<Scope>profile</Scope>
</Scopes>
</WebApplicationInfo> -->

</WebApplicationInfo>
{% endif %}
</VersionOverrides>
</OfficeApp>

0 comments on commit fb2dd99

Please sign in to comment.