Skip to content

Commit

Permalink
[UXE-6266] feat: add origin type live_ingest form to origin pages (#2122
Browse files Browse the repository at this point in the history
)
  • Loading branch information
aloisio-m-bastian authored Feb 5, 2025
1 parent ad9256d commit 03d4c18
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 21 deletions.
4 changes: 3 additions & 1 deletion src/services/contract-services/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { loadContractServicePlan } from './load-contract-service-plan'
import { makeContractBaseUrl } from './make-contract-base-url'
export { loadContractServicePlan, makeContractBaseUrl }
import { loadProductsListService } from './load-products-list-service'

export { loadContractServicePlan, makeContractBaseUrl, loadProductsListService }
21 changes: 21 additions & 0 deletions src/services/contract-services/load-products-list-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { AxiosHttpClientAdapter, parseHttpResponse } from '../axios/AxiosHttpClientAdapter'
import { makeContractBaseUrl } from './make-contract-base-url'

export const loadProductsListService = async ({ clientId }) => {
let httpResponse = await AxiosHttpClientAdapter.request({
url: `${makeContractBaseUrl()}/${clientId}/products`,
method: 'GET'
})
const parsedData = adapt(httpResponse)
return parseHttpResponse(parsedData)
}

const adapt = (httpResponse) => {
const products = httpResponse.body || []
const slugs = products?.map((product) => product.slug)

return {
body: { slugs },
statusCode: httpResponse.statusCode
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ const adapt = (payload) => {
}
}

if (payload.originType === 'live_ingest') {
return {
name: payload.name,
origin_type: payload.originType,
streaming_endpoint: payload.streamingEndpoint
}
}

return {
name: payload.name,
origin_type: payload.originType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ const adapt = (payload) => {
}
}

if (payload.originType === 'live_ingest') {
return {
name: payload.name,
origin_type: payload.originType,
streaming_endpoint: payload.streamingEndpoint
}
}

let payloadAdapted = {
name: payload.name,
host_header: payload.hostHeader,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ const adapt = (httpResponse) => {
originId: convertOriginIdToString(origin.origin_id),
name: origin.name,
originType: originTypeFormat[origin.origin_type],
addresses: formattedListOfAddresses,
addresses:
origin.origin_type === 'live_ingest'
? [origin.streaming_endpoint]
: formattedListOfAddresses,
originProtocolPolicy: origin.origin_protocol_policy,
isOriginRedirectionEnabled: origin.is_origin_redirection_enabled,
hostHeader: origin.host_header,
hostHeader: origin.origin_type === 'live_ingest' ? '-' : origin.host_header,
method: origin.method,
originPath: origin.origin_path,
connectionTimeout: origin.connection_timeout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ export const loadOriginService = async ({ edgeApplicationId, id }) => {

const adapt = (httpResponse) => {
const origin = httpResponse.body?.results
if (origin.origin_type === 'live_ingest') {
return {
body: {
originId: origin.origin_id,
originKey: origin.origin_key,
name: origin.name,
originType: origin.origin_type,
streamingEndpoint: origin.streaming_endpoint
},
statusCode: httpResponse.statusCode
}
}

const parsedBody = {
originId: origin.origin_id,
originKey: origin.origin_key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ const fixtures = {
connectionTimeout: 60,
timeoutBetweenBytes: 35
},
requestPayloadMockLiveIngest: {
name: 'New Origin',
originType: 'live_ingest',
streamingEndpoint: 'br-east-1.azioningest.net'
},
adaptedPayloadMock: {
name: 'New Origin',
origin_type: 'single_origin',
Expand Down Expand Up @@ -107,6 +112,15 @@ const scenarios = [
bucket: 'my-bucket',
prefix: '/'
}
},
{
label: 'should call API with correct params when origin type is live ingest',
payload: fixtures.requestPayloadMockLiveIngest,
adaptedPayload: {
name: 'New Origin',
origin_type: 'live_ingest',
streaming_endpoint: 'br-east-1.azioningest.net'
}
}
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ const fixtures = {
bucketName: 'my-bucket',
prefix: '/test'
},
requestPayloadMockLiveIngest: {
id: '0000000-00000000-00a0a00s0as0-000000',
edgeApplicationId: 123,
name: 'New Origin',
originType: 'live_ingest',
streamingEndpoint: 'br-east-1.azioningest.net'
},
emptyPrefixOrigin: {
id: '0000000-00000000-00a0a00s0as0-000000',
edgeApplicationId: 123,
Expand Down Expand Up @@ -120,6 +127,28 @@ describe('EdgeApplicationOriginsServices', () => {
}
})
})

it('should call API with correct params when origin type is live ingest', async () => {
const requestSpy = vi.spyOn(AxiosHttpClientAdapter, 'request').mockResolvedValueOnce({
statusCode: 200
})

const { sut } = makeSut()
const version = 'v3'

await sut(fixtures.requestPayloadMockLiveIngest)

expect(requestSpy).toHaveBeenCalledWith({
url: `${version}/edge_applications/${fixtures.requestPayloadMockLiveIngest.edgeApplicationId}/origins/${fixtures.requestPayloadMockLiveIngest.id}`,
method: 'PATCH',
body: {
origin_type: fixtures.requestPayloadMockLiveIngest.originType,
name: fixtures.requestPayloadMockLiveIngest.name,
streaming_endpoint: fixtures.requestPayloadMockLiveIngest.streamingEndpoint
}
})
})

it('should adapt prefix to / when the field is empty', async () => {
const requestSpy = vi.spyOn(AxiosHttpClientAdapter, 'request').mockResolvedValueOnce({
statusCode: 200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ const fixtures = {
hmac_access_key: '',
hmac_secret_key: ''
},
originLiveIngestType: {
origin_id: '111111',
origin_key: '11111-0000-11111-111111-11111',
name: 'Origin 2',
origin_type: 'live_ingest',
streaming_endpoint: 'br-east-1.azioningest.net'
},
originLoadBalancerType: {
origin_id: '111111',
origin_key: '11111-0000-11111-111111-11111',
Expand Down Expand Up @@ -84,15 +91,19 @@ describe('EdgeApplicationOriginsServices', () => {
vi.spyOn(AxiosHttpClientAdapter, 'request').mockResolvedValueOnce({
statusCode: 200,
body: {
results: [fixtures.originSingleType, fixtures.originLoadBalancerType]
results: [
fixtures.originSingleType,
fixtures.originLoadBalancerType,
fixtures.originLiveIngestType
]
}
})

const edgeApplicationId = 123

const { sut } = makeSut()
const result = await sut({ id: edgeApplicationId })
const [singleType, loadBalancerType] = result
const [singleType, loadBalancerType, liveIngestType] = result

expect(singleType).toEqual({
id: fixtures.originSingleType.origin_key,
Expand Down Expand Up @@ -137,5 +148,22 @@ describe('EdgeApplicationOriginsServices', () => {
hmacAccessKey: fixtures.originLoadBalancerType.hmac_access_key,
hmacSecretKey: fixtures.originLoadBalancerType.hmac_secret_key
})

expect(liveIngestType).toEqual({
id: fixtures.originLiveIngestType.origin_key,
originKey: {
content: fixtures.originLiveIngestType.origin_key
},
connectionTimeout: undefined,
hmacAccessKey: undefined,
hmacAuthentication: undefined,
hmacRegionName: undefined,
hmacSecretKey: undefined,
hostHeader: '-',
originId: fixtures.originLiveIngestType.origin_id,
name: fixtures.originLiveIngestType.name,
originType: 'Live Ingest',
addresses: ['br-east-1.azioningest.net']
})
})
})
42 changes: 30 additions & 12 deletions src/views/EdgeApplicationsOrigins/Drawer/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import CopyKeyDialog from '@templates/dialog-copy-key'
import { refDebounced } from '@vueuse/core'
import { useToast } from 'primevue/usetoast'
import { onMounted } from 'vue'
import { useAccountStore } from '@/stores/account'
import { loadProductsListService } from '@/services/contract-services'
import { useDialog } from 'primevue/usedialog'
import { createOriginService } from '@/services/edge-application-origins-services'
import { inject, ref } from 'vue'
Expand Down Expand Up @@ -47,14 +50,28 @@
}
})
onMounted(async () => {
const products = await loadProductsListService({ clientId: accountStore.account.client_id })
if (products.slugs.includes('live_ingest')) {
hasLiveIngest.value = true
}
originTypesOptions.value.push({
label: 'Live Ingest',
value: 'live_ingest',
disabled: !hasLiveIngest.value
})
})
const accountStore = useAccountStore()
const toast = useToast()
const showCreateOriginDrawer = ref(false)
const hasLiveIngest = ref(false)
const showEditOriginDrawer = ref(false)
const debouncedDrawerAnimate = 300
const loadCreateOriginDrawer = refDebounced(showCreateOriginDrawer, debouncedDrawerAnimate)
const loadEditOriginDrawer = refDebounced(showEditOriginDrawer, debouncedDrawerAnimate)
const selectedOriginToEdit = ref('')
const ORIGIN_TYPES_OPTIONS = [
const originTypesOptions = ref([
{
label: 'Single Origin',
value: 'single_origin',
Expand All @@ -70,7 +87,7 @@
value: 'object_storage',
disabled: false
}
]
])
const initialValues = ref({
id: props.edgeApplicationId,
Expand Down Expand Up @@ -109,11 +126,11 @@
.string()
.label('Host Header')
.when('originType', {
is: (originType) => originType !== 'object_storage',
is: (originType) => originType !== 'object_storage' && originType !== 'live_ingest',
then: (schema) => schema.required()
}),
addresses: yup.array().when('originType', {
is: (originType) => originType === 'object_storage',
is: (originType) => originType === 'object_storage' || originType === 'live_ingest',
then: (schema) => schema.optional(),
otherwise: (schema) =>
schema.of(
Expand All @@ -130,6 +147,13 @@
return /^(\/\.?[\w][\w.-]*)+$/.test(value) || !value
})
.label('Origin Path'),
streamingEndpoint: yup
.string()
.label('Streaming Endpoint')
.when('originType', {
is: (originType) => originType === 'live_ingest',
then: (schema) => schema.required()
}),
hmacAuthentication: yup.boolean(),
hmacRegionName: yup
.string()
Expand Down Expand Up @@ -203,10 +227,6 @@
emit('onSuccess')
}
const closeDrawerEdit = () => {
showEditOriginDrawer.value = false
}
const handleTrackCreation = () => {
tracker.product
.productCreated({
Expand Down Expand Up @@ -235,8 +255,6 @@
errorType: 'api'
})
.track()
closeDrawerEdit()
}
const handleFailedCreateOrigin = (error) => {
Expand Down Expand Up @@ -289,7 +307,7 @@
<FormFieldsDrawerOrigin
ref="createFormDrawer"
:disabledFields="disabledFields"
:listOrigins="ORIGIN_TYPES_OPTIONS"
:listOrigins="originTypesOptions"
:copyToClipboard="copyToKey"
/>
</template>
Expand All @@ -310,7 +328,7 @@
<FormFieldsDrawerOrigin
isEditMode
:disabledFields="disabledFields"
:listOrigins="ORIGIN_TYPES_OPTIONS"
:listOrigins="originTypesOptions"
:copyToClipboard="copyToKey"
/>
</template>
Expand Down
Loading

0 comments on commit 03d4c18

Please sign in to comment.