-
Notifications
You must be signed in to change notification settings - Fork 2
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
Edit service access control #47
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,10 @@ import { useAsset } from '@context/Asset' | |
import { setNftMetadata } from '@utils/nft' | ||
import { getEncryptedFiles } from '@utils/provider' | ||
import { useAccount, useNetwork, useSigner } from 'wagmi' | ||
import { transformConsumerParameters } from '@components/Publish/_utils' | ||
import { | ||
generateCredentials, | ||
transformConsumerParameters | ||
} from '@components/Publish/_utils' | ||
import { | ||
defaultDatatokenCap, | ||
defaultDatatokenTemplateIndex, | ||
|
@@ -160,6 +163,12 @@ export default function AddService({ | |
newFiles = filesEncrypted | ||
} | ||
|
||
const credentials = generateCredentials( | ||
undefined, | ||
values.allow, | ||
values.deny | ||
) | ||
|
||
const newService: Service = { | ||
id: getHash(datatokenAddress + newFiles), | ||
type: values.access, | ||
|
@@ -169,6 +178,7 @@ export default function AddService({ | |
datatokenAddress, | ||
serviceEndpoint: values.providerUrl.url, | ||
timeout: mapTimeoutStringToSeconds(values.timeout), | ||
credentials, | ||
...(values.access === 'compute' && { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we use enums, to not have string encoded? |
||
compute: await transformComputeFormToServiceComputeOptions( | ||
values, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { Asset, LoggerInstance, Service } from '@oceanprotocol/lib' | ||
import { Asset, Credentials, LoggerInstance, Service } from '@oceanprotocol/lib' | ||
import { ReactElement, useEffect, useState } from 'react' | ||
import DebugOutput from '@shared/DebugOutput' | ||
import { useCancelToken } from '@hooks/useCancelToken' | ||
|
@@ -10,7 +10,10 @@ import { | |
previewDebugPatch | ||
} from '@utils/ddo' | ||
import { getEncryptedFiles } from '@utils/provider' | ||
import { transformConsumerParameters } from '@components/Publish/_utils' | ||
import { | ||
generateCredentials, | ||
transformConsumerParameters | ||
} from '@components/Publish/_utils' | ||
|
||
export default function DebugEditService({ | ||
values, | ||
|
@@ -53,13 +56,20 @@ export default function DebugEditService({ | |
LoggerInstance.error('Error encrypting files:', error.message) | ||
} | ||
|
||
const credentials: Credentials = generateCredentials( | ||
service.credentials, | ||
values.allow, | ||
values.deny | ||
) | ||
|
||
const updatedService: Service = { | ||
...service, | ||
name: values.name, | ||
description: values.description, | ||
type: values.access, | ||
timeout: mapTimeoutStringToSeconds(values.timeout), | ||
files: updatedFiles, // TODO: check if this works | ||
files: updatedFiles, // TODO: check if this works, | ||
credentials, | ||
...(values.access === 'compute' && { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here. enums? |
||
compute: await transformComputeFormToServiceComputeOptions( | ||
values, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,10 @@ import { useAsset } from '@context/Asset' | |
import { setNftMetadata } from '@utils/nft' | ||
import { getEncryptedFiles } from '@utils/provider' | ||
import { useAccount, useNetwork, useSigner } from 'wagmi' | ||
import { transformConsumerParameters } from '@components/Publish/_utils' | ||
import { | ||
generateCredentials, | ||
transformConsumerParameters | ||
} from '@components/Publish/_utils' | ||
import FormEditService from './FormEditService' | ||
import { transformComputeFormToServiceComputeOptions } from '@utils/compute' | ||
import { useCancelToken } from '@hooks/useCancelToken' | ||
|
@@ -103,12 +106,19 @@ export default function EditService({ | |
updatedFiles = filesEncrypted | ||
} | ||
|
||
const updatedCredentials = generateCredentials( | ||
service.credentials, | ||
values.allow, | ||
values.deny | ||
) | ||
|
||
const updatedService: Service = { | ||
...service, | ||
name: values.name, | ||
description: values.description, | ||
timeout: mapTimeoutStringToSeconds(values.timeout), | ||
files: updatedFiles, // TODO: check if this works | ||
files: updatedFiles, // TODO: check if this works, | ||
credentials: updatedCredentials, | ||
...(values.access === 'compute' && { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
compute: await transformComputeFormToServiceComputeOptions( | ||
values, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,8 @@ export const getNewServiceInitialValues = ( | |
timeout: '1 day', | ||
usesConsumerParameters: false, | ||
consumerParameters: [], | ||
allow: [], | ||
deny: [], | ||
...computeSettings | ||
} | ||
} | ||
|
@@ -105,6 +107,14 @@ export const getServiceInitialValues = ( | |
timeout: secondsToString(service.timeout), | ||
usesConsumerParameters: service.consumerParameters?.length > 0, | ||
consumerParameters: parseConsumerParameters(service.consumerParameters), | ||
allow: | ||
service.credentials?.allow?.find( | ||
(credential) => credential.type === 'address' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe enum? |
||
)?.values || [], | ||
deny: | ||
service.credentials?.deny?.find( | ||
(credential) => credential.type === 'address' | ||
)?.values || [], | ||
...computeSettings | ||
} | ||
} |
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.
Usually optional parameters should be last
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.
I am thinking what to do about it, but perhaps it's best to just keep it like that. It is used like that even in the code that I haven't changed e.g. here https://github.com/OceanProtocolEnterprise/market/blob/main/src/components/Publish/_utils.ts#L242
LMK what you think