@@ -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,246 @@ 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 ("don-centric format" , func (t * testing.T ) {
1763+ t .Parallel ()
1764+
1765+ yamlSpec := `
1766+ environment: test
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: test
1777+ - key: product
1778+ value: cre
1779+ jobName: test-gateway-job
1780+ template: gateway
1781+ inputs:
1782+ dons:
1783+ - name: workflow-don
1784+ f: 1
1785+ handlers:
1786+ - web-api-capabilities
1787+ - http-capabilities
1788+ gatewayRequestTimeoutSec: 12
1789+ allowedPorts:
1790+ - 443
1791+ - 8080
1792+ allowedSchemes:
1793+ - https
1794+ authGatewayID: my-gateway-id
1795+ `
1796+ var root yaml.Node
1797+ err := yaml .Unmarshal ([]byte (yamlSpec ), & root )
1798+ require .NoError (t , err )
1799+
1800+ rootMap , ok := cldpipelineinput .YamlNodeToAny (& root ).(map [string ]any )
1801+ require .True (t , ok )
1802+
1803+ environment , _ := rootMap ["environment" ].(string )
1804+ domain , _ := rootMap ["domain" ].(string )
1805+
1806+ changesetData , err := cldpipelineinput .FindChangesetInData (rootMap ["changesets" ], "job_propose_arbitrary" )
1807+ require .NoError (t , err )
1808+
1809+ changesetMap , ok := changesetData .(map [string ]any )
1810+ require .True (t , ok )
1811+
1812+ payload , ok := changesetMap ["payload" ]
1813+ require .True (t , ok )
1814+
1815+ payloadBytes , err := yaml .Marshal (payload )
1816+ require .NoError (t , err )
1817+
1818+ var parsed jobs.ProposeJobSpecInput
1819+ err = yaml .Unmarshal (payloadBytes , & parsed )
1820+ require .NoError (t , err )
1821+
1822+ parsed .Environment = environment
1823+ parsed .Domain = domain
1824+
1825+ assert .Equal (t , "test" , parsed .Environment )
1826+ assert .Equal (t , "cre" , parsed .Domain )
1827+ assert .Equal (t , "gateway-don" , parsed .DONName )
1828+ assert .Equal (t , job_types .Gateway , parsed .Template )
1829+
1830+ var gatewayInput operations.ProposeGatewayJobInput
1831+ err = parsed .Inputs .UnmarshalTo (& gatewayInput )
1832+ require .NoError (t , err )
1833+
1834+ assert .False (t , gatewayInput .ServiceCentricFormatEnabled )
1835+ require .Len (t , gatewayInput .DONs , 1 )
1836+ assert .Equal (t , "workflow-don" , gatewayInput .DONs [0 ].Name )
1837+ assert .Equal (t , 1 , gatewayInput .DONs [0 ].F )
1838+ assert .Equal (t , []string {"web-api-capabilities" , "http-capabilities" }, gatewayInput .DONs [0 ].Handlers )
1839+ assert .Equal (t , 12 , gatewayInput .GatewayRequestTimeoutSec )
1840+ assert .Equal (t , []int {443 , 8080 }, gatewayInput .AllowedPorts )
1841+ assert .Equal (t , []string {"https" }, gatewayInput .AllowedSchemes )
1842+ assert .Equal (t , "my-gateway-id" , gatewayInput .AuthGatewayID )
1843+
1844+ // Build GatewayJob manually; in production member addresses are resolved via JD.
1845+ gj := pkg.GatewayJob {
1846+ JobName : "CRE Gateway" ,
1847+ TargetDONs : []pkg.TargetDON {
1848+ {
1849+ ID : gatewayInput .DONs [0 ].Name ,
1850+ F : gatewayInput .DONs [0 ].F ,
1851+ Handlers : gatewayInput .DONs [0 ].Handlers ,
1852+ Members : []pkg.TargetDONMember {
1853+ {Address : "0xabc123" , Name : "mock-node-1 (DON workflow-don)" },
1854+ },
1855+ },
1856+ },
1857+ RequestTimeoutSec : gatewayInput .GatewayRequestTimeoutSec ,
1858+ AllowedPorts : gatewayInput .AllowedPorts ,
1859+ AllowedSchemes : gatewayInput .AllowedSchemes ,
1860+ AuthGatewayID : gatewayInput .AuthGatewayID ,
1861+ }
1862+
1863+ require .NoError (t , gj .Validate ())
1864+ assert .False (t , gj .ServiceCentricFormatEnabled )
1865+ assert .Equal (t , "CRE Gateway" , gj .JobName )
1866+ assert .Equal (t , 12 , gj .RequestTimeoutSec )
1867+ assert .Equal (t , []int {443 , 8080 }, gj .AllowedPorts )
1868+ assert .Equal (t , []string {"https" }, gj .AllowedSchemes )
1869+ assert .Equal (t , "my-gateway-id" , gj .AuthGatewayID )
1870+ require .Len (t , gj .TargetDONs , 1 )
1871+ assert .Equal (t , "workflow-don" , gj .TargetDONs [0 ].ID )
1872+ assert .Equal (t , 1 , gj .TargetDONs [0 ].F )
1873+ assert .Equal (t , []string {"web-api-capabilities" , "http-capabilities" }, gj .TargetDONs [0 ].Handlers )
1874+ })
1875+
1876+ t .Run ("service-centric format" , func (t * testing.T ) {
1877+ t .Parallel ()
1878+
1879+ yamlSpec := `
1880+ environment: staging
1881+ domain: cre
1882+ changesets:
1883+ - job_propose_arbitrary:
1884+ payload:
1885+ donName: gateway-don
1886+ donFilters:
1887+ - key: don_name
1888+ value: gateway-don
1889+ - key: environment
1890+ value: staging
1891+ - key: product
1892+ value: cre
1893+ jobName: test-gateway-job-svc
1894+ template: gateway
1895+ inputs:
1896+ serviceCentricFormatEnabled: true
1897+ dons:
1898+ - name: workflow-don
1899+ f: 1
1900+ services:
1901+ - servicename: workflows
1902+ handlers:
1903+ - web-api-capabilities
1904+ - http-capabilities
1905+ dons:
1906+ - workflow-don
1907+ gatewayRequestTimeoutSec: 10
1908+ allowedSchemes:
1909+ - https
1910+ allowedIPsCIDR:
1911+ - 10.0.0.0/8
1912+ `
1913+ var root yaml.Node
1914+ err := yaml .Unmarshal ([]byte (yamlSpec ), & root )
1915+ require .NoError (t , err )
1916+
1917+ rootMap , ok := cldpipelineinput .YamlNodeToAny (& root ).(map [string ]any )
1918+ require .True (t , ok )
1919+
1920+ environment , _ := rootMap ["environment" ].(string )
1921+ domain , _ := rootMap ["domain" ].(string )
1922+
1923+ changesetData , err := cldpipelineinput .FindChangesetInData (rootMap ["changesets" ], "job_propose_arbitrary" )
1924+ require .NoError (t , err )
1925+
1926+ changesetMap , ok := changesetData .(map [string ]any )
1927+ require .True (t , ok )
1928+
1929+ payload , ok := changesetMap ["payload" ]
1930+ require .True (t , ok )
1931+
1932+ payloadBytes , err := yaml .Marshal (payload )
1933+ require .NoError (t , err )
1934+
1935+ var parsed jobs.ProposeJobSpecInput
1936+ err = yaml .Unmarshal (payloadBytes , & parsed )
1937+ require .NoError (t , err )
1938+
1939+ parsed .Environment = environment
1940+ parsed .Domain = domain
1941+
1942+ assert .Equal (t , "staging" , parsed .Environment )
1943+ assert .Equal (t , "cre" , parsed .Domain )
1944+ assert .Equal (t , job_types .Gateway , parsed .Template )
1945+
1946+ var gatewayInput operations.ProposeGatewayJobInput
1947+ err = parsed .Inputs .UnmarshalTo (& gatewayInput )
1948+ require .NoError (t , err )
1949+
1950+ assert .True (t , gatewayInput .ServiceCentricFormatEnabled )
1951+ require .Len (t , gatewayInput .DONs , 1 )
1952+ assert .Equal (t , "workflow-don" , gatewayInput .DONs [0 ].Name )
1953+ assert .Equal (t , 1 , gatewayInput .DONs [0 ].F )
1954+ require .Len (t , gatewayInput .Services , 1 )
1955+ assert .Equal (t , "workflows" , gatewayInput .Services [0 ].ServiceName )
1956+ assert .Equal (t , []string {"web-api-capabilities" , "http-capabilities" }, gatewayInput .Services [0 ].Handlers )
1957+ assert .Equal (t , []string {"workflow-don" }, gatewayInput .Services [0 ].DONs )
1958+ assert .Equal (t , 10 , gatewayInput .GatewayRequestTimeoutSec )
1959+ assert .Equal (t , []string {"https" }, gatewayInput .AllowedSchemes )
1960+ assert .Equal (t , []string {"10.0.0.0/8" }, gatewayInput .AllowedIPsCIDR )
1961+
1962+ // Build GatewayJob manually; in production member addresses are resolved via JD.
1963+ gj := pkg.GatewayJob {
1964+ ServiceCentricFormatEnabled : true ,
1965+ JobName : "CRE Gateway" ,
1966+ DONs : []pkg.TargetDON {
1967+ {
1968+ ID : gatewayInput .DONs [0 ].Name ,
1969+ F : gatewayInput .DONs [0 ].F ,
1970+ Members : []pkg.TargetDONMember {
1971+ {Address : "0xdef456" , Name : "mock-node-1 (DON workflow-don)" },
1972+ },
1973+ },
1974+ },
1975+ Services : []pkg.GatewayServiceConfig {
1976+ {
1977+ ServiceName : gatewayInput .Services [0 ].ServiceName ,
1978+ Handlers : gatewayInput .Services [0 ].Handlers ,
1979+ DONs : gatewayInput .Services [0 ].DONs ,
1980+ },
1981+ },
1982+ RequestTimeoutSec : gatewayInput .GatewayRequestTimeoutSec ,
1983+ AllowedSchemes : gatewayInput .AllowedSchemes ,
1984+ AllowedIPsCIDR : gatewayInput .AllowedIPsCIDR ,
1985+ }
1986+
1987+ require .NoError (t , gj .Validate ())
1988+ assert .True (t , gj .ServiceCentricFormatEnabled )
1989+ assert .Equal (t , "CRE Gateway" , gj .JobName )
1990+ assert .Equal (t , 10 , gj .RequestTimeoutSec )
1991+ assert .Equal (t , []string {"https" }, gj .AllowedSchemes )
1992+ assert .Equal (t , []string {"10.0.0.0/8" }, gj .AllowedIPsCIDR )
1993+ require .Len (t , gj .DONs , 1 )
1994+ assert .Equal (t , "workflow-don" , gj .DONs [0 ].ID )
1995+ require .Len (t , gj .Services , 1 )
1996+ assert .Equal (t , "workflows" , gj .Services [0 ].ServiceName )
1997+ assert .Equal (t , []string {"web-api-capabilities" , "http-capabilities" }, gj .Services [0 ].Handlers )
1998+ assert .Equal (t , []string {"workflow-don" }, gj .Services [0 ].DONs )
1999+ })
2000+ }
0 commit comments