Skip to content

Commit

Permalink
Merge pull request #102 from aleph-im/feature-domain-support-confiden…
Browse files Browse the repository at this point in the history
…tials

Add domain support for confidentials
  • Loading branch information
philogicae authored Sep 27, 2024
2 parents 9c3ff2b + 00b3d99 commit f81858f
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 28 deletions.
13 changes: 9 additions & 4 deletions src/components/pages/dashboard/ManageDomain/cmp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ export default function ManageDomain() {
{domain.name}.program.public.aleph.sh.
</span>
)}
{domain.target == EntityDomainType.Instance && (
{[
EntityDomainType.Instance,
EntityDomainType.Confidential,
].includes(domain.target) && (
<span className="text-main0" tw="mx-2">
{domain.name}.instance.public.aleph.sh.
</span>
Expand Down Expand Up @@ -278,9 +281,11 @@ export default function ManageDomain() {
href={
(domain.target === 'instance'
? '/computing/instance/'
: domain.target === 'program'
? '/computing/function/'
: '/storage/volume/') + refEntity.id
: domain.target === 'confidential'
? '/computing/confidential/'
: domain.target === 'program'
? '/computing/function/'
: '/storage/volume/') + refEntity.id
}
>
<IconText iconName="square-up-right">Details</IconText>
Expand Down
16 changes: 12 additions & 4 deletions src/components/pages/settings/NewDomainPage/cmp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@ export default function NewDomain() {
const labelResourceType =
targetCtrl.field.value == EntityDomainType.Instance
? 'instance'
: 'function'
: targetCtrl.field.value == EntityDomainType.Confidential
? 'confidential'
: 'function'

const onTabChange = (tabId: string) => {
setRef('')
setTabId(tabId)
if (['website', 'ipfs'].includes(tabId)) {
setTarget(EntityDomainType.IPFS)
} else {
setTarget(EntityDomainType.Instance)
setTarget(EntityDomainType.Program)
}
}

Expand Down Expand Up @@ -150,13 +152,19 @@ export default function NewDomain() {
label="Choose resource type"
direction="row"
>
<Radio
label={EntityDomainTypeName[EntityDomainType.Program]}
value={EntityDomainType.Program}
/>
<Radio
label={EntityDomainTypeName[EntityDomainType.Instance]}
value={EntityDomainType.Instance}
/>
<Radio
label={EntityDomainTypeName[EntityDomainType.Program]}
value={EntityDomainType.Program}
label={
EntityDomainTypeName[EntityDomainType.Confidential]
}
value={EntityDomainType.Confidential}
/>
</RadioGroup>
{entities.length > 0 ? (
Expand Down
37 changes: 34 additions & 3 deletions src/domain/confidential.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { Account } from '@aleph-sdk/account'
import { InstanceContent, MessageType } from '@aleph-sdk/message'
import { defaultInstanceChannel, EntityType } from '@/helpers/constants'
import {
CheckoutStepType,
defaultInstanceChannel,
EntityType,
} from '@/helpers/constants'
import { getDate, getExplorerURL } from '@/helpers/utils'
import { ExecutableManager, ExecutableStatus } from './executable'
import { FileManager } from './file'
import { SSHKeyManager } from './ssh'
import { VolumeManager } from './volume'
import { DomainManager } from './domain'
import { ReadOnlyEntityManager } from './types'
import { EntityManager } from './types'
import {
instanceSchema,
instanceStreamSchema,
Expand All @@ -33,7 +38,7 @@ export type Confidential = InstanceContent & {

export class ConfidentialManager
extends ExecutableManager
implements ReadOnlyEntityManager<Confidential>
implements EntityManager<Confidential, unknown>
{
static addSchema = instanceSchema
static addStreamSchema = instanceStreamSchema
Expand All @@ -51,6 +56,32 @@ export class ConfidentialManager
super(account, volumeManager, domainManager, nodeManager, sdkClient)
}

add(entity: unknown): Promise<Confidential | Confidential[]> {
throw new Error('Method not implemented.')
}
del(entityOrId: string | Confidential): Promise<void> {
throw new Error('Method not implemented.')
}
getAddSteps(entity: unknown): Promise<CheckoutStepType[]> {
throw new Error('Method not implemented.')
}
addSteps(
entity: unknown,
): AsyncGenerator<void, Confidential | Confidential[], void> {
throw new Error('Method not implemented.')
}
getDelSteps(
entity: string | Confidential | (string | Confidential)[],
): Promise<CheckoutStepType[]> {
throw new Error('Method not implemented.')
}
delSteps(
entity: string | Confidential | (string | Confidential)[],
extra?: any,
): AsyncGenerator<void> {
throw new Error('Method not implemented.')
}

async getAll(): Promise<Confidential[]> {
try {
const response = await this.sdkClient.getMessages({
Expand Down
48 changes: 34 additions & 14 deletions src/domain/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,22 @@ export class DomainManager implements EntityManager<Domain, AddDomain> {
}

async retry(domain: Domain) {
const isConfidential = domain.target == EntityDomainType.Confidential
const type = isConfidential ? EntityDomainType.Instance : domain.target
const content: DomainAggregate = {
[domain.name]: {
message_id: domain.ref,
type: domain.target,
type,
updated_at: new Date().toISOString(),
...(domain.target === EntityDomainType.IPFS
...(type === EntityDomainType.IPFS
? {
options: { catch_all_path: '/404.html' },
}
: {}),
: isConfidential
? {
options: { confidential: true },
}
: {}),
},
}

Expand Down Expand Up @@ -143,15 +149,21 @@ export class DomainManager implements EntityManager<Domain, AddDomain> {
try {
const content: DomainAggregate = domains.reduce((ac, cv) => {
const { name, ref, target } = cv
const isConfidential = target == EntityDomainType.Confidential
const type = isConfidential ? EntityDomainType.Instance : target
ac[name] = {
message_id: ref,
type: target,
type,
updated_at: new Date().toISOString(),
...(target === EntityDomainType.IPFS
...(type === EntityDomainType.IPFS
? {
options: { catch_all_path: '/404.html' },
}
: {}),
: isConfidential
? {
options: { confidential: true },
}
: {}),
}
return ac
}, {} as DomainAggregate)
Expand Down Expand Up @@ -200,7 +212,10 @@ export class DomainManager implements EntityManager<Domain, AddDomain> {
body: JSON.stringify({
name: domain.name,
owner: this.account.address,
target: domain.target,
target:
domain.target == EntityDomainType.Confidential
? EntityDomainType.Instance
: domain.target,
}),
})
const response = await query.json()
Expand Down Expand Up @@ -274,13 +289,18 @@ export class DomainManager implements EntityManager<Domain, AddDomain> {
name: string,
content: DomainAggregateItem,
): Domain {
const { message_id, type, updated_at } = content
const { message_id, type, updated_at, options } = content
const target = options?.['confidential']
? EntityDomainType.Confidential
: type
const ref_path =
type === EntityDomainType.Instance
? 'computing/instance'
: type === EntityDomainType.Program
? 'computing/function'
: 'storage/volume'
type === EntityDomainType.Program
? 'computing/function'
: type === EntityDomainType.Instance
? 'computing/instance'
: type === EntityDomainType.Confidential
? 'computing/confidential'
: 'storage/volume'
let date = '-'
try {
date = updated_at?.slice(0, 19).replace('T', ' ') || '-'
Expand All @@ -289,7 +309,7 @@ export class DomainManager implements EntityManager<Domain, AddDomain> {
type: EntityType.Domain,
id: name,
name,
target: type,
target,
ref: message_id,
confirmed: true,
updated_at: date,
Expand Down
7 changes: 7 additions & 0 deletions src/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const defaultInstanceChannel = defaultConsoleChannel
export const defaultProgramChannel = defaultConsoleChannel
export const defaultDomainChannel = defaultConsoleChannel
export const defaultWebsiteChannel = defaultConsoleChannel
export const defaultConfidentialChannel = defaultConsoleChannel

export enum EntityType {
Volume = 'volume',
Expand All @@ -64,6 +65,7 @@ export enum EntityType {
Domain = 'domain',
Indexer = 'indexer',
Website = 'website',
Confidential = 'confidential',
}

type CheckoutAddStepType =
Expand Down Expand Up @@ -104,12 +106,14 @@ export enum EntityDomainType {
IPFS = 'ipfs',
Program = 'program',
Instance = 'instance',
Confidential = 'confidential',
}

export const EntityDomainTypeName: Record<EntityDomainType, string> = {
[EntityDomainType.IPFS]: 'IPFS',
[EntityDomainType.Program]: 'Function',
[EntityDomainType.Instance]: 'Instance',
[EntityDomainType.Confidential]: 'Confidential',
}

export enum VolumeType {
Expand All @@ -126,12 +130,14 @@ export const EntityTypeName: Record<EntityType, string> = {
[EntityType.Domain]: 'Domain',
[EntityType.Indexer]: 'Indexer',
[EntityType.Website]: 'Website',
[EntityType.Confidential]: 'Confidential',
}

export const EntityTypeUrlSection: Record<EntityType, string> = {
[EntityType.Volume]: 'storage',
[EntityType.Program]: 'computing',
[EntityType.Instance]: 'computing',
[EntityType.Confidential]: 'computing',
[EntityType.SSHKey]: 'settings',
[EntityType.Domain]: 'settings',
[EntityType.Indexer]: 'tools',
Expand All @@ -146,6 +152,7 @@ export const EntityTypeSlug: Record<EntityType, string> = {
[EntityType.Domain]: 'domain',
[EntityType.Indexer]: 'indexer',
[EntityType.Website]: 'website',
[EntityType.Confidential]: 'confidential',
}

export enum IndexerBlockchain {
Expand Down
1 change: 1 addition & 0 deletions src/helpers/schemas/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const ipfsCIDSchema = requiredStringSchema.regex(

export const targetSchema = z.enum([
EntityDomainType.Instance,
EntityDomainType.Confidential,
EntityDomainType.Program,
EntityDomainType.IPFS,
])
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,14 @@ export const isVolume = (msg: AnyMessage) => msg.type === MessageType.store
export const isProgram = (msg: AnyMessage) => msg.type === MessageType.program
export const isInstance = (msg: AnyMessage) => msg.type === MessageType.instance
export const isSSHKey = (msg: AnyMessage) => msg.type === MessageType.post
export const isConfidential = (msg: AnyMessage) =>
msg.type === MessageType.instance &&
(msg.content as any)?.environment?.trusted_execution?.firmware.length == 64

export function getEntityTypeFromMessage(msg: AnyMessage): EntityType {
if (isVolume(msg)) return EntityType.Volume
if (isProgram(msg)) return EntityType.Program
if (isConfidential(msg)) return EntityType.Confidential
if (isInstance(msg)) return EntityType.Instance
if (isSSHKey(msg)) return EntityType.SSHKey
throw Err.UnknownType
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/common/useManager/useEntityManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function useEntityManager(
instanceManager,
indexerManager,
websiteManager,
confidentialManager,
} = appState.manager

const entityMap: Record<
Expand All @@ -29,6 +30,7 @@ export function useEntityManager(
[EntityType.Program]: programManager,
[EntityType.Indexer]: indexerManager,
[EntityType.Website]: websiteManager,
[EntityType.Confidential]: confidentialManager,
}
}, [
domainManager,
Expand All @@ -38,6 +40,7 @@ export function useEntityManager(
volumeManager,
indexerManager,
websiteManager,
confidentialManager,
])

if (!type) return
Expand Down
27 changes: 24 additions & 3 deletions src/hooks/pages/settings/useNewDomainPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export function useNewDomainPage(): UseNewDomainPageReturn {
instance: { entities: instances },
program: { entities: programs },
website: { entities: websites },
confidential: { entities: confidentials },
},
dispatch,
] = useAppState()
Expand Down Expand Up @@ -141,7 +142,11 @@ export function useNewDomainPage(): UseNewDomainPageReturn {
if (!entityType) return []
if (entityType !== EntityDomainType.IPFS) {
const entities =
entityType === EntityDomainType.Instance ? instances : programs
entityType === EntityDomainType.Instance
? instances
: entityType === EntityDomainType.Confidential
? confidentials
: programs
return (entities || []).map(({ id, metadata }) => {
return {
label: (metadata?.name as string | undefined) || id,
Expand All @@ -157,11 +162,15 @@ export function useNewDomainPage(): UseNewDomainPageReturn {
type: entityType,
}
})
}, [entityType, instances, programs, websites])
}, [entityType, instances, programs, websites, confidentials])

const hasInstances = useMemo(() => !!instances?.length, [instances])
const hasFunctions = useMemo(() => !!programs?.length, [programs])
const hasWebsites = useMemo(() => !!websites?.length, [websites])
const hasConfidentials = useMemo(
() => !!confidentials?.length,
[confidentials],
)
/* const hasEntities = useMemo(
() => hasInstances || hasFunctions || hasWebsites,
[hasFunctions, hasInstances, hasWebsites],
Expand All @@ -170,12 +179,24 @@ export function useNewDomainPage(): UseNewDomainPageReturn {
useEffect(() => {
if (entityType === EntityDomainType.Instance && hasInstances) {
setValue('target', EntityDomainType.Instance)
} else if (
entityType === EntityDomainType.Confidential &&
hasConfidentials
) {
setValue('target', EntityDomainType.Confidential)
} else if (entityType === EntityDomainType.Program && hasFunctions) {
setValue('target', EntityDomainType.Program)
} else if (entityType === EntityDomainType.IPFS) {
setValue('target', EntityDomainType.IPFS)
}
}, [entityType, hasFunctions, hasInstances, hasWebsites, setValue])
}, [
entityType,
hasFunctions,
hasInstances,
hasConfidentials,
hasWebsites,
setValue,
])

const setTarget = (target: EntityDomainType) => {
setValue('target', target)
Expand Down
Loading

0 comments on commit f81858f

Please sign in to comment.