Skip to content

Commit

Permalink
Merge pull request #28 from abjrcode/sinks
Browse files Browse the repository at this point in the history
aws credentials file sink can now be configured
  • Loading branch information
abjrcode authored Dec 9, 2023
2 parents 3f80f32 + 7e1df5b commit ca79c6d
Show file tree
Hide file tree
Showing 36 changed files with 832 additions and 128 deletions.
19 changes: 18 additions & 1 deletion app_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/abjrcode/swervo/internal/app"
"github.com/abjrcode/swervo/internal/utils"
awsidc "github.com/abjrcode/swervo/providers/aws_idc"
awscredentialsfile "github.com/abjrcode/swervo/sinks/aws_credentials_file"
"github.com/rs/zerolog"
"github.com/wailsapp/wails/v2/pkg/menu"
"github.com/wailsapp/wails/v2/pkg/menu/keys"
Expand All @@ -28,7 +29,10 @@ type AppController struct {

authController *AuthController
dashboardController *DashboardController
awsIdcController *awsidc.AwsIdentityCenterController

awsIdcController *awsidc.AwsIdentityCenterController

awsCredentialsFileController *awscredentialsfile.AwsCredentialsFileController
}

func (c *AppController) Init(ctx context.Context, errorHandler app.ErrorHandler) {
Expand Down Expand Up @@ -132,6 +136,8 @@ func (c *AppController) RunAppCommand(command string, commandInput map[string]an
output = c.dashboardController.ListProviders()
case "Dashboard_ListFavorites":
output, err = c.dashboardController.ListFavorites(appContext)
case "Dashboard_ListSinks":
output = c.dashboardController.ListSinks()
case "AwsIdc_ListInstances":
output, err = c.awsIdcController.ListInstances(appContext)
case "AwsIdc_GetInstanceData":
Expand Down Expand Up @@ -176,6 +182,17 @@ func (c *AppController) RunAppCommand(command string, commandInput map[string]an
UserCode: commandInput["userCode"].(string),
DeviceCode: commandInput["deviceCode"].(string),
})
case "AwsCredentialsFile_ListInstances":
output, err = c.awsCredentialsFileController.ListInstances(appContext)
case "AwsCredentialsFile_NewInstance":
output, err = c.awsCredentialsFileController.NewInstance(appContext,
awscredentialsfile.AwsCredentialsFile_NewInstanceCommandInput{
FilePath: commandInput["filePath"].(string),
Label: commandInput["label"].(string),
})
case "AwsCredentialsFile_GetInstanceData":
output, err = c.awsCredentialsFileController.GetInstanceData(appContext,
commandInput["instanceId"].(string))
default:
output, err = nil, errors.Join(ErrInvalidAppCommand, app.ErrFatal)
}
Expand Down
27 changes: 23 additions & 4 deletions dashboard_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ import (
"github.com/abjrcode/swervo/favorites"
"github.com/abjrcode/swervo/internal/app"
"github.com/abjrcode/swervo/providers"
"github.com/abjrcode/swervo/sinks"
)

type DashboardController struct {
favoritesRepo favorites.FavoritesRepo
}

type Provider struct {
Code string `json:"code"`
Name string `json:"name"`
Expand All @@ -23,6 +20,16 @@ type FavoriteInstance struct {
InstanceId string `json:"instanceId"`
}

type Sink struct {
Code string `json:"code"`
Name string `json:"name"`
IconSvgBase64 string `json:"iconSvgBase64"`
}

type DashboardController struct {
favoritesRepo favorites.FavoritesRepo
}

var supportedProviders []Provider

func NewDashboardController(favoritesRepo favorites.FavoritesRepo) *DashboardController {
Expand Down Expand Up @@ -61,3 +68,15 @@ func (c *DashboardController) ListFavorites(ctx app.Context) ([]FavoriteInstance
func (c *DashboardController) ListProviders() []Provider {
return supportedProviders
}

func (c *DashboardController) ListSinks() []Sink {
supportedSinks := make([]Sink, 0, len(sinks.SupportedSinks))
for _, sink := range sinks.SupportedSinks {
supportedSinks = append(supportedSinks, Sink{
Code: sink.Code,
Name: sink.Name,
})
}

return supportedSinks
}
5 changes: 5 additions & 0 deletions frontend/src/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export function Layout({ children }: { children: React.ReactNode }) {
className="btn btn-primary btn-outline capitalize">
providers
</Link>
<Link
to="/sinks"
className="btn btn-primary btn-outline capitalize">
sinks
</Link>
</nav>

<button
Expand Down
61 changes: 52 additions & 9 deletions frontend/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,27 @@ import { createHashRouter, RouterProvider } from "react-router-dom"
import { Dashboard } from "./routes/dashboard/dashboard"
import { dashboardLoader } from "./routes/dashboard/dashboard-data"
import { providersLoader } from "./routes/providers/providers-data"
import { awsIdcCardLoader } from "./routes/aws-idc/aws-idc-card-data"
import { awsIdcCardLoader } from "./routes/providers/aws-idc/card-data"
import { Providers } from "./routes/providers/providers"
import { AwsIdcSetup } from "./routes/aws-idc/aws-idc-setup"
import { awsIdcSetupAction } from "./routes/aws-idc/aws-idc-setup-data"
import { AwsIdcSetup } from "./routes/providers/aws-idc/setup"
import { awsIdcSetupAction } from "./routes/providers/aws-idc/setup-data"
import { Vault } from "./routes/vault/vault"
import { AuthProvider } from "./auth-provider/auth-provider"
import { ErrorPage } from "./error-page"
import { WailsProvider } from "./wails-provider/wails-provider"
import { AwsIdcDeviceAuth } from "./routes/aws-idc/aws-idc-device-auth"
import { awsIdcDeviceAuthAction } from "./routes/aws-idc/aws-idc-device-auth-data"
import { AwsIdcDeviceAuth } from "./routes/providers/aws-idc/device-auth"
import { awsIdcDeviceAuthAction } from "./routes/providers/aws-idc/device-auth-data"
import { ToastProvider } from "./toast-provider/toast-provider"
import { AwsIdcInstances } from "./routes/aws-idc/aws-idc-instances"
import { awsIdcInstancesData } from "./routes/aws-idc/aws-idc-instances-data"
import { AwsIdcInstances } from "./routes/providers/aws-idc/instances"
import { awsIdcInstancesData } from "./routes/providers/aws-idc/instances-data"
import { Auth_IsVaultConfigured } from "./utils/ipc-adapter"
import { Sinks } from "./routes/sinks/sinks"
import { sinksLoader } from "./routes/sinks/sinks-data"
import { AwsCredentialsFileInstances } from "./routes/sinks/aws-credentials-file/instances"
import { awsCredentialsFileInstancesData } from "./routes/sinks/aws-credentials-file/instances-data"
import { AwsCredentialsFileNew } from "./routes/sinks/aws-credentials-file/new"
import { awsCredentialsFileSetupAction } from "./routes/sinks/aws-credentials-file/new-data"
import { awsCredentialsFileCardLoader } from "./routes/sinks/aws-credentials-file/card-data"

const devMode = import.meta.env.DEV

Expand Down Expand Up @@ -68,11 +75,47 @@ void (async function main() {
},
],
},
{
path: "/sinks",
element: <Sinks />,
loader: sinksLoader,
children: [
{
path: "aws-credentials-file",
children: [
{
index: true,
element: <AwsCredentialsFileInstances />,
loader: awsCredentialsFileInstancesData,
},
{
path: "setup",
element: <AwsCredentialsFileNew />,
action: awsCredentialsFileSetupAction,
},
],
},
],
},
],
},
{
path: "/internal/api/aws-idc-card",
loader: awsIdcCardLoader,
path: "/internal",
children: [
{
path: "api",
children: [
{
path: "aws-idc-card",
loader: awsIdcCardLoader,
},
{
path: "aws-credentials-file-card",
loader: awsCredentialsFileCardLoader,
},
],
},
],
},
])

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/routes/dashboard/dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useLoaderData } from "react-router-dom"
import { AwsIdcCard } from "../aws-idc/aws-idc-card"
import { AwsIdcCard } from "../providers/aws-idc/card"
import { main } from "../../../wailsjs/go/models"

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { awsidc } from '../../../wailsjs/go/models'
import { ActionDataResult } from '../../utils/action-data-result'
import { AwsIdc_GetInstanceData } from '../../utils/ipc-adapter'
import { awsidc } from '../../../../wailsjs/go/models'
import { ActionDataResult } from '../../../utils/action-data-result'
import { AwsIdc_GetInstanceData } from '../../../utils/ipc-adapter'

export enum AwsIdcCardDataError {
ErrAccessTokenExpired = "ACCESS_TOKEN_EXPIRED",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React from "react"
import { useFetcher, useNavigate, useRevalidator } from "react-router-dom"

import { AwsIdcCardDataError, AwsIdcCardDataResult } from "./aws-idc-card-data"
import { useWails } from "../../wails-provider/wails-context"
import { useToaster } from "../../toast-provider/toast-context"
import { AwsIdcCardDataError, AwsIdcCardDataResult } from "./card-data"
import { useWails } from "../../../wails-provider/wails-context"
import { useToaster } from "../../../toast-provider/toast-context"
import {
AwsIdc_GetRoleCredentials,
AwsIdc_MarkAsFavorite,
AwsIdc_RefreshAccessToken,
AwsIdc_UnmarkAsFavorite,
} from "../../utils/ipc-adapter"
} from "../../../utils/ipc-adapter"

export function AwsIdcCard({ instanceId }: { instanceId: string }) {
const wails = useWails()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ActionFunctionArgs } from "react-router-dom"
import { AwsIdc_FinalizeRefreshAccessToken, AwsIdc_FinalizeSetup } from "../../utils/ipc-adapter"
import { ActionDataResult } from "../../utils/action-data-result"
import { AwsIdc_FinalizeRefreshAccessToken, AwsIdc_FinalizeSetup } from "../../../utils/ipc-adapter"
import { ActionDataResult } from "../../../utils/action-data-result"

export enum AwsIdcDeviceAuthFlowError {
ErrDeviceAuthFlowNotAuthorized = "DEVICE_AUTH_FLOW_NOT_AUTHORIZED",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Form, useActionData, useLocation, useNavigate } from "react-router-dom"
import { ExternalLink } from "../../components/external-link"
import { ExternalLink } from "../../../components/external-link"
import {
AwsIdcDeviceAuthFlowError,
AwsIdcDeviceAuthFlowResult,
} from "./aws-idc-device-auth-data"
} from "./device-auth-data"
import { useEffect, useRef } from "react"
import { useToaster } from "../../toast-provider/toast-context"
import { useToaster } from "../../../toast-provider/toast-context"

export function AwsIdcDeviceAuth() {
const toaster = useToaster()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AwsIdc_ListInstances } from "../../utils/ipc-adapter";
import { AwsIdc_ListInstances } from "../../../utils/ipc-adapter";

export function awsIdcInstancesData() {
return AwsIdc_ListInstances()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Link, useLoaderData } from "react-router-dom"
import { AwsIdcCard } from "./aws-idc-card"
import { AwsIdcCard } from "./card"

export function AwsIdcInstances() {
const loader = useLoaderData() as string[] | undefined
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ActionFunctionArgs } from "react-router-dom"
import { awsidc } from "../../../wailsjs/go/models"
import { ActionDataResult } from "../../utils/action-data-result"
import { AwsIdc_Setup } from "../../utils/ipc-adapter"
import { awsidc } from "../../../../wailsjs/go/models"
import { ActionDataResult } from "../../../utils/action-data-result"
import { AwsIdc_Setup } from "../../../utils/ipc-adapter"

export enum AwsIdcSetupError {
ErrInstanceAlreadyRegistered = "INSTANCE_ALREADY_REGISTERED",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Form, useActionData, useNavigate } from "react-router-dom"
import { useEffect } from "react"
import { useWails } from "../../wails-provider/wails-context"
import { AwsIdcSetupError, AwsIdcSetupResult } from "./aws-idc-setup-data"
import { useToaster } from "../../toast-provider/toast-context"
import { useWails } from "../../../wails-provider/wails-context"
import { AwsIdcSetupError, AwsIdcSetupResult } from "./setup-data"
import { useToaster } from "../../../toast-provider/toast-context"

export function AwsIdcSetup() {
const wails = useWails()
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/routes/providers/providers-data.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ListProviders } from "../../../wailsjs/go/main/DashboardController"
import { Dashboard_ListProviders } from "../../utils/ipc-adapter";

export async function providersLoader() {
return ListProviders()
return Dashboard_ListProviders()
}
26 changes: 26 additions & 0 deletions frontend/src/routes/sinks/aws-credentials-file/card-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { awscredentialsfile } from '../../../../wailsjs/go/models'
import { ActionDataResult } from '../../../utils/action-data-result'
import { AwsCredentialsFile_GetInstanceData } from '../../../utils/ipc-adapter'

export enum AwsCredentialsFileCardDataError { }

export type AwsCredentialsFileCardDataResult = ActionDataResult<awscredentialsfile.AwsCredentialsFileInstance, AwsCredentialsFileCardDataError>

export async function awsCredentialsFileCardLoader({ request }: { request: Request }): Promise<AwsCredentialsFileCardDataResult> {
const instanceId = new URL(request.url).searchParams.get('instanceId')

if (!instanceId) {
throw new Response('instanceId is required', { status: 400 })
}

try {
return { success: true, result: await AwsCredentialsFile_GetInstanceData(instanceId) }
}
catch (error) {
switch (error) {

default:
throw error
}
}
}
42 changes: 42 additions & 0 deletions frontend/src/routes/sinks/aws-credentials-file/card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from "react"
import { useFetcher } from "react-router-dom"

import { AwsCredentialsFileCardDataResult } from "./card-data"

export function AwsCredentialsFileCard({ instanceId }: { instanceId: string }) {
const fetcher = useFetcher()

React.useEffect(() => {
if (fetcher.state === "idle" && !fetcher.data) {
const urlSearchParams = new URLSearchParams()
urlSearchParams.append("instanceId", instanceId)
fetcher.load(
`/internal/api/aws-credentials-file-card?${urlSearchParams.toString()}`,
)
}
}, [instanceId, fetcher])

const cardDataResult = fetcher.data as AwsCredentialsFileCardDataResult | undefined

if (cardDataResult === undefined) {
return <div className="skeleton items-center w-48"></div>
}

if (cardDataResult.success) {
const cardData = cardDataResult.result

return (
<div className="card gap-6 px-6 py-4 max-w-lg card-bordered border-secondary bg-base-200 drop-shadow-lg">
<div
role="heading"
className="card-title justify-between">
<div className="inline-flex items-center justify-center gap-2">
<h1 className="text-2xl font-semibold">{cardData.label}</h1>
</div>
</div>
<div className="card-body">{cardData.filePath}</div>
<div className="card-actions items-center justify-between"></div>
</div>
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { AwsCredentialsFile_ListInstances } from "../../../utils/ipc-adapter";

export function awsCredentialsFileInstancesData() {
return AwsCredentialsFile_ListInstances();
}
Loading

0 comments on commit ca79c6d

Please sign in to comment.