@@ -151,6 +151,7 @@ func (c *Client) GetEgressIPAddresses(ctx context.Context, appName string) (map[
151151 ip
152152 version
153153 region
154+ updatedAt
154155 }
155156 }
156157 }
@@ -227,3 +228,86 @@ func (c *Client) ReleaseIPAddress(ctx context.Context, appName string, ip string
227228
228229 return nil
229230}
231+
232+ func (c * Client ) GetAppScopedEgressIPAddresses (ctx context.Context , appName string ) (map [string ][]EgressIPAddress , error ) {
233+ query := `
234+ query ($appName: String!) {
235+ app(name: $appName) {
236+ egressIpAddresses {
237+ nodes {
238+ id
239+ ip
240+ version
241+ region
242+ updatedAt
243+ }
244+ }
245+ }
246+ }
247+ `
248+
249+ req := c .NewRequest (query )
250+ ctx = ctxWithAction (ctx , "get_app_scoped_egress_ip_addresses" )
251+ req .Var ("appName" , appName )
252+
253+ data , err := c .RunWithContext (ctx , req )
254+ if err != nil {
255+ return nil , err
256+ }
257+
258+ ret := make (map [string ][]EgressIPAddress )
259+ for _ , ip := range data .App .EgressIpAddresses .Nodes {
260+ if _ , ok := ret [ip .Region ]; ! ok {
261+ ret [ip .Region ] = make ([]EgressIPAddress , 0 )
262+ }
263+
264+ ret [ip .Region ] = append (ret [ip .Region ], * ip )
265+ }
266+
267+ return ret , nil
268+ }
269+
270+ func (c * Client ) AllocateAppScopedEgressIPAddress (ctx context.Context , appName string , region string ) (net.IP , net.IP , error ) {
271+ query := `
272+ mutation($input: AllocateEgressIPAddressInput!) {
273+ allocateEgressIpAddress(input: $input) {
274+ v4,
275+ v6
276+ }
277+ }
278+ `
279+
280+ req := c .NewRequest (query )
281+ ctx = ctxWithAction (ctx , "allocate_app_scoped_egress_ip_address" )
282+ req .Var ("input" , AllocateEgressIPAddressInput {AppID : appName , Region : region })
283+
284+ data , err := c .RunWithContext (ctx , req )
285+ if err != nil {
286+ return nil , nil , err
287+ }
288+
289+ return net .ParseIP (data .AllocateEgressIPAddress .V4 ), net .ParseIP (data .AllocateEgressIPAddress .V6 ), nil
290+ }
291+
292+ func (c * Client ) ReleaseAppScopedEgressIPAddress (ctx context.Context , appName , ip string ) error {
293+ query := `
294+ mutation($input: ReleaseEgressIPAddressInput!) {
295+ releaseEgressIpAddress(input: $input) {
296+ v4
297+ v6
298+ clientMutationId
299+ }
300+ }
301+ `
302+
303+ req := c .NewRequest (query )
304+ ctx = ctxWithAction (ctx , "release_app_scoped_egress_ip_address" )
305+ req .Var ("input" , ReleaseEgressIPAddressInput {AppID : appName , IP : ip })
306+
307+ _ , err := c .RunWithContext (ctx , req )
308+ if err != nil {
309+ return err
310+ }
311+
312+ return nil
313+ }
0 commit comments