| 1 | /* |
| 2 | * This file is part of the go-nft project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | * |
| 16 | * Copyright 2021 Red Hat, Inc. |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | package schemascip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/ |
| 21 | |
| 22 | import ( |
| 23 | "encoding/jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/" |
| 24 | ) |
| 25 | |
| 26 | type Rootscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Root# struct { |
| 27 | Nftablesscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Root#Nftables. []Nftablescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nftable# `json:"nftables"` |
| 28 | } |
| 29 | |
| 30 | const ruleSetKeyscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/ruleSetKey. = "ruleset" |
| 31 | |
| 32 | type Objectsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Objects# struct { |
| 33 | Tablescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Objects#Table. *Tablescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Table# `json:"table,omitempty"` |
| 34 | Chainscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Objects#Chain. *Chainscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Chain# `json:"chain,omitempty"` |
| 35 | Rulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Objects#Rule. *Rulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule# `json:"rule,omitempty"` |
| 36 | Rulesetscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Objects#Ruleset. bool `json:"-"` |
| 37 | } |
| 38 | |
| 39 | func (o Objectsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Objects#) MarshalJSONscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Objects#MarshalJSON().() ([]byte, error) { |
| 40 | type _Objects Objectsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Objects# |
| 41 | objects := _Objects(o) |
| 42 | |
| 43 | data, err := jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/Marshal().(objects) |
| 44 | if err != nil { |
| 45 | return nil, err |
| 46 | } |
| 47 | |
| 48 | if o.Rulesetscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Objects#Ruleset. { |
| 49 | // Convert to a dynamic structure |
| 50 | var dynamicStructure map[string]jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.RawMessagescip-go gomod github.com/golang/go/src go1.16 `encoding/json`/RawMessage# |
| 51 | if err := jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/Unmarshal().(data, &dynamicStructure); err != nil { |
| 52 | return nil, err |
| 53 | } |
| 54 | dynamicStructure[ruleSetKeyscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/ruleSetKey.] = nil |
| 55 | data, err = jsonscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.16 `encoding/json`/Marshal().(dynamicStructure) |
| 56 | if err != nil { |
| 57 | return nil, err |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | return data, nil |
| 62 | } |
| 63 | |
| 64 | type Nftablescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nftable# struct { |
| 65 | Tablescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nftable#Table. *Tablescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Table# `json:"table,omitempty"` |
| 66 | Chainscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nftable#Chain. *Chainscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Chain# `json:"chain,omitempty"` |
| 67 | Rulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nftable#Rule. *Rulescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Rule# `json:"rule,omitempty"` |
| 68 | |
| 69 | Addscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nftable#Add. *Objectsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Objects# `json:"add,omitempty"` |
| 70 | Deletescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nftable#Delete. *Objectsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Objects# `json:"delete,omitempty"` |
| 71 | Flushscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nftable#Flush. *Objectsscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Objects# `json:"flush,omitempty"` |
| 72 | |
| 73 | Metainfoscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Nftable#Metainfo. *Metainfoscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Metainfo# `json:"metainfo,omitempty"` |
| 74 | } |
| 75 | |
| 76 | type Metainfoscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Metainfo# struct { |
| 77 | Versionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Metainfo#Version. string `json:"version"` |
| 78 | ReleaseNamescip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Metainfo#ReleaseName. string `json:"release_name"` |
| 79 | JsonSchemaVersionscip-go gomod github.com/networkplumbing/go-nft . `github.com/networkplumbing/go-nft/nft/schema`/Metainfo#JsonSchemaVersion. int `json:"json_schema_version"` |
| 80 | } |