@@ -11,12 +11,14 @@ import (
1111 "github.com/pelletier/go-toml/v2"
1212 "github.com/stretchr/testify/assert"
1313 "github.com/stretchr/testify/require"
14+ "gopkg.in/yaml.v3"
1415
1516 chainsel "github.com/smartcontractkit/chain-selectors"
1617
1718 "github.com/smartcontractkit/chainlink-common/pkg/settings/cresettings"
1819 "github.com/smartcontractkit/chainlink-deployments-framework/datastore"
1920 cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment"
21+ cldpipelineinput "github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/pipeline/input"
2022 "github.com/smartcontractkit/chainlink-protos/job-distributor/v1/job"
2123 "github.com/smartcontractkit/chainlink-protos/job-distributor/v1/node"
2224 "github.com/smartcontractkit/chainlink/deployment/cre/jobs"
@@ -1753,3 +1755,132 @@ CallLimit = 1_000`, "invalid inputs for CRE settings job spec: invalid wf abcd:
17531755 })
17541756 }
17551757}
1758+
1759+ func TestProposeJobSpec_GatewayJobYAMLConversion (t * testing.T ) {
1760+ t .Parallel ()
1761+
1762+ t .Run ("service-centric format" , func (t * testing.T ) {
1763+ t .Parallel ()
1764+
1765+ yamlSpec := `
1766+ environment: staging
1767+ domain: cre
1768+ changesets:
1769+ - job_propose_arbitrary:
1770+ payload:
1771+ donName: gateway-don
1772+ donFilters:
1773+ - key: don_name
1774+ value: gateway-don
1775+ - key: environment
1776+ value: staging
1777+ - key: product
1778+ value: cre
1779+ jobName: test-gateway-job-svc
1780+ template: gateway
1781+ inputs:
1782+ serviceCentricFormatEnabled: true
1783+ dons:
1784+ - name: workflow-don
1785+ f: 1
1786+ services:
1787+ - servicename: workflows
1788+ handlers:
1789+ - web-api-capabilities
1790+ - http-capabilities
1791+ dons:
1792+ - workflow-don
1793+ gatewayRequestTimeoutSec: 10
1794+ allowedSchemes:
1795+ - https
1796+ allowedIPsCIDR:
1797+ - 10.0.0.0/8
1798+ `
1799+ var root yaml.Node
1800+ err := yaml .Unmarshal ([]byte (yamlSpec ), & root )
1801+ require .NoError (t , err )
1802+
1803+ rootMap , ok := cldpipelineinput .YamlNodeToAny (& root ).(map [string ]any )
1804+ require .True (t , ok )
1805+
1806+ environment , _ := rootMap ["environment" ].(string )
1807+ domain , _ := rootMap ["domain" ].(string )
1808+
1809+ changesetData , err := cldpipelineinput .FindChangesetInData (rootMap ["changesets" ], "job_propose_arbitrary" , "test" )
1810+ require .NoError (t , err )
1811+
1812+ changesetMap , ok := changesetData .(map [string ]any )
1813+ require .True (t , ok )
1814+
1815+ payload , ok := changesetMap ["payload" ]
1816+ require .True (t , ok )
1817+
1818+ payloadBytes , err := yaml .Marshal (payload )
1819+ require .NoError (t , err )
1820+
1821+ var parsed jobs.ProposeJobSpecInput
1822+ err = yaml .Unmarshal (payloadBytes , & parsed )
1823+ require .NoError (t , err )
1824+
1825+ parsed .Environment = environment
1826+ parsed .Domain = domain
1827+
1828+ assert .Equal (t , "staging" , parsed .Environment )
1829+ assert .Equal (t , "cre" , parsed .Domain )
1830+ assert .Equal (t , job_types .Gateway , parsed .Template )
1831+
1832+ var gatewayInput operations.ProposeGatewayJobInput
1833+ err = parsed .Inputs .UnmarshalTo (& gatewayInput )
1834+ require .NoError (t , err )
1835+
1836+ assert .True (t , gatewayInput .ServiceCentricFormatEnabled )
1837+ require .Len (t , gatewayInput .DONs , 1 )
1838+ assert .Equal (t , "workflow-don" , gatewayInput .DONs [0 ].Name )
1839+ assert .Equal (t , pkg .Int (1 ), gatewayInput .DONs [0 ].F )
1840+ require .Len (t , gatewayInput .Services , 1 )
1841+ assert .Equal (t , "workflows" , gatewayInput .Services [0 ].ServiceName )
1842+ assert .Equal (t , []string {"web-api-capabilities" , "http-capabilities" }, gatewayInput .Services [0 ].Handlers )
1843+ assert .Equal (t , []string {"workflow-don" }, gatewayInput .Services [0 ].DONs )
1844+ assert .Equal (t , pkg .Int (10 ), gatewayInput .GatewayRequestTimeoutSec )
1845+ assert .Equal (t , []string {"https" }, gatewayInput .AllowedSchemes )
1846+ assert .Equal (t , []string {"10.0.0.0/8" }, gatewayInput .AllowedIPsCIDR )
1847+
1848+ // Build GatewayJob manually; in production member addresses are resolved via JD.
1849+ gj := pkg.GatewayJob {
1850+ ServiceCentricFormatEnabled : true ,
1851+ JobName : "CRE Gateway" ,
1852+ DONs : []pkg.TargetDON {
1853+ {
1854+ ID : gatewayInput .DONs [0 ].Name ,
1855+ F : int (gatewayInput .DONs [0 ].F ),
1856+ Members : []pkg.TargetDONMember {
1857+ {Address : "0xdef456" , Name : "mock-node-1 (DON workflow-don)" },
1858+ },
1859+ },
1860+ },
1861+ Services : []pkg.GatewayServiceConfig {
1862+ {
1863+ ServiceName : gatewayInput .Services [0 ].ServiceName ,
1864+ Handlers : gatewayInput .Services [0 ].Handlers ,
1865+ DONs : gatewayInput .Services [0 ].DONs ,
1866+ },
1867+ },
1868+ RequestTimeoutSec : int (gatewayInput .GatewayRequestTimeoutSec ),
1869+ AllowedSchemes : gatewayInput .AllowedSchemes ,
1870+ AllowedIPsCIDR : gatewayInput .AllowedIPsCIDR ,
1871+ }
1872+
1873+ require .NoError (t , gj .Validate ())
1874+ assert .True (t , gj .ServiceCentricFormatEnabled )
1875+ assert .Equal (t , "CRE Gateway" , gj .JobName )
1876+ assert .Equal (t , 10 , gj .RequestTimeoutSec )
1877+ assert .Equal (t , []string {"https" }, gj .AllowedSchemes )
1878+ assert .Equal (t , []string {"10.0.0.0/8" }, gj .AllowedIPsCIDR )
1879+ require .Len (t , gj .DONs , 1 )
1880+ assert .Equal (t , "workflow-don" , gj .DONs [0 ].ID )
1881+ require .Len (t , gj .Services , 1 )
1882+ assert .Equal (t , "workflows" , gj .Services [0 ].ServiceName )
1883+ assert .Equal (t , []string {"web-api-capabilities" , "http-capabilities" }, gj .Services [0 ].Handlers )
1884+ assert .Equal (t , []string {"workflow-don" }, gj .Services [0 ].DONs )
1885+ })
1886+ }
0 commit comments