diff --git a/LICENSE b/LICENSE index a3b5176..5c15f33 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2024 Adam Crawford +Copyright (c) 2026 Adam Crawford Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/LICENSES/Apache License 2.0 b/LICENSES/Apache License 2.0 deleted file mode 100644 index d9a10c0..0000000 --- a/LICENSES/Apache License 2.0 +++ /dev/null @@ -1,176 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS diff --git a/README.md b/README.md index 6b53f00..7e061b3 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ Citrix NetScaler ADC Go client Still in development - -Struct defintions largely come from the official Citrix [adc-nitro-go](https://github.com/netscaler/adc-nitro-go) package with modifactions such that API responses can actually be unmarshalled into them. \ No newline at end of file diff --git a/nitrogo/aaa.go b/nitrogo/aaa.go index f7e99e2..0ba60db 100644 --- a/nitrogo/aaa.go +++ b/nitrogo/aaa.go @@ -1,5 +1,15 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "strings" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + const ( aaaCertParamsURL = "/nitro/v1/config/aaacertparams" aaaGlobalAAAPreauthenticationPolicyBindingURL = "/nitro/v1/config/aaaglobal_aaapreauthenticationpolicy_binding" @@ -7,6 +17,10 @@ const ( aaaGlobalBindingURL = "/nitro/v1/config/aaaglobal_binding" aaaGroupURL = "/nitro/v1/config/aaagroup" aaaGroupAAAUserBindingURL = "/nitro/v1/config/aaagroup_aaauser_binding" + aaaGroupAuditnslogPolicyBindingURL = "/nitro/v1/config/aaagroup_auditnslogpolicy_binding" + aaaGroupAuditsyslogPolicyBindingURL = "/nitro/v1/config/aaagroup_auditsyslogpolicy_binding" + aaaGroupAuthorizationPolicyBindingURL = "/nitro/v1/config/aaagroup_authorizationpolicy_binding" + aaaGroupBindingURL = "/nitro/v1/config/aaagroup_binding" aaaGroupIntranetIP6BindingURL = "/nitro/v1/config/aaagroup_intranetip6_binding" aaaGroupIntranetIPBindingURL = "/nitro/v1/config/aaagroup_intranetip_binding" aaaGroupTMSessionPolicyBindingURL = "/nitro/v1/config/aaagroup_tmsessionpolicy_binding" @@ -54,385 +68,4332 @@ type AAAService struct { // aaacertparams // Configuration for certificate parameter resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaacertparams -func (s *AAAService) UpdateAAACertParams() {} -func (s *AAAService) UnsetAAACertParams() {} -func (s *AAAService) GetAllAAACertParams() {} +func (s *AAAService) UpdateAAACertParams(resource models.AAACertParams) error { + payload := map[string]any{"aaacertparams": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, aaaCertParamsURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) UnsetAAACertParams(resource models.AAACertParams) error { + payload := map[string]any{"aaacertparams": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", aaaCertParamsURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAACertParams() (models.AAACertParams, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaCertParamsURL, nil) + if err != nil { + return models.AAACertParams{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.AAACertParams{}, err + } + + var result struct { + Data models.AAACertParams `json:"aaacertparams"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.AAACertParams{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} // aaaglobal_aaapreauthenticationpolicy_binding // Binding object showing the aaapreauthenticationpolicy that can be bound to aaaglobal. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaaglobal_aaapreauthenticationpolicy_binding -func (s *AAAService) AddAAAGlobalAAAPreauthenticationPolicyBinding() {} -func (s *AAAService) DeleteAAAGlobalAAAPreauthenticationPolicyBinding() {} -func (s *AAAService) GetAAAGlobalAAAPreauthenticationPolicyBinding() {} -func (s *AAAService) CountAAAGlobalAAAPreauthenticationPolicyBinding() {} +func (s *AAAService) AddAAAGlobalAAAPreauthenticationPolicyBinding(resource models.AAAGlobalAAAPreAuthenticationPolicyBinding) error { + payload := map[string]any{"aaaglobal_aaapreauthenticationpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaGlobalAAAPreauthenticationPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAGlobalAAAPreauthenticationPolicyBinding(policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", aaaGlobalAAAPreauthenticationPolicyBindingURL, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAAAGlobalAAAPreauthenticationPolicyBinding() ([]models.AAAGlobalAAAPreAuthenticationPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaGlobalAAAPreauthenticationPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAGlobalAAAPreAuthenticationPolicyBinding `json:"aaaglobal_aaapreauthenticationpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) CountAAAGlobalAAAPreauthenticationPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", aaaGlobalAAAPreauthenticationPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAGlobalAAAPreAuthenticationPolicyBinding `json:"aaaglobal_aaapreauthenticationpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} // aaaglobal_authenticationnegotiataction_binding // Binding object showing the authenticationnegotiateaction that can be bound to aaaglobal. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaaglobal_authenticationnegotiateaction_binding -func (s *AAAService) AddAAAGlobalAuthenticationNegotiateActionBinding() {} -func (s *AAAService) DeleteAAAGlobalAuthenticationNegotiateActionBinding() {} -func (s *AAAService) GetAAAGlobalAuthenticationNegotiateActionBinding() {} -func (s *AAAService) CountAAAGlobalAuthenticationNegotiateActionBinding() {} +func (s *AAAService) AddAAAGlobalAuthenticationNegotiateActionBinding(resource models.AAAGlobalAuthenticationNegotiateActionBinding) error { + payload := map[string]any{"aaaglobal_authenticationnegotiateaction_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaGlobalAuthenticationNegotiateActionBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAGlobalAuthenticationNegotiateActionBinding(policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", aaaGlobalAuthenticationNegotiateActionBindingURL, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAAAGlobalAuthenticationNegotiateActionBinding() ([]models.AAAGlobalAuthenticationNegotiateActionBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaGlobalAuthenticationNegotiateActionBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAGlobalAuthenticationNegotiateActionBinding `json:"aaaglobal_authenticationnegotiateaction_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) CountAAAGlobalAuthenticationNegotiateActionBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", aaaGlobalAuthenticationNegotiateActionBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAGlobalAuthenticationNegotiateActionBinding `json:"aaaglobal_authenticationnegotiateaction_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} // aaaglobal_binding // Binding object which returns the resources bound to aaaglobal. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaaglobal_binding -func (s *AAAService) GetAAAGlobalBinding() {} +func (s *AAAService) GetAAAGlobalBinding() (models.AAAGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaGlobalBindingURL, nil) + if err != nil { + return models.AAAGlobalBinding{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.AAAGlobalBinding{}, err + } + + var result struct { + Data []models.AAAGlobalBinding `json:"aaaglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.AAAGlobalBinding{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.AAAGlobalBinding{}, fmt.Errorf("aaaglobal_binding not found") + } + + return result.Data[0], nil +} // aaagroup // Configuration for AAA group resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaagroup -func (s *AAAService) AddAAAGroup() {} -func (s *AAAService) DeleteAAAGroup() {} -func (s *AAAService) GetAllAAAGroup() {} -func (s *AAAService) GetAAAGroup() {} -func (s *AAAService) CountAAAGroup() {} +func (s *AAAService) AddAAAGroup(resource models.AAAGroup) error { + payload := map[string]any{"aaagroup": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaGroupURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAGroup(groupname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", aaaGroupURL, groupname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAGroup() ([]models.AAAGroup, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaGroupURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAGroup `json:"aaagroup"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAGroup(groupname string) (models.AAAGroup, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaGroupURL, groupname), nil) + if err != nil { + return models.AAAGroup{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.AAAGroup{}, err + } + + var result struct { + Data []models.AAAGroup `json:"aaagroup"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.AAAGroup{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.AAAGroup{}, fmt.Errorf("aaagroup %s not found", groupname) + } + + return result.Data[0], nil +} + +func (s *AAAService) CountAAAGroup() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", aaaGroupURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAGroup `json:"aaagroup"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} // aaagroup_aaauser_binding // Binding object showing the aaauser that can be bound to aaagroup. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaagroup_aaauser_binding -func (s *AAAService) AddAAAGroupAAAUserBinding() {} -func (s *AAAService) DeleteAAAGroupAAAUserBinding() {} -func (s *AAAService) GetAllAAAGroupAAAUserBinding() {} -func (s *AAAService) GetAAAGroupAAAUserBinding() {} -func (s *AAAService) CountAAAGroupAAAUserBinding() {} +func (s *AAAService) AddAAAGroupAAAUserBinding(resource models.AAAGroupAAAUserBinding) error { + payload := map[string]any{"aaagroup_aaauser_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaGroupAAAUserBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAGroupAAAUserBinding(groupname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", aaaGroupAAAUserBindingURL, groupname, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAGroupAAAUserBinding() ([]models.AAAGroupAAAUserBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaGroupAAAUserBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAGroupAAAUserBinding `json:"aaagroup_aaauser_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAGroupAAAUserBinding(groupname string) ([]models.AAAGroupAAAUserBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaGroupAAAUserBindingURL, groupname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAGroupAAAUserBinding `json:"aaagroup_aaauser_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) CountAAAGroupAAAUserBinding(groupname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", aaaGroupAAAUserBindingURL, groupname), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAGroupAAAUserBinding `json:"aaagroup_aaauser_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} // aaagroup_auditnslogpolicy_binding // Binding object showing the auditnslogpolicy that can be bound to aaagroup. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaagroup_auditnslogpolicy_binding -func (s *AAAService) AddAAAGroupAuditNSLogPolicyBinding() {} -func (s *AAAService) DeleteAAAGroupAuditNSLogPolicyBinding() {} -func (s *AAAService) GetAllAAAGroupAuditNSLogPolicyBinding() {} -func (s *AAAService) GetAAAGroupAuditNSLogPolicyBinding() {} -func (s *AAAService) CountAAAGroupAuditNSLogPolicyBinding() {} +func (s *AAAService) AddAAAGroupAuditNSLogPolicyBinding(resource models.AAAGroupAuditNSLogPolicyBinding) error { + payload := map[string]any{"aaagroup_auditnslogpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaGroupAuditnslogPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAGroupAuditNSLogPolicyBinding(groupname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", aaaGroupAuditnslogPolicyBindingURL, groupname, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAGroupAuditNSLogPolicyBinding() ([]models.AAAGroupAuditNSLogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaGroupAuditnslogPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAGroupAuditNSLogPolicyBinding `json:"aaagroup_auditnslogpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAGroupAuditNSLogPolicyBinding(groupname string) ([]models.AAAGroupAuditNSLogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaGroupAuditnslogPolicyBindingURL, groupname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAGroupAuditNSLogPolicyBinding `json:"aaagroup_auditnslogpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) CountAAAGroupAuditNSLogPolicyBinding(groupname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", aaaGroupAuditnslogPolicyBindingURL, groupname), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAGroupAuditNSLogPolicyBinding `json:"aaagroup_auditnslogpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} // aaagroup_auditsyslogpolicy_binding // Binding object showing the auditsyslogpolicy that can be bound to aaagroup. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaagroup_auditsyslogpolicy_binding -func (s *AAAService) AddAAAGroupAuditSyslogPolicyBinding() {} -func (s *AAAService) DeleteAAAGroupAuditSyslogPolicyBinding() {} -func (s *AAAService) GetAllAAAGroupAuditSyslogPolicyBinding() {} -func (s *AAAService) GetAAAGroupAuditSyslogPolicyBinding() {} -func (s *AAAService) CountAAAGroupAuditSyslogPolicyBinding() {} +func (s *AAAService) AddAAAGroupAuditSyslogPolicyBinding(resource models.AAAGroupAuditSyslogPolicyBinding) error { + payload := map[string]any{"aaagroup_auditsyslogpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// aaagroup_authorizationpolicy_binding -// Binding object showing the authorizationpolicy that can be bound to aaagroup. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaagroup_authorizationpolicy_binding -func (s *AAAService) AddAAAGroupAuthorizationPolicyBinding() {} -func (s *AAAService) DeleteAAAGroupAuthorizationPolicyBinding() {} -func (s *AAAService) GetAllAAAGroupAuthorizationPolicyBinding() {} -func (s *AAAService) GetAAAGroupAuthorizationPolicyBinding() {} -func (s *AAAService) CountAAAGroupAuthorizationPolicyBinding() {} + req, err := s.client.NewRequest(http.MethodPost, aaaGroupAuditsyslogPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } -// aaagroup_binding -// Binding object which returns the resources bound to aaagroup. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaagroup_binding -func (s *AAAService) GetAllAAAGroupBinding() {} -func (s *AAAService) GetAAAGroupBinding() {} + _, err = s.client.Do(req) + return err +} -// aaagroup_intranetip6_binding -// Binding object showing the intranetip6 that can be bound to aaagroup. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaagroup_intranetip6_binding -func (s *AAAService) AddAAAGroupIntranetIP6Binding() {} -func (s *AAAService) DeleteAAAGroupIntranetIP6Binding() {} -func (s *AAAService) GetAllAAAGroupIntranetIP6Binding() {} -func (s *AAAService) GetAAAGroupIntranetIP6Binding() {} -func (s *AAAService) CountAAAGroupIntranetIP6Binding() {} +func (s *AAAService) DeleteAAAGroupAuditSyslogPolicyBinding(groupname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", aaaGroupAuditsyslogPolicyBindingURL, groupname, argsStr), nil) + if err != nil { + return err + } -// aaagroup_intranetip_binding -// Binding object showing the intranetip that can be bound to aaagroup. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaagroup_intranetip_binding -func (s *AAAService) AddAAAGroupIntranetIPBinding() {} -func (s *AAAService) DeleteAAAGroupIntranetIPBinding() {} -func (s *AAAService) GetAllAAAGroupIntranetIPBinding() {} -func (s *AAAService) GetAAAGroupIntranetIPBinding() {} -func (s *AAAService) CountAAAGroupIntranetIPBinding() {} + _, err = s.client.Do(req) + return err +} -// aaagroup_tmsessionpolicy_binding -// Binding object showing the tmsessionpolicy that can be bound to aaagroup. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaagroup_tmsessionpolicy_binding -func (s *AAAService) AddAAAGroupTMSessionPolicyBinding() {} -func (s *AAAService) DeleteAAAGroupTMSessionPolicyBinding() {} -func (s *AAAService) GetAllAAAGroupTMSessionPolicyBinding() {} -func (s *AAAService) GetAAAGroupTMSessionPolicyBinding() {} -func (s *AAAService) CountAAAGroupTMSessionPolicyBinding() {} +func (s *AAAService) GetAllAAAGroupAuditSyslogPolicyBinding() ([]models.AAAGroupAuditSyslogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaGroupAuditsyslogPolicyBindingURL, nil) + if err != nil { + return nil, err + } -// aaagroup_vpnintranetapplication_binding -// Binding object showing the vpnintranetapplication that can be bound to aaagroup. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaagroup_vpnintranetapplication_binding -func (s *AAAService) AddAAAGroupVPNIntranetApplicationBinding() {} -func (s *AAAService) DeleteAAAGroupVPNIntranetApplicationBinding() {} -func (s *AAAService) GetAllAAAGroupVPNIntranetApplicationBinding() {} -func (s *AAAService) GetAAAGroupVPNIntranetApplicationBinding() {} -func (s *AAAService) CountAAAGroupVPNIntranetApplicationBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// aaagroup_vpnsessionpolicy_binding -// Binding object showing the vpnsessionpolicy that can be bound to aaagroup. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaagroup_vpnsessionpolicy_binding -func (s *AAAService) AddAAAGroupVPNSessionPolicyBinding() {} -func (s *AAAService) DeleteAAAGroupVPNSessionPolicyBinding() {} -func (s *AAAService) GetAllAAAGroupVPNSessionPolicyBinding() {} -func (s *AAAService) GetAAAGroupVPNSessionPolicyBinding() {} -func (s *AAAService) CountAAAGroupVPNSessionPolicyBinding() {} + var result struct { + Data []models.AAAGroupAuditSyslogPolicyBinding `json:"aaagroup_auditsyslogpolicy_binding"` + } -// aaagroup_vpntrafficpolicy_binding -// Binding object showing the vpntrafficpolicy that can be bound to aaagroup. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaagroup_vpntrafficpolicy_binding -func (s *AAAService) AddAAAGroupVPNTrafficPolicyBinding() {} -func (s *AAAService) DeleteAAAGroupVPNTrafficPolicyBinding() {} -func (s *AAAService) GetAllAAAGroupVPNTrafficPolicyBinding() {} -func (s *AAAService) GetAAAGroupVPNTrafficPolicyBinding() {} -func (s *AAAService) CountAAAGroupVPNTrafficPolicyBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// aaagroup_vpnurlpolicy_binding -// Binding object showing the vpnurlpolicy that can be bound to aaagroup. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaagroup_vpnurlpolicy_binding -func (s *AAAService) AddAAAGroupVPNURLPolicyBinding() {} -func (s *AAAService) DeleteAAAGroupVPNURLPolicyBinding() {} -func (s *AAAService) GetAllAAAGroupVPNURLPolicyBinding() {} -func (s *AAAService) GetAAAGroupVPNURLPolicyBinding() {} -func (s *AAAService) CountAAAGroupVPNURLPolicyBinding() {} + return result.Data, nil +} -// aaagroup_vpnurl_binding -// Binding object showing the vpnurl that can be bound to aaagroup. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaagroup_vpnurl_binding -func (s *AAAService) AddAAAGroupVPNURLBinding() {} -func (s *AAAService) DeleteAAAGroupVPNURLBinding() {} -func (s *AAAService) GetAllAAAGroupVPNURLBinding() {} -func (s *AAAService) GetAAAGroupVPNURLBinding() {} -func (s *AAAService) CountAAAGroupVPNURLBinding() {} +func (s *AAAService) GetAAAGroupAuditSyslogPolicyBinding(groupname string) ([]models.AAAGroupAuditSyslogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaGroupAuditsyslogPolicyBindingURL, groupname), nil) + if err != nil { + return nil, err + } -// aaakcdaccount -// Configuration for Kerberos constrained delegation account resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaakcdaccount -func (s *AAAService) AddAAAKCDAccount() {} -func (s *AAAService) DeleteAAAKCDAccount() {} -func (s *AAAService) UpdateAAAKCDAccount() {} -func (s *AAAService) UpsetAAAKCDAccount() {} -func (s *AAAService) GetAllAAAKCDAccount() {} -func (s *AAAService) GetAAAKCDAccount() {} -func (s *AAAService) CountAAAKCDAccount() {} -func (s *AAAService) CheckAAAKCDAccount() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// aaaldapparams -// Configuration for LDAP parameter resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaaldapparams -func (s *AAAService) UpdateAAALDAPParams() {} -func (s *AAAService) UnsetAAALDAPParams() {} -func (s *AAAService) GetAllAAALDAPParams() {} + var result struct { + Data []models.AAAGroupAuditSyslogPolicyBinding `json:"aaagroup_auditsyslogpolicy_binding"` + } -// aaaotpparamter -// Configuration for AAA otpparameter resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaaotpparameter -func (s *AAAService) UpdateAAAOTPParameter() {} -func (s *AAAService) UnsetAAAOTPParameter() {} -func (s *AAAService) GetAllAAAOTPParameter() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// aaaparameter -// Configuration for AAA parameter resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaaparameter -func (s *AAAService) UpdateAAAParameter() {} -func (s *AAAService) UnsetAAAParameter() {} -func (s *AAAService) GetAllAAAParameter() {} + return result.Data, nil +} -// aaapreauthenticationaction -// Configuration for pre authentication action resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaapreauthenticationaction -func (s *AAAService) AddAAAPreauthenticationAction() {} -func (s *AAAService) DeleteAAAPreauthenticationAction() {} -func (s *AAAService) UpdateAAAPreauthenticationAction() {} -func (s *AAAService) UnsetAAAPreauthenticationAction() {} -func (s *AAAService) GetAllAAAPreauthenticationAction() {} -func (s *AAAService) GetAAAPreauthenticationAction() {} -func (s *AAAService) CountAAAPreauthenticationAction() {} +func (s *AAAService) CountAAAGroupAuditSyslogPolicyBinding(groupname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", aaaGroupAuditsyslogPolicyBindingURL, groupname), nil) + if err != nil { + return 0, err + } -// aaapreauthenticationparameter -// Configuration for pre authentication parameter resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaapreauthenticationparameter -func (s *AAAService) UpdateAAAPreauthenticationParamter() {} -func (s *AAAService) UnsetAAAPreauthenticationParamter() {} -func (s *AAAService) GetAllAAAPreauthenticationParamter() {} + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } -// aaapreauthenticationpolicy -// Configuration for pre authentication policy resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaapreauthenticationpolicy -func (s *AAAService) AddAAAPreauthenticationPolicy() {} -func (s *AAAService) DeleteAAAPreauthenticationPolicy() {} -func (s *AAAService) UpdateAAAPreauthenticationPolicy() {} -func (s *AAAService) GetAllAAAPreauthenticationPolicy() {} -func (s *AAAService) GetAAAPreauthenticationPolicy() {} -func (s *AAAService) CountAAAPreauthenticationPolicy() {} + var result struct { + Data []models.AAAGroupAuditSyslogPolicyBinding `json:"aaagroup_auditsyslogpolicy_binding"` + } -// aaapreauthenticationpolicy_aaaglobal_binding -// Binding object showing the aaaglobal that can be bound to aaapreauthenticationpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaapreauthenticationpolicy_aaaglobal_binding -func (s *AAAService) GetAllAAAPreauthenticationPolicyAAAGlobalBinding() {} -func (s *AAAService) GetAAAPreauthenticationPolicyAAAGlobalBinding() {} -func (s *AAAService) CountAAAPreauthenticationPolicyAAAGlobalBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } -// aaapreauthenticationpolicy_binding -// Binding object which returns the resources bound to aaapreauthenticationpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaapreauthenticationpolicy_binding -func (s *AAAService) GetAllAAAPreauthenticationPolicyBinding() {} -func (s *AAAService) GetAAAPreauthenticationPolicyBinding() {} + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} -// aaapreauthentiucationpolicy_vpnvserver_binding -// Binding object showing the vpnvserver that can be bound to aaapreauthenticationpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaapreauthenticationpolicy_vpnvserver_binding -func (s *AAAService) GetAllAAAPreauthenticationPolicyVPNVServerBinding() {} -func (s *AAAService) GetAAAPreauthenticationPolicyVPNVServerBinding() {} -func (s *AAAService) CountAAAPreauthenticationPolicyVPNVServerBinding() {} +// aaagroup_authorizationpolicy_binding +// Binding object showing the authorizationpolicy that can be bound to aaagroup. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaagroup_authorizationpolicy_binding +func (s *AAAService) AddAAAGroupAuthorizationPolicyBinding(resource models.AAAGroupAuthorizationPolicyBinding) error { + payload := map[string]any{"aaagroup_authorizationpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// aaaradiusparams -// Configuration for RADIUS parameter resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaaradiusparams -func (s *AAAService) UpdateAAARADIUSParams() {} -func (s *AAAService) UnsetAAARADIUSParams() {} -func (s *AAAService) GetAllAAARADIUSParams() {} + req, err := s.client.NewRequest(http.MethodPost, aaaGroupAuthorizationPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } -// aaasession -// Configuration for active connection resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaasession -func (s *AAAService) GetAllAAASession() {} -func (s *AAAService) CountAAASession() {} -func (s *AAAService) KillAAASession() {} + _, err = s.client.Do(req) + return err +} -// aaassoprofile -// Configuration for aaa sso profile resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaassoprofile -func (s *AAAService) AddAAASSOProfile() {} -func (s *AAAService) DeleteAAASSOProfile() {} -func (s *AAAService) GetAllAAASSOProfile() {} -func (s *AAAService) GetAAASSOProfile() {} -func (s *AAAService) CountAAASSOProfile() {} -func (s *AAAService) UpdateAAASSOProfile() {} +func (s *AAAService) DeleteAAAGroupAuthorizationPolicyBinding(groupname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", aaaGroupAuthorizationPolicyBindingURL, groupname, argsStr), nil) + if err != nil { + return err + } -// aaatacasparams -// Configuration for tacacs parameters resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaatacacsparams -func (s *AAAService) UpdateAAATACACSParams() {} -func (s *AAAService) UnsetAAATACACSParams() {} -func (s *AAAService) GetAllAAATACACSParams() {} + _, err = s.client.Do(req) + return err +} -// aaauser -// Configuration for AAA user resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaauser -func (s *AAAService) AddAAAUser() {} -func (s *AAAService) DeleteAAAUser() {} -func (s *AAAService) UpdateAAAUser() {} -func (s *AAAService) GetAllAAAUser() {} -func (s *AAAService) GetAAAUser() {} -func (s *AAAService) CountAAAUser() {} -func (s *AAAService) UnlockAAAUser() {} +func (s *AAAService) GetAllAAAGroupAuthorizationPolicyBinding() ([]models.AAAGroupAuthorizationPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaGroupAuthorizationPolicyBindingURL, nil) + if err != nil { + return nil, err + } -// aaauser_aaagroup_binding -// Binding object showing the aaagroup that can be bound to aaauser. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaauser_aaagroup_binding -func (s *AAAService) GetAllAAAUserAAAGroupBinding() {} -func (s *AAAService) GetAAAUserAAAGroupBinding() {} -func (s *AAAService) CountAAAUserAAAGroupBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// aaauser_auditnslogpolicy_binding -// Binding object showing the auditnslogpolicy that can be bound to aaauser. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaauser_auditnslogpolicy_binding -func (s *AAAService) AddAAAUserAuditNSLogPolicyBinding() {} -func (s *AAAService) DeleteAAAUserAuditNSLogPolicyBinding() {} -func (s *AAAService) GetAllAAAUserAuditNSLogPolicyBinding() {} -func (s *AAAService) GetAAAUserAuditNSLogPolicyBinding() {} -func (s *AAAService) CountAAAUserAuditNSLogPolicyBinding() {} + var result struct { + Data []models.AAAGroupAuthorizationPolicyBinding `json:"aaagroup_authorizationpolicy_binding"` + } -// aaauser_auditsyslogpolicy_binding -// Binding object showing the auditsyslogpolicy that can be bound to aaauser. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaauser_auditsyslogpolicy_binding -func (s *AAAService) AddAAAUserAuditSyslogPolicyBinding() {} -func (s *AAAService) DeleteAAAUserAuditSyslogPolicyBinding() {} -func (s *AAAService) GetAllAAAUserAuditSyslogPolicyBinding() {} -func (s *AAAService) GetAAAUserAuditSyslogPolicyBinding() {} -func (s *AAAService) CountAAAUserAuditSyslogPolicyBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// aaauser_authorizationpolicy_binding -// Binding object showing the authorizationpolicy that can be bound to aaauser. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaauser_authorizationpolicy_binding -func (s *AAAService) AddAAAUserAuthorizationPolicyBinding() {} -func (s *AAAService) DeleteAAAUserAuthorizationPolicyBinding() {} -func (s *AAAService) GetAllAAAUserAuthorizationPolicyBinding() {} -func (s *AAAService) GetAAAUserAuthorizationPolicyBinding() {} -func (s *AAAService) CountAAAUserAuthorizationPolicyBinding() {} + return result.Data, nil +} -// aaauser_binding -// Binding object which returns the resources bound to aaauser. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaauser_binding -func (s *AAAService) GetAllAAAUserBinding() {} -func (s *AAAService) GetAAAUserBinding() {} +func (s *AAAService) GetAAAGroupAuthorizationPolicyBinding(groupname string) ([]models.AAAGroupAuthorizationPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaGroupAuthorizationPolicyBindingURL, groupname), nil) + if err != nil { + return nil, err + } -// aaauser_intranetip6_binding -// Binding object showing the intranetip6 that can be bound to aaauser. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaauser_intranetip6_binding -func (s *AAAService) AddAAAUserIntranetIP6Binding() {} -func (s *AAAService) DeleteAAAUserIntranetIP6Binding() {} -func (s *AAAService) GetAllAAAUserIntranetIP6Binding() {} -func (s *AAAService) GetAAAUserIntranetIP6Binding() {} -func (s *AAAService) CountAAAUserIntranetIP6Binding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// aaauser_intranetip_binding -// Binding object showing the intranetip that can be bound to aaauser. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaauser_intranetip_binding -func (s *AAAService) AddAAAUserIntranetIPBinding() {} -func (s *AAAService) DeleteAAAUserIntranetIPBinding() {} -func (s *AAAService) GetAllAAAUserIntranetIPBinding() {} -func (s *AAAService) GetAAAUserIntranetIPBinding() {} -func (s *AAAService) CountAAAUserIntranetIPBinding() {} + var result struct { + Data []models.AAAGroupAuthorizationPolicyBinding `json:"aaagroup_authorizationpolicy_binding"` + } -// aaauser_tmsessionpolicy_binding -// Binding object showing the tmsessionpolicy that can be bound to aaauser. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaauser_tmsessionpolicy_binding -func (s *AAAService) AddAAAUserTMSessionPolicyBinding() {} -func (s *AAAService) DeleteAAAUserTMSessionPolicyBinding() {} -func (s *AAAService) GetAllAAAUserTMSessionPolicyBinding() {} -func (s *AAAService) GetAAAUserTMSessionPolicyBinding() {} -func (s *AAAService) CountAAAUserTMSessionPolicyBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// aaauser_vpnintranetapplication_binding -// Binding object showing the vpnintranetapplication that can be bound to aaauser. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaauser_vpnintranetapplication_binding -func (s *AAAService) AddAAAUserVPNIntranetApplicationBinding() {} -func (s *AAAService) DeleteAAAUserVPNIntranetApplicationBinding() {} -func (s *AAAService) GetAllAAAUserVPNIntranetApplicationBinding() {} -func (s *AAAService) GetAAAUserVPNIntranetApplicationBinding() {} -func (s *AAAService) CountAAAUserVPNIntranetApplicationBinding() {} + return result.Data, nil +} -// aaauser_vpnsessionpolicy_binding -// Binding object showing the vpnsessionpolicy that can be bound to aaauser. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaauser_vpnsessionpolicy_binding -func (s *AAAService) AddAAAUserVPNSessionPolicyBinding() {} -func (s *AAAService) DeleteAAAUserVPNSessionPolicyBinding() {} -func (s *AAAService) GetAllAAAUserVPNSessionPolicyBinding() {} -func (s *AAAService) GetAAAUserVPNSessionPolicyBinding() {} -func (s *AAAService) CountAAAUserVPNSessionPolicyBinding() {} +func (s *AAAService) CountAAAGroupAuthorizationPolicyBinding(groupname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", aaaGroupAuthorizationPolicyBindingURL, groupname), nil) + if err != nil { + return 0, err + } -// aaauser_vpntrafficpolicy_binding -// Binding object showing the vpntrafficpolicy that can be bound to aaauser. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaauser_vpntrafficpolicy_binding -func (s *AAAService) AddAAAUserVPNTrafficPolicyBinding() {} -func (s *AAAService) DeleteAAAUserVPNTrafficPolicyBinding() {} -func (s *AAAService) GetAllAAAUserVPNTrafficPolicyBinding() {} -func (s *AAAService) GetAAAUserVPNTrafficPolicyBinding() {} -func (s *AAAService) CountAAAUserVPNTrafficPolicyBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } -// aaauser_vpnurlpolicy_binding -// Binding object showing the vpnurlpolicy that can be bound to aaauser. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaauser_vpnurlpolicy_binding -func (s *AAAService) AddAAAUserVPNURLPolicyBinding() {} -func (s *AAAService) DeleteAAAUserVPNURLPolicyBinding() {} -func (s *AAAService) GetAllAAAUserVPNURLPolicyBinding() {} -func (s *AAAService) GetAAAUserVPNURLPolicyBinding() {} -func (s *AAAService) CountAAAUserVPNURLPolicyBinding() {} + var result struct { + Data []models.AAAGroupAuthorizationPolicyBinding `json:"aaagroup_authorizationpolicy_binding"` + } -// aaauser_vpnurl_binding -// Binding object showing the vpnurl that can be bound to aaauser. + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// aaagroup_binding +// Binding object which returns the resources bound to aaagroup. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaagroup_binding +func (s *AAAService) GetAllAAAGroupBinding() ([]models.AAAGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaGroupBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAGroupBinding `json:"aaagroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAGroupBinding(groupname string) (models.AAAGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaGroupBindingURL, groupname), nil) + if err != nil { + return models.AAAGroupBinding{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.AAAGroupBinding{}, err + } + + var result struct { + Data []models.AAAGroupBinding `json:"aaagroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.AAAGroupBinding{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.AAAGroupBinding{}, fmt.Errorf("aaagroup_binding %s not found", groupname) + } + + return result.Data[0], nil +} + +// aaagroup_intranetip6_binding +// Binding object showing the intranetip6 that can be bound to aaagroup. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaagroup_intranetip6_binding +func (s *AAAService) AddAAAGroupIntranetIP6Binding(resource models.AAAGroupIntranetIP6Binding) error { + payload := map[string]any{"aaagroup_intranetip6_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaGroupIntranetIP6BindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAGroupIntranetIP6Binding(groupname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", aaaGroupIntranetIP6BindingURL, groupname, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAGroupIntranetIP6Binding() ([]models.AAAGroupIntranetIP6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaGroupIntranetIP6BindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAGroupIntranetIP6Binding `json:"aaagroup_intranetip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAGroupIntranetIP6Binding(groupname string) ([]models.AAAGroupIntranetIP6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaGroupIntranetIP6BindingURL, groupname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAGroupIntranetIP6Binding `json:"aaagroup_intranetip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) CountAAAGroupIntranetIP6Binding(groupname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", aaaGroupIntranetIP6BindingURL, groupname), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAGroupIntranetIP6Binding `json:"aaagroup_intranetip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// aaagroup_intranetip_binding +// Binding object showing the intranetip that can be bound to aaagroup. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaagroup_intranetip_binding +func (s *AAAService) AddAAAGroupIntranetIPBinding(resource models.AAAGroupIntranetIPBinding) error { + payload := map[string]any{"aaagroup_intranetip_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaGroupIntranetIPBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAGroupIntranetIPBinding(groupname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", aaaGroupIntranetIPBindingURL, groupname, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAGroupIntranetIPBinding() ([]models.AAAGroupIntranetIPBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaGroupIntranetIPBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAGroupIntranetIPBinding `json:"aaagroup_intranetip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAGroupIntranetIPBinding(groupname string) ([]models.AAAGroupIntranetIPBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaGroupIntranetIPBindingURL, groupname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAGroupIntranetIPBinding `json:"aaagroup_intranetip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) CountAAAGroupIntranetIPBinding(groupname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", aaaGroupIntranetIPBindingURL, groupname), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAGroupIntranetIPBinding `json:"aaagroup_intranetip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// aaagroup_tmsessionpolicy_binding +// Binding object showing the tmsessionpolicy that can be bound to aaagroup. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaagroup_tmsessionpolicy_binding +func (s *AAAService) AddAAAGroupTMSessionPolicyBinding(resource models.AAAGroupTMSessionPolicyBinding) error { + payload := map[string]any{"aaagroup_tmsessionpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaGroupTMSessionPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAGroupTMSessionPolicyBinding(groupname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", aaaGroupTMSessionPolicyBindingURL, groupname, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAGroupTMSessionPolicyBinding() ([]models.AAAGroupTMSessionPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaGroupTMSessionPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAGroupTMSessionPolicyBinding `json:"aaagroup_tmsessionpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAGroupTMSessionPolicyBinding(groupname string) ([]models.AAAGroupTMSessionPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaGroupTMSessionPolicyBindingURL, groupname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAGroupTMSessionPolicyBinding `json:"aaagroup_tmsessionpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) CountAAAGroupTMSessionPolicyBinding(groupname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", aaaGroupTMSessionPolicyBindingURL, groupname), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAGroupTMSessionPolicyBinding `json:"aaagroup_tmsessionpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// aaagroup_vpnintranetapplication_binding +// Binding object showing the vpnintranetapplication that can be bound to aaagroup. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaagroup_vpnintranetapplication_binding +func (s *AAAService) AddAAAGroupVPNIntranetApplicationBinding(resource models.AAAGroupVPNIntranetApplicationBinding) error { + payload := map[string]any{"aaagroup_vpnintranetapplication_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaGroupVPNIntranetApplicationBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAGroupVPNIntranetApplicationBinding(groupname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", aaaGroupVPNIntranetApplicationBindingURL, groupname, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAGroupVPNIntranetApplicationBinding() ([]models.AAAGroupVPNIntranetApplicationBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaGroupVPNIntranetApplicationBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAGroupVPNIntranetApplicationBinding `json:"aaagroup_vpnintranetapplication_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAGroupVPNIntranetApplicationBinding(groupname string) ([]models.AAAGroupVPNIntranetApplicationBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaGroupVPNIntranetApplicationBindingURL, groupname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAGroupVPNIntranetApplicationBinding `json:"aaagroup_vpnintranetapplication_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) CountAAAGroupVPNIntranetApplicationBinding(groupname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", aaaGroupVPNIntranetApplicationBindingURL, groupname), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAGroupVPNIntranetApplicationBinding `json:"aaagroup_vpnintranetapplication_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// aaagroup_vpnsessionpolicy_binding +// Binding object showing the vpnsessionpolicy that can be bound to aaagroup. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaagroup_vpnsessionpolicy_binding +func (s *AAAService) AddAAAGroupVPNSessionPolicyBinding(resource models.AAAGroupVPNSessionPolicyBinding) error { + payload := map[string]any{"aaagroup_vpnsessionpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaGroupVPNSessionPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAGroupVPNSessionPolicyBinding(groupname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", aaaGroupVPNSessionPolicyBindingURL, groupname, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAGroupVPNSessionPolicyBinding() ([]models.AAAGroupVPNSessionPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaGroupVPNSessionPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAGroupVPNSessionPolicyBinding `json:"aaagroup_vpnsessionpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAGroupVPNSessionPolicyBinding(groupname string) ([]models.AAAGroupVPNSessionPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaGroupVPNSessionPolicyBindingURL, groupname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAGroupVPNSessionPolicyBinding `json:"aaagroup_vpnsessionpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) CountAAAGroupVPNSessionPolicyBinding(groupname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", aaaGroupVPNSessionPolicyBindingURL, groupname), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAGroupVPNSessionPolicyBinding `json:"aaagroup_vpnsessionpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// aaagroup_vpntrafficpolicy_binding +// Binding object showing the vpntrafficpolicy that can be bound to aaagroup. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaagroup_vpntrafficpolicy_binding +func (s *AAAService) AddAAAGroupVPNTrafficPolicyBinding(resource models.AAAGroupVPNTrafficPolicyBinding) error { + payload := map[string]any{"aaagroup_vpntrafficpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaGroupVPNTrafficPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAGroupVPNTrafficPolicyBinding(groupname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", aaaGroupVPNTrafficPolicyBindingURL, groupname, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAGroupVPNTrafficPolicyBinding() ([]models.AAAGroupVPNTrafficPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaGroupVPNTrafficPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAGroupVPNTrafficPolicyBinding `json:"aaagroup_vpntrafficpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAGroupVPNTrafficPolicyBinding(groupname string) ([]models.AAAGroupVPNTrafficPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaGroupVPNTrafficPolicyBindingURL, groupname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAGroupVPNTrafficPolicyBinding `json:"aaagroup_vpntrafficpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) CountAAAGroupVPNTrafficPolicyBinding(groupname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", aaaGroupVPNTrafficPolicyBindingURL, groupname), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAGroupVPNTrafficPolicyBinding `json:"aaagroup_vpntrafficpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// aaagroup_vpnurlpolicy_binding +// Binding object showing the vpnurlpolicy that can be bound to aaagroup. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaagroup_vpnurlpolicy_binding +func (s *AAAService) AddAAAGroupVPNURLPolicyBinding(resource models.AAAGroupVPNURLPolicyBinding) error { + payload := map[string]any{"aaagroup_vpnurlpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaGroupVPNURLPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAGroupVPNURLPolicyBinding(groupname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", aaaGroupVPNURLPolicyBindingURL, groupname, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAGroupVPNURLPolicyBinding() ([]models.AAAGroupVPNURLPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaGroupVPNURLPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAGroupVPNURLPolicyBinding `json:"aaagroup_vpnurlpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAGroupVPNURLPolicyBinding(groupname string) ([]models.AAAGroupVPNURLPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaGroupVPNURLPolicyBindingURL, groupname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAGroupVPNURLPolicyBinding `json:"aaagroup_vpnurlpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) CountAAAGroupVPNURLPolicyBinding(groupname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", aaaGroupVPNURLPolicyBindingURL, groupname), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAGroupVPNURLPolicyBinding `json:"aaagroup_vpnurlpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// aaagroup_vpnurl_binding +// Binding object showing the vpnurl that can be bound to aaagroup. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaagroup_vpnurl_binding +func (s *AAAService) AddAAAGroupVPNURLBinding(resource models.AAAGroupVPNURLBinding) error { + payload := map[string]any{"aaagroup_vpnurl_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaGroupVPNURLBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAGroupVPNURLBinding(groupname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", aaaGroupVPNURLBindingURL, groupname, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAGroupVPNURLBinding() ([]models.AAAGroupVPNURLBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaGroupVPNURLBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAGroupVPNURLBinding `json:"aaagroup_vpnurl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAGroupVPNURLBinding(groupname string) ([]models.AAAGroupVPNURLBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaGroupVPNURLBindingURL, groupname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAGroupVPNURLBinding `json:"aaagroup_vpnurl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) CountAAAGroupVPNURLBinding(groupname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", aaaGroupVPNURLBindingURL, groupname), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAGroupVPNURLBinding `json:"aaagroup_vpnurl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// aaakcdaccount +// Configuration for Kerberos constrained delegation account resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaakcdaccount +func (s *AAAService) AddAAAKCDAccount(resource models.AAAKCDAccount) error { + payload := map[string]any{"aaakcdaccount": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaKCDAccountURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAKCDAccount(kcdaccount string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", aaaKCDAccountURL, kcdaccount), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) UpdateAAAKCDAccount(resource models.AAAKCDAccount) error { + payload := map[string]any{"aaakcdaccount": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, aaaKCDAccountURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) UnsetAAAKCDAccount(resource models.AAAKCDAccount) error { + payload := map[string]any{"aaakcdaccount": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", aaaKCDAccountURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAKCDAccount() ([]models.AAAKCDAccount, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaKCDAccountURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAKCDAccount `json:"aaakcdaccount"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAKCDAccount(kcdaccount string) (models.AAAKCDAccount, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaKCDAccountURL, kcdaccount), nil) + if err != nil { + return models.AAAKCDAccount{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.AAAKCDAccount{}, err + } + + var result struct { + Data []models.AAAKCDAccount `json:"aaakcdaccount"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.AAAKCDAccount{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.AAAKCDAccount{}, fmt.Errorf("aaakcdaccount %s not found", kcdaccount) + } + + return result.Data[0], nil +} + +func (s *AAAService) CountAAAKCDAccount() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", aaaKCDAccountURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAKCDAccount `json:"aaakcdaccount"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +func (s *AAAService) CheckAAAKCDAccount(resource models.AAAKCDAccount) error { + payload := map[string]any{"aaakcdaccount": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=check", aaaKCDAccountURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// aaaldapparams +// Configuration for LDAP parameter resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaaldapparams +func (s *AAAService) UpdateAAALDAPParams(resource models.AAALDAPParams) error { + payload := map[string]any{"aaaldapparams": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, aaaLDAPParamsURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) UnsetAAALDAPParams(resource models.AAALDAPParams) error { + payload := map[string]any{"aaaldapparams": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", aaaLDAPParamsURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAALDAPParams() (models.AAALDAPParams, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaLDAPParamsURL, nil) + if err != nil { + return models.AAALDAPParams{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.AAALDAPParams{}, err + } + + var result struct { + Data models.AAALDAPParams `json:"aaaldapparams"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.AAALDAPParams{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// aaaotpparamter +// Configuration for AAA otpparameter resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaaotpparameter +func (s *AAAService) UpdateAAAOTPParameter(resource models.AAAOTPParameter) error { + payload := map[string]any{"aaaotpparameter": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, aaaOTPParameterURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) UnsetAAAOTPParameter(resource models.AAAOTPParameter) error { + payload := map[string]any{"aaaotpparameter": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", aaaOTPParameterURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAOTPParameter() (models.AAAOTPParameter, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaOTPParameterURL, nil) + if err != nil { + return models.AAAOTPParameter{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.AAAOTPParameter{}, err + } + + var result struct { + Data models.AAAOTPParameter `json:"aaaotpparameter"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.AAAOTPParameter{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// aaaparameter +// Configuration for AAA parameter resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaaparameter +func (s *AAAService) UpdateAAAParameter(resource models.AAAParameter) error { + payload := map[string]any{"aaaparameter": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, aaaParameterURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) UnsetAAAParameter(resource models.AAAParameter) error { + payload := map[string]any{"aaaparameter": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", aaaParameterURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAParameter() (models.AAAParameter, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaParameterURL, nil) + if err != nil { + return models.AAAParameter{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.AAAParameter{}, err + } + + var result struct { + Data models.AAAParameter `json:"aaaparameter"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.AAAParameter{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// aaapreauthenticationaction +// Configuration for pre authentication action resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaapreauthenticationaction +func (s *AAAService) AddAAAPreauthenticationAction(resource models.AAAPreAuthenticationAction) error { + payload := map[string]any{"aaapreauthenticationaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaapreauthenticationActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAPreauthenticationAction(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", aaapreauthenticationActionURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) UpdateAAAPreauthenticationAction(resource models.AAAPreAuthenticationAction) error { + payload := map[string]any{"aaapreauthenticationaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, aaapreauthenticationActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) UnsetAAAPreauthenticationAction(resource models.AAAPreAuthenticationAction) error { + payload := map[string]any{"aaapreauthenticationaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", aaapreauthenticationActionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAPreauthenticationAction() ([]models.AAAPreAuthenticationAction, error) { + req, err := s.client.NewRequest(http.MethodGet, aaapreauthenticationActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAPreAuthenticationAction `json:"aaapreauthenticationaction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAPreauthenticationAction(name string) (models.AAAPreAuthenticationAction, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaapreauthenticationActionURL, name), nil) + if err != nil { + return models.AAAPreAuthenticationAction{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.AAAPreAuthenticationAction{}, err + } + + var result struct { + Data []models.AAAPreAuthenticationAction `json:"aaapreauthenticationaction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.AAAPreAuthenticationAction{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.AAAPreAuthenticationAction{}, fmt.Errorf("aaapreauthenticationaction %s not found", name) + } + + return result.Data[0], nil +} + +func (s *AAAService) CountAAAPreauthenticationAction() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", aaapreauthenticationActionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAPreAuthenticationAction `json:"aaapreauthenticationaction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// aaapreauthenticationparameter +// Configuration for pre authentication parameter resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaapreauthenticationparameter +func (s *AAAService) UpdateAAAPreauthenticationParameter(resource models.AAAPreAuthenticationParameter) error { + payload := map[string]any{"aaapreauthenticationparameter": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, aaaPreauthenticationParameterURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) UnsetAAAPreauthenticationParameter(resource models.AAAPreAuthenticationParameter) error { + payload := map[string]any{"aaapreauthenticationparameter": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", aaaPreauthenticationParameterURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAPreauthenticationParameter() (models.AAAPreAuthenticationParameter, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaPreauthenticationParameterURL, nil) + if err != nil { + return models.AAAPreAuthenticationParameter{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.AAAPreAuthenticationParameter{}, err + } + + var result struct { + Data models.AAAPreAuthenticationParameter `json:"aaapreauthenticationparameter"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.AAAPreAuthenticationParameter{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// aaapreauthenticationpolicy +// Configuration for pre authentication policy resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaapreauthenticationpolicy +func (s *AAAService) AddAAAPreauthenticationPolicy(resource models.AAAPreAuthenticationPolicy) error { + payload := map[string]any{"aaapreauthenticationpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaPreauthenticationPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAPreauthenticationPolicy(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", aaaPreauthenticationPolicyURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) UpdateAAAPreauthenticationPolicy(resource models.AAAPreAuthenticationPolicy) error { + payload := map[string]any{"aaapreauthenticationpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, aaaPreauthenticationPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAPreauthenticationPolicy() ([]models.AAAPreAuthenticationPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaPreauthenticationPolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAPreAuthenticationPolicy `json:"aaapreauthenticationpolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAPreauthenticationPolicy(name string) (models.AAAPreAuthenticationPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaPreauthenticationPolicyURL, name), nil) + if err != nil { + return models.AAAPreAuthenticationPolicy{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.AAAPreAuthenticationPolicy{}, err + } + + var result struct { + Data []models.AAAPreAuthenticationPolicy `json:"aaapreauthenticationpolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.AAAPreAuthenticationPolicy{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.AAAPreAuthenticationPolicy{}, fmt.Errorf("aaapreauthenticationpolicy %s not found", name) + } + + return result.Data[0], nil +} + +func (s *AAAService) CountAAAPreauthenticationPolicy() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", aaaPreauthenticationPolicyURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAPreAuthenticationPolicy `json:"aaapreauthenticationpolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// aaapreauthenticationpolicy_aaaglobal_binding +// Binding object showing the aaaglobal that can be bound to aaapreauthenticationpolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaapreauthenticationpolicy_aaaglobal_binding +func (s *AAAService) GetAllAAAPreauthenticationPolicyAAAGlobalBinding() ([]models.AAAPreAuthenticationPolicyAAAGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaPreauthenticationPolicyAAAGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAPreAuthenticationPolicyAAAGlobalBinding `json:"aaapreauthenticationpolicy_aaaglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAPreauthenticationPolicyAAAGlobalBinding(name string) (models.AAAPreAuthenticationPolicyAAAGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaPreauthenticationPolicyAAAGlobalBindingURL, name), nil) + if err != nil { + return models.AAAPreAuthenticationPolicyAAAGlobalBinding{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.AAAPreAuthenticationPolicyAAAGlobalBinding{}, err + } + + var result struct { + Data []models.AAAPreAuthenticationPolicyAAAGlobalBinding `json:"aaapreauthenticationpolicy_aaaglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.AAAPreAuthenticationPolicyAAAGlobalBinding{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.AAAPreAuthenticationPolicyAAAGlobalBinding{}, fmt.Errorf("aaapreauthenticationpolicy_aaaglobal_binding %s not found", name) + } + + return result.Data[0], nil +} + +func (s *AAAService) CountAAAPreauthenticationPolicyAAAGlobalBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", aaaPreauthenticationPolicyAAAGlobalBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAPreAuthenticationPolicyAAAGlobalBinding `json:"aaapreauthenticationpolicy_aaaglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// aaapreauthenticationpolicy_binding +// Binding object which returns the resources bound to aaapreauthenticationpolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaapreauthenticationpolicy_binding +func (s *AAAService) GetAllAAAPreauthenticationPolicyBinding() ([]models.AAAPreAuthenticationPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaPreauthenticationPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAPreAuthenticationPolicyBinding `json:"aaapreauthenticationpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAPreauthenticationPolicyBinding(name string) (models.AAAPreAuthenticationPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaPreauthenticationPolicyBindingURL, name), nil) + if err != nil { + return models.AAAPreAuthenticationPolicyBinding{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.AAAPreAuthenticationPolicyBinding{}, err + } + + var result struct { + Data []models.AAAPreAuthenticationPolicyBinding `json:"aaapreauthenticationpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.AAAPreAuthenticationPolicyBinding{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.AAAPreAuthenticationPolicyBinding{}, fmt.Errorf("aaapreauthenticationpolicy_binding %s not found", name) + } + + return result.Data[0], nil +} + +// aaapreauthentiucationpolicy_vpnvserver_binding +// Binding object showing the vpnvserver that can be bound to aaapreauthenticationpolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaapreauthenticationpolicy_vpnvserver_binding +func (s *AAAService) GetAllAAAPreauthenticationPolicyVPNVServerBinding() ([]models.AAAPreAuthenticationPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaPreauthenticationPolicyVPNVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAPreAuthenticationPolicyVPNVServerBinding `json:"aaapreauthenticationpolicy_vpnvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAPreauthenticationPolicyVPNVServerBinding(name string) (models.AAAPreAuthenticationPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaPreauthenticationPolicyVPNVServerBindingURL, name), nil) + if err != nil { + return models.AAAPreAuthenticationPolicyVPNVServerBinding{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.AAAPreAuthenticationPolicyVPNVServerBinding{}, err + } + + var result struct { + Data []models.AAAPreAuthenticationPolicyVPNVServerBinding `json:"aaapreauthenticationpolicy_vpnvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.AAAPreAuthenticationPolicyVPNVServerBinding{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.AAAPreAuthenticationPolicyVPNVServerBinding{}, fmt.Errorf("aaapreauthenticationpolicy_vpnvserver_binding %s not found", name) + } + + return result.Data[0], nil +} + +func (s *AAAService) CountAAAPreauthenticationPolicyVPNVServerBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", aaaPreauthenticationPolicyVPNVServerBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAPreAuthenticationPolicyVPNVServerBinding `json:"aaapreauthenticationpolicy_vpnvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// aaaradiusparams +// Configuration for RADIUS parameter resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaaradiusparams +func (s *AAAService) UpdateAAARADIUSParams(resource models.AAARADIUSParams) error { + payload := map[string]any{"aaaradiusparams": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, aaaRADIUSParamsURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) UnsetAAARADIUSParams(resource models.AAARADIUSParams) error { + payload := map[string]any{"aaaradiusparams": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", aaaRADIUSParamsURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAARADIUSParams() (models.AAARADIUSParams, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaRADIUSParamsURL, nil) + if err != nil { + return models.AAARADIUSParams{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.AAARADIUSParams{}, err + } + + var result struct { + Data models.AAARADIUSParams `json:"aaaradiusparams"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.AAARADIUSParams{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// aaasession +// Configuration for active connection resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaasession +func (s *AAAService) GetAllAAASession() ([]models.AAASession, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaSessionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAASession `json:"aaasession"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) CountAAASession() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", aaaSessionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAASession `json:"aaasession"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +func (s *AAAService) KillAAASession(resource models.AAASession) error { + payload := map[string]any{"aaasession": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=kill", aaaSessionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// aaassoprofile +// Configuration for aaa sso profile resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaassoprofile +func (s *AAAService) AddAAASSOProfile(resource models.AAASSOProfile) error { + payload := map[string]any{"aaassoprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaSSOProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAASSOProfile(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", aaaSSOProfileURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAASSOProfile() ([]models.AAASSOProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaSSOProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAASSOProfile `json:"aaassoprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAASSOProfile(name string) (models.AAASSOProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaSSOProfileURL, name), nil) + if err != nil { + return models.AAASSOProfile{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.AAASSOProfile{}, err + } + + var result struct { + Data []models.AAASSOProfile `json:"aaassoprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.AAASSOProfile{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.AAASSOProfile{}, fmt.Errorf("aaassoprofile %s not found", name) + } + + return result.Data[0], nil +} + +func (s *AAAService) CountAAASSOProfile() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", aaaSSOProfileURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAASSOProfile `json:"aaassoprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +func (s *AAAService) UpdateAAASSOProfile(resource models.AAASSOProfile) error { + payload := map[string]any{"aaassoprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, aaaSSOProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// aaatacasparams +// Configuration for tacacs parameters resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaatacacsparams +func (s *AAAService) UpdateAAATACACSParams(resource models.AAATACACSParams) error { + payload := map[string]any{"aaatacacsparams": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, aaaTACACSParamsURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) UnsetAAATACACSParams(resource models.AAATACACSParams) error { + payload := map[string]any{"aaatacacsparams": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", aaaTACACSParamsURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAATACACSParams() (models.AAATACACSParams, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaTACACSParamsURL, nil) + if err != nil { + return models.AAATACACSParams{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.AAATACACSParams{}, err + } + + var result struct { + Data models.AAATACACSParams `json:"aaatacacsparams"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.AAATACACSParams{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// aaauser +// Configuration for AAA user resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaauser +func (s *AAAService) AddAAAUser(resource models.AAAUser) error { + payload := map[string]any{"aaauser": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaUserURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAUser(username string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", aaaUserURL, username), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) UpdateAAAUser(resource models.AAAUser) error { + payload := map[string]any{"aaauser": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, aaaUserURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAUser() ([]models.AAAUser, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaUserURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAUser `json:"aaauser"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAUser(username string) (models.AAAUser, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaUserURL, username), nil) + if err != nil { + return models.AAAUser{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.AAAUser{}, err + } + + var result struct { + Data []models.AAAUser `json:"aaauser"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.AAAUser{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.AAAUser{}, fmt.Errorf("aaauser %s not found", username) + } + + return result.Data[0], nil +} + +func (s *AAAService) CountAAAUser() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", aaaUserURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAUser `json:"aaauser"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +func (s *AAAService) UnlockAAAUser(resource models.AAAUser) error { + payload := map[string]any{"aaauser": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unlock", aaaUserURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// aaauser_aaagroup_binding +// Binding object showing the aaagroup that can be bound to aaauser. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaauser_aaagroup_binding +func (s *AAAService) GetAllAAAUserAAAGroupBinding() ([]models.AAAUserAAAGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaUserAAAGroupBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAUserAAAGroupBinding `json:"aaauser_aaagroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAUserAAAGroupBinding(username string) ([]models.AAAUserAAAGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaUserAAAGroupBindingURL, username), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAUserAAAGroupBinding `json:"aaauser_aaagroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) CountAAAUserAAAGroupBinding(username string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", aaaUserAAAGroupBindingURL, username), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAUserAAAGroupBinding `json:"aaauser_aaagroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// aaauser_auditnslogpolicy_binding +// Binding object showing the auditnslogpolicy that can be bound to aaauser. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaauser_auditnslogpolicy_binding +func (s *AAAService) AddAAAUserAuditNSLogPolicyBinding(resource models.AAAUserAuditNSLogPolicyBinding) error { + payload := map[string]any{"aaauser_auditnslogpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaUserAuditnslogPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAUserAuditNSLogPolicyBinding(username string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", aaaUserAuditnslogPolicyBindingURL, username, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAUserAuditNSLogPolicyBinding() ([]models.AAAUserAuditNSLogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaUserAuditnslogPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAUserAuditNSLogPolicyBinding `json:"aaauser_auditnslogpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAUserAuditNSLogPolicyBinding(username string) ([]models.AAAUserAuditNSLogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaUserAuditnslogPolicyBindingURL, username), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAUserAuditNSLogPolicyBinding `json:"aaauser_auditnslogpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) CountAAAUserAuditNSLogPolicyBinding(username string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", aaaUserAuditnslogPolicyBindingURL, username), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAUserAuditNSLogPolicyBinding `json:"aaauser_auditnslogpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// aaauser_auditsyslogpolicy_binding +// Binding object showing the auditsyslogpolicy that can be bound to aaauser. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaauser_auditsyslogpolicy_binding +func (s *AAAService) AddAAAUserAuditSyslogPolicyBinding(resource models.AAAUserAuditSyslogPolicyBinding) error { + payload := map[string]any{"aaauser_auditsyslogpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaUserAuditsyslogPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAUserAuditSyslogPolicyBinding(username string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", aaaUserAuditsyslogPolicyBindingURL, username, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAUserAuditSyslogPolicyBinding() ([]models.AAAUserAuditSyslogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaUserAuditsyslogPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAUserAuditSyslogPolicyBinding `json:"aaauser_auditsyslogpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAUserAuditSyslogPolicyBinding(username string) ([]models.AAAUserAuditSyslogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaUserAuditsyslogPolicyBindingURL, username), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAUserAuditSyslogPolicyBinding `json:"aaauser_auditsyslogpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) CountAAAUserAuditSyslogPolicyBinding(username string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", aaaUserAuditsyslogPolicyBindingURL, username), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAUserAuditSyslogPolicyBinding `json:"aaauser_auditsyslogpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// aaauser_authorizationpolicy_binding +// Binding object showing the authorizationpolicy that can be bound to aaauser. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaauser_authorizationpolicy_binding +func (s *AAAService) AddAAAUserAuthorizationPolicyBinding(resource models.AAAUserAuthorizationPolicyBinding) error { + payload := map[string]any{"aaauser_authorizationpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaUserAuthorizationPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAUserAuthorizationPolicyBinding(username string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", aaaUserAuthorizationPolicyBindingURL, username, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAUserAuthorizationPolicyBinding() ([]models.AAAUserAuthorizationPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaUserAuthorizationPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAUserAuthorizationPolicyBinding `json:"aaauser_authorizationpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAUserAuthorizationPolicyBinding(username string) ([]models.AAAUserAuthorizationPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaUserAuthorizationPolicyBindingURL, username), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAUserAuthorizationPolicyBinding `json:"aaauser_authorizationpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) CountAAAUserAuthorizationPolicyBinding(username string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", aaaUserAuthorizationPolicyBindingURL, username), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAUserAuthorizationPolicyBinding `json:"aaauser_authorizationpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// aaauser_binding +// Binding object which returns the resources bound to aaauser. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaauser_binding +func (s *AAAService) GetAllAAAUserBinding() ([]models.AAAUserBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaUserBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAUserBinding `json:"aaauser_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAUserBinding(username string) (models.AAAUserBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaUserBindingURL, username), nil) + if err != nil { + return models.AAAUserBinding{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.AAAUserBinding{}, err + } + + var result struct { + Data []models.AAAUserBinding `json:"aaauser_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.AAAUserBinding{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.AAAUserBinding{}, fmt.Errorf("aaauser_binding %s not found", username) + } + + return result.Data[0], nil +} + +// aaauser_intranetip6_binding +// Binding object showing the intranetip6 that can be bound to aaauser. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaauser_intranetip6_binding +func (s *AAAService) AddAAAUserIntranetIP6Binding(resource models.AAAUserIntranetIP6Binding) error { + payload := map[string]any{"aaauser_intranetip6_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaUserIntranetIP6BindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAUserIntranetIP6Binding(username string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", aaaUserIntranetIP6BindingURL, username, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAUserIntranetIP6Binding() ([]models.AAAUserIntranetIP6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaUserIntranetIP6BindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAUserIntranetIP6Binding `json:"aaauser_intranetip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAUserIntranetIP6Binding(username string) ([]models.AAAUserIntranetIP6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaUserIntranetIP6BindingURL, username), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAUserIntranetIP6Binding `json:"aaauser_intranetip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) CountAAAUserIntranetIP6Binding(username string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", aaaUserIntranetIP6BindingURL, username), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAUserIntranetIP6Binding `json:"aaauser_intranetip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// aaauser_intranetip_binding +// Binding object showing the intranetip that can be bound to aaauser. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaauser_intranetip_binding +func (s *AAAService) AddAAAUserIntranetIPBinding(resource models.AAAUserIntranetIPBinding) error { + payload := map[string]any{"aaauser_intranetip_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaUserIntranetIPBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAUserIntranetIPBinding(username string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", aaaUserIntranetIPBindingURL, username, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAUserIntranetIPBinding() ([]models.AAAUserIntranetIPBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaUserIntranetIPBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAUserIntranetIPBinding `json:"aaauser_intranetip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAUserIntranetIPBinding(username string) ([]models.AAAUserIntranetIPBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaUserIntranetIPBindingURL, username), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAUserIntranetIPBinding `json:"aaauser_intranetip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) CountAAAUserIntranetIPBinding(username string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", aaaUserIntranetIPBindingURL, username), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAUserIntranetIPBinding `json:"aaauser_intranetip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// aaauser_tmsessionpolicy_binding +// Binding object showing the tmsessionpolicy that can be bound to aaauser. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaauser_tmsessionpolicy_binding +func (s *AAAService) AddAAAUserTMSessionPolicyBinding(resource models.AAAUserTMSessionPolicyBinding) error { + payload := map[string]any{"aaauser_tmsessionpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaUserTMSessionPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAUserTMSessionPolicyBinding(username string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", aaaUserTMSessionPolicyBindingURL, username, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAUserTMSessionPolicyBinding() ([]models.AAAUserTMSessionPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaUserTMSessionPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAUserTMSessionPolicyBinding `json:"aaauser_tmsessionpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAUserTMSessionPolicyBinding(username string) ([]models.AAAUserTMSessionPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaUserTMSessionPolicyBindingURL, username), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAUserTMSessionPolicyBinding `json:"aaauser_tmsessionpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) CountAAAUserTMSessionPolicyBinding(username string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", aaaUserTMSessionPolicyBindingURL, username), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAUserTMSessionPolicyBinding `json:"aaauser_tmsessionpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// aaauser_vpnintranetapplication_binding +// Binding object showing the vpnintranetapplication that can be bound to aaauser. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaauser_vpnintranetapplication_binding +func (s *AAAService) AddAAAUserVPNIntranetApplicationBinding(resource models.AAAUserVPNIntranetApplicationBinding) error { + payload := map[string]any{"aaauser_vpnintranetapplication_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaUserVPNIntranetApplicationBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAUserVPNIntranetApplicationBinding(username string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", aaaUserVPNIntranetApplicationBindingURL, username, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAUserVPNIntranetApplicationBinding() ([]models.AAAUserVPNIntranetApplicationBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaUserVPNIntranetApplicationBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAUserVPNIntranetApplicationBinding `json:"aaauser_vpnintranetapplication_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAUserVPNIntranetApplicationBinding(username string) ([]models.AAAUserVPNIntranetApplicationBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaUserVPNIntranetApplicationBindingURL, username), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAUserVPNIntranetApplicationBinding `json:"aaauser_vpnintranetapplication_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) CountAAAUserVPNIntranetApplicationBinding(username string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", aaaUserVPNIntranetApplicationBindingURL, username), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAUserVPNIntranetApplicationBinding `json:"aaauser_vpnintranetapplication_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// aaauser_vpnsessionpolicy_binding +// Binding object showing the vpnsessionpolicy that can be bound to aaauser. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaauser_vpnsessionpolicy_binding +func (s *AAAService) AddAAAUserVPNSessionPolicyBinding(resource models.AAAUserVPNSessionPolicyBinding) error { + payload := map[string]any{"aaauser_vpnsessionpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaUserVPNSessionPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAUserVPNSessionPolicyBinding(username string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", aaaUserVPNSessionPolicyBindingURL, username, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAUserVPNSessionPolicyBinding() ([]models.AAAUserVPNSessionPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaUserVPNSessionPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAUserVPNSessionPolicyBinding `json:"aaauser_vpnsessionpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAUserVPNSessionPolicyBinding(username string) ([]models.AAAUserVPNSessionPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaUserVPNSessionPolicyBindingURL, username), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAUserVPNSessionPolicyBinding `json:"aaauser_vpnsessionpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) CountAAAUserVPNSessionPolicyBinding(username string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", aaaUserVPNSessionPolicyBindingURL, username), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAUserVPNSessionPolicyBinding `json:"aaauser_vpnsessionpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// aaauser_vpntrafficpolicy_binding +// Binding object showing the vpntrafficpolicy that can be bound to aaauser. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaauser_vpntrafficpolicy_binding +func (s *AAAService) AddAAAUserVPNTrafficPolicyBinding(resource models.AAAUserVPNTrafficPolicyBinding) error { + payload := map[string]any{"aaauser_vpntrafficpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaUserVPNTrafficPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAUserVPNTrafficPolicyBinding(username string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", aaaUserVPNTrafficPolicyBindingURL, username, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAUserVPNTrafficPolicyBinding() ([]models.AAAUserVPNTrafficPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaUserVPNTrafficPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAUserVPNTrafficPolicyBinding `json:"aaauser_vpntrafficpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAUserVPNTrafficPolicyBinding(username string) ([]models.AAAUserVPNTrafficPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaUserVPNTrafficPolicyBindingURL, username), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAUserVPNTrafficPolicyBinding `json:"aaauser_vpntrafficpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) CountAAAUserVPNTrafficPolicyBinding(username string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", aaaUserVPNTrafficPolicyBindingURL, username), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAUserVPNTrafficPolicyBinding `json:"aaauser_vpntrafficpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// aaauser_vpnurlpolicy_binding +// Binding object showing the vpnurlpolicy that can be bound to aaauser. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaauser_vpnurlpolicy_binding +func (s *AAAService) AddAAAUserVPNURLPolicyBinding(resource models.AAAUserVPNURLPolicyBinding) error { + payload := map[string]any{"aaauser_vpnurlpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaUserVPNURLPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAUserVPNURLPolicyBinding(username string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", aaaUserVPNURLPolicyBindingURL, username, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAUserVPNURLPolicyBinding() ([]models.AAAUserVPNURLPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaUserVPNURLPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAUserVPNURLPolicyBinding `json:"aaauser_vpnurlpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAUserVPNURLPolicyBinding(username string) ([]models.AAAUserVPNURLPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaUserVPNURLPolicyBindingURL, username), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAUserVPNURLPolicyBinding `json:"aaauser_vpnurlpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) CountAAAUserVPNURLPolicyBinding(username string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", aaaUserVPNURLPolicyBindingURL, username), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAUserVPNURLPolicyBinding `json:"aaauser_vpnurlpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// aaauser_vpnurl_binding +// Binding object showing the vpnurl that can be bound to aaauser. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/aaa/aaauser_vpnurl_binding -func (s *AAAService) AddAAAUserVPNURLBinding() {} -func (s *AAAService) DeleteAAAUserVPNURLBinding() {} -func (s *AAAService) GetAllAAAUserVPNURLBinding() {} -func (s *AAAService) GetAAAUserVPNURLBinding() {} -func (s *AAAService) CountAAAUserVPNURLBinding() {} +func (s *AAAService) AddAAAUserVPNURLBinding(resource models.AAAUserVPNURLBinding) error { + payload := map[string]any{"aaauser_vpnurl_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, aaaUserVPNURLBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) DeleteAAAUserVPNURLBinding(username string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", aaaUserVPNURLBindingURL, username, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AAAService) GetAllAAAUserVPNURLBinding() ([]models.AAAUserVPNURLBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, aaaUserVPNURLBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAUserVPNURLBinding `json:"aaauser_vpnurl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) GetAAAUserVPNURLBinding(username string) ([]models.AAAUserVPNURLBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", aaaUserVPNURLBindingURL, username), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AAAUserVPNURLBinding `json:"aaauser_vpnurl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AAAService) CountAAAUserVPNURLBinding(username string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", aaaUserVPNURLBindingURL, username), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AAAUserVPNURLBinding `json:"aaauser_vpnurl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} diff --git a/nitrogo/adm.go b/nitrogo/adm.go index 1064481..e9c1655 100644 --- a/nitrogo/adm.go +++ b/nitrogo/adm.go @@ -1,5 +1,18 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + admParameterURL = "/nitro/v1/config/admparameter" +) + // ADM related configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/adm/adm type ADMService struct { @@ -9,6 +22,72 @@ type ADMService struct { // admparameter // Configuration for ADM parameter resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/adm/admparameter -func (s *ADMService) UpdateADMParamter() {} -func (s *ADMService) UnsetADMParamter() {} -func (s *ADMService) GetAllADMParamter() {} + +func (s *ADMService) UpdateADMParamter(param models.ADMParameter) error { + payload := map[string]any{ + "admparameter": param, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, admParameterURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ADMService) UnsetADMParamter(args []string) error { + unsetMap := make(map[string]bool) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "admparameter": unsetMap, + } + + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, admParameterURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ADMService) GetAllADMParamter() (models.ADMParameter, error) { + req, err := s.client.NewRequest(http.MethodGet, admParameterURL, nil) + if err != nil { + return models.ADMParameter{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.ADMParameter{}, err + } + + var result struct { + ADMParameters []models.ADMParameter `json:"admparameter"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.ADMParameter{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.ADMParameters) > 0 { + return result.ADMParameters[0], nil + } + + return models.ADMParameter{}, nil +} diff --git a/nitrogo/analytics.go b/nitrogo/analytics.go index 061cf79..c65288f 100644 --- a/nitrogo/analytics.go +++ b/nitrogo/analytics.go @@ -1,5 +1,21 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + analyticsProfileURL = "/nitro/v1/config/analyticsprofile" + analyticsGlobalAnalyticsProfileBindingURL = "/nitro/v1/config/analyticsglobal_analyticsprofile_binding" + analyticsGlobalBindingURL = "/nitro/v1/config/analyticsglobal_binding" +) + // Analytics configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/analytics/analytics type AnalyticsService struct { @@ -9,24 +25,283 @@ type AnalyticsService struct { // analyticsglobal_analyticsprofile_binding // Binding object showing the analyticsprofile that can be bound to analyticsglobal. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/analytics/analyticsglobal_analyticsprofile_binding -func (s *AnalyticsService) AddAnalyticsGlobalAnalyticsProfile() {} -func (s *AnalyticsService) DeleteAnalyticsGlobalAnalyticsProfile() {} -func (s *AnalyticsService) GetAnalyticsGlobalAnalyticsProfile() {} -func (s *AnalyticsService) CountAnalyticsGlobalAnalyticsProfile() {} + +func (s *AnalyticsService) AddAnalyticsGlobalAnalyticsProfileBinding(binding models.AnalyticsGlobalAnalyticsProfileBinding) error { + payload := map[string]any{ + "analyticsglobal_analyticsprofile_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, analyticsGlobalAnalyticsProfileBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AnalyticsService) DeleteAnalyticsGlobalAnalyticsProfileBinding(analyticsprofile string) error { + reqURL := fmt.Sprintf("%s?args=analyticsprofile:%s", analyticsGlobalAnalyticsProfileBindingURL, url.QueryEscape(analyticsprofile)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AnalyticsService) GetAnalyticsGlobalAnalyticsProfileBinding() ([]models.AnalyticsGlobalAnalyticsProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, analyticsGlobalAnalyticsProfileBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AnalyticsGlobalAnalyticsProfileBinding `json:"analyticsglobal_analyticsprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AnalyticsService) CountAnalyticsGlobalAnalyticsProfileBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, analyticsGlobalAnalyticsProfileBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"analyticsglobal_analyticsprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} // analyticsglobal_binding // Binding object which returns the resources bound to analyticsglobal. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/analytics/analyticsglobal_binding -func (s *AnalyticsService) AnalyticsGlobalBinding() {} + +func (s *AnalyticsService) AnalyticsGlobalBinding() (models.AnalyticsGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, analyticsGlobalBindingURL, nil) + if err != nil { + return models.AnalyticsGlobalBinding{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.AnalyticsGlobalBinding{}, err + } + + var result struct { + Bindings []models.AnalyticsGlobalBinding `json:"analyticsglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.AnalyticsGlobalBinding{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0], nil + } + + return models.AnalyticsGlobalBinding{}, nil +} // analyticsprofile // Configuration for Analytics profile resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/analytics/analyticsprofile -func (s *AnalyticsService) AddAnalyticsProfile() {} -func (s *AnalyticsService) UpdateAnalyticsProfile() {} -func (s *AnalyticsService) UnsetAnalyticsProfile() {} -func (s *AnalyticsService) DeleteAnalyticsProfile() {} -func (s *AnalyticsService) GetAllAnalyticsProfile() {} -func (s *AnalyticsService) GetAnalyticsProfile() {} -func (s *AnalyticsService) CheckAnalyticsProfile() {} -func (s *AnalyticsService) ChangeAnalyticsProfile() {} + +func (s *AnalyticsService) AddAnalyticsProfile(profile models.AnalyticsProfile) error { + payload := map[string]any{ + "analyticsprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, analyticsProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AnalyticsService) UpdateAnalyticsProfile(profile models.AnalyticsProfile) error { + payload := map[string]any{ + "analyticsprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, analyticsProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AnalyticsService) UnsetAnalyticsProfile(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "analyticsprofile": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, analyticsProfileURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AnalyticsService) DeleteAnalyticsProfile(name string) error { + url := fmt.Sprintf("%s/%s", analyticsProfileURL, name) + req, err := s.client.NewRequest(http.MethodDelete, url, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AnalyticsService) GetAllAnalyticsProfile() ([]models.AnalyticsProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, analyticsProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + AnalyticsProfiles []models.AnalyticsProfile `json:"analyticsprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.AnalyticsProfiles, nil +} + +func (s *AnalyticsService) GetAnalyticsProfile(name string) ([]models.AnalyticsProfile, error) { + url := fmt.Sprintf("%s/%s", analyticsProfileURL, name) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + AnalyticsProfiles []models.AnalyticsProfile `json:"analyticsprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.AnalyticsProfiles, nil +} + +func (s *AnalyticsService) CheckAnalyticsProfile() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, analyticsProfileURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + AnalyticsProfiles []struct { + Count float64 `json:"__count"` + } `json:"analyticsprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.AnalyticsProfiles) > 0 { + return result.AnalyticsProfiles[0].Count, nil + } + + return 0, nil +} + +func (s *AnalyticsService) ChangeAnalyticsProfile(profile models.AnalyticsProfile) error { + payload := map[string]any{ + "analyticsprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, analyticsProfileURL+"?action=update", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} diff --git a/nitrogo/app.go b/nitrogo/app.go index 4436f6e..642cb80 100644 --- a/nitrogo/app.go +++ b/nitrogo/app.go @@ -1,5 +1,19 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + applicationURL = "/nitro/v1/config/application" +) + // Application // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/app/app type AppService struct { @@ -9,6 +23,50 @@ type AppService struct { // application // Configuration for application resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/app/application -func (s *AppService) ImportApplication() {} -func (s *AppService) ExportApplication() {} -func (s *AppService) DeleteApplication() {} + +func (s *AppService) ImportApplication(app models.Application) error { + payload := map[string]any{ + "application": app, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, applicationURL+"?action=Import", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppService) ExportApplication(app models.Application) error { + payload := map[string]any{ + "application": app, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, applicationURL+"?action=export", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppService) DeleteApplication(appname string) error { + reqURL := fmt.Sprintf("%s?args=appname:%s", applicationURL, url.QueryEscape(appname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} diff --git a/nitrogo/appflow.go b/nitrogo/appflow.go index ab12a47..71c4ccd 100644 --- a/nitrogo/appflow.go +++ b/nitrogo/appflow.go @@ -1,5 +1,35 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + appFlowActionURL = "/nitro/v1/config/appflowaction" + appFlowActionAnalyticsProfileBindingURL = "/nitro/v1/config/appflowaction_analyticsprofile_binding" + appFlowActionBindingURL = "/nitro/v1/config/appflowaction_binding" + appFlowCollectorURL = "/nitro/v1/config/appflowcollector" + appFlowGlobalAppFlowPolicyBindingURL = "/nitro/v1/config/appflowglobal_appflowpolicy_binding" + appFlowGlobalBindingURL = "/nitro/v1/config/appflowglobal_binding" + appFlowParamURL = "/nitro/v1/config/appflowparam" + appFlowPolicyURL = "/nitro/v1/config/appflowpolicy" + appFlowPolicyAppFlowGlobalBindingURL = "/nitro/v1/config/appflowpolicy_appflowglobal_binding" + appFlowPolicyAppFlowPolicyLabelBindingURL = "/nitro/v1/config/appflowpolicy_appflowpolicylabel_binding" + appFlowPolicyBindingURL = "/nitro/v1/config/appflowpolicy_binding" + appFlowPolicyCSVServerBindingURL = "/nitro/v1/config/appflowpolicy_csvserver_binding" + appFlowPolicyLBVServerBindingURL = "/nitro/v1/config/appflowpolicy_lbvserver_binding" + appFlowPolicyVPNVServerBindingURL = "/nitro/v1/config/appflowpolicy_vpnvserver_binding" + appFlowPolicyLabelURL = "/nitro/v1/config/appflowpolicylabel" + appFlowPolicyLabelAppFlowPolicyBindingURL = "/nitro/v1/config/appflowpolicylabel_appflowpolicy_binding" + appFlowPolicyLabelBindingURL = "/nitro/v1/config/appflowpolicylabel_binding" +) + // AppFlow configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appflow/appflow type AppFlowService struct { @@ -9,136 +39,1370 @@ type AppFlowService struct { // appflowaction // Configuration for AppFlow action resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appflow/appflowaction -func (s *AppFlowService) AddAppFlowAction() {} -func (s *AppFlowService) DeleteAppFlowAction() {} -func (s *AppFlowService) UpdateAppFlowAction() {} -func (s *AppFlowService) UnsetAppFlowAction() {} -func (s *AppFlowService) RenameAppFlowAction() {} -func (s *AppFlowService) GetAllAppFlowAction() {} -func (s *AppFlowService) GetAppFlowAction() {} -func (s *AppFlowService) CountAppFlowAction() {} + +func (s *AppFlowService) AddAppFlowAction(action models.AppFlowAction) error { + payload := map[string]any{ + "appflowaction": action, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, appFlowActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AppFlowService) DeleteAppFlowAction(name string) error { + reqURL := fmt.Sprintf("%s/%s", appFlowActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AppFlowService) UpdateAppFlowAction(action models.AppFlowAction) error { + payload := map[string]any{ + "appflowaction": action, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, appFlowActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AppFlowService) UnsetAppFlowAction(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{ + "appflowaction": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, appFlowActionURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AppFlowService) RenameAppFlowAction(name, newname string) error { + payload := map[string]any{ + "appflowaction": map[string]string{ + "name": name, + "newname": newname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, appFlowActionURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AppFlowService) GetAllAppFlowAction() ([]models.AppFlowAction, error) { + req, err := s.client.NewRequest(http.MethodGet, appFlowActionURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + AppFlowActions []models.AppFlowAction `json:"appflowaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.AppFlowActions, nil +} + +func (s *AppFlowService) GetAppFlowAction(name string) ([]models.AppFlowAction, error) { + reqURL := fmt.Sprintf("%s/%s", appFlowActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + AppFlowActions []models.AppFlowAction `json:"appflowaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.AppFlowActions, nil +} + +func (s *AppFlowService) CountAppFlowAction() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, appFlowActionURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + AppFlowActions []struct { + Count float64 `json:"__count"` + } `json:"appflowaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.AppFlowActions) > 0 { + return result.AppFlowActions[0].Count, nil + } + return 0, nil +} // appflowaction_analyticsprofile_binding // Binding object showing the analyticsprofile that can be bound to appflowaction. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appflow/appflowaction_analyticsprofile_binding -func (s *AppFlowService) AddAppFlowActionAnalyticsProfileBinding() {} -func (s *AppFlowService) DeleteAppFlowActionAnalyticsProfileBinding() {} -func (s *AppFlowService) GetAllAppFlowActionAnalyticsProfileBinding() {} -func (s *AppFlowService) GetAppFlowActionAnalyticsProfileBinding() {} -func (s *AppFlowService) CountAppFlowActionAnalyticsProfileBinding() {} + +func (s *AppFlowService) AddAppFlowActionAnalyticsProfileBinding(binding models.AppFlowActionAnalyticsProfileBinding) error { + payload := map[string]any{ + "appflowaction_analyticsprofile_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, appFlowActionAnalyticsProfileBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AppFlowService) DeleteAppFlowActionAnalyticsProfileBinding(name string) error { + reqURL := fmt.Sprintf("%s/%s", appFlowActionAnalyticsProfileBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AppFlowService) GetAllAppFlowActionAnalyticsProfileBinding() ([]models.AppFlowActionAnalyticsProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFlowActionAnalyticsProfileBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AppFlowActionAnalyticsProfileBinding `json:"appflowaction_analyticsprofile_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AppFlowService) GetAppFlowActionAnalyticsProfileBinding(name string) ([]models.AppFlowActionAnalyticsProfileBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFlowActionAnalyticsProfileBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AppFlowActionAnalyticsProfileBinding `json:"appflowaction_analyticsprofile_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AppFlowService) CountAppFlowActionAnalyticsProfileBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFlowActionAnalyticsProfileBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appflowaction_analyticsprofile_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // appflowaction_binding // Binding object which returns the resources bound to appflowaction. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appflow/appflowaction_binding -func (s *AppFlowService) GetAllAppFlowActionBinding() {} -func (s *AppFlowService) GetAppFlowActionBinding() {} + +func (s *AppFlowService) GetAllAppFlowActionBinding() ([]models.AppFlowActionBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFlowActionBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AppFlowActionBinding `json:"appflowaction_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AppFlowService) GetAppFlowActionBinding(name string) ([]models.AppFlowActionBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFlowActionBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AppFlowActionBinding `json:"appflowaction_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // appflowcollector // Configuration for AppFlow collector resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appflow/appflowcollector -func (s *AppFlowService) AddAppFlowCollector() {} -func (s *AppFlowService) UpdateAppFlowCollector() {} -func (s *AppFlowService) UnsetAppFlowCollector() {} -func (s *AppFlowService) DeleteAppFlowCollector() {} -func (s *AppFlowService) RenameAppFlowCollector() {} -func (s *AppFlowService) GetAllAppFlowCollector() {} -func (s *AppFlowService) GetAppFlowCollector() {} -func (s *AppFlowService) CountAppFlowCollector() {} + +func (s *AppFlowService) AddAppFlowCollector(collector models.AppFlowCollector) error { + payload := map[string]any{ + "appflowcollector": collector, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, appFlowCollectorURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AppFlowService) UpdateAppFlowCollector(collector models.AppFlowCollector) error { + payload := map[string]any{ + "appflowcollector": collector, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, appFlowCollectorURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AppFlowService) UnsetAppFlowCollector(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{ + "appflowcollector": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, appFlowCollectorURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AppFlowService) DeleteAppFlowCollector(name string) error { + reqURL := fmt.Sprintf("%s/%s", appFlowCollectorURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AppFlowService) RenameAppFlowCollector(name, newname string) error { + payload := map[string]any{ + "appflowcollector": map[string]string{ + "name": name, + "newname": newname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, appFlowCollectorURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AppFlowService) GetAllAppFlowCollector() ([]models.AppFlowCollector, error) { + req, err := s.client.NewRequest(http.MethodGet, appFlowCollectorURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + AppFlowCollectors []models.AppFlowCollector `json:"appflowcollector"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.AppFlowCollectors, nil +} + +func (s *AppFlowService) GetAppFlowCollector(name string) ([]models.AppFlowCollector, error) { + reqURL := fmt.Sprintf("%s/%s", appFlowCollectorURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + AppFlowCollectors []models.AppFlowCollector `json:"appflowcollector"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.AppFlowCollectors, nil +} + +func (s *AppFlowService) CountAppFlowCollector() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, appFlowCollectorURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + AppFlowCollectors []struct { + Count float64 `json:"__count"` + } `json:"appflowcollector"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.AppFlowCollectors) > 0 { + return result.AppFlowCollectors[0].Count, nil + } + return 0, nil +} // appflowglobal_appflowpolicy_binding // Binding object showing the appflowpolicy that can be bound to appflowglobal. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appflow/appflowglobal_appflowpolicy_binding -func (s *AppFlowService) AddAppFlowGlobalAppFlowPolicyBinding() {} -func (s *AppFlowService) DeleteAppFlowGlobalAppFlowPolicyBinding() {} -func (s *AppFlowService) GetAppFlowGlobalAppFlowPolicyBinding() {} -func (s *AppFlowService) CountAppFlowGlobalAppFlowPolicyBinding() {} + +func (s *AppFlowService) AddAppFlowGlobalAppFlowPolicyBinding(binding models.AppFlowGlobalAppFlowPolicyBinding) error { + payload := map[string]any{ + "appflowglobal_appflowpolicy_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, appFlowGlobalAppFlowPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AppFlowService) DeleteAppFlowGlobalAppFlowPolicyBinding(policyname string) error { + reqURL := fmt.Sprintf("%s?args=policyname:%s", appFlowGlobalAppFlowPolicyBindingURL, url.QueryEscape(policyname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AppFlowService) GetAppFlowGlobalAppFlowPolicyBinding() ([]models.AppFlowGlobalAppFlowPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFlowGlobalAppFlowPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AppFlowGlobalAppFlowPolicyBinding `json:"appflowglobal_appflowpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AppFlowService) CountAppFlowGlobalAppFlowPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, appFlowGlobalAppFlowPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appflowglobal_appflowpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // appflowglobal_binding // Binding object which returns the resources bound to appflowglobal. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appflow/appflowglobal_binding -func (s *AppFlowService) GetAppFlowGlobalBinding() {} + +func (s *AppFlowService) GetAppFlowGlobalBinding() ([]models.AppFlowGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFlowGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AppFlowGlobalBinding `json:"appflowglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // appflowparam // Configuration for AppFlow parameter resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appflow/appflowparam -func (s *AppFlowService) UpdateAppFlowParam() {} -func (s *AppFlowService) UnsetAppFlowParam() {} -func (s *AppFlowService) GetAllAppFlowParam() {} + +func (s *AppFlowService) UpdateAppFlowParam(param models.AppFlowParam) error { + payload := map[string]any{ + "appflowparam": param, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, appFlowParamURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AppFlowService) UnsetAppFlowParam(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{ + "appflowparam": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, appFlowParamURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AppFlowService) GetAllAppFlowParam() (models.AppFlowParam, error) { + req, err := s.client.NewRequest(http.MethodGet, appFlowParamURL, nil) + if err != nil { + return models.AppFlowParam{}, err + } + resp, err := s.client.Do(req) + if err != nil { + return models.AppFlowParam{}, err + } + var result struct { + AppFlowParams []models.AppFlowParam `json:"appflowparam"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return models.AppFlowParam{}, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.AppFlowParams) > 0 { + return result.AppFlowParams[0], nil + } + return models.AppFlowParam{}, nil +} // appflowpolicy // Configuration for AppFlow policy resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appflow/appflowpolicy -func (s *AppFlowService) AddAppFlowPolicy() {} -func (s *AppFlowService) DeleteAppFlowPolicy() {} -func (s *AppFlowService) UpdateAppFlowPolicy() {} -func (s *AppFlowService) UnsetAppFlowPolicy() {} -func (s *AppFlowService) RenameAppFlowPolicy() {} -func (s *AppFlowService) GetAllAppFlowPolicy() {} -func (s *AppFlowService) GetAppFlowPolicy() {} -func (s *AppFlowService) CountAppFlowPolicy() {} + +func (s *AppFlowService) AddAppFlowPolicy(policy models.AppFlowPolicy) error { + payload := map[string]any{ + "appflowpolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, appFlowPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AppFlowService) DeleteAppFlowPolicy(name string) error { + reqURL := fmt.Sprintf("%s/%s", appFlowPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AppFlowService) UpdateAppFlowPolicy(policy models.AppFlowPolicy) error { + payload := map[string]any{ + "appflowpolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, appFlowPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AppFlowService) UnsetAppFlowPolicy(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{ + "appflowpolicy": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, appFlowPolicyURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AppFlowService) RenameAppFlowPolicy(name, newname string) error { + payload := map[string]any{ + "appflowpolicy": map[string]string{ + "name": name, + "newname": newname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, appFlowPolicyURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AppFlowService) GetAllAppFlowPolicy() ([]models.AppFlowPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, appFlowPolicyURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + AppFlowPolicies []models.AppFlowPolicy `json:"appflowpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.AppFlowPolicies, nil +} + +func (s *AppFlowService) GetAppFlowPolicy(name string) ([]models.AppFlowPolicy, error) { + reqURL := fmt.Sprintf("%s/%s", appFlowPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + AppFlowPolicies []models.AppFlowPolicy `json:"appflowpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.AppFlowPolicies, nil +} + +func (s *AppFlowService) CountAppFlowPolicy() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, appFlowPolicyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + AppFlowPolicies []struct { + Count float64 `json:"__count"` + } `json:"appflowpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.AppFlowPolicies) > 0 { + return result.AppFlowPolicies[0].Count, nil + } + return 0, nil +} // appflowpolicylabel // Configuration for AppFlow policy label resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appflow/appflowpolicylabel -func (s *AppFlowService) AddAppFlowPolicyLabel() {} -func (s *AppFlowService) DeleteAppFlowPolicyLabel() {} -func (s *AppFlowService) RenameAppFlowPolicyLabel() {} -func (s *AppFlowService) GetAllAppFlowPolicyLabel() {} -func (s *AppFlowService) GetAppFlowPolicyLabel() {} -func (s *AppFlowService) CountAppFlowPolicyLabel() {} + +func (s *AppFlowService) AddAppFlowPolicyLabel(label models.AppFlowPolicyLabel) error { + payload := map[string]any{ + "appflowpolicylabel": label, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, appFlowPolicyLabelURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AppFlowService) DeleteAppFlowPolicyLabel(labelname string) error { + reqURL := fmt.Sprintf("%s/%s", appFlowPolicyLabelURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AppFlowService) RenameAppFlowPolicyLabel(labelname, newname string) error { + payload := map[string]any{ + "appflowpolicylabel": map[string]string{ + "labelname": labelname, + "newname": newname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, appFlowPolicyLabelURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AppFlowService) GetAllAppFlowPolicyLabel() ([]models.AppFlowPolicyLabel, error) { + req, err := s.client.NewRequest(http.MethodGet, appFlowPolicyLabelURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + AppFlowPolicyLabels []models.AppFlowPolicyLabel `json:"appflowpolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.AppFlowPolicyLabels, nil +} + +func (s *AppFlowService) GetAppFlowPolicyLabel(labelname string) ([]models.AppFlowPolicyLabel, error) { + reqURL := fmt.Sprintf("%s/%s", appFlowPolicyLabelURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + AppFlowPolicyLabels []models.AppFlowPolicyLabel `json:"appflowpolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.AppFlowPolicyLabels, nil +} + +func (s *AppFlowService) CountAppFlowPolicyLabel() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, appFlowPolicyLabelURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + AppFlowPolicyLabels []struct { + Count float64 `json:"__count"` + } `json:"appflowpolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.AppFlowPolicyLabels) > 0 { + return result.AppFlowPolicyLabels[0].Count, nil + } + return 0, nil +} // appflowpolicylabel_appflowpolicy_binding // Binding object showing the appflowpolicy that can be bound to appflowpolicylabel. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appflow/appflowpolicylabel_appflowpolicy_binding -func (s *AppFlowService) AddAppFlowPolicyLabelAppFlowPolicyBinding() {} -func (s *AppFlowService) DeleteAppFlowPolicyLabelAppFlowPolicyBinding() {} -func (s *AppFlowService) GetAllAppFlowPolicyLabelAppFlowPolicyBinding() {} -func (s *AppFlowService) GetAppFlowPolicyLabelAppFlowPolicyBinding() {} -func (s *AppFlowService) CountAppFlowPolicyLabelAppFlowPolicyBinding() {} + +func (s *AppFlowService) AddAppFlowPolicyLabelAppFlowPolicyBinding(binding models.AppFlowPolicyLabelAppFlowPolicyBinding) error { + payload := map[string]any{ + "appflowpolicylabel_appflowpolicy_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, appFlowPolicyLabelAppFlowPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AppFlowService) DeleteAppFlowPolicyLabelAppFlowPolicyBinding(labelname string, policyname string) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s", appFlowPolicyLabelAppFlowPolicyBindingURL, url.QueryEscape(labelname), url.QueryEscape(policyname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AppFlowService) GetAllAppFlowPolicyLabelAppFlowPolicyBinding() ([]models.AppFlowPolicyLabelAppFlowPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFlowPolicyLabelAppFlowPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AppFlowPolicyLabelAppFlowPolicyBinding `json:"appflowpolicylabel_appflowpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AppFlowService) GetAppFlowPolicyLabelAppFlowPolicyBinding(labelname string) ([]models.AppFlowPolicyLabelAppFlowPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFlowPolicyLabelAppFlowPolicyBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AppFlowPolicyLabelAppFlowPolicyBinding `json:"appflowpolicylabel_appflowpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AppFlowService) CountAppFlowPolicyLabelAppFlowPolicyBinding(labelname string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFlowPolicyLabelAppFlowPolicyBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appflowpolicylabel_appflowpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // appflowpolicylabel_binding // Binding object which returns the resources bound to appflowpolicylabel. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appflow/appflowpolicylabel_binding -func (s *AppFlowService) GetAllAppFlowPolicyLabelBinding() {} -func (s *AppFlowService) GetAppFlowPolicyLabelBinding() {} + +func (s *AppFlowService) GetAllAppFlowPolicyLabelBinding() ([]models.AppFlowPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFlowPolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AppFlowPolicyLabelBinding `json:"appflowpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AppFlowService) GetAppFlowPolicyLabelBinding(labelname string) ([]models.AppFlowPolicyLabelBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFlowPolicyLabelBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AppFlowPolicyLabelBinding `json:"appflowpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // appflowpolicy_appflowglobal_binding // Binding object showing the appflowglobal that can be bound to appflowpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appflow/appflowpolicy_appflowglobal_binding -func (s *AppFlowService) GetAllAppFlowPolicyAppFlowGlobalBinding() {} -func (s *AppFlowService) GetAppFlowPolicyAppFlowGlobalBinding() {} -func (s *AppFlowService) CountAppFlowPolicyAppFlowGlobalBinding() {} + +func (s *AppFlowService) GetAllAppFlowPolicyAppFlowGlobalBinding() ([]models.AppFlowPolicyAppFlowGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFlowPolicyAppFlowGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AppFlowPolicyAppFlowGlobalBinding `json:"appflowpolicy_appflowglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AppFlowService) GetAppFlowPolicyAppFlowGlobalBinding(name string) ([]models.AppFlowPolicyAppFlowGlobalBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFlowPolicyAppFlowGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AppFlowPolicyAppFlowGlobalBinding `json:"appflowpolicy_appflowglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AppFlowService) CountAppFlowPolicyAppFlowGlobalBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFlowPolicyAppFlowGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appflowpolicy_appflowglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // appflowpolicy_appflowpolicylabel_binding // Binding object showing the appflowpolicylabel that can be bound to appflowpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appflow/appflowpolicy_appflowpolicylabel_binding -func (s *AppFlowService) GetAllAppFlowPolicyAppFlowPolicyLabelBinding() {} -func (s *AppFlowService) GetAppFlowPolicyAppFlowPolicyLabelBinding() {} -func (s *AppFlowService) CountAppFlowPolicyAppFlowPolicyLabelBinding() {} + +func (s *AppFlowService) GetAllAppFlowPolicyAppFlowPolicyLabelBinding() ([]models.AppFlowPolicyAppFlowPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFlowPolicyAppFlowPolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AppFlowPolicyAppFlowPolicyLabelBinding `json:"appflowpolicy_appflowpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AppFlowService) GetAppFlowPolicyAppFlowPolicyLabelBinding(name string) ([]models.AppFlowPolicyAppFlowPolicyLabelBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFlowPolicyAppFlowPolicyLabelBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AppFlowPolicyAppFlowPolicyLabelBinding `json:"appflowpolicy_appflowpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AppFlowService) CountAppFlowPolicyAppFlowPolicyLabelBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFlowPolicyAppFlowPolicyLabelBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appflowpolicy_appflowpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // appflowpolicy_binding // Binding object which returns the resources bound to appflowpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appflow/appflowpolicy_binding -func (s *AppFlowService) GetAllAppFlowPolicyBinding() {} -func (s *AppFlowService) GetAppFlowPolicyBinding() {} + +func (s *AppFlowService) GetAllAppFlowPolicyBinding() ([]models.AppFlowPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFlowPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AppFlowPolicyBinding `json:"appflowpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AppFlowService) GetAppFlowPolicyBinding(name string) ([]models.AppFlowPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFlowPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AppFlowPolicyBinding `json:"appflowpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // appflowpolicy_csvserver_binding // Binding object showing the csvserver that can be bound to appflowpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appflow/appflowpolicy_csvserver_binding -func (s *AppFlowService) GetAllAppFlowPolicyCSVServerBinding() {} -func (s *AppFlowService) GetAppFlowPolicyCSVServerBinding() {} -func (s *AppFlowService) CountAppFlowPolicyCSVServerBinding() {} + +func (s *AppFlowService) GetAllAppFlowPolicyCSVServerBinding() ([]models.AppFlowPolicyCSVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFlowPolicyCSVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AppFlowPolicyCSVServerBinding `json:"appflowpolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AppFlowService) GetAppFlowPolicyCSVServerBinding(name string) ([]models.AppFlowPolicyCSVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFlowPolicyCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AppFlowPolicyCSVServerBinding `json:"appflowpolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AppFlowService) CountAppFlowPolicyCSVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFlowPolicyCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appflowpolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // appflowpolicy_lbvserver_binding // Binding object showing the lbvserver that can be bound to appflowpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appflow/appflowpolicy_lbvserver_binding -func (s *AppFlowService) GetAllAppFlowPolicy_LBVServerBinding() {} -func (s *AppFlowService) GetAppFlowPolicy_LBVServerBinding() {} -func (s *AppFlowService) CountAppFlowPolicy_LBVServerBinding() {} + +func (s *AppFlowService) GetAllAppFlowPolicy_LBVServerBinding() ([]models.AppFlowPolicyLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFlowPolicyLBVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AppFlowPolicyLBVServerBinding `json:"appflowpolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AppFlowService) GetAppFlowPolicy_LBVServerBinding(name string) ([]models.AppFlowPolicyLBVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFlowPolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AppFlowPolicyLBVServerBinding `json:"appflowpolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AppFlowService) CountAppFlowPolicy_LBVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFlowPolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appflowpolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // appflowpolicy_vpnvserver_binding // Binding object showing the vpnvserver that can be bound to appflowpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appflow/appflowpolicy_vpnvserver_binding -func (s *AppFlowService) GetAllAppFlowPolicyVPNVServerBinding() {} -func (s *AppFlowService) GetAppFlowPolicyVPNVServerBinding() {} -func (s *AppFlowService) CountAppFlowPolicyVPNVServerBinding() {} + +func (s *AppFlowService) GetAllAppFlowPolicyVPNVServerBinding() ([]models.AppFlowPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFlowPolicyVPNVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AppFlowPolicyVPNVServerBinding `json:"appflowpolicy_vpnvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AppFlowService) GetAppFlowPolicyVPNVServerBinding(name string) ([]models.AppFlowPolicyVPNVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFlowPolicyVPNVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AppFlowPolicyVPNVServerBinding `json:"appflowpolicy_vpnvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AppFlowService) CountAppFlowPolicyVPNVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFlowPolicyVPNVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appflowpolicy_vpnvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} diff --git a/nitrogo/appfw.go b/nitrogo/appfw.go index 7c0b7a0..9b71ced 100644 --- a/nitrogo/appfw.go +++ b/nitrogo/appfw.go @@ -1,5 +1,77 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + appFWArchiveURL = "/nitro/v1/config/appfwarchive" + appFWConfidFieldURL = "/nitro/v1/config/appfwconfidfield" + appFWCustomSettingsURL = "/nitro/v1/config/appfwcustomsettings" + appFWFieldTypeURL = "/nitro/v1/config/appfwfieldtype" + appFWGlobalAppFWPolicyBindingURL = "/nitro/v1/config/appfwglobal_appfwpolicy_binding" + appFWGlobalAuditNSLogPolicyBindingURL = "/nitro/v1/config/appfwglobal_auditnslogpolicy_binding" + appFWGlobalAuditSyslogPolicyBindingURL = "/nitro/v1/config/appfwglobal_auditsyslogpolicy_binding" + appFWGlobalBindingURL = "/nitro/v1/config/appfwglobal_binding" + appFWHTMLErrorPageURL = "/nitro/v1/config/appfwhtmlerrorpage" + appFWJSONContentTypeURL = "/nitro/v1/config/appfwjsoncontenttype" + appFWJSONErrorPageURL = "/nitro/v1/config/appfwjsonerrorpage" + appFWLearningDataURL = "/nitro/v1/config/appfwlearningdata" + appFWLearningSettingsURL = "/nitro/v1/config/appfwlearningsettings" + appFWMultipartFormContentTypeURL = "/nitro/v1/config/appfwmultipartformcontenttype" + appFWPolicyURL = "/nitro/v1/config/appfwpolicy" + appFWPolicyAppFWGlobalBindingURL = "/nitro/v1/config/appfwpolicy_appfwglobal_binding" + appFWPolicyAppFWPolicyLabelBindingURL = "/nitro/v1/config/appfwpolicy_appfwpolicylabel_binding" + appFWPolicyBindingURL = "/nitro/v1/config/appfwpolicy_binding" + appFWPolicyCSVServerBindingURL = "/nitro/v1/config/appfwpolicy_csvserver_binding" + appFWPolicyLBVServerBindingURL = "/nitro/v1/config/appfwpolicy_lbvserver_binding" + appFWPolicyLabelURL = "/nitro/v1/config/appfwpolicylabel" + appFWPolicyLabelAppFWPolicyBindingURL = "/nitro/v1/config/appfwpolicylabel_appfwpolicy_binding" + appFWPolicyLabelBindingURL = "/nitro/v1/config/appfwpolicylabel_binding" + appFWPolicyLabelPolicyBindingBindingURL = "/nitro/v1/config/appfwpolicylabel_policybinding_binding" + appFWProfileURL = "/nitro/v1/config/appfwprofile" + appFWProfileBindingURL = "/nitro/v1/config/appfwprofile_binding" + appFWProfileCMDInjectionBindingURL = "/nitro/v1/config/appfwprofile_cmdinjection_binding" + appFWProfileContentTypeBindingURL = "/nitro/v1/config/appfwprofile_contenttype_binding" + appFWProfileCookieConsistencyBindingURL = "/nitro/v1/config/appfwprofile_cookieconsistency_binding" + appFWProfileCreditCardNumberBindingURL = "/nitro/v1/config/appfwprofile_creditcardnumber_binding" + appFWProfileCrossSiteScriptingBindingURL = "/nitro/v1/config/appfwprofile_crosssitescripting_binding" + appFWProfileCSRFTagBindingURL = "/nitro/v1/config/appfwprofile_csrftag_binding" + appFWProfileDenyURLBindingURL = "/nitro/v1/config/appfwprofile_denyurl_binding" + appFWProfileExcludeRESContentTypeBindingURL = "/nitro/v1/config/appfwprofile_excluderescontenttype_binding" + appFWProfileFieldConsistencyBindingURL = "/nitro/v1/config/appfwprofile_fieldconsistency_binding" + appFWProfileFieldFormatBindingURL = "/nitro/v1/config/appfwprofile_fieldformat_binding" + appFWProfileFileUploadTypeBindingURL = "/nitro/v1/config/appfwprofile_fileuploadtype_binding" + appFWProfileJSONDOSURLBindingURL = "/nitro/v1/config/appfwprofile_jsondosurl_binding" + appFWProfileJSONSQLURLBindingURL = "/nitro/v1/config/appfwprofile_jsonsqlurl_binding" + appFWProfileJSONXSSURLBindingURL = "/nitro/v1/config/appfwprofile_jsonxssurl_binding" + appFWProfileLogExpressionBindingURL = "/nitro/v1/config/appfwprofile_logexpression_binding" + appFWProfileSafeObjectBindingURL = "/nitro/v1/config/appfwprofile_safeobject_binding" + appFWProfileSQLInjectionBindingURL = "/nitro/v1/config/appfwprofile_sqlinjection_binding" + appFWProfileStartURLBindingURL = "/nitro/v1/config/appfwprofile_starturl_binding" + appFWProfileTrustedLearningClientsBindingURL = "/nitro/v1/config/appfwprofile_trustedlearningclients_binding" + appFWProfileXMLAttachmentURLBindingURL = "/nitro/v1/config/appfwprofile_xmlattachmenturl_binding" + appFWProfileXMLDOSURLBindingURL = "/nitro/v1/config/appfwprofile_xmldosurl_binding" + appFWProfileXMLSQLInjectionBindingURL = "/nitro/v1/config/appfwprofile_xmlsqlinjection_binding" + appFWProfileXMLValidationURLBindingURL = "/nitro/v1/config/appfwprofile_xmlvalidationurl_binding" + appFWProfileXMLWSIURLBindingURL = "/nitro/v1/config/appfwprofile_xmlwsiurl_binding" + appFWProfileXMLXSSBindingURL = "/nitro/v1/config/appfwprofile_xmlxss_binding" + appFWSettingsURL = "/nitro/v1/config/appfwsettings" + appFWSignaturesURL = "/nitro/v1/config/appfwsignatures" + appFWTransactionRecordsURL = "/nitro/v1/config/appfwtransactionrecords" + appFWURLEncodedFormContentTypeURL = "/nitro/v1/config/appfwurlencodedformcontenttype" + appFWWSDLURL = "/nitro/v1/config/appfwwsdl" + appFWXMLContentTypeURL = "/nitro/v1/config/appfwxmlcontenttype" + appFWXMLErrorPageURL = "/nitro/v1/config/appfwxmlerrorpage" + appFWXMLSchemaURL = "/nitro/v1/config/appfwxmlschema" +) + // Application Firewall configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfw type AppFWService struct { @@ -9,501 +81,5930 @@ type AppFWService struct { // appfwarchive // Configuration for archive resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwarchive -func (s *AppFWService) DeleteAppFWArchive() {} -func (s *AppFWService) ExportAppFWArchive() {} -func (s *AppFWService) ImportAppFWArchive() {} -func (s *AppFWService) GetAllAppFWArchive() {} +func (s *AppFWService) DeleteAppFWArchive(name string) error { + reqURL := fmt.Sprintf("%s/%s", appFWArchiveURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) ExportAppFWArchive(resource models.AppFWArchive) error { + payload := map[string]any{ + "appfwarchive": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWArchiveURL+"?action=export", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) ImportAppFWArchive(resource models.AppFWArchive) error { + payload := map[string]any{ + "appfwarchive": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWArchiveURL+"?action=Import", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWArchive() ([]models.AppFWArchive, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWArchiveURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Archives []models.AppFWArchive `json:"appfwarchive"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Archives, nil +} // appfwconfidfield // Configuration for configured confidential form fields resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwconfidfield -func (s *AppFWService) AddAppFWConfigField() {} -func (s *AppFWService) DeleteAppFWConfigField() {} -func (s *AppFWService) UpdateAppFWConfigField() {} -func (s *AppFWService) UnsetAppFWConfigField() {} -func (s *AppFWService) GetAllAppFWConfigField() {} -func (s *AppFWService) CountAppFWConfigField() {} +func (s *AppFWService) AddAppFWConfigField(resource models.AppFWConfidField) error { + payload := map[string]any{ + "appfwconfidfield": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWConfidFieldURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWConfigField(name string) error { + reqURL := fmt.Sprintf("%s/%s", appFWConfidFieldURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) UpdateAppFWConfigField(resource models.AppFWConfidField) error { + payload := map[string]any{ + "appfwconfidfield": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, appFWConfidFieldURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) UnsetAppFWConfigField(resource models.AppFWConfidField) error { + payload := map[string]any{ + "appfwconfidfield": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWConfidFieldURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWConfigField() ([]models.AppFWConfidField, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWConfidFieldURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Fields []models.AppFWConfidField `json:"appfwconfidfield"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Fields, nil +} + +func (s *AppFWService) CountAppFWConfigField() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWConfidFieldURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Fields []struct { + Count float64 `json:"__count"` + } `json:"appfwconfidfield"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Fields) > 0 { + return result.Fields[0].Count, nil + } + + return 0, nil +} // appfwcustomsettings // Configuration for application firewall custom settings XML configuration resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwcustomsettings -func (s *AppFWService) ExportAppFWCustomSettings() {} +func (s *AppFWService) ExportAppFWCustomSettings(resource models.AppFWCustomSettings) error { + payload := map[string]any{ + "appfwcustomsettings": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWCustomSettingsURL+"?action=export", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} // appfwfieldtype // Configuration for application firewall form field type resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwfieldtype -func (s *AppFWService) AddAppFWFieldType() {} -func (s *AppFWService) DeleteAppFWFieldType() {} -func (s *AppFWService) UpdateAppFWFieldType() {} -func (s *AppFWService) GetAllAppFWFieldType() {} -func (s *AppFWService) GetAppFWFieldType() {} -func (s *AppFWService) CountAppFWFieldType() {} +func (s *AppFWService) AddAppFWFieldType(resource models.AppFWFieldType) error { + payload := map[string]any{ + "appfwfieldtype": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWFieldTypeURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWFieldType(name string) error { + reqURL := fmt.Sprintf("%s/%s", appFWFieldTypeURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) UpdateAppFWFieldType(resource models.AppFWFieldType) error { + payload := map[string]any{ + "appfwfieldtype": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, appFWFieldTypeURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWFieldType() ([]models.AppFWFieldType, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWFieldTypeURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + FieldTypes []models.AppFWFieldType `json:"appfwfieldtype"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.FieldTypes, nil +} + +func (s *AppFWService) GetAppFWFieldType(name string) (*models.AppFWFieldType, error) { + reqURL := fmt.Sprintf("%s/%s", appFWFieldTypeURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + FieldTypes []models.AppFWFieldType `json:"appfwfieldtype"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.FieldTypes) == 0 { + return nil, fmt.Errorf("appfwfieldtype not found") + } + + return &result.FieldTypes[0], nil +} + +func (s *AppFWService) CountAppFWFieldType() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWFieldTypeURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + FieldTypes []struct { + Count float64 `json:"__count"` + } `json:"appfwfieldtype"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.FieldTypes) > 0 { + return result.FieldTypes[0].Count, nil + } + + return 0, nil +} // appfwglobal_appfwpolicy_binding // Binding object showing the appfwpolicy that can be bound to appfwglobal. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwglobal_appfwpolicy_binding -func (s *AppFWService) AddAppFWGlobalAppFWPolicyBinding() {} -func (s *AppFWService) DeleteAppFWGlobalAppFWPolicyBinding() {} -func (s *AppFWService) GetAppFWGlobalAppFWPolicyBinding() {} -func (s *AppFWService) CountAppFWGlobalAppFWPolicyBinding() {} +func (s *AppFWService) AddAppFWGlobalAppFWPolicyBinding(resource models.AppFWGlobalAppFWPolicyBinding) error { + payload := map[string]any{ + "appfwglobal_appfwpolicy_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } -// appfwglobal_auditnslogpolicy_binding -// Binding object showing the auditnslogpolicy that can be bound to appfwglobal. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwglobal_auditnslogpolicy_binding -func (s *AppFWService) AddAppFWGlobalAuditNSLogPolicyBinding() {} -func (s *AppFWService) DeleteAppFWGlobalAuditNSLogPolicyBinding() {} -func (s *AppFWService) GetAppFWGlobalAuditNSLogPolicyBinding() {} -func (s *AppFWService) CountAppFWGlobalAuditNSLogPolicyBinding() {} + req, err := s.client.NewRequest(http.MethodPost, appFWGlobalAppFWPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } -// appfwglobal_audtisyslogpolicy_binding -// Binding object showing the auditsyslogpolicy that can be bound to appfwglobal. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwglobal_auditsyslogpolicy_binding -func (s *AppFWService) AddAppFWGlobalAuditSyslogPolicyBinding() {} -func (s *AppFWService) DeleteAppFWGlobalAuditSyslogPolicyBinding() {} -func (s *AppFWService) GetAppFWGlobalAuditSyslogPolicyBinding() {} -func (s *AppFWService) CountAppFWGlobalAuditSyslogPolicyBinding() {} + _, err = s.client.Do(req) + return err +} -// appfwglobal_binding -// Binding object which returns the resources bound to appfwglobal. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwglobal_binding -func (s *AppFWService) GetAppFWGlobalBinding() {} +func (s *AppFWService) DeleteAppFWGlobalAppFWPolicyBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWGlobalAppFWPolicyBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } -// appfwhtmlerrorpage -// Configuration for HTML error page resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwhtmlerrorpage -func (s *AppFWService) DeleteAppFWHTMLErrorPage() {} -func (s *AppFWService) GetAllAppFWHTMLErrorPage() {} -func (s *AppFWService) GetAppFWHTMLErrorPage() {} -func (s *AppFWService) ImportAppFWHTMLErrorPage() {} -func (s *AppFWService) ChangeAppFWHTMLErrorPage() {} + _, err = s.client.Do(req) + return err +} -// appfwjsoncontenttype -// Configuration for JSON content type resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwjsoncontenttype -func (s *AppFWService) AddAppFWJSONContentType() {} -func (s *AppFWService) DeleteAppFWJSONContentType() {} -func (s *AppFWService) GetAllAppFWJSONContentType() {} -func (s *AppFWService) GetAppFWJSONContentType() {} -func (s *AppFWService) CountAppFWJSONContentType() {} +func (s *AppFWService) GetAppFWGlobalAppFWPolicyBinding() ([]models.AppFWGlobalAppFWPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWGlobalAppFWPolicyBindingURL, nil) + if err != nil { + return nil, err + } -// appfwjsonerrorpage -// Configuration for JSON error page resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwjsonerrorpage -func (s *AppFWService) DeleteAppFWJSONErrorPage() {} -func (s *AppFWService) GetAllAppFWJSONErrorPage() {} -func (s *AppFWService) GetAppFWJSONErrorPage() {} -func (s *AppFWService) ImportAppFWJSONErrorPage() {} -func (s *AppFWService) ChangeAppFWJSONErrorPage() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// appfwlearningdata -// Configuration for learning data resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwlearningdata -func (s *AppFWService) DeleteAppFWLearningData() {} -func (s *AppFWService) GetAllAppFWLearningData() {} -func (s *AppFWService) CountAppFWLearningData() {} -func (s *AppFWService) ResetAppFWLearningData() {} -func (s *AppFWService) ExportAppFWLearningData() {} + var result struct { + Bindings []models.AppFWGlobalAppFWPolicyBinding `json:"appfwglobal_appfwpolicy_binding"` + } -// appfwlearningsettings -// Configuration for learning settings resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwlearningsettings -func (s *AppFWService) UpdateAppFWLearningSettings() {} -func (s *AppFWService) UnsetAppFWLearningSettings() {} -func (s *AppFWService) GetAllAppFWLearningSettings() {} -func (s *AppFWService) GetAppFWLearningSettings() {} -func (s *AppFWService) CountAppFWLearningSettings() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// appfwmultipartformcontenttype -// Configuration for Multipart form content type resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwmultipartformcontenttype -func (s *AppFWService) AddAppFWMultipartFormContentType() {} -func (s *AppFWService) DeleteAppFWMultipartFormContentType() {} -func (s *AppFWService) GetAllAppFWMultipartFormContentType() {} -func (s *AppFWService) GetAppFWMultipartFormContentType() {} -func (s *AppFWService) CountAppFWMultipartFormContentType() {} + return result.Bindings, nil +} -// appfwpolicy -// Configuration for application firewall policy resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwpolicy -func (s *AppFWService) AddAppFWPolicy() {} -func (s *AppFWService) DeleteAppFWPolicy() {} -func (s *AppFWService) UpdateAppFWPolicy() {} -func (s *AppFWService) UnsetAppFWPolicy() {} -func (s *AppFWService) GetAllAppFWPolicy() {} -func (s *AppFWService) GetAppFWPolicy() {} -func (s *AppFWService) CountAppFWPolicy() {} -func (s *AppFWService) RenameAppFWPolicy() {} +func (s *AppFWService) CountAppFWGlobalAppFWPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWGlobalAppFWPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } -// appfwpolicylabel -// Configuration for application firewall policy label resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwpolicylabel -func (s *AppFWService) AddAppFWPolicyLabel() {} -func (s *AppFWService) DeleteAppFWPolicyLabel() {} -func (s *AppFWService) GetAllAppFWPolicyLabel() {} -func (s *AppFWService) GetAppFWPolicyLabel() {} -func (s *AppFWService) CountAppFWPolicyLabel() {} -func (s *AppFWService) RenameAppFWPolicyLabel() {} + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } -// appfwpolicylabel_appfwpolicy_binding -// Binding object showing the appfwpolicy that can be bound to appfwpolicylabel. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwpolicylabel_appfwpolicy_binding -func (s *AppFWService) AddAppFWPolicyLabelAppFWPolicyBinding() {} -func (s *AppFWService) DeleteAppFWPolicyLabelAppFWPolicyBinding() {} -func (s *AppFWService) GetAllAppFWPolicyLabelAppFWPolicyBinding() {} -func (s *AppFWService) GetAppFWPolicyLabelAppFWPolicyBinding() {} -func (s *AppFWService) CountAppFWPolicyLabelAppFWPolicyBinding() {} + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwglobal_appfwpolicy_binding"` + } -// appfwpolicylabel_binding -// Binding object which returns the resources bound to appfwpolicylabel. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwpolicylabel_binding -func (s *AppFWService) GetAllAppFWPolicyLabelBinding() {} -func (s *AppFWService) GetAppFWPolicyLabelBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } -// appfwpolicylabel_policybinding_binding -// Binding object showing the policybinding that can be bound to appfwpolicylabel. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwpolicylabel_policybinding_binding -func (s *AppFWService) GetAllAppFWPolicyLabelPolicyBindingBinding() {} -func (s *AppFWService) GetAppFWPolicyLabelPolicyBindingBinding() {} -func (s *AppFWService) CountAppFWPolicyLabelPolicyBindingBinding() {} + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } -// appfwpolicy_appfwglobal_binding -// Binding object showing the appfwglobal that can be bound to appfwpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwpolicy_appfwglobal_binding -func (s *AppFWService) GetAllAppFWPolicyAppFWGlobalBinding() {} -func (s *AppFWService) GetAppFWPolicyAppFWGlobalBinding() {} -func (s *AppFWService) CountAppFWPolicyAppFWGlobalBinding() {} + return 0, nil +} -// appfwpolicy_appfwpolicylabel_binding -// Binding object showing the appfwpolicylabel that can be bound to appfwpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwpolicy_appfwpolicylabel_binding -func (s *AppFWService) GetAllAppFWPolicyAppFWPolicyLabelBinding() {} -func (s *AppFWService) GetAppFWPolicyAppFWPolicyLabelBinding() {} -func (s *AppFWService) CountAppFWPolicyAppFWPolicyLabelBinding() {} +// appfwglobal_auditnslogpolicy_binding +// Binding object showing the auditnslogpolicy that can be bound to appfwglobal. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwglobal_auditnslogpolicy_binding +func (s *AppFWService) AddAppFWGlobalAuditNSLogPolicyBinding(resource models.AppFWGlobalAuditNSLogPolicyBinding) error { + payload := map[string]any{ + "appfwglobal_auditnslogpolicy_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } -// appfwpolicy_binding -// Binding object which returns the resources bound to appfwpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwpolicy_binding -func (s *AppFWService) GetAllAppFWPolcyBinding() {} -func (s *AppFWService) GetAppFWPolcyBinding() {} + req, err := s.client.NewRequest(http.MethodPost, appFWGlobalAuditNSLogPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } -// appfwpolicy_csvserver_binding -// Binding object showing the csvserver that can be bound to appfwpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwpolicy_csvserver_binding -func (s *AppFWService) GetAllAppFWPolicyCSVServerBinding() {} -func (s *AppFWService) GetAppFWPolicyCSVServerBinding() {} -func (s *AppFWService) CountAppFWPolicyCSVServerBinding() {} + _, err = s.client.Do(req) + return err +} -// appfwpolicy_lbvserver_binding -// Binding object showing the lbvserver that can be bound to appfwpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwpolicy_lbvserver_binding -func (s *AppFWService) GetAllAppFWPolcyLBVServerBinding() {} -func (s *AppFWService) GetAppFWPolcyLBVServerBinding() {} -func (s *AppFWService) CountAppFWPolcyLBVServerBinding() {} +func (s *AppFWService) DeleteAppFWGlobalAuditNSLogPolicyBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWGlobalAuditNSLogPolicyBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } -// appfwprofile -// Configuration for application firewall profile resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile -func (s *AppFWService) AddAppFWProfile() {} -func (s *AppFWService) DeleteAppFWProfile() {} -func (s *AppFWService) UpdateAppFWProfile() {} -func (s *AppFWService) UnsetAppFWProfile() {} -func (s *AppFWService) GetAllAppFWProfile() {} -func (s *AppFWService) GetAppFWProfile() {} -func (s *AppFWService) CountAppFWProfile() {} -func (s *AppFWService) RestoreAppFWProfile() {} + _, err = s.client.Do(req) + return err +} -// appfwprofile_binding -// Binding object which returns the resources bound to appfwprofile. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_binding -func (s *AppFWService) GetAllAppFWProfileBinding() {} -func (s *AppFWService) GetAppFWProfileBinding() {} +func (s *AppFWService) GetAppFWGlobalAuditNSLogPolicyBinding() ([]models.AppFWGlobalAuditNSLogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWGlobalAuditNSLogPolicyBindingURL, nil) + if err != nil { + return nil, err + } -// appfwprofile_cmdinjection_binding -// Binding object showing the cmdinjection that can be bound to appfwprofile. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_cmdinjection_binding -func (s *AppFWService) AddAppFWProfileCMDInjectionBinding() {} -func (s *AppFWService) DeleteAppFWProfileCMDInjectionBinding() {} -func (s *AppFWService) GetAllAppFWProfileCMDInjectionBinding() {} -func (s *AppFWService) GetAppFWProfileCMDInjectionBinding() {} -func (s *AppFWService) CountAppFWProfileCMDInjectionBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// appfwprofile_contenttype_binding -// Binding object showing the contenttype that can be bound to appfwprofile. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_contenttype_binding -func (s *AppFWService) AddAppFWProfileContentypeBinding() {} -func (s *AppFWService) DeleteAppFWProfileContentypeBinding() {} -func (s *AppFWService) GetAllAppFWProfileContentypeBinding() {} -func (s *AppFWService) GetAppFWProfileContentypeBinding() {} -func (s *AppFWService) CountAppFWProfileContentypeBinding() {} + var result struct { + Bindings []models.AppFWGlobalAuditNSLogPolicyBinding `json:"appfwglobal_auditnslogpolicy_binding"` + } -// appfwprofile_cookieconsistency_binding -// Binding object showing the cookieconsistency that can be bound to appfwprofile. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_cookieconsistency_binding -func (s *AppFWService) AddAppFWProfileCookieConsistencyBinding() {} -func (s *AppFWService) DeleteAppFWProfileCookieConsistencyBinding() {} -func (s *AppFWService) GetAllAppFWProfileCookieConsistencyBinding() {} -func (s *AppFWService) GetAppFWProfileCookieConsistencyBinding() {} -func (s *AppFWService) CountAppFWProfileCookieConsistencyBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// appfwprofile_creditcardnumber_binding -// Binding object showing the creditcardnumber that can be bound to appfwprofile. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_creditcardnumber_binding -func (s *AppFWService) AddAppFWProfileCreditCardNumberBinding() {} -func (s *AppFWService) DeleteAppFWProfileCreditCardNumberBinding() {} -func (s *AppFWService) GetAllAppFWProfileCreditCardNumberBinding() {} -func (s *AppFWService) GetAppFWProfileCreditCardNumberBinding() {} -func (s *AppFWService) CountAppFWProfileCreditCardNumberBinding() {} + return result.Bindings, nil +} -// appfwprofile_crosssitescripting_binding -// Binding object showing the crosssitescripting that can be bound to appfwprofile. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_crosssitescripting_binding -func (s *AppFWService) AddAppFWProfileCrossSiteScriptingBinding() {} -func (s *AppFWService) DeleteAppFWProfileCrossSiteScriptingBinding() {} -func (s *AppFWService) GetAllAppFWProfileCrossSiteScriptingBinding() {} -func (s *AppFWService) GetAppFWProfileCrossSiteScriptingBinding() {} -func (s *AppFWService) CountAppFWProfileCrossSiteScriptingBinding() {} +func (s *AppFWService) CountAppFWGlobalAuditNSLogPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWGlobalAuditNSLogPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } -// appfwprofile_csrftag_binding -// Binding object showing the csrftag that can be bound to appfwprofile. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_csrftag_binding -func (s *AppFWService) AddAppFWProfileCSRFTagBinding() {} -func (s *AppFWService) DeleteAppFWProfileCSRFTagBinding() {} -func (s *AppFWService) GetAllAppFWProfileCSRFTagBinding() {} -func (s *AppFWService) GetAppFWProfileCSRFTagBinding() {} -func (s *AppFWService) CountAppFWProfileCSRFTagBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } -// appfwprofile_denyurl_binding -// Binding object showing the denyurl that can be bound to appfwprofile. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_denyurl_binding -func (s *AppFWService) AddAppFWProfileDenyURLBinding() {} -func (s *AppFWService) DeleteAppFWProfileDenyURLBinding() {} -func (s *AppFWService) GetAllAppFWProfileDenyURLBinding() {} -func (s *AppFWService) GetAppFWProfileDenyURLBinding() {} -func (s *AppFWService) CountAppFWProfileDenyURLBinding() {} + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwglobal_auditnslogpolicy_binding"` + } -// appfwprofile_excluderescontenttype_binding -// Binding object showing the excluderescontenttype that can be bound to appfwprofile. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_excluderescontenttype_binding -func (s *AppFWService) AddAppFWProfileExcludeRESContentTypeBinding() {} -func (s *AppFWService) DeleteAppFWProfileExcludeRESContentTypeBinding() {} -func (s *AppFWService) GetAllAppFWProfileExcludeRESContentTypeBinding() {} -func (s *AppFWService) GetAppFWProfileExcludeRESContentTypeBinding() {} -func (s *AppFWService) CountAppFWProfileExcludeRESContentTypeBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } -// appfwprofile_fieldconsistency_binding -// Binding object showing the fieldconsistency that can be bound to appfwprofile. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_fieldconsistency_binding -func (s *AppFWService) AddAppFWProfileFieldConsistencyBinding() {} -func (s *AppFWService) DeleteAppFWProfileFieldConsistencyBinding() {} -func (s *AppFWService) GetAllAppFWProfileFieldConsistencyBinding() {} -func (s *AppFWService) GetAppFWProfileFieldConsistencyBinding() {} -func (s *AppFWService) CountAppFWProfileFieldConsistencyBinding() {} + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } -// appfwprofile_fieldformat_binding -// Binding object showing the fieldformat that can be bound to appfwprofile. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_fieldformat_binding -func (s *AppFWService) AddAppFWProfileFieldFormatBinding() {} -func (s *AppFWService) DeleteAppFWProfileFieldFormatBinding() {} -func (s *AppFWService) GetAllAppFWProfileFieldFormatBinding() {} -func (s *AppFWService) GetAppFWProfileFieldFormatBinding() {} -func (s *AppFWService) CountAppFWProfileFieldFormatBinding() {} + return 0, nil +} -// appfwprofile_fileuploadtype_binding -// Binding object showing the fileuploadtype that can be bound to appfwprofile. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_fileuploadtype_binding -func (s *AppFWService) AddAppFWProfileFielUploadTypeBinding() {} -func (s *AppFWService) DeleteAppFWProfileFielUploadTypeBinding() {} -func (s *AppFWService) GetAllAppFWProfileFielUploadTypeBinding() {} -func (s *AppFWService) GetAppFWProfileFielUploadTypeBinding() {} -func (s *AppFWService) CountAppFWProfileFielUploadTypeBinding() {} +// appfwglobal_audtisyslogpolicy_binding +// Binding object showing the auditsyslogpolicy that can be bound to appfwglobal. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwglobal_auditsyslogpolicy_binding +func (s *AppFWService) AddAppFWGlobalAuditSyslogPolicyBinding(resource models.AppFWGlobalAuditSyslogPolicyBinding) error { + payload := map[string]any{ + "appfwglobal_auditsyslogpolicy_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } -// appfwprofile_jsondosurl_binding -// Binding object showing the jsondosurl that can be bound to appfwprofile. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_jsondosurl_binding -func (s *AppFWService) AddAppFWProfileJSONDOSURLBinding() {} -func (s *AppFWService) DeleteAppFWProfileJSONDOSURLBinding() {} -func (s *AppFWService) GetAllAppFWProfileJSONDOSURLBinding() {} -func (s *AppFWService) GetAppFWProfileJSONDOSURLBinding() {} -func (s *AppFWService) CountAppFWProfileJSONDOSURLBinding() {} + req, err := s.client.NewRequest(http.MethodPost, appFWGlobalAuditSyslogPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } -// appfwprofile_jsonsqlurl_binding -// Binding object showing the jsonsqlurl that can be bound to appfwprofile. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_jsonsqlurl_binding -func (s *AppFWService) AddAppFWProfileJSONSQLURLBinding() {} -func (s *AppFWService) DeleteAppFWProfileJSONSQLURLBinding() {} -func (s *AppFWService) GetAllAppFWProfileJSONSQLURLBinding() {} -func (s *AppFWService) GetAppFWProfileJSONSQLURLBinding() {} -func (s *AppFWService) CountAppFWProfileJSONSQLURLBinding() {} + _, err = s.client.Do(req) + return err +} -// appfwprofile_jsonxssurl_binding -// Binding object showing the jsonxssurl that can be bound to appfwprofile. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_jsonxssurl_binding -func (s *AppFWService) AddAppFWProfileJSONXSSURLBinding() {} -func (s *AppFWService) DeleteAppFWProfileJSONXSSURLBinding() {} -func (s *AppFWService) GetAllAppFWProfileJSONXSSURLBinding() {} -func (s *AppFWService) GetAppFWProfileJSONXSSURLBinding() {} -func (s *AppFWService) CountAppFWProfileJSONXSSURLBinding() {} +func (s *AppFWService) DeleteAppFWGlobalAuditSyslogPolicyBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWGlobalAuditSyslogPolicyBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } -// appfwprofile_logexpression_binding -// Binding object showing the logexpression that can be bound to appfwprofile. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_logexpression_binding -func (s *AppFWService) AddAppFWProfileLogExpressionBinding() {} -func (s *AppFWService) DeleteAppFWProfileLogExpressionBinding() {} -func (s *AppFWService) GetAllAppFWProfileLogExpressionBinding() {} -func (s *AppFWService) GetAppFWProfileLogExpressionBinding() {} -func (s *AppFWService) CountAppFWProfileLogExpressionBinding() {} + _, err = s.client.Do(req) + return err +} -// appfwprofile_safeobject_binding -// Binding object showing the safeobject that can be bound to appfwprofile. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_safeobject_binding -func (s *AppFWService) AddAppFWProfileSafeObjectBinding() {} -func (s *AppFWService) DeleteAppFWProfileSafeObjectBinding() {} -func (s *AppFWService) GetAllAppFWProfileSafeObjectBinding() {} -func (s *AppFWService) GetAppFWProfileSafeObjectBinding() {} -func (s *AppFWService) CountAppFWProfileSafeObjectBinding() {} +func (s *AppFWService) GetAppFWGlobalAuditSyslogPolicyBinding() ([]models.AppFWGlobalAuditSyslogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWGlobalAuditSyslogPolicyBindingURL, nil) + if err != nil { + return nil, err + } -// appfwprofile_sqlinjection_binding -// Binding object showing the sqlinjection that can be bound to appfwprofile. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_sqlinjection_binding -func (s *AppFWService) AddAppFWProfileSQLInjectionBinding() {} -func (s *AppFWService) DeleteAppFWProfileSQLInjectionBinding() {} -func (s *AppFWService) GetAllAppFWProfileSQLInjectionBinding() {} -func (s *AppFWService) GetAppFWProfileSQLInjectionBinding() {} -func (s *AppFWService) CountAppFWProfileSQLInjectionBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// appfwprofile_starturl_binding -// Binding object showing the starturl that can be bound to appfwprofile. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_starturl_binding -func (s *AppFWService) AddAppFWProfileStartURLBinding() {} -func (s *AppFWService) DeleteAppFWProfileStartURLBinding() {} -func (s *AppFWService) GetAllAppFWProfileStartURLBinding() {} -func (s *AppFWService) GetAppFWProfileStartURLBinding() {} -func (s *AppFWService) CountAppFWProfileStartURLBinding() {} + var result struct { + Bindings []models.AppFWGlobalAuditSyslogPolicyBinding `json:"appfwglobal_auditsyslogpolicy_binding"` + } -// appfwprofile_trustedlearningclients_binding -// Binding object showing the trustedlearningclients that can be bound to appfwprofile. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_trustedlearningclients_binding -func (s *AppFWService) AddAppFWProfileTrustedLearningClientsBinding() {} -func (s *AppFWService) DeleteAppFWProfileTrustedLearningClientsBinding() {} -func (s *AppFWService) GetAllAppFWProfileTrustedLearningClientsBinding() {} -func (s *AppFWService) GetAppFWProfileTrustedLearningClientsBinding() {} -func (s *AppFWService) CountAppFWProfileTrustedLearningClientsBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// appfwprofile_xmlattachmenturl_binding -// Binding object showing the xmlattachmenturl that can be bound to appfwprofile. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_xmlattachmenturl_binding -func (s *AppFWService) AddAppFWProfileXMLAttachmentURLBinding() {} -func (s *AppFWService) DeleteAppFWProfileXMLAttachmentURLBinding() {} -func (s *AppFWService) GetAllAppFWProfileXMLAttachmentURLBinding() {} -func (s *AppFWService) GetAppFWProfileXMLAttachmentURLBinding() {} -func (s *AppFWService) CountAppFWProfileXMLAttachmentURLBinding() {} + return result.Bindings, nil +} -// appfwprofile_xmldosurl_binding -// Binding object showing the xmldosurl that can be bound to appfwprofile. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_xmldosurl_binding -func (s *AppFWService) AddAppFWProfileXMLDOSURLBinding() {} -func (s *AppFWService) DeleteAppFWProfileXMLDOSURLBinding() {} -func (s *AppFWService) GetAllAppFWProfileXMLDOSURLBinding() {} -func (s *AppFWService) GetAppFWProfileXMLDOSURLBinding() {} -func (s *AppFWService) CountAppFWProfileXMLDOSURLBinding() {} +func (s *AppFWService) CountAppFWGlobalAuditSyslogPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWGlobalAuditSyslogPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } -// appfwprofile_xmlsqlinjection_binding -// Binding object showing the xmlsqlinjection that can be bound to appfwprofile. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_xmlsqlinjection_binding -func (s *AppFWService) AddAppFWProfileXMLSQLInjectionBinding() {} -func (s *AppFWService) DeleteAppFWProfileXMLSQLInjectionBinding() {} -func (s *AppFWService) GetAllAppFWProfileXMLSQLInjectionBinding() {} -func (s *AppFWService) GetAppFWProfileXMLSQLInjectionBinding() {} -func (s *AppFWService) CountAppFWProfileXMLSQLInjectionBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } -// appfwprofile_xmlvalidationurl_binding -// Binding object showing the xmlvalidationurl that can be bound to appfwprofile. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_xmlvalidationurl_binding -func (s *AppFWService) AddAppFWProfileXMLValidationURLBinding() {} -func (s *AppFWService) DeleteAppFWProfileXMLValidationURLBinding() {} -func (s *AppFWService) GetAllAppFWProfileXMLValidationURLBinding() {} -func (s *AppFWService) GetAppFWProfileXMLValidationURLBinding() {} -func (s *AppFWService) CountAppFWProfileXMLValidationURLBinding() {} + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwglobal_auditsyslogpolicy_binding"` + } -// appfwprofile_xmlwsiurl_binding -// Binding object showing the xmlwsiurl that can be bound to appfwprofile. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_xmlwsiurl_binding -func (s *AppFWService) AddAppFWProfileXMLWSIURLBinding() {} -func (s *AppFWService) DeleteAppFWProfileXMLWSIURLBinding() {} -func (s *AppFWService) GetAllAppFWProfileXMLWSIURLBinding() {} -func (s *AppFWService) GetAppFWProfileXMLWSIURLBinding() {} -func (s *AppFWService) CountAppFWProfileXMLWSIURLBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } -// appfwprofile_xmlxss_binding -// Binding object showing the xmlxss that can be bound to appfwprofile. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_xmlxss_binding -func (s *AppFWService) AddAppFWProfileXMLXSSBinding() {} -func (s *AppFWService) DeleteAppFWProfileXMLXSSBinding() {} -func (s *AppFWService) GetAllAppFWProfileXMLXSSBinding() {} -func (s *AppFWService) GetAppFWProfileXMLXSSBinding() {} -func (s *AppFWService) CountAppFWProfileXMLXSSBinding() {} + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } -// appfwsettings -// Configuration for AS settings resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwsettings -func (s *AppFWService) UpdateAppFWSettings() {} -func (s *AppFWService) UnsetAppFWSettings() {} -func (s *AppFWService) GetAllAppFWSettings() {} + return 0, nil +} -// appfwsignatures -// Configuration for application firewall signatures XML configuration resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwsignatures -func (s *AppFWService) DeleteAppFWSignatures() {} -func (s *AppFWService) GetAllAppFWSignatures() {} -func (s *AppFWService) GetAppFWSignatures() {} -func (s *AppFWService) ImportAppFWSignatures() {} -func (s *AppFWService) ChangeAppFWSignatures() {} +// appfwglobal_binding +// Binding object which returns the resources bound to appfwglobal. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwglobal_binding +func (s *AppFWService) GetAppFWGlobalBinding() (*models.AppFWGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWGlobalBindingURL, nil) + if err != nil { + return nil, err + } -// appfwtransactionrecords -// Configuration for Application firewall transaction record resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwtransactionrecords -func (s *AppFWService) GetAllAppFWTransactionRecords() {} -func (s *AppFWService) CountAppFWTransactionRecords() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// appfwurlencodedformcontenttype -// Configuration for Urlencoded form content type resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwurlencodedformcontenttype -func (s *AppFWService) AddAppFWURLEncodedFormContentType() {} -func (s *AppFWService) DeleteAppFWURLEncodedFormContentType() {} -func (s *AppFWService) GetAllAppFWURLEncodedFormContentType() {} -func (s *AppFWService) GetAppFWURLEncodedFormContentType() {} -func (s *AppFWService) CountAppFWURLEncodedFormContentType() {} + var result struct { + Bindings []models.AppFWGlobalBinding `json:"appfwglobal_binding"` + } -// appfwwsdl -// Configuration for WSDL file resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwwsdl -func (s *AppFWService) DeleteAppFWWSDL() {} -func (s *AppFWService) GetAllAppFWWSDL() {} -func (s *AppFWService) GetAppFWWSDL() {} -func (s *AppFWService) ImportAppFWWSDL() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// appfwxmlcontenttype -// Configuration for XML Content type resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwxmlcontenttype -func (s *AppFWService) AddAppFWXMLContentType() {} -func (s *AppFWService) DeleteAppFWXMLContentType() {} -func (s *AppFWService) GetAllAppFWXMLContentType() {} -func (s *AppFWService) GetAppFWXMLContentType() {} -func (s *AppFWService) CountAppFWXMLContentType() {} + if len(result.Bindings) == 0 { + return nil, fmt.Errorf("appfwglobal_binding not found") + } + + return &result.Bindings[0], nil +} + +// appfwhtmlerrorpage +// Configuration for HTML error page resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwhtmlerrorpage +func (s *AppFWService) DeleteAppFWHTMLErrorPage(name string) error { + reqURL := fmt.Sprintf("%s/%s", appFWHTMLErrorPageURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWHTMLErrorPage() ([]models.AppFWHTMLErrorPage, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWHTMLErrorPageURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Pages []models.AppFWHTMLErrorPage `json:"appfwhtmlerrorpage"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Pages, nil +} + +func (s *AppFWService) GetAppFWHTMLErrorPage(name string) (*models.AppFWHTMLErrorPage, error) { + reqURL := fmt.Sprintf("%s/%s", appFWHTMLErrorPageURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Pages []models.AppFWHTMLErrorPage `json:"appfwhtmlerrorpage"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Pages) == 0 { + return nil, fmt.Errorf("appfwhtmlerrorpage not found") + } + + return &result.Pages[0], nil +} + +func (s *AppFWService) ImportAppFWHTMLErrorPage(resource models.AppFWHTMLErrorPage) error { + payload := map[string]any{ + "appfwhtmlerrorpage": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWHTMLErrorPageURL+"?action=Import", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) ChangeAppFWHTMLErrorPage(resource models.AppFWHTMLErrorPage) error { + payload := map[string]any{ + "appfwhtmlerrorpage": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWHTMLErrorPageURL+"?action=change", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// appfwjsoncontenttype +// Configuration for JSON content type resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwjsoncontenttype +func (s *AppFWService) AddAppFWJSONContentType(resource models.AppFWJSONContentType) error { + payload := map[string]any{ + "appfwjsoncontenttype": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWJSONContentTypeURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWJSONContentType(name string) error { + reqURL := fmt.Sprintf("%s/%s", appFWJSONContentTypeURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWJSONContentType() ([]models.AppFWJSONContentType, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWJSONContentTypeURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Types []models.AppFWJSONContentType `json:"appfwjsoncontenttype"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Types, nil +} + +func (s *AppFWService) GetAppFWJSONContentType(name string) (*models.AppFWJSONContentType, error) { + reqURL := fmt.Sprintf("%s/%s", appFWJSONContentTypeURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Types []models.AppFWJSONContentType `json:"appfwjsoncontenttype"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Types) == 0 { + return nil, fmt.Errorf("appfwjsoncontenttype not found") + } + + return &result.Types[0], nil +} + +func (s *AppFWService) CountAppFWJSONContentType() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWJSONContentTypeURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Types []struct { + Count float64 `json:"__count"` + } `json:"appfwjsoncontenttype"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Types) > 0 { + return result.Types[0].Count, nil + } + + return 0, nil +} + +// appfwjsonerrorpage +// Configuration for JSON error page resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwjsonerrorpage +func (s *AppFWService) DeleteAppFWJSONErrorPage(name string) error { + reqURL := fmt.Sprintf("%s/%s", appFWJSONErrorPageURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWJSONErrorPage() ([]models.AppFWJSONErrorPage, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWJSONErrorPageURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Pages []models.AppFWJSONErrorPage `json:"appfwjsonerrorpage"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Pages, nil +} + +func (s *AppFWService) GetAppFWJSONErrorPage(name string) (*models.AppFWJSONErrorPage, error) { + reqURL := fmt.Sprintf("%s/%s", appFWJSONErrorPageURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Pages []models.AppFWJSONErrorPage `json:"appfwjsonerrorpage"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Pages) == 0 { + return nil, fmt.Errorf("appfwjsonerrorpage not found") + } + + return &result.Pages[0], nil +} + +func (s *AppFWService) ImportAppFWJSONErrorPage(resource models.AppFWJSONErrorPage) error { + payload := map[string]any{ + "appfwjsonerrorpage": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWJSONErrorPageURL+"?action=Import", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) ChangeAppFWJSONErrorPage(resource models.AppFWJSONErrorPage) error { + payload := map[string]any{ + "appfwjsonerrorpage": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWJSONErrorPageURL+"?action=change", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// appfwlearningdata +// Configuration for learning data resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwlearningdata +func (s *AppFWService) DeleteAppFWLearningData(name string) error { + reqURL := fmt.Sprintf("%s/%s", appFWLearningDataURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWLearningData() ([]models.AppFWLearningData, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWLearningDataURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AppFWLearningData `json:"appfwlearningdata"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *AppFWService) CountAppFWLearningData() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWLearningDataURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []struct { + Count float64 `json:"__count"` + } `json:"appfwlearningdata"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return result.Data[0].Count, nil + } + + return 0, nil +} + +func (s *AppFWService) ResetAppFWLearningData(resource models.AppFWLearningData) error { + payload := map[string]any{ + "appfwlearningdata": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWLearningDataURL+"?action=reset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) ExportAppFWLearningData(resource models.AppFWLearningData) error { + payload := map[string]any{ + "appfwlearningdata": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWLearningDataURL+"?action=export", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// appfwlearningsettings +// Configuration for learning settings resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwlearningsettings +func (s *AppFWService) UpdateAppFWLearningSettings(resource models.AppFWLearningSettings) error { + payload := map[string]any{ + "appfwlearningsettings": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, appFWLearningSettingsURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) UnsetAppFWLearningSettings(resource models.AppFWLearningSettings) error { + payload := map[string]any{ + "appfwlearningsettings": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWLearningSettingsURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWLearningSettings() ([]models.AppFWLearningSettings, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWLearningSettingsURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Settings []models.AppFWLearningSettings `json:"appfwlearningsettings"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Settings, nil +} + +func (s *AppFWService) GetAppFWLearningSettings(name string) (*models.AppFWLearningSettings, error) { + reqURL := fmt.Sprintf("%s/%s", appFWLearningSettingsURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Settings []models.AppFWLearningSettings `json:"appfwlearningsettings"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Settings) == 0 { + return nil, fmt.Errorf("appfwlearningsettings not found") + } + + return &result.Settings[0], nil +} + +func (s *AppFWService) CountAppFWLearningSettings() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWLearningSettingsURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Settings []struct { + Count float64 `json:"__count"` + } `json:"appfwlearningsettings"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Settings) > 0 { + return result.Settings[0].Count, nil + } + + return 0, nil +} + +// appfwmultipartformcontenttype +// Configuration for Multipart form content type resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwmultipartformcontenttype +func (s *AppFWService) AddAppFWMultipartFormContentType(resource models.AppFWMultipartFormContentType) error { + payload := map[string]any{ + "appfwmultipartformcontenttype": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWMultipartFormContentTypeURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWMultipartFormContentType(name string) error { + reqURL := fmt.Sprintf("%s/%s", appFWMultipartFormContentTypeURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWMultipartFormContentType() ([]models.AppFWMultipartFormContentType, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWMultipartFormContentTypeURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Types []models.AppFWMultipartFormContentType `json:"appfwmultipartformcontenttype"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Types, nil +} + +func (s *AppFWService) GetAppFWMultipartFormContentType(name string) (*models.AppFWMultipartFormContentType, error) { + reqURL := fmt.Sprintf("%s/%s", appFWMultipartFormContentTypeURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Types []models.AppFWMultipartFormContentType `json:"appfwmultipartformcontenttype"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Types) == 0 { + return nil, fmt.Errorf("appfwmultipartformcontenttype not found") + } + + return &result.Types[0], nil +} + +func (s *AppFWService) CountAppFWMultipartFormContentType() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWMultipartFormContentTypeURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Types []struct { + Count float64 `json:"__count"` + } `json:"appfwmultipartformcontenttype"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Types) > 0 { + return result.Types[0].Count, nil + } + + return 0, nil +} + +// appfwpolicy +// Configuration for application firewall policy resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwpolicy +func (s *AppFWService) AddAppFWPolicy(resource models.AppFWPolicy) error { + payload := map[string]any{ + "appfwpolicy": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWPolicy(name string) error { + reqURL := fmt.Sprintf("%s/%s", appFWPolicyURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) UpdateAppFWPolicy(resource models.AppFWPolicy) error { + payload := map[string]any{ + "appfwpolicy": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, appFWPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) UnsetAppFWPolicy(resource models.AppFWPolicy) error { + payload := map[string]any{ + "appfwpolicy": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWPolicyURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWPolicy() ([]models.AppFWPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWPolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Policies []models.AppFWPolicy `json:"appfwpolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Policies, nil +} + +func (s *AppFWService) GetAppFWPolicy(name string) (*models.AppFWPolicy, error) { + reqURL := fmt.Sprintf("%s/%s", appFWPolicyURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Policies []models.AppFWPolicy `json:"appfwpolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Policies) == 0 { + return nil, fmt.Errorf("appfwpolicy not found") + } + + return &result.Policies[0], nil +} + +func (s *AppFWService) CountAppFWPolicy() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWPolicyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Policies []struct { + Count float64 `json:"__count"` + } `json:"appfwpolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Policies) > 0 { + return result.Policies[0].Count, nil + } + + return 0, nil +} + +func (s *AppFWService) RenameAppFWPolicy(resource models.AppFWPolicy) error { + payload := map[string]any{ + "appfwpolicy": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWPolicyURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// appfwpolicylabel +// Configuration for application firewall policy label resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwpolicylabel +func (s *AppFWService) AddAppFWPolicyLabel(resource models.AppFWPolicyLabel) error { + payload := map[string]any{ + "appfwpolicylabel": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWPolicyLabelURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWPolicyLabel(name string) error { + reqURL := fmt.Sprintf("%s/%s", appFWPolicyLabelURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWPolicyLabel() ([]models.AppFWPolicyLabel, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWPolicyLabelURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Labels []models.AppFWPolicyLabel `json:"appfwpolicylabel"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Labels, nil +} + +func (s *AppFWService) GetAppFWPolicyLabel(name string) (*models.AppFWPolicyLabel, error) { + reqURL := fmt.Sprintf("%s/%s", appFWPolicyLabelURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Labels []models.AppFWPolicyLabel `json:"appfwpolicylabel"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Labels) == 0 { + return nil, fmt.Errorf("appfwpolicylabel not found") + } + + return &result.Labels[0], nil +} + +func (s *AppFWService) CountAppFWPolicyLabel() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWPolicyLabelURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Labels []struct { + Count float64 `json:"__count"` + } `json:"appfwpolicylabel"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Labels) > 0 { + return result.Labels[0].Count, nil + } + + return 0, nil +} + +func (s *AppFWService) RenameAppFWPolicyLabel(resource models.AppFWPolicyLabel) error { + payload := map[string]any{ + "appfwpolicylabel": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWPolicyLabelURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// appfwpolicylabel_appfwpolicy_binding +// Binding object showing the appfwpolicy that can be bound to appfwpolicylabel. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwpolicylabel_appfwpolicy_binding +func (s *AppFWService) AddAppFWPolicyLabelAppFWPolicyBinding(resource models.AppFWPolicyLabelAppFWPolicyBinding) error { + payload := map[string]any{ + "appfwpolicylabel_appfwpolicy_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWPolicyLabelAppFWPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWPolicyLabelAppFWPolicyBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWPolicyLabelAppFWPolicyBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWPolicyLabelAppFWPolicyBinding() ([]models.AppFWPolicyLabelAppFWPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWPolicyLabelAppFWPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWPolicyLabelAppFWPolicyBinding `json:"appfwpolicylabel_appfwpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWPolicyLabelAppFWPolicyBinding(name string) ([]models.AppFWPolicyLabelAppFWPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWPolicyLabelAppFWPolicyBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWPolicyLabelAppFWPolicyBinding `json:"appfwpolicylabel_appfwpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWPolicyLabelAppFWPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWPolicyLabelAppFWPolicyBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwpolicylabel_appfwpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwpolicylabel_binding +// Binding object which returns the resources bound to appfwpolicylabel. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwpolicylabel_binding +func (s *AppFWService) GetAllAppFWPolicyLabelBinding() ([]models.AppFWPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWPolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWPolicyLabelBinding `json:"appfwpolicylabel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWPolicyLabelBinding(name string) (*models.AppFWPolicyLabelBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWPolicyLabelBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWPolicyLabelBinding `json:"appfwpolicylabel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) == 0 { + return nil, fmt.Errorf("appfwpolicylabel_binding not found") + } + + return &result.Bindings[0], nil +} + +// appfwpolicylabel_policybinding_binding +// Binding object showing the policybinding that can be bound to appfwpolicylabel. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwpolicylabel_policybinding_binding +func (s *AppFWService) GetAllAppFWPolicyLabelPolicyBindingBinding() ([]models.AppFWPolicyLabelPolicyBindingBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWPolicyLabelPolicyBindingBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWPolicyLabelPolicyBindingBinding `json:"appfwpolicylabel_policybinding_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWPolicyLabelPolicyBindingBinding(name string) ([]models.AppFWPolicyLabelPolicyBindingBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWPolicyLabelPolicyBindingBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWPolicyLabelPolicyBindingBinding `json:"appfwpolicylabel_policybinding_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWPolicyLabelPolicyBindingBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWPolicyLabelPolicyBindingBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwpolicylabel_policybinding_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwpolicy_appfwglobal_binding +// Binding object showing the appfwglobal that can be bound to appfwpolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwpolicy_appfwglobal_binding +func (s *AppFWService) GetAllAppFWPolicyAppFWGlobalBinding() ([]models.AppFWPolicyAppFWGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWPolicyAppFWGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWPolicyAppFWGlobalBinding `json:"appfwpolicy_appfwglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWPolicyAppFWGlobalBinding(name string) ([]models.AppFWPolicyAppFWGlobalBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWPolicyAppFWGlobalBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWPolicyAppFWGlobalBinding `json:"appfwpolicy_appfwglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWPolicyAppFWGlobalBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWPolicyAppFWGlobalBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwpolicy_appfwglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwpolicy_appfwpolicylabel_binding +// Binding object showing the appfwpolicylabel that can be bound to appfwpolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwpolicy_appfwpolicylabel_binding +func (s *AppFWService) GetAllAppFWPolicyAppFWPolicyLabelBinding() ([]models.AppFWPolicyAppFWPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWPolicyAppFWPolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWPolicyAppFWPolicyLabelBinding `json:"appfwpolicy_appfwpolicylabel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWPolicyAppFWPolicyLabelBinding(name string) ([]models.AppFWPolicyAppFWPolicyLabelBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWPolicyAppFWPolicyLabelBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWPolicyAppFWPolicyLabelBinding `json:"appfwpolicy_appfwpolicylabel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWPolicyAppFWPolicyLabelBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWPolicyAppFWPolicyLabelBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwpolicy_appfwpolicylabel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwpolicy_binding +// Binding object which returns the resources bound to appfwpolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwpolicy_binding +func (s *AppFWService) GetAllAppFWPolicyBinding() ([]models.AppFWPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWPolicyBinding `json:"appfwpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWPolicyBinding(name string) (*models.AppFWPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWPolicyBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWPolicyBinding `json:"appfwpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) == 0 { + return nil, fmt.Errorf("appfwpolicy_binding not found") + } + + return &result.Bindings[0], nil +} + +// appfwpolicy_csvserver_binding +// Binding object showing the csvserver that can be bound to appfwpolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwpolicy_csvserver_binding +func (s *AppFWService) GetAllAppFWPolicyCSVServerBinding() ([]models.AppFWPolicyCSVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWPolicyCSVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWPolicyCSVServerBinding `json:"appfwpolicy_csvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWPolicyCSVServerBinding(name string) ([]models.AppFWPolicyCSVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWPolicyCSVServerBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWPolicyCSVServerBinding `json:"appfwpolicy_csvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWPolicyCSVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWPolicyCSVServerBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwpolicy_csvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwpolicy_lbvserver_binding +// Binding object showing the lbvserver that can be bound to appfwpolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwpolicy_lbvserver_binding +func (s *AppFWService) GetAllAppFWPolicyLBVServerBinding() ([]models.AppFWPolicyLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWPolicyLBVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWPolicyLBVServerBinding `json:"appfwpolicy_lbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWPolicyLBVServerBinding(name string) ([]models.AppFWPolicyLBVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWPolicyLBVServerBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWPolicyLBVServerBinding `json:"appfwpolicy_lbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWPolicyLBVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWPolicyLBVServerBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwpolicy_lbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwprofile +// Configuration for application firewall profile resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile +func (s *AppFWService) AddAppFWProfile(resource models.AppFWProfile) error { + payload := map[string]interface{}{ + "appfwprofile": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWProfile(name string) error { + reqURL := fmt.Sprintf("%s/%s", appFWProfileURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) UpdateAppFWProfile(resource models.AppFWProfile) error { + payload := map[string]interface{}{ + "appfwprofile": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, appFWProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) UnsetAppFWProfile(resource models.AppFWProfile) error { + payload := map[string]interface{}{ + "appfwprofile": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWProfile() ([]models.AppFWProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Profiles []models.AppFWProfile `json:"appfwprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Profiles, nil +} + +func (s *AppFWService) GetAppFWProfile(name string) (*models.AppFWProfile, error) { + reqURL := fmt.Sprintf("%s/%s", appFWProfileURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Profiles []models.AppFWProfile `json:"appfwprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Profiles) == 0 { + return nil, fmt.Errorf("appfwprofile not found") + } + + return &result.Profiles[0], nil +} + +func (s *AppFWService) CountAppFWProfile() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Profiles []struct { + Count float64 `json:"__count"` + } `json:"appfwprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Profiles) > 0 { + return result.Profiles[0].Count, nil + } + + return 0, nil +} + +func (s *AppFWService) RestoreAppFWProfile(resource models.AppFWProfile) error { + payload := map[string]interface{}{ + "appfwprofile": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileURL+"?action=restore", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// appfwprofile_binding +// Binding object which returns the resources bound to appfwprofile. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_binding +func (s *AppFWService) GetAllAppFWProfileBinding() ([]models.AppFWProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileBinding `json:"appfwprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWProfileBinding(name string) (*models.AppFWProfileBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWProfileBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileBinding `json:"appfwprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) == 0 { + return nil, fmt.Errorf("appfwprofile_binding not found") + } + + return &result.Bindings[0], nil +} + +// appfwprofile_cmdinjection_binding +// Binding object showing the cmdinjection that can be bound to appfwprofile. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_cmdinjection_binding +func (s *AppFWService) AddAppFWProfileCMDInjectionBinding(resource models.AppFWProfileCMDInjectionBinding) error { + payload := map[string]interface{}{ + "appfwprofile_cmdinjection_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileCMDInjectionBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWProfileCMDInjectionBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWProfileCMDInjectionBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWProfileCMDInjectionBinding() ([]models.AppFWProfileCMDInjectionBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileCMDInjectionBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileCMDInjectionBinding `json:"appfwprofile_cmdinjection_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWProfileCMDInjectionBinding(name string) ([]models.AppFWProfileCMDInjectionBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWProfileCMDInjectionBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileCMDInjectionBinding `json:"appfwprofile_cmdinjection_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWProfileCMDInjectionBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWProfileCMDInjectionBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwprofile_cmdinjection_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwprofile_contenttype_binding +// Binding object showing the contenttype that can be bound to appfwprofile. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_contenttype_binding +func (s *AppFWService) AddAppFWProfileContentTypeBinding(resource models.AppFWProfileContentTypeBinding) error { + payload := map[string]interface{}{ + "appfwprofile_contenttype_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileContentTypeBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWProfileContentTypeBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWProfileContentTypeBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWProfileContentTypeBinding() ([]models.AppFWProfileContentTypeBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileContentTypeBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileContentTypeBinding `json:"appfwprofile_contenttype_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWProfileContentTypeBinding(name string) ([]models.AppFWProfileContentTypeBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWProfileContentTypeBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileContentTypeBinding `json:"appfwprofile_contenttype_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWProfileContentTypeBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWProfileContentTypeBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwprofile_contenttype_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwprofile_cookieconsistency_binding +// Binding object showing the cookieconsistency that can be bound to appfwprofile. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_cookieconsistency_binding +func (s *AppFWService) AddAppFWProfileCookieConsistencyBinding(resource models.AppFWProfileCookieConsistencyBinding) error { + payload := map[string]interface{}{ + "appfwprofile_cookieconsistency_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileCookieConsistencyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWProfileCookieConsistencyBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWProfileCookieConsistencyBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWProfileCookieConsistencyBinding() ([]models.AppFWProfileCookieConsistencyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileCookieConsistencyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileCookieConsistencyBinding `json:"appfwprofile_cookieconsistency_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWProfileCookieConsistencyBinding(name string) ([]models.AppFWProfileCookieConsistencyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWProfileCookieConsistencyBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileCookieConsistencyBinding `json:"appfwprofile_cookieconsistency_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWProfileCookieConsistencyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWProfileCookieConsistencyBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwprofile_cookieconsistency_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwprofile_creditcardnumber_binding +// Binding object showing the creditcardnumber that can be bound to appfwprofile. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_creditcardnumber_binding +func (s *AppFWService) AddAppFWProfileCreditCardNumberBinding(resource models.AppFWProfileCreditCardNumberBinding) error { + payload := map[string]interface{}{ + "appfwprofile_creditcardnumber_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileCreditCardNumberBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWProfileCreditCardNumberBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWProfileCreditCardNumberBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWProfileCreditCardNumberBinding() ([]models.AppFWProfileCreditCardNumberBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileCreditCardNumberBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileCreditCardNumberBinding `json:"appfwprofile_creditcardnumber_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWProfileCreditCardNumberBinding(name string) ([]models.AppFWProfileCreditCardNumberBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWProfileCreditCardNumberBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileCreditCardNumberBinding `json:"appfwprofile_creditcardnumber_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWProfileCreditCardNumberBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWProfileCreditCardNumberBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwprofile_creditcardnumber_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwprofile_crosssitescripting_binding +// Binding object showing the crosssitescripting that can be bound to appfwprofile. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_crosssitescripting_binding +func (s *AppFWService) AddAppFWProfileCrossSiteScriptingBinding(resource models.AppFWProfileCrossSiteScriptingBinding) error { + payload := map[string]interface{}{ + "appfwprofile_crosssitescripting_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileCrossSiteScriptingBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWProfileCrossSiteScriptingBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWProfileCrossSiteScriptingBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWProfileCrossSiteScriptingBinding() ([]models.AppFWProfileCrossSiteScriptingBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileCrossSiteScriptingBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileCrossSiteScriptingBinding `json:"appfwprofile_crosssitescripting_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWProfileCrossSiteScriptingBinding(name string) ([]models.AppFWProfileCrossSiteScriptingBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWProfileCrossSiteScriptingBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileCrossSiteScriptingBinding `json:"appfwprofile_crosssitescripting_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWProfileCrossSiteScriptingBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWProfileCrossSiteScriptingBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwprofile_crosssitescripting_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwprofile_csrftag_binding +// Binding object showing the csrftag that can be bound to appfwprofile. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_csrftag_binding +func (s *AppFWService) AddAppFWProfileCSRFTagBinding(resource models.AppFWProfileCSRFTagBinding) error { + payload := map[string]interface{}{ + "appfwprofile_csrftag_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileCSRFTagBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWProfileCSRFTagBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWProfileCSRFTagBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWProfileCSRFTagBinding() ([]models.AppFWProfileCSRFTagBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileCSRFTagBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileCSRFTagBinding `json:"appfwprofile_csrftag_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWProfileCSRFTagBinding(name string) ([]models.AppFWProfileCSRFTagBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWProfileCSRFTagBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileCSRFTagBinding `json:"appfwprofile_csrftag_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWProfileCSRFTagBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWProfileCSRFTagBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwprofile_csrftag_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwprofile_denyurl_binding +// Binding object showing the denyurl that can be bound to appfwprofile. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_denyurl_binding +func (s *AppFWService) AddAppFWProfileDenyURLBinding(resource models.AppFWProfileDenyURLBinding) error { + payload := map[string]interface{}{ + "appfwprofile_denyurl_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileDenyURLBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWProfileDenyURLBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWProfileDenyURLBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWProfileDenyURLBinding() ([]models.AppFWProfileDenyURLBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileDenyURLBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileDenyURLBinding `json:"appfwprofile_denyurl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWProfileDenyURLBinding(name string) ([]models.AppFWProfileDenyURLBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWProfileDenyURLBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileDenyURLBinding `json:"appfwprofile_denyurl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWProfileDenyURLBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWProfileDenyURLBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwprofile_denyurl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwprofile_excluderescontenttype_binding +// Binding object showing the excluderescontenttype that can be bound to appfwprofile. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_excluderescontenttype_binding +func (s *AppFWService) AddAppFWProfileExcludeRESContentTypeBinding(resource models.AppFWProfileExcludeRESContentTypeBinding) error { + payload := map[string]interface{}{ + "appfwprofile_excluderescontenttype_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileExcludeRESContentTypeBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWProfileExcludeRESContentTypeBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWProfileExcludeRESContentTypeBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWProfileExcludeRESContentTypeBinding() ([]models.AppFWProfileExcludeRESContentTypeBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileExcludeRESContentTypeBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileExcludeRESContentTypeBinding `json:"appfwprofile_excluderescontenttype_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWProfileExcludeRESContentTypeBinding(name string) ([]models.AppFWProfileExcludeRESContentTypeBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWProfileExcludeRESContentTypeBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileExcludeRESContentTypeBinding `json:"appfwprofile_excluderescontenttype_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWProfileExcludeRESContentTypeBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWProfileExcludeRESContentTypeBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwprofile_excluderescontenttype_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwprofile_fieldconsistency_binding +// Binding object showing the fieldconsistency that can be bound to appfwprofile. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_fieldconsistency_binding +func (s *AppFWService) AddAppFWProfileFieldConsistencyBinding(resource models.AppFWProfileFieldConsistencyBinding) error { + payload := map[string]interface{}{ + "appfwprofile_fieldconsistency_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileFieldConsistencyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWProfileFieldConsistencyBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWProfileFieldConsistencyBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWProfileFieldConsistencyBinding() ([]models.AppFWProfileFieldConsistencyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileFieldConsistencyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileFieldConsistencyBinding `json:"appfwprofile_fieldconsistency_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWProfileFieldConsistencyBinding(name string) ([]models.AppFWProfileFieldConsistencyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWProfileFieldConsistencyBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileFieldConsistencyBinding `json:"appfwprofile_fieldconsistency_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWProfileFieldConsistencyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWProfileFieldConsistencyBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwprofile_fieldconsistency_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwprofile_fieldformat_binding +// Binding object showing the fieldformat that can be bound to appfwprofile. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_fieldformat_binding +func (s *AppFWService) AddAppFWProfileFieldFormatBinding(resource models.AppFWProfileFieldFormatBinding) error { + payload := map[string]interface{}{ + "appfwprofile_fieldformat_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileFieldFormatBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWProfileFieldFormatBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWProfileFieldFormatBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWProfileFieldFormatBinding() ([]models.AppFWProfileFieldFormatBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileFieldFormatBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileFieldFormatBinding `json:"appfwprofile_fieldformat_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWProfileFieldFormatBinding(name string) ([]models.AppFWProfileFieldFormatBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWProfileFieldFormatBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileFieldFormatBinding `json:"appfwprofile_fieldformat_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWProfileFieldFormatBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWProfileFieldFormatBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwprofile_fieldformat_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwprofile_fileuploadtype_binding +// Binding object showing the fileuploadtype that can be bound to appfwprofile. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_fileuploadtype_binding +func (s *AppFWService) AddAppFWProfileFileUploadTypeBinding(resource models.AppFWProfileFileUploadTypeBinding) error { + payload := map[string]interface{}{ + "appfwprofile_fileuploadtype_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileFileUploadTypeBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWProfileFileUploadTypeBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWProfileFileUploadTypeBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWProfileFileUploadTypeBinding() ([]models.AppFWProfileFileUploadTypeBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileFileUploadTypeBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileFileUploadTypeBinding `json:"appfwprofile_fileuploadtype_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWProfileFileUploadTypeBinding(name string) ([]models.AppFWProfileFileUploadTypeBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWProfileFileUploadTypeBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileFileUploadTypeBinding `json:"appfwprofile_fileuploadtype_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWProfileFileUploadTypeBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWProfileFileUploadTypeBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwprofile_fileuploadtype_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwprofile_jsondosurl_binding +// Binding object showing the jsondosurl that can be bound to appfwprofile. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_jsondosurl_binding +func (s *AppFWService) AddAppFWProfileJSONDOSURLBinding(resource models.AppFWProfileJSONDOSURLBinding) error { + payload := map[string]interface{}{ + "appfwprofile_jsondosurl_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileJSONDOSURLBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWProfileJSONDOSURLBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWProfileJSONDOSURLBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWProfileJSONDOSURLBinding() ([]models.AppFWProfileJSONDOSURLBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileJSONDOSURLBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileJSONDOSURLBinding `json:"appfwprofile_jsondosurl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWProfileJSONDOSURLBinding(name string) ([]models.AppFWProfileJSONDOSURLBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWProfileJSONDOSURLBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileJSONDOSURLBinding `json:"appfwprofile_jsondosurl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWProfileJSONDOSURLBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWProfileJSONDOSURLBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwprofile_jsondosurl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwprofile_jsonsqlurl_binding +// Binding object showing the jsonsqlurl that can be bound to appfwprofile. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_jsonsqlurl_binding +func (s *AppFWService) AddAppFWProfileJSONSQLURLBinding(resource models.AppFWProfileJSONSQLURLBinding) error { + payload := map[string]interface{}{ + "appfwprofile_jsonsqlurl_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileJSONSQLURLBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWProfileJSONSQLURLBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWProfileJSONSQLURLBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWProfileJSONSQLURLBinding() ([]models.AppFWProfileJSONSQLURLBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileJSONSQLURLBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileJSONSQLURLBinding `json:"appfwprofile_jsonsqlurl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWProfileJSONSQLURLBinding(name string) ([]models.AppFWProfileJSONSQLURLBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWProfileJSONSQLURLBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileJSONSQLURLBinding `json:"appfwprofile_jsonsqlurl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWProfileJSONSQLURLBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWProfileJSONSQLURLBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwprofile_jsonsqlurl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwprofile_jsonxssurl_binding +// Binding object showing the jsonxssurl that can be bound to appfwprofile. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_jsonxssurl_binding +func (s *AppFWService) AddAppFWProfileJSONXSSURLBinding(resource models.AppFWProfileJSONXSSURLBinding) error { + payload := map[string]interface{}{ + "appfwprofile_jsonxssurl_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileJSONXSSURLBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWProfileJSONXSSURLBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWProfileJSONXSSURLBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWProfileJSONXSSURLBinding() ([]models.AppFWProfileJSONXSSURLBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileJSONXSSURLBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileJSONXSSURLBinding `json:"appfwprofile_jsonxssurl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWProfileJSONXSSURLBinding(name string) ([]models.AppFWProfileJSONXSSURLBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWProfileJSONXSSURLBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileJSONXSSURLBinding `json:"appfwprofile_jsonxssurl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWProfileJSONXSSURLBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWProfileJSONXSSURLBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwprofile_jsonxssurl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwprofile_logexpression_binding +// Binding object showing the logexpression that can be bound to appfwprofile. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_logexpression_binding +func (s *AppFWService) AddAppFWProfileLogExpressionBinding(resource models.AppFWProfileLogExpressionBinding) error { + payload := map[string]interface{}{ + "appfwprofile_logexpression_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileLogExpressionBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWProfileLogExpressionBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWProfileLogExpressionBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWProfileLogExpressionBinding() ([]models.AppFWProfileLogExpressionBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileLogExpressionBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileLogExpressionBinding `json:"appfwprofile_logexpression_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWProfileLogExpressionBinding(name string) ([]models.AppFWProfileLogExpressionBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWProfileLogExpressionBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileLogExpressionBinding `json:"appfwprofile_logexpression_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWProfileLogExpressionBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWProfileLogExpressionBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwprofile_logexpression_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwprofile_safeobject_binding +// Binding object showing the safeobject that can be bound to appfwprofile. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_safeobject_binding +func (s *AppFWService) AddAppFWProfileSafeObjectBinding(resource models.AppFWProfileSafeObjectBinding) error { + payload := map[string]interface{}{ + "appfwprofile_safeobject_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileSafeObjectBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWProfileSafeObjectBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWProfileSafeObjectBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWProfileSafeObjectBinding() ([]models.AppFWProfileSafeObjectBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileSafeObjectBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileSafeObjectBinding `json:"appfwprofile_safeobject_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWProfileSafeObjectBinding(name string) ([]models.AppFWProfileSafeObjectBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWProfileSafeObjectBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileSafeObjectBinding `json:"appfwprofile_safeobject_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWProfileSafeObjectBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWProfileSafeObjectBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwprofile_safeobject_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwprofile_sqlinjection_binding +// Binding object showing the sqlinjection that can be bound to appfwprofile. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_sqlinjection_binding +func (s *AppFWService) AddAppFWProfileSQLInjectionBinding(resource models.AppFWProfileSQLInjectionBinding) error { + payload := map[string]interface{}{ + "appfwprofile_sqlinjection_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileSQLInjectionBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWProfileSQLInjectionBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWProfileSQLInjectionBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWProfileSQLInjectionBinding() ([]models.AppFWProfileSQLInjectionBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileSQLInjectionBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileSQLInjectionBinding `json:"appfwprofile_sqlinjection_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWProfileSQLInjectionBinding(name string) ([]models.AppFWProfileSQLInjectionBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWProfileSQLInjectionBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileSQLInjectionBinding `json:"appfwprofile_sqlinjection_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWProfileSQLInjectionBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWProfileSQLInjectionBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwprofile_sqlinjection_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwprofile_starturl_binding +// Binding object showing the starturl that can be bound to appfwprofile. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_starturl_binding +func (s *AppFWService) AddAppFWProfileStartURLBinding(resource models.AppFWProfileStartURLBinding) error { + payload := map[string]interface{}{ + "appfwprofile_starturl_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileStartURLBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWProfileStartURLBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWProfileStartURLBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWProfileStartURLBinding() ([]models.AppFWProfileStartURLBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileStartURLBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileStartURLBinding `json:"appfwprofile_starturl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWProfileStartURLBinding(name string) ([]models.AppFWProfileStartURLBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWProfileStartURLBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileStartURLBinding `json:"appfwprofile_starturl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWProfileStartURLBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWProfileStartURLBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwprofile_starturl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwprofile_trustedlearningclients_binding +// Binding object showing the trustedlearningclients that can be bound to appfwprofile. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_trustedlearningclients_binding +func (s *AppFWService) AddAppFWProfileTrustedLearningClientsBinding(resource models.AppFWProfileTrustedLearningClientsBinding) error { + payload := map[string]interface{}{ + "appfwprofile_trustedlearningclients_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileTrustedLearningClientsBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWProfileTrustedLearningClientsBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWProfileTrustedLearningClientsBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWProfileTrustedLearningClientsBinding() ([]models.AppFWProfileTrustedLearningClientsBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileTrustedLearningClientsBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileTrustedLearningClientsBinding `json:"appfwprofile_trustedlearningclients_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWProfileTrustedLearningClientsBinding(name string) ([]models.AppFWProfileTrustedLearningClientsBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWProfileTrustedLearningClientsBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileTrustedLearningClientsBinding `json:"appfwprofile_trustedlearningclients_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWProfileTrustedLearningClientsBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWProfileTrustedLearningClientsBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwprofile_trustedlearningclients_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwprofile_xmlattachmenturl_binding +// Binding object showing the xmlattachmenturl that can be bound to appfwprofile. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_xmlattachmenturl_binding +func (s *AppFWService) AddAppFWProfileXMLAttachmentURLBinding(resource models.AppFWProfileXMLAttachmentURLBinding) error { + payload := map[string]interface{}{ + "appfwprofile_xmlattachmenturl_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileXMLAttachmentURLBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWProfileXMLAttachmentURLBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWProfileXMLAttachmentURLBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWProfileXMLAttachmentURLBinding() ([]models.AppFWProfileXMLAttachmentURLBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileXMLAttachmentURLBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileXMLAttachmentURLBinding `json:"appfwprofile_xmlattachmenturl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWProfileXMLAttachmentURLBinding(name string) ([]models.AppFWProfileXMLAttachmentURLBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWProfileXMLAttachmentURLBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileXMLAttachmentURLBinding `json:"appfwprofile_xmlattachmenturl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWProfileXMLAttachmentURLBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWProfileXMLAttachmentURLBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwprofile_xmlattachmenturl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwprofile_xmldosurl_binding +// Binding object showing the xmldosurl that can be bound to appfwprofile. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_xmldosurl_binding +func (s *AppFWService) AddAppFWProfileXMLDOSURLBinding(resource models.AppFWProfileXMLDOSURLBinding) error { + payload := map[string]interface{}{ + "appfwprofile_xmldosurl_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileXMLDOSURLBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWProfileXMLDOSURLBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWProfileXMLDOSURLBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWProfileXMLDOSURLBinding() ([]models.AppFWProfileXMLDOSURLBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileXMLDOSURLBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileXMLDOSURLBinding `json:"appfwprofile_xmldosurl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWProfileXMLDOSURLBinding(name string) ([]models.AppFWProfileXMLDOSURLBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWProfileXMLDOSURLBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileXMLDOSURLBinding `json:"appfwprofile_xmldosurl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWProfileXMLDOSURLBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWProfileXMLDOSURLBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwprofile_xmldosurl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwprofile_xmlsqlinjection_binding +// Binding object showing the xmlsqlinjection that can be bound to appfwprofile. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_xmlsqlinjection_binding +func (s *AppFWService) AddAppFWProfileXMLSQLInjectionBinding(resource models.AppFWProfileXMLSQLInjectionBinding) error { + payload := map[string]interface{}{ + "appfwprofile_xmlsqlinjection_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileXMLSQLInjectionBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWProfileXMLSQLInjectionBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWProfileXMLSQLInjectionBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWProfileXMLSQLInjectionBinding() ([]models.AppFWProfileXMLSQLInjectionBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileXMLSQLInjectionBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileXMLSQLInjectionBinding `json:"appfwprofile_xmlsqlinjection_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWProfileXMLSQLInjectionBinding(name string) ([]models.AppFWProfileXMLSQLInjectionBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWProfileXMLSQLInjectionBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileXMLSQLInjectionBinding `json:"appfwprofile_xmlsqlinjection_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWProfileXMLSQLInjectionBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWProfileXMLSQLInjectionBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwprofile_xmlsqlinjection_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwprofile_xmlvalidationurl_binding +// Binding object showing the xmlvalidationurl that can be bound to appfwprofile. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_xmlvalidationurl_binding +func (s *AppFWService) AddAppFWProfileXMLValidationURLBinding(resource models.AppFWProfileXMLValidationURLBinding) error { + payload := map[string]interface{}{ + "appfwprofile_xmlvalidationurl_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileXMLValidationURLBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWProfileXMLValidationURLBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWProfileXMLValidationURLBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWProfileXMLValidationURLBinding() ([]models.AppFWProfileXMLValidationURLBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileXMLValidationURLBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileXMLValidationURLBinding `json:"appfwprofile_xmlvalidationurl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWProfileXMLValidationURLBinding(name string) ([]models.AppFWProfileXMLValidationURLBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWProfileXMLValidationURLBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileXMLValidationURLBinding `json:"appfwprofile_xmlvalidationurl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWProfileXMLValidationURLBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWProfileXMLValidationURLBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwprofile_xmlvalidationurl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwprofile_xmlwsiurl_binding +// Binding object showing the xmlwsiurl that can be bound to appfwprofile. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_xmlwsiurl_binding +func (s *AppFWService) AddAppFWProfileXMLWSIURLBinding(resource models.AppFWProfileXMLWSIURLBinding) error { + payload := map[string]interface{}{ + "appfwprofile_xmlwsiurl_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileXMLWSIURLBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWProfileXMLWSIURLBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWProfileXMLWSIURLBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWProfileXMLWSIURLBinding() ([]models.AppFWProfileXMLWSIURLBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileXMLWSIURLBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileXMLWSIURLBinding `json:"appfwprofile_xmlwsiurl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWProfileXMLWSIURLBinding(name string) ([]models.AppFWProfileXMLWSIURLBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWProfileXMLWSIURLBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileXMLWSIURLBinding `json:"appfwprofile_xmlwsiurl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWProfileXMLWSIURLBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWProfileXMLWSIURLBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwprofile_xmlwsiurl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwprofile_xmlxss_binding +// Binding object showing the xmlxss that can be bound to appfwprofile. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwprofile_xmlxss_binding +func (s *AppFWService) AddAppFWProfileXMLXSSBinding(resource models.AppFWProfileXMLXSSBinding) error { + payload := map[string]interface{}{ + "appfwprofile_xmlxss_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWProfileXMLXSSBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWProfileXMLXSSBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", appFWProfileXMLXSSBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWProfileXMLXSSBinding() ([]models.AppFWProfileXMLXSSBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWProfileXMLXSSBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileXMLXSSBinding `json:"appfwprofile_xmlxss_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) GetAppFWProfileXMLXSSBinding(name string) ([]models.AppFWProfileXMLXSSBinding, error) { + reqURL := fmt.Sprintf("%s/%s", appFWProfileXMLXSSBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppFWProfileXMLXSSBinding `json:"appfwprofile_xmlxss_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppFWService) CountAppFWProfileXMLXSSBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", appFWProfileXMLXSSBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appfwprofile_xmlxss_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// appfwsettings +// Configuration for AS settings resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwsettings +func (s *AppFWService) UpdateAppFWSettings(resource models.AppFWSettings) error { + payload := map[string]interface{}{ + "appfwsettings": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, appFWSettingsURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) UnsetAppFWSettings(resource models.AppFWSettings) error { + payload := map[string]interface{}{ + "appfwsettings": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWSettingsURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWSettings() (*models.AppFWSettings, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWSettingsURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Settings []models.AppFWSettings `json:"appfwsettings"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Settings) == 0 { + return nil, fmt.Errorf("appfwsettings not found") + } + + return &result.Settings[0], nil +} + +// appfwsignatures +// Configuration for application firewall signatures XML configuration resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwsignatures +func (s *AppFWService) DeleteAppFWSignatures(name string) error { + reqURL := fmt.Sprintf("%s/%s", appFWSignaturesURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWSignatures() ([]models.AppFWSignatures, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWSignaturesURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Signatures []models.AppFWSignatures `json:"appfwsignatures"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Signatures, nil +} + +func (s *AppFWService) GetAppFWSignatures(name string) (*models.AppFWSignatures, error) { + reqURL := fmt.Sprintf("%s/%s", appFWSignaturesURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Signatures []models.AppFWSignatures `json:"appfwsignatures"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Signatures) == 0 { + return nil, fmt.Errorf("appfwsignatures not found") + } + + return &result.Signatures[0], nil +} + +func (s *AppFWService) ImportAppFWSignatures(resource models.AppFWSignatures) error { + payload := map[string]interface{}{ + "appfwsignatures": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWSignaturesURL+"?action=Import", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) ChangeAppFWSignatures(resource models.AppFWSignatures) error { + payload := map[string]interface{}{ + "appfwsignatures": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWSignaturesURL+"?action=change", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// appfwtransactionrecords +// Configuration for Application firewall transaction record resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwtransactionrecords +func (s *AppFWService) GetAllAppFWTransactionRecords() ([]models.AppFWTransactionRecords, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWTransactionRecordsURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Records []models.AppFWTransactionRecords `json:"appfwtransactionrecords"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Records, nil +} + +func (s *AppFWService) CountAppFWTransactionRecords() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWTransactionRecordsURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Records []struct { + Count float64 `json:"__count"` + } `json:"appfwtransactionrecords"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Records) > 0 { + return result.Records[0].Count, nil + } + + return 0, nil +} + +// appfwurlencodedformcontenttype +// Configuration for Urlencoded form content type resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwurlencodedformcontenttype +func (s *AppFWService) AddAppFWURLEncodedFormContentType(resource models.AppFWURLEncodedFormContentType) error { + payload := map[string]interface{}{ + "appfwurlencodedformcontenttype": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWURLEncodedFormContentTypeURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWURLEncodedFormContentType(name string) error { + reqURL := fmt.Sprintf("%s/%s", appFWURLEncodedFormContentTypeURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWURLEncodedFormContentType() ([]models.AppFWURLEncodedFormContentType, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWURLEncodedFormContentTypeURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Types []models.AppFWURLEncodedFormContentType `json:"appfwurlencodedformcontenttype"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Types, nil +} + +func (s *AppFWService) GetAppFWURLEncodedFormContentType(name string) (*models.AppFWURLEncodedFormContentType, error) { + reqURL := fmt.Sprintf("%s/%s", appFWURLEncodedFormContentTypeURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Types []models.AppFWURLEncodedFormContentType `json:"appfwurlencodedformcontenttype"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Types) == 0 { + return nil, fmt.Errorf("appfwurlencodedformcontenttype not found") + } + + return &result.Types[0], nil +} + +func (s *AppFWService) CountAppFWURLEncodedFormContentType() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWURLEncodedFormContentTypeURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Types []struct { + Count float64 `json:"__count"` + } `json:"appfwurlencodedformcontenttype"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Types) > 0 { + return result.Types[0].Count, nil + } + + return 0, nil +} + +// appfwwsdl +// Configuration for WSDL file resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwwsdl +func (s *AppFWService) DeleteAppFWWSDL(name string) error { + reqURL := fmt.Sprintf("%s/%s", appFWWSDLURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWWSDL() ([]models.AppFWWSDL, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWWSDLURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + WSDLs []models.AppFWWSDL `json:"appfwwsdl"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.WSDLs, nil +} + +func (s *AppFWService) GetAppFWWSDL(name string) (*models.AppFWWSDL, error) { + reqURL := fmt.Sprintf("%s/%s", appFWWSDLURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + WSDLs []models.AppFWWSDL `json:"appfwwsdl"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.WSDLs) == 0 { + return nil, fmt.Errorf("appfwwsdl not found") + } + + return &result.WSDLs[0], nil +} + +func (s *AppFWService) ImportAppFWWSDL(resource models.AppFWWSDL) error { + payload := map[string]interface{}{ + "appfwwsdl": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWWSDLURL+"?action=Import", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// appfwxmlcontenttype +// Configuration for XML Content type resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwxmlcontenttype +func (s *AppFWService) AddAppFWXMLContentType(resource models.AppFWXMLContentType) error { + payload := map[string]interface{}{ + "appfwxmlcontenttype": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWXMLContentTypeURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) DeleteAppFWXMLContentType(name string) error { + reqURL := fmt.Sprintf("%s/%s", appFWXMLContentTypeURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWXMLContentType() ([]models.AppFWXMLContentType, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWXMLContentTypeURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Types []models.AppFWXMLContentType `json:"appfwxmlcontenttype"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Types, nil +} + +func (s *AppFWService) GetAppFWXMLContentType(name string) (*models.AppFWXMLContentType, error) { + reqURL := fmt.Sprintf("%s/%s", appFWXMLContentTypeURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Types []models.AppFWXMLContentType `json:"appfwxmlcontenttype"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Types) == 0 { + return nil, fmt.Errorf("appfwxmlcontenttype not found") + } + + return &result.Types[0], nil +} + +func (s *AppFWService) CountAppFWXMLContentType() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWXMLContentTypeURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Types []struct { + Count float64 `json:"__count"` + } `json:"appfwxmlcontenttype"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Types) > 0 { + return result.Types[0].Count, nil + } + + return 0, nil +} // appfwxmlerrorpage // Configuration for xml error page resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwxmlerrorpage -func (s *AppFWService) DeleteAppFWXMLErrorPage() {} -func (s *AppFWService) GetAllAppFWXMLErrorPage() {} -func (s *AppFWService) GetAppFWXMLErrorPage() {} -func (s *AppFWService) ImportAppFWXMLErrorPage() {} -func (s *AppFWService) ChangeAppFWXMLErrorPage() {} +func (s *AppFWService) DeleteAppFWXMLErrorPage(name string) error { + reqURL := fmt.Sprintf("%s/%s", appFWXMLErrorPageURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWXMLErrorPage() ([]models.AppFWXMLErrorPage, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWXMLErrorPageURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Pages []models.AppFWXMLErrorPage `json:"appfwxmlerrorpage"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Pages, nil +} + +func (s *AppFWService) GetAppFWXMLErrorPage(name string) (*models.AppFWXMLErrorPage, error) { + reqURL := fmt.Sprintf("%s/%s", appFWXMLErrorPageURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// appfwxmlscheme + var result struct { + Pages []models.AppFWXMLErrorPage `json:"appfwxmlerrorpage"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Pages) == 0 { + return nil, fmt.Errorf("appfwxmlerrorpage not found") + } + + return &result.Pages[0], nil +} + +func (s *AppFWService) ImportAppFWXMLErrorPage(resource models.AppFWXMLErrorPage) error { + payload := map[string]interface{}{ + "appfwxmlerrorpage": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWXMLErrorPageURL+"?action=Import", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) ChangeAppFWXMLErrorPage(resource models.AppFWXMLErrorPage) error { + payload := map[string]interface{}{ + "appfwxmlerrorpage": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWXMLErrorPageURL+"?action=change", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// appfwxmlschema // Configuration for XML schema resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appfw/appfwxmlschema -func (s *AppFWService) DeleteAppFWXMLScheme() {} -func (s *AppFWService) GetAllAppFWXMLScheme() {} -func (s *AppFWService) GetAppFWXMLScheme() {} -func (s *AppFWService) ImportAppFWXMLScheme() {} +func (s *AppFWService) DeleteAppFWXMLSchema(name string) error { + reqURL := fmt.Sprintf("%s/%s", appFWXMLSchemaURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppFWService) GetAllAppFWXMLSchema() ([]models.AppFWXMLSchema, error) { + req, err := s.client.NewRequest(http.MethodGet, appFWXMLSchemaURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Schemas []models.AppFWXMLSchema `json:"appfwxmlschema"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Schemas, nil +} + +func (s *AppFWService) GetAppFWXMLSchema(name string) (*models.AppFWXMLSchema, error) { + reqURL := fmt.Sprintf("%s/%s", appFWXMLSchemaURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Schemas []models.AppFWXMLSchema `json:"appfwxmlschema"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Schemas) == 0 { + return nil, fmt.Errorf("appfwxmlschema not found") + } + + return &result.Schemas[0], nil +} + +func (s *AppFWService) ImportAppFWXMLSchema(resource models.AppFWXMLSchema) error { + payload := map[string]interface{}{ + "appfwxmlschema": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appFWXMLSchemaURL+"?action=Import", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} diff --git a/nitrogo/appqoe.go b/nitrogo/appqoe.go index 9bbd67a..f75a04f 100644 --- a/nitrogo/appqoe.go +++ b/nitrogo/appqoe.go @@ -1,5 +1,24 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + appQOEActionURL = "/nitro/v1/config/appqoeaction" + appQOECustomRespURL = "/nitro/v1/config/appqoecustomresp" + appQOEParameterURL = "/nitro/v1/config/appqoeparameter" + appQOEPolicyURL = "/nitro/v1/config/appqoepolicy" + appQOEPolicyBindingURL = "/nitro/v1/config/appqoepolicy_binding" + appQOEPolicyLBVServerBindingURL = "/nitro/v1/config/appqoepolicy_lbvserver_binding" +) + // Application Level Quality of Experience configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appqoe/appqoe type AppQOEService struct { @@ -9,49 +28,583 @@ type AppQOEService struct { // appqoeaction // Configuration for AppQoS action resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appqoe/appqoeaction -func (s *AppQOEService) AddAppQOEAction() {} -func (s *AppQOEService) DeleteAppQOEAction() {} -func (s *AppQOEService) UpdateAppQOEAction() {} -func (s *AppQOEService) UnsetAppQOEAction() {} -func (s *AppQOEService) GetAllAppQOEAction() {} -func (s *AppQOEService) GetAppQOEAction() {} -func (s *AppQOEService) CountAppQOEAction() {} + +func (s *AppQOEService) AddAppQOEAction(action models.AppQOEAction) error { + payload := map[string]any{ + "appqoeaction": action, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appQOEActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppQOEService) DeleteAppQOEAction(name string) error { + urlReq := fmt.Sprintf("%s/%s", appQOEActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppQOEService) UpdateAppQOEAction(action models.AppQOEAction) error { + payload := map[string]any{ + "appqoeaction": action, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, appQOEActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppQOEService) UnsetAppQOEAction(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "appqoeaction": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appQOEActionURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppQOEService) GetAllAppQOEAction() ([]models.AppQOEAction, error) { + req, err := s.client.NewRequest(http.MethodGet, appQOEActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Actions []models.AppQOEAction `json:"appqoeaction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Actions, nil +} + +func (s *AppQOEService) GetAppQOEAction(name string) ([]models.AppQOEAction, error) { + urlReq := fmt.Sprintf("%s/%s", appQOEActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Actions []models.AppQOEAction `json:"appqoeaction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Actions, nil +} + +func (s *AppQOEService) CountAppQOEAction() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, appQOEActionURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Actions []struct { + Count float64 `json:"__count"` + } `json:"appqoeaction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Actions) > 0 { + return result.Actions[0].Count, nil + } + + return 0, nil +} // appqoecustomerresp // Configuration for AppQoE custom response page resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appqoe/appqoecustomresp -func (s *AppQOEService) ImportAppQOECustomerResp() {} -func (s *AppQOEService) DeleteAppQOECustomerResp() {} -func (s *AppQOEService) GetAllAppQOECustomerResp() {} -func (s *AppQOEService) CountAppQOECustomerResp() {} -func (s *AppQOEService) ChangeAppQOECustomerResp() {} + +func (s *AppQOEService) ImportAppQOECustomResp(resp models.AppQOECustomResp) error { + payload := map[string]any{ + "appqoecustomresp": resp, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appQOECustomRespURL+"?action=Import", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppQOEService) DeleteAppQOECustomResp(name string) error { + urlReq := fmt.Sprintf("%s/%s", appQOECustomRespURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppQOEService) GetAllAppQOECustomResp() ([]models.AppQOECustomResp, error) { + req, err := s.client.NewRequest(http.MethodGet, appQOECustomRespURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + CustomResps []models.AppQOECustomResp `json:"appqoecustomresp"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.CustomResps, nil +} + +func (s *AppQOEService) CountAppQOECustomResp() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, appQOECustomRespURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + CustomResps []struct { + Count float64 `json:"__count"` + } `json:"appqoecustomresp"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.CustomResps) > 0 { + return result.CustomResps[0].Count, nil + } + + return 0, nil +} + +func (s *AppQOEService) ChangeAppQOECustomResp(resp models.AppQOECustomResp) error { + payload := map[string]any{ + "appqoecustomresp": resp, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appQOECustomRespURL+"?action=change", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} // appqoeparameter // Configuration for QOS parameter resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appqoe/appqoeparameter -func (s *AppQOEService) UpdateAppQOEParameter() {} -func (s *AppQOEService) UnsetAppQOEParameter() {} -func (s *AppQOEService) GetAllAppQOEParameter() {} + +func (s *AppQOEService) UpdateAppQOEParameter(param models.AppQOEParameter) error { + payload := map[string]any{ + "appqoeparameter": param, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, appQOEParameterURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppQOEService) UnsetAppQOEParameter(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "appqoeparameter": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appQOEParameterURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppQOEService) GetAllAppQOEParameter() (models.AppQOEParameter, error) { + req, err := s.client.NewRequest(http.MethodGet, appQOEParameterURL, nil) + if err != nil { + return models.AppQOEParameter{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.AppQOEParameter{}, err + } + + var result struct { + Parameters []models.AppQOEParameter `json:"appqoeparameter"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.AppQOEParameter{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Parameters) > 0 { + return result.Parameters[0], nil + } + + return models.AppQOEParameter{}, nil +} // appqoepolicy // Configuration for AppQoS policy resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appqoe/appqoepolicy -func (s *AppQOEService) AddAppQOEPolicy() {} -func (s *AppQOEService) DeleteAppQOEPolicy() {} -func (s *AppQOEService) UpdateAppQOEPolicy() {} -func (s *AppQOEService) GetAllAppQOEPolicy() {} -func (s *AppQOEService) GetAppQOEPolicy() {} -func (s *AppQOEService) CountAppQOEPolicy() {} + +func (s *AppQOEService) AddAppQOEPolicy(policy models.AppQOEPolicy) error { + payload := map[string]any{ + "appqoepolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, appQOEPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppQOEService) DeleteAppQOEPolicy(name string) error { + urlReq := fmt.Sprintf("%s/%s", appQOEPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppQOEService) UpdateAppQOEPolicy(policy models.AppQOEPolicy) error { + payload := map[string]any{ + "appqoepolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, appQOEPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AppQOEService) GetAllAppQOEPolicy() ([]models.AppQOEPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, appQOEPolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Policies []models.AppQOEPolicy `json:"appqoepolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Policies, nil +} + +func (s *AppQOEService) GetAppQOEPolicy(name string) ([]models.AppQOEPolicy, error) { + urlReq := fmt.Sprintf("%s/%s", appQOEPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Policies []models.AppQOEPolicy `json:"appqoepolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Policies, nil +} + +func (s *AppQOEService) CountAppQOEPolicy() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, appQOEPolicyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Policies []struct { + Count float64 `json:"__count"` + } `json:"appqoepolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Policies) > 0 { + return result.Policies[0].Count, nil + } + + return 0, nil +} // appqoepolicy_binding // Binding object which returns the resources bound to appqoepolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appqoe/appqoepolicy_binding -func (s *AppQOEService) GetAllAppQOEPolicyBinding() {} -func (s *AppQOEService) GetAppQOEPolicyBinding() {} + +func (s *AppQOEService) GetAllAppQOEPolicyBinding() ([]models.AppQOEPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appQOEPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppQOEPolicyBinding `json:"appqoepolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppQOEService) GetAppQOEPolicyBinding(name string) ([]models.AppQOEPolicyBinding, error) { + urlReq := fmt.Sprintf("%s/%s", appQOEPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppQOEPolicyBinding `json:"appqoepolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} // appqoepolicy_lbvserver_binding // Binding object showing the lbvserver that can be bound to appqoepolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/appqoe/appqoepolicy_lbvserver_binding -func (s *AppQOEService) GetAllAppQOEPolicyLBVServerBinding() {} -func (s *AppQOEService) GetAppQOEPolicyLBVServerBinding() {} -func (s *AppQOEService) CountAppQOEPolicyLBVServerBinding() {} + +func (s *AppQOEService) GetAllAppQOEPolicyLBVServerBinding() ([]models.AppQOEPolicyLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, appQOEPolicyLBVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppQOEPolicyLBVServerBinding `json:"appqoepolicy_lbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppQOEService) GetAppQOEPolicyLBVServerBinding(name string) ([]models.AppQOEPolicyLBVServerBinding, error) { + urlReq := fmt.Sprintf("%s/%s", appQOEPolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AppQOEPolicyLBVServerBinding `json:"appqoepolicy_lbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AppQOEService) CountAppQOEPolicyLBVServerBinding(name string) (float64, error) { + urlReq := fmt.Sprintf("%s/%s?count=yes", appQOEPolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"appqoepolicy_lbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} diff --git a/nitrogo/audit.go b/nitrogo/audit.go index 54fb186..99ac67d 100644 --- a/nitrogo/audit.go +++ b/nitrogo/audit.go @@ -1,5 +1,54 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + auditMessageActionURL = "/nitro/v1/config/auditmessageaction" + auditMessagesURL = "/nitro/v1/config/auditmessages" + auditNSLogActionURL = "/nitro/v1/config/auditnslogaction" + auditNSLogGlobalAuditNSLogPolicyBindingURL = "/nitro/v1/config/auditnslogglobal_auditnslogpolicy_binding" + auditNSLogGlobalBindingURL = "/nitro/v1/config/auditnslogglobal_binding" + auditNSLogParamsURL = "/nitro/v1/config/auditnslogparams" + auditNSLogPolicyURL = "/nitro/v1/config/auditnslogpolicy" + auditNSLogPolicyAAAGroupBindingURL = "/nitro/v1/config/auditnslogpolicy_aaagroup_binding" + auditNSLogPolicyAAAUserBindingURL = "/nitro/v1/config/auditnslogpolicy_aaauser_binding" + auditNSLogPolicyAppFWGlobalBindingURL = "/nitro/v1/config/auditnslogpolicy_appfwglobal_binding" + auditNSLogPolicyAuditNSLogGlobalBindingURL = "/nitro/v1/config/auditnslogpolicy_auditnslogglobal_binding" + auditNSLogPolicyAuthenticationVServerBindingURL = "/nitro/v1/config/auditnslogpolicy_authenticationvserver_binding" + auditNSLogPolicyBindingURL = "/nitro/v1/config/auditnslogpolicy_binding" + auditNSLogPolicyCSVServerBindingURL = "/nitro/v1/config/auditnslogpolicy_csvserver_binding" + auditNSLogPolicyLBVServerBindingURL = "/nitro/v1/config/auditnslogpolicy_lbvserver_binding" + auditNSLogPolicySystemGlobalBindingURL = "/nitro/v1/config/auditnslogpolicy_systemglobal_binding" + auditNSLogPolicyTMGlobalBindingURL = "/nitro/v1/config/auditnslogpolicy_tmglobal_binding" + auditNSLogPolicyVPNGlobalBindingURL = "/nitro/v1/config/auditnslogpolicy_vpnglobal_binding" + auditNSLogPolicyVPNVServerBindingURL = "/nitro/v1/config/auditnslogpolicy_vpnvserver_binding" + auditSyslogActionURL = "/nitro/v1/config/auditsyslogaction" + auditSyslogGlobalAuditSyslogPolicyBindingURL = "/nitro/v1/config/auditsyslogglobal_auditsyslogpolicy_binding" + auditSyslogGlobalBindingURL = "/nitro/v1/config/auditsyslogglobal_binding" + auditSyslogParamsURL = "/nitro/v1/config/auditsyslogparams" + auditSyslogPolicyURL = "/nitro/v1/config/auditsyslogpolicy" + auditSyslogPolicyAAAGroupBindingURL = "/nitro/v1/config/auditsyslogpolicy_aaagroup_binding" + auditSyslogPolicyAAAUserBindingURL = "/nitro/v1/config/auditsyslogpolicy_aaauser_binding" + auditSyslogPolicyAuditSyslogGlobalBindingURL = "/nitro/v1/config/auditsyslogpolicy_auditsyslogglobal_binding" + auditSyslogPolicyAuthenticationVServerBindingURL = "/nitro/v1/config/auditsyslogpolicy_authenticationvserver_binding" + auditSyslogPolicyBindingURL = "/nitro/v1/config/auditsyslogpolicy_binding" + auditSyslogPolicyCSVServerBindingURL = "/nitro/v1/config/auditsyslogpolicy_csvserver_binding" + auditSyslogPolicyLBVServerBindingURL = "/nitro/v1/config/auditsyslogpolicy_lbvserver_binding" + auditSyslogPolicyRNATGlobalBindingURL = "/nitro/v1/config/auditsyslogpolicy_rnatglobal_binding" + auditSyslogPolicySystemGlobalBindingURL = "/nitro/v1/config/auditsyslogpolicy_systemglobal_binding" + auditSyslogPolicyTMGlobalBindingURL = "/nitro/v1/config/auditsyslogpolicy_tmglobal_binding" + auditSyslogPolicyVPNGlobalBindingURL = "/nitro/v1/config/auditsyslogpolicy_vpnglobal_binding" + auditSyslogPolicyVPNVServerBindingURL = "/nitro/v1/config/auditsyslogpolicy_vpnvserver_binding" +) + // Audit configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/audit type AuditService struct { @@ -9,264 +58,2511 @@ type AuditService struct { // auditmessageaction // Configuration for message action resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditmessageaction -func (s *AuditService) AddAuditMessageAction() {} -func (s *AuditService) DeleteAuditMessageAction() {} -func (s *AuditService) UpdateAuditMessageAction() {} -func (s *AuditService) UnsetAuditMessageAction() {} -func (s *AuditService) GetAllAuditMessageAction() {} -func (s *AuditService) GetAuditMessageAction() {} -func (s *AuditService) CountAuditMessageAction() {} + +func (s *AuditService) AddAuditMessageAction(action models.AuditMessageAction) error { + payload := map[string]any{"auditmessageaction": action} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, auditMessageActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuditService) DeleteAuditMessageAction(name string) error { + reqURL := fmt.Sprintf("%s/%s", auditMessageActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuditService) UpdateAuditMessageAction(action models.AuditMessageAction) error { + payload := map[string]any{"auditmessageaction": action} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, auditMessageActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuditService) UnsetAuditMessageAction(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"auditmessageaction": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, auditMessageActionURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuditService) GetAllAuditMessageAction() ([]models.AuditMessageAction, error) { + req, err := s.client.NewRequest(http.MethodGet, auditMessageActionURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Actions []models.AuditMessageAction `json:"auditmessageaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Actions, nil +} + +func (s *AuditService) GetAuditMessageAction(name string) ([]models.AuditMessageAction, error) { + reqURL := fmt.Sprintf("%s/%s", auditMessageActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Actions []models.AuditMessageAction `json:"auditmessageaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Actions, nil +} + +func (s *AuditService) CountAuditMessageAction() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, auditMessageActionURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Actions []struct { + Count float64 `json:"__count"` + } `json:"auditmessageaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Actions) > 0 { + return result.Actions[0].Count, nil + } + return 0, nil +} // auditmessages // Configuration for audit message resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditmessages -func (s *AuditService) GetAllAuditMessages() {} -func (s *AuditService) CountAuditMessages() {} + +func (s *AuditService) GetAllAuditMessages() ([]models.AuditMessages, error) { + req, err := s.client.NewRequest(http.MethodGet, auditMessagesURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Messages []models.AuditMessages `json:"auditmessages"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Messages, nil +} + +func (s *AuditService) CountAuditMessages() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, auditMessagesURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Messages []struct { + Count float64 `json:"__count"` + } `json:"auditmessages"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Messages) > 0 { + return result.Messages[0].Count, nil + } + return 0, nil +} // auditnslogaction // Configuration for ns log action resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditnslogaction -func (s *AuditService) AddAuditNSLogAction() {} -func (s *AuditService) DeleteAuditNSLogAction() {} -func (s *AuditService) UpdateAuditNSLogAction() {} -func (s *AuditService) UnsetAuditNSLogAction() {} -func (s *AuditService) GetAllAuditNSLogAction() {} -func (s *AuditService) GetAuditNSLogAction() {} -func (s *AuditService) CountAuditNSLogAction() {} + +func (s *AuditService) AddAuditNSLogAction(action models.AuditNSLogAction) error { + payload := map[string]any{"auditnslogaction": action} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, auditNSLogActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuditService) DeleteAuditNSLogAction(name string) error { + reqURL := fmt.Sprintf("%s/%s", auditNSLogActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuditService) UpdateAuditNSLogAction(action models.AuditNSLogAction) error { + payload := map[string]any{"auditnslogaction": action} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, auditNSLogActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuditService) UnsetAuditNSLogAction(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"auditnslogaction": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, auditNSLogActionURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuditService) GetAllAuditNSLogAction() ([]models.AuditNSLogAction, error) { + req, err := s.client.NewRequest(http.MethodGet, auditNSLogActionURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Actions []models.AuditNSLogAction `json:"auditnslogaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Actions, nil +} + +func (s *AuditService) GetAuditNSLogAction(name string) ([]models.AuditNSLogAction, error) { + reqURL := fmt.Sprintf("%s/%s", auditNSLogActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Actions []models.AuditNSLogAction `json:"auditnslogaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Actions, nil +} + +func (s *AuditService) CountAuditNSLogAction() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, auditNSLogActionURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Actions []struct { + Count float64 `json:"__count"` + } `json:"auditnslogaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Actions) > 0 { + return result.Actions[0].Count, nil + } + return 0, nil +} // auditnslogglobal_auditnslogpolicy_binding // Binding object showing the auditnslogpolicy that can be bound to auditnslogglobal. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditnslogglobal_auditnslogpolicy_binding -func (s *AuditService) AddAuditNSLogGlobalAuditNSLogPolicyBinding() {} -func (s *AuditService) DeleteAuditNSLogGlobalAuditNSLogPolicyBinding() {} -func (s *AuditService) GetAuditNSLogGlobalAuditNSLogPolicyBinding() {} -func (s *AuditService) CountAuditNSLogGlobalAuditNSLogPolicyBinding() {} + +func (s *AuditService) AddAuditNSLogGlobalAuditNSLogPolicyBinding(binding models.AuditNSLogGlobalAuditNSLogPolicyBinding) error { + payload := map[string]any{"auditnslogglobal_auditnslogpolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, auditNSLogGlobalAuditNSLogPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuditService) DeleteAuditNSLogGlobalAuditNSLogPolicyBinding(policyname string) error { + reqURL := fmt.Sprintf("%s?args=policyname:%s", auditNSLogGlobalAuditNSLogPolicyBindingURL, url.QueryEscape(policyname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuditService) GetAuditNSLogGlobalAuditNSLogPolicyBinding() ([]models.AuditNSLogGlobalAuditNSLogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditNSLogGlobalAuditNSLogPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditNSLogGlobalAuditNSLogPolicyBinding `json:"auditnslogglobal_auditnslogpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) CountAuditNSLogGlobalAuditNSLogPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, auditNSLogGlobalAuditNSLogPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"auditnslogglobal_auditnslogpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // auditnslogglobal_binding // Binding object which returns the resources bound to auditnslogglobal. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditnslogglobal_binding -func (s *AuditService) GetAuditNSLogGlobalBinding() {} + +func (s *AuditService) GetAuditNSLogGlobalBinding() ([]models.AuditNSLogGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditNSLogGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditNSLogGlobalBinding `json:"auditnslogglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // auditnslogparams // Configuration for ns log parameters resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditnslogparams -func (s *AuditService) UpdateAuditNSLogParams() {} -func (s *AuditService) UnsetAuditNSLogParams() {} -func (s *AuditService) GetAllAuditNSLogParams() {} + +func (s *AuditService) UpdateAuditNSLogParams(params models.AuditNSLogParams) error { + payload := map[string]any{"auditnslogparams": params} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, auditNSLogParamsURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuditService) UnsetAuditNSLogParams(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"auditnslogparams": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, auditNSLogParamsURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuditService) GetAllAuditNSLogParams() (models.AuditNSLogParams, error) { + req, err := s.client.NewRequest(http.MethodGet, auditNSLogParamsURL, nil) + if err != nil { + return models.AuditNSLogParams{}, err + } + resp, err := s.client.Do(req) + if err != nil { + return models.AuditNSLogParams{}, err + } + var result struct { + Params []models.AuditNSLogParams `json:"auditnslogparams"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return models.AuditNSLogParams{}, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Params) > 0 { + return result.Params[0], nil + } + return models.AuditNSLogParams{}, nil +} // auditnslogpolicy // Configuration for ns log policy resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditnslogpolicy -func (s *AuditService) AddAuditNSLogPolicy() {} -func (s *AuditService) DeleteAuditNSLogPolicy() {} -func (s *AuditService) UpdateAuditNSLogPolicy() {} -func (s *AuditService) GetAllAuditNSLogPolicy() {} -func (s *AuditService) GetAuditNSLogPolicy() {} -func (s *AuditService) CountAuditNSLogPolicy() {} + +func (s *AuditService) AddAuditNSLogPolicy(policy models.AuditNSLogPolicy) error { + payload := map[string]any{"auditnslogpolicy": policy} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, auditNSLogPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuditService) DeleteAuditNSLogPolicy(name string) error { + reqURL := fmt.Sprintf("%s/%s", auditNSLogPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuditService) UpdateAuditNSLogPolicy(policy models.AuditNSLogPolicy) error { + payload := map[string]any{"auditnslogpolicy": policy} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, auditNSLogPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuditService) GetAllAuditNSLogPolicy() ([]models.AuditNSLogPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, auditNSLogPolicyURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Policies []models.AuditNSLogPolicy `json:"auditnslogpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Policies, nil +} + +func (s *AuditService) GetAuditNSLogPolicy(name string) ([]models.AuditNSLogPolicy, error) { + reqURL := fmt.Sprintf("%s/%s", auditNSLogPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Policies []models.AuditNSLogPolicy `json:"auditnslogpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Policies, nil +} + +func (s *AuditService) CountAuditNSLogPolicy() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, auditNSLogPolicyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Policies []struct { + Count float64 `json:"__count"` + } `json:"auditnslogpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Policies) > 0 { + return result.Policies[0].Count, nil + } + return 0, nil +} // auditnslogpolicy_aaagroup_binding // Binding object showing the aaagroup that can be bound to auditnslogpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditnslogpolicy_aaagroup_binding -func (s *AuditService) GetAllAuditNSLogPolicyAAAGroupBinding() {} -func (s *AuditService) GetAuditNSLogPolicyAAAGroupBinding() {} -func (s *AuditService) CountAuditNSLogPolicyAAAGroupBinding() {} + +func (s *AuditService) GetAllAuditNSLogPolicyAAAGroupBinding() ([]models.AuditNSLogPolicyAAAGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditNSLogPolicyAAAGroupBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditNSLogPolicyAAAGroupBinding `json:"auditnslogpolicy_aaagroup_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) GetAuditNSLogPolicyAAAGroupBinding(name string) ([]models.AuditNSLogPolicyAAAGroupBinding, error) { + reqURL := fmt.Sprintf("%s/%s", auditNSLogPolicyAAAGroupBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditNSLogPolicyAAAGroupBinding `json:"auditnslogpolicy_aaagroup_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) CountAuditNSLogPolicyAAAGroupBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", auditNSLogPolicyAAAGroupBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"auditnslogpolicy_aaagroup_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // auditnslogpolicy_aaauser_binding // Binding object showing the aaauser that can be bound to auditnslogpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditnslogpolicy_aaauser_binding -func (s *AuditService) GetAllAuditNSLogPolicyAAAUserBinding() {} -func (s *AuditService) GetAuditNSLogPolicyAAAUserBinding() {} -func (s *AuditService) CountAuditNSLogPolicyAAAUserBinding() {} + +func (s *AuditService) GetAllAuditNSLogPolicyAAAUserBinding() ([]models.AuditNSLogPolicyAAAUserBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditNSLogPolicyAAAUserBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditNSLogPolicyAAAUserBinding `json:"auditnslogpolicy_aaauser_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) GetAuditNSLogPolicyAAAUserBinding(name string) ([]models.AuditNSLogPolicyAAAUserBinding, error) { + reqURL := fmt.Sprintf("%s/%s", auditNSLogPolicyAAAUserBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditNSLogPolicyAAAUserBinding `json:"auditnslogpolicy_aaauser_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) CountAuditNSLogPolicyAAAUserBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", auditNSLogPolicyAAAUserBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"auditnslogpolicy_aaauser_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // auditnslogpolicy_appfwglobal_binding // Binding object showing the appfwglobal that can be bound to auditnslogpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditnslogpolicy_appfwglobal_binding -func (s *AuditService) GetAllAuditNSLogPolicyAppFWGlobalBinding() {} -func (s *AuditService) GetAuditNSLogPolicyAppFWGlobalBinding() {} -func (s *AuditService) CountAuditNSLogPolicyAppFWGlobalBinding() {} + +func (s *AuditService) GetAllAuditNSLogPolicyAppFWGlobalBinding() ([]models.AuditNSLogPolicyAppFWGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditNSLogPolicyAppFWGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditNSLogPolicyAppFWGlobalBinding `json:"auditnslogpolicy_appfwglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) GetAuditNSLogPolicyAppFWGlobalBinding(name string) ([]models.AuditNSLogPolicyAppFWGlobalBinding, error) { + reqURL := fmt.Sprintf("%s/%s", auditNSLogPolicyAppFWGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditNSLogPolicyAppFWGlobalBinding `json:"auditnslogpolicy_appfwglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) CountAuditNSLogPolicyAppFWGlobalBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", auditNSLogPolicyAppFWGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"auditnslogpolicy_appfwglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // auditnslogpolicy_auditnslogglobal_binding // Binding object showing the auditnslogglobal that can be bound to auditnslogpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditnslogpolicy_auditnslogglobal_binding -func (s *AuditService) GetAllAuditLogPolicyAuditNSLogGlobalBinding() {} -func (s *AuditService) GetAuditLogPolicyAuditNSLogGlobalBinding() {} -func (s *AuditService) CountAuditLogPolicyAuditNSLogGlobalBinding() {} + +func (s *AuditService) GetAllAuditNSLogPolicyAuditNSLogGlobalBinding() ([]models.AuditNSLogPolicyAuditNSLogGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditNSLogPolicyAuditNSLogGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditNSLogPolicyAuditNSLogGlobalBinding `json:"auditnslogpolicy_auditnslogglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) GetAuditNSLogPolicyAuditNSLogGlobalBinding(name string) ([]models.AuditNSLogPolicyAuditNSLogGlobalBinding, error) { + reqURL := fmt.Sprintf("%s/%s", auditNSLogPolicyAuditNSLogGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditNSLogPolicyAuditNSLogGlobalBinding `json:"auditnslogpolicy_auditnslogglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) CountAuditNSLogPolicyAuditNSLogGlobalBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", auditNSLogPolicyAuditNSLogGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"auditnslogpolicy_auditnslogglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // auditnslogpolicy_authenticationvserver_binding // Binding object showing the authenticationvserver that can be bound to auditnslogpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditnslogpolicy_authenticationvserver_binding -func (s *AuditService) GetAllAuditNSLogPolicyAuthenticationVServerBinding() {} -func (s *AuditService) GetAuditNSLogPolicyAuthenticationVServerBinding() {} -func (s *AuditService) CountAuditNSLogPolicyAuthenticationVServerBinding() {} + +func (s *AuditService) GetAllAuditNSLogPolicyAuthenticationVServerBinding() ([]models.AuditNSLogPolicyAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditNSLogPolicyAuthenticationVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditNSLogPolicyAuthenticationVServerBinding `json:"auditnslogpolicy_authenticationvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) GetAuditNSLogPolicyAuthenticationVServerBinding(name string) ([]models.AuditNSLogPolicyAuthenticationVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", auditNSLogPolicyAuthenticationVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditNSLogPolicyAuthenticationVServerBinding `json:"auditnslogpolicy_authenticationvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) CountAuditNSLogPolicyAuthenticationVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", auditNSLogPolicyAuthenticationVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"auditnslogpolicy_authenticationvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // auditnslogpolicy_binding // Binding object which returns the resources bound to auditnslogpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditnslogpolicy_binding -func (s *AuditService) GetAllAuditNSLogPolicyBinding() {} -func (s *AuditService) GetAuditNSLogPolicyBinding() {} + +func (s *AuditService) GetAllAuditNSLogPolicyBinding() ([]models.AuditNSLogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditNSLogPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditNSLogPolicyBinding `json:"auditnslogpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) GetAuditNSLogPolicyBinding(name string) ([]models.AuditNSLogPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", auditNSLogPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditNSLogPolicyBinding `json:"auditnslogpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // auditnslogpolicy_csvserver_binding // Binding object showing the csvserver that can be bound to auditnslogpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditnslogpolicy_csvserver_binding -func (s *AuditService) GetAllAuditNSLogPolicyCSVServerBinding() {} -func (s *AuditService) GetAuditNSLogPolicyCSVServerBinding() {} -func (s *AuditService) CountAuditNSLogPolicyCSVServerBinding() {} + +func (s *AuditService) GetAllAuditNSLogPolicyCSVServerBinding() ([]models.AuditNSLogPolicyCSVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditNSLogPolicyCSVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditNSLogPolicyCSVServerBinding `json:"auditnslogpolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) GetAuditNSLogPolicyCSVServerBinding(name string) ([]models.AuditNSLogPolicyCSVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", auditNSLogPolicyCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditNSLogPolicyCSVServerBinding `json:"auditnslogpolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) CountAuditNSLogPolicyCSVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", auditNSLogPolicyCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"auditnslogpolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // auditnslogpolicy_lbvserver_binding // Binding object showing the lbvserver that can be bound to auditnslogpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditnslogpolicy_lbvserver_binding -func (s *AuditService) GetAllAuditNSLogPolicyLBVServerBinding() {} -func (s *AuditService) GetAuditNSLogPolicyLBVServerBinding() {} -func (s *AuditService) CountAuditNSLogPolicyLBVServerBinding() {} + +func (s *AuditService) GetAllAuditNSLogPolicyLBVServerBinding() ([]models.AuditNSLogPolicyLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditNSLogPolicyLBVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditNSLogPolicyLBVServerBinding `json:"auditnslogpolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) GetAuditNSLogPolicyLBVServerBinding(name string) ([]models.AuditNSLogPolicyLBVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", auditNSLogPolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditNSLogPolicyLBVServerBinding `json:"auditnslogpolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) CountAuditNSLogPolicyLBVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", auditNSLogPolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"auditnslogpolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // auditnslogpolicy_systemglobal_binding // Binding object showing the systemglobal that can be bound to auditnslogpolicy // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditnslogpolicy_systemglobal_binding -func (s *AuditService) GetAllAuditNSLogPolicySystemGlobalBinding() {} -func (s *AuditService) GetAuditNSLogPolicySystemGlobalBinding() {} -func (s *AuditService) CountAuditNSLogPolicySystemGlobalBinding() {} + +func (s *AuditService) GetAllAuditNSLogPolicySystemGlobalBinding() ([]models.AuditNSLogPolicySystemGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditNSLogPolicySystemGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditNSLogPolicySystemGlobalBinding `json:"auditnslogpolicy_systemglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) GetAuditNSLogPolicySystemGlobalBinding(name string) ([]models.AuditNSLogPolicySystemGlobalBinding, error) { + reqURL := fmt.Sprintf("%s/%s", auditNSLogPolicySystemGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditNSLogPolicySystemGlobalBinding `json:"auditnslogpolicy_systemglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) CountAuditNSLogPolicySystemGlobalBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", auditNSLogPolicySystemGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"auditnslogpolicy_systemglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // auditnslogpolicy_tmglobal_binding // Binding object showing the tmglobal that can be bound to auditnslogpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditnslogpolicy_tmglobal_binding -func (s *AuditService) GetAllAuditNSLogPolicyTMGlobalBinding() {} -func (s *AuditService) GetAuditNSLogPolicyTMGlobalBinding() {} -func (s *AuditService) CountAuditNSLogPolicyTMGlobalBinding() {} + +func (s *AuditService) GetAllAuditNSLogPolicyTMGlobalBinding() ([]models.AuditNSLogPolicyTMGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditNSLogPolicyTMGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditNSLogPolicyTMGlobalBinding `json:"auditnslogpolicy_tmglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) GetAuditNSLogPolicyTMGlobalBinding(name string) ([]models.AuditNSLogPolicyTMGlobalBinding, error) { + reqURL := fmt.Sprintf("%s/%s", auditNSLogPolicyTMGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditNSLogPolicyTMGlobalBinding `json:"auditnslogpolicy_tmglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) CountAuditNSLogPolicyTMGlobalBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", auditNSLogPolicyTMGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"auditnslogpolicy_tmglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // auditnslogpolicy_vpnglobal_binding // Binding object showing the vpnglobal that can be bound to auditnslogpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditnslogpolicy_vpnglobal_binding -func (s *AuditService) GetAllAuditNSLogPolicyVPNGlobalBinding() {} -func (s *AuditService) GetAuditNSLogPolicyVPNGlobalBinding() {} -func (s *AuditService) CountAuditNSLogPolicyVPNGlobalBinding() {} + +func (s *AuditService) GetAllAuditNSLogPolicyVPNGlobalBinding() ([]models.AuditNSLogPolicyVPNGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditNSLogPolicyVPNGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditNSLogPolicyVPNGlobalBinding `json:"auditnslogpolicy_vpnglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) GetAuditNSLogPolicyVPNGlobalBinding(name string) ([]models.AuditNSLogPolicyVPNGlobalBinding, error) { + reqURL := fmt.Sprintf("%s/%s", auditNSLogPolicyVPNGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditNSLogPolicyVPNGlobalBinding `json:"auditnslogpolicy_vpnglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) CountAuditNSLogPolicyVPNGlobalBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", auditNSLogPolicyVPNGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"auditnslogpolicy_vpnglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // auditnslogpolicy_vpnvserver_binding // Binding object showing the vpnvserver that can be bound to auditnslogpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditnslogpolicy_vpnvserver_binding -func (s *AuditService) GetAllAuditNSLogPolicyVPNVServerBinding() {} -func (s *AuditService) GetAuditNSLogPolicyVPNVServerBinding() {} -func (s *AuditService) CountAuditNSLogPolicyVPNVServerBinding() {} + +func (s *AuditService) GetAllAuditNSLogPolicyVPNVServerBinding() ([]models.AuditNSLogPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditNSLogPolicyVPNVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditNSLogPolicyVPNVServerBinding `json:"auditnslogpolicy_vpnvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) GetAuditNSLogPolicyVPNVServerBinding(name string) ([]models.AuditNSLogPolicyVPNVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", auditNSLogPolicyVPNVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditNSLogPolicyVPNVServerBinding `json:"auditnslogpolicy_vpnvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) CountAuditNSLogPolicyVPNVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", auditNSLogPolicyVPNVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"auditnslogpolicy_vpnvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // auditsyslogaction // Configuration for system log action resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditsyslogaction -func (s *AuditService) AddAuditSyslogAction() {} -func (s *AuditService) DeleteAuditSyslogAction() {} -func (s *AuditService) UpdateAuditSyslogAction() {} -func (s *AuditService) UnsetAuditSyslogAction() {} -func (s *AuditService) GetAllAuditSyslogAction() {} -func (s *AuditService) GetAuditSyslogAction() {} -func (s *AuditService) CountAuditSyslogAction() {} + +func (s *AuditService) AddAuditSyslogAction(action models.AuditSyslogAction) error { + payload := map[string]any{"auditsyslogaction": action} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, auditSyslogActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuditService) DeleteAuditSyslogAction(name string) error { + reqURL := fmt.Sprintf("%s/%s", auditSyslogActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuditService) UpdateAuditSyslogAction(action models.AuditSyslogAction) error { + payload := map[string]any{"auditsyslogaction": action} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, auditSyslogActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuditService) UnsetAuditSyslogAction(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"auditsyslogaction": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, auditSyslogActionURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuditService) GetAllAuditSyslogAction() ([]models.AuditSyslogAction, error) { + req, err := s.client.NewRequest(http.MethodGet, auditSyslogActionURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Actions []models.AuditSyslogAction `json:"auditsyslogaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Actions, nil +} + +func (s *AuditService) GetAuditSyslogAction(name string) ([]models.AuditSyslogAction, error) { + reqURL := fmt.Sprintf("%s/%s", auditSyslogActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Actions []models.AuditSyslogAction `json:"auditsyslogaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Actions, nil +} + +func (s *AuditService) CountAuditSyslogAction() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, auditSyslogActionURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Actions []struct { + Count float64 `json:"__count"` + } `json:"auditsyslogaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Actions) > 0 { + return result.Actions[0].Count, nil + } + return 0, nil +} // auditsyslogglobal_auditsyslogpolicy_binding // Binding object showing the auditsyslogpolicy that can be bound to auditsyslogglobal. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditsyslogglobal_auditsyslogpolicy_binding -func (s *AuditService) AddAuditSyslogGlobalAuditSyslogPolicyBinding() {} -func (s *AuditService) DeleteAuditSyslogGlobalAuditSyslogPolicyBinding() {} -func (s *AuditService) GetAuditSyslogGlobalAuditSyslogPolicyBinding() {} -func (s *AuditService) CountAuditSyslogGlobalAuditSyslogPolicyBinding() {} + +func (s *AuditService) AddAuditSyslogGlobalAuditSyslogPolicyBinding(binding models.AuditSyslogGlobalAuditSyslogPolicyBinding) error { + payload := map[string]any{"auditsyslogglobal_auditsyslogpolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, auditSyslogGlobalAuditSyslogPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuditService) DeleteAuditSyslogGlobalAuditSyslogPolicyBinding(policyname string) error { + reqURL := fmt.Sprintf("%s?args=policyname:%s", auditSyslogGlobalAuditSyslogPolicyBindingURL, url.QueryEscape(policyname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuditService) GetAuditSyslogGlobalAuditSyslogPolicyBinding() ([]models.AuditSyslogGlobalAuditSyslogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditSyslogGlobalAuditSyslogPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditSyslogGlobalAuditSyslogPolicyBinding `json:"auditsyslogglobal_auditsyslogpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) CountAuditSyslogGlobalAuditSyslogPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, auditSyslogGlobalAuditSyslogPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"auditsyslogglobal_auditsyslogpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // auditsyslogglobal_binding // Binding object which returns the resources bound to auditsyslogglobal. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditsyslogglobal_binding -func (s *AuditService) GetAuditSyslogGlobalBinding() {} + +func (s *AuditService) GetAuditSyslogGlobalBinding() ([]models.AuditSyslogGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditSyslogGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditSyslogGlobalBinding `json:"auditsyslogglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // auditsyslogparams // Configuration for system log parameters resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditsyslogparams -func (s *AuditService) UpdateAuditSyslogParams() {} -func (s *AuditService) UnsetAuditSyslogParams() {} -func (s *AuditService) GetAllAuditSyslogParams() {} + +func (s *AuditService) UpdateAuditSyslogParams(params models.AuditSyslogParams) error { + payload := map[string]any{"auditsyslogparams": params} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, auditSyslogParamsURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuditService) UnsetAuditSyslogParams(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"auditsyslogparams": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, auditSyslogParamsURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuditService) GetAllAuditSyslogParams() (models.AuditSyslogParams, error) { + req, err := s.client.NewRequest(http.MethodGet, auditSyslogParamsURL, nil) + if err != nil { + return models.AuditSyslogParams{}, err + } + resp, err := s.client.Do(req) + if err != nil { + return models.AuditSyslogParams{}, err + } + var result struct { + Params []models.AuditSyslogParams `json:"auditsyslogparams"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return models.AuditSyslogParams{}, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Params) > 0 { + return result.Params[0], nil + } + return models.AuditSyslogParams{}, nil +} // auditsyslogpolicy // Configuration for system log policy resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditsyslogpolicy -func (s *AuditService) AddAuditSyslogPolicy() {} -func (s *AuditService) DeleteAuditSyslogPolicy() {} -func (s *AuditService) UpdateAuditSyslogPolicy() {} -func (s *AuditService) GetAllAuditSyslogPolicy() {} -func (s *AuditService) GetAuditSyslogPolicy() {} -func (s *AuditService) CountAuditSyslogPolicy() {} + +func (s *AuditService) AddAuditSyslogPolicy(policy models.AuditSyslogPolicy) error { + payload := map[string]any{"auditsyslogpolicy": policy} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, auditSyslogPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuditService) DeleteAuditSyslogPolicy(name string) error { + reqURL := fmt.Sprintf("%s/%s", auditSyslogPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuditService) UpdateAuditSyslogPolicy(policy models.AuditSyslogPolicy) error { + payload := map[string]any{"auditsyslogpolicy": policy} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, auditSyslogPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuditService) GetAllAuditSyslogPolicy() ([]models.AuditSyslogPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, auditSyslogPolicyURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Policies []models.AuditSyslogPolicy `json:"auditsyslogpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Policies, nil +} + +func (s *AuditService) GetAuditSyslogPolicy(name string) ([]models.AuditSyslogPolicy, error) { + reqURL := fmt.Sprintf("%s/%s", auditSyslogPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Policies []models.AuditSyslogPolicy `json:"auditsyslogpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Policies, nil +} + +func (s *AuditService) CountAuditSyslogPolicy() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, auditSyslogPolicyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Policies []struct { + Count float64 `json:"__count"` + } `json:"auditsyslogpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Policies) > 0 { + return result.Policies[0].Count, nil + } + return 0, nil +} // auditsyslogpolicy_aaagroup_binding // Binding object showing the aaagroup that can be bound to auditsyslogpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditsyslogpolicy_aaagroup_binding -func (s *AuditService) GetAllAuditSyslogPolicyAAAGroupBinding() {} -func (s *AuditService) GetAuditSyslogPolicyAAAGroupBinding() {} -func (s *AuditService) CountAuditSyslogPolicyAAAGroupBinding() {} + +func (s *AuditService) GetAllAuditSyslogPolicyAAAGroupBinding() ([]models.AuditSyslogPolicyAAAGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditSyslogPolicyAAAGroupBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditSyslogPolicyAAAGroupBinding `json:"auditsyslogpolicy_aaagroup_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) GetAuditSyslogPolicyAAAGroupBinding(name string) ([]models.AuditSyslogPolicyAAAGroupBinding, error) { + reqURL := fmt.Sprintf("%s/%s", auditSyslogPolicyAAAGroupBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditSyslogPolicyAAAGroupBinding `json:"auditsyslogpolicy_aaagroup_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) CountAuditSyslogPolicyAAAGroupBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", auditSyslogPolicyAAAGroupBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"auditsyslogpolicy_aaagroup_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // auditsyslogpolicy_aaauser_binding // Binding object showing the aaauser that can be bound to auditsyslogpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditsyslogpolicy_aaauser_binding -func (s *AuditService) GetAllAuditSyslogPolicyAAAUserBinding() {} -func (s *AuditService) GetAuditSyslogPolicyAAAUserBinding() {} -func (s *AuditService) CountAuditSyslogPolicyAAAUserBinding() {} + +func (s *AuditService) GetAllAuditSyslogPolicyAAAUserBinding() ([]models.AuditSyslogPolicyAAAUserBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditSyslogPolicyAAAUserBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditSyslogPolicyAAAUserBinding `json:"auditsyslogpolicy_aaauser_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) GetAuditSyslogPolicyAAAUserBinding(name string) ([]models.AuditSyslogPolicyAAAUserBinding, error) { + reqURL := fmt.Sprintf("%s/%s", auditSyslogPolicyAAAUserBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditSyslogPolicyAAAUserBinding `json:"auditsyslogpolicy_aaauser_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) CountAuditSyslogPolicyAAAUserBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", auditSyslogPolicyAAAUserBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"auditsyslogpolicy_aaauser_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // auditsyslogpolicy_auditsyslogglobal_binding // Binding object showing the auditsyslogglobal that can be bound to auditsyslogpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditsyslogpolicy_auditsyslogglobal_binding -func (s *AuditService) GetAllAuditSyslogPolicyAuditSyslogGlobalBinding() {} -func (s *AuditService) GetAuditSyslogPolicyAuditSyslogGlobalBinding() {} -func (s *AuditService) CountAuditSyslogPolicyAuditSyslogGlobalBinding() {} + +func (s *AuditService) GetAllAuditSyslogPolicyAuditSyslogGlobalBinding() ([]models.AuditSyslogPolicyAuditSyslogGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditSyslogPolicyAuditSyslogGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditSyslogPolicyAuditSyslogGlobalBinding `json:"auditsyslogpolicy_auditsyslogglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) GetAuditSyslogPolicyAuditSyslogGlobalBinding(name string) ([]models.AuditSyslogPolicyAuditSyslogGlobalBinding, error) { + reqURL := fmt.Sprintf("%s/%s", auditSyslogPolicyAuditSyslogGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditSyslogPolicyAuditSyslogGlobalBinding `json:"auditsyslogpolicy_auditsyslogglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) CountAuditSyslogPolicyAuditSyslogGlobalBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", auditSyslogPolicyAuditSyslogGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"auditsyslogpolicy_auditsyslogglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // auditsyslogpolicy_authenticationvserver_binding // Binding object showing the authenticationvserver that can be bound to auditsyslogpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditsyslogpolicy_authenticationvserver_binding -func (s *AuditService) GetAllAuditSyslogPolicyAuthenticationVServerBinding() {} -func (s *AuditService) GetAuditSyslogPolicyAuthenticationVServerBinding() {} -func (s *AuditService) CountAuditSyslogPolicyAuthenticationVServerBinding() {} + +func (s *AuditService) GetAllAuditSyslogPolicyAuthenticationVServerBinding() ([]models.AuditSyslogPolicyAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditSyslogPolicyAuthenticationVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditSyslogPolicyAuthenticationVServerBinding `json:"auditsyslogpolicy_authenticationvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) GetAuditSyslogPolicyAuthenticationVServerBinding(name string) ([]models.AuditSyslogPolicyAuthenticationVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", auditSyslogPolicyAuthenticationVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditSyslogPolicyAuthenticationVServerBinding `json:"auditsyslogpolicy_authenticationvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) CountAuditSyslogPolicyAuthenticationVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", auditSyslogPolicyAuthenticationVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"auditsyslogpolicy_authenticationvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // auditsyslogpolicy_binding // Binding object which returns the resources bound to auditsyslogpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditsyslogpolicy_binding -func (s *AuditService) GetAllAuditSyslogPolicyBinding() {} -func (s *AuditService) GetAuditSyslogPolicyBinding() {} + +func (s *AuditService) GetAllAuditSyslogPolicyBinding() ([]models.AuditSyslogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditSyslogPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditSyslogPolicyBinding `json:"auditsyslogpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) GetAuditSyslogPolicyBinding(name string) ([]models.AuditSyslogPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", auditSyslogPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditSyslogPolicyBinding `json:"auditsyslogpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // auditsyslogpolicy_csvserver_binding // Binding object showing the csvserver that can be bound to auditsyslogpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditsyslogpolicy_csvserver_binding -func (s *AuditService) GetAllAuditSyslogPolicyCSVServerBinding() {} -func (s *AuditService) GetAuditSyslogPolicyCSVServerBinding() {} -func (s *AuditService) CountAuditSyslogPolicyCSVServerBinding() {} + +func (s *AuditService) GetAllAuditSyslogPolicyCSVServerBinding() ([]models.AuditSyslogPolicyCSVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditSyslogPolicyCSVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditSyslogPolicyCSVServerBinding `json:"auditsyslogpolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) GetAuditSyslogPolicyCSVServerBinding(name string) ([]models.AuditSyslogPolicyCSVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", auditSyslogPolicyCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditSyslogPolicyCSVServerBinding `json:"auditsyslogpolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) CountAuditSyslogPolicyCSVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", auditSyslogPolicyCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"auditsyslogpolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // auditsyslogpolicy_lbvserver_binding // Binding object showing the lbvserver that can be bound to auditsyslogpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditsyslogpolicy_lbvserver_binding -func (s *AuditService) GetAllAuditSyslogPolicyLBVServerBinding() {} -func (s *AuditService) GetAuditSyslogPolicyLBVServerBinding() {} -func (s *AuditService) CountAuditSyslogPolicyLBVServerBinding() {} + +func (s *AuditService) GetAllAuditSyslogPolicyLBVServerBinding() ([]models.AuditSyslogPolicyLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditSyslogPolicyLBVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditSyslogPolicyLBVServerBinding `json:"auditsyslogpolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) GetAuditSyslogPolicyLBVServerBinding(name string) ([]models.AuditSyslogPolicyLBVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", auditSyslogPolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditSyslogPolicyLBVServerBinding `json:"auditsyslogpolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) CountAuditSyslogPolicyLBVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", auditSyslogPolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"auditsyslogpolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // auditsyslogpolicy_rnatglobal_binding // Binding object showing the rnatglobal that can be bound to auditsyslogpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditsyslogpolicy_rnatglobal_binding -func (s *AuditService) GetAllAuditSyslogPolicyRNATGlobalBinding() {} -func (s *AuditService) GetAuditSyslogPolicyRNATGlobalBinding() {} -func (s *AuditService) CountAuditSyslogPolicyRNATGlobalBinding() {} + +func (s *AuditService) GetAllAuditSyslogPolicyRNATGlobalBinding() ([]models.AuditSyslogPolicyRNATGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditSyslogPolicyRNATGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditSyslogPolicyRNATGlobalBinding `json:"auditsyslogpolicy_rnatglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) GetAuditSyslogPolicyRNATGlobalBinding(name string) ([]models.AuditSyslogPolicyRNATGlobalBinding, error) { + reqURL := fmt.Sprintf("%s/%s", auditSyslogPolicyRNATGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditSyslogPolicyRNATGlobalBinding `json:"auditsyslogpolicy_rnatglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) CountAuditSyslogPolicyRNATGlobalBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", auditSyslogPolicyRNATGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"auditsyslogpolicy_rnatglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // auditsyslogpolicy_systemglobal_binding // Binding object showing the systemglobal that can be bound to auditsyslogpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditsyslogpolicy_systemglobal_binding -func (s *AuditService) GetAllAuditSyslogPolicySystemGlobalBinding() {} -func (s *AuditService) GetAuditSyslogPolicySystemGlobalBinding() {} -func (s *AuditService) CountAuditSyslogPolicySystemGlobalBinding() {} + +func (s *AuditService) GetAllAuditSyslogPolicySystemGlobalBinding() ([]models.AuditSyslogPolicySystemGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditSyslogPolicySystemGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditSyslogPolicySystemGlobalBinding `json:"auditsyslogpolicy_systemglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) GetAuditSyslogPolicySystemGlobalBinding(name string) ([]models.AuditSyslogPolicySystemGlobalBinding, error) { + reqURL := fmt.Sprintf("%s/%s", auditSyslogPolicySystemGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditSyslogPolicySystemGlobalBinding `json:"auditsyslogpolicy_systemglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) CountAuditSyslogPolicySystemGlobalBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", auditSyslogPolicySystemGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"auditsyslogpolicy_systemglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // auditsyslogpolicy_tmpglobal_binding // Binding object showing the tmglobal that can be bound to auditsyslogpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditsyslogpolicy_tmglobal_binding -func (s *AuditService) GetAllAuditSyslogPolicyTMGlobalBinding() {} -func (s *AuditService) GetAuditSyslogPolicyTMGlobalBinding() {} -func (s *AuditService) CountAuditSyslogPolicyTMGlobalBinding() {} + +func (s *AuditService) GetAllAuditSyslogPolicyTMGlobalBinding() ([]models.AuditSyslogPolicyTMGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditSyslogPolicyTMGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditSyslogPolicyTMGlobalBinding `json:"auditsyslogpolicy_tmglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) GetAuditSyslogPolicyTMGlobalBinding(name string) ([]models.AuditSyslogPolicyTMGlobalBinding, error) { + reqURL := fmt.Sprintf("%s/%s", auditSyslogPolicyTMGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditSyslogPolicyTMGlobalBinding `json:"auditsyslogpolicy_tmglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) CountAuditSyslogPolicyTMGlobalBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", auditSyslogPolicyTMGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"auditsyslogpolicy_tmglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // auditsyslogpolicy_vpnglobal_binding // Binding object showing the vpnglobal that can be bound to auditsyslogpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditsyslogpolicy_vpnglobal_binding -func (s *AuditService) GetAllAuditSyslogPolicyVPNGlobalBinding() {} -func (s *AuditService) GetAuditSyslogPolicyVPNGlobalBinding() {} -func (s *AuditService) CountAuditSyslogPolicyVPNGlobalBinding() {} + +func (s *AuditService) GetAllAuditSyslogPolicyVPNGlobalBinding() ([]models.AuditSyslogPolicyVPNGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditSyslogPolicyVPNGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditSyslogPolicyVPNGlobalBinding `json:"auditsyslogpolicy_vpnglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) GetAuditSyslogPolicyVPNGlobalBinding(name string) ([]models.AuditSyslogPolicyVPNGlobalBinding, error) { + reqURL := fmt.Sprintf("%s/%s", auditSyslogPolicyVPNGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditSyslogPolicyVPNGlobalBinding `json:"auditsyslogpolicy_vpnglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) CountAuditSyslogPolicyVPNGlobalBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", auditSyslogPolicyVPNGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"auditsyslogpolicy_vpnglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // auditsyslogpolicy_vpnvserver_binding // Binding object showing the vpnvserver that can be bound to auditsyslogpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/audit/auditsyslogpolicy_vpnvserver_binding -func (s *AuditService) GetAllAuditSyslogPolicyVPNVServerBinding() {} -func (s *AuditService) GetAuditSyslogPolicyVPNVServerBinding() {} -func (s *AuditService) CountAuditSyslogPolicyVPNVServerBinding() {} + +func (s *AuditService) GetAllAuditSyslogPolicyVPNVServerBinding() ([]models.AuditSyslogPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, auditSyslogPolicyVPNVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditSyslogPolicyVPNVServerBinding `json:"auditsyslogpolicy_vpnvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) GetAuditSyslogPolicyVPNVServerBinding(name string) ([]models.AuditSyslogPolicyVPNVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", auditSyslogPolicyVPNVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuditSyslogPolicyVPNVServerBinding `json:"auditsyslogpolicy_vpnvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuditService) CountAuditSyslogPolicyVPNVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", auditSyslogPolicyVPNVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"auditsyslogpolicy_vpnvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} diff --git a/nitrogo/authentication.go b/nitrogo/authentication.go index 90e4671..8f4b017 100644 --- a/nitrogo/authentication.go +++ b/nitrogo/authentication.go @@ -1,5 +1,128 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + authenticationADFSProxyProfileURL = "/nitro/v1/config/authenticationadfsproxyprofile" + authenticationAuthnProfileURL = "/nitro/v1/config/authenticationauthnprofile" + authenticationAzureKeyVaultURL = "/nitro/v1/config/authenticationazurekeyvault" + authenticationCaptchaActionURL = "/nitro/v1/config/authenticationcaptchaaction" + authenticationCertActionURL = "/nitro/v1/config/authenticationcertaction" + authenticationCertPolicyURL = "/nitro/v1/config/authenticationcertpolicy" + authenticationCertPolicyAuthenticationVServerBindingURL = "/nitro/v1/config/authenticationcertpolicy_authenticationvserver_binding" + authenticationCertPolicyBindingURL = "/nitro/v1/config/authenticationcertpolicy_binding" + authenticationCertPolicyVPNGlobalBindingURL = "/nitro/v1/config/authenticationcertpolicy_vpnglobal_binding" + authenticationCertPolicyVPNVServerBindingURL = "/nitro/v1/config/authenticationcertpolicy_vpnvserver_binding" + authenticationCitrixAuthActionURL = "/nitro/v1/config/authenticationcitrixauthaction" + authenticationDFAActionURL = "/nitro/v1/config/authenticationdfaaction" + authenticationDFAPolicyURL = "/nitro/v1/config/authenticationdfapolicy" + authenticationDFAPolicyBindingURL = "/nitro/v1/config/authenticationdfapolicy_binding" + authenticationDFAPolicyVPNVServerBindingURL = "/nitro/v1/config/authenticationdfapolicy_vpnvserver_binding" + authenticationEmailActionURL = "/nitro/v1/config/authenticationemailaction" + authenticationEPAActionURL = "/nitro/v1/config/authenticationepaaction" + authenticationLDAPActionURL = "/nitro/v1/config/authenticationldapaction" + authenticationLDAPPolicyURL = "/nitro/v1/config/authenticationldappolicy" + authenticationLDAPPolicyAuthenticationVServerBindingURL = "/nitro/v1/config/authenticationldappolicy_authenticationvserver_binding" + authenticationLDAPPolicyBindingURL = "/nitro/v1/config/authenticationldappolicy_binding" + authenticationLDAPPolicySystemGlobalBindingURL = "/nitro/v1/config/authenticationldappolicy_systemglobal_binding" + authenticationLDAPPolicyVPNGlobalBindingURL = "/nitro/v1/config/authenticationldappolicy_vpnglobal_binding" + authenticationLDAPPolicyVPNVServerBindingURL = "/nitro/v1/config/authenticationldappolicy_vpnvserver_binding" + authenticationLocalPolicyURL = "/nitro/v1/config/authenticationlocalpolicy" + authenticationLocalPolicyAuthenticationVServerBindingURL = "/nitro/v1/config/authenticationlocalpolicy_authenticationvserver_binding" + authenticationLocalPolicyBindingURL = "/nitro/v1/config/authenticationlocalpolicy_binding" + authenticationLocalPolicySystemGlobalBindingURL = "/nitro/v1/config/authenticationlocalpolicy_systemglobal_binding" + authenticationLocalPolicyVPNGlobalBindingURL = "/nitro/v1/config/authenticationlocalpolicy_vpnglobal_binding" + authenticationLocalPolicyVPNVServerBindingURL = "/nitro/v1/config/authenticationlocalpolicy_vpnvserver_binding" + authenticationLoginSchemaURL = "/nitro/v1/config/authenticationloginschema" + authenticationLoginSchemaPolicyURL = "/nitro/v1/config/authenticationloginschemapolicy" + authenticationLoginSchemaPolicyAuthenticationVServerBindingURL = "/nitro/v1/config/authenticationloginschemapolicy_authenticationvserver_binding" + authenticationLoginSchemaPolicyBindingURL = "/nitro/v1/config/authenticationloginschemapolicy_binding" + authenticationLoginSchemaPolicyVPNVServerBindingURL = "/nitro/v1/config/authenticationloginschemapolicy_vpnvserver_binding" + authenticationNegotiateActionURL = "/nitro/v1/config/authenticationnegotiateaction" + authenticationNegotiatePolicyURL = "/nitro/v1/config/authenticationnegotiatepolicy" + authenticationNegotiatePolicyAuthenticationVServerBindingURL = "/nitro/v1/config/authenticationnegotiatepolicy_authenticationvserver_binding" + authenticationNegotiatePolicyBindingURL = "/nitro/v1/config/authenticationnegotiatepolicy_binding" + authenticationNegotiatePolicyVPNGlobalBindingURL = "/nitro/v1/config/authenticationnegotiatepolicy_vpnglobal_binding" + authenticationNegotiatePolicyVPNVServerBindingURL = "/nitro/v1/config/authenticationnegotiatepolicy_vpnvserver_binding" + authenticationNoAuthActionURL = "/nitro/v1/config/authenticationnoauthaction" + authenticationOAuthActionURL = "/nitro/v1/config/authenticationoauthaction" + authenticationOAuthIdPPolicyURL = "/nitro/v1/config/authenticationoauthidppolicy" + authenticationOAuthIdPPolicyAuthenticationVServerBindingURL = "/nitro/v1/config/authenticationoauthidppolicy_authenticationvserver_binding" + authenticationOAuthIdPPolicyBindingURL = "/nitro/v1/config/authenticationoauthidppolicy_binding" + authenticationOAuthIdPPolicyVPNVServerBindingURL = "/nitro/v1/config/authenticationoauthidppolicy_vpnvserver_binding" + authenticationOAuthIdPProfileURL = "/nitro/v1/config/authenticationoauthidpprofile" + authenticationPolicyURL = "/nitro/v1/config/authenticationpolicy" + authenticationPolicyLabelURL = "/nitro/v1/config/authenticationpolicylabel" + authenticationPolicyLabelAuthenticationPolicyBindingURL = "/nitro/v1/config/authenticationpolicylabel_authenticationpolicy_binding" + authenticationPolicyLabelBindingURL = "/nitro/v1/config/authenticationpolicylabel_binding" + authenticationPolicyAuthenticationPolicyLabelBindingURL = "/nitro/v1/config/authenticationpolicy_authenticationpolicylabel_binding" + authenticationPolicyAuthenticationVServerBindingURL = "/nitro/v1/config/authenticationpolicy_authenticationvserver_binding" + authenticationPolicyBindingURL = "/nitro/v1/config/authenticationpolicy_binding" + authenticationPolicySystemGlobalBindingURL = "/nitro/v1/config/authenticationpolicy_systemglobal_binding" + authenticationPushServiceURL = "/nitro/v1/config/authenticationpushservice" + authenticationRADIUSActionURL = "/nitro/v1/config/authenticationradiusaction" + authenticationRADIUSPolicyURL = "/nitro/v1/config/authenticationradiuspolicy" + authenticationRADIUSPolicyAuthenticationVServerBindingURL = "/nitro/v1/config/authenticationradiuspolicy_authenticationvserver_binding" + authenticationRADIUSPolicyBindingURL = "/nitro/v1/config/authenticationradiuspolicy_binding" + authenticationRADIUSPolicySystemGlobalBindingURL = "/nitro/v1/config/authenticationradiuspolicy_systemglobal_binding" + authenticationRADIUSPolicyVPNGlobalBindingURL = "/nitro/v1/config/authenticationradiuspolicy_vpnglobal_binding" + authenticationRADIUSPolicyVPNVServerBindingURL = "/nitro/v1/config/authenticationradiuspolicy_vpnvserver_binding" + authenticationSAMLActionURL = "/nitro/v1/config/authenticationsamlaction" + authenticationSAMLIdPPolicyURL = "/nitro/v1/config/authenticationsamlidppolicy" + authenticationSAMLIdPPolicyAuthenticationVServerBindingURL = "/nitro/v1/config/authenticationsamlidppolicy_authenticationvserver_binding" + authenticationSAMLIdPPolicyBindingURL = "/nitro/v1/config/authenticationsamlidppolicy_binding" + authenticationSAMLIdPPolicyVPNVServerBindingURL = "/nitro/v1/config/authenticationsamlidppolicy_vpnvserver_binding" + authenticationSAMLIdPProfileURL = "/nitro/v1/config/authenticationsamlidpprofile" + authenticationSAMLPolicyURL = "/nitro/v1/config/authenticationsamlpolicy" + authenticationSAMLPolicyAuthenticationVServerBindingURL = "/nitro/v1/config/authenticationsamlpolicy_authenticationvserver_binding" + authenticationSAMLPolicyBindingURL = "/nitro/v1/config/authenticationsamlpolicy_binding" + authenticationSAMLPolicyVPNGlobalBindingURL = "/nitro/v1/config/authenticationsamlpolicy_vpnglobal_binding" + authenticationSAMLPolicyVPNVServerBindingURL = "/nitro/v1/config/authenticationsamlpolicy_vpnvserver_binding" + authenticationStoreFrontAuthActionURL = "/nitro/v1/config/authenticationstorefrontauthaction" + authenticationTACACSActionURL = "/nitro/v1/config/authenticationtacacsaction" + authenticationTACACSPolicyURL = "/nitro/v1/config/authenticationtacacspolicy" + authenticationTACACSPolicyAuthenticationVServerBindingURL = "/nitro/v1/config/authenticationtacacspolicy_authenticationvserver_binding" + authenticationTACACSPolicyBindingURL = "/nitro/v1/config/authenticationtacacspolicy_binding" + authenticationTACACSPolicySystemGlobalBindingURL = "/nitro/v1/config/authenticationtacacspolicy_systemglobal_binding" + authenticationTACACSPolicyVPNGlobalBindingURL = "/nitro/v1/config/authenticationtacacspolicy_vpnglobal_binding" + authenticationTACACSPolicyVPNVServerBindingURL = "/nitro/v1/config/authenticationtacacspolicy_vpnvserver_binding" + authenticationVServerURL = "/nitro/v1/config/authenticationvserver" + authenticationVServerAuditNSLogPolicyBindingURL = "/nitro/v1/config/authenticationvserver_auditnslogpolicy_binding" + authenticationVServerAuditSyslogPolicyBindingURL = "/nitro/v1/config/authenticationvserver_auditsyslogpolicy_binding" + authenticationVServerAuthenticationCertPolicyBindingURL = "/nitro/v1/config/authenticationvserver_authenticationcertpolicy_binding" + authenticationVServerAuthenticationLDAPPolicyBindingURL = "/nitro/v1/config/authenticationvserver_authenticationldappolicy_binding" + authenticationVServerAuthenticationLocalPolicyBindingURL = "/nitro/v1/config/authenticationvserver_authenticationlocalpolicy_binding" + authenticationVServerAuthenticationLoginSchemaPolicyBindingURL = "/nitro/v1/config/authenticationvserver_authenticationloginschemapolicy_binding" + authenticationVServerAuthenticationNegotiatePolicyBindingURL = "/nitro/v1/config/authenticationvserver_authenticationnegotiatepolicy_binding" + authenticationVServerAuthenticationOAuthIdPPolicyBindingURL = "/nitro/v1/config/authenticationvserver_authenticationoauthidppolicy_binding" + authenticationVServerAuthenticationPolicyBindingURL = "/nitro/v1/config/authenticationvserver_authenticationpolicy_binding" + authenticationVServerAuthenticationRADIUSPolicyBindingURL = "/nitro/v1/config/authenticationvserver_authenticationradiuspolicy_binding" + authenticationVServerAuthenticationSAMLIdPPolicyBindingURL = "/nitro/v1/config/authenticationvserver_authenticationsamlidppolicy_binding" + authenticationVServerAuthenticationSAMLPolicyBindingURL = "/nitro/v1/config/authenticationvserver_authenticationsamlpolicy_binding" + authenticationVServerAuthenticationTACACSPolicyBindingURL = "/nitro/v1/config/authenticationvserver_authenticationtacacspolicy_binding" + authenticationVServerAuthenticationWebAuthPolicyBindingURL = "/nitro/v1/config/authenticationvserver_authenticationwebauthpolicy_binding" + authenticationVServerBindingURL = "/nitro/v1/config/authenticationvserver_binding" + authenticationVServerCachePolicyBindingURL = "/nitro/v1/config/authenticationvserver_cachepolicy_binding" + authenticationVServerCSPolicyBindingURL = "/nitro/v1/config/authenticationvserver_cspolicy_binding" + authenticationVServerResponderPolicyBindingURL = "/nitro/v1/config/authenticationvserver_responderpolicy_binding" + authenticationVServerTMSessionPolicyBindingURL = "/nitro/v1/config/authenticationvserver_tmsessionpolicy_binding" + authenticationVServerVPNPortalThemeBindingURL = "/nitro/v1/config/authenticationvserver_vpnportaltheme_binding" + authenticationWebAuthActionURL = "/nitro/v1/config/authenticationwebauthaction" + authenticationWebAuthPolicyURL = "/nitro/v1/config/authenticationwebauthpolicy" + authenticationWebAuthPolicyAuthenticationVServerBindingURL = "/nitro/v1/config/authenticationwebauthpolicy_authenticationvserver_binding" + authenticationWebAuthPolicyBindingURL = "/nitro/v1/config/authenticationwebauthpolicy_binding" + authenticationWebAuthPolicySystemGlobalBindingURL = "/nitro/v1/config/authenticationwebauthpolicy_systemglobal_binding" + authenticationWebAuthPolicyVPNGlobalBindingURL = "/nitro/v1/config/authenticationwebauthpolicy_vpnglobal_binding" + authenticationWebAuthPolicyVPNVServerBindingURL = "/nitro/v1/config/authenticationwebauthpolicy_vpnvserver_binding" +) + // Authentication configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authentication type AuthenticationService struct { @@ -9,951 +132,10566 @@ type AuthenticationService struct { // authenticationadfsproxyprofile // Configuration for ADFSProxy Profile resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationadfsproxyprofile -func (s *AuthenticationService) AddAuthenticationADFSProxyProfile() {} -func (s *AuthenticationService) DeleteAuthenticationADFSProxyProfile() {} -func (s *AuthenticationService) UpdateAuthenticationADFSProxyProfile() {} -func (s *AuthenticationService) GetAllAuthenticationADFSProxyProfile() {} -func (s *AuthenticationService) GetAuthenticationADFSProxyProfile() {} -func (s *AuthenticationService) CountAuthenticationADFSProxyProfile() {} +func (s *AuthenticationService) AddAuthenticationADFSProxyProfile(resource models.AuthenticationADFSProxyProfile) error { + payload := map[string]any{"authenticationadfsproxyprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// authenticationauthnprofile -// Configuration for Authentication profile resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationauthnprofile -func (s *AuthenticationService) AddAuthenticationAuthnProfile() {} -func (s *AuthenticationService) DeleteAuthenticationAuthnProfile() {} -func (s *AuthenticationService) UpdateAuthenticationAuthnProfile() {} -func (s *AuthenticationService) UnsetAuthenticationAuthnProfile() {} -func (s *AuthenticationService) GetAllAuthenticationAuthnProfile() {} -func (s *AuthenticationService) GetAuthenticationAuthnProfile() {} -func (s *AuthenticationService) CountAuthenticationAuthnProfile() {} + req, err := s.client.NewRequest(http.MethodPost, authenticationADFSProxyProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } -// authenticationazurekeyvault -// Configuration for Azure Key Vault entity resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationazurekeyvault -func (s *AuthenticationService) AddAuthenticationAzureKeyVault() {} -func (s *AuthenticationService) DeleteAuthenticationAzureKeyVault() {} -func (s *AuthenticationService) UpdateAuthenticationAzureKeyVault() {} -func (s *AuthenticationService) UnsetAuthenticationAzureKeyVault() {} -func (s *AuthenticationService) GetAllAuthenticationAzureKeyVault() {} -func (s *AuthenticationService) GetAuthenticationAzureKeyVault() {} -func (s *AuthenticationService) CountAuthenticationAzureKeyVault() {} + _, err = s.client.Do(req) + return err +} -// authenticationcaptchaaction -// Configuration for Captcha Action resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationcaptchaaction -func (s *AuthenticationService) AddAuthenticationCaptchaAction() {} -func (s *AuthenticationService) DeleteAuthenticationCaptchaAction() {} -func (s *AuthenticationService) UpdateAuthenticationCaptchaAction() {} -func (s *AuthenticationService) UnsetAuthenticationCaptchaAction() {} -func (s *AuthenticationService) GetAllAuthenticationCaptchaAction() {} -func (s *AuthenticationService) GetAuthenticationCaptchaAction() {} -func (s *AuthenticationService) CountAuthenticationCaptchaAction() {} +func (s *AuthenticationService) DeleteAuthenticationADFSProxyProfile(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationADFSProxyProfileURL, name), nil) + if err != nil { + return err + } -// authenticationcertaction -// Configuration for CERT action resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationcertaction -func (s *AuthenticationService) AddAuthenticationCertAction() {} -func (s *AuthenticationService) DeleteAuthenticationCertAction() {} -func (s *AuthenticationService) UpdateAuthenticationCertAction() {} -func (s *AuthenticationService) UnsetAuthenticationCertAction() {} -func (s *AuthenticationService) GetAllAuthenticationCertAction() {} -func (s *AuthenticationService) GetAuthenticationCertAction() {} -func (s *AuthenticationService) CountAuthenticationCertAction() {} + _, err = s.client.Do(req) + return err +} -// authenticationcertpolicy -// Configuration for CERT policy resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationcertpolicy -func (s *AuthenticationService) AddAuthenticationCertPolicy() {} -func (s *AuthenticationService) DeleteAuthenticationCertPolicy() {} -func (s *AuthenticationService) UpdateAuthenticationCertPolicy() {} -func (s *AuthenticationService) UnsetAuthenticationCertPolicy() {} -func (s *AuthenticationService) GetAllAuthenticationCertPolicy() {} -func (s *AuthenticationService) GetAuthenticationCertPolicy() {} -func (s *AuthenticationService) CountAuthenticationCertPolicy() {} +func (s *AuthenticationService) UpdateAuthenticationADFSProxyProfile(resource models.AuthenticationADFSProxyProfile) error { + payload := map[string]any{"authenticationadfsproxyprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// authenticationcertpolicy_authenticationvserver_binding -// Binding object showing the authenticationvserver that can be bound to authenticationcertpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationcertpolicy_authenticationvserver_binding -func (s *AuthenticationService) GetAllAuthenticationCertPolicyAuthenticationVServerBinding() {} -func (s *AuthenticationService) GetAuthenticationCertPolicyAuthenticationVServerBinding() {} -func (s *AuthenticationService) CountAuthenticationCertPolicyAuthenticationVServerBinding() {} + req, err := s.client.NewRequest(http.MethodPut, authenticationADFSProxyProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } -// authenticationcertpolicy_binding -// Binding object which returns the resources bound to authenticationcertpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationcertpolicy_binding -func (s *AuthenticationService) GetAllAuthenticationCertPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationCertPolicyBinding() {} + _, err = s.client.Do(req) + return err +} -// authenticationcertpolicy_vpnglobal_binding -// Binding object showing the vpnglobal that can be bound to authenticationcertpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationcertpolicy_vpnglobal_binding -func (s *AuthenticationService) GetAllAuthenticationCertPolicyVPNGlobalBinding() {} -func (s *AuthenticationService) GetAuthenticationCertPolicyVPNGlobalBinding() {} -func (s *AuthenticationService) CountAuthenticationCertPolicyVPNGlobalBinding() {} +func (s *AuthenticationService) GetAllAuthenticationADFSProxyProfile() ([]models.AuthenticationADFSProxyProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationADFSProxyProfileURL, nil) + if err != nil { + return nil, err + } -// authenticationcertpolicy_vpnvserver_binding -// Binding object showing the vpnvserver that can be bound to authenticationcertpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationcertpolicy_vpnvserver_binding -func (s *AuthenticationService) GetAllAuthenticationCertPolicyVPNVServerBinding() {} -func (s *AuthenticationService) GetAuthenticationCertPolicyVPNVServerBinding() {} -func (s *AuthenticationService) CountAuthenticationCertPolicyVPNVServerBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// authenticationcitrixauthaction -// Configuration for Citrix Authentication action resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationcitrixauthaction -func (s *AuthenticationService) AddAuthenticationCitrixAuthAction() {} -func (s *AuthenticationService) DeleteAuthenticationCitrixAuthAction() {} -func (s *AuthenticationService) UpdateAuthenticationCitrixAuthAction() {} -func (s *AuthenticationService) UnsetAuthenticationCitrixAuthAction() {} -func (s *AuthenticationService) GetAllAuthenticationCitrixAuthAction() {} -func (s *AuthenticationService) GetAuthenticationCitrixAuthAction() {} -func (s *AuthenticationService) CountAuthenticationCitrixAuthAction() {} + var result struct { + Data []models.AuthenticationADFSProxyProfile `json:"authenticationadfsproxyprofile"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } -// authenticationdfaaction -// Configuration for Dfa authentication action resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationdfaaction -func (s *AuthenticationService) AddAuthenticationDFAAction() {} -func (s *AuthenticationService) DeleteAuthenticationDFAAction() {} -func (s *AuthenticationService) UpdateAuthenticationDFAAction() {} -func (s *AuthenticationService) UnsetAuthenticationDFAAction() {} -func (s *AuthenticationService) GetAllAuthenticationDFAAction() {} -func (s *AuthenticationService) GetAuthenticationDFAAction() {} -func (s *AuthenticationService) CountAuthenticationDFAAction() {} + return result.Data, nil +} -// authenticationdfapolicy -// Configuration for Dfa authentication policy resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationdfapolicy -func (s *AuthenticationService) AddAuthenticationDFAPolicy() {} -func (s *AuthenticationService) DeleteAuthenticationDFAPolicy() {} -func (s *AuthenticationService) UpdateAuthenticationDFAPolicy() {} -func (s *AuthenticationService) GetAllAuthenticationDFAPolicy() {} -func (s *AuthenticationService) GetAuthenticationDFAPolicy() {} -func (s *AuthenticationService) CountAuthenticationDFAPolicy() {} +func (s *AuthenticationService) GetAuthenticationADFSProxyProfile(name string) (*models.AuthenticationADFSProxyProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationADFSProxyProfileURL, name), nil) + if err != nil { + return nil, err + } -// authenticationdfapolicy_binding -// Binding object which returns the resources bound to authenticationdfapolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationdfapolicy_binding -func (s *AuthenticationService) GetAllAuthenticationDFAPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationDFAPolicyBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// authenticationdfapolicy_vpnvserver_binding -// Binding object showing the vpnvserver that can be bound to authenticationdfapolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationdfapolicy_vpnvserver_binding -func (s *AuthenticationService) GetAllAuthenticationDFAPolicyVPNVServerBinding() {} -func (s *AuthenticationService) GetAuthenticationDFAPolicyVPNVServerBinding() {} -func (s *AuthenticationService) CountAuthenticationDFAPolicyVPNVServerBinding() {} + var result struct { + Data []models.AuthenticationADFSProxyProfile `json:"authenticationadfsproxyprofile"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } -// authenticationemailaction -// Configuration for Email entity resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationemailaction -func (s *AuthenticationService) AddAuthenticationEmailAction() {} -func (s *AuthenticationService) DeleteAuthenticationEmailAction() {} -func (s *AuthenticationService) UpdateAuthenticationEmailAction() {} -func (s *AuthenticationService) UnsetAuthenticationEmailAction() {} -func (s *AuthenticationService) GetAllAuthenticationEmailAction() {} -func (s *AuthenticationService) GetAuthenticationEmailAction() {} -func (s *AuthenticationService) CountAuthenticationEmailAction() {} + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationadfsproxyprofile %s not found", name) + } -// authenticationepaaction -// Configuration for epa action resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationepaaction -func (s *AuthenticationService) AddAuthenticationEPAAction() {} -func (s *AuthenticationService) DeleteAuthenticationEPAAction() {} -func (s *AuthenticationService) UpdateAuthenticationEPAAction() {} -func (s *AuthenticationService) UnsetAuthenticationEPAAction() {} -func (s *AuthenticationService) GetAllAuthenticationEPAAction() {} -func (s *AuthenticationService) GetAuthenticationEPAAction() {} -func (s *AuthenticationService) CountAuthenticationEPAAction() {} + return &result.Data[0], nil +} -// authenticationldapaction -// Configuration for LDAP action resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationldapaction -func (s *AuthenticationService) AddAuthenticationLDAPAction() {} -func (s *AuthenticationService) DeleteAuthenticationLDAPAction() {} -func (s *AuthenticationService) UpdateAuthenticationLDAPAction() {} -func (s *AuthenticationService) UnsetAuthenticationLDAPAction() {} -func (s *AuthenticationService) GetAllAuthenticationLDAPAction() {} -func (s *AuthenticationService) GetAuthenticationLDAPAction() {} -func (s *AuthenticationService) CountAuthenticationLDAPAction() {} +func (s *AuthenticationService) CountAuthenticationADFSProxyProfile() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationADFSProxyProfileURL), nil) + if err != nil { + return 0, err + } -// authenticationldappolicy -// Configuration for LDAP policy resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationldappolicy -func (s *AuthenticationService) AddAuthenticationLDAPPolicy() {} -func (s *AuthenticationService) DeleteAuthenticationLDAPPolicy() {} -func (s *AuthenticationService) UpdateAuthenticationLDAPPolicy() {} -func (s *AuthenticationService) UnsetAuthenticationLDAPPolicy() {} -func (s *AuthenticationService) GetAllAuthenticationLDAPPolicy() {} -func (s *AuthenticationService) GetAuthenticationLDAPPolicy() {} -func (s *AuthenticationService) CountAuthenticationLDAPPolicy() {} + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } -// authenticationldappolicy_authenticationvserver_binding -// Binding object showing the authenticationvserver that can be bound to authenticationldappolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationldappolicy_authenticationvserver_binding -func (s *AuthenticationService) GetAllAuthenticationLDAPPolicyAuthenticationVServerBinding() {} -func (s *AuthenticationService) GetAuthenticationLDAPPolicyAuthenticationVServerBinding() {} -func (s *AuthenticationService) CountAuthenticationLDAPPolicyAuthenticationVServerBinding() {} + var result struct { + Data []models.AuthenticationADFSProxyProfile `json:"authenticationadfsproxyprofile"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } -// authenticationldappolicy_binding -// Binding object which returns the resources bound to authenticationldappolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationldappolicy_binding -func (s *AuthenticationService) GetAllAuthenticationLDAPPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationLDAPPolicyBinding() {} + if len(result.Data) == 0 { + return 0, nil + } -// authenticationldappolicy_systemglobal_binding -// Binding object showing the systemglobal that can be bound to authenticationldappolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationldappolicy_systemglobal_binding -func (s *AuthenticationService) GetAllAuthenticationLDAPPolicySystemGlobalBinding() {} -func (s *AuthenticationService) GetAuthenticationLDAPPolicySystemGlobalBinding() {} -func (s *AuthenticationService) CountAuthenticationLDAPPolicySystemGlobalBinding() {} + return int(result.Data[0].Count), nil +} -// authenticationldappolicy_vpnglobal_binding -// Binding object showing the vpnglobal that can be bound to authenticationldappolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationldappolicy_vpnglobal_binding -func (s *AuthenticationService) GetAllAuthenticationLDAPPolicyVPNGlobalBinding() {} -func (s *AuthenticationService) GetAuthenticationLDAPPolicyVPNGlobalBinding() {} -func (s *AuthenticationService) CountAuthenticationLDAPPolicyVPNGlobalBinding() {} +// authenticationauthnprofile +// Configuration for Authentication profile resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationauthnprofile +func (s *AuthenticationService) AddAuthenticationAuthnProfile(resource models.AuthenticationAuthNProfile) error { + payload := map[string]any{"authenticationauthnprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// authenticationldappolicy_vpnvserver_binding -// Binding object showing the vpnvserver that can be bound to authenticationldappolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationldappolicy_vpnvserver_binding -func (s *AuthenticationService) GetAllAuthenticationLDAPPolicyVPNVServerBinding() {} -func (s *AuthenticationService) GetAuthenticationLDAPPolicyVPNVServerBinding() {} -func (s *AuthenticationService) CountAuthenticationLDAPPolicyVPNVServerBinding() {} + req, err := s.client.NewRequest(http.MethodPost, authenticationAuthnProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } -// authenticationlocalpolicy -// Configuration for LOCAL policy resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationlocalpolicy -func (s *AuthenticationService) AddAuthenticationLocalPolicy() {} -func (s *AuthenticationService) DeleteAuthenticationLocalPolicy() {} -func (s *AuthenticationService) UpdateAuthenticationLocalPolicy() {} -func (s *AuthenticationService) GetAllAuthenticationLocalPolicy() {} -func (s *AuthenticationService) GetAuthenticationLocalPolicy() {} -func (s *AuthenticationService) CountAuthenticationLocalPolicy() {} + _, err = s.client.Do(req) + return err +} -// authenticationlocalpolicy_authenticationvserver_binding -// Binding object showing the authenticationvserver that can be bound to authenticationlocalpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationlocalpolicy_authenticationvserver_binding -func (s *AuthenticationService) GetAllAuthenticationLocalPolicyAuthenticationVServerBinding() {} -func (s *AuthenticationService) GetAuthenticationLocalPolicyAuthenticationVServerBinding() {} -func (s *AuthenticationService) CountAuthenticationLocalPolicyAuthenticationVServerBinding() {} +func (s *AuthenticationService) DeleteAuthenticationAuthnProfile(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationAuthnProfileURL, name), nil) + if err != nil { + return err + } -// authenticationlocalpolicy_binding -// Binding object which returns the resources bound to authenticationlocalpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationlocalpolicy_binding -func (s *AuthenticationService) GetAllAuthenticationLocalPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationLocalPolicyBinding() {} + _, err = s.client.Do(req) + return err +} -// authenticationlocalpolicy_systemglobal_binding -// Binding object showing the systemglobal that can be bound to authenticationlocalpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationlocalpolicy_systemglobal_binding -func (s *AuthenticationService) GetAllAuthenticationLocalPolicySystemGlobalBinding() {} -func (s *AuthenticationService) GetAuthenticationLocalPolicySystemGlobalBinding() {} -func (s *AuthenticationService) CountAuthenticationLocalPolicySystemGlobalBinding() {} +func (s *AuthenticationService) UpdateAuthenticationAuthnProfile(resource models.AuthenticationAuthNProfile) error { + payload := map[string]any{"authenticationauthnprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// authenticationlocalpolicy_vpnglobal_binding -// Binding object showing the vpnglobal that can be bound to authenticationlocalpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationlocalpolicy_vpnglobal_binding -func (s *AuthenticationService) GetAllAuthenticationLocalPolicyVPNGlobalBinding() {} -func (s *AuthenticationService) GetAuthenticationLocalPolicyVPNGlobalBinding() {} -func (s *AuthenticationService) CountAuthenticationLocalPolicyVPNGlobalBinding() {} + req, err := s.client.NewRequest(http.MethodPut, authenticationAuthnProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } -// authenticationlocalpolicy_vpnvserver_binding -// Binding object showing the vpnvserver that can be bound to authenticationlocalpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationlocalpolicy_vpnvserver_binding -func (s *AuthenticationService) GetAllAuthenticationLocalPolicyVPNVServerBinding() {} -func (s *AuthenticationService) GetAuthenticationLocalPolicyVPNVServerBinding() {} -func (s *AuthenticationService) CountAuthenticationLocalPolicyVPNVServerBinding() {} + _, err = s.client.Do(req) + return err +} -// authenticationloginscheme -// Configuration for 0 resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationloginschema -func (s *AuthenticationService) AddAuthenticationLoginScheme() {} -func (s *AuthenticationService) DeleteAuthenticationLoginScheme() {} -func (s *AuthenticationService) UpdateAuthenticationLoginScheme() {} -func (s *AuthenticationService) UnsetAuthenticationLoginScheme() {} -func (s *AuthenticationService) GetAllAuthenticationLoginScheme() {} -func (s *AuthenticationService) GetAuthenticationLoginScheme() {} -func (s *AuthenticationService) CountAuthenticationLoginScheme() {} +func (s *AuthenticationService) UnsetAuthenticationAuthnProfile(resource models.AuthenticationAuthNProfile) error { + payload := map[string]any{"authenticationauthnprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// authenticationloginschemapolicy -// Configuration for 0 resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationloginschemapolicy -func (s *AuthenticationService) AddAuthenticationLoginSchemaPolicy() {} -func (s *AuthenticationService) DeleteAuthenticationLoginSchemaPolicy() {} -func (s *AuthenticationService) UpdateAuthenticationLoginSchemaPolicy() {} -func (s *AuthenticationService) UnsetAuthenticationLoginSchemaPolicy() {} -func (s *AuthenticationService) GetAllAuthenticationLoginSchemaPolicy() {} -func (s *AuthenticationService) GetAuthenticationLoginSchemaPolicy() {} -func (s *AuthenticationService) CountAuthenticationLoginSchemaPolicy() {} -func (s *AuthenticationService) RenameAuthenticationLoginSchemaPolicy() {} + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationAuthnProfileURL), bytes.NewReader(data)) + if err != nil { + return err + } -// authenticationloginschemapolicy_authenticationvserver_binding -// Binding object showing the authenticationvserver that can be bound to authenticationloginschemapolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationloginschemapolicy_authenticationvserver_binding -func (s *AuthenticationService) GetAllAuthenticationLoginSchemaPolicyAuthenticationVServerBinding() {} -func (s *AuthenticationService) GetAuthenticationLoginSchemaPolicyAuthenticationVServerBinding() {} -func (s *AuthenticationService) CountAuthenticationLoginSchemaPolicyAuthenticationVServerBinding() {} + _, err = s.client.Do(req) + return err +} -// authenticationloginschemapolicy_binding -// Binding object which returns the resources bound to authenticationloginschemapolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationloginschemapolicy_binding -func (s *AuthenticationService) GetAllAuthenticationLoginSchemaPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationLoginSchemaPolicyBinding() {} +func (s *AuthenticationService) GetAllAuthenticationAuthnProfile() ([]models.AuthenticationAuthNProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationAuthnProfileURL, nil) + if err != nil { + return nil, err + } -// authenticationloginschemapolicy_vpnvserver_binding -// Binding object showing the vpnvserver that can be bound to authenticationloginschemapolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationloginschemapolicy_vpnvserver_binding -func (s *AuthenticationService) GetAllAuthenticationLoginSchemaPolicyVPNVServerBinding() {} -func (s *AuthenticationService) GetAuthenticationLoginSchemaPolicyVPNVServerBinding() {} -func (s *AuthenticationService) CountAuthenticationLoginSchemaPolicyVPNVServerBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// authenticationnegotiataction -// Configuration for Negotiate action resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationnegotiateaction -func (s *AuthenticationService) AddAuthenticationNegotiateAction() {} -func (s *AuthenticationService) DeleteAuthenticationNegotiateAction() {} -func (s *AuthenticationService) UpdateAuthenticationNegotiateAction() {} -func (s *AuthenticationService) UnsetAuthenticationNegotiateAction() {} -func (s *AuthenticationService) GetAllAuthenticationNegotiateAction() {} -func (s *AuthenticationService) GetAuthenticationNegotiateAction() {} -func (s *AuthenticationService) CountAuthenticationNegotiateAction() {} + var result struct { + Data []models.AuthenticationAuthNProfile `json:"authenticationauthnprofile"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } -// authenticationnegotiatpolicy -// Configuration for Negotiate Policy resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationnegotiatepolicy -func (s *AuthenticationService) AddAuthenticationNegotiatePolicy() {} -func (s *AuthenticationService) DeleteAuthenticationNegotiatePolicy() {} -func (s *AuthenticationService) UpdateAuthenticationNegotiatePolicy() {} -func (s *AuthenticationService) UnsetAuthenticationNegotiatePolicy() {} -func (s *AuthenticationService) GetAllAuthenticationNegotiatePolicy() {} -func (s *AuthenticationService) GetAuthenticationNegotiatePolicy() {} -func (s *AuthenticationService) CountAuthenticationNegotiatePolicy() {} + return result.Data, nil +} -// authenticationnegotiatepolicy_authenticationvserver_binding -// Binding object showing the authenticationvserver that can be bound to authenticationnegotiatepolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationnegotiatepolicy_authenticationvserver_binding -func (s *AuthenticationService) GetAllAuthenticationNegotiatePolicyAuthencationVServerBinding() {} -func (s *AuthenticationService) GetAuthenticationNegotiatePolicyAuthencationVServerBinding() {} -func (s *AuthenticationService) CountAuthenticationNegotiatePolicyAuthencationVServerBinding() {} +func (s *AuthenticationService) GetAuthenticationAuthnProfile(name string) (*models.AuthenticationAuthNProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationAuthnProfileURL, name), nil) + if err != nil { + return nil, err + } -// authenticationnegotiatepolicy_binding -// Binding object which returns the resources bound to authenticationnegotiatepolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationnegotiatepolicy_binding -func (s *AuthenticationService) GetAllAuthenticationNegotiatePolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationNegotiatePolicyBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// authenticationnegotiatepolicy_vpnglobal_binding -// Binding object showing the vpnglobal that can be bound to authenticationnegotiatepolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationnegotiatepolicy_vpnglobal_binding -func (s *AuthenticationService) GetAllAuthenticationNegotiatePolicyVPNGlobalBinding() {} -func (s *AuthenticationService) GetAuthenticationNegotiatePolicyVPNGlobalBinding() {} -func (s *AuthenticationService) CountAuthenticationNegotiatePolicyVPNGlobalBinding() {} + var result struct { + Data []models.AuthenticationAuthNProfile `json:"authenticationauthnprofile"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } -// authenticationnegotiatepolicy_vpnvserver_binding -// Binding object showing the vpnvserver that can be bound to authenticationnegotiatepolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationnegotiatepolicy_vpnvserver_binding -func (s *AuthenticationService) GetAllAuthenticationNegotiatePolicyVPNVServerBinding() {} -func (s *AuthenticationService) GetAuthenticationNegotiatePolicyVPNVServerBinding() {} -func (s *AuthenticationService) CountAuthenticationNegotiatePolicyVPNVServerBinding() {} + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationauthnprofile %s not found", name) + } -// authenticationnoauthaction -// Configuration for no authentication action resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationnoauthaction -func (s *AuthenticationService) AddAuthenticationNoAuthAction() {} -func (s *AuthenticationService) DeleteAuthenticationNoAuthAction() {} -func (s *AuthenticationService) UpdateAuthenticationNoAuthAction() {} -func (s *AuthenticationService) UnsetAuthenticationNoAuthAction() {} -func (s *AuthenticationService) GetAllAuthenticationNoAuthAction() {} -func (s *AuthenticationService) GetAuthenticationNoAuthAction() {} -func (s *AuthenticationService) CountAuthenticationNoAuthAction() {} + return &result.Data[0], nil +} -// authenticationoauthaction -// Configuration for OAuth authentication action resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationoauthaction -func (s *AuthenticationService) AddAuthenticationOAuthAction() {} -func (s *AuthenticationService) DeleteAuthenticationOAuthAction() {} -func (s *AuthenticationService) UpdateAuthenticationOAuthAction() {} -func (s *AuthenticationService) UnsetAuthenticationOAuthAction() {} -func (s *AuthenticationService) GetAllAuthenticationOAuthAction() {} -func (s *AuthenticationService) GetAuthenticationOAuthAction() {} -func (s *AuthenticationService) CountAuthenticationOAuthAction() {} +func (s *AuthenticationService) CountAuthenticationAuthnProfile() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationAuthnProfileURL), nil) + if err != nil { + return 0, err + } -// authenticationoauthidppolicy -// Configuration for AAA OAuth IdentityProvider (IdP) policy resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationoauthidppolicy -func (s *AuthenticationService) AddAuthenticationOAuthIdPPolicy() {} -func (s *AuthenticationService) DeleteAuthenticationOAuthIdPPolicy() {} -func (s *AuthenticationService) UpdateAuthenticationOAuthIdPPolicy() {} -func (s *AuthenticationService) UnsetAuthenticationOAuthIdPPolicy() {} -func (s *AuthenticationService) GetAllAuthenticationOAuthIdPPolicy() {} -func (s *AuthenticationService) GetAuthenticationOAuthIdPPolicy() {} -func (s *AuthenticationService) CountAuthenticationOAuthIdPPolicy() {} -func (s *AuthenticationService) RenameAuthenticationOAuthIdPPolicy() {} + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } -// authenticationoauthidppolicy_authenticationvserver_binding -// Binding object showing the authenticationvserver that can be bound to authenticationoauthidppolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationoauthidppolicy_authenticationvserver_binding -func (s *AuthenticationService) GetAllAuthenticationOAuthIdPPolicyAuthenticationVServerBinding() {} -func (s *AuthenticationService) GetAuthenticationOAuthIdPPolicyAuthenticationVServerBinding() {} -func (s *AuthenticationService) CountAuthenticationOAuthIdPPolicyAuthenticationVServerBinding() {} + var result struct { + Data []models.AuthenticationAuthNProfile `json:"authenticationauthnprofile"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } -// authenticationoauthidppolicy_binding -// Binding object which returns the resources bound to authenticationoauthidppolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationoauthidppolicy_binding -func (s *AuthenticationService) GetAllAuthenticationOAuthIdPPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationOAuthIdPPolicyBinding() {} + if len(result.Data) == 0 { + return 0, nil + } -// authenticationoauthidppolicy_vpnvserver_binding -// Binding object showing the vpnvserver that can be bound to authenticationoauthidppolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationoauthidppolicy_vpnvserver_binding -func (s *AuthenticationService) GetAllAuthenticationOAuthIdPPolicyVPNVServerBinding() {} -func (s *AuthenticationService) GetAuthenticationOAuthIdPPolicyVPNVServerBinding() {} -func (s *AuthenticationService) CountAuthenticationOAuthIdPPolicyVPNVServerBinding() {} + return int(result.Data[0].Count), nil +} -// authenticationoauthidpprofile -// Configuration for OAuth Identity Provider (IdP) profile resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationoauthidpprofile -func (s *AuthenticationService) AddAuthenticationOAuthIdPProfile() {} -func (s *AuthenticationService) DeleteAuthenticationOAuthIdPProfile() {} -func (s *AuthenticationService) UpdateAuthenticationOAuthIdPProfile() {} -func (s *AuthenticationService) UnsetAuthenticationOAuthIdPProfile() {} -func (s *AuthenticationService) GetAllAuthenticationOAuthIdPProfile() {} -func (s *AuthenticationService) GetAuthenticationOAuthIdPProfile() {} -func (s *AuthenticationService) CountAuthenticationOAuthIdPProfile() {} +// authenticationazurekeyvault +// Configuration for Azure Key Vault entity resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationazurekeyvault +func (s *AuthenticationService) AddAuthenticationAzureKeyVault(resource models.AuthenticationAzureKeyVault) error { + payload := map[string]any{"authenticationazurekeyvault": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// authenticationpolicy -// Configuration for Authentication Policy resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationpolicy -func (s *AuthenticationService) AddAuthenticationPolicy() {} -func (s *AuthenticationService) DeleteAuthenticationPolicy() {} -func (s *AuthenticationService) UpdateAuthenticationPolicy() {} -func (s *AuthenticationService) UnsetAuthenticationPolicy() {} -func (s *AuthenticationService) GetAllAuthenticationPolicy() {} -func (s *AuthenticationService) GetAuthenticationPolicy() {} -func (s *AuthenticationService) CountAuthenticationPolicy() {} -func (s *AuthenticationService) RenameAuthenticationPolicy() {} + req, err := s.client.NewRequest(http.MethodPost, authenticationAzureKeyVaultURL, bytes.NewReader(data)) + if err != nil { + return err + } -// authenticationpolicylabel -// Configuration for authentication policy label resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationpolicylabel -func (s *AuthenticationService) AddAuthenticationPolicyLabel() {} -func (s *AuthenticationService) DeleteAuthenticationPolicyLabel() {} -func (s *AuthenticationService) GetAllAuthenticationPolicyLabel() {} -func (s *AuthenticationService) GetAuthenticationPolicyLabel() {} -func (s *AuthenticationService) CountAuthenticationPolicyLabel() {} -func (s *AuthenticationService) RenameAuthenticationPolicyLabel() {} + _, err = s.client.Do(req) + return err +} -// authenticationpolicylabel_authenticationpolicy_binding -// Binding object showing the authenticationpolicy that can be bound to authenticationpolicylabel. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationpolicylabel_authenticationpolicy_binding -func (s *AuthenticationService) AddAuthenticationPolicyLabelAuthenticationPolicyBinding() {} -func (s *AuthenticationService) DeleteAuthenticationPolicyLabelAuthenticationPolicyBinding() {} -func (s *AuthenticationService) GetAllAuthenticationPolicyLabelAuthenticationPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationPolicyLabelAuthenticationPolicyBinding() {} -func (s *AuthenticationService) CountAuthenticationPolicyLabelAuthenticationPolicyBinding() {} +func (s *AuthenticationService) DeleteAuthenticationAzureKeyVault(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationAzureKeyVaultURL, name), nil) + if err != nil { + return err + } -// authenticaitonpolicylabel_binding -// Binding object which returns the resources bound to authenticationpolicylabel. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationpolicylabel_binding -func (s *AuthenticationService) GetAllAuthenticationPolicyLabelBinding() {} -func (s *AuthenticationService) GetAuthenticationPolicyLabelBinding() {} + _, err = s.client.Do(req) + return err +} -// authenticationpolicy_authenticationpolicylabel_binding -// Binding object showing the authenticationpolicylabel that can be bound to authenticationpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationpolicy_authenticationpolicylabel_binding -func (s *AuthenticationService) GetAllAuthenticationPolicyAuthenticationPolicyLabelBinding() {} -func (s *AuthenticationService) GetAuthenticationPolicyAuthenticationPolicyLabelBinding() {} -func (s *AuthenticationService) CountAuthenticationPolicyAuthenticationPolicyLabelBinding() {} +func (s *AuthenticationService) UpdateAuthenticationAzureKeyVault(resource models.AuthenticationAzureKeyVault) error { + payload := map[string]any{"authenticationazurekeyvault": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// authenticationpolicy_authenticationvserver_binding -// Binding object showing the authenticationvserver that can be bound to authenticationpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationpolicy_authenticationvserver_binding -func (s *AuthenticationService) GetAllAuthenticationPolicyAuthenticationVServerBinding() {} -func (s *AuthenticationService) GetAuthenticationPolicyAuthenticationVServerBinding() {} -func (s *AuthenticationService) CountAuthenticationPolicyAuthenticationVServerBinding() {} + req, err := s.client.NewRequest(http.MethodPut, authenticationAzureKeyVaultURL, bytes.NewReader(data)) + if err != nil { + return err + } -// authenticationpolicy_binding -// Binding object which returns the resources bound to authenticationpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationpolicy_binding -func (s *AuthenticationService) GetAllAuthenticationPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationPolicyBinding() {} + _, err = s.client.Do(req) + return err +} -// authenicationpolicy_systemglobal_binding -// Binding object showing the systemglobal that can be bound to authenticationpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationpolicy_systemglobal_binding -func (s *AuthenticationService) GetAllAuthenticationPolicySystemGlobalBinding() {} -func (s *AuthenticationService) GetAuthenticationPolicySystemGlobalBinding() {} -func (s *AuthenticationService) CountAuthenticationPolicySystemGlobalBinding() {} +func (s *AuthenticationService) UnsetAuthenticationAzureKeyVault(resource models.AuthenticationAzureKeyVault) error { + payload := map[string]any{"authenticationazurekeyvault": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// authenticationpushservice -// Configuration for Service details for sending push notifications resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationpushservice -func (s *AuthenticationService) AddAuthenticationPushService() {} -func (s *AuthenticationService) DeleteAuthenticationPushService() {} -func (s *AuthenticationService) UpdateAuthenticationPushService() {} -func (s *AuthenticationService) UnsetAuthenticationPushService() {} -func (s *AuthenticationService) GetAllAuthenticationPushService() {} -func (s *AuthenticationService) GetAuthenticationPushService() {} -func (s *AuthenticationService) CountAuthenticationPushService() {} + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationAzureKeyVaultURL), bytes.NewReader(data)) + if err != nil { + return err + } -// authenticationradiusaction -// Configuration for RADIUS action resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationradiusaction -func (s *AuthenticationService) AddAuthenticationRADIUSAction() {} -func (s *AuthenticationService) DeleteAuthenticationRADIUSAction() {} -func (s *AuthenticationService) UpdateAuthenticationRADIUSAction() {} -func (s *AuthenticationService) UnsetAuthenticationRADIUSAction() {} -func (s *AuthenticationService) GetAllAuthenticationRADIUSAction() {} -func (s *AuthenticationService) GetAuthenticationRADIUSAction() {} -func (s *AuthenticationService) CountAuthenticationRADIUSAction() {} + _, err = s.client.Do(req) + return err +} -// authenticationradiuspolicy -// Configuration for RADIUS policy resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationradiuspolicy -func (s *AuthenticationService) AddAuthenticationRADIUSPolicy() {} -func (s *AuthenticationService) DeleteAuthenticationRADIUSPolicy() {} -func (s *AuthenticationService) UpdateAuthenticationRADIUSPolicy() {} -func (s *AuthenticationService) UnsetAuthenticationRADIUSPolicy() {} -func (s *AuthenticationService) GetAllAuthenticationRADIUSPolicy() {} -func (s *AuthenticationService) GetAuthenticationRADIUSPolicy() {} -func (s *AuthenticationService) CountAuthenticationRADIUSPolicy() {} +func (s *AuthenticationService) GetAllAuthenticationAzureKeyVault() ([]models.AuthenticationAzureKeyVault, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationAzureKeyVaultURL, nil) + if err != nil { + return nil, err + } -// authenticationradiuspolicy_authenticationvserver_binding -// Binding object showing the authenticationvserver that can be bound to authenticationradiuspolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationradiuspolicy_authenticationvserver_binding -func (s *AuthenticationService) GetAllAuthenticationRADIUSPolicyAuthenticationVServerBinding() {} -func (s *AuthenticationService) GetAuthenticationRADIUSPolicyAuthenticationVServerBinding() {} -func (s *AuthenticationService) CountAuthenticationRADIUSPolicyAuthenticationVServerBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// authenticationradiuspolicy_binding -// Binding object which returns the resources bound to authenticationradiuspolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationradiuspolicy_binding -func (s *AuthenticationService) GetAllAuthenticationRADIUSPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationRADIUSPolicyBinding() {} + var result struct { + Data []models.AuthenticationAzureKeyVault `json:"authenticationazurekeyvault"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } -// authenticationradiuspolicy_systemglobal_binding -// Binding object showing the systemglobal that can be bound to authenticationradiuspolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationradiuspolicy_systemglobal_binding -func (s *AuthenticationService) GetAllAuthenticationRADIUSPolicySystemGlobalBinding() {} -func (s *AuthenticationService) GetAuthenticationRADIUSPolicySystemGlobalBinding() {} -func (s *AuthenticationService) CountAuthenticationRADIUSPolicySystemGlobalBinding() {} + return result.Data, nil +} -// authenticationradiuspolicy_vpnglobal_binding -// Binding object showing the vpnglobal that can be bound to authenticationradiuspolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationradiuspolicy_vpnglobal_binding -func (s *AuthenticationService) GetAllAuthenticationRADIUSPolicyVPNGlobalBinding() {} -func (s *AuthenticationService) GetAuthenticationRADIUSPolicyVPNGlobalBinding() {} -func (s *AuthenticationService) CountAuthenticationRADIUSPolicyVPNGlobalBinding() {} +func (s *AuthenticationService) GetAuthenticationAzureKeyVault(name string) (*models.AuthenticationAzureKeyVault, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationAzureKeyVaultURL, name), nil) + if err != nil { + return nil, err + } -// authenticationradiuspolicy_vpnvserver_binding -// Binding object showing the vpnvserver that can be bound to authenticationradiuspolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationradiuspolicy_vpnvserver_binding -func (s *AuthenticationService) GetAllAuthenticationRADIUSPolicyVPNVServerBinding() {} -func (s *AuthenticationService) GetAuthenticationRADIUSPolicyVPNVServerBinding() {} -func (s *AuthenticationService) CountAuthenticationRADIUSPolicyVPNVServerBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// authenticationsamlaction -// Configuration for AAA Saml action resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationsamlaction -func (s *AuthenticationService) AddAuthenticationSAMLAction() {} -func (s *AuthenticationService) DeleteAuthenticationSAMLAction() {} -func (s *AuthenticationService) UpdateAuthenticationSAMLAction() {} -func (s *AuthenticationService) UnsetAuthenticationSAMLAction() {} -func (s *AuthenticationService) GetAllAuthenticationSAMLAction() {} -func (s *AuthenticationService) GetAuthenticationSAMLAction() {} -func (s *AuthenticationService) CountAuthenticationSAMLAction() {} + var result struct { + Data []models.AuthenticationAzureKeyVault `json:"authenticationazurekeyvault"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } -// authenticationsamlidppolicy -// Configuration for AAA Saml IdentityProvider (IdP) policy resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationsamlidppolicy -func (s *AuthenticationService) AddAuthenticationSAMLIdPPolicy() {} -func (s *AuthenticationService) DeleteAuthenticationSAMLIdPPolicy() {} -func (s *AuthenticationService) UpdateAuthenticationSAMLIdPPolicy() {} -func (s *AuthenticationService) UnsetAuthenticationSAMLIdPPolicy() {} -func (s *AuthenticationService) GetAllAuthenticationSAMLIdPPolicy() {} -func (s *AuthenticationService) GetAuthenticationSAMLIdPPolicy() {} -func (s *AuthenticationService) CountAuthenticationSAMLIdPPolicy() {} -func (s *AuthenticationService) RenameAuthenticationSAMLIdPPolicy() {} + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationazurekeyvault %s not found", name) + } -// authenticationsamlidppolicy_authenticationvserver_binding -// Binding object showing the authenticationvserver that can be bound to authenticationsamlidppolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationsamlidppolicy_authenticationvserver_binding -func (s *AuthenticationService) GetAllAuthenticationSAMLIdPPolicyAuthenticationVServerBinding() {} -func (s *AuthenticationService) GetAuthenticationSAMLIdPPolicyAuthenticationVServerBinding() {} -func (s *AuthenticationService) CountAuthenticationSAMLIdPPolicyAuthenticationVServerBinding() {} + return &result.Data[0], nil +} -// authenticationsamlidppolicy_binding -// Binding object which returns the resources bound to authenticationsamlidppolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationsamlidppolicy_binding -func (s *AuthenticationService) GetAllAuthenticationSAMLIdPPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationSAMLIdPPolicyBinding() {} +func (s *AuthenticationService) CountAuthenticationAzureKeyVault() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationAzureKeyVaultURL), nil) + if err != nil { + return 0, err + } -// authenticationsamlidppolicy_vpnvserver_binding -// Binding object showing the vpnvserver that can be bound to authenticationsamlidppolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationsamlidppolicy_vpnvserver_binding -func (s *AuthenticationService) GetAllAuthenticationSAMLIdPPolicyVPNVServerBinding() {} -func (s *AuthenticationService) GetAuthenticationSAMLIdPPolicyVPNVServerBinding() {} -func (s *AuthenticationService) CountAuthenticationSAMLIdPPolicyVPNVServerBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } -// authenticationsamlidpprofile -// Configuration for AAA Saml IdentityProvider (IdP) profile resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationsamlidpprofile -func (s *AuthenticationService) AddAuthenticationSAMLIdPProfile() {} -func (s *AuthenticationService) DeleteAuthenticationSAMLIdPProfile() {} -func (s *AuthenticationService) UpdateAuthenticationSAMLIdPProfile() {} -func (s *AuthenticationService) UnsetAuthenticationSAMLIdPProfile() {} -func (s *AuthenticationService) GetAllAuthenticationSAMLIdPProfile() {} -func (s *AuthenticationService) GetAuthenticationSAMLIdPProfile() {} -func (s *AuthenticationService) CountAuthenticationSAMLIdPProfile() {} + var result struct { + Data []models.AuthenticationAzureKeyVault `json:"authenticationazurekeyvault"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } -// authenticaitonsamlpolicy -// Configuration for AAA Saml policy resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationsamlpolicy -func (s *AuthenticationService) AddAuthenticationSAMLPolicy() {} -func (s *AuthenticationService) DeleteAuthenticationSAMLPolicy() {} -func (s *AuthenticationService) UpdateAuthenticationSAMLPolicy() {} -func (s *AuthenticationService) UnsetAuthenticationSAMLPolicy() {} -func (s *AuthenticationService) GetAllAuthenticationSAMLPolicy() {} -func (s *AuthenticationService) GetAuthenticationSAMLPolicy() {} -func (s *AuthenticationService) CountAuthenticationSAMLPolicy() {} + if len(result.Data) == 0 { + return 0, nil + } -// authenticationsamlpolicy_authenticationvserver_binding -// Binding object showing the authenticationvserver that can be bound to authenticationsamlpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationsamlpolicy_authenticationvserver_binding -func (s *AuthenticationService) GetAllAuthenticationSAMLPolicyAuthenticationVServerBinding() {} -func (s *AuthenticationService) GetAuthenticationSAMLPolicyAuthenticationVServerBinding() {} -func (s *AuthenticationService) CountAuthenticationSAMLPolicyAuthenticationVServerBinding() {} + return int(result.Data[0].Count), nil +} -// authenticationsamlpolicy_binding -// Binding object which returns the resources bound to authenticationsamlpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationsamlpolicy_binding -func (s *AuthenticationService) GetAllAuthenticationSAMLPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationSAMLPolicyBinding() {} +// authenticationcaptchaaction +// Configuration for Captcha Action resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationcaptchaaction +func (s *AuthenticationService) AddAuthenticationCaptchaAction(resource models.AuthenticationCaptchaAction) error { + payload := map[string]any{"authenticationcaptchaaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// authenticationsamlpolicy_vpnglobal_binding -// Binding object showing the vpnglobal that can be bound to authenticationsamlpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationsamlpolicy_vpnglobal_binding -func (s *AuthenticationService) GetAllAuthenticationSAMLPolicyVPNGlobalBinding() {} -func (s *AuthenticationService) GetAuthenticationSAMLPolicyVPNGlobalBinding() {} -func (s *AuthenticationService) CountAuthenticationSAMLPolicyVPNGlobalBinding() {} + req, err := s.client.NewRequest(http.MethodPost, authenticationCaptchaActionURL, bytes.NewReader(data)) + if err != nil { + return err + } -// authenticationsamlpolicy_vpnvserver_binding -// Binding object showing the vpnvserver that can be bound to authenticationsamlpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationsamlpolicy_vpnvserver_binding -func (s *AuthenticationService) GetAllAuthenticationSAMLPolicyVPNVServerBinding() {} -func (s *AuthenticationService) GetAuthenticationSAMLPolicyVPNVServerBinding() {} -func (s *AuthenticationService) CountAuthenticationSAMLPolicyVPNVServerBinding() {} + _, err = s.client.Do(req) + return err +} -// authenticationstorefrontauthaction -// Configuration for Storefront authentication action resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationstorefrontauthaction -func (s *AuthenticationService) AddAuthenticationStoreFrontAuthAction() {} -func (s *AuthenticationService) DeleteAuthenticationStoreFrontAuthAction() {} -func (s *AuthenticationService) UpdateAuthenticationStoreFrontAuthAction() {} -func (s *AuthenticationService) UnsetAuthenticationStoreFrontAuthAction() {} -func (s *AuthenticationService) GetAllAuthenticationStoreFrontAuthAction() {} -func (s *AuthenticationService) GetAuthenticationStoreFrontAuthAction() {} -func (s *AuthenticationService) CountAuthenticationStoreFrontAuthAction() {} +func (s *AuthenticationService) DeleteAuthenticationCaptchaAction(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationCaptchaActionURL, name), nil) + if err != nil { + return err + } -// authenticationtacacsaction + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationCaptchaAction(resource models.AuthenticationCaptchaAction) error { + payload := map[string]any{"authenticationcaptchaaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationCaptchaActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationCaptchaAction(resource models.AuthenticationCaptchaAction) error { + payload := map[string]any{"authenticationcaptchaaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationCaptchaActionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationCaptchaAction() ([]models.AuthenticationCaptchaAction, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationCaptchaActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationCaptchaAction `json:"authenticationcaptchaaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationCaptchaAction(name string) (*models.AuthenticationCaptchaAction, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationCaptchaActionURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationCaptchaAction `json:"authenticationcaptchaaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationcaptchaaction %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationCaptchaAction() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationCaptchaActionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationCaptchaAction `json:"authenticationcaptchaaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationcertaction +// Configuration for CERT action resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationcertaction +func (s *AuthenticationService) AddAuthenticationCertAction(resource models.AuthenticationCertAction) error { + payload := map[string]any{"authenticationcertaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationCertActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationCertAction(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationCertActionURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationCertAction(resource models.AuthenticationCertAction) error { + payload := map[string]any{"authenticationcertaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationCertActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationCertAction(resource models.AuthenticationCertAction) error { + payload := map[string]any{"authenticationcertaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationCertActionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationCertAction() ([]models.AuthenticationCertAction, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationCertActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationCertAction `json:"authenticationcertaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationCertAction(name string) (*models.AuthenticationCertAction, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationCertActionURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationCertAction `json:"authenticationcertaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationcertaction %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationCertAction() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationCertActionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationCertAction `json:"authenticationcertaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationcertpolicy +// Configuration for CERT policy resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationcertpolicy +func (s *AuthenticationService) AddAuthenticationCertPolicy(resource models.AuthenticationCertPolicy) error { + payload := map[string]any{"authenticationcertpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationCertPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationCertPolicy(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationCertPolicyURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationCertPolicy(resource models.AuthenticationCertPolicy) error { + payload := map[string]any{"authenticationcertpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationCertPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationCertPolicy(resource models.AuthenticationCertPolicy) error { + payload := map[string]any{"authenticationcertpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationCertPolicyURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationCertPolicy() ([]models.AuthenticationCertPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationCertPolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationCertPolicy `json:"authenticationcertpolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationCertPolicy(name string) (*models.AuthenticationCertPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationCertPolicyURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationCertPolicy `json:"authenticationcertpolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationcertpolicy %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationCertPolicy() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationCertPolicyURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationCertPolicy `json:"authenticationcertpolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationcertpolicy_authenticationvserver_binding +// Binding object showing the authenticationvserver that can be bound to authenticationcertpolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationcertpolicy_authenticationvserver_binding +func (s *AuthenticationService) GetAllAuthenticationCertPolicyAuthenticationVServerBinding() ([]models.AuthenticationCertPolicyAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationCertPolicyAuthenticationVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationCertPolicyAuthenticationVServerBinding `json:"authenticationcertpolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationCertPolicyAuthenticationVServerBinding(name string) (*models.AuthenticationCertPolicyAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationCertPolicyAuthenticationVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationCertPolicyAuthenticationVServerBinding `json:"authenticationcertpolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationcertpolicy_authenticationvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationCertPolicyAuthenticationVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationCertPolicyAuthenticationVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationCertPolicyAuthenticationVServerBinding `json:"authenticationcertpolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationcertpolicy_binding +// Binding object which returns the resources bound to authenticationcertpolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationcertpolicy_binding +func (s *AuthenticationService) GetAllAuthenticationCertPolicyBinding() ([]models.AuthenticationCertPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationCertPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationCertPolicyBinding `json:"authenticationcertpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationCertPolicyBinding(name string) (*models.AuthenticationCertPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationCertPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationCertPolicyBinding `json:"authenticationcertpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationcertpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +// authenticationcertpolicy_vpnglobal_binding +// Binding object showing the vpnglobal that can be bound to authenticationcertpolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationcertpolicy_vpnglobal_binding +func (s *AuthenticationService) GetAllAuthenticationCertPolicyVPNGlobalBinding() ([]models.AuthenticationCertPolicyVPNGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationCertPolicyVPNGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationCertPolicyVPNGlobalBinding `json:"authenticationcertpolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationCertPolicyVPNGlobalBinding(name string) (*models.AuthenticationCertPolicyVPNGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationCertPolicyVPNGlobalBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationCertPolicyVPNGlobalBinding `json:"authenticationcertpolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationcertpolicy_vpnglobal_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationCertPolicyVPNGlobalBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationCertPolicyVPNGlobalBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationCertPolicyVPNGlobalBinding `json:"authenticationcertpolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationcertpolicy_vpnvserver_binding +// Binding object showing the vpnvserver that can be bound to authenticationcertpolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationcertpolicy_vpnvserver_binding +func (s *AuthenticationService) GetAllAuthenticationCertPolicyVPNVServerBinding() ([]models.AuthenticationCertPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationCertPolicyVPNVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationCertPolicyVPNVServerBinding `json:"authenticationcertpolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationCertPolicyVPNVServerBinding(name string) (*models.AuthenticationCertPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationCertPolicyVPNVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationCertPolicyVPNVServerBinding `json:"authenticationcertpolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationcertpolicy_vpnvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationCertPolicyVPNVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationCertPolicyVPNVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationCertPolicyVPNVServerBinding `json:"authenticationcertpolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationcitrixauthaction +// Configuration for Citrix Authentication action resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationcitrixauthaction +func (s *AuthenticationService) AddAuthenticationCitrixAuthAction(resource models.AuthenticationCitrixAuthAction) error { + payload := map[string]any{"authenticationcitrixauthaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationCitrixAuthActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationCitrixAuthAction(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationCitrixAuthActionURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationCitrixAuthAction(resource models.AuthenticationCitrixAuthAction) error { + payload := map[string]any{"authenticationcitrixauthaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationCitrixAuthActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationCitrixAuthAction(resource models.AuthenticationCitrixAuthAction) error { + payload := map[string]any{"authenticationcitrixauthaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationCitrixAuthActionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationCitrixAuthAction() ([]models.AuthenticationCitrixAuthAction, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationCitrixAuthActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationCitrixAuthAction `json:"authenticationcitrixauthaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationCitrixAuthAction(name string) (*models.AuthenticationCitrixAuthAction, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationCitrixAuthActionURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationCitrixAuthAction `json:"authenticationcitrixauthaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationcitrixauthaction %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationCitrixAuthAction() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationCitrixAuthActionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationCitrixAuthAction `json:"authenticationcitrixauthaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationdfaaction +// Configuration for Dfa authentication action resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationdfaaction +func (s *AuthenticationService) AddAuthenticationDFAAction(resource models.AuthenticationDFAAction) error { + payload := map[string]any{"authenticationdfaaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationDFAActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationDFAAction(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationDFAActionURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationDFAAction(resource models.AuthenticationDFAAction) error { + payload := map[string]any{"authenticationdfaaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationDFAActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationDFAAction(resource models.AuthenticationDFAAction) error { + payload := map[string]any{"authenticationdfaaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationDFAActionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationDFAAction() ([]models.AuthenticationDFAAction, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationDFAActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationDFAAction `json:"authenticationdfaaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationDFAAction(name string) (*models.AuthenticationDFAAction, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationDFAActionURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationDFAAction `json:"authenticationdfaaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationdfaaction %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationDFAAction() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationDFAActionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationDFAAction `json:"authenticationdfaaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationdfapolicy +// Configuration for Dfa authentication policy resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationdfapolicy +func (s *AuthenticationService) AddAuthenticationDFAPolicy(resource models.AuthenticationDFAPolicy) error { + payload := map[string]any{"authenticationdfapolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationDFAPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationDFAPolicy(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationDFAPolicyURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationDFAPolicy(resource models.AuthenticationDFAPolicy) error { + payload := map[string]any{"authenticationdfapolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationDFAPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationDFAPolicy() ([]models.AuthenticationDFAPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationDFAPolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationDFAPolicy `json:"authenticationdfapolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationDFAPolicy(name string) (*models.AuthenticationDFAPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationDFAPolicyURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationDFAPolicy `json:"authenticationdfapolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationdfapolicy %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationDFAPolicy() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationDFAPolicyURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationDFAPolicy `json:"authenticationdfapolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationdfapolicy_binding +// Binding object which returns the resources bound to authenticationdfapolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationdfapolicy_binding +func (s *AuthenticationService) GetAllAuthenticationDFAPolicyBinding() ([]models.AuthenticationDFAPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationDFAPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationDFAPolicyBinding `json:"authenticationdfapolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationDFAPolicyBinding(name string) (*models.AuthenticationDFAPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationDFAPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationDFAPolicyBinding `json:"authenticationdfapolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationdfapolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +// authenticationdfapolicy_vpnvserver_binding +// Binding object showing the vpnvserver that can be bound to authenticationdfapolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationdfapolicy_vpnvserver_binding +func (s *AuthenticationService) GetAllAuthenticationDFAPolicyVPNVServerBinding() ([]models.AuthenticationDFAPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationDFAPolicyVPNVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationDFAPolicyVPNVServerBinding `json:"authenticationdfapolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationDFAPolicyVPNVServerBinding(name string) (*models.AuthenticationDFAPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationDFAPolicyVPNVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationDFAPolicyVPNVServerBinding `json:"authenticationdfapolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationdfapolicy_vpnvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationDFAPolicyVPNVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationDFAPolicyVPNVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationDFAPolicyVPNVServerBinding `json:"authenticationdfapolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationemailaction +// Configuration for Email entity resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationemailaction +func (s *AuthenticationService) AddAuthenticationEmailAction(resource models.AuthenticationEmailAction) error { + payload := map[string]any{"authenticationemailaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationEmailActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationEmailAction(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationEmailActionURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationEmailAction(resource models.AuthenticationEmailAction) error { + payload := map[string]any{"authenticationemailaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationEmailActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationEmailAction(resource models.AuthenticationEmailAction) error { + payload := map[string]any{"authenticationemailaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationEmailActionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationEmailAction() ([]models.AuthenticationEmailAction, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationEmailActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationEmailAction `json:"authenticationemailaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationEmailAction(name string) (*models.AuthenticationEmailAction, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationEmailActionURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationEmailAction `json:"authenticationemailaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationemailaction %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationEmailAction() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationEmailActionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationEmailAction `json:"authenticationemailaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationepaaction +// Configuration for epa action resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationepaaction +func (s *AuthenticationService) AddAuthenticationEPAAction(resource models.AuthenticationEPAAction) error { + payload := map[string]any{"authenticationepaaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationEPAActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationEPAAction(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationEPAActionURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationEPAAction(resource models.AuthenticationEPAAction) error { + payload := map[string]any{"authenticationepaaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationEPAActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationEPAAction(resource models.AuthenticationEPAAction) error { + payload := map[string]any{"authenticationepaaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationEPAActionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationEPAAction() ([]models.AuthenticationEPAAction, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationEPAActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationEPAAction `json:"authenticationepaaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationEPAAction(name string) (*models.AuthenticationEPAAction, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationEPAActionURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationEPAAction `json:"authenticationepaaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationepaaction %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationEPAAction() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationEPAActionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationEPAAction `json:"authenticationepaaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationldapaction +// Configuration for LDAP action resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationldapaction +func (s *AuthenticationService) AddAuthenticationLDAPAction(resource models.AuthenticationLDAPAction) error { + payload := map[string]any{"authenticationldapaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationLDAPActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationLDAPAction(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationLDAPActionURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationLDAPAction(resource models.AuthenticationLDAPAction) error { + payload := map[string]any{"authenticationldapaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationLDAPActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationLDAPAction(resource models.AuthenticationLDAPAction) error { + payload := map[string]any{"authenticationldapaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationLDAPActionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationLDAPAction() ([]models.AuthenticationLDAPAction, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationLDAPActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLDAPAction `json:"authenticationldapaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationLDAPAction(name string) (*models.AuthenticationLDAPAction, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationLDAPActionURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLDAPAction `json:"authenticationldapaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationldapaction %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationLDAPAction() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationLDAPActionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationLDAPAction `json:"authenticationldapaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationldappolicy +// Configuration for LDAP policy resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationldappolicy +func (s *AuthenticationService) AddAuthenticationLDAPPolicy(resource models.AuthenticationLDAPPolicy) error { + payload := map[string]any{"authenticationldappolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationLDAPPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationLDAPPolicy(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationLDAPPolicyURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationLDAPPolicy(resource models.AuthenticationLDAPPolicy) error { + payload := map[string]any{"authenticationldappolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationLDAPPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationLDAPPolicy(resource models.AuthenticationLDAPPolicy) error { + payload := map[string]any{"authenticationldappolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationLDAPPolicyURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationLDAPPolicy() ([]models.AuthenticationLDAPPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationLDAPPolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLDAPPolicy `json:"authenticationldappolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationLDAPPolicy(name string) (*models.AuthenticationLDAPPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationLDAPPolicyURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLDAPPolicy `json:"authenticationldappolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationldappolicy %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationLDAPPolicy() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationLDAPPolicyURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationLDAPPolicy `json:"authenticationldappolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationldappolicy_authenticationvserver_binding +// Binding object showing the authenticationvserver that can be bound to authenticationldappolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationldappolicy_authenticationvserver_binding +func (s *AuthenticationService) GetAllAuthenticationLDAPPolicyAuthenticationVServerBinding() ([]models.AuthenticationLDAPPolicyAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationLDAPPolicyAuthenticationVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLDAPPolicyAuthenticationVServerBinding `json:"authenticationldappolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationLDAPPolicyAuthenticationVServerBinding(name string) (*models.AuthenticationLDAPPolicyAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationLDAPPolicyAuthenticationVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLDAPPolicyAuthenticationVServerBinding `json:"authenticationldappolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationldappolicy_authenticationvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationLDAPPolicyAuthenticationVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationLDAPPolicyAuthenticationVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationLDAPPolicyAuthenticationVServerBinding `json:"authenticationldappolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationldappolicy_binding +// Binding object which returns the resources bound to authenticationldappolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationldappolicy_binding +func (s *AuthenticationService) GetAllAuthenticationLDAPPolicyBinding() ([]models.AuthenticationLDAPPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationLDAPPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLDAPPolicyBinding `json:"authenticationldappolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationLDAPPolicyBinding(name string) (*models.AuthenticationLDAPPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationLDAPPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLDAPPolicyBinding `json:"authenticationldappolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationldappolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +// authenticationldappolicy_systemglobal_binding +// Binding object showing the systemglobal that can be bound to authenticationldappolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationldappolicy_systemglobal_binding +func (s *AuthenticationService) GetAllAuthenticationLDAPPolicySystemGlobalBinding() ([]models.AuthenticationLDAPPolicySystemGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationLDAPPolicySystemGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLDAPPolicySystemGlobalBinding `json:"authenticationldappolicy_systemglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationLDAPPolicySystemGlobalBinding(name string) (*models.AuthenticationLDAPPolicySystemGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationLDAPPolicySystemGlobalBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLDAPPolicySystemGlobalBinding `json:"authenticationldappolicy_systemglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationldappolicy_systemglobal_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationLDAPPolicySystemGlobalBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationLDAPPolicySystemGlobalBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationLDAPPolicySystemGlobalBinding `json:"authenticationldappolicy_systemglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationldappolicy_vpnglobal_binding +// Binding object showing the vpnglobal that can be bound to authenticationldappolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationldappolicy_vpnglobal_binding +func (s *AuthenticationService) GetAllAuthenticationLDAPPolicyVPNGlobalBinding() ([]models.AuthenticationLDAPPolicyVPNGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationLDAPPolicyVPNGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLDAPPolicyVPNGlobalBinding `json:"authenticationldappolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationLDAPPolicyVPNGlobalBinding(name string) (*models.AuthenticationLDAPPolicyVPNGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationLDAPPolicyVPNGlobalBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLDAPPolicyVPNGlobalBinding `json:"authenticationldappolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationldappolicy_vpnglobal_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationLDAPPolicyVPNGlobalBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationLDAPPolicyVPNGlobalBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationLDAPPolicyVPNGlobalBinding `json:"authenticationldappolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationldappolicy_vpnvserver_binding +// Binding object showing the vpnvserver that can be bound to authenticationldappolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationldappolicy_vpnvserver_binding +func (s *AuthenticationService) GetAllAuthenticationLDAPPolicyVPNVServerBinding() ([]models.AuthenticationLDAPPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationLDAPPolicyVPNVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLDAPPolicyVPNVServerBinding `json:"authenticationldappolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationLDAPPolicyVPNVServerBinding(name string) (*models.AuthenticationLDAPPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationLDAPPolicyVPNVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLDAPPolicyVPNVServerBinding `json:"authenticationldappolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationldappolicy_vpnvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationLDAPPolicyVPNVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationLDAPPolicyVPNVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationLDAPPolicyVPNVServerBinding `json:"authenticationldappolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationlocalpolicy +// Configuration for LOCAL policy resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationlocalpolicy +func (s *AuthenticationService) AddAuthenticationLocalPolicy(resource models.AuthenticationLocalPolicy) error { + payload := map[string]any{"authenticationlocalpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationLocalPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationLocalPolicy(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationLocalPolicyURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationLocalPolicy(resource models.AuthenticationLocalPolicy) error { + payload := map[string]any{"authenticationlocalpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationLocalPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationLocalPolicy() ([]models.AuthenticationLocalPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationLocalPolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLocalPolicy `json:"authenticationlocalpolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationLocalPolicy(name string) (*models.AuthenticationLocalPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationLocalPolicyURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLocalPolicy `json:"authenticationlocalpolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationlocalpolicy %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationLocalPolicy() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationLocalPolicyURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationLocalPolicy `json:"authenticationlocalpolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationlocalpolicy_authenticationvserver_binding +// Binding object showing the authenticationvserver that can be bound to authenticationlocalpolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationlocalpolicy_authenticationvserver_binding +func (s *AuthenticationService) GetAllAuthenticationLocalPolicyAuthenticationVServerBinding() ([]models.AuthenticationLocalPolicyAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationLocalPolicyAuthenticationVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLocalPolicyAuthenticationVServerBinding `json:"authenticationlocalpolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationLocalPolicyAuthenticationVServerBinding(name string) (*models.AuthenticationLocalPolicyAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationLocalPolicyAuthenticationVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLocalPolicyAuthenticationVServerBinding `json:"authenticationlocalpolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationlocalpolicy_authenticationvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationLocalPolicyAuthenticationVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationLocalPolicyAuthenticationVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationLocalPolicyAuthenticationVServerBinding `json:"authenticationlocalpolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationlocalpolicy_binding +// Binding object which returns the resources bound to authenticationlocalpolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationlocalpolicy_binding +func (s *AuthenticationService) GetAllAuthenticationLocalPolicyBinding() ([]models.AuthenticationLocalPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationLocalPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLocalPolicyBinding `json:"authenticationlocalpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationLocalPolicyBinding(name string) (*models.AuthenticationLocalPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationLocalPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLocalPolicyBinding `json:"authenticationlocalpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationlocalpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +// authenticationlocalpolicy_systemglobal_binding +// Binding object showing the systemglobal that can be bound to authenticationlocalpolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationlocalpolicy_systemglobal_binding +func (s *AuthenticationService) GetAllAuthenticationLocalPolicySystemGlobalBinding() ([]models.AuthenticationLocalPolicySystemGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationLocalPolicySystemGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLocalPolicySystemGlobalBinding `json:"authenticationlocalpolicy_systemglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationLocalPolicySystemGlobalBinding(name string) (*models.AuthenticationLocalPolicySystemGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationLocalPolicySystemGlobalBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLocalPolicySystemGlobalBinding `json:"authenticationlocalpolicy_systemglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationlocalpolicy_systemglobal_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationLocalPolicySystemGlobalBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationLocalPolicySystemGlobalBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationLocalPolicySystemGlobalBinding `json:"authenticationlocalpolicy_systemglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationlocalpolicy_vpnglobal_binding +// Binding object showing the vpnglobal that can be bound to authenticationlocalpolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationlocalpolicy_vpnglobal_binding +func (s *AuthenticationService) GetAllAuthenticationLocalPolicyVPNGlobalBinding() ([]models.AuthenticationLocalPolicyVPNGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationLocalPolicyVPNGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLocalPolicyVPNGlobalBinding `json:"authenticationlocalpolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationLocalPolicyVPNGlobalBinding(name string) (*models.AuthenticationLocalPolicyVPNGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationLocalPolicyVPNGlobalBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLocalPolicyVPNGlobalBinding `json:"authenticationlocalpolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationlocalpolicy_vpnglobal_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationLocalPolicyVPNGlobalBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationLocalPolicyVPNGlobalBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationLocalPolicyVPNGlobalBinding `json:"authenticationlocalpolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationlocalpolicy_vpnvserver_binding +// Binding object showing the vpnvserver that can be bound to authenticationlocalpolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationlocalpolicy_vpnvserver_binding +func (s *AuthenticationService) GetAllAuthenticationLocalPolicyVPNVServerBinding() ([]models.AuthenticationLocalPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationLocalPolicyVPNVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLocalPolicyVPNVServerBinding `json:"authenticationlocalpolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationLocalPolicyVPNVServerBinding(name string) (*models.AuthenticationLocalPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationLocalPolicyVPNVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLocalPolicyVPNVServerBinding `json:"authenticationlocalpolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationlocalpolicy_vpnvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationLocalPolicyVPNVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationLocalPolicyVPNVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationLocalPolicyVPNVServerBinding `json:"authenticationlocalpolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationloginschema +// Configuration for Login Schema resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationloginschema +func (s *AuthenticationService) AddAuthenticationLoginSchema(resource models.AuthenticationLoginSchema) error { + payload := map[string]any{"authenticationloginschema": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationLoginSchemaURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationLoginSchema(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationLoginSchemaURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationLoginSchema(resource models.AuthenticationLoginSchema) error { + payload := map[string]any{"authenticationloginschema": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationLoginSchemaURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationLoginSchema(resource models.AuthenticationLoginSchema) error { + payload := map[string]any{"authenticationloginschema": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationLoginSchemaURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationLoginSchema() ([]models.AuthenticationLoginSchema, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationLoginSchemaURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLoginSchema `json:"authenticationloginschema"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationLoginSchema(name string) (*models.AuthenticationLoginSchema, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationLoginSchemaURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLoginSchema `json:"authenticationloginschema"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationloginschema %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationLoginSchema() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationLoginSchemaURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationLoginSchema `json:"authenticationloginschema"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationloginschemapolicy +// Configuration for Login Schema Policy resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationloginschemapolicy +func (s *AuthenticationService) AddAuthenticationLoginSchemaPolicy(resource models.AuthenticationLoginSchemaPolicy) error { + payload := map[string]any{"authenticationloginschemapolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationLoginSchemaPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationLoginSchemaPolicy(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationLoginSchemaPolicyURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationLoginSchemaPolicy(resource models.AuthenticationLoginSchemaPolicy) error { + payload := map[string]any{"authenticationloginschemapolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationLoginSchemaPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationLoginSchemaPolicy(resource models.AuthenticationLoginSchemaPolicy) error { + payload := map[string]any{"authenticationloginschemapolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationLoginSchemaPolicyURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationLoginSchemaPolicy() ([]models.AuthenticationLoginSchemaPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationLoginSchemaPolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLoginSchemaPolicy `json:"authenticationloginschemapolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationLoginSchemaPolicy(name string) (*models.AuthenticationLoginSchemaPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationLoginSchemaPolicyURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLoginSchemaPolicy `json:"authenticationloginschemapolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationloginschemapolicy %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationLoginSchemaPolicy() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationLoginSchemaPolicyURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationLoginSchemaPolicy `json:"authenticationloginschemapolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +func (s *AuthenticationService) RenameAuthenticationLoginSchemaPolicy(name string, newname string) error { + payload := map[string]any{ + "authenticationloginschemapolicy": map[string]any{ + "name": name, + "newname": newname, + }, + } + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=rename", authenticationLoginSchemaPolicyURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// authenticationloginschemapolicy_authenticationvserver_binding +// Binding object showing the authenticationvserver that can be bound to authenticationloginschemapolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationloginschemapolicy_authenticationvserver_binding +func (s *AuthenticationService) GetAllAuthenticationLoginSchemaPolicyAuthenticationVServerBinding() ([]models.AuthenticationLoginSchemaPolicyAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationLoginSchemaPolicyAuthenticationVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLoginSchemaPolicyAuthenticationVServerBinding `json:"authenticationloginschemapolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationLoginSchemaPolicyAuthenticationVServerBinding(name string) (*models.AuthenticationLoginSchemaPolicyAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationLoginSchemaPolicyAuthenticationVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLoginSchemaPolicyAuthenticationVServerBinding `json:"authenticationloginschemapolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationloginschemapolicy_authenticationvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationLoginSchemaPolicyAuthenticationVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationLoginSchemaPolicyAuthenticationVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationLoginSchemaPolicyAuthenticationVServerBinding `json:"authenticationloginschemapolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationloginschemapolicy_binding +// Binding object which returns the resources bound to authenticationloginschemapolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationloginschemapolicy_binding +func (s *AuthenticationService) GetAllAuthenticationLoginSchemaPolicyBinding() ([]models.AuthenticationLoginSchemaPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationLoginSchemaPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLoginSchemaPolicyBinding `json:"authenticationloginschemapolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationLoginSchemaPolicyBinding(name string) (*models.AuthenticationLoginSchemaPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationLoginSchemaPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLoginSchemaPolicyBinding `json:"authenticationloginschemapolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationloginschemapolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +// authenticationloginschemapolicy_vpnvserver_binding +// Binding object showing the vpnvserver that can be bound to authenticationloginschemapolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationloginschemapolicy_vpnvserver_binding +func (s *AuthenticationService) GetAllAuthenticationLoginSchemaPolicyVPNVServerBinding() ([]models.AuthenticationLoginSchemaPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationLoginSchemaPolicyVPNVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLoginSchemaPolicyVPNVServerBinding `json:"authenticationloginschemapolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationLoginSchemaPolicyVPNVServerBinding(name string) (*models.AuthenticationLoginSchemaPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationLoginSchemaPolicyVPNVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationLoginSchemaPolicyVPNVServerBinding `json:"authenticationloginschemapolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationloginschemapolicy_vpnvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationLoginSchemaPolicyVPNVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationLoginSchemaPolicyVPNVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationLoginSchemaPolicyVPNVServerBinding `json:"authenticationloginschemapolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationnegotiataction +// Configuration for Negotiate action resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationnegotiateaction +func (s *AuthenticationService) AddAuthenticationNegotiateAction(resource models.AuthenticationNegotiateAction) error { + payload := map[string]any{"authenticationnegotiateaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationNegotiateActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationNegotiateAction(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationNegotiateActionURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationNegotiateAction(resource models.AuthenticationNegotiateAction) error { + payload := map[string]any{"authenticationnegotiateaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationNegotiateActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationNegotiateAction(resource models.AuthenticationNegotiateAction) error { + payload := map[string]any{"authenticationnegotiateaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationNegotiateActionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationNegotiateAction() ([]models.AuthenticationNegotiateAction, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationNegotiateActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationNegotiateAction `json:"authenticationnegotiateaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationNegotiateAction(name string) (*models.AuthenticationNegotiateAction, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationNegotiateActionURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationNegotiateAction `json:"authenticationnegotiateaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationnegotiateaction %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationNegotiateAction() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationNegotiateActionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationNegotiateAction `json:"authenticationnegotiateaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationnegotiatpolicy +// Configuration for Negotiate Policy resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationnegotiatepolicy +func (s *AuthenticationService) AddAuthenticationNegotiatePolicy(resource models.AuthenticationNegotiatePolicy) error { + payload := map[string]any{"authenticationnegotiatepolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationNegotiatePolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationNegotiatePolicy(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationNegotiatePolicyURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationNegotiatePolicy(resource models.AuthenticationNegotiatePolicy) error { + payload := map[string]any{"authenticationnegotiatepolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationNegotiatePolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationNegotiatePolicy(resource models.AuthenticationNegotiatePolicy) error { + payload := map[string]any{"authenticationnegotiatepolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationNegotiatePolicyURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationNegotiatePolicy() ([]models.AuthenticationNegotiatePolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationNegotiatePolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationNegotiatePolicy `json:"authenticationnegotiatepolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationNegotiatePolicy(name string) (*models.AuthenticationNegotiatePolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationNegotiatePolicyURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationNegotiatePolicy `json:"authenticationnegotiatepolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationnegotiatepolicy %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationNegotiatePolicy() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationNegotiatePolicyURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationNegotiatePolicy `json:"authenticationnegotiatepolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationnegotiatepolicy_authenticationvserver_binding +// Binding object showing the authenticationvserver that can be bound to authenticationnegotiatepolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationnegotiatepolicy_authenticationvserver_binding +func (s *AuthenticationService) GetAllAuthenticationNegotiatePolicyAuthenticationVServerBinding() ([]models.AuthenticationNegotiatePolicyAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationNegotiatePolicyAuthenticationVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationNegotiatePolicyAuthenticationVServerBinding `json:"authenticationnegotiatepolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationNegotiatePolicyAuthenticationVServerBinding(name string) (*models.AuthenticationNegotiatePolicyAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationNegotiatePolicyAuthenticationVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationNegotiatePolicyAuthenticationVServerBinding `json:"authenticationnegotiatepolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationnegotiatepolicy_authenticationvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationNegotiatePolicyAuthenticationVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationNegotiatePolicyAuthenticationVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationNegotiatePolicyAuthenticationVServerBinding `json:"authenticationnegotiatepolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationnegotiatepolicy_binding +// Binding object which returns the resources bound to authenticationnegotiatepolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationnegotiatepolicy_binding +func (s *AuthenticationService) GetAllAuthenticationNegotiatePolicyBinding() ([]models.AuthenticationNegotiatePolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationNegotiatePolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationNegotiatePolicyBinding `json:"authenticationnegotiatepolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationNegotiatePolicyBinding(name string) (*models.AuthenticationNegotiatePolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationNegotiatePolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationNegotiatePolicyBinding `json:"authenticationnegotiatepolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationnegotiatepolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +// authenticationnegotiatepolicy_vpnglobal_binding +// Binding object showing the vpnglobal that can be bound to authenticationnegotiatepolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationnegotiatepolicy_vpnglobal_binding +func (s *AuthenticationService) GetAllAuthenticationNegotiatePolicyVPNGlobalBinding() ([]models.AuthenticationNegotiatePolicyVPNGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationNegotiatePolicyVPNGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationNegotiatePolicyVPNGlobalBinding `json:"authenticationnegotiatepolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationNegotiatePolicyVPNGlobalBinding(name string) (*models.AuthenticationNegotiatePolicyVPNGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationNegotiatePolicyVPNGlobalBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationNegotiatePolicyVPNGlobalBinding `json:"authenticationnegotiatepolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationnegotiatepolicy_vpnglobal_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationNegotiatePolicyVPNGlobalBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationNegotiatePolicyVPNGlobalBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationNegotiatePolicyVPNGlobalBinding `json:"authenticationnegotiatepolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationnegotiatepolicy_vpnvserver_binding +// Binding object showing the vpnvserver that can be bound to authenticationnegotiatepolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationnegotiatepolicy_vpnvserver_binding +func (s *AuthenticationService) GetAllAuthenticationNegotiatePolicyVPNVServerBinding() ([]models.AuthenticationNegotiatePolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationNegotiatePolicyVPNVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationNegotiatePolicyVPNVServerBinding `json:"authenticationnegotiatepolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationNegotiatePolicyVPNVServerBinding(name string) (*models.AuthenticationNegotiatePolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationNegotiatePolicyVPNVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationNegotiatePolicyVPNVServerBinding `json:"authenticationnegotiatepolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationnegotiatepolicy_vpnvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationNegotiatePolicyVPNVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationNegotiatePolicyVPNVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationNegotiatePolicyVPNVServerBinding `json:"authenticationnegotiatepolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationnoauthaction +// Configuration for no authentication action resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationnoauthaction +func (s *AuthenticationService) AddAuthenticationNoAuthAction(resource models.AuthenticationNoAuthAction) error { + payload := map[string]any{"authenticationnoauthaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationNoAuthActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationNoAuthAction(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationNoAuthActionURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationNoAuthAction(resource models.AuthenticationNoAuthAction) error { + payload := map[string]any{"authenticationnoauthaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationNoAuthActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationNoAuthAction(resource models.AuthenticationNoAuthAction) error { + payload := map[string]any{"authenticationnoauthaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationNoAuthActionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationNoAuthAction() ([]models.AuthenticationNoAuthAction, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationNoAuthActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationNoAuthAction `json:"authenticationnoauthaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationNoAuthAction(name string) (*models.AuthenticationNoAuthAction, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationNoAuthActionURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationNoAuthAction `json:"authenticationnoauthaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationnoauthaction %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationNoAuthAction() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationNoAuthActionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationNoAuthAction `json:"authenticationnoauthaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationoauthaction +// Configuration for OAuth authentication action resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationoauthaction +func (s *AuthenticationService) AddAuthenticationOAuthAction(resource models.AuthenticationOAuthAction) error { + payload := map[string]any{"authenticationoauthaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationOAuthActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationOAuthAction(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationOAuthActionURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationOAuthAction(resource models.AuthenticationOAuthAction) error { + payload := map[string]any{"authenticationoauthaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationOAuthActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationOAuthAction(resource models.AuthenticationOAuthAction) error { + payload := map[string]any{"authenticationoauthaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationOAuthActionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationOAuthAction() ([]models.AuthenticationOAuthAction, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationOAuthActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationOAuthAction `json:"authenticationoauthaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationOAuthAction(name string) (*models.AuthenticationOAuthAction, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationOAuthActionURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationOAuthAction `json:"authenticationoauthaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationoauthaction %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationOAuthAction() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationOAuthActionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationOAuthAction `json:"authenticationoauthaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationoauthidppolicy +// Configuration for AAA OAuth IdentityProvider (IdP) policy resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationoauthidppolicy +func (s *AuthenticationService) AddAuthenticationOAuthIdPPolicy(resource models.AuthenticationOAuthIDPPolicy) error { + payload := map[string]any{"authenticationoauthidppolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationOAuthIdPPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationOAuthIdPPolicy(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationOAuthIdPPolicyURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationOAuthIdPPolicy(resource models.AuthenticationOAuthIDPPolicy) error { + payload := map[string]any{"authenticationoauthidppolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationOAuthIdPPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationOAuthIdPPolicy(resource models.AuthenticationOAuthIDPPolicy) error { + payload := map[string]any{"authenticationoauthidppolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationOAuthIdPPolicyURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationOAuthIdPPolicy() ([]models.AuthenticationOAuthIDPPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationOAuthIdPPolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationOAuthIDPPolicy `json:"authenticationoauthidppolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationOAuthIdPPolicy(name string) (*models.AuthenticationOAuthIDPPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationOAuthIdPPolicyURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationOAuthIDPPolicy `json:"authenticationoauthidppolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationoauthidppolicy %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationOAuthIdPPolicy() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationOAuthIdPPolicyURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationOAuthIDPPolicy `json:"authenticationoauthidppolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +func (s *AuthenticationService) RenameAuthenticationOAuthIdPPolicy(name string, newname string) error { + payload := map[string]any{ + "authenticationoauthidppolicy": map[string]any{ + "name": name, + "newname": newname, + }, + } + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=rename", authenticationOAuthIdPPolicyURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// authenticationoauthidppolicy_authenticationvserver_binding +// Binding object showing the authenticationvserver that can be bound to authenticationoauthidppolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationoauthidppolicy_authenticationvserver_binding +func (s *AuthenticationService) GetAllAuthenticationOAuthIdPPolicyAuthenticationVServerBinding() ([]models.AuthenticationOAuthIDPPolicyAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationOAuthIdPPolicyAuthenticationVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationOAuthIDPPolicyAuthenticationVServerBinding `json:"authenticationoauthidppolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationOAuthIdPPolicyAuthenticationVServerBinding(name string) (*models.AuthenticationOAuthIDPPolicyAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationOAuthIdPPolicyAuthenticationVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationOAuthIDPPolicyAuthenticationVServerBinding `json:"authenticationoauthidppolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationoauthidppolicy_authenticationvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationOAuthIdPPolicyAuthenticationVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationOAuthIdPPolicyAuthenticationVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationOAuthIDPPolicyAuthenticationVServerBinding `json:"authenticationoauthidppolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationoauthidppolicy_binding +// Binding object which returns the resources bound to authenticationoauthidppolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationoauthidppolicy_binding +func (s *AuthenticationService) GetAllAuthenticationOAuthIdPPolicyBinding() ([]models.AuthenticationOAuthIDPPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationOAuthIdPPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationOAuthIDPPolicyBinding `json:"authenticationoauthidppolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationOAuthIdPPolicyBinding(name string) (*models.AuthenticationOAuthIDPPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationOAuthIdPPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationOAuthIDPPolicyBinding `json:"authenticationoauthidppolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationoauthidppolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +// authenticationoauthidppolicy_vpnvserver_binding +// Binding object showing the vpnvserver that can be bound to authenticationoauthidppolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationoauthidppolicy_vpnvserver_binding +func (s *AuthenticationService) GetAllAuthenticationOAuthIdPPolicyVPNVServerBinding() ([]models.AuthenticationOAuthIDPPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationOAuthIdPPolicyVPNVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationOAuthIDPPolicyVPNVServerBinding `json:"authenticationoauthidppolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationOAuthIdPPolicyVPNVServerBinding(name string) (*models.AuthenticationOAuthIDPPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationOAuthIdPPolicyVPNVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationOAuthIDPPolicyVPNVServerBinding `json:"authenticationoauthidppolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationoauthidppolicy_vpnvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationOAuthIdPPolicyVPNVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationOAuthIdPPolicyVPNVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationOAuthIDPPolicyVPNVServerBinding `json:"authenticationoauthidppolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationoauthidpprofile +// Configuration for OAuth Identity Provider (IdP) profile resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationoauthidpprofile +func (s *AuthenticationService) AddAuthenticationOAuthIdPProfile(resource models.AuthenticationOAuthIDPProfile) error { + payload := map[string]any{"authenticationoauthidpprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationOAuthIdPProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationOAuthIdPProfile(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationOAuthIdPProfileURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationOAuthIdPProfile(resource models.AuthenticationOAuthIDPProfile) error { + payload := map[string]any{"authenticationoauthidpprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationOAuthIdPProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationOAuthIdPProfile(resource models.AuthenticationOAuthIDPProfile) error { + payload := map[string]any{"authenticationoauthidpprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationOAuthIdPProfileURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationOAuthIdPProfile() ([]models.AuthenticationOAuthIDPProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationOAuthIdPProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationOAuthIDPProfile `json:"authenticationoauthidpprofile"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationOAuthIdPProfile(name string) (*models.AuthenticationOAuthIDPProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationOAuthIdPProfileURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationOAuthIDPProfile `json:"authenticationoauthidpprofile"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationoauthidpprofile %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationOAuthIdPProfile() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationOAuthIdPProfileURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationOAuthIDPProfile `json:"authenticationoauthidpprofile"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationpolicy +// Configuration for Authentication Policy resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationpolicy +func (s *AuthenticationService) AddAuthenticationPolicy(resource models.AuthenticationPolicy) error { + payload := map[string]any{"authenticationpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationPolicy(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationPolicyURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationPolicy(resource models.AuthenticationPolicy) error { + payload := map[string]any{"authenticationpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationPolicy(resource models.AuthenticationPolicy) error { + payload := map[string]any{"authenticationpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationPolicyURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationPolicy() ([]models.AuthenticationPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationPolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationPolicy `json:"authenticationpolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationPolicy(name string) (*models.AuthenticationPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationPolicyURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationPolicy `json:"authenticationpolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationpolicy %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationPolicy() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationPolicyURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationPolicy `json:"authenticationpolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +func (s *AuthenticationService) RenameAuthenticationPolicy(name string, newname string) error { + payload := map[string]any{ + "authenticationpolicy": map[string]any{ + "name": name, + "newname": newname, + }, + } + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=rename", authenticationPolicyURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// authenticationpolicylabel +// Configuration for authentication policy label resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationpolicylabel +func (s *AuthenticationService) AddAuthenticationPolicyLabel(resource models.AuthenticationPolicyLabel) error { + payload := map[string]any{"authenticationpolicylabel": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationPolicyLabelURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationPolicyLabel(labelname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationPolicyLabelURL, labelname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationPolicyLabel() ([]models.AuthenticationPolicyLabel, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationPolicyLabelURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationPolicyLabel `json:"authenticationpolicylabel"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationPolicyLabel(labelname string) (*models.AuthenticationPolicyLabel, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationPolicyLabelURL, labelname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationPolicyLabel `json:"authenticationpolicylabel"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationpolicylabel %s not found", labelname) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationPolicyLabel() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationPolicyLabelURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationPolicyLabel `json:"authenticationpolicylabel"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +func (s *AuthenticationService) RenameAuthenticationPolicyLabel(labelname string, newname string) error { + payload := map[string]any{ + "authenticationpolicylabel": map[string]any{ + "labelname": labelname, + "newname": newname, + }, + } + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=rename", authenticationPolicyLabelURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// authenticationpolicylabel_authenticationpolicy_binding +// Binding object showing the authenticationpolicy that can be bound to authenticationpolicylabel. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationpolicylabel_authenticationpolicy_binding +func (s *AuthenticationService) AddAuthenticationPolicyLabelAuthenticationPolicyBinding(resource models.AuthenticationPolicyLabelAuthenticationPolicyBinding) error { + payload := map[string]any{"authenticationpolicylabel_authenticationpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationPolicyLabelAuthenticationPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationPolicyLabelAuthenticationPolicyBinding(labelname string, policyname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policyname:%s", authenticationPolicyLabelAuthenticationPolicyBindingURL, labelname, policyname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationPolicyLabelAuthenticationPolicyBinding() ([]models.AuthenticationPolicyLabelAuthenticationPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationPolicyLabelAuthenticationPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationPolicyLabelAuthenticationPolicyBinding `json:"authenticationpolicylabel_authenticationpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationPolicyLabelAuthenticationPolicyBinding(labelname string) (*models.AuthenticationPolicyLabelAuthenticationPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationPolicyLabelAuthenticationPolicyBindingURL, labelname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationPolicyLabelAuthenticationPolicyBinding `json:"authenticationpolicylabel_authenticationpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationpolicylabel_authenticationpolicy_binding %s not found", labelname) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationPolicyLabelAuthenticationPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationPolicyLabelAuthenticationPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationPolicyLabelAuthenticationPolicyBinding `json:"authenticationpolicylabel_authenticationpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticaitonpolicylabel_binding +// Binding object which returns the resources bound to authenticationpolicylabel. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationpolicylabel_binding +func (s *AuthenticationService) GetAllAuthenticationPolicyLabelBinding() ([]models.AuthenticationPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationPolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationPolicyLabelBinding `json:"authenticationpolicylabel_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationPolicyLabelBinding(labelname string) (*models.AuthenticationPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationPolicyLabelBindingURL, labelname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationPolicyLabelBinding `json:"authenticationpolicylabel_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationpolicylabel_binding %s not found", labelname) + } + + return &result.Data[0], nil +} + +// authenticationpolicy_authenticationpolicylabel_binding +// Binding object showing the authenticationpolicylabel that can be bound to authenticationpolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationpolicy_authenticationpolicylabel_binding +func (s *AuthenticationService) GetAllAuthenticationPolicyAuthenticationPolicyLabelBinding() ([]models.AuthenticationPolicyAuthenticationPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationPolicyAuthenticationPolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationPolicyAuthenticationPolicyLabelBinding `json:"authenticationpolicy_authenticationpolicylabel_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationPolicyAuthenticationPolicyLabelBinding(name string) (*models.AuthenticationPolicyAuthenticationPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationPolicyAuthenticationPolicyLabelBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationPolicyAuthenticationPolicyLabelBinding `json:"authenticationpolicy_authenticationpolicylabel_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationpolicy_authenticationpolicylabel_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationPolicyAuthenticationPolicyLabelBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationPolicyAuthenticationPolicyLabelBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationPolicyAuthenticationPolicyLabelBinding `json:"authenticationpolicy_authenticationpolicylabel_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationpolicy_authenticationvserver_binding +// Binding object showing the authenticationvserver that can be bound to authenticationpolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationpolicy_authenticationvserver_binding +func (s *AuthenticationService) GetAllAuthenticationPolicyAuthenticationVServerBinding() ([]models.AuthenticationPolicyAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationPolicyAuthenticationVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationPolicyAuthenticationVServerBinding `json:"authenticationpolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationPolicyAuthenticationVServerBinding(name string) (*models.AuthenticationPolicyAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationPolicyAuthenticationVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationPolicyAuthenticationVServerBinding `json:"authenticationpolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationpolicy_authenticationvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationPolicyAuthenticationVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationPolicyAuthenticationVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationPolicyAuthenticationVServerBinding `json:"authenticationpolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationpolicy_binding +// Binding object which returns the resources bound to authenticationpolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationpolicy_binding +func (s *AuthenticationService) GetAllAuthenticationPolicyBinding() ([]models.AuthenticationPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationPolicyBinding `json:"authenticationpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationPolicyBinding(name string) (*models.AuthenticationPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationPolicyBinding `json:"authenticationpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +// authenicationpolicy_systemglobal_binding +// Binding object showing the systemglobal that can be bound to authenticationpolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationpolicy_systemglobal_binding +func (s *AuthenticationService) GetAllAuthenticationPolicySystemGlobalBinding() ([]models.AuthenticationPolicySystemGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationPolicySystemGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationPolicySystemGlobalBinding `json:"authenticationpolicy_systemglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationPolicySystemGlobalBinding(name string) (*models.AuthenticationPolicySystemGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationPolicySystemGlobalBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationPolicySystemGlobalBinding `json:"authenticationpolicy_systemglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationpolicy_systemglobal_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationPolicySystemGlobalBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationPolicySystemGlobalBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationPolicySystemGlobalBinding `json:"authenticationpolicy_systemglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationpushservice +// Configuration for Service details for sending push notifications resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationpushservice +func (s *AuthenticationService) AddAuthenticationPushService(resource models.AuthenticationPushService) error { + payload := map[string]any{"authenticationpushservice": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationPushServiceURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationPushService(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationPushServiceURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationPushService(resource models.AuthenticationPushService) error { + payload := map[string]any{"authenticationpushservice": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationPushServiceURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationPushService(resource models.AuthenticationPushService) error { + payload := map[string]any{"authenticationpushservice": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationPushServiceURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationPushService() ([]models.AuthenticationPushService, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationPushServiceURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationPushService `json:"authenticationpushservice"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationPushService(name string) (*models.AuthenticationPushService, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationPushServiceURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationPushService `json:"authenticationpushservice"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationpushservice %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationPushService() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationPushServiceURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationPushService `json:"authenticationpushservice"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationradiusaction +// Configuration for RADIUS action resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationradiusaction +func (s *AuthenticationService) AddAuthenticationRADIUSAction(resource models.AuthenticationRADIUSAction) error { + payload := map[string]any{"authenticationradiusaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationRADIUSActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationRADIUSAction(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationRADIUSActionURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationRADIUSAction(resource models.AuthenticationRADIUSAction) error { + payload := map[string]any{"authenticationradiusaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationRADIUSActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationRADIUSAction(resource models.AuthenticationRADIUSAction) error { + payload := map[string]any{"authenticationradiusaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationRADIUSActionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationRADIUSAction() ([]models.AuthenticationRADIUSAction, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationRADIUSActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationRADIUSAction `json:"authenticationradiusaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationRADIUSAction(name string) (*models.AuthenticationRADIUSAction, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationRADIUSActionURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationRADIUSAction `json:"authenticationradiusaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationradiusaction %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationRADIUSAction() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationRADIUSActionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationRADIUSAction `json:"authenticationradiusaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationradiuspolicy +// Configuration for RADIUS policy resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationradiuspolicy +func (s *AuthenticationService) AddAuthenticationRADIUSPolicy(resource models.AuthenticationRADIUSPolicy) error { + payload := map[string]any{"authenticationradiuspolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationRADIUSPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationRADIUSPolicy(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationRADIUSPolicyURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationRADIUSPolicy(resource models.AuthenticationRADIUSPolicy) error { + payload := map[string]any{"authenticationradiuspolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationRADIUSPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationRADIUSPolicy(resource models.AuthenticationRADIUSPolicy) error { + payload := map[string]any{"authenticationradiuspolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationRADIUSPolicyURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationRADIUSPolicy() ([]models.AuthenticationRADIUSPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationRADIUSPolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationRADIUSPolicy `json:"authenticationradiuspolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationRADIUSPolicy(name string) (*models.AuthenticationRADIUSPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationRADIUSPolicyURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationRADIUSPolicy `json:"authenticationradiuspolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationradiuspolicy %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationRADIUSPolicy() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationRADIUSPolicyURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationRADIUSPolicy `json:"authenticationradiuspolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationradiuspolicy_authenticationvserver_binding +// Binding object showing the authenticationvserver that can be bound to authenticationradiuspolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationradiuspolicy_authenticationvserver_binding +func (s *AuthenticationService) GetAllAuthenticationRADIUSPolicyAuthenticationVServerBinding() ([]models.AuthenticationRADIUSPolicyAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationRADIUSPolicyAuthenticationVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationRADIUSPolicyAuthenticationVServerBinding `json:"authenticationradiuspolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationRADIUSPolicyAuthenticationVServerBinding(name string) (*models.AuthenticationRADIUSPolicyAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationRADIUSPolicyAuthenticationVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationRADIUSPolicyAuthenticationVServerBinding `json:"authenticationradiuspolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationradiuspolicy_authenticationvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationRADIUSPolicyAuthenticationVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationRADIUSPolicyAuthenticationVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationRADIUSPolicyAuthenticationVServerBinding `json:"authenticationradiuspolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationradiuspolicy_binding +// Binding object which returns the resources bound to authenticationradiuspolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationradiuspolicy_binding +func (s *AuthenticationService) GetAllAuthenticationRADIUSPolicyBinding() ([]models.AuthenticationRADIUSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationRADIUSPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationRADIUSPolicyBinding `json:"authenticationradiuspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationRADIUSPolicyBinding(name string) (*models.AuthenticationRADIUSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationRADIUSPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationRADIUSPolicyBinding `json:"authenticationradiuspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationradiuspolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +// authenticationradiuspolicy_systemglobal_binding +// Binding object showing the systemglobal that can be bound to authenticationradiuspolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationradiuspolicy_systemglobal_binding +func (s *AuthenticationService) GetAllAuthenticationRADIUSPolicySystemGlobalBinding() ([]models.AuthenticationRADIUSPolicySystemGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationRADIUSPolicySystemGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationRADIUSPolicySystemGlobalBinding `json:"authenticationradiuspolicy_systemglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationRADIUSPolicySystemGlobalBinding(name string) (*models.AuthenticationRADIUSPolicySystemGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationRADIUSPolicySystemGlobalBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationRADIUSPolicySystemGlobalBinding `json:"authenticationradiuspolicy_systemglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationradiuspolicy_systemglobal_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationRADIUSPolicySystemGlobalBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationRADIUSPolicySystemGlobalBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationRADIUSPolicySystemGlobalBinding `json:"authenticationradiuspolicy_systemglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationradiuspolicy_vpnglobal_binding +// Binding object showing the vpnglobal that can be bound to authenticationradiuspolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationradiuspolicy_vpnglobal_binding +func (s *AuthenticationService) GetAllAuthenticationRADIUSPolicyVPNGlobalBinding() ([]models.AuthenticationRADIUSPolicyVPNGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationRADIUSPolicyVPNGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationRADIUSPolicyVPNGlobalBinding `json:"authenticationradiuspolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationRADIUSPolicyVPNGlobalBinding(name string) (*models.AuthenticationRADIUSPolicyVPNGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationRADIUSPolicyVPNGlobalBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationRADIUSPolicyVPNGlobalBinding `json:"authenticationradiuspolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationradiuspolicy_vpnglobal_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationRADIUSPolicyVPNGlobalBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationRADIUSPolicyVPNGlobalBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationRADIUSPolicyVPNGlobalBinding `json:"authenticationradiuspolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationradiuspolicy_vpnvserver_binding +// Binding object showing the vpnvserver that can be bound to authenticationradiuspolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationradiuspolicy_vpnvserver_binding +func (s *AuthenticationService) GetAllAuthenticationRADIUSPolicyVPNVServerBinding() ([]models.AuthenticationRADIUSPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationRADIUSPolicyVPNVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationRADIUSPolicyVPNVServerBinding `json:"authenticationradiuspolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationRADIUSPolicyVPNVServerBinding(name string) (*models.AuthenticationRADIUSPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationRADIUSPolicyVPNVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationRADIUSPolicyVPNVServerBinding `json:"authenticationradiuspolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationradiuspolicy_vpnvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationRADIUSPolicyVPNVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationRADIUSPolicyVPNVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationRADIUSPolicyVPNVServerBinding `json:"authenticationradiuspolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationsamlaction +// Configuration for AAA Saml action resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationsamlaction +func (s *AuthenticationService) AddAuthenticationSAMLAction(resource models.AuthenticationSAMLAction) error { + payload := map[string]any{"authenticationsamlaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationSAMLActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationSAMLAction(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationSAMLActionURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationSAMLAction(resource models.AuthenticationSAMLAction) error { + payload := map[string]any{"authenticationsamlaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationSAMLActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationSAMLAction(resource models.AuthenticationSAMLAction) error { + payload := map[string]any{"authenticationsamlaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationSAMLActionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationSAMLAction() ([]models.AuthenticationSAMLAction, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationSAMLActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationSAMLAction `json:"authenticationsamlaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationSAMLAction(name string) (*models.AuthenticationSAMLAction, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationSAMLActionURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationSAMLAction `json:"authenticationsamlaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationsamlaction %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationSAMLAction() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationSAMLActionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationSAMLAction `json:"authenticationsamlaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationsamlidppolicy +// Configuration for AAA Saml IdentityProvider (IdP) policy resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationsamlidppolicy +func (s *AuthenticationService) AddAuthenticationSAMLIdPPolicy(resource models.AuthenticationSAMLIDPPolicy) error { + payload := map[string]any{"authenticationsamlidppolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationSAMLIdPPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationSAMLIdPPolicy(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationSAMLIdPPolicyURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationSAMLIdPPolicy(resource models.AuthenticationSAMLIDPPolicy) error { + payload := map[string]any{"authenticationsamlidppolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationSAMLIdPPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationSAMLIdPPolicy(resource models.AuthenticationSAMLIDPPolicy) error { + payload := map[string]any{"authenticationsamlidppolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationSAMLIdPPolicyURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationSAMLIdPPolicy() ([]models.AuthenticationSAMLIDPPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationSAMLIdPPolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationSAMLIDPPolicy `json:"authenticationsamlidppolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationSAMLIdPPolicy(name string) (*models.AuthenticationSAMLIDPPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationSAMLIdPPolicyURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationSAMLIDPPolicy `json:"authenticationsamlidppolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationsamlidppolicy %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationSAMLIdPPolicy() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationSAMLIdPPolicyURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationSAMLIDPPolicy `json:"authenticationsamlidppolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +func (s *AuthenticationService) RenameAuthenticationSAMLIdPPolicy(name string, newname string) error { + payload := map[string]any{ + "authenticationsamlidppolicy": map[string]any{ + "name": name, + "newname": newname, + }, + } + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=rename", authenticationSAMLIdPPolicyURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// authenticationsamlidppolicy_authenticationvserver_binding +// Binding object showing the authenticationvserver that can be bound to authenticationsamlidppolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationsamlidppolicy_authenticationvserver_binding +func (s *AuthenticationService) GetAllAuthenticationSAMLIdPPolicyAuthenticationVServerBinding() ([]models.AuthenticationSAMLIDPPolicyAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationSAMLIdPPolicyAuthenticationVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationSAMLIDPPolicyAuthenticationVServerBinding `json:"authenticationsamlidppolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationSAMLIdPPolicyAuthenticationVServerBinding(name string) (*models.AuthenticationSAMLIDPPolicyAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationSAMLIdPPolicyAuthenticationVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationSAMLIDPPolicyAuthenticationVServerBinding `json:"authenticationsamlidppolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationsamlidppolicy_authenticationvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationSAMLIdPPolicyAuthenticationVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationSAMLIdPPolicyAuthenticationVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationSAMLIDPPolicyAuthenticationVServerBinding `json:"authenticationsamlidppolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationsamlidppolicy_binding +// Binding object which returns the resources bound to authenticationsamlidppolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationsamlidppolicy_binding +func (s *AuthenticationService) GetAllAuthenticationSAMLIdPPolicyBinding() ([]models.AuthenticationSAMLIDPPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationSAMLIdPPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationSAMLIDPPolicyBinding `json:"authenticationsamlidppolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationSAMLIdPPolicyBinding(name string) (*models.AuthenticationSAMLIDPPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationSAMLIdPPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationSAMLIDPPolicyBinding `json:"authenticationsamlidppolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationsamlidppolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +// authenticationsamlidppolicy_vpnvserver_binding +// Binding object showing the vpnvserver that can be bound to authenticationsamlidppolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationsamlidppolicy_vpnvserver_binding +func (s *AuthenticationService) GetAllAuthenticationSAMLIdPPolicyVPNVServerBinding() ([]models.AuthenticationSAMLIDPPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationSAMLIdPPolicyVPNVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationSAMLIDPPolicyVPNVServerBinding `json:"authenticationsamlidppolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationSAMLIdPPolicyVPNVServerBinding(name string) (*models.AuthenticationSAMLIDPPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationSAMLIdPPolicyVPNVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationSAMLIDPPolicyVPNVServerBinding `json:"authenticationsamlidppolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationsamlidppolicy_vpnvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationSAMLIdPPolicyVPNVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationSAMLIdPPolicyVPNVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationSAMLIDPPolicyVPNVServerBinding `json:"authenticationsamlidppolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationsamlidpprofile +// Configuration for AAA Saml IdentityProvider (IdP) profile resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationsamlidpprofile +func (s *AuthenticationService) AddAuthenticationSAMLIdPProfile(resource models.AuthenticationSAMLIDPProfile) error { + payload := map[string]any{"authenticationsamlidpprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationSAMLIdPProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationSAMLIdPProfile(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationSAMLIdPProfileURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationSAMLIdPProfile(resource models.AuthenticationSAMLIDPProfile) error { + payload := map[string]any{"authenticationsamlidpprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationSAMLIdPProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationSAMLIdPProfile(resource models.AuthenticationSAMLIDPProfile) error { + payload := map[string]any{"authenticationsamlidpprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationSAMLIdPProfileURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationSAMLIdPProfile() ([]models.AuthenticationSAMLIDPProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationSAMLIdPProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationSAMLIDPProfile `json:"authenticationsamlidpprofile"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationSAMLIdPProfile(name string) (*models.AuthenticationSAMLIDPProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationSAMLIdPProfileURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationSAMLIDPProfile `json:"authenticationsamlidpprofile"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationsamlidpprofile %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationSAMLIdPProfile() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationSAMLIdPProfileURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationSAMLIDPProfile `json:"authenticationsamlidpprofile"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticaitonsamlpolicy +// Configuration for AAA Saml policy resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationsamlpolicy +func (s *AuthenticationService) AddAuthenticationSAMLPolicy(resource models.AuthenticationSAMLPolicy) error { + payload := map[string]any{"authenticationsamlpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationSAMLPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationSAMLPolicy(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationSAMLPolicyURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationSAMLPolicy(resource models.AuthenticationSAMLPolicy) error { + payload := map[string]any{"authenticationsamlpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationSAMLPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationSAMLPolicy(resource models.AuthenticationSAMLPolicy) error { + payload := map[string]any{"authenticationsamlpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationSAMLPolicyURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationSAMLPolicy() ([]models.AuthenticationSAMLPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationSAMLPolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationSAMLPolicy `json:"authenticationsamlpolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationSAMLPolicy(name string) (*models.AuthenticationSAMLPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationSAMLPolicyURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationSAMLPolicy `json:"authenticationsamlpolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationsamlpolicy %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationSAMLPolicy() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationSAMLPolicyURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationSAMLPolicy `json:"authenticationsamlpolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationsamlpolicy_authenticationvserver_binding +// Binding object showing the authenticationvserver that can be bound to authenticationsamlpolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationsamlpolicy_authenticationvserver_binding +func (s *AuthenticationService) GetAllAuthenticationSAMLPolicyAuthenticationVServerBinding() ([]models.AuthenticationSAMLPolicyAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationSAMLPolicyAuthenticationVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationSAMLPolicyAuthenticationVServerBinding `json:"authenticationsamlpolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationSAMLPolicyAuthenticationVServerBinding(name string) (*models.AuthenticationSAMLPolicyAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationSAMLPolicyAuthenticationVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationSAMLPolicyAuthenticationVServerBinding `json:"authenticationsamlpolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationsamlpolicy_authenticationvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationSAMLPolicyAuthenticationVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationSAMLPolicyAuthenticationVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationSAMLPolicyAuthenticationVServerBinding `json:"authenticationsamlpolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationsamlpolicy_binding +// Binding object which returns the resources bound to authenticationsamlpolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationsamlpolicy_binding +func (s *AuthenticationService) GetAllAuthenticationSAMLPolicyBinding() ([]models.AuthenticationSAMLPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationSAMLPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationSAMLPolicyBinding `json:"authenticationsamlpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationSAMLPolicyBinding(name string) (*models.AuthenticationSAMLPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationSAMLPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationSAMLPolicyBinding `json:"authenticationsamlpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationsamlpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +// authenticationsamlpolicy_vpnglobal_binding +// Binding object showing the vpnglobal that can be bound to authenticationsamlpolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationsamlpolicy_vpnglobal_binding +func (s *AuthenticationService) GetAllAuthenticationSAMLPolicyVPNGlobalBinding() ([]models.AuthenticationSAMLPolicyVPNGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationSAMLPolicyVPNGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationSAMLPolicyVPNGlobalBinding `json:"authenticationsamlpolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationSAMLPolicyVPNGlobalBinding(name string) (*models.AuthenticationSAMLPolicyVPNGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationSAMLPolicyVPNGlobalBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationSAMLPolicyVPNGlobalBinding `json:"authenticationsamlpolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationsamlpolicy_vpnglobal_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationSAMLPolicyVPNGlobalBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationSAMLPolicyVPNGlobalBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationSAMLPolicyVPNGlobalBinding `json:"authenticationsamlpolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationsamlpolicy_vpnvserver_binding +// Binding object showing the vpnvserver that can be bound to authenticationsamlpolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationsamlpolicy_vpnvserver_binding +func (s *AuthenticationService) GetAllAuthenticationSAMLPolicyVPNVServerBinding() ([]models.AuthenticationSAMLPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationSAMLPolicyVPNVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationSAMLPolicyVPNVServerBinding `json:"authenticationsamlpolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationSAMLPolicyVPNVServerBinding(name string) (*models.AuthenticationSAMLPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationSAMLPolicyVPNVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationSAMLPolicyVPNVServerBinding `json:"authenticationsamlpolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationsamlpolicy_vpnvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationSAMLPolicyVPNVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationSAMLPolicyVPNVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationSAMLPolicyVPNVServerBinding `json:"authenticationsamlpolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationstorefrontauthaction +// Configuration for Storefront authentication action resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationstorefrontauthaction +func (s *AuthenticationService) AddAuthenticationStoreFrontAuthAction(resource models.AuthenticationStoreFrontAuthAction) error { + payload := map[string]any{"authenticationstorefrontauthaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationStoreFrontAuthActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationStoreFrontAuthAction(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationStoreFrontAuthActionURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationStoreFrontAuthAction(resource models.AuthenticationStoreFrontAuthAction) error { + payload := map[string]any{"authenticationstorefrontauthaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationStoreFrontAuthActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationStoreFrontAuthAction(resource models.AuthenticationStoreFrontAuthAction) error { + payload := map[string]any{"authenticationstorefrontauthaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationStoreFrontAuthActionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationStoreFrontAuthAction() ([]models.AuthenticationStoreFrontAuthAction, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationStoreFrontAuthActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationStoreFrontAuthAction `json:"authenticationstorefrontauthaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationStoreFrontAuthAction(name string) (*models.AuthenticationStoreFrontAuthAction, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationStoreFrontAuthActionURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationStoreFrontAuthAction `json:"authenticationstorefrontauthaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationstorefrontauthaction %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationStoreFrontAuthAction() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationStoreFrontAuthActionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationStoreFrontAuthAction `json:"authenticationstorefrontauthaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationtacacsaction // Configuration for TACACS action resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationtacacsaction -func (s *AuthenticationService) AddAuthenticationTACACSAction() {} -func (s *AuthenticationService) DeleteAuthenticationTACACSAction() {} -func (s *AuthenticationService) UpdateAuthenticationTACACSAction() {} -func (s *AuthenticationService) UnsetAuthenticationTACACSAction() {} -func (s *AuthenticationService) GetAllAuthenticationTACACSAction() {} -func (s *AuthenticationService) GetAuthenticationTACACSAction() {} -func (s *AuthenticationService) CountAuthenticationTACACSAction() {} +func (s *AuthenticationService) AddAuthenticationTACACSAction(resource models.AuthenticationTACACSAction) error { + payload := map[string]any{"authenticationtacacsaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationTACACSActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationTACACSAction(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationTACACSActionURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationTACACSAction(resource models.AuthenticationTACACSAction) error { + payload := map[string]any{"authenticationtacacsaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationTACACSActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationTACACSAction(resource models.AuthenticationTACACSAction) error { + payload := map[string]any{"authenticationtacacsaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationTACACSActionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationTACACSAction() ([]models.AuthenticationTACACSAction, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationTACACSActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationTACACSAction `json:"authenticationtacacsaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationTACACSAction(name string) (*models.AuthenticationTACACSAction, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationTACACSActionURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationTACACSAction `json:"authenticationtacacsaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationtacacsaction %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationTACACSAction() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationTACACSActionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationTACACSAction `json:"authenticationtacacsaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationtacacspolicy +// Configuration for TACACS policy resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationtacacspolicy +func (s *AuthenticationService) AddAuthenticationTACACSPolicy(resource models.AuthenticationTACACSPolicy) error { + payload := map[string]any{"authenticationtacacspolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationTACACSPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationTACACSPolicy(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationTACACSPolicyURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationTACACSPolicy(resource models.AuthenticationTACACSPolicy) error { + payload := map[string]any{"authenticationtacacspolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationTACACSPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationTACACSPolicy(resource models.AuthenticationTACACSPolicy) error { + payload := map[string]any{"authenticationtacacspolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationTACACSPolicyURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationTACACSPolicy() ([]models.AuthenticationTACACSPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationTACACSPolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationTACACSPolicy `json:"authenticationtacacspolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationTACACSPolicy(name string) (*models.AuthenticationTACACSPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationTACACSPolicyURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationTACACSPolicy `json:"authenticationtacacspolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationtacacspolicy %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationTACACSPolicy() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationTACACSPolicyURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationTACACSPolicy `json:"authenticationtacacspolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationtacacspolicy_authenticationvserver_binding +// Binding object showing the authenticationvserver that can be bound to authenticationtacacspolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationtacacspolicy_authenticationvserver_binding +func (s *AuthenticationService) GetAllAuthenticationTACACSPolicyAuthenticationVServerBinding() ([]models.AuthenticationTACACSPolicyAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationTACACSPolicyAuthenticationVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationTACACSPolicyAuthenticationVServerBinding `json:"authenticationtacacspolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationTACACSPolicyAuthenticationVServerBinding(name string) (*models.AuthenticationTACACSPolicyAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationTACACSPolicyAuthenticationVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationTACACSPolicyAuthenticationVServerBinding `json:"authenticationtacacspolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationtacacspolicy_authenticationvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationTACACSPolicyAuthenticationVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationTACACSPolicyAuthenticationVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationTACACSPolicyAuthenticationVServerBinding `json:"authenticationtacacspolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationtacacspolicy_binding +// Binding object which returns the resources bound to authenticationtacacspolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationtacacspolicy_binding +func (s *AuthenticationService) GetAllAuthenticationTACACSPolicyBinding() ([]models.AuthenticationTACACSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationTACACSPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationTACACSPolicyBinding `json:"authenticationtacacspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationTACACSPolicyBinding(name string) (*models.AuthenticationTACACSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationTACACSPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationTACACSPolicyBinding `json:"authenticationtacacspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationtacacspolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +// authenticationtacacspolicy_systemglobal_binding +// Binding object showing the systemglobal that can be bound to authenticationtacacspolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationtacacspolicy_systemglobal_binding +func (s *AuthenticationService) GetAllAuthenticationTACACSPolicySystemGlobalBinding() ([]models.AuthenticationTACACSPolicySystemGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationTACACSPolicySystemGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationTACACSPolicySystemGlobalBinding `json:"authenticationtacacspolicy_systemglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationTACACSPolicySystemGlobalBinding(name string) (*models.AuthenticationTACACSPolicySystemGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationTACACSPolicySystemGlobalBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationTACACSPolicySystemGlobalBinding `json:"authenticationtacacspolicy_systemglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationtacacspolicy_systemglobal_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationTACACSPolicySystemGlobalBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationTACACSPolicySystemGlobalBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationTACACSPolicySystemGlobalBinding `json:"authenticationtacacspolicy_systemglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationtacacspolicy_vpnglobal_binding +// Binding object showing the vpnglobal that can be bound to authenticationtacacspolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationtacacspolicy_vpnglobal_binding +func (s *AuthenticationService) GetAllAuthenticationTACACSPolicyVPNGlobalBinding() ([]models.AuthenticationTACACSPolicyVPNGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationTACACSPolicyVPNGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationTACACSPolicyVPNGlobalBinding `json:"authenticationtacacspolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationTACACSPolicyVPNGlobalBinding(name string) (*models.AuthenticationTACACSPolicyVPNGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationTACACSPolicyVPNGlobalBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationTACACSPolicyVPNGlobalBinding `json:"authenticationtacacspolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationtacacspolicy_vpnglobal_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationTACACSPolicyVPNGlobalBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationTACACSPolicyVPNGlobalBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationTACACSPolicyVPNGlobalBinding `json:"authenticationtacacspolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationtacacspolicy_vpnvserver_binding +// Binding object showing the vpnvserver that can be bound to authenticationtacacspolicy. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationtacacspolicy_vpnvserver_binding +func (s *AuthenticationService) GetAllAuthenticationTACACSPolicyVPNVServerBinding() ([]models.AuthenticationTACACSPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationTACACSPolicyVPNVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationTACACSPolicyVPNVServerBinding `json:"authenticationtacacspolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationTACACSPolicyVPNVServerBinding(name string) (*models.AuthenticationTACACSPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationTACACSPolicyVPNVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationTACACSPolicyVPNVServerBinding `json:"authenticationtacacspolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationtacacspolicy_vpnvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationTACACSPolicyVPNVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationTACACSPolicyVPNVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationTACACSPolicyVPNVServerBinding `json:"authenticationtacacspolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticaitonvserver +// Configuration for authentication virtual server resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver +func (s *AuthenticationService) AddAuthenticationVServer(resource models.AuthenticationVServer) error { + payload := map[string]any{"authenticationvserver": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationVServerURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationVServer(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationVServerURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationVServer(resource models.AuthenticationVServer) error { + payload := map[string]any{"authenticationvserver": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationVServerURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationVServer(resource models.AuthenticationVServer) error { + payload := map[string]any{"authenticationvserver": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationVServerURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) EnableAuthenticationVServer(name string) error { + payload := map[string]any{"authenticationvserver": map[string]string{"name": name}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=enable", authenticationVServerURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DisableAuthenticationVServer(name string) error { + payload := map[string]any{"authenticationvserver": map[string]string{"name": name}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=disable", authenticationVServerURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationVServer() ([]models.AuthenticationVServer, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationVServerURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServer `json:"authenticationvserver"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationVServer(name string) (*models.AuthenticationVServer, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationVServerURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServer `json:"authenticationvserver"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationvserver %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationVServer() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationVServerURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationVServer `json:"authenticationvserver"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +func (s *AuthenticationService) RenameAuthenticationVServer(name string, newname string) error { + payload := map[string]any{ + "authenticationvserver": map[string]any{ + "name": name, + "newname": newname, + }, + } + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=rename", authenticationVServerURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// authenticationvserver_auditnslogpolicy_binding +// Binding object showing the auditnslogpolicy that can be bound to authenticationvserver. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_auditnslogpolicy_binding +func (s *AuthenticationService) AddAuthenticationVServerAuditNSLogPolicyBinding(resource models.AuthenticationVServerAuditNSLogPolicyBinding) error { + payload := map[string]any{"authenticationvserver_auditnslogpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationVServerAuditNSLogPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationVServerAuditNSLogPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", authenticationVServerAuditNSLogPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationVServerAuditNSLogPolicyBinding() ([]models.AuthenticationVServerAuditNSLogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationVServerAuditNSLogPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuditNSLogPolicyBinding `json:"authenticationvserver_auditnslogpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationVServerAuditNSLogPolicyBinding(name string) (*models.AuthenticationVServerAuditNSLogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationVServerAuditNSLogPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuditNSLogPolicyBinding `json:"authenticationvserver_auditnslogpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationvserver_auditnslogpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationVServerAuditNSLogPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationVServerAuditNSLogPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationVServerAuditNSLogPolicyBinding `json:"authenticationvserver_auditnslogpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationvserver_auditsyslogpolicy_binding +// Binding object showing the auditsyslogpolicy that can be bound to authenticationvserver. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_auditsyslogpolicy_binding +func (s *AuthenticationService) AddAuthenticationVServerAuditSyslogPolicyBinding(resource models.AuthenticationVServerAuditSyslogPolicyBinding) error { + payload := map[string]any{"authenticationvserver_auditsyslogpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationVServerAuditSyslogPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationVServerAuditSyslogPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", authenticationVServerAuditSyslogPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationVServerAuditSyslogPolicyBinding() ([]models.AuthenticationVServerAuditSyslogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationVServerAuditSyslogPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuditSyslogPolicyBinding `json:"authenticationvserver_auditsyslogpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationVServerAuditSyslogPolicyBinding(name string) (*models.AuthenticationVServerAuditSyslogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationVServerAuditSyslogPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuditSyslogPolicyBinding `json:"authenticationvserver_auditsyslogpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationvserver_auditsyslogpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationVServerAuditSyslogPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationVServerAuditSyslogPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationVServerAuditSyslogPolicyBinding `json:"authenticationvserver_auditsyslogpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationvserver_authenticationcertpolicy_binding +// Binding object showing the authenticationcertpolicy that can be bound to authenticationvserver. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_authenticationcertpolicy_binding +func (s *AuthenticationService) AddAuthenticationVServerAuthenticationCertPolicyBinding(resource models.AuthenticationVServerAuthenticationCertPolicyBinding) error { + payload := map[string]any{"authenticationvserver_authenticationcertpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationVServerAuthenticationCertPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationVServerAuthenticationCertPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", authenticationVServerAuthenticationCertPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationVServerAuthenticationCertPolicyBinding() ([]models.AuthenticationVServerAuthenticationCertPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationVServerAuthenticationCertPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationCertPolicyBinding `json:"authenticationvserver_authenticationcertpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationVServerAuthenticationCertPolicyBinding(name string) (*models.AuthenticationVServerAuthenticationCertPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationVServerAuthenticationCertPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationCertPolicyBinding `json:"authenticationvserver_authenticationcertpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationvserver_authenticationcertpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationVServerAuthenticationCertPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationVServerAuthenticationCertPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationCertPolicyBinding `json:"authenticationvserver_authenticationcertpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationvserver_authenticationldappolicy_binding +// Binding object showing the authenticationldappolicy that can be bound to authenticationvserver. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_authenticationldappolicy_binding +func (s *AuthenticationService) AddAuthenticationVServerAuthenticationLDAPPolicyBinding(resource models.AuthenticationVServerAuthenticationLDAPPolicyBinding) error { + payload := map[string]any{"authenticationvserver_authenticationldappolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationVServerAuthenticationLDAPPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationVServerAuthenticationLDAPPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", authenticationVServerAuthenticationLDAPPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationVServerAuthenticationLDAPPolicyBinding() ([]models.AuthenticationVServerAuthenticationLDAPPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationVServerAuthenticationLDAPPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationLDAPPolicyBinding `json:"authenticationvserver_authenticationldappolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationVServerAuthenticationLDAPPolicyBinding(name string) (*models.AuthenticationVServerAuthenticationLDAPPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationVServerAuthenticationLDAPPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationLDAPPolicyBinding `json:"authenticationvserver_authenticationldappolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationvserver_authenticationldappolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationVServerAuthenticationLDAPPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationVServerAuthenticationLDAPPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationLDAPPolicyBinding `json:"authenticationvserver_authenticationldappolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationvserver_authenticationlocalpolicy_binding +// Binding object showing the authenticationlocalpolicy that can be bound to authenticationvserver. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_authenticationlocalpolicy_binding +func (s *AuthenticationService) AddAuthenticationVServerAuthenticationLocalPolicyBinding(resource models.AuthenticationVServerAuthenticationLocalPolicyBinding) error { + payload := map[string]any{"authenticationvserver_authenticationlocalpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationVServerAuthenticationLocalPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationVServerAuthenticationLocalPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", authenticationVServerAuthenticationLocalPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationVServerAuthenticationLocalPolicyBinding() ([]models.AuthenticationVServerAuthenticationLocalPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationVServerAuthenticationLocalPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationLocalPolicyBinding `json:"authenticationvserver_authenticationlocalpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationVServerAuthenticationLocalPolicyBinding(name string) (*models.AuthenticationVServerAuthenticationLocalPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationVServerAuthenticationLocalPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationLocalPolicyBinding `json:"authenticationvserver_authenticationlocalpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationvserver_authenticationlocalpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationVServerAuthenticationLocalPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationVServerAuthenticationLocalPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationLocalPolicyBinding `json:"authenticationvserver_authenticationlocalpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationvserver_authenticationloginschemapolicy_binding +// Binding object showing the authenticationloginschemapolicy that can be bound to authenticationvserver. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_authenticationloginschemapolicy_binding +func (s *AuthenticationService) AddAuthenticationVServerAuthenticationLoginSchemaPolicyBinding(resource models.AuthenticationVServerAuthenticationLoginSchemaPolicyBinding) error { + payload := map[string]any{"authenticationvserver_authenticationloginschemapolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationVServerAuthenticationLoginSchemaPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationVServerAuthenticationLoginSchemaPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", authenticationVServerAuthenticationLoginSchemaPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationVServerAuthenticationLoginSchemaPolicyBinding() ([]models.AuthenticationVServerAuthenticationLoginSchemaPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationVServerAuthenticationLoginSchemaPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationLoginSchemaPolicyBinding `json:"authenticationvserver_authenticationloginschemapolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationVServerAuthenticationLoginSchemaPolicyBinding(name string) (*models.AuthenticationVServerAuthenticationLoginSchemaPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationVServerAuthenticationLoginSchemaPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationLoginSchemaPolicyBinding `json:"authenticationvserver_authenticationloginschemapolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationvserver_authenticationloginschemapolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationVServerAuthenticationLoginSchemaPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationVServerAuthenticationLoginSchemaPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationLoginSchemaPolicyBinding `json:"authenticationvserver_authenticationloginschemapolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationvserver_authenticationnegotiatepolicy_binding +// Binding object showing the authenticationnegotiatepolicy that can be bound to authenticationvserver. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_authenticationnegotiatepolicy_binding +func (s *AuthenticationService) AddAuthenticationVServerAuthenticationNegotiatePolicyBinding(resource models.AuthenticationVServerAuthenticationNegotiatePolicyBinding) error { + payload := map[string]any{"authenticationvserver_authenticationnegotiatepolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationVServerAuthenticationNegotiatePolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationVServerAuthenticationNegotiatePolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", authenticationVServerAuthenticationNegotiatePolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationVServerAuthenticationNegotiatePolicyBinding() ([]models.AuthenticationVServerAuthenticationNegotiatePolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationVServerAuthenticationNegotiatePolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationNegotiatePolicyBinding `json:"authenticationvserver_authenticationnegotiatepolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationVServerAuthenticationNegotiatePolicyBinding(name string) (*models.AuthenticationVServerAuthenticationNegotiatePolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationVServerAuthenticationNegotiatePolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationNegotiatePolicyBinding `json:"authenticationvserver_authenticationnegotiatepolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationvserver_authenticationnegotiatepolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationVServerAuthenticationNegotiatePolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationVServerAuthenticationNegotiatePolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationNegotiatePolicyBinding `json:"authenticationvserver_authenticationnegotiatepolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} -// authenticationtacacspolicy -// Configuration for TACACS policy resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationtacacspolicy -func (s *AuthenticationService) AddAuthenticationTACACSPolicy() {} -func (s *AuthenticationService) DeleteAuthenticationTACACSPolicy() {} -func (s *AuthenticationService) UpdateAuthenticationTACACSPolicy() {} -func (s *AuthenticationService) UnsetAuthenticationTACACSPolicy() {} -func (s *AuthenticationService) GetAllAuthenticationTACACSPolicy() {} -func (s *AuthenticationService) GetAuthenticationTACACSPolicy() {} -func (s *AuthenticationService) CountAuthenticationTACACSPolicy() {} +// authenticationvserver_authenticationoauthidppolicy_binding +// Binding object showing the authenticationoauthidppolicy that can be bound to authenticationvserver. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_authenticationoauthidppolicy_binding +func (s *AuthenticationService) AddAuthenticationVServerAuthenticationOAuthIdPPolicyBinding(resource models.AuthenticationVServerAuthenticationOAuthIDPPolicyBinding) error { + payload := map[string]any{"authenticationvserver_authenticationoauthidppolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// authenticationtacacspolicy_authenticationvserver_binding -// Binding object showing the authenticationvserver that can be bound to authenticationtacacspolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationtacacspolicy_authenticationvserver_binding -func (s *AuthenticationService) GetAllAuthenticationTACACSPolicyAuthenticationVServerBinding() {} -func (s *AuthenticationService) GetAuthenticationTACACSPolicyAuthenticationVServerBinding() {} -func (s *AuthenticationService) CountAuthenticationTACACSPolicyAuthenticationVServerBinding() {} + req, err := s.client.NewRequest(http.MethodPost, authenticationVServerAuthenticationOAuthIdPPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationVServerAuthenticationOAuthIdPPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", authenticationVServerAuthenticationOAuthIdPPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationVServerAuthenticationOAuthIdPPolicyBinding() ([]models.AuthenticationVServerAuthenticationOAuthIDPPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationVServerAuthenticationOAuthIdPPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationOAuthIDPPolicyBinding `json:"authenticationvserver_authenticationoauthidppolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationVServerAuthenticationOAuthIdPPolicyBinding(name string) (*models.AuthenticationVServerAuthenticationOAuthIDPPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationVServerAuthenticationOAuthIdPPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationOAuthIDPPolicyBinding `json:"authenticationvserver_authenticationoauthidppolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationvserver_authenticationoauthidppolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationVServerAuthenticationOAuthIdPPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationVServerAuthenticationOAuthIdPPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationOAuthIDPPolicyBinding `json:"authenticationvserver_authenticationoauthidppolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationvserver_authenticationpolicy_binding +// Binding object showing the authenticationpolicy that can be bound to authenticationvserver. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_authenticationpolicy_binding +func (s *AuthenticationService) AddAuthenticationVServerAuthenticationPolicyBinding(resource models.AuthenticationVServerAuthenticationPolicyBinding) error { + payload := map[string]any{"authenticationvserver_authenticationpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationVServerAuthenticationPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationVServerAuthenticationPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", authenticationVServerAuthenticationPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationVServerAuthenticationPolicyBinding() ([]models.AuthenticationVServerAuthenticationPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationVServerAuthenticationPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationPolicyBinding `json:"authenticationvserver_authenticationpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationVServerAuthenticationPolicyBinding(name string) (*models.AuthenticationVServerAuthenticationPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationVServerAuthenticationPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationPolicyBinding `json:"authenticationvserver_authenticationpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationvserver_authenticationpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationVServerAuthenticationPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationVServerAuthenticationPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationPolicyBinding `json:"authenticationvserver_authenticationpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationvserver_authenticationradiuspolicy_binding +// Binding object showing the authenticationradiuspolicy that can be bound to authenticationvserver. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_authenticationradiuspolicy_binding +func (s *AuthenticationService) AddAuthenticationVServerAuthenticationRADIUSPolicyBinding(resource models.AuthenticationVServerAuthenticationRADIUSPolicyBinding) error { + payload := map[string]any{"authenticationvserver_authenticationradiuspolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationVServerAuthenticationRADIUSPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationVServerAuthenticationRADIUSPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", authenticationVServerAuthenticationRADIUSPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationVServerAuthenticationRADIUSPolicyBinding() ([]models.AuthenticationVServerAuthenticationRADIUSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationVServerAuthenticationRADIUSPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationRADIUSPolicyBinding `json:"authenticationvserver_authenticationradiuspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationVServerAuthenticationRADIUSPolicyBinding(name string) (*models.AuthenticationVServerAuthenticationRADIUSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationVServerAuthenticationRADIUSPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationRADIUSPolicyBinding `json:"authenticationvserver_authenticationradiuspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationvserver_authenticationradiuspolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationVServerAuthenticationRADIUSPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationVServerAuthenticationRADIUSPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationRADIUSPolicyBinding `json:"authenticationvserver_authenticationradiuspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationvserver_authenticationsamlidppolicy_binding +// Binding object showing the authenticationsamlidppolicy that can be bound to authenticationvserver. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_authenticationsamlidppolicy_binding +func (s *AuthenticationService) AddAuthenticationVServerAuthenticationSAMLIdPPolicyBinding(resource models.AuthenticationVServerAuthenticationSAMLIDPPolicyBinding) error { + payload := map[string]any{"authenticationvserver_authenticationsamlidppolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationVServerAuthenticationSAMLIdPPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationVServerAuthenticationSAMLIdPPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", authenticationVServerAuthenticationSAMLIdPPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationVServerAuthenticationSAMLIdPPolicyBinding() ([]models.AuthenticationVServerAuthenticationSAMLIDPPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationVServerAuthenticationSAMLIdPPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationSAMLIDPPolicyBinding `json:"authenticationvserver_authenticationsamlidppolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationVServerAuthenticationSAMLIdPPolicyBinding(name string) (*models.AuthenticationVServerAuthenticationSAMLIDPPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationVServerAuthenticationSAMLIdPPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationSAMLIDPPolicyBinding `json:"authenticationvserver_authenticationsamlidppolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationvserver_authenticationsamlidppolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationVServerAuthenticationSAMLIdPPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationVServerAuthenticationSAMLIdPPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationSAMLIDPPolicyBinding `json:"authenticationvserver_authenticationsamlidppolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationvserver_authenticationsamlpolicy_binding +// Binding object showing the authenticationsamlpolicy that can be bound to authenticationvserver. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_authenticationsamlpolicy_binding +func (s *AuthenticationService) AddAuthenticationVServerAuthenticationSAMLPolicyBinding(resource models.AuthenticationVServerAuthenticationSAMLPolicyBinding) error { + payload := map[string]any{"authenticationvserver_authenticationsamlpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationVServerAuthenticationSAMLPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationVServerAuthenticationSAMLPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", authenticationVServerAuthenticationSAMLPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationVServerAuthenticationSAMLPolicyBinding() ([]models.AuthenticationVServerAuthenticationSAMLPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationVServerAuthenticationSAMLPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationSAMLPolicyBinding `json:"authenticationvserver_authenticationsamlpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationVServerAuthenticationSAMLPolicyBinding(name string) (*models.AuthenticationVServerAuthenticationSAMLPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationVServerAuthenticationSAMLPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationSAMLPolicyBinding `json:"authenticationvserver_authenticationsamlpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationvserver_authenticationsamlpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationVServerAuthenticationSAMLPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationVServerAuthenticationSAMLPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationSAMLPolicyBinding `json:"authenticationvserver_authenticationsamlpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationvserver_authenticationtacacspolicy_binding +// Binding object showing the authenticationtacacspolicy that can be bound to authenticationvserver. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_authenticationtacacspolicy_binding +func (s *AuthenticationService) AddAuthenticationVServerAuthenticationTACACSPolicyBinding(resource models.AuthenticationVServerAuthenticationTACACSPolicyBinding) error { + payload := map[string]any{"authenticationvserver_authenticationtacacspolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationVServerAuthenticationTACACSPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationVServerAuthenticationTACACSPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", authenticationVServerAuthenticationTACACSPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationVServerAuthenticationTACACSPolicyBinding() ([]models.AuthenticationVServerAuthenticationTACACSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationVServerAuthenticationTACACSPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationTACACSPolicyBinding `json:"authenticationvserver_authenticationtacacspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationVServerAuthenticationTACACSPolicyBinding(name string) (*models.AuthenticationVServerAuthenticationTACACSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationVServerAuthenticationTACACSPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationTACACSPolicyBinding `json:"authenticationvserver_authenticationtacacspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationvserver_authenticationtacacspolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationVServerAuthenticationTACACSPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationVServerAuthenticationTACACSPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationTACACSPolicyBinding `json:"authenticationvserver_authenticationtacacspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationvserver_authenticationwebauthpolicy_binding +// Binding object showing the authenticationwebauthpolicy that can be bound to authenticationvserver. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_authenticationwebauthpolicy_binding +func (s *AuthenticationService) AddAuthenticationVServerAuthenticationWebAuthPolicyBinding(resource models.AuthenticationVServerAuthenticationWebAuthPolicyBinding) error { + payload := map[string]any{"authenticationvserver_authenticationwebauthpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationVServerAuthenticationWebAuthPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationVServerAuthenticationWebAuthPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", authenticationVServerAuthenticationWebAuthPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationVServerAuthenticationWebAuthPolicyBinding() ([]models.AuthenticationVServerAuthenticationWebAuthPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationVServerAuthenticationWebAuthPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationWebAuthPolicyBinding `json:"authenticationvserver_authenticationwebauthpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationVServerAuthenticationWebAuthPolicyBinding(name string) (*models.AuthenticationVServerAuthenticationWebAuthPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationVServerAuthenticationWebAuthPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationWebAuthPolicyBinding `json:"authenticationvserver_authenticationwebauthpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationvserver_authenticationwebauthpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationVServerAuthenticationWebAuthPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationVServerAuthenticationWebAuthPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationVServerAuthenticationWebAuthPolicyBinding `json:"authenticationvserver_authenticationwebauthpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationvserver_binding +// Binding object which returns the resources bound to authenticationvserver. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_binding +func (s *AuthenticationService) GetAllAuthenticationVServerBinding() ([]models.AuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerBinding `json:"authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationVServerBinding(name string) (*models.AuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerBinding `json:"authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +// authenticationvserver_cachepolicy_binding +// Binding object showing the cachepolicy that can be bound to authenticationvserver. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_cachepolicy_binding +func (s *AuthenticationService) AddAuthenticationVServerCachePolicyBinding(resource models.AuthenticationVServerCachePolicyBinding) error { + payload := map[string]any{"authenticationvserver_cachepolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationVServerCachePolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationVServerCachePolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", authenticationVServerCachePolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationVServerCachePolicyBinding() ([]models.AuthenticationVServerCachePolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationVServerCachePolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerCachePolicyBinding `json:"authenticationvserver_cachepolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationVServerCachePolicyBinding(name string) (*models.AuthenticationVServerCachePolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationVServerCachePolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerCachePolicyBinding `json:"authenticationvserver_cachepolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationvserver_cachepolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationVServerCachePolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationVServerCachePolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationVServerCachePolicyBinding `json:"authenticationvserver_cachepolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// authenticationvserver_cspolicy_binding +// Binding object showing the cspolicy that can be bound to authenticationvserver. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_cspolicy_binding +func (s *AuthenticationService) AddAuthenticationVServerCSPolicyBinding(resource models.AuthenticationVServerCSPolicyBinding) error { + payload := map[string]any{"authenticationvserver_cspolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationVServerCSPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationVServerCSPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", authenticationVServerCSPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationVServerCSPolicyBinding() ([]models.AuthenticationVServerCSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationVServerCSPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerCSPolicyBinding `json:"authenticationvserver_cspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationVServerCSPolicyBinding(name string) (*models.AuthenticationVServerCSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationVServerCSPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerCSPolicyBinding `json:"authenticationvserver_cspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationvserver_cspolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationVServerCSPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationVServerCSPolicyBindingURL), nil) + if err != nil { + return 0, err + } -// authenticationtacacspolicy_binding -// Binding object which returns the resources bound to authenticationtacacspolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationtacacspolicy_binding -func (s *AuthenticationService) GetAllAuthenticationTACACSPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationTACACSPolicyBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } -// authenticationtacacspolicy_systemglobal_binding -// Binding object showing the systemglobal that can be bound to authenticationtacacspolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationtacacspolicy_systemglobal_binding -func (s *AuthenticationService) GetAllAuthenticationTACACSPolicySystemGlobalBinding() {} -func (s *AuthenticationService) GetAuthenticationTACACSPolicySystemGlobalBinding() {} -func (s *AuthenticationService) CountAuthenticationTACACSPolicySystemGlobalBinding() {} + var result struct { + Data []models.AuthenticationVServerCSPolicyBinding `json:"authenticationvserver_cspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } -// authenticationtacacspolicy_vpnglobal_binding -// Binding object showing the vpnglobal that can be bound to authenticationtacacspolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationtacacspolicy_vpnglobal_binding -func (s *AuthenticationService) GetAllAuthenticationTACACSPolicyVPNGlobalBinding() {} -func (s *AuthenticationService) GetAuthenticationTACACSPolicyVPNGlobalBinding() {} -func (s *AuthenticationService) CountAuthenticationTACACSPolicyVPNGlobalBinding() {} + if len(result.Data) == 0 { + return 0, nil + } -// authenticationtacacspolicy_vpnvserver_binding -// Binding object showing the vpnvserver that can be bound to authenticationtacacspolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationtacacspolicy_vpnvserver_binding -func (s *AuthenticationService) GetAllAuthenticationTACACSPolicyVPNVserverBinding() {} -func (s *AuthenticationService) GetAuthenticationTACACSPolicyVPNVserverBinding() {} -func (s *AuthenticationService) CountAuthenticationTACACSPolicyVPNVserverBinding() {} + return int(result.Data[0].Count), nil +} -// authenticaitonvserver -// Configuration for authentication virtual server resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver -func (s *AuthenticationService) AddAuthenticationVServer() {} -func (s *AuthenticationService) DeleteAuthenticationVServer() {} -func (s *AuthenticationService) UpdateAuthenticationVServer() {} -func (s *AuthenticationService) UnsetAuthenticationVServer() {} -func (s *AuthenticationService) EnableAuthenticationVServer() {} -func (s *AuthenticationService) DisableAuthenticationVServer() {} -func (s *AuthenticationService) GetAllAuthenticationVServer() {} -func (s *AuthenticationService) GetAuthenticationVServer() {} -func (s *AuthenticationService) CountAuthenticationVServer() {} -func (s *AuthenticationService) RenameAuthenticationVServer() {} +// authenticationvserver_responderpolicy_binding +// Binding object showing the responderpolicy that can be bound to authenticationvserver. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_responderpolicy_binding +func (s *AuthenticationService) AddAuthenticationVServerResponderPolicyBinding(resource models.AuthenticationVServerResponderPolicyBinding) error { + payload := map[string]any{"authenticationvserver_responderpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// authenticationvserver_auditnslogpolicy_binding -// Binding object showing the auditnslogpolicy that can be bound to authenticationvserver. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_auditnslogpolicy_binding -func (s *AuthenticationService) AddAuthenticationVServerAuditNSLogPolicyBinding() {} -func (s *AuthenticationService) DeleteAuthenticationVServerAuditNSLogPolicyBinding() {} -func (s *AuthenticationService) GetAllAuthenticationVServerAuditNSLogPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationVServerAuditNSLogPolicyBinding() {} -func (s *AuthenticationService) CountAuthenticationVServerAuditNSLogPolicyBinding() {} + req, err := s.client.NewRequest(http.MethodPost, authenticationVServerResponderPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } -// authenticationvserver_auditsyslogpolicy_binding -// Binding object showing the auditsyslogpolicy that can be bound to authenticationvserver. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_auditsyslogpolicy_binding -func (s *AuthenticationService) AddAuthenticationVServerAuditSyslogPolicyBinding() {} -func (s *AuthenticationService) DeleteAuthenticationVServerAuditSyslogPolicyBinding() {} -func (s *AuthenticationService) GetAllAuthenticationVServerAuditSyslogPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationVServerAuditSyslogPolicyBinding() {} -func (s *AuthenticationService) CountAuthenticationVServerAuditSyslogPolicyBinding() {} + _, err = s.client.Do(req) + return err +} -// authenticationvserver_authenticationcertpolicy_binding -// Binding object showing the authenticationcertpolicy that can be bound to authenticationvserver. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_authenticationcertpolicy_binding -func (s *AuthenticationService) AddAuthenticationVServerAuthenticationCertPolicyBinding() {} -func (s *AuthenticationService) DeleteAuthenticationVServerAuthenticationCertPolicyBinding() {} -func (s *AuthenticationService) GetAllAuthenticationVServerAuthenticationCertPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationVServerAuthenticationCertPolicyBinding() {} -func (s *AuthenticationService) CountAuthenticationVServerAuthenticationCertPolicyBinding() {} +func (s *AuthenticationService) DeleteAuthenticationVServerResponderPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", authenticationVServerResponderPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } -// authenticationvserver_authenticationldappolicy_binding -// Binding object showing the authenticationldappolicy that can be bound to authenticationvserver. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_authenticationldappolicy_binding -func (s *AuthenticationService) AddAuthenticationVServerAuthenticationLDAPPolicyBinding() {} -func (s *AuthenticationService) DeleteAuthenticationVServerAuthenticationLDAPPolicyBinding() {} -func (s *AuthenticationService) GetAllAuthenticationVServerAuthenticationLDAPPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationVServerAuthenticationLDAPPolicyBinding() {} -func (s *AuthenticationService) CountAuthenticationVServerAuthenticationLDAPPolicyBinding() {} + _, err = s.client.Do(req) + return err +} -// authenticationvserver_authenticationlocalpolicy_binding -// Binding object showing the authenticationlocalpolicy that can be bound to authenticationvserver. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_authenticationlocalpolicy_binding -func (s *AuthenticationService) AddAuthenticationVServerAuthenticationLocalPolicyBinding() {} -func (s *AuthenticationService) DeleteAuthenticationVServerAuthenticationLocalPolicyBinding() {} -func (s *AuthenticationService) GetAllAuthenticationVServerAuthenticationLocalPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationVServerAuthenticationLocalPolicyBinding() {} -func (s *AuthenticationService) CountAuthenticationVServerAuthenticationLocalPolicyBinding() {} +func (s *AuthenticationService) GetAllAuthenticationVServerResponderPolicyBinding() ([]models.AuthenticationVServerResponderPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationVServerResponderPolicyBindingURL, nil) + if err != nil { + return nil, err + } -// authenticationvserver_authenticationloginschemapolicy_binding -// Binding object showing the authenticationloginschemapolicy that can be bound to authenticationvserver. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_authenticationloginschemapolicy_binding -func (s *AuthenticationService) AddAuthenticationVServerAuthenticationLoginSchemaPolicyBinding() {} -func (s *AuthenticationService) DeleteAuthenticationVServerAuthenticationLoginSchemaPolicyBinding() {} -func (s *AuthenticationService) GetAllAuthenticationVServerAuthenticationLoginSchemaPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationVServerAuthenticationLoginSchemaPolicyBinding() {} -func (s *AuthenticationService) CountAuthenticationVServerAuthenticationLoginSchemaPolicyBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// authenticationvserver_authenticationnegotiatepolicy_binding -// Binding object showing the authenticationnegotiatepolicy that can be bound to authenticationvserver. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_authenticationnegotiatepolicy_binding -func (s *AuthenticationService) AddAuthenticationVServerAuthenticationNegotiatePolicyBinding() {} -func (s *AuthenticationService) DeleteAuthenticationVServerAuthenticationNegotiatePolicyBinding() {} -func (s *AuthenticationService) GetAllAuthenticationVServerAuthenticationNegotiatePolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationVServerAuthenticationNegotiatePolicyBinding() {} -func (s *AuthenticationService) CountAuthenticationVServerAuthenticationNegotiatePolicyBinding() {} + var result struct { + Data []models.AuthenticationVServerResponderPolicyBinding `json:"authenticationvserver_responderpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } -// authenticationvserver_authenticationoauthidppolicy_binding -// Binding object showing the authenticationoauthidppolicy that can be bound to authenticationvserver. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_authenticationoauthidppolicy_binding -func (s *AuthenticationService) AddAuthenticationVServerAuthenticationOAuthIdPPolicyBinding() {} -func (s *AuthenticationService) DeleteAuthenticationVServerAuthenticationOAuthIdPPolicyBinding() {} -func (s *AuthenticationService) GetAllAuthenticationVServerAuthenticationOAuthIdPPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationVServerAuthenticationOAuthIdPPolicyBinding() {} -func (s *AuthenticationService) CountAuthenticationVServerAuthenticationOAuthIdPPolicyBinding() {} + return result.Data, nil +} -// authenticationvserver_authenticationpolicy_binding -// Binding object showing the authenticationpolicy that can be bound to authenticationvserver. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_authenticationpolicy_binding -func (s *AuthenticationService) AddAuthenticationVServerAuthenticationPolicyBinding() {} -func (s *AuthenticationService) DeleteAuthenticationVServerAuthenticationPolicyBinding() {} -func (s *AuthenticationService) GetAllAuthenticationVServerAuthenticationPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationVServerAuthenticationPolicyBinding() {} -func (s *AuthenticationService) CountAuthenticationVServerAuthenticationPolicyBinding() {} +func (s *AuthenticationService) GetAuthenticationVServerResponderPolicyBinding(name string) (*models.AuthenticationVServerResponderPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationVServerResponderPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } -// authenticationvserver_authenticationradiuspolicy_binding -// Binding object showing the authenticationradiuspolicy that can be bound to authenticationvserver. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_authenticationradiuspolicy_binding -func (s *AuthenticationService) AddAuthenticationVServerAuthenticationRADIUSPolicyBinding() {} -func (s *AuthenticationService) DeleteAuthenticationVServerAuthenticationRADIUSPolicyBinding() {} -func (s *AuthenticationService) GetAllAuthenticationVServerAuthenticationRADIUSPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationVServerAuthenticationRADIUSPolicyBinding() {} -func (s *AuthenticationService) CountAuthenticationVServerAuthenticationRADIUSPolicyBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// authenticationvserver_authenticationsamlidppolicy_binding -// Binding object showing the authenticationsamlidppolicy that can be bound to authenticationvserver. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_authenticationsamlidppolicy_binding -func (s *AuthenticationService) AddAuthenticationVServerAuthenticationSAMLIdPPolicyBinding() {} -func (s *AuthenticationService) DeleteAuthenticationVServerAuthenticationSAMLIdPPolicyBinding() {} -func (s *AuthenticationService) GetAllAuthenticationVServerAuthenticationSAMLIdPPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationVServerAuthenticationSAMLIdPPolicyBinding() {} -func (s *AuthenticationService) CountAuthenticationVServerAuthenticationSAMLIdPPolicyBinding() {} + var result struct { + Data []models.AuthenticationVServerResponderPolicyBinding `json:"authenticationvserver_responderpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } -// authenticationvserver_authenticationsamlpolicy_binding -// Binding object showing the authenticationsamlpolicy that can be bound to authenticationvserver. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_authenticationsamlpolicy_binding -func (s *AuthenticationService) AddAuthenticationVServerAuthenticationSAMLPolicyBinding() {} -func (s *AuthenticationService) DeleteAuthenticationVServerAuthenticationSAMLPolicyBinding() {} -func (s *AuthenticationService) GetAllAuthenticationVServerAuthenticationSAMLPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationVServerAuthenticationSAMLPolicyBinding() {} -func (s *AuthenticationService) CountAuthenticationVServerAuthenticationSAMLPolicyBinding() {} + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationvserver_responderpolicy_binding %s not found", name) + } -// authenticationvserver_authenticationtacacspolicy_binding -// Binding object showing the authenticationtacacspolicy that can be bound to authenticationvserver. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_authenticationtacacspolicy_binding -func (s *AuthenticationService) AddAuthenticationVServerAuthenticationTACACSPolicyBinding() {} -func (s *AuthenticationService) DeleteAuthenticationVServerAuthenticationTACACSPolicyBinding() {} -func (s *AuthenticationService) GetAllAuthenticationVServerAuthenticationTACACSPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationVServerAuthenticationTACACSPolicyBinding() {} -func (s *AuthenticationService) CountAuthenticationVServerAuthenticationTACACSPolicyBinding() {} + return &result.Data[0], nil +} -// authenticationvserver_authenticationwebauthpolicy_binding -// Binding object showing the authenticationwebauthpolicy that can be bound to authenticationvserver. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_authenticationwebauthpolicy_binding -func (s *AuthenticationService) AddAuthenticationVServerAuthenticationWebAuthPolicyBinding() {} -func (s *AuthenticationService) DeleteAuthenticationVServerAuthenticationWebAuthPolicyBinding() {} -func (s *AuthenticationService) GetAllAuthenticationVServerAuthenticationWebAuthPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationVServerAuthenticationWebAuthPolicyBinding() {} -func (s *AuthenticationService) CountAuthenticationVServerAuthenticationWebAuthPolicyBinding() {} +func (s *AuthenticationService) CountAuthenticationVServerResponderPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationVServerResponderPolicyBindingURL), nil) + if err != nil { + return 0, err + } -// authenticationvserver_binding -// Binding object which returns the resources bound to authenticationvserver. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_binding -func (s *AuthenticationService) GetAllAuthenticationVServerBinding() {} -func (s *AuthenticationService) GetAuthenticationVServerBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } -// authenticationvserver_cachepolicy_binding -// Binding object showing the cachepolicy that can be bound to authenticationvserver. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_cachepolicy_binding -func (s *AuthenticationService) AddAuthenticationVServerCachePolicyBinding() {} -func (s *AuthenticationService) DeleteAuthenticationVServerCachePolicyBinding() {} -func (s *AuthenticationService) GetAllAuthenticationVServerCachePolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationVServerCachePolicyBinding() {} -func (s *AuthenticationService) CountAuthenticationVServerCachePolicyBinding() {} + var result struct { + Data []models.AuthenticationVServerResponderPolicyBinding `json:"authenticationvserver_responderpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } -// authenticationvserver_cspolicy_binding -// Binding object showing the cspolicy that can be bound to authenticationvserver. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_cspolicy_binding -func (s *AuthenticationService) AddAuthenticationVServerCSPolicyBinding() {} -func (s *AuthenticationService) DeleteAuthenticationVServerCSPolicyBinding() {} -func (s *AuthenticationService) GetAllAuthenticationVServerCSPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationVServerCSPolicyBinding() {} -func (s *AuthenticationService) CountAuthenticationVServerCSPolicyBinding() {} + if len(result.Data) == 0 { + return 0, nil + } -// authenticationvserver_responderpolicy_binding -// Binding object showing the responderpolicy that can be bound to authenticationvserver. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_responderpolicy_binding -func (s *AuthenticationService) AddAuthenticationVServerResponderPolicyBinding() {} -func (s *AuthenticationService) DeleteAuthenticationVServerResponderPolicyBinding() {} -func (s *AuthenticationService) GetAllAuthenticationVServerResponderPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationVServerResponderPolicyBinding() {} -func (s *AuthenticationService) CountAuthenticationVServerResponderPolicyBinding() {} + return int(result.Data[0].Count), nil +} // authenticationvserver_tmsessionpolicy_binding // Binding object showing the tmsessionpolicy that can be bound to authenticationvserver. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_tmsessionpolicy_binding -func (s *AuthenticationService) AddAuthenticationVServerTMSessionPolicyBinding() {} -func (s *AuthenticationService) DeleteAuthenticationVServerTMSessionPolicyBinding() {} -func (s *AuthenticationService) GetAllAuthenticationVServerTMSessionPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationVServerTMSessionPolicyBinding() {} -func (s *AuthenticationService) CountAuthenticationVServerTMSessionPolicyBinding() {} +func (s *AuthenticationService) AddAuthenticationVServerTMSessionPolicyBinding(resource models.AuthenticationVServerTMSessionPolicyBinding) error { + payload := map[string]any{"authenticationvserver_tmsessionpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationVServerTMSessionPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationVServerTMSessionPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", authenticationVServerTMSessionPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationVServerTMSessionPolicyBinding() ([]models.AuthenticationVServerTMSessionPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationVServerTMSessionPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerTMSessionPolicyBinding `json:"authenticationvserver_tmsessionpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationVServerTMSessionPolicyBinding(name string) (*models.AuthenticationVServerTMSessionPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationVServerTMSessionPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerTMSessionPolicyBinding `json:"authenticationvserver_tmsessionpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationvserver_tmsessionpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationVServerTMSessionPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationVServerTMSessionPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationVServerTMSessionPolicyBinding `json:"authenticationvserver_tmsessionpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} // authenticationvserver_vpnportaltheme_binding // Binding object showing the vpnportaltheme that can be bound to authenticationvserver. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationvserver_vpnportaltheme_binding -func (s *AuthenticationService) AddAuthenticationVServerVPNPortalThemeBinding() {} -func (s *AuthenticationService) DeleteAuthenticationVServerVPNPortalThemeBinding() {} -func (s *AuthenticationService) GetAllAuthenticationVServerVPNPortalThemeBinding() {} -func (s *AuthenticationService) GetAuthenticationVServerVPNPortalThemeBinding() {} -func (s *AuthenticationService) CountAuthenticationVServerVPNPortalThemeBinding() {} +func (s *AuthenticationService) AddAuthenticationVServerVPNPortalThemeBinding(resource models.AuthenticationVServerVPNPortalThemeBinding) error { + payload := map[string]any{"authenticationvserver_vpnportaltheme_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationVServerVPNPortalThemeBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationVServerVPNPortalThemeBinding(name string, portaltheme string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=portaltheme:%s", authenticationVServerVPNPortalThemeBindingURL, name, portaltheme), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationVServerVPNPortalThemeBinding() ([]models.AuthenticationVServerVPNPortalThemeBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationVServerVPNPortalThemeBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerVPNPortalThemeBinding `json:"authenticationvserver_vpnportaltheme_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationVServerVPNPortalThemeBinding(name string) (*models.AuthenticationVServerVPNPortalThemeBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationVServerVPNPortalThemeBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationVServerVPNPortalThemeBinding `json:"authenticationvserver_vpnportaltheme_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationvserver_vpnportaltheme_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationVServerVPNPortalThemeBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationVServerVPNPortalThemeBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationVServerVPNPortalThemeBinding `json:"authenticationvserver_vpnportaltheme_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} // authenticationwebauthaction // Configuration for Web authentication action resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationwebauthaction -func (s *AuthenticationService) AddAuthenticationWebAuthAction() {} -func (s *AuthenticationService) DeleteAuthenticationWebAuthAction() {} -func (s *AuthenticationService) UpdateAuthenticationWebAuthAction() {} -func (s *AuthenticationService) UnsetAuthenticationWebAuthAction() {} -func (s *AuthenticationService) GetAllAuthenticationWebAuthAction() {} -func (s *AuthenticationService) GetAuthenticationWebAuthAction() {} -func (s *AuthenticationService) CountAuthenticationWebAuthAction() {} +func (s *AuthenticationService) AddAuthenticationWebAuthAction(resource models.AuthenticationWebAuthAction) error { + payload := map[string]any{"authenticationwebauthaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationWebAuthActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationWebAuthAction(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationWebAuthActionURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationWebAuthAction(resource models.AuthenticationWebAuthAction) error { + payload := map[string]any{"authenticationwebauthaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationWebAuthActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UnsetAuthenticationWebAuthAction(resource models.AuthenticationWebAuthAction) error { + payload := map[string]any{"authenticationwebauthaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", authenticationWebAuthActionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationWebAuthAction() ([]models.AuthenticationWebAuthAction, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationWebAuthActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationWebAuthAction `json:"authenticationwebauthaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationWebAuthAction(name string) (*models.AuthenticationWebAuthAction, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationWebAuthActionURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationWebAuthAction `json:"authenticationwebauthaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationwebauthaction %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationWebAuthAction() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationWebAuthActionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationWebAuthAction `json:"authenticationwebauthaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} // authenticationwebauthpolicy // Configuration for Web authentication policy resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationwebauthpolicy -func (s *AuthenticationService) AddAuthenticationWebAuthPolicy() {} -func (s *AuthenticationService) DeleteAuthenticationWebAuthPolicy() {} -func (s *AuthenticationService) UpdateAuthenticationWebAuthPolicy() {} -func (s *AuthenticationService) GetAllAuthenticationWebAuthPolicy() {} -func (s *AuthenticationService) GetAuthenticationWebAuthPolicy() {} -func (s *AuthenticationService) CountAuthenticationWebAuthPolicy() {} +func (s *AuthenticationService) AddAuthenticationWebAuthPolicy(resource models.AuthenticationWebAuthPolicy) error { + payload := map[string]any{"authenticationwebauthpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, authenticationWebAuthPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) DeleteAuthenticationWebAuthPolicy(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", authenticationWebAuthPolicyURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) UpdateAuthenticationWebAuthPolicy(resource models.AuthenticationWebAuthPolicy) error { + payload := map[string]any{"authenticationwebauthpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, authenticationWebAuthPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AuthenticationService) GetAllAuthenticationWebAuthPolicy() ([]models.AuthenticationWebAuthPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationWebAuthPolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationWebAuthPolicy `json:"authenticationwebauthpolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationWebAuthPolicy(name string) (*models.AuthenticationWebAuthPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationWebAuthPolicyURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationWebAuthPolicy `json:"authenticationwebauthpolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationwebauthpolicy %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationWebAuthPolicy() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationWebAuthPolicyURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationWebAuthPolicy `json:"authenticationwebauthpolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} // authenticationwebauthpolicy_authenticationvserver_binding // Binding object showing the authenticationvserver that can be bound to authenticationwebauthpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationwebauthpolicy_authenticationvserver_binding -func (s *AuthenticationService) GetAllAuthenticationWebAuthPolicyAuthenticationVServerBinding() {} -func (s *AuthenticationService) GetAuthenticationWebAuthPolicyAuthenticationVServerBinding() {} -func (s *AuthenticationService) CountAuthenticationWebAuthPolicyAuthenticationVServerBinding() {} +func (s *AuthenticationService) GetAllAuthenticationWebAuthPolicyAuthenticationVServerBinding() ([]models.AuthenticationWebAuthPolicyAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationWebAuthPolicyAuthenticationVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationWebAuthPolicyAuthenticationVServerBinding `json:"authenticationwebauthpolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationWebAuthPolicyAuthenticationVServerBinding(name string) (*models.AuthenticationWebAuthPolicyAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationWebAuthPolicyAuthenticationVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationWebAuthPolicyAuthenticationVServerBinding `json:"authenticationwebauthpolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationwebauthpolicy_authenticationvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationWebAuthPolicyAuthenticationVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationWebAuthPolicyAuthenticationVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationWebAuthPolicyAuthenticationVServerBinding `json:"authenticationwebauthpolicy_authenticationvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} // authenticationwebauthpolicy_binding // Binding object which returns the resources bound to authenticationwebauthpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationwebauthpolicy_binding -func (s *AuthenticationService) GetAllAuthenticationWebAuthPolicyBinding() {} -func (s *AuthenticationService) GetAuthenticationWebAuthPolicyBinding() {} +func (s *AuthenticationService) GetAllAuthenticationWebAuthPolicyBinding() ([]models.AuthenticationWebAuthPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationWebAuthPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationWebAuthPolicyBinding `json:"authenticationwebauthpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationWebAuthPolicyBinding(name string) (*models.AuthenticationWebAuthPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationWebAuthPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationWebAuthPolicyBinding `json:"authenticationwebauthpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationwebauthpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} // authenticationwebauthpolicy_systemglobal_binding // Binding object showing the systemglobal that can be bound to authenticationwebauthpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationwebauthpolicy_systemglobal_binding -func (s *AuthenticationService) GetAllAuthenticationWebAuthPolicySystemGlobalBinding() {} -func (s *AuthenticationService) GetAuthenticationWebAuthPolicySystemGlobalBinding() {} -func (s *AuthenticationService) CountAuthenticationWebAuthPolicySystemGlobalBinding() {} +func (s *AuthenticationService) GetAllAuthenticationWebAuthPolicySystemGlobalBinding() ([]models.AuthenticationWebAuthPolicySystemGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationWebAuthPolicySystemGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationWebAuthPolicySystemGlobalBinding `json:"authenticationwebauthpolicy_systemglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationWebAuthPolicySystemGlobalBinding(name string) (*models.AuthenticationWebAuthPolicySystemGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationWebAuthPolicySystemGlobalBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationWebAuthPolicySystemGlobalBinding `json:"authenticationwebauthpolicy_systemglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationwebauthpolicy_systemglobal_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationWebAuthPolicySystemGlobalBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationWebAuthPolicySystemGlobalBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationWebAuthPolicySystemGlobalBinding `json:"authenticationwebauthpolicy_systemglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} // authenticationwebauthpolicy_vpnglobal_binding // Binding object showing the vpnglobal that can be bound to authenticationwebauthpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationwebauthpolicy_vpnglobal_binding -func (s *AuthenticationService) GetAllAuthenticationWebAuthPolicyVPNGlobalBinding() {} -func (s *AuthenticationService) GetAuthenticationWebAuthPolicyVPNGlobalBinding() {} -func (s *AuthenticationService) CountAuthenticationWebAuthPolicyVPNGlobalBinding() {} +func (s *AuthenticationService) GetAllAuthenticationWebAuthPolicyVPNGlobalBinding() ([]models.AuthenticationWebAuthPolicyVPNGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationWebAuthPolicyVPNGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationWebAuthPolicyVPNGlobalBinding `json:"authenticationwebauthpolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationWebAuthPolicyVPNGlobalBinding(name string) (*models.AuthenticationWebAuthPolicyVPNGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationWebAuthPolicyVPNGlobalBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationWebAuthPolicyVPNGlobalBinding `json:"authenticationwebauthpolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationwebauthpolicy_vpnglobal_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationWebAuthPolicyVPNGlobalBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationWebAuthPolicyVPNGlobalBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationWebAuthPolicyVPNGlobalBinding `json:"authenticationwebauthpolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} // authenticationwebauthpolicy_vpnvserver_binding // Binding object showing the vpnvserver that can be bound to authenticationwebauthpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authentication/authenticationwebauthpolicy_vpnvserver_binding -func (s *AuthenticationService) GetAllAuthenticationWebAuthPolicyVPNVServerBinding() {} -func (s *AuthenticationService) GetAuthenticationWebAuthPolicyVPNVServerBinding() {} -func (s *AuthenticationService) CountAuthenticationWebAuthPolicyVPNVServerBinding() {} +func (s *AuthenticationService) GetAllAuthenticationWebAuthPolicyVPNVServerBinding() ([]models.AuthenticationWebAuthPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authenticationWebAuthPolicyVPNVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationWebAuthPolicyVPNVServerBinding `json:"authenticationwebauthpolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *AuthenticationService) GetAuthenticationWebAuthPolicyVPNVServerBinding(name string) (*models.AuthenticationWebAuthPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", authenticationWebAuthPolicyVPNVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AuthenticationWebAuthPolicyVPNVServerBinding `json:"authenticationwebauthpolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("authenticationwebauthpolicy_vpnvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *AuthenticationService) CountAuthenticationWebAuthPolicyVPNVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", authenticationWebAuthPolicyVPNVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.AuthenticationWebAuthPolicyVPNVServerBinding `json:"authenticationwebauthpolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} diff --git a/nitrogo/authorization.go b/nitrogo/authorization.go index c531255..c97a28a 100644 --- a/nitrogo/authorization.go +++ b/nitrogo/authorization.go @@ -1,5 +1,29 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + authorizationActionURL = "/nitro/v1/config/authorizationaction" + authorizationPolicyURL = "/nitro/v1/config/authorizationpolicy" + authorizationPolicyAAAGroupBindingURL = "/nitro/v1/config/authorizationpolicy_aaagroup_binding" + authorizationPolicyAAAUserBindingURL = "/nitro/v1/config/authorizationpolicy_aaauser_binding" + authorizationPolicyLabelAuthorizationPolicyBindingURL = "/nitro/v1/config/authorizationpolicylabel_authorizationpolicy_binding" + authorizationPolicyLabelBindingURL = "/nitro/v1/config/authorizationpolicylabel_binding" + authorizationPolicyCSVServerBindingURL = "/nitro/v1/config/authorizationpolicy_csvserver_binding" + authorizationPolicyLBVServerBindingURL = "/nitro/v1/config/authorizationpolicy_lbvserver_binding" + authorizationPolicyLabelURL = "/nitro/v1/config/authorizationpolicylabel" + authorizationPolicyAuthorizationPolicyLabelBindingURL = "/nitro/v1/config/authorizationpolicy_authorizationpolicylabel_binding" + authorizationPolicyBindingURL = "/nitro/v1/config/authorizationpolicy_binding" +) + // Authorization configuration. Authorization services check which resources users are authorized to access, and grant permissions accordingly. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authorization/authorization type AuthorizationService struct { @@ -7,85 +31,806 @@ type AuthorizationService struct { } // authorizationaction -// Configuration for authorization action resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authorization/authorizationaction -func (s *AuthorizationService) GetAllAuthorizationAction() {} -func (s *AuthorizationService) GetAuthorizationAction() {} -func (s *AuthorizationService) CountAuthorizationAction() {} + +func (s *AuthorizationService) GetAllAuthorizationAction() ([]models.AuthorizationAction, error) { + req, err := s.client.NewRequest(http.MethodGet, authorizationActionURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Actions []models.AuthorizationAction `json:"authorizationaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Actions, nil +} + +func (s *AuthorizationService) GetAuthorizationAction(name string) ([]models.AuthorizationAction, error) { + reqURL := fmt.Sprintf("%s/%s", authorizationActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Actions []models.AuthorizationAction `json:"authorizationaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Actions, nil +} + +func (s *AuthorizationService) CountAuthorizationAction() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, authorizationActionURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Actions []struct { + Count float64 `json:"__count"` + } `json:"authorizationaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Actions) > 0 { + return result.Actions[0].Count, nil + } + return 0, nil +} // authorizationpolicy -// Configuration for authorization policy resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authorization/authorizationpolicy -func (s *AuthorizationService) AddAuthorizationPolicy() {} -func (s *AuthorizationService) DeleteAuthorizationPolicy() {} -func (s *AuthorizationService) UpdateAuthorizationPolicy() {} -func (s *AuthorizationService) RenameAuthorizationPolicy() {} -func (s *AuthorizationService) GetAllAuthorizationPolicy() {} -func (s *AuthorizationService) GetAuthorizationPolicy() {} -func (s *AuthorizationService) CountAuthorizationPolicy() {} + +func (s *AuthorizationService) AddAuthorizationPolicy(policy models.AuthorizationPolicy) error { + payload := map[string]any{ + "authorizationpolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, authorizationPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuthorizationService) DeleteAuthorizationPolicy(name string) error { + reqURL := fmt.Sprintf("%s/%s", authorizationPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuthorizationService) UpdateAuthorizationPolicy(policy models.AuthorizationPolicy) error { + payload := map[string]any{ + "authorizationpolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, authorizationPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuthorizationService) RenameAuthorizationPolicy(name, newname string) error { + payload := map[string]any{ + "authorizationpolicy": map[string]string{ + "name": name, + "newname": newname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, authorizationPolicyURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuthorizationService) GetAllAuthorizationPolicy() ([]models.AuthorizationPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, authorizationPolicyURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Policies []models.AuthorizationPolicy `json:"authorizationpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Policies, nil +} + +func (s *AuthorizationService) GetAuthorizationPolicy(name string) ([]models.AuthorizationPolicy, error) { + reqURL := fmt.Sprintf("%s/%s", authorizationPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Policies []models.AuthorizationPolicy `json:"authorizationpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Policies, nil +} + +func (s *AuthorizationService) CountAuthorizationPolicy() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, authorizationPolicyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Policies []struct { + Count float64 `json:"__count"` + } `json:"authorizationpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Policies) > 0 { + return result.Policies[0].Count, nil + } + return 0, nil +} // authorizationpolicylabel -// Configuration for authorization policy label resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authorization/authorizationpolicylabel -func (s *AuthorizationService) AddAuthorizationPolicyLabel() {} -func (s *AuthorizationService) DeleteAuthorizationPolicyLabel() {} -func (s *AuthorizationService) RenameAuthorizationPolicyLabel() {} -func (s *AuthorizationService) GetAllAuthorizationPolicyLabel() {} -func (s *AuthorizationService) GetAuthorizationPolicyLabel() {} -func (s *AuthorizationService) CountAuthorizationPolicyLabel() {} + +func (s *AuthorizationService) AddAuthorizationPolicyLabel(label models.AuthorizationPolicyLabel) error { + payload := map[string]any{ + "authorizationpolicylabel": label, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, authorizationPolicyLabelURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuthorizationService) DeleteAuthorizationPolicyLabel(labelname string) error { + reqURL := fmt.Sprintf("%s/%s", authorizationPolicyLabelURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuthorizationService) RenameAuthorizationPolicyLabel(labelname, newname string) error { + payload := map[string]any{ + "authorizationpolicylabel": map[string]string{ + "labelname": labelname, + "newname": newname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, authorizationPolicyLabelURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuthorizationService) GetAllAuthorizationPolicyLabel() ([]models.AuthorizationPolicyLabel, error) { + req, err := s.client.NewRequest(http.MethodGet, authorizationPolicyLabelURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Labels []models.AuthorizationPolicyLabel `json:"authorizationpolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Labels, nil +} + +func (s *AuthorizationService) GetAuthorizationPolicyLabel(labelname string) ([]models.AuthorizationPolicyLabel, error) { + reqURL := fmt.Sprintf("%s/%s", authorizationPolicyLabelURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Labels []models.AuthorizationPolicyLabel `json:"authorizationpolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Labels, nil +} + +func (s *AuthorizationService) CountAuthorizationPolicyLabel() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, authorizationPolicyLabelURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Labels []struct { + Count float64 `json:"__count"` + } `json:"authorizationpolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Labels) > 0 { + return result.Labels[0].Count, nil + } + return 0, nil +} // authorizationpolicylabel_authorizationpolicy_binding -// Binding object showing the authorizationpolicy that can be bound to authorizationpolicylabel. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authorization/authorizationpolicylabel_authorizationpolicy_binding -func (s *AuthorizationService) AddAuthorizationPolicyLabelAuthorizationPolicyBinding() {} -func (s *AuthorizationService) DeleteAuthorizationPolicyLabelAuthorizationPolicyBinding() {} -func (s *AuthorizationService) GetAllAuthorizationPolicyLabelAuthorizationPolicyBinding() {} -func (s *AuthorizationService) GetAuthorizationPolicyLabelAuthorizationPolicyBinding() {} -func (s *AuthorizationService) CountAuthorizationPolicyLabelAuthorizationPolicyBinding() {} + +func (s *AuthorizationService) AddAuthorizationPolicyLabelAuthorizationPolicyBinding(binding models.AuthorizationPolicyLabelAuthorizationPolicyBinding) error { + payload := map[string]any{ + "authorizationpolicylabel_authorizationpolicy_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, authorizationPolicyLabelAuthorizationPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuthorizationService) DeleteAuthorizationPolicyLabelAuthorizationPolicyBinding(labelname, policyname string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,priority:%d", authorizationPolicyLabelAuthorizationPolicyBindingURL, url.QueryEscape(labelname), url.QueryEscape(policyname), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *AuthorizationService) GetAllAuthorizationPolicyLabelAuthorizationPolicyBinding() ([]models.AuthorizationPolicyLabelAuthorizationPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authorizationPolicyLabelAuthorizationPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuthorizationPolicyLabelAuthorizationPolicyBinding `json:"authorizationpolicylabel_authorizationpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuthorizationService) GetAuthorizationPolicyLabelAuthorizationPolicyBinding(labelname string) ([]models.AuthorizationPolicyLabelAuthorizationPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", authorizationPolicyLabelAuthorizationPolicyBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuthorizationPolicyLabelAuthorizationPolicyBinding `json:"authorizationpolicylabel_authorizationpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuthorizationService) CountAuthorizationPolicyLabelAuthorizationPolicyBinding(labelname string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", authorizationPolicyLabelAuthorizationPolicyBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"authorizationpolicylabel_authorizationpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // authorizationpolicylabel_binding -// Binding object which returns the resources bound to authorizationpolicylabel. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authorization/authorizationpolicylabel_binding -func (s *AuthorizationService) GetAllAuthorizationPolicyLabelBinding() {} -func (s *AuthorizationService) GetAuthorizationPolicyLabelBinding() {} + +func (s *AuthorizationService) GetAllAuthorizationPolicyLabelBinding() ([]models.AuthorizationPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authorizationPolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuthorizationPolicyLabelBinding `json:"authorizationpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuthorizationService) GetAuthorizationPolicyLabelBinding(labelname string) ([]models.AuthorizationPolicyLabelBinding, error) { + reqURL := fmt.Sprintf("%s/%s", authorizationPolicyLabelBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuthorizationPolicyLabelBinding `json:"authorizationpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // authorizationpolicy_aaagroup_binding -// Binding object showing the aaagroup that can be bound to authorizationpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authorization/authorizationpolicy_aaagroup_binding -func (s *AuthorizationService) GetAllAuthorizationPolicyAAAGroupBinding() {} -func (s *AuthorizationService) GetAuthorizationPolicyAAAGroupBinding() {} -func (s *AuthorizationService) CountAuthorizationPolicyAAAGroupBinding() {} + +func (s *AuthorizationService) GetAllAuthorizationPolicyAAAGroupBinding() ([]models.AuthorizationPolicyAAAGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authorizationPolicyAAAGroupBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuthorizationPolicyAAAGroupBinding `json:"authorizationpolicy_aaagroup_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuthorizationService) GetAuthorizationPolicyAAAGroupBinding(name string) ([]models.AuthorizationPolicyAAAGroupBinding, error) { + reqURL := fmt.Sprintf("%s/%s", authorizationPolicyAAAGroupBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuthorizationPolicyAAAGroupBinding `json:"authorizationpolicy_aaagroup_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuthorizationService) CountAuthorizationPolicyAAAGroupBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", authorizationPolicyAAAGroupBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"authorizationpolicy_aaagroup_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // authorizationpolicy_aaauser_binding -// Binding object showing the aaauser that can be bound to authorizationpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authorization/authorizationpolicy_aaauser_binding -func (s *AuthorizationService) GetAllAuthorizationPolicyAAAUserBinding() {} -func (s *AuthorizationService) GetAuthorizationPolicyAAAUserBinding() {} -func (s *AuthorizationService) CountAuthorizationPolicyAAAUserBinding() {} + +func (s *AuthorizationService) GetAllAuthorizationPolicyAAAUserBinding() ([]models.AuthorizationPolicyAAAUserBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authorizationPolicyAAAUserBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuthorizationPolicyAAAUserBinding `json:"authorizationpolicy_aaauser_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuthorizationService) GetAuthorizationPolicyAAAUserBinding(name string) ([]models.AuthorizationPolicyAAAUserBinding, error) { + reqURL := fmt.Sprintf("%s/%s", authorizationPolicyAAAUserBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuthorizationPolicyAAAUserBinding `json:"authorizationpolicy_aaauser_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuthorizationService) CountAuthorizationPolicyAAAUserBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", authorizationPolicyAAAUserBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"authorizationpolicy_aaauser_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // authorizationpolicy_authorizationpolicylabel_binding -// Binding object showing the authorizationpolicylabel that can be bound to authorizationpolicy -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authorization/authorizationpolicy_authorizationpolicylabel_binding -func (s *AuthorizationService) GetAllAuthorizationPolicyAuthorizationPolicyLabelBinding() {} -func (s *AuthorizationService) GetAuthorizationPolicyAuthorizationPolicyLabelBinding() {} -func (s *AuthorizationService) CountAuthorizationPolicyAuthorizationPolicyLabelBinding() {} + +func (s *AuthorizationService) GetAllAuthorizationPolicyAuthorizationPolicyLabelBinding() ([]models.AuthorizationPolicyAuthorizationPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authorizationPolicyAuthorizationPolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuthorizationPolicyAuthorizationPolicyLabelBinding `json:"authorizationpolicy_authorizationpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuthorizationService) GetAuthorizationPolicyAuthorizationPolicyLabelBinding(name string) ([]models.AuthorizationPolicyAuthorizationPolicyLabelBinding, error) { + reqURL := fmt.Sprintf("%s/%s", authorizationPolicyAuthorizationPolicyLabelBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuthorizationPolicyAuthorizationPolicyLabelBinding `json:"authorizationpolicy_authorizationpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuthorizationService) CountAuthorizationPolicyAuthorizationPolicyLabelBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", authorizationPolicyAuthorizationPolicyLabelBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"authorizationpolicy_authorizationpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // authorizationpolicy_binding -// Binding object which returns the resources bound to authorizationpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authorization/authorizationpolicy_binding -func (s *AuthorizationService) GetAllAuthorizationPolicyBinding() {} -func (s *AuthorizationService) GetAuthorizationPolicyBinding() {} + +func (s *AuthorizationService) GetAllAuthorizationPolicyBinding() ([]models.AuthorizationPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authorizationPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuthorizationPolicyBinding `json:"authorizationpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuthorizationService) GetAuthorizationPolicyBinding(name string) ([]models.AuthorizationPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", authorizationPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuthorizationPolicyBinding `json:"authorizationpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // authorizationpolicy_csvserver_binding -// Binding object showing the csvserver that can be bound to authorizationpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authorization/authorizationpolicy_csvserver_binding -func (s *AuthorizationService) GetAllAuthorizationPolicyCSVServerBinding() {} -func (s *AuthorizationService) GetAuthorizationPolicyCSVServerBinding() {} -func (s *AuthorizationService) CountAuthorizationPolicyCSVServerBinding() {} + +func (s *AuthorizationService) GetAllAuthorizationPolicyCSVServerBinding() ([]models.AuthorizationPolicyCSVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authorizationPolicyCSVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuthorizationPolicyCSVServerBinding `json:"authorizationpolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuthorizationService) GetAuthorizationPolicyCSVServerBinding(name string) ([]models.AuthorizationPolicyCSVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", authorizationPolicyCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuthorizationPolicyCSVServerBinding `json:"authorizationpolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuthorizationService) CountAuthorizationPolicyCSVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", authorizationPolicyCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"authorizationpolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // authorizationpolicy_lbvserver_binding -// Binding object showing the lbvserver that can be bound to authorizationpolicy. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/authorization/authorizationpolicy_lbvserver_binding -func (s *AuthorizationService) GetAllAuthorizationPolicyLBVServerBinding() {} -func (s *AuthorizationService) GetAuthorizationPolicyLBVServerBinding() {} -func (s *AuthorizationService) CountAuthorizationPolicyLBVServerBinding() {} + +func (s *AuthorizationService) GetAllAuthorizationPolicyLBVServerBinding() ([]models.AuthorizationPolicyLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, authorizationPolicyLBVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuthorizationPolicyLBVServerBinding `json:"authorizationpolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuthorizationService) GetAuthorizationPolicyLBVServerBinding(name string) ([]models.AuthorizationPolicyLBVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", authorizationPolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.AuthorizationPolicyLBVServerBinding `json:"authorizationpolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *AuthorizationService) CountAuthorizationPolicyLBVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", authorizationPolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"authorizationpolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} diff --git a/nitrogo/autoscale.go b/nitrogo/autoscale.go index a032c41..9ddba6e 100644 --- a/nitrogo/autoscale.go +++ b/nitrogo/autoscale.go @@ -1,5 +1,23 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + autoscaleActionURL = "/nitro/v1/config/autoscaleaction" + autoscalePolicyURL = "/nitro/v1/config/autoscalepolicy" + autoscalePolicyBindingURL = "/nitro/v1/config/autoscalepolicy_binding" + autoscalePolicyNSTimerBindingURL = "/nitro/v1/config/autoscalepolicy_nstimer_binding" + autoscaleProfileURL = "/nitro/v1/config/autoscaleprofile" +) + // AutoScale configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/autoscale/autoscale type AutoscaleService struct { @@ -9,45 +27,579 @@ type AutoscaleService struct { // autoscaleaction // Configuration for autoscale action resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/autoscale/autoscaleaction -func (s *AutoscaleService) AddAutoscaleAction() {} -func (s *AutoscaleService) DeleteAutoscaleAction() {} -func (s *AutoscaleService) UpdateAutoscaleAction() {} -func (s *AutoscaleService) UnsetAutoscaleAction() {} -func (s *AutoscaleService) GetAllAutoscaleAction() {} -func (s *AutoscaleService) GetAutoscaleAction() {} -func (s *AutoscaleService) CountAutoscaleAction() {} + +func (s *AutoscaleService) AddAutoscaleAction(action models.AutoscaleAction) error { + payload := map[string]any{ + "autoscaleaction": action, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, autoscaleActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AutoscaleService) DeleteAutoscaleAction(name string) error { + urlReq := fmt.Sprintf("%s/%s", autoscaleActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AutoscaleService) UpdateAutoscaleAction(action models.AutoscaleAction) error { + payload := map[string]any{ + "autoscaleaction": action, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, autoscaleActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AutoscaleService) UnsetAutoscaleAction(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "autoscaleaction": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, autoscaleActionURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AutoscaleService) GetAllAutoscaleAction() ([]models.AutoscaleAction, error) { + req, err := s.client.NewRequest(http.MethodGet, autoscaleActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Actions []models.AutoscaleAction `json:"autoscaleaction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Actions, nil +} + +func (s *AutoscaleService) GetAutoscaleAction(name string) ([]models.AutoscaleAction, error) { + urlReq := fmt.Sprintf("%s/%s", autoscaleActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Actions []models.AutoscaleAction `json:"autoscaleaction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Actions, nil +} + +func (s *AutoscaleService) CountAutoscaleAction() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, autoscaleActionURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Actions []struct { + Count float64 `json:"__count"` + } `json:"autoscaleaction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Actions) > 0 { + return result.Actions[0].Count, nil + } + + return 0, nil +} // autoscalepolicy // Configuration for Autoscale policy resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/autoscale/autoscalepolicy -func (s *AutoscaleService) AddAutoscalePolicy() {} -func (s *AutoscaleService) DeleteAutoscalePolicy() {} -func (s *AutoscaleService) UpdateAutoscalePolicy() {} -func (s *AutoscaleService) UnsetAutoscalePolicy() {} -func (s *AutoscaleService) GetAllAutoscalePolicy() {} -func (s *AutoscaleService) GetAutoscalePolicy() {} -func (s *AutoscaleService) CountAutoscalePolicy() {} -func (s *AutoscaleService) RenameAutoscalePolicy() {} + +func (s *AutoscaleService) AddAutoscalePolicy(policy models.AutoscalePolicy) error { + payload := map[string]any{ + "autoscalepolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, autoscalePolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AutoscaleService) DeleteAutoscalePolicy(name string) error { + urlReq := fmt.Sprintf("%s/%s", autoscalePolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AutoscaleService) UpdateAutoscalePolicy(policy models.AutoscalePolicy) error { + payload := map[string]any{ + "autoscalepolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, autoscalePolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AutoscaleService) UnsetAutoscalePolicy(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "autoscalepolicy": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, autoscalePolicyURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AutoscaleService) GetAllAutoscalePolicy() ([]models.AutoscalePolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, autoscalePolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Policies []models.AutoscalePolicy `json:"autoscalepolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Policies, nil +} + +func (s *AutoscaleService) GetAutoscalePolicy(name string) ([]models.AutoscalePolicy, error) { + urlReq := fmt.Sprintf("%s/%s", autoscalePolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Policies []models.AutoscalePolicy `json:"autoscalepolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Policies, nil +} + +func (s *AutoscaleService) CountAutoscalePolicy() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, autoscalePolicyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Policies []struct { + Count float64 `json:"__count"` + } `json:"autoscalepolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Policies) > 0 { + return result.Policies[0].Count, nil + } + + return 0, nil +} + +func (s *AutoscaleService) RenameAutoscalePolicy(name string, newname string) error { + payload := map[string]any{ + "autoscalepolicy": map[string]string{ + "name": name, + "newname": newname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, autoscalePolicyURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} // autoscalepolicy_binding // Binding object which returns the resources bound to autoscalepolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/autoscale/autoscalepolicy_binding -func (s *AutoscaleService) GetAllAutoscalePolicyBinding() {} -func (s *AutoscaleService) GetAutoscalePolicyBinding() {} + +func (s *AutoscaleService) GetAllAutoscalePolicyBinding() ([]models.AutoscalePolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, autoscalePolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AutoscalePolicyBinding `json:"autoscalepolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AutoscaleService) GetAutoscalePolicyBinding(name string) ([]models.AutoscalePolicyBinding, error) { + urlReq := fmt.Sprintf("%s/%s", autoscalePolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AutoscalePolicyBinding `json:"autoscalepolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} // autoscalepolicy_nstimer_binding // Binding object showing the nstimer that can be bound to autoscalepolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/autoscale/autoscalepolicy_nstimer_binding -func (s *AutoscaleService) GetAllAutoscalePolicyNSTimerBinding() {} -func (s *AutoscaleService) GetAutoscalePolicyNSTimerBinding() {} -func (s *AutoscaleService) CountAutoscalePolicyNSTimerBinding() {} + +func (s *AutoscaleService) GetAllAutoscalePolicyNSTimerBinding() ([]models.AutoscalePolicyNSTimerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, autoscalePolicyNSTimerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AutoscalePolicyNSTimerBinding `json:"autoscalepolicy_nstimer_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AutoscaleService) GetAutoscalePolicyNSTimerBinding(name string) ([]models.AutoscalePolicyNSTimerBinding, error) { + urlReq := fmt.Sprintf("%s/%s", autoscalePolicyNSTimerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.AutoscalePolicyNSTimerBinding `json:"autoscalepolicy_nstimer_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *AutoscaleService) CountAutoscalePolicyNSTimerBinding(name string) (float64, error) { + urlReq := fmt.Sprintf("%s/%s?count=yes", autoscalePolicyNSTimerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"autoscalepolicy_nstimer_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} // autoscaleprofile // Configuration for autoscale profile resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/autoscale/autoscaleprofile -func (s *AutoscaleService) AddAutoscaleProfile() {} -func (s *AutoscaleService) DeleteAutoscaleProfile() {} -func (s *AutoscaleService) UpdateAutoscaleProfile() {} -func (s *AutoscaleService) GetAllAutoscaleProfile() {} -func (s *AutoscaleService) GetAutoscaleProfile() {} -func (s *AutoscaleService) CountAutoscaleProfile() {} + +func (s *AutoscaleService) AddAutoscaleProfile(profile models.AutoscaleProfile) error { + payload := map[string]any{ + "autoscaleprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, autoscaleProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AutoscaleService) DeleteAutoscaleProfile(name string) error { + urlReq := fmt.Sprintf("%s/%s", autoscaleProfileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AutoscaleService) UpdateAutoscaleProfile(profile models.AutoscaleProfile) error { + payload := map[string]any{ + "autoscaleprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, autoscaleProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AutoscaleService) GetAllAutoscaleProfile() ([]models.AutoscaleProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, autoscaleProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Profiles []models.AutoscaleProfile `json:"autoscaleprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Profiles, nil +} + +func (s *AutoscaleService) GetAutoscaleProfile(name string) ([]models.AutoscaleProfile, error) { + urlReq := fmt.Sprintf("%s/%s", autoscaleProfileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Profiles []models.AutoscaleProfile `json:"autoscaleprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Profiles, nil +} + +func (s *AutoscaleService) CountAutoscaleProfile() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, autoscaleProfileURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Profiles []struct { + Count float64 `json:"__count"` + } `json:"autoscaleprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Profiles) > 0 { + return result.Profiles[0].Count, nil + } + + return 0, nil +} diff --git a/nitrogo/azure.go b/nitrogo/azure.go index 5f3eedf..f7a36cd 100644 --- a/nitrogo/azure.go +++ b/nitrogo/azure.go @@ -1,5 +1,19 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + azureApplicationURL = "/nitro/v1/config/azureapplication" + azureKeyVaultURL = "/nitro/v1/config/azurekeyvault" +) + // Azure configuration // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/azure/azure type AzureService struct { @@ -9,17 +23,217 @@ type AzureService struct { // azureapplication // Configuration for Azure Application resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/azure/azureapplication -func (s *AzureService) AddAzureApplication() {} -func (s *AzureService) DeleteAzureApplication() {} -func (s *AzureService) GetAllAzureApplication() {} -func (s *AzureService) GetAzureApplication() {} -func (s *AzureService) CountAzureApplication() {} + +func (s *AzureService) AddAzureApplication(application models.AzureApplication) error { + payload := map[string]any{ + "azureapplication": application, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, azureApplicationURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AzureService) DeleteAzureApplication(name string) error { + url := fmt.Sprintf("%s/%s", azureApplicationURL, name) + req, err := s.client.NewRequest(http.MethodDelete, url, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AzureService) GetAllAzureApplication() ([]models.AzureApplication, error) { + req, err := s.client.NewRequest(http.MethodGet, azureApplicationURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + AzureApplications []models.AzureApplication `json:"azureapplication"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.AzureApplications, nil +} + +func (s *AzureService) GetAzureApplication(name string) ([]models.AzureApplication, error) { + url := fmt.Sprintf("%s/%s", azureApplicationURL, name) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + AzureApplications []models.AzureApplication `json:"azureapplication"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.AzureApplications, nil +} + +func (s *AzureService) CountAzureApplication() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, azureApplicationURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + AzureApplications []struct { + Count float64 `json:"__count"` + } `json:"azureapplication"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.AzureApplications) > 0 { + return result.AzureApplications[0].Count, nil + } + + return 0, nil +} // azurekeyvault // Configuration for Azure Key Vault entity resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/azure/azurekeyvault -func (s *AzureService) AddAzureKeyVault() {} -func (s *AzureService) DeleteAzureKeyVault() {} -func (s *AzureService) GetAllAzureKeyVault() {} -func (s *AzureService) GetAzureKeyVault() {} -func (s *AzureService) CountAzureKeyVault() {} + +func (s *AzureService) AddAzureKeyVault(keyVault models.AzureKeyVault) error { + payload := map[string]any{ + "azurekeyvault": keyVault, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, azureKeyVaultURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AzureService) DeleteAzureKeyVault(name string) error { + url := fmt.Sprintf("%s/%s", azureKeyVaultURL, name) + req, err := s.client.NewRequest(http.MethodDelete, url, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *AzureService) GetAllAzureKeyVault() ([]models.AzureKeyVault, error) { + req, err := s.client.NewRequest(http.MethodGet, azureKeyVaultURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + AzureKeyVaults []models.AzureKeyVault `json:"azurekeyvault"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.AzureKeyVaults, nil +} + +func (s *AzureService) GetAzureKeyVault(name string) ([]models.AzureKeyVault, error) { + url := fmt.Sprintf("%s/%s", azureKeyVaultURL, name) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + AzureKeyVaults []models.AzureKeyVault `json:"azurekeyvault"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.AzureKeyVaults, nil +} + +func (s *AzureService) CountAzureKeyVault() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, azureKeyVaultURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + AzureKeyVaults []struct { + Count float64 `json:"__count"` + } `json:"azurekeyvault"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.AzureKeyVaults) > 0 { + return result.AzureKeyVaults[0].Count, nil + } + + return 0, nil +} diff --git a/nitrogo/basic.go b/nitrogo/basic.go index 84b519e..cd61f14 100644 --- a/nitrogo/basic.go +++ b/nitrogo/basic.go @@ -1,13 +1,47 @@ package nitrogo import ( + "bytes" "encoding/json" "fmt" "net/http" + "net/url" + "strings" "github.com/AdamJCrawford/NitroGo/nitrogo/models" ) +const ( + dbsMonitorsURL = "/nitro/v1/config/dbsmonitors" + extendedMemoryParamURL = "/nitro/v1/config/extendedmemoryparam" + locationURL = "/nitro/v1/config/location" + locationDataURL = "/nitro/v1/config/locationdata" + locationFileURL = "/nitro/v1/config/locationfile" + locationFile6URL = "/nitro/v1/config/locationfile6" + locationParameterURL = "/nitro/v1/config/locationparameter" + nsTraceURL = "/nitro/v1/config/nstrace" + radiusNodeURL = "/nitro/v1/config/radiusnode" + reportingURL = "/nitro/v1/config/reporting" + serverURL = "/nitro/v1/config/server" + serverBindingURL = "/nitro/v1/config/server_binding" + serverGSLBServiceBindingURL = "/nitro/v1/config/server_gslbservice_binding" + serverGSLBServiceGroupBindingURL = "/nitro/v1/config/server_gslbservicegroup_binding" + serverServiceBindingURL = "/nitro/v1/config/server_service_binding" + serverServiceGroupBindingURL = "/nitro/v1/config/server_servicegroup_binding" + serviceURL = "/nitro/v1/config/service" + serviceBindingURL = "/nitro/v1/config/service_binding" + serviceGroupLBMonitorBindingURL = "/nitro/v1/config/servicegroup_lbmonitor_binding" + serviceGroupURL = "/nitro/v1/config/servicegroup" + serviceGroupBindingURL = "/nitro/v1/config/servicegroup_binding" + serviceLBMonitorBindingURL = "/nitro/v1/config/service_lbmonitor_binding" + serviceGroupServiceGroupEntityMonBindingsBindingURL = "/nitro/v1/config/servicegroup_servicegroupentitymonbindings_binding" + serviceGroupServiceGroupMemberBindingURL = "/nitro/v1/config/servicegroup_servicegroupmember_binding" + serviceGroupServiceGroupMemberListBindingURL = "/nitro/v1/config/servicegroup_servicegoupmemberlist_binding" + serviceGroupBindingsURL = "/nitro/v1/config/servicegroupbindings" + svcBindingsURL = "/nitro/v1/config/svcbindings" + vServerURL = "/nitro/v1/config/vserver" +) + // Basic system configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/basic type BasicService struct { @@ -17,246 +51,2356 @@ type BasicService struct { // dbsmonitors // Configuration for DB monitors resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/dbsmonitors -func (s *BasicService) RestartDBSMonitors() {} +func (s *BasicService) RestartDBSMonitors() error { + req, err := s.client.NewRequest(http.MethodPost, dbsMonitorsURL+"?action=restart", nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} // extendedmemoryparam // Configuration for Parameter for extended memory used by LSN and Subscriber Store resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/extendedmemoryparam -func (s *BasicService) UpdateExtendedMemoryParam() {} -func (s *BasicService) UnsetExtendedMemoryParam() {} -func (s *BasicService) GetAllExtendedMemoryParam() {} +func (s *BasicService) UpdateExtendedMemoryParam(resource models.ExtendedMemoryParam) error { + payload := map[string]any{"extendedmemoryparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, extendedMemoryParamURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) UnsetExtendedMemoryParam(resource models.ExtendedMemoryParam) error { + payload := map[string]any{"extendedmemoryparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", extendedMemoryParamURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) GetAllExtendedMemoryParam() (models.ExtendedMemoryParam, error) { + req, err := s.client.NewRequest(http.MethodGet, extendedMemoryParamURL, nil) + if err != nil { + return models.ExtendedMemoryParam{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.ExtendedMemoryParam{}, err + } + + var result struct { + ExtendedMemoryParam models.ExtendedMemoryParam `json:"extendedmemoryparam"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.ExtendedMemoryParam{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.ExtendedMemoryParam, nil +} // location // Configuration for location resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/location -func (s *BasicService) AddLocation() {} -func (s *BasicService) DeleteLocation() {} -func (s *BasicService) GetAllLocation() {} -func (s *BasicService) GetLocation() {} -func (s *BasicService) CountLocation() {} +func (s *BasicService) AddLocation(resource models.Location) error { + payload := map[string]any{"location": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, locationURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) DeleteLocation(ip string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", locationURL, ip), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) GetAllLocation() ([]models.Location, error) { + req, err := s.client.NewRequest(http.MethodGet, locationURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Location []models.Location `json:"location"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Location, nil +} + +func (s *BasicService) GetLocation(ip string) (models.Location, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", locationURL, ip), nil) + if err != nil { + return models.Location{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.Location{}, err + } + + var result struct { + Location []models.Location `json:"location"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.Location{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Location) == 0 { + return models.Location{}, fmt.Errorf("location %s not found", ip) + } + + return result.Location[0], nil +} + +// Struct lacks Count field, leaving for later +func (s *BasicService) CountLocation() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, locationURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"location"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} // locationdata // Configuration for location data resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/locationdata -func (s *BasicService) ClearLocationData() {} +func (s *BasicService) ClearLocationData() error { + payload := map[string]any{"locationdata": models.LocationData{}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=clear", locationDataURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} // locationfile // Configuration for location file resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/locationfile -func (s *BasicService) AddLocationFile() {} -func (s *BasicService) DeleteLocationFile() {} -func (s *BasicService) GetAllLocationFile() {} -func (s *BasicService) ImportLocationFile() {} +func (s *BasicService) AddLocationFile(resource models.LocationFile) error { + payload := map[string]any{"locationfile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, locationFileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) DeleteLocationFile(LocationFile string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", locationFileURL, LocationFile), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) GetAllLocationFile() ([]models.LocationFile, error) { + req, err := s.client.NewRequest(http.MethodGet, locationFileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + LocationFile []models.LocationFile `json:"locationfile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.LocationFile, nil +} + +func (s *BasicService) ImportLocationFile(resource models.LocationFile) error { + payload := map[string]any{"locationfile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=import", locationFileURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} // locationfile6 // Configuration for location file6 resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/locationfile6 -func (s *BasicService) AddLocationFile6() {} -func (s *BasicService) DeleteLocationFile6() {} -func (s *BasicService) GetAllLocationFile6() {} -func (s *BasicService) CountLocationFile6() {} -func (s *BasicService) ImportLocationFile6() {} +func (s *BasicService) AddLocationFile6(resource models.LocationFile6) error { + payload := map[string]any{"locationfile6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// locationparameter -// Configuration for location parameter resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/locationparameter -func (s *BasicService) UpdateLocationParameter() {} -func (s *BasicService) UnsetLocationParameter() {} -func (s *BasicService) GetAllLocationParameter() {} + req, err := s.client.NewRequest(http.MethodPost, locationFile6URL, bytes.NewReader(data)) + if err != nil { + return err + } -// nstrace -// Configuration for nstrace operations resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/nstrace -func (s *BasicService) GetAllNSTrace() {} + _, err = s.client.Do(req) + return err +} -// radiusnode -// Configuration for RADIUS Node resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/radiusnode -func (s *BasicService) AddRADIUSNode() {} -func (s *BasicService) DeleteRADIUSNode() {} -func (s *BasicService) UpdateRADIUSNode() {} -func (s *BasicService) GetAllRADIUSNode() {} -func (s *BasicService) GetRADIUSNode() {} -func (s *BasicService) CountRADIUSNode() {} +func (s *BasicService) DeleteLocationFile6() error { + req, err := s.client.NewRequest(http.MethodDelete, locationFile6URL, nil) + if err != nil { + return err + } -// reporting -// Configuration for reporting resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/reporting -func (s *BasicService) EnableReporting() {} -func (s *BasicService) DisableReporting() {} -func (s *BasicService) GetAllReporting() {} + _, err = s.client.Do(req) + return err +} -// server -// Configuration for server resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/server -func (s *BasicService) AddServer() {} -func (s *BasicService) DeleteServer() {} -func (s *BasicService) UpdateServer() {} -func (s *BasicService) UnsetServer() {} -func (s *BasicService) EnableServer() {} -func (s *BasicService) DisableServer() {} -func (s *BasicService) GetAllServer() {} -func (s *BasicService) GetServer() {} -func (s *BasicService) CountServer() {} -func (s *BasicService) RenameServer() {} +func (s *BasicService) GetAllLocationFile6() ([]models.LocationFile6, error) { + req, err := s.client.NewRequest(http.MethodGet, locationFile6URL, nil) + if err != nil { + return nil, err + } -// server_binding -// Binding object which returns the resources bound to server. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/server_binding -func (s *BasicService) GetAllServerBinding() {} -func (s *BasicService) GetServerBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// server_gslbservicegroup_binding -// Binding object showing the gslbservicegroup that can be bound to server. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/server_gslbservicegroup_binding -func (s *BasicService) GetAllServerGSLBServiceGroupBinding() {} -func (s *BasicService) GetServerGSLBServiceGroupBinding() {} -func (s *BasicService) CountServerGSLBServiceGroupBinding() {} + var result struct { + LocationFile6 []models.LocationFile6 `json:"locationfile6"` + } -// server_gslbservice_binding -// Binding object showing the gslbservice that can be bound to server. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/server_gslbservice_binding -func (s *BasicService) GetAllServerGSLBServiceBinding() {} -func (s *BasicService) GetServerGSLBServiceBinding() {} -func (s *BasicService) CountServerGSLBServiceBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// server_servicegroup_binding -// Binding object showing the servicegroup that can be bound to server. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/server_servicegroup_binding -func (s *BasicService) GetAllServerServiceGroupBinding() {} -func (s *BasicService) GetServerServiceGroupBinding() {} -func (s *BasicService) CountServerServiceGroupBinding() {} + return result.LocationFile6, nil +} -// server_service_binding -// Binding object showing the service that can be bound to server. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/server_service_binding -func (s *BasicService) GetAllServerServiceBinding() {} -func (s *BasicService) GetServerServiceBinding() {} -func (s *BasicService) CountServerServiceBinding() {} +// Struct lacks Count field, leaving for later +func (s *BasicService) CountLocationFile6() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, locationFile6URL+"?count=yes", nil) + if err != nil { + return 0, err + } -// service -// Configuration for service resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/service -func (s *BasicService) AddService() {} -func (s *BasicService) DeleteService() {} -func (s *BasicService) UpdateService() {} -func (s *BasicService) UnsetService() {} -func (s *BasicService) EnableService() {} -func (s *BasicService) DisableService() {} -func (s *BasicService) GetAllService() {} -func (s *BasicService) GetService() {} -func (s *BasicService) CountService() {} -func (s *BasicService) RenameService() {} + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } -// servicegroup -// Configuration for service group resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/servicegroup -func (s *BasicService) AddServiceGroup() {} -func (s *BasicService) DeleteServiceGroup() {} -func (s *BasicService) UpdateServiceGroup() {} -func (s *BasicService) UnsetServiceGroup() {} -func (s *BasicService) EnableServiceGroup() {} -func (s *BasicService) DisableServiceGroup() {} -func (s *BasicService) GetAllServiceGroup() {} -func (s *BasicService) GetServiceGroup() {} -func (s *BasicService) CountServiceGroup() {} -func (s *BasicService) RenameServiceGroup() {} + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"locationfile6"` + } -// servicegroupbindings -// Configuration for servicegroupbind resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/servicegroupbindings -func (s *BasicService) GetAllServiceGroupBindings() {} -func (s *BasicService) GetServiceGroupBindings() {} -func (s *BasicService) CountServiceGroupBindings() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } -// servicegroup_binding -// Binding object which returns the resources bound to servicegroup. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/servicegroup_binding -func (s *BasicService) GetAllServiceGroupBinding() {} -func (s *BasicService) GetServiceGroupBinding(serviceGroupName string) ([]models.ServiceGroupBinding, error) { - u := fmt.Sprintf("nitro/v1/config/servicegroup_binding/%s", serviceGroupName) - v := []models.ServiceGroupBinding{} + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} - req, err := s.client.NewRequest(http.MethodGet, u, nil) +func (s *BasicService) ImportLocationFile6(resource models.LocationFile6) error { + payload := map[string]any{"locationfile6": resource} + data, err := json.Marshal(payload) if err != nil { - return v, err + return err } - resp, err := s.client.Do(req) + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=import", locationFile6URL), bytes.NewReader(data)) if err != nil { - return v, err + return err } - data, err := json.Marshal(resp["servicegroup_binding"]) + _, err = s.client.Do(req) + return err +} + +// locationparameter +// Configuration for location parameter resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/locationparameter +func (s *BasicService) UpdateLocationParameter(resource models.LocationParameter) error { + payload := map[string]any{"locationparameter": resource} + data, err := json.Marshal(payload) if err != nil { - return v, err + return err } - err = json.Unmarshal(data, &v) + req, err := s.client.NewRequest(http.MethodPut, locationParameterURL, bytes.NewReader(data)) if err != nil { - return v, fmt.Errorf("failed to unmarshal: %w", err) + return err } - return v, nil + _, err = s.client.Do(req) + return err } -// servicegroup_lbmonitor_binding -// Binding object showing the lbmonitor that can be bound to servicegroup. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/servicegroup_lbmonitor_binding -func (s *BasicService) AddServiceGroupLBMonitorBinding() {} -func (s *BasicService) DeleteServiceGroupLBMonitorBinding() {} -func (s *BasicService) GetAllServiceGroupLBMonitorBinding() {} -func (s *BasicService) GetServiceGroupLBMonitorBinding() {} -func (s *BasicService) CountServiceGroupLBMonitorBinding() {} +func (s *BasicService) UnsetLocationParameter(resource models.LocationParameter) error { + payload := map[string]any{"locationparameter": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// servicegroup_servicegroupentitymonbindings_binding -// Binding object showing the servicegroupentitymonbindings that can be bound to servicegroup. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/servicegroup_servicegroupentitymonbindings_binding -func (s *BasicService) GetAllServiceGroupServiceGroupEntityMonBindingsBinding() {} -func (s *BasicService) GetServiceGroupServiceGroupEntityMonBindingsBinding() {} -func (s *BasicService) CountServiceGroupServiceGroupEntityMonBindingsBinding() {} + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", locationParameterURL), bytes.NewReader(data)) + if err != nil { + return err + } -// servicegroup_servicegoupmemberlist_binding -// Binding object showing the servicegroupmemberlist that can be bound to servicegroup. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/servicegroup_servicegroupmemberlist_binding -func (s *BasicService) AddServiceGroupServiceGroupMemberListBinding() {} -func (s *BasicService) DeleteServiceGroupServiceGroupMemberListBinding() {} + _, err = s.client.Do(req) + return err +} -// servicegroup_servicegroupmember_binding -// Binding object showing the servicegroupmember that can be bound to servicegroup. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/servicegroup_servicegroupmember_binding -func (s *BasicService) AddServiceGroupServiceGroupMemberBinding() {} -func (s *BasicService) DeleteServiceGroupServiceGroupMemberBinding() {} -func (s *BasicService) GetAllServiceGroupServiceGroupMemberBinding() {} -func (s *BasicService) GetServiceGroupServiceGroupMemberBinding() {} -func (s *BasicService) CountServiceGroupServiceGroupMemberBinding() {} +func (s *BasicService) GetAllLocationParameter() (models.LocationParameter, error) { + req, err := s.client.NewRequest(http.MethodGet, locationParameterURL, nil) + if err != nil { + return models.LocationParameter{}, err + } -// service_binding -// Binding object which returns the resources bound to service. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/service_binding -func (s *BasicService) GetAllServiceBinding() {} -func (s *BasicService) GetServiceBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return models.LocationParameter{}, err + } -// service_lbmonitor_binding -// Binding object showing the lbmonitor that can be bound to service. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/service_lbmonitor_binding -func (s *BasicService) AddServiceLBMonitorBinding() {} -func (s *BasicService) DeleteServiceLBMonitorBinding() {} -func (s *BasicService) GetAllServiceLBMonitorBinding() {} -func (s *BasicService) GetServiceLBMonitorBinding() {} -func (s *BasicService) CountServiceLBMonitorBinding() {} + var result struct { + LocationParameter models.LocationParameter `json:"locationparameter"` + } -// svcbindings -// Configuration for service bindings resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/svcbindings -func (s *BasicService) GetAllSVCBindings() {} -func (s *BasicService) GetSVCBindings() {} -func (s *BasicService) CountSVCBindings() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return models.LocationParameter{}, fmt.Errorf("failed to unmarshal: %w", err) + } -// vserver -// Configuration for virtual server resource. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/vserver -func (s *BasicService) DeleteVServer() {} -func (s *BasicService) UpdateVServer() {} -func (s *BasicService) EnableVServer() {} -func (s *BasicService) DisableVServer() {} + return result.LocationParameter, nil +} + +// nstrace +// Configuration for nstrace operations resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/nstrace +func (s *BasicService) GetAllNSTrace() ([]models.NSTrace, error) { + req, err := s.client.NewRequest(http.MethodGet, nsTraceURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + NSTrace []models.NSTrace `json:"nstrace"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.NSTrace, nil +} + +// radiusnode +// Configuration for RADIUS Node resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/radiusnode +func (s *BasicService) AddRADIUSNode(resource models.RADIUSNode) error { + payload := map[string]any{"radiusnode": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, radiusNodeURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) DeleteRADIUSNode(nodeprefix string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", radiusNodeURL, nodeprefix), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) UpdateRADIUSNode(resource models.RADIUSNode) error { + payload := map[string]any{"radiusnode": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, radiusNodeURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) GetAllRADIUSNode() ([]models.RADIUSNode, error) { + req, err := s.client.NewRequest(http.MethodGet, radiusNodeURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + RADIUSNode []models.RADIUSNode `json:"radiusnode"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.RADIUSNode, nil +} + +func (s *BasicService) GetRADIUSNode(nodeprefix string) (models.RADIUSNode, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", radiusNodeURL, nodeprefix), nil) + if err != nil { + return models.RADIUSNode{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.RADIUSNode{}, err + } + + var result struct { + RADIUSNode []models.RADIUSNode `json:"radiusnode"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.RADIUSNode{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.RADIUSNode) == 0 { + return models.RADIUSNode{}, fmt.Errorf("radiusnode %s not found", nodeprefix) + } + + return result.RADIUSNode[0], nil +} + +// Struct lacks Count field, leaving for later +func (s *BasicService) CountRADIUSNode() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, radiusNodeURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"radiusnode"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// reporting +// Configuration for reporting resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/reporting +func (s *BasicService) EnableReporting() error { + payload := map[string]any{"reporting": models.Reporting{}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=enable", reportingURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) DisableReporting() error { + payload := map[string]any{"reporting": models.Reporting{}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=disable", reportingURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) GetAllReporting() (models.Reporting, error) { + req, err := s.client.NewRequest(http.MethodGet, reportingURL, nil) + if err != nil { + return models.Reporting{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.Reporting{}, err + } + + var result struct { + Data models.Reporting `json:"reporting"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.Reporting{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// server +// Configuration for server resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/server +func (s *BasicService) AddServer(resource models.Server) error { + payload := map[string]any{"server": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, serverURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) DeleteServer(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", serverURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) UpdateServer(resource models.Server) error { + payload := map[string]any{"server": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, serverURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) UnsetServer(resource models.Server) error { + payload := map[string]any{"server": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", serverURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) EnableServer(resource models.Server) error { + payload := map[string]any{"server": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=enable", serverURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) DisableServer(resource models.Server) error { + payload := map[string]any{"server": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=disable", serverURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) GetAllServer() ([]models.Server, error) { + req, err := s.client.NewRequest(http.MethodGet, serverURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Server []models.Server `json:"server"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Server, nil +} + +func (s *BasicService) GetServer(name string) (models.Server, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", serverURL, name), nil) + if err != nil { + return models.Server{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.Server{}, err + } + + var result struct { + Server []models.Server `json:"server"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.Server{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Server) == 0 { + return models.Server{}, fmt.Errorf("server %s not found", name) + } + + return result.Server[0], nil +} + +func (s *BasicService) CountServer() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", serverURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Server []models.Server `json:"server"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Server) > 0 { + return int(result.Server[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +func (s *BasicService) RenameServer(resource models.Server) error { + payload := map[string]any{"server": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=rename", serverURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// server_binding +// Binding object which returns the resources bound to server. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/server_binding +func (s *BasicService) GetAllServerBinding() ([]models.ServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, serverBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + ServerBinding []models.ServerBinding `json:"server_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.ServerBinding, nil +} + +func (s *BasicService) GetServerBinding(name string) (models.ServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", serverBindingURL, name), nil) + if err != nil { + return models.ServerBinding{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.ServerBinding{}, err + } + + var result struct { + ServerBinding []models.ServerBinding `json:"server_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.ServerBinding{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.ServerBinding) == 0 { + return models.ServerBinding{}, fmt.Errorf("server_binding %s not found", name) + } + + return result.ServerBinding[0], nil +} + +// server_gslbservicegroup_binding +// Binding object showing the gslbservicegroup that can be bound to server. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/server_gslbservicegroup_binding +func (s *BasicService) GetAllServerGSLBServiceGroupBinding() ([]models.ServerGSLBServiceGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, serverGSLBServiceGroupBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + ServerGSLBServiceGroupBinding []models.ServerGSLBServiceGroupBinding `json:"server_gslbservicegroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.ServerGSLBServiceGroupBinding, nil +} + +func (s *BasicService) GetServerGSLBServiceGroupBinding(name string) ([]models.ServerGSLBServiceGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", serverGSLBServiceGroupBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + ServerGSLBServiceGroupBinding []models.ServerGSLBServiceGroupBinding `json:"server_gslbservicegroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.ServerGSLBServiceGroupBinding, nil +} + +// Struct lacks Count field, leaving for later +func (s *BasicService) CountServerGSLBServiceGroupBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, serverGSLBServiceGroupBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"server_gslbservicegroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// server_gslbservice_binding +// Binding object showing the gslbservice that can be bound to server. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/server_gslbservice_binding +func (s *BasicService) GetAllServerGSLBServiceBinding() ([]models.ServerGSLBServiceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, serverGSLBServiceBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + ServerGSLBServiceBinding []models.ServerGSLBServiceBinding `json:"server_gslbservice_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.ServerGSLBServiceBinding, nil +} + +func (s *BasicService) GetServerGSLBServiceBinding(name string) ([]models.ServerGSLBServiceBinding, error) { + reqURL := fmt.Sprintf("%s/%s", serverGSLBServiceBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + ServerGSLBServiceBinding []models.ServerGSLBServiceBinding `json:"server_gslbservice_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.ServerGSLBServiceBinding, nil +} + +func (s *BasicService) CountServerGSLBServiceBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, serverGSLBServiceBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"server_gslbservice_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// server_servicegroup_binding +// Binding object showing the servicegroup that can be bound to server. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/server_servicegroup_binding +func (s *BasicService) GetAllServerServiceGroupBinding() ([]models.ServerServiceGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, serverServiceGroupBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + ServerServiceGroupBinding []models.ServerServiceGroupBinding `json:"server_servicegroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.ServerServiceGroupBinding, nil +} + +func (s *BasicService) GetServerServiceGroupBinding(name string) ([]models.ServerServiceGroupBinding, error) { + reqURL := fmt.Sprintf("%s/%s", serverServiceGroupBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + ServerServiceGroupBinding []models.ServerServiceGroupBinding `json:"server_servicegroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.ServerServiceGroupBinding, nil +} + +func (s *BasicService) CountServerServiceGroupBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, serverServiceGroupBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"server_servicegroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// server_service_binding +// Binding object showing the service that can be bound to server. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/server_service_binding +func (s *BasicService) GetAllServerServiceBinding() ([]models.ServerServiceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, serverServiceBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + ServerServiceBinding []models.ServerServiceBinding `json:"server_service_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.ServerServiceBinding, nil +} + +func (s *BasicService) GetServerServiceBinding(name string) ([]models.ServerServiceBinding, error) { + reqURL := fmt.Sprintf("%s/%s", serverServiceBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + ServerServiceBinding []models.ServerServiceBinding `json:"server_service_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.ServerServiceBinding, nil +} + +// Struct lacks Count field, leaving for later +func (s *BasicService) CountServerServiceBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, serverServiceBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"server_service_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// service +// Configuration for service resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/service +func (s *BasicService) AddService(resource models.Service) error { + payload := map[string]interface{}{ + "service": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, serviceURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) DeleteService(name string) error { + reqURL := fmt.Sprintf("%s/%s", serviceURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) UpdateService(resource models.Service) error { + payload := map[string]interface{}{ + "service": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, serviceURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) UnsetService(resource models.Service) error { + payload := map[string]interface{}{ + "service": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, serviceURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) EnableService(resource models.Service) error { + payload := map[string]interface{}{ + "service": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, serviceURL+"?action=enable", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) DisableService(resource models.Service) error { + payload := map[string]interface{}{ + "service": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, serviceURL+"?action=disable", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) GetAllService() ([]models.Service, error) { + req, err := s.client.NewRequest(http.MethodGet, serviceURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Services []models.Service `json:"service"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Services, nil +} + +func (s *BasicService) GetService(name string) (*models.Service, error) { + reqURL := fmt.Sprintf("%s/%s", serviceURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Services []models.Service `json:"service"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Services) == 0 { + return nil, fmt.Errorf("service not found") + } + + return &result.Services[0], nil +} + +func (s *BasicService) CountService() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, serviceURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Services []struct { + Count float64 `json:"__count"` + } `json:"service"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Services) > 0 { + return result.Services[0].Count, nil + } + + return 0, nil +} + +func (s *BasicService) RenameService(resource models.Service) error { + payload := map[string]interface{}{ + "service": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, serviceURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// servicegroup +// Configuration for service group resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/servicegroup +func (s *BasicService) AddServiceGroup(resource models.ServiceGroup) error { + payload := map[string]any{"servicegroup": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, serviceGroupURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) DeleteServiceGroup(servicegroupname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", serviceGroupURL, servicegroupname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) UpdateServiceGroup(resource models.ServiceGroup) error { + payload := map[string]any{"servicegroup": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, serviceGroupURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) UnsetServiceGroup(resource models.ServiceGroup) error { + payload := map[string]any{"servicegroup": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", serviceGroupURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) EnableServiceGroup(resource models.ServiceGroup) error { + payload := map[string]any{"servicegroup": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=enable", serviceGroupURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) DisableServiceGroup(resource models.ServiceGroup) error { + payload := map[string]any{"servicegroup": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=disable", serviceGroupURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) GetAllServiceGroup() ([]models.ServiceGroup, error) { + req, err := s.client.NewRequest(http.MethodGet, serviceGroupURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + ServiceGroup []models.ServiceGroup `json:"servicegroup"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.ServiceGroup, nil +} + +func (s *BasicService) GetServiceGroup(servicegroupname string) (models.ServiceGroup, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", serviceGroupURL, servicegroupname), nil) + if err != nil { + return models.ServiceGroup{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.ServiceGroup{}, err + } + + var result struct { + ServiceGroup []models.ServiceGroup `json:"servicegroup"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.ServiceGroup{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.ServiceGroup) == 0 { + return models.ServiceGroup{}, fmt.Errorf("servicegroup %s not found", servicegroupname) + } + + return result.ServiceGroup[0], nil +} + +func (s *BasicService) CountServiceGroup() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", serviceGroupURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + ServiceGroup []models.ServiceGroup `json:"servicegroup"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.ServiceGroup) > 0 { + return int(result.ServiceGroup[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +func (s *BasicService) RenameServiceGroup(resource models.ServiceGroup) error { + payload := map[string]any{"servicegroup": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=rename", serviceGroupURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// servicegroupbindings +// Configuration for servicegroupbind resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/servicegroupbindings +func (s *BasicService) GetAllServiceGroupBindings() ([]models.ServiceGroupBindings, error) { + req, err := s.client.NewRequest(http.MethodGet, serviceGroupBindingsURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + ServiceGroupBindings []models.ServiceGroupBindings `json:"servicegroupbindings"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.ServiceGroupBindings, nil +} + +func (s *BasicService) GetServiceGroupBindings(servicegroupname string) (models.ServiceGroupBindings, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", serviceGroupBindingsURL, servicegroupname), nil) + if err != nil { + return models.ServiceGroupBindings{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.ServiceGroupBindings{}, err + } + + var result struct { + ServiceGroupBindings []models.ServiceGroupBindings `json:"servicegroupbindings"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.ServiceGroupBindings{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.ServiceGroupBindings) == 0 { + return models.ServiceGroupBindings{}, fmt.Errorf("servicegroupbindings %s not found", servicegroupname) + } + + return result.ServiceGroupBindings[0], nil +} + +// Struct lacks Count field, leaving for later +func (s *BasicService) CountServiceGroupBindings() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, serviceGroupBindingsURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"servicegroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// servicegroup_binding +// Binding object which returns the resources bound to servicegroup. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/servicegroup_binding +func (s *BasicService) GetAllServiceGroupBinding() ([]models.ServiceGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, serviceGroupBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + ServiceGroupBinding []models.ServiceGroupBinding `json:"servicegroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.ServiceGroupBinding, nil +} + +func (s *BasicService) GetServiceGroupBinding(serviceGroupName string) ([]models.ServiceGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", serviceGroupBindingURL, serviceGroupName), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + ServiceGroupBinding []models.ServiceGroupBinding `json:"servicegroup_binding"` + } + + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.ServiceGroupBinding, nil +} + +// servicegroup_lbmonitor_binding +// Binding object showing the lbmonitor that can be bound to servicegroup. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/servicegroup_lbmonitor_binding +func (s *BasicService) AddServiceGroupLBMonitorBinding(resource models.ServiceGroupLBMonitorBinding) error { + payload := map[string]any{"servicegroup_lbmonitor_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, serviceGroupLBMonitorBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) DeleteServiceGroupLBMonitorBinding(servicegroupname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", serviceGroupLBMonitorBindingURL, servicegroupname, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) GetAllServiceGroupLBMonitorBinding() ([]models.ServiceGroupLBMonitorBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, serviceGroupLBMonitorBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + ServiceGroupLBMonitorBinding []models.ServiceGroupLBMonitorBinding `json:"servicegroup_lbmonitor_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.ServiceGroupLBMonitorBinding, nil +} + +func (s *BasicService) GetServiceGroupLBMonitorBinding(servicegroupname string) ([]models.ServiceGroupLBMonitorBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", serviceGroupLBMonitorBindingURL, servicegroupname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + ServiceGroupLBMonitorBinding []models.ServiceGroupLBMonitorBinding `json:"servicegroup_lbmonitor_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.ServiceGroupLBMonitorBinding, nil +} + +// Struct lacks Count field, leaving for later +func (s *BasicService) CountServiceGroupLBMonitorBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, serviceGroupLBMonitorBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"servicegroup_lbmonitor_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// servicegroup_servicegroupentitymonbindings_binding +// Binding object showing the servicegroupentitymonbindings that can be bound to servicegroup. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/servicegroup_servicegroupentitymonbindings_binding +func (s *BasicService) GetAllServiceGroupServiceGroupEntityMonBindingsBinding() ([]models.ServiceGroupServiceGroupEntityMonBindingsBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, serviceGroupServiceGroupEntityMonBindingsBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + ServiceGroupServiceGroupEntityMonBindingsBinding []models.ServiceGroupServiceGroupEntityMonBindingsBinding `json:"servicegroup_servicegroupentitymonbindings_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.ServiceGroupServiceGroupEntityMonBindingsBinding, nil +} + +func (s *BasicService) GetServiceGroupServiceGroupEntityMonBindingsBinding(servicegroupname string) ([]models.ServiceGroupServiceGroupEntityMonBindingsBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", serviceGroupServiceGroupEntityMonBindingsBindingURL, servicegroupname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + ServiceGroupServiceGroupEntityMonBindingsBinding []models.ServiceGroupServiceGroupEntityMonBindingsBinding `json:"servicegroup_servicegroupentitymonbindings_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.ServiceGroupServiceGroupEntityMonBindingsBinding, nil +} + +// Struct lacks Count field, leaving for later +func (s *BasicService) CountServiceGroupServiceGroupEntityMonBindingsBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, serviceGroupServiceGroupEntityMonBindingsBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"servicegroup_servicegroupentitymonbindings_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// servicegroup_servicegroupmemberlist_binding +// Binding object showing the servicegroupmemberlist that can be bound to servicegroup. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/servicegroup_servicegroupmemberlist_binding +func (s *BasicService) AddServiceGroupServiceGroupMemberListBinding(resource models.ServiceGroupServiceGroupMemberListBinding) error { + payload := map[string]any{"servicegroup_servicegroupmemberlist_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, serviceGroupServiceGroupMemberListBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) DeleteServiceGroupServiceGroupMemberListBinding(servicegroupname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", serviceGroupServiceGroupMemberListBindingURL, servicegroupname, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// servicegroup_servicegroupmember_binding +// Binding object showing the servicegroupmember that can be bound to servicegroup. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/servicegroup_servicegroupmember_binding +func (s *BasicService) AddServiceGroupServiceGroupMemberBinding(resource models.ServiceGroupServiceGroupMemberBinding) error { + payload := map[string]any{"servicegroup_servicegroupmember_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, serviceGroupServiceGroupMemberBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) DeleteServiceGroupServiceGroupMemberBinding(servicegroupname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", serviceGroupServiceGroupMemberBindingURL, servicegroupname, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) GetAllServiceGroupServiceGroupMemberBinding() ([]models.ServiceGroupServiceGroupMemberBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, serviceGroupServiceGroupMemberBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + ServiceGroupServiceGroupMemberBinding []models.ServiceGroupServiceGroupMemberBinding `json:"servicegroup_servicegroupmember_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.ServiceGroupServiceGroupMemberBinding, nil +} + +func (s *BasicService) GetServiceGroupServiceGroupMemberBinding(servicegroupname string) ([]models.ServiceGroupServiceGroupMemberBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", serviceGroupServiceGroupMemberBindingURL, servicegroupname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + ServiceGroupServiceGroupMemberBinding []models.ServiceGroupServiceGroupMemberBinding `json:"servicegroup_servicegroupmember_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.ServiceGroupServiceGroupMemberBinding, nil +} + +// Struct lacks Count field, leaving for later +func (s *BasicService) CountServiceGroupServiceGroupMemberBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, serviceGroupServiceGroupMemberBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"servicegroup_servicegroupmember_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// service_binding +// Binding object which returns the resources bound to service. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/service_binding +func (s *BasicService) GetAllServiceBinding() ([]models.ServiceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, serviceBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + ServiceBinding []models.ServiceBinding `json:"service_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.ServiceBinding, nil +} + +func (s *BasicService) GetServiceBinding(name string) (models.ServiceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", serviceBindingURL, name), nil) + if err != nil { + return models.ServiceBinding{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.ServiceBinding{}, err + } + + var result struct { + ServiceBinding []models.ServiceBinding `json:"service_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.ServiceBinding{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.ServiceBinding) == 0 { + return models.ServiceBinding{}, fmt.Errorf("service_binding %s not found", name) + } + + return result.ServiceBinding[0], nil +} + +// service_lbmonitor_binding +// Binding object showing the lbmonitor that can be bound to service. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/service_lbmonitor_binding +func (s *BasicService) AddServiceLBMonitorBinding(resource models.ServiceLBMonitorBinding) error { + payload := map[string]any{"service_lbmonitor_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, serviceLBMonitorBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) DeleteServiceLBMonitorBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", serviceLBMonitorBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) GetAllServiceLBMonitorBinding() ([]models.ServiceLBMonitorBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, serviceLBMonitorBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + ServiceLBMonitorBinding []models.ServiceLBMonitorBinding `json:"service_lbmonitor_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.ServiceLBMonitorBinding, nil +} + +func (s *BasicService) GetServiceLBMonitorBinding(name string) ([]models.ServiceLBMonitorBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", serviceLBMonitorBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + ServiceLBMonitorBinding []models.ServiceLBMonitorBinding `json:"service_lbmonitor_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.ServiceLBMonitorBinding, nil +} + +// Struct lacks Count field, leaving for later +func (s *BasicService) CountServiceLBMonitorBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, serviceLBMonitorBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"service_lbmonitor_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// svcbindings +// Configuration for service bindings resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/svcbindings +func (s *BasicService) GetAllSVCBindings() ([]models.SVCBindings, error) { + req, err := s.client.NewRequest(http.MethodGet, svcBindingsURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SVCBindings []models.SVCBindings `json:"svcbindings"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SVCBindings, nil +} + +func (s *BasicService) GetSVCBindings(name string) ([]models.SVCBindings, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", svcBindingsURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SVCBindings []models.SVCBindings `json:"svcbindings"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SVCBindings, nil +} + +// Struct lacks Count field, leaving for later +func (s *BasicService) CountSVCBindings() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, svcBindingsURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"svcbindings"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// vserver +// Configuration for virtual server resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/basic/vserver +func (s *BasicService) DeleteVServer(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vServerURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) UpdateVServer(resource models.VServer) error { + payload := map[string]any{"vserver": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, vServerURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) EnableVServer(resource models.VServer) error { + payload := map[string]any{"vserver": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=enable", vServerURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *BasicService) DisableVServer(resource models.VServer) error { + payload := map[string]any{"vserver": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=disable", vServerURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} diff --git a/nitrogo/bfd.go b/nitrogo/bfd.go index 991a626..77bff85 100644 --- a/nitrogo/bfd.go +++ b/nitrogo/bfd.go @@ -1,5 +1,17 @@ package nitrogo +import ( + "encoding/json" + "fmt" + "net/http" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + bfdSessionURL = "/nitro/v1/config/bfdsession" +) + // Bidirectional Forwarding Detection // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/bfd/bfd type BFDService struct { @@ -9,5 +21,55 @@ type BFDService struct { // bfdsession // Configuration for BFD configuration resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/bfd/bfdsession -func (s *BFDService) GetAllBFDSession() {} -func (s *BFDService) CountBFDSession() {} + +func (s *BFDService) GetAllBFDSession() ([]models.BFDSession, error) { + req, err := s.client.NewRequest(http.MethodGet, bfdSessionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + BFDSessions []models.BFDSession `json:"bfdsession"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.BFDSessions, nil +} + +func (s *BFDService) CountBFDSession() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, bfdSessionURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + BFDSessions []struct { + Count float64 `json:"__count"` + } `json:"bfdsession"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.BFDSessions) > 0 { + return result.BFDSessions[0].Count, nil + } + + return 0, nil +} diff --git a/nitrogo/bot.go b/nitrogo/bot.go index 9fe21d5..29eabba 100644 --- a/nitrogo/bot.go +++ b/nitrogo/bot.go @@ -1,5 +1,40 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + botGlobalBindingURL = "/nitro/v1/config/botglobal_binding" + botGlobalBotPolicyBindingURL = "/nitro/v1/config/botglobal_botpolicy_binding" + botPolicyURL = "/nitro/v1/config/botpolicy" + botPolicyBindingURL = "/nitro/v1/config/botpolicy_binding" + botPolicyBotGlobalBindingURL = "/nitro/v1/config/botpolicy_botglobal_binding" + botPolicyBotPolicyLabelBindingURL = "/nitro/v1/config/botpolicy_botpolicylabel_binding" + botPolicyCSVServerBindingURL = "/nitro/v1/config/botpolicy_csvserver_binding" + botPolicyLBVServerBindingURL = "/nitro/v1/config/botpolicy_lbvserver_binding" + botPolicyLabelURL = "/nitro/v1/config/botpolicylabel" + botPolicyLabelBindingURL = "/nitro/v1/config/botpolicylabel_binding" + botPolicyLabelBotPolicyBindingURL = "/nitro/v1/config/botpolicylabel_botpolicy_binding" + botPolicyLabelPolicyBindingBindingURL = "/nitro/v1/config/botpolicylabel_policybinding_binding" + botProfileURL = "/nitro/v1/config/botprofile" + botProfileBindingURL = "/nitro/v1/config/botprofile_binding" + botProfileBlacklistBindingURL = "/nitro/v1/config/botprofile_blacklist_binding" + botProfileCaptchaBindingURL = "/nitro/v1/config/botprofile_captcha_binding" + botProfileIPReputationBindingURL = "/nitro/v1/config/botprofile_ipreputation_binding" + botProfileRatelimitBindingURL = "/nitro/v1/config/botprofile_ratelimit_binding" + botProfileTPSBindingURL = "/nitro/v1/config/botprofile_tps_binding" + botProfileWhitelistBindingURL = "/nitro/v1/config/botprofile_whitelist_binding" + botSettingsURL = "/nitro/v1/config/botsettings" + botSignatureURL = "/nitro/v1/config/botsignature" +) + // Bot Management. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/bot/bot type BotService struct { @@ -7,135 +42,1716 @@ type BotService struct { } // botglobal_binding -func (s *BotService) GetBotGlobalBinding() {} + +func (s *BotService) GetBotGlobalBinding() ([]models.BotGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, botGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotGlobalBinding `json:"botglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // botglobal_botpolicy_binding -func (s *BotService) AddBotGlobalBotPolicyBinding() {} -func (s *BotService) DeleteBotGlobalBotPolicyBinding() {} -func (s *BotService) GetBotGlobalBotPolicyBinding() {} -func (s *BotService) CountBotGlobalBotPolicyBinding() {} + +func (s *BotService) AddBotGlobalBotPolicyBinding(binding models.BotGlobalBotPolicyBinding) error { + payload := map[string]any{ + "botglobal_botpolicy_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, botGlobalBotPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) DeleteBotGlobalBotPolicyBinding(policyname, typeField string, priority int) error { + reqURL := fmt.Sprintf("%s?args=policyname:%s,type:%s,priority:%d", botGlobalBotPolicyBindingURL, url.QueryEscape(policyname), url.QueryEscape(typeField), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) GetBotGlobalBotPolicyBinding() ([]models.BotGlobalBotPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, botGlobalBotPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotGlobalBotPolicyBinding `json:"botglobal_botpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) CountBotGlobalBotPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, botGlobalBotPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"botglobal_botpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // botpolicy -func (s *BotService) AddBotPolicy() {} -func (s *BotService) DeleteBotPolicy() {} -func (s *BotService) UpdateBotPolicy() {} -func (s *BotService) UnsetBotPolicy() {} -func (s *BotService) GetAllBotPolicy() {} -func (s *BotService) GetBotPolicy() {} -func (s *BotService) CountBotPolicy() {} -func (s *BotService) RenameBotPolicy() {} + +func (s *BotService) AddBotPolicy(policy models.BotPolicy) error { + payload := map[string]any{ + "botpolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, botPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) DeleteBotPolicy(name string) error { + reqURL := fmt.Sprintf("%s/%s", botPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) UpdateBotPolicy(policy models.BotPolicy) error { + payload := map[string]any{ + "botpolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, botPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) UnsetBotPolicy(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{ + "botpolicy": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, botPolicyURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) RenameBotPolicy(name, newname string) error { + payload := map[string]any{ + "botpolicy": map[string]string{ + "name": name, + "newname": newname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, botPolicyURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) GetAllBotPolicy() ([]models.BotPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, botPolicyURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Policies []models.BotPolicy `json:"botpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Policies, nil +} + +func (s *BotService) GetBotPolicy(name string) ([]models.BotPolicy, error) { + reqURL := fmt.Sprintf("%s/%s", botPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Policies []models.BotPolicy `json:"botpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Policies, nil +} + +func (s *BotService) CountBotPolicy() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, botPolicyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Policies []struct { + Count float64 `json:"__count"` + } `json:"botpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Policies) > 0 { + return result.Policies[0].Count, nil + } + return 0, nil +} // botpolicylabel -func (s *BotService) AddBotPolicyLabel() {} -func (s *BotService) DeleteBotPolicyLabel() {} -func (s *BotService) GetAllBotPolicyLabel() {} -func (s *BotService) GetBotPolicyLabel() {} -func (s *BotService) CountBotPolicyLabel() {} -func (s *BotService) RenameBotPolicyLabel() {} + +func (s *BotService) AddBotPolicyLabel(label models.BotPolicyLabel) error { + payload := map[string]any{ + "botpolicylabel": label, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, botPolicyLabelURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) DeleteBotPolicyLabel(labelname string) error { + reqURL := fmt.Sprintf("%s/%s", botPolicyLabelURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) RenameBotPolicyLabel(labelname, newname string) error { + payload := map[string]any{ + "botpolicylabel": map[string]string{ + "labelname": labelname, + "newname": newname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, botPolicyLabelURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) GetAllBotPolicyLabel() ([]models.BotPolicyLabel, error) { + req, err := s.client.NewRequest(http.MethodGet, botPolicyLabelURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Labels []models.BotPolicyLabel `json:"botpolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Labels, nil +} + +func (s *BotService) GetBotPolicyLabel(labelname string) ([]models.BotPolicyLabel, error) { + reqURL := fmt.Sprintf("%s/%s", botPolicyLabelURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Labels []models.BotPolicyLabel `json:"botpolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Labels, nil +} + +func (s *BotService) CountBotPolicyLabel() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, botPolicyLabelURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Labels []struct { + Count float64 `json:"__count"` + } `json:"botpolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Labels) > 0 { + return result.Labels[0].Count, nil + } + return 0, nil +} // botpolicylabel_binding -func (s *BotService) GetAllBotPolicyLabelBinding() {} -func (s *BotService) GetBotPolicyLabelBinding() {} + +func (s *BotService) GetAllBotPolicyLabelBinding() ([]models.BotPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, botPolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotPolicyLabelBinding `json:"botpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) GetBotPolicyLabelBinding(labelname string) ([]models.BotPolicyLabelBinding, error) { + reqURL := fmt.Sprintf("%s/%s", botPolicyLabelBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotPolicyLabelBinding `json:"botpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // botpolicylabel_botpolicy_binding -func (s *BotService) AddBotPolicyLabelBotPolicyBinding() {} -func (s *BotService) DeleteBotPolicyLabelBotPolicyBinding() {} -func (s *BotService) GetAllBotPolicyLabelBotPolicyBinding() {} -func (s *BotService) GetBotPolicyLabelBotPolicyBinding() {} -func (s *BotService) CountBotPolicyLabelBotPolicyBinding() {} + +func (s *BotService) AddBotPolicyLabelBotPolicyBinding(binding models.BotPolicyLabelBotPolicyBinding) error { + payload := map[string]any{ + "botpolicylabel_botpolicy_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, botPolicyLabelBotPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) DeleteBotPolicyLabelBotPolicyBinding(labelname, policyname string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,priority:%d", botPolicyLabelBotPolicyBindingURL, url.QueryEscape(labelname), url.QueryEscape(policyname), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) GetAllBotPolicyLabelBotPolicyBinding() ([]models.BotPolicyLabelBotPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, botPolicyLabelBotPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotPolicyLabelBotPolicyBinding `json:"botpolicylabel_botpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) GetBotPolicyLabelBotPolicyBinding(labelname string) ([]models.BotPolicyLabelBotPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", botPolicyLabelBotPolicyBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotPolicyLabelBotPolicyBinding `json:"botpolicylabel_botpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) CountBotPolicyLabelBotPolicyBinding(labelname string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", botPolicyLabelBotPolicyBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"botpolicylabel_botpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // botpolicylabel_policybinding_binding -func (s *BotService) GetAllBotPolicyLabelPolicyBindingBinding() {} -func (s *BotService) GetBotPolicyLabelPolicyBindingBinding() {} -func (s *BotService) CountBotPolicyLabelPolicyBindingBinding() {} -// botpolcy_binding -func (s *BotService) GetAllBotPolicyBinding() {} -func (s *BotService) GetBotPolicyBinding() {} +func (s *BotService) GetAllBotPolicyLabelPolicyBindingBinding() ([]models.BotPolicyLabelPolicyBindingBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, botPolicyLabelPolicyBindingBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotPolicyLabelPolicyBindingBinding `json:"botpolicylabel_policybinding_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) GetBotPolicyLabelPolicyBindingBinding(labelname string) ([]models.BotPolicyLabelPolicyBindingBinding, error) { + reqURL := fmt.Sprintf("%s/%s", botPolicyLabelPolicyBindingBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotPolicyLabelPolicyBindingBinding `json:"botpolicylabel_policybinding_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) CountBotPolicyLabelPolicyBindingBinding(labelname string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", botPolicyLabelPolicyBindingBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"botpolicylabel_policybinding_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} + +// botpolicy_binding + +func (s *BotService) GetAllBotPolicyBinding() ([]models.BotPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, botPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotPolicyBinding `json:"botpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) GetBotPolicyBinding(name string) ([]models.BotPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", botPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotPolicyBinding `json:"botpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // botpolicy_botglobal_binding -func (s *BotService) GetAllBotPolicyBotGlobalBinding() {} -func (s *BotService) GetBotPolicyBotGlobalBinding() {} -func (s *BotService) CountBotPolicyBotGlobalBinding() {} -// gotpolicy_botpolicylabel_binding -func (s *BotService) GetAllBotPolicyBotPolicyLabelBinding() {} -func (s *BotService) GetBotPolicyBotPolicyLabelBinding() {} -func (s *BotService) CountBotPolicyBotPolicyLabelBinding() {} +func (s *BotService) GetAllBotPolicyBotGlobalBinding() ([]models.BotPolicyBotGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, botPolicyBotGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotPolicyBotGlobalBinding `json:"botpolicy_botglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) GetBotPolicyBotGlobalBinding(name string) ([]models.BotPolicyBotGlobalBinding, error) { + reqURL := fmt.Sprintf("%s/%s", botPolicyBotGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotPolicyBotGlobalBinding `json:"botpolicy_botglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) CountBotPolicyBotGlobalBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", botPolicyBotGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"botpolicy_botglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} + +// botpolicy_botpolicylabel_binding + +func (s *BotService) GetAllBotPolicyBotPolicyLabelBinding() ([]models.BotPolicyBotPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, botPolicyBotPolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotPolicyBotPolicyLabelBinding `json:"botpolicy_botpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) GetBotPolicyBotPolicyLabelBinding(name string) ([]models.BotPolicyBotPolicyLabelBinding, error) { + reqURL := fmt.Sprintf("%s/%s", botPolicyBotPolicyLabelBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotPolicyBotPolicyLabelBinding `json:"botpolicy_botpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) CountBotPolicyBotPolicyLabelBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", botPolicyBotPolicyLabelBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"botpolicy_botpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // botpolicy_csvserver_binding -func (s *BotService) GetAllBotPolicyCSVServerBinding() {} -func (s *BotService) GetBotPolicyCSVServerBinding() {} -func (s *BotService) CountBotPolicyCSVServerBinding() {} + +func (s *BotService) GetAllBotPolicyCSVServerBinding() ([]models.BotPolicyCSVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, botPolicyCSVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotPolicyCSVServerBinding `json:"botpolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) GetBotPolicyCSVServerBinding(name string) ([]models.BotPolicyCSVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", botPolicyCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotPolicyCSVServerBinding `json:"botpolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) CountBotPolicyCSVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", botPolicyCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"botpolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // botpolicy_lbvserver_binding -func (s *BotService) GetAllBotPolicyLBVServerBinding() {} -func (s *BotService) GetBotPolicyLBVServerBinding() {} -func (s *BotService) CountBotPolicyLBVServerBinding() {} + +func (s *BotService) GetAllBotPolicyLBVServerBinding() ([]models.BotPolicyLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, botPolicyLBVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotPolicyLBVServerBinding `json:"botpolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) GetBotPolicyLBVServerBinding(name string) ([]models.BotPolicyLBVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", botPolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotPolicyLBVServerBinding `json:"botpolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) CountBotPolicyLBVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", botPolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"botpolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // botprofile -func (s *BotService) AddBotProfile() {} -func (s *BotService) DeleteBotProfile() {} -func (s *BotService) UpdateBotProfile() {} -func (s *BotService) UnsetBotProfile() {} -func (s *BotService) GetAllBotProfile() {} -func (s *BotService) GetBotProfile() {} -func (s *BotService) CountBotProfile() {} + +func (s *BotService) AddBotProfile(profile models.BotProfile) error { + payload := map[string]any{ + "botprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, botProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) DeleteBotProfile(name string) error { + reqURL := fmt.Sprintf("%s/%s", botProfileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) UpdateBotProfile(profile models.BotProfile) error { + payload := map[string]any{ + "botprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, botProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) UnsetBotProfile(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{ + "botprofile": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, botProfileURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) GetAllBotProfile() ([]models.BotProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, botProfileURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Profiles []models.BotProfile `json:"botprofile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Profiles, nil +} + +func (s *BotService) GetBotProfile(name string) ([]models.BotProfile, error) { + reqURL := fmt.Sprintf("%s/%s", botProfileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Profiles []models.BotProfile `json:"botprofile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Profiles, nil +} + +func (s *BotService) CountBotProfile() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, botProfileURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Profiles []struct { + Count float64 `json:"__count"` + } `json:"botprofile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Profiles) > 0 { + return result.Profiles[0].Count, nil + } + return 0, nil +} // botprofile_binding -func (s *BotService) GetAllBotProfileBinding() {} -func (s *BotService) GetBotProfileBinding() {} + +func (s *BotService) GetAllBotProfileBinding() ([]models.BotProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, botProfileBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotProfileBinding `json:"botprofile_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) GetBotProfileBinding(name string) ([]models.BotProfileBinding, error) { + reqURL := fmt.Sprintf("%s/%s", botProfileBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotProfileBinding `json:"botprofile_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // botprofile_blacklist_binding -func (s *BotService) AddBotProfileBlacklistBinding() {} -func (s *BotService) DeleteBotProfileBlacklistBinding() {} -func (s *BotService) GetAllBotProfileBlacklistBinding() {} -func (s *BotService) GetBotProfileBlacklistBinding() {} -func (s *BotService) CountBotProfileBlacklistBinding() {} + +func (s *BotService) AddBotProfileBlacklistBinding(binding models.BotProfileBlacklistBinding) error { + payload := map[string]any{ + "botprofile_blacklist_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, botProfileBlacklistBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) DeleteBotProfileBlacklistBinding(name, blacklistType, blacklistValue string) error { + reqURL := fmt.Sprintf("%s/%s?args=bot_blacklist_type:%s,bot_blacklist_value:%s", botProfileBlacklistBindingURL, url.QueryEscape(name), url.QueryEscape(blacklistType), url.QueryEscape(blacklistValue)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) GetAllBotProfileBlacklistBinding() ([]models.BotProfileBlacklistBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, botProfileBlacklistBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotProfileBlacklistBinding `json:"botprofile_blacklist_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) GetBotProfileBlacklistBinding(name string) ([]models.BotProfileBlacklistBinding, error) { + reqURL := fmt.Sprintf("%s/%s", botProfileBlacklistBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotProfileBlacklistBinding `json:"botprofile_blacklist_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) CountBotProfileBlacklistBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", botProfileBlacklistBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"botprofile_blacklist_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // botprofile_captcha_binding -func (s *BotService) AddBotProfileCaptchaBinding() {} -func (s *BotService) DeleteBotProfileCaptchaBinding() {} -func (s *BotService) GetAllBotProfileCaptchaBinding() {} -func (s *BotService) GetBotProfileCaptchaBinding() {} -func (s *BotService) CountBotProfileCaptchaBinding() {} + +func (s *BotService) AddBotProfileCaptchaBinding(binding models.BotProfileCaptchaBinding) error { + payload := map[string]any{ + "botprofile_captcha_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, botProfileCaptchaBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) DeleteBotProfileCaptchaBinding(name, captchaURL string) error { + reqURL := fmt.Sprintf("%s/%s?args=bot_captcha_url:%s", botProfileCaptchaBindingURL, url.QueryEscape(name), url.QueryEscape(captchaURL)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) GetAllBotProfileCaptchaBinding() ([]models.BotProfileCaptchaBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, botProfileCaptchaBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotProfileCaptchaBinding `json:"botprofile_captcha_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) GetBotProfileCaptchaBinding(name string) ([]models.BotProfileCaptchaBinding, error) { + reqURL := fmt.Sprintf("%s/%s", botProfileCaptchaBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotProfileCaptchaBinding `json:"botprofile_captcha_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) CountBotProfileCaptchaBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", botProfileCaptchaBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"botprofile_captcha_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // botprofile_ipreputation_binding -func (s *BotService) AddBotProfileIPReputationBinding() {} -func (s *BotService) DeleteBotProfileIPReputationBinding() {} -func (s *BotService) GetAllBotProfileIPReputationBinding() {} -func (s *BotService) GetBotProfileIPReputationBinding() {} -func (s *BotService) CountBotProfileIPReputationBinding() {} + +func (s *BotService) AddBotProfileIPReputationBinding(binding models.BotProfileIPReputationBinding) error { + payload := map[string]any{ + "botprofile_ipreputation_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, botProfileIPReputationBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) DeleteBotProfileIPReputationBinding(name, category string) error { + reqURL := fmt.Sprintf("%s/%s?args=category:%s", botProfileIPReputationBindingURL, url.QueryEscape(name), url.QueryEscape(category)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) GetAllBotProfileIPReputationBinding() ([]models.BotProfileIPReputationBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, botProfileIPReputationBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotProfileIPReputationBinding `json:"botprofile_ipreputation_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) GetBotProfileIPReputationBinding(name string) ([]models.BotProfileIPReputationBinding, error) { + reqURL := fmt.Sprintf("%s/%s", botProfileIPReputationBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotProfileIPReputationBinding `json:"botprofile_ipreputation_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) CountBotProfileIPReputationBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", botProfileIPReputationBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"botprofile_ipreputation_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // botprofile_ratelimit_binding -func (s *BotService) AddBotProfileRatelimitBinding() {} -func (s *BotService) DeleteBotProfileRatelimitBinding() {} -func (s *BotService) GetAllBotProfileRatelimitBinding() {} -func (s *BotService) GetBotProfileRatelimitBinding() {} -func (s *BotService) CountBotProfileRatelimitBinding() {} + +func (s *BotService) AddBotProfileRatelimitBinding(binding models.BotProfileRateLimitBinding) error { + payload := map[string]any{ + "botprofile_ratelimit_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, botProfileRatelimitBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) DeleteBotProfileRatelimitBinding(name, limitType, botRateLimitURL string) error { + reqURL := fmt.Sprintf("%s/%s?args=bot_rate_limit_type:%s,bot_rate_limit_url:%s", botProfileRatelimitBindingURL, url.QueryEscape(name), url.QueryEscape(limitType), url.QueryEscape(botRateLimitURL)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) GetAllBotProfileRatelimitBinding() ([]models.BotProfileRateLimitBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, botProfileRatelimitBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotProfileRateLimitBinding `json:"botprofile_ratelimit_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) GetBotProfileRatelimitBinding(name string) ([]models.BotProfileRateLimitBinding, error) { + reqURL := fmt.Sprintf("%s/%s", botProfileRatelimitBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotProfileRateLimitBinding `json:"botprofile_ratelimit_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) CountBotProfileRatelimitBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", botProfileRatelimitBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"botprofile_ratelimit_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // botprofile_tps_binding -func (s *BotService) AddBotProfileTPSBinding() {} -func (s *BotService) DeleteBotProfileTPSBinding() {} -func (s *BotService) GetAllBotProfileTPSBinding() {} -func (s *BotService) GetBotProfileTPSBinding() {} -func (s *BotService) CountBotProfileTPSBinding() {} + +func (s *BotService) AddBotProfileTPSBinding(binding models.BotProfileTPSBinding) error { + payload := map[string]any{ + "botprofile_tps_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, botProfileTPSBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) DeleteBotProfileTPSBinding(name, tpsType string) error { + reqURL := fmt.Sprintf("%s/%s?args=bot_tps_type:%s", botProfileTPSBindingURL, url.QueryEscape(name), url.QueryEscape(tpsType)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) GetAllBotProfileTPSBinding() ([]models.BotProfileTPSBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, botProfileTPSBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotProfileTPSBinding `json:"botprofile_tps_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) GetBotProfileTPSBinding(name string) ([]models.BotProfileTPSBinding, error) { + reqURL := fmt.Sprintf("%s/%s", botProfileTPSBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotProfileTPSBinding `json:"botprofile_tps_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) CountBotProfileTPSBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", botProfileTPSBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"botprofile_tps_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // botprofile_whitelist_binding -func (s *BotService) AddBotProfileWhitelistBinding() {} -func (s *BotService) DeleteBotProfileWhitelistBinding() {} -func (s *BotService) GetAllBotProfileWhitelistBinding() {} -func (s *BotService) GetBotProfileWhitelistBinding() {} -func (s *BotService) CountBotProfileWhitelistBinding() {} + +func (s *BotService) AddBotProfileWhitelistBinding(binding models.BotProfileWhitelistBinding) error { + payload := map[string]any{ + "botprofile_whitelist_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, botProfileWhitelistBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) DeleteBotProfileWhitelistBinding(name, whitelistType, whitelistValue string) error { + reqURL := fmt.Sprintf("%s/%s?args=bot_whitelist_type:%s,bot_whitelist_value:%s", botProfileWhitelistBindingURL, url.QueryEscape(name), url.QueryEscape(whitelistType), url.QueryEscape(whitelistValue)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) GetAllBotProfileWhitelistBinding() ([]models.BotProfileWhitelistBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, botProfileWhitelistBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotProfileWhitelistBinding `json:"botprofile_whitelist_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) GetBotProfileWhitelistBinding(name string) ([]models.BotProfileWhitelistBinding, error) { + reqURL := fmt.Sprintf("%s/%s", botProfileWhitelistBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.BotProfileWhitelistBinding `json:"botprofile_whitelist_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *BotService) CountBotProfileWhitelistBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", botProfileWhitelistBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"botprofile_whitelist_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // botsettings -func (s *BotService) UpdateBotSettings() {} -func (s *BotService) UnsetBotSettings() {} -func (s *BotService) GetAllBotSettings() {} + +func (s *BotService) UpdateBotSettings(settings models.BotSettings) error { + payload := map[string]any{ + "botsettings": settings, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, botSettingsURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) UnsetBotSettings(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{ + "botsettings": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, botSettingsURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) GetAllBotSettings() (models.BotSettings, error) { + req, err := s.client.NewRequest(http.MethodGet, botSettingsURL, nil) + if err != nil { + return models.BotSettings{}, err + } + resp, err := s.client.Do(req) + if err != nil { + return models.BotSettings{}, err + } + var result struct { + Settings []models.BotSettings `json:"botsettings"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return models.BotSettings{}, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Settings) > 0 { + return result.Settings[0], nil + } + return models.BotSettings{}, nil +} // botsignature -func (s *BotService) ImportBotSignature() {} -func (s *BotService) DeleteBotSignature() {} -func (s *BotService) ChangeBotSignature() {} -func (s *BotService) GetAllBotSignature() {} -func (s *BotService) GetBotSignature() {} + +func (s *BotService) ImportBotSignature(signature models.BotSignature) error { + payload := map[string]any{ + "botsignature": signature, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, botSignatureURL+"?action=Import", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) DeleteBotSignature(name string) error { + reqURL := fmt.Sprintf("%s/%s", botSignatureURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) ChangeBotSignature(signature models.BotSignature) error { + payload := map[string]any{ + "botsignature": signature, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, botSignatureURL+"?action=update", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *BotService) GetAllBotSignature() ([]models.BotSignature, error) { + req, err := s.client.NewRequest(http.MethodGet, botSignatureURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Signatures []models.BotSignature `json:"botsignature"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Signatures, nil +} + +func (s *BotService) GetBotSignature(name string) ([]models.BotSignature, error) { + reqURL := fmt.Sprintf("%s/%s", botSignatureURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Signatures []models.BotSignature `json:"botsignature"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Signatures, nil +} diff --git a/nitrogo/cache.go b/nitrogo/cache.go index a095184..1d4584c 100644 --- a/nitrogo/cache.go +++ b/nitrogo/cache.go @@ -1,5 +1,35 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + cacheContentGroupURL = "/nitro/v1/config/cachecontentgroup" + cacheForwardProxyURL = "/nitro/v1/config/cacheforwardproxy" + cacheGlobalBindingURL = "/nitro/v1/config/cacheglobal_binding" + cacheGlobalCachePolicyBindingURL = "/nitro/v1/config/cacheglobal_cachepolicy_binding" + cacheObjectURL = "/nitro/v1/config/cacheobject" + cacheParameterURL = "/nitro/v1/config/cacheparameter" + cachePolicyURL = "/nitro/v1/config/cachepolicy" + cachePolicyBindingURL = "/nitro/v1/config/cachepolicy_binding" + cachePolicyCacheGlobalBindingURL = "/nitro/v1/config/cachepolicy_cacheglobal_binding" + cachePolicyCachePolicyLabelBindingURL = "/nitro/v1/config/cachepolicy_cachepolicylabel_binding" + cachePolicyCSVServerBindingURL = "/nitro/v1/config/cachepolicy_csvserver_binding" + cachePolicyLBVServerBindingURL = "/nitro/v1/config/cachepolicy_lbvserver_binding" + cachePolicyLabelURL = "/nitro/v1/config/cachepolicylabel" + cachePolicyLabelBindingURL = "/nitro/v1/config/cachepolicylabel_binding" + cachePolicyLabelCachePolicyBindingURL = "/nitro/v1/config/cachepolicylabel_cachepolicy_binding" + cachePolicyLabelPolicyBindingBindingURL = "/nitro/v1/config/cachepolicylabel_policybinding_binding" + cacheSelectorURL = "/nitro/v1/config/cacheselector" +) + // Integrated Caching Configuration. The Integrated Caching feature is used to cache static and dynamic web application data. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/cache/cache type CacheService struct { @@ -7,106 +37,1359 @@ type CacheService struct { } // cachecontentgroup -func (s *CacheService) AddCacheContentGroup() {} -func (s *CacheService) DeleteCacheContentGroup() {} -func (s *CacheService) UpdateCacheContentGroup() {} -func (s *CacheService) UnsetCacheContentGroup() {} -func (s *CacheService) GetAllCacheContentGroup() {} -func (s *CacheService) GetCacheContentGroup() {} -func (s *CacheService) CountCacheContentGroup() {} -func (s *CacheService) ExpireCacheContentGroup() {} -func (s *CacheService) FlushCacheContentGroup() {} -func (s *CacheService) SaveCacheContentGroup() {} + +func (s *CacheService) AddCacheContentGroup(group models.CacheContentGroup) error { + payload := map[string]any{ + "cachecontentgroup": group, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, cacheContentGroupURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CacheService) DeleteCacheContentGroup(name string) error { + reqURL := fmt.Sprintf("%s/%s", cacheContentGroupURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CacheService) UpdateCacheContentGroup(group models.CacheContentGroup) error { + payload := map[string]any{ + "cachecontentgroup": group, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, cacheContentGroupURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CacheService) UnsetCacheContentGroup(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{ + "cachecontentgroup": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, cacheContentGroupURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CacheService) GetAllCacheContentGroup() ([]models.CacheContentGroup, error) { + req, err := s.client.NewRequest(http.MethodGet, cacheContentGroupURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Groups []models.CacheContentGroup `json:"cachecontentgroup"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Groups, nil +} + +func (s *CacheService) GetCacheContentGroup(name string) ([]models.CacheContentGroup, error) { + reqURL := fmt.Sprintf("%s/%s", cacheContentGroupURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Groups []models.CacheContentGroup `json:"cachecontentgroup"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Groups, nil +} + +func (s *CacheService) CountCacheContentGroup() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, cacheContentGroupURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Groups []struct { + Count float64 `json:"__count"` + } `json:"cachecontentgroup"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Groups) > 0 { + return result.Groups[0].Count, nil + } + return 0, nil +} + +func (s *CacheService) ExpireCacheContentGroup(group models.CacheContentGroup) error { + payload := map[string]any{ + "cachecontentgroup": group, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, cacheContentGroupURL+"?action=expire", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CacheService) FlushCacheContentGroup(group models.CacheContentGroup) error { + payload := map[string]any{ + "cachecontentgroup": group, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, cacheContentGroupURL+"?action=flush", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CacheService) SaveCacheContentGroup(group models.CacheContentGroup) error { + payload := map[string]any{ + "cachecontentgroup": group, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, cacheContentGroupURL+"?action=save", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} // cacheforwardproxy -func (s *CacheService) AddCacheForwardProxy() {} -func (s *CacheService) DeleteCacheForwardProxy() {} -func (s *CacheService) GetAllCacheForwardProxy() {} -func (s *CacheService) CountCacheForwardProxy() {} + +func (s *CacheService) AddCacheForwardProxy(proxy models.CacheForwardProxy) error { + payload := map[string]any{ + "cacheforwardproxy": proxy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, cacheForwardProxyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CacheService) DeleteCacheForwardProxy(ipaddress string, port int) error { + reqURL := fmt.Sprintf("%s/%s?args=port:%d", cacheForwardProxyURL, url.QueryEscape(ipaddress), port) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CacheService) GetAllCacheForwardProxy() ([]models.CacheForwardProxy, error) { + req, err := s.client.NewRequest(http.MethodGet, cacheForwardProxyURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Proxies []models.CacheForwardProxy `json:"cacheforwardproxy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Proxies, nil +} + +func (s *CacheService) CountCacheForwardProxy() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, cacheForwardProxyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Proxies []struct { + Count float64 `json:"__count"` + } `json:"cacheforwardproxy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Proxies) > 0 { + return result.Proxies[0].Count, nil + } + return 0, nil +} // cacheglobal_binding -func (s *CacheService) GetCacheGlobalBinding() {} + +func (s *CacheService) GetCacheGlobalBinding() ([]models.CacheGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, cacheGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CacheGlobalBinding `json:"cacheglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // cacheglobal_cachepolicy_binding -func (s *CacheService) AddCacheGlobalCachePolicyBinding() {} -func (s *CacheService) DeleteCacheGlobalCachePolicyBinding() {} -func (s *CacheService) GetCacheGlobalCachePolicyBinding() {} -func (s *CacheService) CountCacheGlobalCachePolicyBinding() {} + +func (s *CacheService) AddCacheGlobalCachePolicyBinding(binding models.CacheGlobalCachePolicyBinding) error { + payload := map[string]any{ + "cacheglobal_cachepolicy_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, cacheGlobalCachePolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CacheService) DeleteCacheGlobalCachePolicyBinding(policyname string) error { + reqURL := fmt.Sprintf("%s?args=policy:%s", cacheGlobalCachePolicyBindingURL, url.QueryEscape(policyname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CacheService) GetCacheGlobalCachePolicyBinding() ([]models.CacheGlobalCachePolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, cacheGlobalCachePolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CacheGlobalCachePolicyBinding `json:"cacheglobal_cachepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CacheService) CountCacheGlobalCachePolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, cacheGlobalCachePolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"cacheglobal_cachepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // cacheobject -func (s *CacheService) GetAllCacheObject() {} -func (s *CacheService) CountCacheObject() {} -func (s *CacheService) FlushCacheObject() {} -func (s *CacheService) ExpireCacheObject() {} -func (s *CacheService) SaveCacheObject() {} + +func (s *CacheService) GetAllCacheObject() ([]models.CacheObject, error) { + req, err := s.client.NewRequest(http.MethodGet, cacheObjectURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Objects []models.CacheObject `json:"cacheobject"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Objects, nil +} + +func (s *CacheService) CountCacheObject() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, cacheObjectURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Objects []struct { + Count float64 `json:"__count"` + } `json:"cacheobject"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Objects) > 0 { + return result.Objects[0].Count, nil + } + return 0, nil +} + +func (s *CacheService) FlushCacheObject(object models.CacheObject) error { + payload := map[string]any{ + "cacheobject": object, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, cacheObjectURL+"?action=flush", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CacheService) ExpireCacheObject(object models.CacheObject) error { + payload := map[string]any{ + "cacheobject": object, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, cacheObjectURL+"?action=expire", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CacheService) SaveCacheObject(object models.CacheObject) error { + payload := map[string]any{ + "cacheobject": object, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, cacheObjectURL+"?action=save", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} // cacheparameter -func (s *CacheService) UpdateCacheParameter() {} -func (s *CacheService) UnsetCacheParameter() {} -func (s *CacheService) GetAllCacheParameter() {} + +func (s *CacheService) UpdateCacheParameter(param models.CacheParameter) error { + payload := map[string]any{ + "cacheparameter": param, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, cacheParameterURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CacheService) UnsetCacheParameter(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{ + "cacheparameter": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, cacheParameterURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CacheService) GetAllCacheParameter() (models.CacheParameter, error) { + req, err := s.client.NewRequest(http.MethodGet, cacheParameterURL, nil) + if err != nil { + return models.CacheParameter{}, err + } + resp, err := s.client.Do(req) + if err != nil { + return models.CacheParameter{}, err + } + var result struct { + Params []models.CacheParameter `json:"cacheparameter"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return models.CacheParameter{}, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Params) > 0 { + return result.Params[0], nil + } + return models.CacheParameter{}, nil +} // cachepolicy -func (s *CacheService) AddCachePolicy() {} -func (s *CacheService) DeleteCachePolicy() {} -func (s *CacheService) UpdateCachePolicy() {} -func (s *CacheService) UnsetCachePolicy() {} -func (s *CacheService) GetAllCachePolicy() {} -func (s *CacheService) GetCachePolicy() {} -func (s *CacheService) CountCachePolicy() {} -func (s *CacheService) RenameCachePolicy() {} + +func (s *CacheService) AddCachePolicy(policy models.CachePolicy) error { + payload := map[string]any{ + "cachepolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, cachePolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CacheService) DeleteCachePolicy(name string) error { + reqURL := fmt.Sprintf("%s/%s", cachePolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CacheService) UpdateCachePolicy(policy models.CachePolicy) error { + payload := map[string]any{ + "cachepolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, cachePolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CacheService) UnsetCachePolicy(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{ + "cachepolicy": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, cachePolicyURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CacheService) GetAllCachePolicy() ([]models.CachePolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, cachePolicyURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Policies []models.CachePolicy `json:"cachepolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Policies, nil +} + +func (s *CacheService) GetCachePolicy(name string) ([]models.CachePolicy, error) { + reqURL := fmt.Sprintf("%s/%s", cachePolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Policies []models.CachePolicy `json:"cachepolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Policies, nil +} + +func (s *CacheService) CountCachePolicy() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, cachePolicyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Policies []struct { + Count float64 `json:"__count"` + } `json:"cachepolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Policies) > 0 { + return result.Policies[0].Count, nil + } + return 0, nil +} + +func (s *CacheService) RenameCachePolicy(name, newname string) error { + payload := map[string]any{ + "cachepolicy": map[string]string{ + "policyname": name, + "newname": newname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, cachePolicyURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} // cachepolicylabel -func (s *CacheService) AddCachePolicyLabel() {} -func (s *CacheService) DeleteCachePolicyLabel() {} -func (s *CacheService) GetAllCachePolicyLabel() {} -func (s *CacheService) GetCachePolicyLabel() {} -func (s *CacheService) CountCachePolicyLabel() {} -func (s *CacheService) RenameCachePolicyLabel() {} + +func (s *CacheService) AddCachePolicyLabel(label models.CachePolicyLabel) error { + payload := map[string]any{ + "cachepolicylabel": label, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, cachePolicyLabelURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CacheService) DeleteCachePolicyLabel(labelname string) error { + reqURL := fmt.Sprintf("%s/%s", cachePolicyLabelURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CacheService) GetAllCachePolicyLabel() ([]models.CachePolicyLabel, error) { + req, err := s.client.NewRequest(http.MethodGet, cachePolicyLabelURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Labels []models.CachePolicyLabel `json:"cachepolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Labels, nil +} + +func (s *CacheService) GetCachePolicyLabel(labelname string) ([]models.CachePolicyLabel, error) { + reqURL := fmt.Sprintf("%s/%s", cachePolicyLabelURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Labels []models.CachePolicyLabel `json:"cachepolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Labels, nil +} + +func (s *CacheService) CountCachePolicyLabel() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, cachePolicyLabelURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Labels []struct { + Count float64 `json:"__count"` + } `json:"cachepolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Labels) > 0 { + return result.Labels[0].Count, nil + } + return 0, nil +} + +func (s *CacheService) RenameCachePolicyLabel(labelname, newname string) error { + payload := map[string]any{ + "cachepolicylabel": map[string]string{ + "labelname": labelname, + "newname": newname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, cachePolicyLabelURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} // cachepolicylabel_binding -func (s *CacheService) GetAllCachePolicyLabelBinding() {} -func (s *CacheService) GetCachePolicyLabelBinding() {} + +func (s *CacheService) GetAllCachePolicyLabelBinding() ([]models.CachePolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, cachePolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CachePolicyLabelBinding `json:"cachepolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CacheService) GetCachePolicyLabelBinding(labelname string) ([]models.CachePolicyLabelBinding, error) { + reqURL := fmt.Sprintf("%s/%s", cachePolicyLabelBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CachePolicyLabelBinding `json:"cachepolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // cachepolicylabel_cachepolicy_binding -func (s *CacheService) AddCachePolicyLabelCachePolicyBinding() {} -func (s *CacheService) DeleteCachePolicyLabelCachePolicyBinding() {} -func (s *CacheService) GetAllCachePolicyLabelCachePolicyBinding() {} -func (s *CacheService) GetCachePolicyLabelCachePolicyBinding() {} -func (s *CacheService) CountCachePolicyLabelCachePolicyBinding() {} + +func (s *CacheService) AddCachePolicyLabelCachePolicyBinding(binding models.CachePolicyLabelCachePolicyBinding) error { + payload := map[string]any{ + "cachepolicylabel_cachepolicy_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, cachePolicyLabelCachePolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CacheService) DeleteCachePolicyLabelCachePolicyBinding(labelname, policyname string) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s", cachePolicyLabelCachePolicyBindingURL, url.QueryEscape(labelname), url.QueryEscape(policyname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CacheService) GetAllCachePolicyLabelCachePolicyBinding() ([]models.CachePolicyLabelCachePolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, cachePolicyLabelCachePolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CachePolicyLabelCachePolicyBinding `json:"cachepolicylabel_cachepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CacheService) GetCachePolicyLabelCachePolicyBinding(labelname string) ([]models.CachePolicyLabelCachePolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", cachePolicyLabelCachePolicyBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CachePolicyLabelCachePolicyBinding `json:"cachepolicylabel_cachepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CacheService) CountCachePolicyLabelCachePolicyBinding(labelname string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", cachePolicyLabelCachePolicyBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"cachepolicylabel_cachepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // cachepolicylabel_policybinding_binding -func (s *CacheService) GetAllCachePolicyLabelPolicyBindingBinding() {} -func (s *CacheService) GetCachePolicyLabelPolicyBindingBinding() {} -func (s *CacheService) CountCachePolicyLabelPolicyBindingBinding() {} + +func (s *CacheService) GetAllCachePolicyLabelPolicyBindingBinding() ([]models.CachePolicyLabelPolicyBindingBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, cachePolicyLabelPolicyBindingBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CachePolicyLabelPolicyBindingBinding `json:"cachepolicylabel_policybinding_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CacheService) GetCachePolicyLabelPolicyBindingBinding(labelname string) ([]models.CachePolicyLabelPolicyBindingBinding, error) { + reqURL := fmt.Sprintf("%s/%s", cachePolicyLabelPolicyBindingBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CachePolicyLabelPolicyBindingBinding `json:"cachepolicylabel_policybinding_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CacheService) CountCachePolicyLabelPolicyBindingBinding(labelname string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", cachePolicyLabelPolicyBindingBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"cachepolicylabel_policybinding_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // cachepolicy_binding -func (s *CacheService) GetAllCachePolicyBinding() {} -func (s *CacheService) GetCachePolicyBinding() {} + +func (s *CacheService) GetAllCachePolicyBinding() ([]models.CachePolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, cachePolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CachePolicyBinding `json:"cachepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CacheService) GetCachePolicyBinding(policyname string) ([]models.CachePolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", cachePolicyBindingURL, url.QueryEscape(policyname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CachePolicyBinding `json:"cachepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // cachepolicy_cacheglobal_binding -func (s *CacheService) GetAllCachePolicyCacheGlobalBinding() {} -func (s *CacheService) GetCachePolicyCacheGlobalBinding() {} -func (s *CacheService) CountCachePolicyCacheGlobalBinding() {} + +func (s *CacheService) GetAllCachePolicyCacheGlobalBinding() ([]models.CachePolicyCacheGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, cachePolicyCacheGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CachePolicyCacheGlobalBinding `json:"cachepolicy_cacheglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CacheService) GetCachePolicyCacheGlobalBinding(policyname string) ([]models.CachePolicyCacheGlobalBinding, error) { + reqURL := fmt.Sprintf("%s/%s", cachePolicyCacheGlobalBindingURL, url.QueryEscape(policyname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CachePolicyCacheGlobalBinding `json:"cachepolicy_cacheglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CacheService) CountCachePolicyCacheGlobalBinding(policyname string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", cachePolicyCacheGlobalBindingURL, url.QueryEscape(policyname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"cachepolicy_cacheglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // cachepolicy_cachepolicylabel_binding -func (s *CacheService) GetAllCachePolicyCachePolicyLabelBinding() {} -func (s *CacheService) GetCachePolicyCachePolicyLabelBinding() {} -func (s *CacheService) CountCachePolicyCachePolicyLabelBinding() {} + +func (s *CacheService) GetAllCachePolicyCachePolicyLabelBinding() ([]models.CachePolicyCachePolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, cachePolicyCachePolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CachePolicyCachePolicyLabelBinding `json:"cachepolicy_cachepolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CacheService) GetCachePolicyCachePolicyLabelBinding(policyname string) ([]models.CachePolicyCachePolicyLabelBinding, error) { + reqURL := fmt.Sprintf("%s/%s", cachePolicyCachePolicyLabelBindingURL, url.QueryEscape(policyname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CachePolicyCachePolicyLabelBinding `json:"cachepolicy_cachepolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CacheService) CountCachePolicyCachePolicyLabelBinding(policyname string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", cachePolicyCachePolicyLabelBindingURL, url.QueryEscape(policyname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"cachepolicy_cachepolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // cachepolicy_csvserver_binding -func (s *CacheService) GetAllCachePolicyCSVServerBinding() {} -func (s *CacheService) GetCachePolicyCSVServerBinding() {} -func (s *CacheService) CountCachePolicyCSVServerBinding() {} + +func (s *CacheService) GetAllCachePolicyCSVServerBinding() ([]models.CachePolicyCSVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, cachePolicyCSVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CachePolicyCSVServerBinding `json:"cachepolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CacheService) GetCachePolicyCSVServerBinding(policyname string) ([]models.CachePolicyCSVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", cachePolicyCSVServerBindingURL, url.QueryEscape(policyname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CachePolicyCSVServerBinding `json:"cachepolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CacheService) CountCachePolicyCSVServerBinding(policyname string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", cachePolicyCSVServerBindingURL, url.QueryEscape(policyname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"cachepolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // cachepolicy_lbvserver_binding -func (s *CacheService) GetAllCachePolicyLBVServerBinding() {} -func (s *CacheService) GetCachePolicyLBVServerBinding() {} -func (s *CacheService) CountCachePolicyLBVServerBinding() {} + +func (s *CacheService) GetAllCachePolicyLBVServerBinding() ([]models.CachePolicyLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, cachePolicyLBVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CachePolicyLBVServerBinding `json:"cachepolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CacheService) GetCachePolicyLBVServerBinding(policyname string) ([]models.CachePolicyLBVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", cachePolicyLBVServerBindingURL, url.QueryEscape(policyname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CachePolicyLBVServerBinding `json:"cachepolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CacheService) CountCachePolicyLBVServerBinding(policyname string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", cachePolicyLBVServerBindingURL, url.QueryEscape(policyname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"cachepolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // cacheselector -func (s *CacheService) AddCacheSelector() {} -func (s *CacheService) DeleteCacheSelector() {} -func (s *CacheService) UpdateCacheSelector() {} -func (s *CacheService) GetAllCacheSelector() {} -func (s *CacheService) GetCacheSelector() {} -func (s *CacheService) CountCacheSelector() {} + +func (s *CacheService) AddCacheSelector(selector models.CacheSelector) error { + payload := map[string]any{ + "cacheselector": selector, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, cacheSelectorURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CacheService) DeleteCacheSelector(selectorname string) error { + reqURL := fmt.Sprintf("%s/%s", cacheSelectorURL, url.QueryEscape(selectorname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CacheService) UpdateCacheSelector(selector models.CacheSelector) error { + payload := map[string]any{ + "cacheselector": selector, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, cacheSelectorURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CacheService) GetAllCacheSelector() ([]models.CacheSelector, error) { + req, err := s.client.NewRequest(http.MethodGet, cacheSelectorURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Selectors []models.CacheSelector `json:"cacheselector"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Selectors, nil +} + +func (s *CacheService) GetCacheSelector(selectorname string) ([]models.CacheSelector, error) { + reqURL := fmt.Sprintf("%s/%s", cacheSelectorURL, url.QueryEscape(selectorname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Selectors []models.CacheSelector `json:"cacheselector"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Selectors, nil +} + +func (s *CacheService) CountCacheSelector() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, cacheSelectorURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Selectors []struct { + Count float64 `json:"__count"` + } `json:"cacheselector"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Selectors) > 0 { + return result.Selectors[0].Count, nil + } + return 0, nil +} diff --git a/nitrogo/client.go b/nitrogo/client.go index 4362ea8..f0f4b79 100644 --- a/nitrogo/client.go +++ b/nitrogo/client.go @@ -6,9 +6,15 @@ import ( "fmt" "io" "net/http" + "strings" "time" ) +const ( + loginURL = "/nitro/v1/config/login" + logoutURL = "/nitro/v1/config/logout" +) + type Credential struct { username string password string @@ -19,8 +25,8 @@ type Client struct { hostname string proxiedURL string - credential Credential - sessionid string + credential Credential + sessionid string httpClient *http.Client @@ -49,7 +55,7 @@ type Client struct { DB *DBService DNS *DNSService FEO *FEOService - GLSB *GLSBService + GSLB *GSLBService HA *HAService ICA *ICAService IPSEC *IPSECService @@ -86,11 +92,12 @@ type Client struct { VPN *VPNService } -func NewNitroClient(username, password string, options ...ClientOptionFunc) (*Client, error) { +func NewNitroClient(host, username, password string, options ...ClientOptionFunc) (*Client, error) { c := &Client{ httpClient: &http.Client{ - Timeout: 5 * time.Second, + Timeout: 10 * time.Second, }, + baseURL: strings.TrimRight(host, "/"), } for _, opt := range options { @@ -124,7 +131,7 @@ func NewNitroClient(username, password string, options ...ClientOptionFunc) (*Cl c.DB = &DBService{client: c} c.DNS = &DNSService{client: c} c.FEO = &FEOService{client: c} - c.GLSB = &GLSBService{client: c} + c.GSLB = &GSLBService{client: c} c.HA = &HAService{client: c} c.ICA = &ICAService{client: c} c.IPSEC = &IPSECService{client: c} @@ -168,7 +175,7 @@ func NewNitroClient(username, password string, options ...ClientOptionFunc) (*Cl // NewRequest - creates the http.Request and applies the relevant authorization func (c *Client) NewRequest(method, path string, body io.Reader) (*http.Request, error) { - url := fmt.Sprintf("%s/%s", c.baseURL, path) + url := fmt.Sprintf("%s/%s", c.baseURL, strings.TrimLeft(path, "/")) req, err := http.NewRequest(method, url, body) if err != nil { return nil, fmt.Errorf("failed to make new HTTP request: %w", err) @@ -192,41 +199,36 @@ func (c *Client) NewRequest(method, path string, body io.Reader) (*http.Request, return req, nil } -// Do - executes the HTTP request and unmarshals the result into r. -func (c *Client) Do(req *http.Request) (map[string]any, error) { - v := map[string]any{} +// Do - executes the HTTP request and returns the response body. +func (c *Client) Do(req *http.Request) ([]byte, error) { resp, err := c.httpClient.Do(req) if err != nil { - return v, err + return nil, err } defer func() { + // should do something with these errors io.Copy(io.Discard, resp.Body) resp.Body.Close() }() respByte, err := io.ReadAll(resp.Body) if err != nil { - return v, fmt.Errorf("failed to read response body: %w", err) + return nil, fmt.Errorf("failed to read response body: %w", err) } if resp.StatusCode < 200 || resp.StatusCode > 299 { - return v, fmt.Errorf("request returned non-200 status code: %s", string(respByte)) - } - - if len(respByte) == 0 { - return v, nil + return nil, fmt.Errorf("request returned non-200 status code: %s", string(respByte)) } - return v, json.Unmarshal(respByte, &v) + return respByte, nil } +// Login - creates a session for the current NetScaler func (c *Client) Login() error { - u := "nitro/v1/config/login" - login := fmt.Appendf(nil, `{"login": {"username":"%s","password":"%s"}}`, c.credential.username, c.credential.password) - req, err := c.NewRequest(http.MethodPost, u, bytes.NewBuffer(login)) + req, err := c.NewRequest(http.MethodPost, loginURL, bytes.NewBuffer(login)) if err != nil { return err } @@ -235,11 +237,16 @@ func (c *Client) Login() error { req.Header.Del("X-Nitro-Pass") req.Header.Del("Set-Cookie") - resp, err := c.Do(req) + respByte, err := c.Do(req) if err != nil { return err } + var resp map[string]any + if err := json.Unmarshal(respByte, &resp); err != nil { + return fmt.Errorf("failed to unmarshal login response: %w", err) + } + var ok bool c.sessionid, ok = resp["sessionid"].(string) if !ok { @@ -249,12 +256,11 @@ func (c *Client) Login() error { return nil } +// Logout - Ends the on going session with the NetScaler func (c *Client) Logout() error { - u := "nitro/v1/config/logout" - logout := fmt.Appendf(nil, `{"logout": {}}`) - req, err := c.NewRequest(http.MethodPost, u, bytes.NewBuffer(logout)) + req, err := c.NewRequest(http.MethodPost, logoutURL, bytes.NewBuffer(logout)) if err != nil { return err } @@ -267,11 +273,6 @@ func (c *Client) Logout() error { return nil } -// Credential - getter for client's credentials -func (c *Client) Credential() Credential { - return c.credential -} - // Hostname - getter for client's hostname. func (c *Client) Hostname() string { return c.hostname @@ -287,10 +288,12 @@ func (c *Client) URL() string { return c.baseURL } -// SetCredential - setter for client's credential. Handles clearing and creating a new Nitro token if present. -func (c *Client) SetCredential(cred Credential) error { - c.credential = cred - return nil +// SetCredential - setter for client's credential. +func (c *Client) SetCredential(username, password string) { + c.credential = Credential{ + username: username, + password: password, + } } // SetHostname - getter for clients's hostname @@ -298,12 +301,12 @@ func (c *Client) SetHostname(hostname string) { c.hostname = hostname } -// SetProxiedURL - setter for client's proxy URL. Handles clearing and creating a new Nitro token if present. +// SetProxiedURL - setter for client's proxy URL. func (c *Client) SetProxiedURL(proxy string) { c.proxiedURL = proxy } // SetURL - setter for the client's baseURL func (c *Client) SetURL(url string) { - c.baseURL = url + c.baseURL = strings.TrimRight(url, "/") } diff --git a/nitrogo/client_options.go b/nitrogo/client_options.go index 238c19e..2d80bf7 100644 --- a/nitrogo/client_options.go +++ b/nitrogo/client_options.go @@ -4,13 +4,6 @@ import "net/http" type ClientOptionFunc func(*Client) error -func WithBaseUrl(url string) ClientOptionFunc { - return func(c *Client) error { - c.baseURL = url - return nil - } -} - func WithHostname(hostname string) ClientOptionFunc { return func(c *Client) error { c.hostname = hostname diff --git a/nitrogo/cloud.go b/nitrogo/cloud.go index c670ba8..3b6904f 100644 --- a/nitrogo/cloud.go +++ b/nitrogo/cloud.go @@ -1,54 +1,617 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + cloudAllowedNGSTicketProfileURL = "/nitro/v1/config/cloudallowedngsticketprofile" + cloudAutoscaleGroupURL = "/nitro/v1/config/cloudautoscalegroup" + cloudCredentialURL = "/nitro/v1/config/cloudcredential" + cloudParameterURL = "/nitro/v1/config/cloudparameter" + cloudParamInternalURL = "/nitro/v1/config/cloudparaminternal" + cloudProfileURL = "/nitro/v1/config/cloudprofile" + cloudServiceURL = "/nitro/v1/config/cloudservice" + cloudVServerIPURL = "/nitro/v1/config/cloudvserverip" +) + // Citrix ADC as SD proxy Configuration and cloud discovery commands. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/cloud/cloud type CloudService struct { client *Client } -// cloudautoscalegroup +// cloudallowedngsticketprofile // Configuration for Allowed ticket profile for NGS resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/cloud/cloudallowedngsticketprofile -func (s *CloudService) GetAllCloudAutoscaleGroup() {} -func (s *CloudService) GetCloudAutoscaleGroup() {} -func (s *CloudService) CountCloudAutoscaleGroup() {} + +func (s *CloudService) AddCloudAllowedNGSTicketProfile(profile models.CloudAllowedNGSTicketProfile) error { + payload := map[string]any{ + "cloudallowedngsticketprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, cloudAllowedNGSTicketProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *CloudService) DeleteCloudAllowedNGSTicketProfile(name string) error { + urlReq := fmt.Sprintf("%s/%s", cloudAllowedNGSTicketProfileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *CloudService) UpdateCloudAllowedNGSTicketProfile(profile models.CloudAllowedNGSTicketProfile) error { + payload := map[string]any{ + "cloudallowedngsticketprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, cloudAllowedNGSTicketProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *CloudService) GetAllCloudAllowedNGSTicketProfile() ([]models.CloudAllowedNGSTicketProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, cloudAllowedNGSTicketProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Profiles []models.CloudAllowedNGSTicketProfile `json:"cloudallowedngsticketprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Profiles, nil +} + +func (s *CloudService) GetCloudAllowedNGSTicketProfile(name string) ([]models.CloudAllowedNGSTicketProfile, error) { + urlReq := fmt.Sprintf("%s/%s", cloudAllowedNGSTicketProfileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Profiles []models.CloudAllowedNGSTicketProfile `json:"cloudallowedngsticketprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Profiles, nil +} + +func (s *CloudService) CountCloudAllowedNGSTicketProfile() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, cloudAllowedNGSTicketProfileURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Profiles []struct { + Count float64 `json:"__count"` + } `json:"cloudallowedngsticketprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Profiles) > 0 { + return result.Profiles[0].Count, nil + } + + return 0, nil +} + +// cloudautoscalegroup +// Configuration for Cloud Autoscale Group resource. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/cloud/cloudautoscalegroup + +func (s *CloudService) GetAllCloudAutoscaleGroup() ([]models.CloudAutoscaleGroup, error) { + req, err := s.client.NewRequest(http.MethodGet, cloudAutoscaleGroupURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Groups []models.CloudAutoscaleGroup `json:"cloudautoscalegroup"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Groups, nil +} + +func (s *CloudService) GetCloudAutoscaleGroup(name string) ([]models.CloudAutoscaleGroup, error) { + urlReq := fmt.Sprintf("%s/%s", cloudAutoscaleGroupURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Groups []models.CloudAutoscaleGroup `json:"cloudautoscalegroup"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Groups, nil +} + +func (s *CloudService) CountCloudAutoscaleGroup() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, cloudAutoscaleGroupURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Groups []struct { + Count float64 `json:"__count"` + } `json:"cloudautoscalegroup"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Groups) > 0 { + return result.Groups[0].Count, nil + } + + return 0, nil +} // cloudcredential // Configuration for cloud credentials resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/cloud/cloudcredential -func (s *CloudService) GetAllCloudCredential() {} -func (s *CloudService) UpdateCloudCredential() {} + +func (s *CloudService) GetAllCloudCredential() ([]models.CloudCredential, error) { + req, err := s.client.NewRequest(http.MethodGet, cloudCredentialURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Credentials []models.CloudCredential `json:"cloudcredential"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Credentials, nil +} + +func (s *CloudService) UpdateCloudCredential(credential models.CloudCredential) error { + payload := map[string]any{ + "cloudcredential": credential, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, cloudCredentialURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} // cloudparameter // Configuration for cloud parameter resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/cloud/cloudparameter -func (s *CloudService) UpdateCloudParameter() {} -func (s *CloudService) UnsetCloudParameter() {} -func (s *CloudService) GetAllCloudParameter() {} + +func (s *CloudService) UpdateCloudParameter(param models.CloudParameter) error { + payload := map[string]any{ + "cloudparameter": param, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, cloudParameterURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *CloudService) UnsetCloudParameter(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "cloudparameter": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, cloudParameterURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *CloudService) GetAllCloudParameter() (models.CloudParameter, error) { + req, err := s.client.NewRequest(http.MethodGet, cloudParameterURL, nil) + if err != nil { + return models.CloudParameter{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.CloudParameter{}, err + } + + var result struct { + Parameters []models.CloudParameter `json:"cloudparameter"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.CloudParameter{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Parameters) > 0 { + return result.Parameters[0], nil + } + + return models.CloudParameter{}, nil +} // cloudparaminternal // Configuration for cloud paramInternal resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/cloud/cloudparaminternal -func (s *CloudService) GetAllCloudParamInternal() {} -func (s *CloudService) CountCloudParamInternal() {} -func (s *CloudService) UpdateCloudParamInternal() {} + +func (s *CloudService) GetAllCloudParamInternal() (models.CloudParamInternal, error) { + req, err := s.client.NewRequest(http.MethodGet, cloudParamInternalURL, nil) + if err != nil { + return models.CloudParamInternal{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.CloudParamInternal{}, err + } + + var result struct { + Parameters []models.CloudParamInternal `json:"cloudparaminternal"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.CloudParamInternal{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Parameters) > 0 { + return result.Parameters[0], nil + } + + return models.CloudParamInternal{}, nil +} + +func (s *CloudService) CountCloudParamInternal() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, cloudParamInternalURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Parameters []struct { + Count float64 `json:"__count"` + } `json:"cloudparaminternal"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Parameters) > 0 { + return result.Parameters[0].Count, nil + } + + return 0, nil +} + +func (s *CloudService) UpdateCloudParamInternal(param models.CloudParamInternal) error { + payload := map[string]any{ + "cloudparaminternal": param, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, cloudParamInternalURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} // cloudprofile // Configuration for cloud profile resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/cloud/cloudprofile -func (s *CloudService) AddCloudProfile() {} -func (s *CloudService) DeleteCloudProfile() {} -func (s *CloudService) GetAllCloudProfile() {} -func (s *CloudService) GetCloudProfile() {} -func (s *CloudService) CountCloudProfile() {} + +func (s *CloudService) AddCloudProfile(profile models.CloudProfile) error { + payload := map[string]any{ + "cloudprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, cloudProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *CloudService) DeleteCloudProfile(name string) error { + urlReq := fmt.Sprintf("%s/%s", cloudProfileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *CloudService) GetAllCloudProfile() ([]models.CloudProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, cloudProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Profiles []models.CloudProfile `json:"cloudprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Profiles, nil +} + +func (s *CloudService) GetCloudProfile(name string) ([]models.CloudProfile, error) { + urlReq := fmt.Sprintf("%s/%s", cloudProfileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Profiles []models.CloudProfile `json:"cloudprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Profiles, nil +} + +func (s *CloudService) CountCloudProfile() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, cloudProfileURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Profiles []struct { + Count float64 `json:"__count"` + } `json:"cloudprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Profiles) > 0 { + return result.Profiles[0].Count, nil + } + + return 0, nil +} // cloudservice // Configuration for cloud service resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/cloud/cloudservice -func (s *CloudService) CheckCloudService() {} + +func (s *CloudService) CheckCloudService(service models.CloudService) error { + payload := map[string]any{ + "cloudservice": service, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, cloudServiceURL+"?action=check", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} // cloudvserverip // Configuration for Cloud virtual server IPs resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/cloud/cloudvserverip -func (s *CloudService) GetAllCloudVServerIP() {} -func (s *CloudService) CountCloudVServerIP() {} + +func (s *CloudService) GetAllCloudVServerIP() ([]models.CloudVServerIP, error) { + req, err := s.client.NewRequest(http.MethodGet, cloudVServerIPURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + VServerIPs []models.CloudVServerIP `json:"cloudvserverip"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.VServerIPs, nil +} + +func (s *CloudService) CountCloudVServerIP() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, cloudVServerIPURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + VServerIPs []struct { + Count float64 `json:"__count"` + } `json:"cloudvserverip"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.VServerIPs) > 0 { + return result.VServerIPs[0].Count, nil + } + + return 0, nil +} diff --git a/nitrogo/cluster.go b/nitrogo/cluster.go index b1c6983..1f7216b 100644 --- a/nitrogo/cluster.go +++ b/nitrogo/cluster.go @@ -1,151 +1,1775 @@ package nitrogo -// Configuration for 0 resource. +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + clusterFilesURL = "/nitro/v1/config/clusterfiles" + clusterInstanceURL = "/nitro/v1/config/clusterinstance" + clusterInstanceBindingURL = "/nitro/v1/config/clusterinstance_binding" + clusterInstanceClusterNodeBindingURL = "/nitro/v1/config/clusterinstance_clusternode_binding" + clusterNodeURL = "/nitro/v1/config/clusternode" + clusterNodeBindingURL = "/nitro/v1/config/clusternode_binding" + clusterNodeRouteMonitorBindingURL = "/nitro/v1/config/clusternode_routemonitor_binding" + clusterNodeGroupURL = "/nitro/v1/config/clusternodegroup" + clusterNodeGroupAuthenticationVServerBindingURL = "/nitro/v1/config/clusternodegroup_authenticationvserver_binding" + clusterNodeGroupBindingURL = "/nitro/v1/config/clusternodegroup_binding" + clusterNodeGroupClusterNodeBindingURL = "/nitro/v1/config/clusternodegroup_clusternode_binding" + clusterNodeGroupCRVServerBindingURL = "/nitro/v1/config/clusternodegroup_crvserver_binding" + clusterNodeGroupCSVServerBindingURL = "/nitro/v1/config/clusternodegroup_csvserver_binding" + clusterNodeGroupGSLBSiteBindingURL = "/nitro/v1/config/clusternodegroup_gslbsite_binding" + clusterNodeGroupGSLBVServerBindingURL = "/nitro/v1/config/clusternodegroup_gslbvserver_binding" + clusterNodeGroupLBVServerBindingURL = "/nitro/v1/config/clusternodegroup_lbvserver_binding" + clusterNodeGroupNSLimitIdentifierBindingURL = "/nitro/v1/config/clusternodegroup_nslimitidentifier_binding" + clusterNodeGroupServiceBindingURL = "/nitro/v1/config/clusternodegroup_service_binding" + clusterNodeGroupStreamIdentifierBindingURL = "/nitro/v1/config/clusternodegroup_streamidentifier_binding" + clusterNodeGroupVPNVServerBindingURL = "/nitro/v1/config/clusternodegroup_vpnvserver_binding" + clusterPropStatusURL = "/nitro/v1/config/clusterpropstatus" + clusterSyncURL = "/nitro/v1/config/clustersync" +) + +// Configuration for cluster resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/cluster/cluster type ClusterService struct { client *Client } // clusterfiles -func (s *ClusterService) SyncClusterFiles() {} +func (s *ClusterService) SyncClusterFiles(files models.ClusterFiles) error { + payload := map[string]any{"clusterfiles": files} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, clusterFilesURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} // clusterinstance -func (s *ClusterService) AddClusterInstance() {} -func (s *ClusterService) DeleteClusterInstance() {} -func (s *ClusterService) UpdateClusterInstance() {} -func (s *ClusterService) UnsetClusterInstance() {} -func (s *ClusterService) EnableClusterInstance() {} -func (s *ClusterService) DisableClusterInstance() {} -func (s *ClusterService) GetAllClusterInstance() {} -func (s *ClusterService) GetClusterInstance() {} -func (s *ClusterService) CountClusterInstance() {} +func (s *ClusterService) AddClusterInstance(instance models.ClusterInstance) error { + payload := map[string]any{"clusterinstance": instance} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, clusterInstanceURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) DeleteClusterInstance(clid int) error { + reqURL := fmt.Sprintf("%s/%d", clusterInstanceURL, clid) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) UpdateClusterInstance(instance models.ClusterInstance) error { + payload := map[string]any{"clusterinstance": instance} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, clusterInstanceURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) UnsetClusterInstance(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"clusterinstance": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, clusterInstanceURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) EnableClusterInstance(clid int) error { + payload := map[string]any{ + "clusterinstance": map[string]any{"clid": clid}, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, clusterInstanceURL+"?action=enable", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) DisableClusterInstance(clid int) error { + payload := map[string]any{ + "clusterinstance": map[string]any{"clid": clid}, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, clusterInstanceURL+"?action=disable", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) GetAllClusterInstance() ([]models.ClusterInstance, error) { + req, err := s.client.NewRequest(http.MethodGet, clusterInstanceURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Instances []models.ClusterInstance `json:"clusterinstance"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Instances, nil +} + +func (s *ClusterService) GetClusterInstance(clid string) ([]models.ClusterInstance, error) { + reqURL := fmt.Sprintf("%s/%s", clusterInstanceURL, url.QueryEscape(clid)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Instances []models.ClusterInstance `json:"clusterinstance"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Instances, nil +} + +func (s *ClusterService) CountClusterInstance() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, clusterInstanceURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Instances []struct { + Count float64 `json:"__count"` + } `json:"clusterinstance"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Instances) > 0 { + return result.Instances[0].Count, nil + } + return 0, nil +} // clusterinstance_binding -func (s *ClusterService) GetAllClusterInstanceBinding() {} -func (s *ClusterService) GetClusterInstanceBinding() {} +func (s *ClusterService) GetAllClusterInstanceBinding() ([]models.ClusterInstanceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, clusterInstanceBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterInstanceBinding `json:"clusterinstance_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} -// cluisterinstance_clusternode_binding -func (s *ClusterService) GetAllClusterInstanceClusterNodeBinding() {} -func (s *ClusterService) GetClusterInstanceClusterNodeBinding() {} -func (s *ClusterService) CountClusterInstanceClusterNodeBinding() {} +func (s *ClusterService) GetClusterInstanceBinding(clid string) ([]models.ClusterInstanceBinding, error) { + reqURL := fmt.Sprintf("%s/%s", clusterInstanceBindingURL, url.QueryEscape(clid)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterInstanceBinding `json:"clusterinstance_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +// clusterinstance_clusternode_binding +func (s *ClusterService) GetAllClusterInstanceClusterNodeBinding() ([]models.ClusterInstanceClusterNodeBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, clusterInstanceClusterNodeBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterInstanceClusterNodeBinding `json:"clusterinstance_clusternode_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) GetClusterInstanceClusterNodeBinding(clid string) ([]models.ClusterInstanceClusterNodeBinding, error) { + reqURL := fmt.Sprintf("%s/%s", clusterInstanceClusterNodeBindingURL, url.QueryEscape(clid)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterInstanceClusterNodeBinding `json:"clusterinstance_clusternode_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) CountClusterInstanceClusterNodeBinding(clid string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", clusterInstanceClusterNodeBindingURL, url.QueryEscape(clid)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"clusterinstance_clusternode_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // clusternode -func (s *ClusterService) AddClusterNode() {} -func (s *ClusterService) DeleteClusterNode() {} -func (s *ClusterService) UpdateClusterNode() {} -func (s *ClusterService) UnsetClusterNode() {} -func (s *ClusterService) GetAllClusterNode() {} -func (s *ClusterService) GetClusterNode() {} -func (s *ClusterService) CountClusterNode() {} +func (s *ClusterService) AddClusterNode(node models.ClusterNode) error { + payload := map[string]any{"clusternode": node} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, clusterNodeURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) DeleteClusterNode(nodeID int) error { + reqURL := fmt.Sprintf("%s/%d", clusterNodeURL, nodeID) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) UpdateClusterNode(node models.ClusterNode) error { + payload := map[string]any{"clusternode": node} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, clusterNodeURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) UnsetClusterNode(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"clusternode": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, clusterNodeURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) GetAllClusterNode() ([]models.ClusterNode, error) { + req, err := s.client.NewRequest(http.MethodGet, clusterNodeURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Nodes []models.ClusterNode `json:"clusternode"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Nodes, nil +} + +func (s *ClusterService) GetClusterNode(nodeID string) ([]models.ClusterNode, error) { + reqURL := fmt.Sprintf("%s/%s", clusterNodeURL, url.QueryEscape(nodeID)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Nodes []models.ClusterNode `json:"clusternode"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Nodes, nil +} + +func (s *ClusterService) CountClusterNode() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, clusterNodeURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Nodes []struct { + Count float64 `json:"__count"` + } `json:"clusternode"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Nodes) > 0 { + return result.Nodes[0].Count, nil + } + return 0, nil +} // clusternodegroup -func (s *ClusterService) AddClusterNodeGroup() {} -func (s *ClusterService) DeleteClusterNodeGroup() {} -func (s *ClusterService) UpdateClusterNodeGroup() {} -func (s *ClusterService) UnsetClusterNodeGroup() {} -func (s *ClusterService) GetAllClusterNodeGroup() {} -func (s *ClusterService) GetClusterNodeGroup() {} -func (s *ClusterService) CountClusterNodeGroup() {} +func (s *ClusterService) AddClusterNodeGroup(group models.ClusterNodeGroup) error { + payload := map[string]any{"clusternodegroup": group} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, clusterNodeGroupURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) DeleteClusterNodeGroup(name string) error { + reqURL := fmt.Sprintf("%s/%s", clusterNodeGroupURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) UpdateClusterNodeGroup(group models.ClusterNodeGroup) error { + payload := map[string]any{"clusternodegroup": group} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, clusterNodeGroupURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) UnsetClusterNodeGroup(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"clusternodegroup": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, clusterNodeGroupURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) GetAllClusterNodeGroup() ([]models.ClusterNodeGroup, error) { + req, err := s.client.NewRequest(http.MethodGet, clusterNodeGroupURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Groups []models.ClusterNodeGroup `json:"clusternodegroup"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Groups, nil +} + +func (s *ClusterService) GetClusterNodeGroup(name string) ([]models.ClusterNodeGroup, error) { + reqURL := fmt.Sprintf("%s/%s", clusterNodeGroupURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Groups []models.ClusterNodeGroup `json:"clusternodegroup"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Groups, nil +} + +func (s *ClusterService) CountClusterNodeGroup() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, clusterNodeGroupURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Groups []struct { + Count float64 `json:"__count"` + } `json:"clusternodegroup"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Groups) > 0 { + return result.Groups[0].Count, nil + } + return 0, nil +} // clusternodegroup_authenticationvserver_binding -func (s *ClusterService) AddClusternodeGroupAuthenticationVServerBinding() {} -func (s *ClusterService) DeleteClusternodeGroupAuthenticationVServerBinding() {} -func (s *ClusterService) GetAllClusternodeGroupAuthenticationVServerBinding() {} -func (s *ClusterService) GetClusternodeGroupAuthenticationVServerBinding() {} -func (s *ClusterService) CountClusternodeGroupAuthenticationVServerBinding() {} +func (s *ClusterService) AddClusternodeGroupAuthenticationVServerBinding(binding models.ClusterNodeGroupAuthenticationVServerBinding) error { + payload := map[string]any{"clusternodegroup_authenticationvserver_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, clusterNodeGroupAuthenticationVServerBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) DeleteClusternodeGroupAuthenticationVServerBinding(name string, vserver string) error { + reqURL := fmt.Sprintf("%s/%s?args=vserver:%s", clusterNodeGroupAuthenticationVServerBindingURL, url.QueryEscape(name), url.QueryEscape(vserver)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) GetAllClusternodeGroupAuthenticationVServerBinding() ([]models.ClusterNodeGroupAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, clusterNodeGroupAuthenticationVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeGroupAuthenticationVServerBinding `json:"clusternodegroup_authenticationvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) GetClusternodeGroupAuthenticationVServerBinding(name string) ([]models.ClusterNodeGroupAuthenticationVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", clusterNodeGroupAuthenticationVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeGroupAuthenticationVServerBinding `json:"clusternodegroup_authenticationvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) CountClusternodeGroupAuthenticationVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", clusterNodeGroupAuthenticationVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"clusternodegroup_authenticationvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // clusternodegroup_binding -func (s *ClusterService) GetAllClusterNodeGroupBinding() {} -func (s *ClusterService) GetClusterNodeGroupBinding() {} +func (s *ClusterService) GetAllClusterNodeGroupBinding() ([]models.ClusterNodeGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, clusterNodeGroupBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeGroupBinding `json:"clusternodegroup_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) GetClusterNodeGroupBinding(name string) ([]models.ClusterNodeGroupBinding, error) { + reqURL := fmt.Sprintf("%s/%s", clusterNodeGroupBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeGroupBinding `json:"clusternodegroup_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // clusternodegroup_clusternode_binding -func (s *ClusterService) AddClusterNodeGroupClusterNodeBinding() {} -func (s *ClusterService) DeleteClusterNodeGroupClusterNodeBinding() {} -func (s *ClusterService) GetAllClusterNodeGroupClusterNodeBinding() {} -func (s *ClusterService) GetClusterNodeGroupClusterNodeBinding() {} -func (s *ClusterService) CountClusterNodeGroupClusterNodeBinding() {} +func (s *ClusterService) AddClusterNodeGroupClusterNodeBinding(binding models.ClusterNodeGroupClusterNodeBinding) error { + payload := map[string]any{"clusternodegroup_clusternode_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, clusterNodeGroupClusterNodeBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) DeleteClusterNodeGroupClusterNodeBinding(name string, node int) error { + reqURL := fmt.Sprintf("%s/%s?args=node:%d", clusterNodeGroupClusterNodeBindingURL, url.QueryEscape(name), node) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) GetAllClusterNodeGroupClusterNodeBinding() ([]models.ClusterNodeGroupClusterNodeBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, clusterNodeGroupClusterNodeBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeGroupClusterNodeBinding `json:"clusternodegroup_clusternode_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) GetClusterNodeGroupClusterNodeBinding(name string) ([]models.ClusterNodeGroupClusterNodeBinding, error) { + reqURL := fmt.Sprintf("%s/%s", clusterNodeGroupClusterNodeBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeGroupClusterNodeBinding `json:"clusternodegroup_clusternode_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) CountClusterNodeGroupClusterNodeBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", clusterNodeGroupClusterNodeBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"clusternodegroup_clusternode_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // clusternodegroup_crvserver_binding -func (s *ClusterService) AddClusterNodeGroupCRVServerBinding() {} -func (s *ClusterService) DeleteClusterNodeGroupCRVServerBinding() {} -func (s *ClusterService) GetAllClusterNodeGroupCRVServerBinding() {} -func (s *ClusterService) GetClusterNodeGroupCRVServerBinding() {} -func (s *ClusterService) CountClusterNodeGroupCRVServerBinding() {} +func (s *ClusterService) AddClusterNodeGroupCRVServerBinding(binding models.ClusterNodeGroupCRVServerBinding) error { + payload := map[string]any{"clusternodegroup_crvserver_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, clusterNodeGroupCRVServerBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) DeleteClusterNodeGroupCRVServerBinding(name string, vserver string) error { + reqURL := fmt.Sprintf("%s/%s?args=vserver:%s", clusterNodeGroupCRVServerBindingURL, url.QueryEscape(name), url.QueryEscape(vserver)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) GetAllClusterNodeGroupCRVServerBinding() ([]models.ClusterNodeGroupCRVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, clusterNodeGroupCRVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeGroupCRVServerBinding `json:"clusternodegroup_crvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) GetClusterNodeGroupCRVServerBinding(name string) ([]models.ClusterNodeGroupCRVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", clusterNodeGroupCRVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeGroupCRVServerBinding `json:"clusternodegroup_crvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) CountClusterNodeGroupCRVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", clusterNodeGroupCRVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"clusternodegroup_crvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // clusternodegroup_csvserver_binding -func (s *ClusterService) AddClusterNodeGroupCSVServerBinding() {} -func (s *ClusterService) DeleteClusterNodeGroupCSVServerBinding() {} -func (s *ClusterService) GetAllClusterNodeGroupCSVServerBinding() {} -func (s *ClusterService) GetClusterNodeGroupCSVServerBinding() {} -func (s *ClusterService) CountClusterNodeGroupCSVServerBinding() {} +func (s *ClusterService) AddClusterNodeGroupCSVServerBinding(binding models.ClusterNodeGroupCSVServerBinding) error { + payload := map[string]any{"clusternodegroup_csvserver_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, clusterNodeGroupCSVServerBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) DeleteClusterNodeGroupCSVServerBinding(name string, vserver string) error { + reqURL := fmt.Sprintf("%s/%s?args=vserver:%s", clusterNodeGroupCSVServerBindingURL, url.QueryEscape(name), url.QueryEscape(vserver)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) GetAllClusterNodeGroupCSVServerBinding() ([]models.ClusterNodeGroupCSVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, clusterNodeGroupCSVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeGroupCSVServerBinding `json:"clusternodegroup_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) GetClusterNodeGroupCSVServerBinding(name string) ([]models.ClusterNodeGroupCSVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", clusterNodeGroupCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeGroupCSVServerBinding `json:"clusternodegroup_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) CountClusterNodeGroupCSVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", clusterNodeGroupCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"clusternodegroup_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // clusternodegroup_gslbsite_binding -func (s *ClusterService) AddClusterNodeGroupGLSBSiteBinding() {} -func (s *ClusterService) DeleteClusterNodeGroupGLSBSiteBinding() {} -func (s *ClusterService) GetAllClusterNodeGroupGLSBSiteBinding() {} -func (s *ClusterService) GetClusterNodeGroupGLSBSiteBinding() {} -func (s *ClusterService) CountClusterNodeGroupGLSBSiteBinding() {} - -// clusternodegroup_glsbvserver_binding -func (s *ClusterService) AddClusterNodeGroupGSLBVServerBinding() {} -func (s *ClusterService) DeleteClusterNodeGroupGSLBVServerBinding() {} -func (s *ClusterService) GetAllClusterNodeGroupGSLBVServerBinding() {} -func (s *ClusterService) GetClusterNodeGroupGSLBVServerBinding() {} -func (s *ClusterService) CountClusterNodeGroupGSLBVServerBinding() {} +func (s *ClusterService) AddClusterNodeGroupGSLBSiteBinding(binding models.ClusterNodeGroupGSLBSiteBinding) error { + payload := map[string]any{"clusternodegroup_gslbsite_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, clusterNodeGroupGSLBSiteBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) DeleteClusterNodeGroupGSLBSiteBinding(name string, gslbsite string) error { + reqURL := fmt.Sprintf("%s/%s?args=gslbsite:%s", clusterNodeGroupGSLBSiteBindingURL, url.QueryEscape(name), url.QueryEscape(gslbsite)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) GetAllClusterNodeGroupGSLBSiteBinding() ([]models.ClusterNodeGroupGSLBSiteBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, clusterNodeGroupGSLBSiteBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeGroupGSLBSiteBinding `json:"clusternodegroup_gslbsite_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) GetClusterNodeGroupGSLBSiteBinding(name string) ([]models.ClusterNodeGroupGSLBSiteBinding, error) { + reqURL := fmt.Sprintf("%s/%s", clusterNodeGroupGSLBSiteBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeGroupGSLBSiteBinding `json:"clusternodegroup_gslbsite_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) CountClusterNodeGroupGSLBSiteBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", clusterNodeGroupGSLBSiteBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"clusternodegroup_gslbsite_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} + +// clusternodegroup_gslbvserver_binding +func (s *ClusterService) AddClusterNodeGroupGSLBVServerBinding(binding models.ClusterNodeGroupGSLBVServerBinding) error { + payload := map[string]any{"clusternodegroup_gslbvserver_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, clusterNodeGroupGSLBVServerBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) DeleteClusterNodeGroupGSLBVServerBinding(name string, vserver string) error { + reqURL := fmt.Sprintf("%s/%s?args=vserver:%s", clusterNodeGroupGSLBVServerBindingURL, url.QueryEscape(name), url.QueryEscape(vserver)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) GetAllClusterNodeGroupGSLBVServerBinding() ([]models.ClusterNodeGroupGSLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, clusterNodeGroupGSLBVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeGroupGSLBVServerBinding `json:"clusternodegroup_gslbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) GetClusterNodeGroupGSLBVServerBinding(name string) ([]models.ClusterNodeGroupGSLBVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", clusterNodeGroupGSLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeGroupGSLBVServerBinding `json:"clusternodegroup_gslbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) CountClusterNodeGroupGSLBVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", clusterNodeGroupGSLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"clusternodegroup_gslbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // clusternodegroup_lbvserver_binding -func (s *ClusterService) AddClusterNodeGroupLBVServerBinding() {} -func (s *ClusterService) DeleteClusterNodeGroupLBVServerBinding() {} -func (s *ClusterService) GetAllClusterNodeGroupLBVServerBinding() {} -func (s *ClusterService) GetClusterNodeGroupLBVServerBinding() {} -func (s *ClusterService) CountClusterNodeGroupLBVServerBinding() {} +func (s *ClusterService) AddClusterNodeGroupLBVServerBinding(binding models.ClusterNodeGroupLBVServerBinding) error { + payload := map[string]any{"clusternodegroup_lbvserver_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, clusterNodeGroupLBVServerBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) DeleteClusterNodeGroupLBVServerBinding(name string, vserver string) error { + reqURL := fmt.Sprintf("%s/%s?args=vserver:%s", clusterNodeGroupLBVServerBindingURL, url.QueryEscape(name), url.QueryEscape(vserver)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) GetAllClusterNodeGroupLBVServerBinding() ([]models.ClusterNodeGroupLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, clusterNodeGroupLBVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeGroupLBVServerBinding `json:"clusternodegroup_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) GetClusterNodeGroupLBVServerBinding(name string) ([]models.ClusterNodeGroupLBVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", clusterNodeGroupLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeGroupLBVServerBinding `json:"clusternodegroup_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) CountClusterNodeGroupLBVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", clusterNodeGroupLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"clusternodegroup_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // clusternodegroup_nslimitidentifier_binding -func (s *ClusterService) AddClusterNodeGroupNSLimitIdentifierBinding() {} -func (s *ClusterService) DeleteClusterNodeGroupNSLimitIdentifierBinding() {} -func (s *ClusterService) GetAllClusterNodeGroupNSLimitIdentifierBinding() {} -func (s *ClusterService) GetClusterNodeGroupNSLimitIdentifierBinding() {} -func (s *ClusterService) CountClusterNodeGroupNSLimitIdentifierBinding() {} +func (s *ClusterService) AddClusterNodeGroupNSLimitIdentifierBinding(binding models.ClusterNodeGroupNSLimitIdentifierBinding) error { + payload := map[string]any{"clusternodegroup_nslimitidentifier_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, clusterNodeGroupNSLimitIdentifierBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) DeleteClusterNodeGroupNSLimitIdentifierBinding(name string, identifierName string) error { + reqURL := fmt.Sprintf("%s/%s?args=identifiername:%s", clusterNodeGroupNSLimitIdentifierBindingURL, url.QueryEscape(name), url.QueryEscape(identifierName)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) GetAllClusterNodeGroupNSLimitIdentifierBinding() ([]models.ClusterNodeGroupNSLimitIdentifierBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, clusterNodeGroupNSLimitIdentifierBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeGroupNSLimitIdentifierBinding `json:"clusternodegroup_nslimitidentifier_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) GetClusterNodeGroupNSLimitIdentifierBinding(name string) ([]models.ClusterNodeGroupNSLimitIdentifierBinding, error) { + reqURL := fmt.Sprintf("%s/%s", clusterNodeGroupNSLimitIdentifierBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeGroupNSLimitIdentifierBinding `json:"clusternodegroup_nslimitidentifier_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) CountClusterNodeGroupNSLimitIdentifierBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", clusterNodeGroupNSLimitIdentifierBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"clusternodegroup_nslimitidentifier_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // clusternodegroup_service_binding -func (s *ClusterService) AddClusterNodeGroupServiceBinding() {} -func (s *ClusterService) DeleteClusterNodeGroupServiceBinding() {} -func (s *ClusterService) GetAllClusterNodeGroupServiceBinding() {} -func (s *ClusterService) GetClusterNodeGroupServiceBinding() {} -func (s *ClusterService) CountClusterNodeGroupServiceBinding() {} +func (s *ClusterService) AddClusterNodeGroupServiceBinding(binding models.ClusterNodeGroupServiceBinding) error { + payload := map[string]any{"clusternodegroup_service_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, clusterNodeGroupServiceBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) DeleteClusterNodeGroupServiceBinding(name string, service string) error { + reqURL := fmt.Sprintf("%s/%s?args=service:%s", clusterNodeGroupServiceBindingURL, url.QueryEscape(name), url.QueryEscape(service)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) GetAllClusterNodeGroupServiceBinding() ([]models.ClusterNodeGroupServiceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, clusterNodeGroupServiceBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeGroupServiceBinding `json:"clusternodegroup_service_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) GetClusterNodeGroupServiceBinding(name string) ([]models.ClusterNodeGroupServiceBinding, error) { + reqURL := fmt.Sprintf("%s/%s", clusterNodeGroupServiceBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeGroupServiceBinding `json:"clusternodegroup_service_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) CountClusterNodeGroupServiceBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", clusterNodeGroupServiceBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"clusternodegroup_service_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // clusternodegroup_streamidentifier_binding -func (s *ClusterService) AddClusterNodeGroupStreamIdentifierBinding() {} -func (s *ClusterService) DeleteClusterNodeGroupStreamIdentifierBinding() {} -func (s *ClusterService) GetAllClusterNodeGroupStreamIdentifierBinding() {} -func (s *ClusterService) GetClusterNodeGroupStreamIdentifierBinding() {} -func (s *ClusterService) CountClusterNodeGroupStreamIdentifierBinding() {} +func (s *ClusterService) AddClusterNodeGroupStreamIdentifierBinding(binding models.ClusterNodeGroupStreamIdentifierBinding) error { + payload := map[string]any{"clusternodegroup_streamidentifier_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, clusterNodeGroupStreamIdentifierBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) DeleteClusterNodeGroupStreamIdentifierBinding(name string, identifierName string) error { + reqURL := fmt.Sprintf("%s/%s?args=identifiername:%s", clusterNodeGroupStreamIdentifierBindingURL, url.QueryEscape(name), url.QueryEscape(identifierName)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) GetAllClusterNodeGroupStreamIdentifierBinding() ([]models.ClusterNodeGroupStreamIdentifierBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, clusterNodeGroupStreamIdentifierBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeGroupStreamIdentifierBinding `json:"clusternodegroup_streamidentifier_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) GetClusterNodeGroupStreamIdentifierBinding(name string) ([]models.ClusterNodeGroupStreamIdentifierBinding, error) { + reqURL := fmt.Sprintf("%s/%s", clusterNodeGroupStreamIdentifierBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeGroupStreamIdentifierBinding `json:"clusternodegroup_streamidentifier_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) CountClusterNodeGroupStreamIdentifierBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", clusterNodeGroupStreamIdentifierBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"clusternodegroup_streamidentifier_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // clusternodegroup_vpnvserver_binding -func (s *ClusterService) AddClusterNodeGroupVPNVServerBinding() {} -func (s *ClusterService) DeleteClusterNodeGroupVPNVServerBinding() {} -func (s *ClusterService) GetAllClusterNodeGroupVPNVServerBinding() {} -func (s *ClusterService) GetClusterNodeGroupVPNVServerBinding() {} -func (s *ClusterService) CountClusterNodeGroupVPNVServerBinding() {} +func (s *ClusterService) AddClusterNodeGroupVPNVServerBinding(binding models.ClusterNodeGroupVPNVServerBinding) error { + payload := map[string]any{"clusternodegroup_vpnvserver_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, clusterNodeGroupVPNVServerBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) DeleteClusterNodeGroupVPNVServerBinding(name string, vserver string) error { + reqURL := fmt.Sprintf("%s/%s?args=vserver:%s", clusterNodeGroupVPNVServerBindingURL, url.QueryEscape(name), url.QueryEscape(vserver)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) GetAllClusterNodeGroupVPNVServerBinding() ([]models.ClusterNodeGroupVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, clusterNodeGroupVPNVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeGroupVPNVServerBinding `json:"clusternodegroup_vpnvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) GetClusterNodeGroupVPNVServerBinding(name string) ([]models.ClusterNodeGroupVPNVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", clusterNodeGroupVPNVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeGroupVPNVServerBinding `json:"clusternodegroup_vpnvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) CountClusterNodeGroupVPNVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", clusterNodeGroupVPNVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"clusternodegroup_vpnvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // clusternode_binding -func (s *ClusterService) GetAllClusterNodeBinding() {} -func (s *ClusterService) GetClusterNodeBinding() {} +func (s *ClusterService) GetAllClusterNodeBinding() ([]models.ClusterNodeBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, clusterNodeBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeBinding `json:"clusternode_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) GetClusterNodeBinding(nodeID string) ([]models.ClusterNodeBinding, error) { + reqURL := fmt.Sprintf("%s/%s", clusterNodeBindingURL, url.QueryEscape(nodeID)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeBinding `json:"clusternode_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // clusternode_routemonitor_binding -func (s *ClusterService) AddClusterNodeRouteMonitorBinding() {} -func (s *ClusterService) DeleteClusterNodeRouteMonitorBinding() {} -func (s *ClusterService) GetAllClusterNodeRouteMonitorBinding() {} -func (s *ClusterService) GetClusterNodeRouteMonitorBinding() {} -func (s *ClusterService) CountClusterNodeRouteMonitorBinding() {} +func (s *ClusterService) AddClusterNodeRouteMonitorBinding(binding models.ClusterNodeRouteMonitorBinding) error { + payload := map[string]any{"clusternode_routemonitor_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, clusterNodeRouteMonitorBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) DeleteClusterNodeRouteMonitorBinding(nodeID int, routeMonitor string) error { + reqURL := fmt.Sprintf("%s/%d?args=routemonitor:%s", clusterNodeRouteMonitorBindingURL, nodeID, url.QueryEscape(routeMonitor)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ClusterService) GetAllClusterNodeRouteMonitorBinding() ([]models.ClusterNodeRouteMonitorBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, clusterNodeRouteMonitorBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeRouteMonitorBinding `json:"clusternode_routemonitor_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) GetClusterNodeRouteMonitorBinding(nodeID string) ([]models.ClusterNodeRouteMonitorBinding, error) { + reqURL := fmt.Sprintf("%s/%s", clusterNodeRouteMonitorBindingURL, url.QueryEscape(nodeID)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ClusterNodeRouteMonitorBinding `json:"clusternode_routemonitor_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ClusterService) CountClusterNodeRouteMonitorBinding(nodeID string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", clusterNodeRouteMonitorBindingURL, url.QueryEscape(nodeID)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"clusternode_routemonitor_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // clusterpropstatus -func (s *ClusterService) GetAllClusterPropStatus() {} -func (s *ClusterService) CountClusterPropStatus() {} -func (s *ClusterService) ClearClusterPropStatus() {} +func (s *ClusterService) GetAllClusterPropStatus() ([]models.ClusterPropStatus, error) { + req, err := s.client.NewRequest(http.MethodGet, clusterPropStatusURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Status []models.ClusterPropStatus `json:"clusterpropstatus"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Status, nil +} -// clustersync -func (s *ClusterService) ForceClusterSync() {} +func (s *ClusterService) CountClusterPropStatus() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, clusterPropStatusURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Status []struct { + Count float64 `json:"__count"` + } `json:"clusterpropstatus"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Status) > 0 { + return result.Status[0].Count, nil + } + return 0, nil +} + +func (s *ClusterService) ClearClusterPropStatus() error { + payload := map[string]any{} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, clusterPropStatusURL+"?action=clear", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} -// cluster_grp -// Documentation page doesn't work +// clustersync +func (s *ClusterService) ForceClusterSync() error { + payload := map[string]any{} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, clusterSyncURL+"?action=force", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} diff --git a/nitrogo/cmp.go b/nitrogo/cmp.go index b71b539..1377259 100644 --- a/nitrogo/cmp.go +++ b/nitrogo/cmp.go @@ -1,5 +1,33 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + cmpActionURL = "/nitro/v1/config/cmpaction" + cmpGlobalBindingURL = "/nitro/v1/config/cmpglobal_binding" + cmpGlobalCMPPolicyBindingURL = "/nitro/v1/config/cmpglobal_cmppolicy_binding" + cmpParameterURL = "/nitro/v1/config/cmpparameter" + cmpPolicyURL = "/nitro/v1/config/cmppolicy" + cmpPolicyLabelURL = "/nitro/v1/config/cmppolicylabel" + cmpPolicyLabelBindingURL = "/nitro/v1/config/cmppolicylabel_binding" + cmpPolicyLabelCMPPolicyBindingURL = "/nitro/v1/config/cmppolicylabel_cmppolicy_binding" + cmpPolicyLabelPolicyBindingBindingURL = "/nitro/v1/config/cmppolicylabel_policybinding_binding" + cmpPolicyBindingURL = "/nitro/v1/config/cmppolicy_binding" + cmpPolicyCMPGlobalBindingURL = "/nitro/v1/config/cmppolicy_cmpglobal_binding" + cmpPolicyCMPPolicyLabelBindingURL = "/nitro/v1/config/cmppolicy_cmppolicylabel_binding" + cmpPolicyCRVServerBindingURL = "/nitro/v1/config/cmppolicy_crvserver_binding" + cmpPolicyCSVServerBindingURL = "/nitro/v1/config/cmppolicy_csvserver_binding" + cmpPolicyLBVServerBindingURL = "/nitro/v1/config/cmppolicy_lbvserver_binding" +) + // Compression configuration. The system’s feature for compressing HTTP responses to compression-aware browsers. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/cmp/cmp type CMPService struct { @@ -7,87 +35,1105 @@ type CMPService struct { } // cmpaction -func (s *CMPService) AddCMPAction() {} -func (s *CMPService) DeleteCMPAction() {} -func (s *CMPService) UpdateCMPAction() {} -func (s *CMPService) UnsetCMPAction() {} -func (s *CMPService) GetAllCMPAction() {} -func (s *CMPService) GetCMPAction() {} -func (s *CMPService) CountCMPAction() {} -func (s *CMPService) RenameCMPAction() {} + +func (s *CMPService) AddCMPAction(action models.CMPAction) error { + payload := map[string]any{ + "cmpaction": action, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, cmpActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CMPService) DeleteCMPAction(name string) error { + reqURL := fmt.Sprintf("%s/%s", cmpActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CMPService) UpdateCMPAction(action models.CMPAction) error { + payload := map[string]any{ + "cmpaction": action, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, cmpActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CMPService) UnsetCMPAction(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{ + "cmpaction": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, cmpActionURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CMPService) GetAllCMPAction() ([]models.CMPAction, error) { + req, err := s.client.NewRequest(http.MethodGet, cmpActionURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Actions []models.CMPAction `json:"cmpaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Actions, nil +} + +func (s *CMPService) GetCMPAction(name string) ([]models.CMPAction, error) { + reqURL := fmt.Sprintf("%s/%s", cmpActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Actions []models.CMPAction `json:"cmpaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Actions, nil +} + +func (s *CMPService) CountCMPAction() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, cmpActionURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Actions []struct { + Count float64 `json:"__count"` + } `json:"cmpaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Actions) > 0 { + return result.Actions[0].Count, nil + } + return 0, nil +} + +func (s *CMPService) RenameCMPAction(name, newname string) error { + payload := map[string]any{ + "cmpaction": map[string]string{ + "name": name, + "newname": newname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, cmpActionURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} // cmpglobal_binding -func (s *CMPService) GetCMPGlobalBinding() {} -// cmpglobal_cpmpolicy_binding -func (s *CMPService) AddCMPGlobalCMPPolicyBinding() {} -func (s *CMPService) DeleteCMPGlobalCMPPolicyBinding() {} -func (s *CMPService) GetCMPGlobalCMPPolicyBinding() {} -func (s *CMPService) CountCMPGlobalCMPPolicyBinding() {} +func (s *CMPService) GetCMPGlobalBinding() ([]models.CMPGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, cmpGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CMPGlobalBinding `json:"cmpglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +// cmpglobal_cmppolicy_binding + +func (s *CMPService) AddCMPGlobalCMPPolicyBinding(binding models.CMPGlobalCMPPolicyBinding) error { + payload := map[string]any{ + "cmpglobal_cmppolicy_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, cmpGlobalCMPPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CMPService) DeleteCMPGlobalCMPPolicyBinding(policyname string) error { + reqURL := fmt.Sprintf("%s?args=policyname:%s", cmpGlobalCMPPolicyBindingURL, url.QueryEscape(policyname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CMPService) GetCMPGlobalCMPPolicyBinding() ([]models.CMPGlobalCMPPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, cmpGlobalCMPPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CMPGlobalCMPPolicyBinding `json:"cmpglobal_cmppolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CMPService) CountCMPGlobalCMPPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, cmpGlobalCMPPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"cmpglobal_cmppolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // cmpparameter -func (s *CMPService) UpdateCMPParameter() {} -func (s *CMPService) UnsetCMPParameter() {} -func (s *CMPService) GetAllCMPParameter() {} + +func (s *CMPService) UpdateCMPParameter(param models.CMPParameter) error { + payload := map[string]any{ + "cmpparameter": param, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, cmpParameterURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CMPService) UnsetCMPParameter(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{ + "cmpparameter": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, cmpParameterURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CMPService) GetAllCMPParameter() (models.CMPParameter, error) { + req, err := s.client.NewRequest(http.MethodGet, cmpParameterURL, nil) + if err != nil { + return models.CMPParameter{}, err + } + resp, err := s.client.Do(req) + if err != nil { + return models.CMPParameter{}, err + } + var result struct { + Params []models.CMPParameter `json:"cmpparameter"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return models.CMPParameter{}, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Params) > 0 { + return result.Params[0], nil + } + return models.CMPParameter{}, nil +} // cmppolicy -func (s *CMPService) AddCOMPolicy() {} -func (s *CMPService) DeleteCOMPolicy() {} -func (s *CMPService) UpdateCOMPolicy() {} -func (s *CMPService) GetAllCOMPolicy() {} -func (s *CMPService) GetCOMPolicy() {} -func (s *CMPService) CountCOMPolicy() {} -func (s *CMPService) RenameCOMPolicy() {} + +func (s *CMPService) AddCOMPolicy(policy models.CMPPolicy) error { + payload := map[string]any{ + "cmppolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, cmpPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CMPService) DeleteCOMPolicy(name string) error { + reqURL := fmt.Sprintf("%s/%s", cmpPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CMPService) UpdateCOMPolicy(policy models.CMPPolicy) error { + payload := map[string]any{ + "cmppolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, cmpPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CMPService) GetAllCOMPolicy() ([]models.CMPPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, cmpPolicyURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Policies []models.CMPPolicy `json:"cmppolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Policies, nil +} + +func (s *CMPService) GetCOMPolicy(name string) ([]models.CMPPolicy, error) { + reqURL := fmt.Sprintf("%s/%s", cmpPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Policies []models.CMPPolicy `json:"cmppolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Policies, nil +} + +func (s *CMPService) CountCOMPolicy() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, cmpPolicyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Policies []struct { + Count float64 `json:"__count"` + } `json:"cmppolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Policies) > 0 { + return result.Policies[0].Count, nil + } + return 0, nil +} + +func (s *CMPService) RenameCOMPolicy(name, newname string) error { + payload := map[string]any{ + "cmppolicy": map[string]string{ + "name": name, + "newname": newname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, cmpPolicyURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} // cmppolicylabel -func (s *CMPService) AddCMPPolicyLabel() {} -func (s *CMPService) DeleteCMPPolicyLabel() {} -func (s *CMPService) GetAllCMPPolicyLabel() {} -func (s *CMPService) GetCMPPolicyLabel() {} -func (s *CMPService) CountCMPPolicyLabel() {} -func (s *CMPService) RenameCMPPolicyLabel() {} + +func (s *CMPService) AddCMPPolicyLabel(label models.CMPPolicyLabel) error { + payload := map[string]any{ + "cmppolicylabel": label, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, cmpPolicyLabelURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CMPService) DeleteCMPPolicyLabel(name string) error { + reqURL := fmt.Sprintf("%s/%s", cmpPolicyLabelURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CMPService) GetAllCMPPolicyLabel() ([]models.CMPPolicyLabel, error) { + req, err := s.client.NewRequest(http.MethodGet, cmpPolicyLabelURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Labels []models.CMPPolicyLabel `json:"cmppolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Labels, nil +} + +func (s *CMPService) GetCMPPolicyLabel(name string) ([]models.CMPPolicyLabel, error) { + reqURL := fmt.Sprintf("%s/%s", cmpPolicyLabelURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Labels []models.CMPPolicyLabel `json:"cmppolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Labels, nil +} + +func (s *CMPService) CountCMPPolicyLabel() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, cmpPolicyLabelURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Labels []struct { + Count float64 `json:"__count"` + } `json:"cmppolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Labels) > 0 { + return result.Labels[0].Count, nil + } + return 0, nil +} + +func (s *CMPService) RenameCMPPolicyLabel(name, newname string) error { + payload := map[string]any{ + "cmppolicylabel": map[string]string{ + "labelname": name, + "newname": newname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, cmpPolicyLabelURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} // cmppolicylabel_binding -func (s *CMPService) GetAllCMPPolicyLabelBinding() {} -func (s *CMPService) GetCMPPolicyLabelBinding() {} + +func (s *CMPService) GetAllCMPPolicyLabelBinding() ([]models.CMPPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, cmpPolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CMPPolicyLabelBinding `json:"cmppolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CMPService) GetCMPPolicyLabelBinding(name string) ([]models.CMPPolicyLabelBinding, error) { + reqURL := fmt.Sprintf("%s/%s", cmpPolicyLabelBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CMPPolicyLabelBinding `json:"cmppolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // cmppolicylabel_cmppolicy_binding -func (s *CMPService) AddCMPPolicyLabelCMPPolicyBinding() {} -func (s *CMPService) DeleteCMPPolicyLabelCMPPolicyBinding() {} -func (s *CMPService) GetAllCMPPolicyLabelCMPPolicyBinding() {} -func (s *CMPService) GetCMPPolicyLabelCMPPolicyBinding() {} -func (s *CMPService) CountCMPPolicyLabelCMPPolicyBinding() {} + +func (s *CMPService) AddCMPPolicyLabelCMPPolicyBinding(binding models.CMPPolicyLabelCMPPolicyBinding) error { + payload := map[string]any{ + "cmppolicylabel_cmppolicy_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, cmpPolicyLabelCMPPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CMPService) DeleteCMPPolicyLabelCMPPolicyBinding(labelname, policyname string) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s", cmpPolicyLabelCMPPolicyBindingURL, url.QueryEscape(labelname), url.QueryEscape(policyname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CMPService) GetAllCMPPolicyLabelCMPPolicyBinding() ([]models.CMPPolicyLabelCMPPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, cmpPolicyLabelCMPPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CMPPolicyLabelCMPPolicyBinding `json:"cmppolicylabel_cmppolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CMPService) GetCMPPolicyLabelCMPPolicyBinding(name string) ([]models.CMPPolicyLabelCMPPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", cmpPolicyLabelCMPPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CMPPolicyLabelCMPPolicyBinding `json:"cmppolicylabel_cmppolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CMPService) CountCMPPolicyLabelCMPPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", cmpPolicyLabelCMPPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"cmppolicylabel_cmppolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // cmppolicylabel_policybinding_binding -func (s *CMPService) GetAllCMPPolicyLabelPolicyBindingBinding() {} -func (s *CMPService) GetCMPPolicyLabelPolicyBindingBinding() {} -func (s *CMPService) CountCMPPolicyLabelPolicyBindingBinding() {} + +func (s *CMPService) GetAllCMPPolicyLabelPolicyBindingBinding() ([]models.CMPPolicyLabelPolicyBindingBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, cmpPolicyLabelPolicyBindingBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CMPPolicyLabelPolicyBindingBinding `json:"cmppolicylabel_policybinding_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CMPService) GetCMPPolicyLabelPolicyBindingBinding(name string) ([]models.CMPPolicyLabelPolicyBindingBinding, error) { + reqURL := fmt.Sprintf("%s/%s", cmpPolicyLabelPolicyBindingBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CMPPolicyLabelPolicyBindingBinding `json:"cmppolicylabel_policybinding_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CMPService) CountCMPPolicyLabelPolicyBindingBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", cmpPolicyLabelPolicyBindingBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"cmppolicylabel_policybinding_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // cmppolicy_binding -func (s *CMPService) GetAllCMPPolicyBinding() {} -func (s *CMPService) GetCMPPolicyBinding() {} + +func (s *CMPService) GetAllCMPPolicyBinding() ([]models.CMPPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, cmpPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CMPPolicyBinding `json:"cmppolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CMPService) GetCMPPolicyBinding(name string) ([]models.CMPPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", cmpPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CMPPolicyBinding `json:"cmppolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // cmppolicy_cmpglobal_binding -func (s *CMPService) GetAllCMPPolicyCMPGlobalBinding() {} -func (s *CMPService) GetCMPPolicyCMPGlobalBinding() {} -func (s *CMPService) CountCMPPolicyCMPGlobalBinding() {} + +func (s *CMPService) GetAllCMPPolicyCMPGlobalBinding() ([]models.CMPPolicyCMPGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, cmpPolicyCMPGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CMPPolicyCMPGlobalBinding `json:"cmppolicy_cmpglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CMPService) GetCMPPolicyCMPGlobalBinding(name string) ([]models.CMPPolicyCMPGlobalBinding, error) { + reqURL := fmt.Sprintf("%s/%s", cmpPolicyCMPGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CMPPolicyCMPGlobalBinding `json:"cmppolicy_cmpglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CMPService) CountCMPPolicyCMPGlobalBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", cmpPolicyCMPGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"cmppolicy_cmpglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // cmppolicy_cmppolicylabel_binding -func (s *CMPService) GetAllCMPPolicyCMPPolicyLabelBinding() {} -func (s *CMPService) GetCMPPolicyCMPPolicyLabelBinding() {} -func (s *CMPService) CountCMPPolicyCMPPolicyLabelBinding() {} + +func (s *CMPService) GetAllCMPPolicyCMPPolicyLabelBinding() ([]models.CMPPolicyCMPPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, cmpPolicyCMPPolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CMPPolicyCMPPolicyLabelBinding `json:"cmppolicy_cmppolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CMPService) GetCMPPolicyCMPPolicyLabelBinding(name string) ([]models.CMPPolicyCMPPolicyLabelBinding, error) { + reqURL := fmt.Sprintf("%s/%s", cmpPolicyCMPPolicyLabelBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CMPPolicyCMPPolicyLabelBinding `json:"cmppolicy_cmppolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CMPService) CountCMPPolicyCMPPolicyLabelBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", cmpPolicyCMPPolicyLabelBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"cmppolicy_cmppolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // cmppolicy_crvserver_binding -func (s *CMPService) GetAllCMPPolicyCRVserverBinding() {} -func (s *CMPService) GetCMPPolicyCRVserverBinding() {} -func (s *CMPService) CountCMPPolicyCRVserverBinding() {} + +func (s *CMPService) GetAllCMPPolicyCRVserverBinding() ([]models.CMPPolicyCRVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, cmpPolicyCRVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CMPPolicyCRVServerBinding `json:"cmppolicy_crvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CMPService) GetCMPPolicyCRVserverBinding(name string) ([]models.CMPPolicyCRVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", cmpPolicyCRVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CMPPolicyCRVServerBinding `json:"cmppolicy_crvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CMPService) CountCMPPolicyCRVserverBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", cmpPolicyCRVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"cmppolicy_crvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // cmppolicy_csvserver_binding -func (s *CMPService) GetAllCMPPolicyCSVServerBinding() {} -func (s *CMPService) GetCMPPolicyCSVServerBinding() {} -func (s *CMPService) CountCMPPolicyCSVServerBinding() {} + +func (s *CMPService) GetAllCMPPolicyCSVServerBinding() ([]models.CMPPolicyCSVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, cmpPolicyCSVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CMPPolicyCSVServerBinding `json:"cmppolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CMPService) GetCMPPolicyCSVServerBinding(name string) ([]models.CMPPolicyCSVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", cmpPolicyCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CMPPolicyCSVServerBinding `json:"cmppolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CMPService) CountCMPPolicyCSVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", cmpPolicyCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"cmppolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // cmppolicy_lbvserver_binding -func (s *CMPService) GetAllCMPPolicyLBVServerBinding() {} -func (s *CMPService) GetCMPPolicyLBVServerBinding() {} -func (s *CMPService) CountCMPPolicyLBVServerBinding() {} + +func (s *CMPService) GetAllCMPPolicyLBVServerBinding() ([]models.CMPPolicyLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, cmpPolicyLBVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CMPPolicyLBVServerBinding `json:"cmppolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CMPService) GetCMPPolicyLBVServerBinding(name string) ([]models.CMPPolicyLBVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", cmpPolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CMPPolicyLBVServerBinding `json:"cmppolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CMPService) CountCMPPolicyLBVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", cmpPolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"cmppolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} diff --git a/nitrogo/content_inspection.go b/nitrogo/content_inspection.go index 1f97e92..af29df8 100644 --- a/nitrogo/content_inspection.go +++ b/nitrogo/content_inspection.go @@ -1,5 +1,34 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + contentInspectionActionURL = "/nitro/v1/config/contentinspectionaction" + contentInspectionCalloutURL = "/nitro/v1/config/contentinspectioncallout" + contentInspectionGlobalBindingURL = "/nitro/v1/config/contentinspectionglobal_binding" + contentInspectionGlobalContentInspectionPolicyBindingURL = "/nitro/v1/config/contentinspectionglobal_contentinspectionpolicy_binding" + contentInspectionParameterURL = "/nitro/v1/config/contentinspectionparameter" + contentInspectionPolicyURL = "/nitro/v1/config/contentinspectionpolicy" + contentInspectionPolicyLabelURL = "/nitro/v1/config/contentinspectionpolicylabel" + contentInspectionPolicyLabelBindingURL = "/nitro/v1/config/contentinspectionpolicylabel_binding" + contentInspectionPolicyLabelContentInspectionPolicyBindingURL = "/nitro/v1/config/contentinspectionpolicylabel_contentinspectionpolicy_binding" + contentInspectionPolicyLabelPolicyBindingBindingURL = "/nitro/v1/config/contentinspectionpolicylabel_policybinding_binding" + contentInspectionPolicyBindingURL = "/nitro/v1/config/contentinspectionpolicy_binding" + contentInspectionPolicyContentInspectionGlobalBindingURL = "/nitro/v1/config/contentinspectionpolicy_contentinspectionglobal_binding" + contentInspectionPolicyContentInspectionPolicyLabelBindingURL = "/nitro/v1/config/contentinspectionpolicy_contentinspectionpolicylabel_binding" + contentInspectionPolicyCSVServerBindingURL = "/nitro/v1/config/contentinspectionpolicy_csvserver_binding" + contentInspectionPolicyLBVServerBindingURL = "/nitro/v1/config/contentinspectionpolicy_lbvserver_binding" + contentInspectionProfileURL = "/nitro/v1/config/contentinspectionprofile" +) + // Content Inspection // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/contentinspection/contentinspection type ContentInspectionService struct { @@ -7,105 +36,1405 @@ type ContentInspectionService struct { } // contentinspectionaction -func (s *ContentInspectionService) AddContentInspectionAction() {} -func (s *ContentInspectionService) DeleteContentInspectionAction() {} -func (s *ContentInspectionService) UpdateContentInspectionAction() {} -func (s *ContentInspectionService) UnsetContentInspectionAction() {} -func (s *ContentInspectionService) GetAllContentInspectionAction() {} -func (s *ContentInspectionService) GetContentInspectionAction() {} -func (s *ContentInspectionService) CountContentInspectionAction() {} +func (s *ContentInspectionService) AddContentInspectionAction(resource models.ContentInspectionAction) error { + payload := map[string]any{"contentinspectionaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, contentInspectionActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ContentInspectionService) DeleteContentInspectionAction(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", contentInspectionActionURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ContentInspectionService) UpdateContentInspectionAction(resource models.ContentInspectionAction) error { + payload := map[string]any{"contentinspectionaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, contentInspectionActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ContentInspectionService) UnsetContentInspectionAction(resource models.ContentInspectionAction) error { + payload := map[string]any{"contentinspectionaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", contentInspectionActionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ContentInspectionService) GetAllContentInspectionAction() ([]models.ContentInspectionAction, error) { + req, err := s.client.NewRequest(http.MethodGet, contentInspectionActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.ContentInspectionAction `json:"contentinspectionaction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *ContentInspectionService) GetContentInspectionAction(name string) (models.ContentInspectionAction, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", contentInspectionActionURL, name), nil) + if err != nil { + return models.ContentInspectionAction{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.ContentInspectionAction{}, err + } + + var result struct { + Data []models.ContentInspectionAction `json:"contentinspectionaction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.ContentInspectionAction{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.ContentInspectionAction{}, fmt.Errorf("contentinspectionaction %s not found", name) + } + + return result.Data[0], nil +} + +func (s *ContentInspectionService) CountContentInspectionAction() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", contentInspectionActionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.ContentInspectionAction `json:"contentinspectionaction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} // contentinspectioncallout -func (s *ContentInspectionService) AddContentInspectionCallout() {} -func (s *ContentInspectionService) DeleteContentInspectionCallout() {} -func (s *ContentInspectionService) UpdateContentInspectionCallout() {} -func (s *ContentInspectionService) UnsetContentInspectionCallout() {} -func (s *ContentInspectionService) GetAllContentInspectionCallout() {} -func (s *ContentInspectionService) GetContentInspectionCallout() {} -func (s *ContentInspectionService) CountContentInspectionCallout() {} +func (s *ContentInspectionService) AddContentInspectionCallout(resource models.ContentInspectionCallout) error { + payload := map[string]any{"contentinspectioncallout": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, contentInspectionCalloutURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ContentInspectionService) DeleteContentInspectionCallout(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", contentInspectionCalloutURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ContentInspectionService) UpdateContentInspectionCallout(resource models.ContentInspectionCallout) error { + payload := map[string]any{"contentinspectioncallout": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, contentInspectionCalloutURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ContentInspectionService) UnsetContentInspectionCallout(resource models.ContentInspectionCallout) error { + payload := map[string]any{"contentinspectioncallout": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", contentInspectionCalloutURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ContentInspectionService) GetAllContentInspectionCallout() ([]models.ContentInspectionCallout, error) { + req, err := s.client.NewRequest(http.MethodGet, contentInspectionCalloutURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.ContentInspectionCallout `json:"contentinspectioncallout"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *ContentInspectionService) GetContentInspectionCallout(name string) (models.ContentInspectionCallout, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", contentInspectionCalloutURL, name), nil) + if err != nil { + return models.ContentInspectionCallout{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.ContentInspectionCallout{}, err + } + + var result struct { + Data []models.ContentInspectionCallout `json:"contentinspectioncallout"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.ContentInspectionCallout{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.ContentInspectionCallout{}, fmt.Errorf("contentinspectioncallout %s not found", name) + } + + return result.Data[0], nil +} + +func (s *ContentInspectionService) CountContentInspectionCallout() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", contentInspectionCalloutURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.ContentInspectionCallout `json:"contentinspectioncallout"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} // contentinspectionglobal_binding -func (s *ContentInspectionService) GetContentInspectionGlobalBinding() {} +func (s *ContentInspectionService) GetContentInspectionGlobalBinding() (models.ContentInspectionGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, contentInspectionGlobalBindingURL, nil) + if err != nil { + return models.ContentInspectionGlobalBinding{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.ContentInspectionGlobalBinding{}, err + } + + var result struct { + Data []models.ContentInspectionGlobalBinding `json:"contentinspectionglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.ContentInspectionGlobalBinding{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.ContentInspectionGlobalBinding{}, fmt.Errorf("contentinspectionglobal_binding not found") + } + + return result.Data[0], nil +} // contentinspectionglobal_contentinspectionpolicy_binding -func (s *ContentInspectionService) AddContentInspectionGlobalContentInspectionPolicyBinding() {} -func (s *ContentInspectionService) DeleteContentInspectionGlobalContentInspectionPolicyBinding() {} -func (s *ContentInspectionService) GetContentInspectionGlobalContentInspectionPolicyBinding() {} -func (s *ContentInspectionService) CountContentInspectionGlobalContentInspectionPolicyBinding() {} +func (s *ContentInspectionService) AddContentInspectionGlobalContentInspectionPolicyBinding(resource models.ContentInspectionGlobalContentInspectionPolicyBinding) error { + payload := map[string]any{"contentinspectionglobal_contentinspectionpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, contentInspectionGlobalContentInspectionPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ContentInspectionService) DeleteContentInspectionGlobalContentInspectionPolicyBinding(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", contentInspectionGlobalContentInspectionPolicyBindingURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ContentInspectionService) GetContentInspectionGlobalContentInspectionPolicyBinding() ([]models.ContentInspectionGlobalContentInspectionPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, contentInspectionGlobalContentInspectionPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.ContentInspectionGlobalContentInspectionPolicyBinding `json:"contentinspectionglobal_contentinspectionpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// Struct lacks Count field, leaving for later +func (s *ContentInspectionService) CountContentInspectionGlobalContentInspectionPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, contentInspectionGlobalContentInspectionPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"contentinspectionglobal_contentinspectionpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} // contentinspectionparameter -func (s *ContentInspectionService) UpdateContentInspectionParameter() {} -func (s *ContentInspectionService) UnsetContentInspectionParameter() {} -func (s *ContentInspectionService) GetAllContentInspectionParameter() {} +func (s *ContentInspectionService) UpdateContentInspectionParameter(resource models.ContentInspectionParameter) error { + payload := map[string]any{"contentinspectionparameter": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, contentInspectionParameterURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ContentInspectionService) UnsetContentInspectionParameter(resource models.ContentInspectionParameter) error { + payload := map[string]any{"contentinspectionparameter": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", contentInspectionParameterURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ContentInspectionService) GetAllContentInspectionParameter() (models.ContentInspectionParameter, error) { + req, err := s.client.NewRequest(http.MethodGet, contentInspectionParameterURL, nil) + if err != nil { + return models.ContentInspectionParameter{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.ContentInspectionParameter{}, err + } + + var result struct { + Data models.ContentInspectionParameter `json:"contentinspectionparameter"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.ContentInspectionParameter{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} // contentinspectionpolicy -func (s *ContentInspectionService) AddContentInspectionPolicy() {} -func (s *ContentInspectionService) DeleteContentInspectionPolicy() {} -func (s *ContentInspectionService) UpdateContentInspectionPolicy() {} -func (s *ContentInspectionService) UnsetContentInspectionPolicy() {} -func (s *ContentInspectionService) GetAllContentInspectionPolicy() {} -func (s *ContentInspectionService) GetContentInspectionPolicy() {} -func (s *ContentInspectionService) CountContentInspectionPolicy() {} -func (s *ContentInspectionService) RenameContentInspectionPolicy() {} +func (s *ContentInspectionService) AddContentInspectionPolicy(resource models.ContentInspectionPolicy) error { + payload := map[string]any{"contentinspectionpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, contentInspectionPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ContentInspectionService) DeleteContentInspectionPolicy(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", contentInspectionPolicyURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ContentInspectionService) UpdateContentInspectionPolicy(resource models.ContentInspectionPolicy) error { + payload := map[string]any{"contentinspectionpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, contentInspectionPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ContentInspectionService) UnsetContentInspectionPolicy(resource models.ContentInspectionPolicy) error { + payload := map[string]any{"contentinspectionpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", contentInspectionPolicyURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ContentInspectionService) GetAllContentInspectionPolicy() ([]models.ContentInspectionPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, contentInspectionPolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.ContentInspectionPolicy `json:"contentinspectionpolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *ContentInspectionService) GetContentInspectionPolicy(name string) (models.ContentInspectionPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", contentInspectionPolicyURL, name), nil) + if err != nil { + return models.ContentInspectionPolicy{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.ContentInspectionPolicy{}, err + } + + var result struct { + Data []models.ContentInspectionPolicy `json:"contentinspectionpolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.ContentInspectionPolicy{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.ContentInspectionPolicy{}, fmt.Errorf("contentinspectionpolicy %s not found", name) + } + + return result.Data[0], nil +} + +func (s *ContentInspectionService) CountContentInspectionPolicy() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", contentInspectionPolicyURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.ContentInspectionPolicy `json:"contentinspectionpolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +func (s *ContentInspectionService) RenameContentInspectionPolicy(resource models.ContentInspectionPolicy) error { + payload := map[string]any{"contentinspectionpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=rename", contentInspectionPolicyURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} // contentinspectionpolicylabel -func (s *ContentInspectionService) AddContentInspectionPolicyLabel() {} -func (s *ContentInspectionService) DeleteContentInspectionPolicyLabel() {} -func (s *ContentInspectionService) GetAllContentInspectionPolicyLabel() {} -func (s *ContentInspectionService) GetContentInspectionPolicyLabel() {} -func (s *ContentInspectionService) CountContentInspectionPolicyLabel() {} -func (s *ContentInspectionService) RenameContentInspectionPolicyLabel() {} +func (s *ContentInspectionService) AddContentInspectionPolicyLabel(resource models.ContentInspectionPolicyLabel) error { + payload := map[string]any{"contentinspectionpolicylabel": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, contentInspectionPolicyLabelURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ContentInspectionService) DeleteContentInspectionPolicyLabel(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", contentInspectionPolicyLabelURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ContentInspectionService) GetAllContentInspectionPolicyLabel() ([]models.ContentInspectionPolicyLabel, error) { + req, err := s.client.NewRequest(http.MethodGet, contentInspectionPolicyLabelURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.ContentInspectionPolicyLabel `json:"contentinspectionpolicylabel"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *ContentInspectionService) GetContentInspectionPolicyLabel(name string) (models.ContentInspectionPolicyLabel, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", contentInspectionPolicyLabelURL, name), nil) + if err != nil { + return models.ContentInspectionPolicyLabel{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.ContentInspectionPolicyLabel{}, err + } + + var result struct { + Data []models.ContentInspectionPolicyLabel `json:"contentinspectionpolicylabel"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.ContentInspectionPolicyLabel{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.ContentInspectionPolicyLabel{}, fmt.Errorf("contentinspectionpolicylabel %s not found", name) + } + + return result.Data[0], nil +} + +func (s *ContentInspectionService) CountContentInspectionPolicyLabel() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", contentInspectionPolicyLabelURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.ContentInspectionPolicyLabel `json:"contentinspectionpolicylabel"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +func (s *ContentInspectionService) RenameContentInspectionPolicyLabel(resource models.ContentInspectionPolicyLabel) error { + payload := map[string]any{"contentinspectionpolicylabel": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=rename", contentInspectionPolicyLabelURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} // contentinspectionpolicylabel_binding -func (s *ContentInspectionService) GetAllContentInspectionPolicyLabelBinding() {} -func (s *ContentInspectionService) GetContentInspectionPolicyLabelBinding() {} +func (s *ContentInspectionService) GetAllContentInspectionPolicyLabelBinding() ([]models.ContentInspectionPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, contentInspectionPolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.ContentInspectionPolicyLabelBinding `json:"contentinspectionpolicylabel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *ContentInspectionService) GetContentInspectionPolicyLabelBinding(name string) (models.ContentInspectionPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", contentInspectionPolicyLabelBindingURL, name), nil) + if err != nil { + return models.ContentInspectionPolicyLabelBinding{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.ContentInspectionPolicyLabelBinding{}, err + } + + var result struct { + Data []models.ContentInspectionPolicyLabelBinding `json:"contentinspectionpolicylabel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.ContentInspectionPolicyLabelBinding{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.ContentInspectionPolicyLabelBinding{}, fmt.Errorf("contentinspectionpolicylabel_binding %s not found", name) + } + + return result.Data[0], nil +} // contentinspectionpolicylabel_contentinspectionpolicy_binding -func (s *ContentInspectionService) AddContentInspectionPolicyLabelContentInspectionPolicyBinding() {} -func (s *ContentInspectionService) DeleteContentInspectionPolicyLabelContentInspectionPolicyBinding() { +func (s *ContentInspectionService) AddContentInspectionPolicyLabelContentInspectionPolicyBinding(resource models.ContentInspectionPolicyLabelContentInspectionPolicyBinding) error { + payload := map[string]any{"contentinspectionpolicylabel_contentinspectionpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, contentInspectionPolicyLabelContentInspectionPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ContentInspectionService) DeleteContentInspectionPolicyLabelContentInspectionPolicyBinding(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", contentInspectionPolicyLabelContentInspectionPolicyBindingURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err } -func (s *ContentInspectionService) GetAllContentInspectionPolicyLabelContentInspectionPolicyBinding() { + +func (s *ContentInspectionService) GetAllContentInspectionPolicyLabelContentInspectionPolicyBinding() ([]models.ContentInspectionPolicyLabelContentInspectionPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, contentInspectionPolicyLabelContentInspectionPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.ContentInspectionPolicyLabelContentInspectionPolicyBinding `json:"contentinspectionpolicylabel_contentinspectionpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil } -func (s *ContentInspectionService) GetContentInspectionPolicyLabelContentInspectionPolicyBinding() {} + +func (s *ContentInspectionService) GetContentInspectionPolicyLabelContentInspectionPolicyBinding(name string) (models.ContentInspectionPolicyLabelContentInspectionPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", contentInspectionPolicyLabelContentInspectionPolicyBindingURL, name), nil) + if err != nil { + return models.ContentInspectionPolicyLabelContentInspectionPolicyBinding{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.ContentInspectionPolicyLabelContentInspectionPolicyBinding{}, err + } + + var result struct { + Data []models.ContentInspectionPolicyLabelContentInspectionPolicyBinding `json:"contentinspectionpolicylabel_contentinspectionpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.ContentInspectionPolicyLabelContentInspectionPolicyBinding{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.ContentInspectionPolicyLabelContentInspectionPolicyBinding{}, fmt.Errorf("contentinspectionpolicylabel_contentinspectionpolicy_binding %s not found", name) + } + + return result.Data[0], nil +} + +// Struct lacks Count field, leaving for later func (s *ContentInspectionService) CountContentInspectionPolicyLabelContentInspectionPolicyBinding() { } // contentinspectionpolicylabel_policybinding_binding -func (s *ContentInspectionService) GetAllContentInspectionPolicyLabelPolicyBindingBinding() {} -func (s *ContentInspectionService) GetContentInspectionPolicyLabelPolicyBindingBinding() {} -func (s *ContentInspectionService) CountContentInspectionPolicyLabelPolicyBindingBinding() {} +func (s *ContentInspectionService) GetAllContentInspectionPolicyLabelPolicyBindingBinding() ([]models.ContentInspectionPolicyLabelPolicyBindingBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, contentInspectionPolicyLabelPolicyBindingBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.ContentInspectionPolicyLabelPolicyBindingBinding `json:"contentinspectionpolicylabel_policybinding_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *ContentInspectionService) GetContentInspectionPolicyLabelPolicyBindingBinding(name string) (models.ContentInspectionPolicyLabelPolicyBindingBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", contentInspectionPolicyLabelPolicyBindingBindingURL, name), nil) + if err != nil { + return models.ContentInspectionPolicyLabelPolicyBindingBinding{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.ContentInspectionPolicyLabelPolicyBindingBinding{}, err + } + + var result struct { + Data []models.ContentInspectionPolicyLabelPolicyBindingBinding `json:"contentinspectionpolicylabel_policybinding_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.ContentInspectionPolicyLabelPolicyBindingBinding{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.ContentInspectionPolicyLabelPolicyBindingBinding{}, fmt.Errorf("contentinspectionpolicylabel_policybinding_binding %s not found", name) + } + + return result.Data[0], nil +} + +// Struct lacks Count field, leaving for later +func (s *ContentInspectionService) CountContentInspectionPolicyLabelPolicyBindingBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, contentInspectionPolicyLabelPolicyBindingBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"contentinspectionpolicylabel_policybinding_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} // contentinspectionpolicy_binding -func (s *ContentInspectionService) GetAllContentInspectionPolicyBinding() {} -func (s *ContentInspectionService) GetContentInspectionPolicyBinding() {} +func (s *ContentInspectionService) GetAllContentInspectionPolicyBinding() ([]models.ContentInspectionPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, contentInspectionPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.ContentInspectionPolicyBinding `json:"contentinspectionpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *ContentInspectionService) GetContentInspectionPolicyBinding(name string) (models.ContentInspectionPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", contentInspectionPolicyBindingURL, name), nil) + if err != nil { + return models.ContentInspectionPolicyBinding{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.ContentInspectionPolicyBinding{}, err + } + + var result struct { + Data []models.ContentInspectionPolicyBinding `json:"contentinspectionpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.ContentInspectionPolicyBinding{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.ContentInspectionPolicyBinding{}, fmt.Errorf("contentinspectionpolicy_binding %s not found", name) + } + + return result.Data[0], nil +} // contentinspectionpolicy_contentinspectionglobal_binding -func (s *ContentInspectionService) GetAllContentInspectionPolcyContentInspectionGlobalBinding() {} -func (s *ContentInspectionService) GetContentInspectionPolcyContentInspectionGlobalBinding() {} -func (s *ContentInspectionService) CountContentInspectionPolcyContentInspectionGlobalBinding() {} +func (s *ContentInspectionService) GetAllContentInspectionPolcyContentInspectionGlobalBinding() ([]models.ContentInspectionPolicyContentInspectionGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, contentInspectionPolicyContentInspectionGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.ContentInspectionPolicyContentInspectionGlobalBinding `json:"contentinspectionpolicy_contentinspectionglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *ContentInspectionService) GetContentInspectionPolcyContentInspectionGlobalBinding(name string) (models.ContentInspectionPolicyContentInspectionGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", contentInspectionPolicyContentInspectionGlobalBindingURL, name), nil) + if err != nil { + return models.ContentInspectionPolicyContentInspectionGlobalBinding{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.ContentInspectionPolicyContentInspectionGlobalBinding{}, err + } + + var result struct { + Data []models.ContentInspectionPolicyContentInspectionGlobalBinding `json:"contentinspectionpolicy_contentinspectionglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.ContentInspectionPolicyContentInspectionGlobalBinding{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.ContentInspectionPolicyContentInspectionGlobalBinding{}, fmt.Errorf("contentinspectionpolicy_contentinspectionglobal_binding %s not found", name) + } + + return result.Data[0], nil +} + +// Struct lacks Count field, leaving for later +func (s *ContentInspectionService) CountContentInspectionPolcyContentInspectionGlobalBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", contentInspectionPolicyContentInspectionGlobalBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"contentinspectionpolicy_contentinspectionglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} // contentinspectionpolicy_contentinspectionpolicylabel_binding -func (s *ContentInspectionService) GetAllContentInspectionPolicyContentInspectionPolicyLabelBinding() { +func (s *ContentInspectionService) GetAllContentInspectionPolicyContentInspectionPolicyLabelBinding() ([]models.ContentInspectionPolicyContentInspectionPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, contentInspectionPolicyContentInspectionPolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.ContentInspectionPolicyContentInspectionPolicyLabelBinding `json:"contentinspectionpolicy_contentinspectionpolicylabel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil } -func (s *ContentInspectionService) GetContentInspectionPolicyContentInspectionPolicyLabelBinding() {} + +func (s *ContentInspectionService) GetContentInspectionPolicyContentInspectionPolicyLabelBinding(name string) (models.ContentInspectionPolicyContentInspectionPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", contentInspectionPolicyContentInspectionPolicyLabelBindingURL, name), nil) + if err != nil { + return models.ContentInspectionPolicyContentInspectionPolicyLabelBinding{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.ContentInspectionPolicyContentInspectionPolicyLabelBinding{}, err + } + + var result struct { + Data []models.ContentInspectionPolicyContentInspectionPolicyLabelBinding `json:"contentinspectionpolicy_contentinspectionpolicylabel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.ContentInspectionPolicyContentInspectionPolicyLabelBinding{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.ContentInspectionPolicyContentInspectionPolicyLabelBinding{}, fmt.Errorf("contentinspectionpolicy_contentinspectionpolicylabel_binding %s not found", name) + } + + return result.Data[0], nil +} + +// Struct lacks Count field, leaving for later func (s *ContentInspectionService) CountContentInspectionPolicyContentInspectionPolicyLabelBinding() { } // contentinspectionpolicy_csvserver_binding -func (s *ContentInspectionService) GetAllContentInspectionPolicyCSVServerBinding() {} -func (s *ContentInspectionService) GetContentInspectionPolicyCSVServerBinding() {} -func (s *ContentInspectionService) CountContentInspectionPolicyCSVServerBinding() {} +func (s *ContentInspectionService) GetAllContentInspectionPolicyCSVServerBinding() ([]models.ContentInspectionPolicyCSVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, contentInspectionPolicyCSVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.ContentInspectionPolicyCSVServerBinding `json:"contentinspectionpolicy_csvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *ContentInspectionService) GetContentInspectionPolicyCSVServerBinding(name string) (models.ContentInspectionPolicyCSVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", contentInspectionPolicyCSVServerBindingURL, name), nil) + if err != nil { + return models.ContentInspectionPolicyCSVServerBinding{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.ContentInspectionPolicyCSVServerBinding{}, err + } + + var result struct { + Data []models.ContentInspectionPolicyCSVServerBinding `json:"contentinspectionpolicy_csvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.ContentInspectionPolicyCSVServerBinding{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.ContentInspectionPolicyCSVServerBinding{}, fmt.Errorf("contentinspectionpolicy_csvserver_binding %s not found", name) + } + + return result.Data[0], nil +} + +// Struct lacks Count field, leaving for later +func (s *ContentInspectionService) CountContentInspectionPolicyCSVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", contentInspectionPolicyCSVServerBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"contentinspectionpolicy_csvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} // contentinspectionpolicy_lbvserver_binding -func (s *ContentInspectionService) GetAllContentInspectionPolcyLBVServerBinding() {} -func (s *ContentInspectionService) GetContentInspectionPolcyLBVServerBinding() {} -func (s *ContentInspectionService) CountContentInspectionPolcyLBVServerBinding() {} +func (s *ContentInspectionService) GetAllContentInspectionPolcyLBVServerBinding() ([]models.ContentInspectionPolicyLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, contentInspectionPolicyLBVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.ContentInspectionPolicyLBVServerBinding `json:"contentinspectionpolicy_lbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *ContentInspectionService) GetContentInspectionPolcyLBVServerBinding(name string) (models.ContentInspectionPolicyLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", contentInspectionPolicyLBVServerBindingURL, name), nil) + if err != nil { + return models.ContentInspectionPolicyLBVServerBinding{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.ContentInspectionPolicyLBVServerBinding{}, err + } + + var result struct { + Data []models.ContentInspectionPolicyLBVServerBinding `json:"contentinspectionpolicy_lbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.ContentInspectionPolicyLBVServerBinding{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.ContentInspectionPolicyLBVServerBinding{}, fmt.Errorf("contentinspectionpolicy_lbvserver_binding %s not found", name) + } + + return result.Data[0], nil +} + +// Struct lacks Count field, leaving for later +func (s *ContentInspectionService) CountContentInspectionPolcyLBVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", contentInspectionPolicyLBVServerBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"contentinspectionpolicy_lbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} // contentinspectionprofile -func (s *ContentInspectionService) AddContentInspectionProfile() {} -func (s *ContentInspectionService) DeleteContentInspectionProfile() {} -func (s *ContentInspectionService) UpdateContentInspectionProfile() {} -func (s *ContentInspectionService) UnsetContentInspectionProfile() {} -func (s *ContentInspectionService) GetAllContentInspectionProfile() {} -func (s *ContentInspectionService) GetContentInspectionProfile() {} -func (s *ContentInspectionService) CountContentInspectionProfile() {} +func (s *ContentInspectionService) AddContentInspectionProfile(resource models.ContentInspectionProfile) error { + payload := map[string]any{"contentinspectionprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, contentInspectionProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ContentInspectionService) DeleteContentInspectionProfile(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", contentInspectionProfileURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ContentInspectionService) UpdateContentInspectionProfile(resource models.ContentInspectionProfile) error { + payload := map[string]any{"contentinspectionprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, contentInspectionProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ContentInspectionService) UnsetContentInspectionProfile(resource models.ContentInspectionProfile) error { + payload := map[string]any{"contentinspectionprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", contentInspectionProfileURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ContentInspectionService) GetAllContentInspectionProfile() ([]models.ContentInspectionProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, contentInspectionProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.ContentInspectionProfile `json:"contentinspectionprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *ContentInspectionService) GetContentInspectionProfile(name string) (models.ContentInspectionProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", contentInspectionProfileURL, name), nil) + if err != nil { + return models.ContentInspectionProfile{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.ContentInspectionProfile{}, err + } + + var result struct { + Data []models.ContentInspectionProfile `json:"contentinspectionprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.ContentInspectionProfile{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.ContentInspectionProfile{}, fmt.Errorf("contentinspectionprofile %s not found", name) + } + + return result.Data[0], nil +} + +func (s *ContentInspectionService) CountContentInspectionProfile() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", contentInspectionProfileURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.ContentInspectionProfile `json:"contentinspectionprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} diff --git a/nitrogo/cr.go b/nitrogo/cr.go index a3784ce..8612195 100644 --- a/nitrogo/cr.go +++ b/nitrogo/cr.go @@ -1,155 +1,1895 @@ package nitrogo -// Cache redirection configuration. The cache redirection feature can transparently redirect cacheable HTTP -// requests to a cache and send non-cacheable or dynamic HTTP requests to the origin server. A cache stores -// or caches frequently requested web content and serves such web content to a client on behalf of the origin -// servers, alleviating the load on the origin server farm. +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + crActionURL = "/nitro/v1/config/craction" + crPolicyURL = "/nitro/v1/config/crpolicy" + crPolicyBindingURL = "/nitro/v1/config/crpolicy_binding" + crPolicyCRVServerBindingURL = "/nitro/v1/config/crpolicy_crvserver_binding" + crVServerURL = "/nitro/v1/config/crvserver" + crVServerAnalyticsProfileBindingURL = "/nitro/v1/config/crvserver_analyticsprofile_binding" + crVServerAppFlowPolicyBindingURL = "/nitro/v1/config/crvserver_appflowpolicy_binding" + crVServerAppFWPolicyBindingURL = "/nitro/v1/config/crvserver_appfwpolicy_binding" + crVServerAppQOEPolicyBindingURL = "/nitro/v1/config/crvserver_appqoepolicy_binding" + crVServerBindingURL = "/nitro/v1/config/crvserver_binding" + crVServerCachePolicyBindingURL = "/nitro/v1/config/crvserver_cachepolicy_binding" + crVServerCMPPolicyBindingURL = "/nitro/v1/config/crvserver_cmppolicy_binding" + crVServerCRPolicyBindingURL = "/nitro/v1/config/crvserver_crpolicy_binding" + crVServerCSPolicyBindingURL = "/nitro/v1/config/crvserver_cspolicy_binding" + crVServerFEOPolicyBindingURL = "/nitro/v1/config/crvserver_feopolicy_binding" + crVServerICAPolicyBindingURL = "/nitro/v1/config/crvserver_icapolicy_binding" + crVServerLBVServerBindingURL = "/nitro/v1/config/crvserver_lbvserver_binding" + crVServerPolicyMapBindingURL = "/nitro/v1/config/crvserver_policymap_binding" + crVServerResponderPolicyBindingURL = "/nitro/v1/config/crvserver_responderpolicy_binding" + crVServerRewritePolicyBindingURL = "/nitro/v1/config/crvserver_rewritepolicy_binding" + crVServerSpilloverPolicyBindingURL = "/nitro/v1/config/crvserver_spilloverpolicy_binding" +) + +// Cache redirection configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/cr/cr type CRService struct { client *Client } // craction -func (s *CRService) GetAllCRAction() {} -func (s *CRService) GetCRAction() {} -func (s *CRService) CountCRAction() {} +func (s *CRService) GetAllCRAction() ([]models.CRAction, error) { + req, err := s.client.NewRequest(http.MethodGet, crActionURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Actions []models.CRAction `json:"craction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Actions, nil +} + +func (s *CRService) GetCRAction(name string) ([]models.CRAction, error) { + reqURL := fmt.Sprintf("%s/%s", crActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Actions []models.CRAction `json:"craction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Actions, nil +} + +func (s *CRService) CountCRAction() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, crActionURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Actions []struct { + Count float64 `json:"__count"` + } `json:"craction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Actions) > 0 { + return result.Actions[0].Count, nil + } + return 0, nil +} // crpolicy -func (s *CRService) AddCRPolicy() {} -func (s *CRService) DeleteCRPolicy() {} -func (s *CRService) UpdateCRPolicy() {} -func (s *CRService) UnsetCRPolicy() {} -func (s *CRService) GetAllCRPolicy() {} -func (s *CRService) GetCRPolicy() {} -func (s *CRService) CountCRPolicy() {} -func (s *CRService) RenameCRPolicy() {} +func (s *CRService) AddCRPolicy(policy models.CRPolicy) error { + payload := map[string]any{"crpolicy": policy} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, crPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) DeleteCRPolicy(policyName string) error { + reqURL := fmt.Sprintf("%s/%s", crPolicyURL, url.QueryEscape(policyName)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) UpdateCRPolicy(policy models.CRPolicy) error { + payload := map[string]any{"crpolicy": policy} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, crPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) UnsetCRPolicy(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"crpolicy": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, crPolicyURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) RenameCRPolicy(name string, newName string) error { + payload := map[string]any{ + "crpolicy": map[string]string{ + "policyname": name, + "newname": newName, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, crPolicyURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) GetAllCRPolicy() ([]models.CRPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, crPolicyURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Policies []models.CRPolicy `json:"crpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Policies, nil +} + +func (s *CRService) GetCRPolicy(policyName string) ([]models.CRPolicy, error) { + reqURL := fmt.Sprintf("%s/%s", crPolicyURL, url.QueryEscape(policyName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Policies []models.CRPolicy `json:"crpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Policies, nil +} + +func (s *CRService) CountCRPolicy() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, crPolicyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Policies []struct { + Count float64 `json:"__count"` + } `json:"crpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Policies) > 0 { + return result.Policies[0].Count, nil + } + return 0, nil +} // crpolicy_binding -func (s *CRService) GetAllCRPolicyBinding() {} -func (s *CRService) GetCRPolicyBinding() {} +func (s *CRService) GetAllCRPolicyBinding() ([]models.CRPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, crPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRPolicyBinding `json:"crpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) GetCRPolicyBinding(policyName string) ([]models.CRPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", crPolicyBindingURL, url.QueryEscape(policyName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRPolicyBinding `json:"crpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // crpolicy_crvserver_binding -func (s *CRService) GetAllCRPolicyCRVServerBinding() {} -func (s *CRService) GetCRPolicyCRVServerBinding() {} -func (s *CRService) CountCRPolicyCRVServerBinding() {} +func (s *CRService) GetAllCRPolicyCRVServerBinding() ([]models.CRPolicyCRVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, crPolicyCRVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRPolicyCRVServerBinding `json:"crpolicy_crvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) GetCRPolicyCRVServerBinding(policyName string) ([]models.CRPolicyCRVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", crPolicyCRVServerBindingURL, url.QueryEscape(policyName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRPolicyCRVServerBinding `json:"crpolicy_crvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) CountCRPolicyCRVServerBinding(policyName string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", crPolicyCRVServerBindingURL, url.QueryEscape(policyName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"crpolicy_crvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // crvserver -func (s *CRService) AddCRVServer() {} -func (s *CRService) DeleteCRVServer() {} -func (s *CRService) UpdateCRVServer() {} -func (s *CRService) UnsetCRVServer() {} -func (s *CRService) EnableCRVServer() {} -func (s *CRService) DisableCRVServer() {} -func (s *CRService) GetAllCRVServer() {} -func (s *CRService) GetCRVServer() {} -func (s *CRService) CountCRVServer() {} -func (s *CRService) RenameCRVServer() {} +func (s *CRService) AddCRVServer(vserver models.CRVServer) error { + payload := map[string]any{"crvserver": vserver} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, crVServerURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) DeleteCRVServer(name string) error { + reqURL := fmt.Sprintf("%s/%s", crVServerURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) UpdateCRVServer(vserver models.CRVServer) error { + payload := map[string]any{"crvserver": vserver} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, crVServerURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) UnsetCRVServer(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"crvserver": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, crVServerURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) EnableCRVServer(name string) error { + payload := map[string]any{ + "crvserver": map[string]string{"name": name}, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, crVServerURL+"?action=enable", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) DisableCRVServer(name string) error { + payload := map[string]any{ + "crvserver": map[string]string{"name": name}, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, crVServerURL+"?action=disable", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) RenameCRVServer(name string, newName string) error { + payload := map[string]any{ + "crvserver": map[string]string{ + "name": name, + "newname": newName, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, crVServerURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) GetAllCRVServer() ([]models.CRVServer, error) { + req, err := s.client.NewRequest(http.MethodGet, crVServerURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + VServers []models.CRVServer `json:"crvserver"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.VServers, nil +} + +func (s *CRService) GetCRVServer(name string) ([]models.CRVServer, error) { + reqURL := fmt.Sprintf("%s/%s", crVServerURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + VServers []models.CRVServer `json:"crvserver"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.VServers, nil +} + +func (s *CRService) CountCRVServer() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, crVServerURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + VServers []struct { + Count float64 `json:"__count"` + } `json:"crvserver"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.VServers) > 0 { + return result.VServers[0].Count, nil + } + return 0, nil +} // crvserver_analyticsprofile_binding -func (s *CRService) AddCRVServerAnalyticsProfileBinding() {} -func (s *CRService) DeleteCRVServerAnalyticsProfileBinding() {} -func (s *CRService) GetAllCRVServerAnalyticsProfileBinding() {} -func (s *CRService) GetCRVServerAnalyticsProfileBinding() {} -func (s *CRService) CountCRVServerAnalyticsProfileBinding() {} +func (s *CRService) AddCRVServerAnalyticsProfileBinding(binding models.CRVServerAnalyticsProfileBinding) error { + payload := map[string]any{"crvserver_analyticsprofile_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, crVServerAnalyticsProfileBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) DeleteCRVServerAnalyticsProfileBinding(name string, analyticsProfile string) error { + reqURL := fmt.Sprintf("%s/%s?args=analyticsprofile:%s", crVServerAnalyticsProfileBindingURL, url.QueryEscape(name), url.QueryEscape(analyticsProfile)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) GetAllCRVServerAnalyticsProfileBinding() ([]models.CRVServerAnalyticsProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, crVServerAnalyticsProfileBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerAnalyticsProfileBinding `json:"crvserver_analyticsprofile_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) GetCRVServerAnalyticsProfileBinding(name string) ([]models.CRVServerAnalyticsProfileBinding, error) { + reqURL := fmt.Sprintf("%s/%s", crVServerAnalyticsProfileBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerAnalyticsProfileBinding `json:"crvserver_analyticsprofile_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) CountCRVServerAnalyticsProfileBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", crVServerAnalyticsProfileBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"crvserver_analyticsprofile_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // crvserver_appflowpolicy_binding -func (s *CRService) AddCRVServerAppFlowPolicyBinding() {} -func (s *CRService) DeleteCRVServerAppFlowPolicyBinding() {} -func (s *CRService) GetAllCRVServerAppFlowPolicyBinding() {} -func (s *CRService) GetCRVServerAppFlowPolicyBinding() {} -func (s *CRService) CountCRVServerAppFlowPolicyBinding() {} +func (s *CRService) AddCRVServerAppFlowPolicyBinding(binding models.CRVServerAppFlowPolicyBinding) error { + payload := map[string]any{"crvserver_appflowpolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, crVServerAppFlowPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) DeleteCRVServerAppFlowPolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", crVServerAppFlowPolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) GetAllCRVServerAppFlowPolicyBinding() ([]models.CRVServerAppFlowPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, crVServerAppFlowPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerAppFlowPolicyBinding `json:"crvserver_appflowpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) GetCRVServerAppFlowPolicyBinding(name string) ([]models.CRVServerAppFlowPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", crVServerAppFlowPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerAppFlowPolicyBinding `json:"crvserver_appflowpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) CountCRVServerAppFlowPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", crVServerAppFlowPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"crvserver_appflowpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // crvserver_appfwpolicy_binding -func (s *CRService) AddCRVServerAppFWPolicyBinding() {} -func (s *CRService) DeleteCRVServerAppFWPolicyBinding() {} -func (s *CRService) GetAllCRVServerAppFWPolicyBinding() {} -func (s *CRService) GetCRVServerAppFWPolicyBinding() {} -func (s *CRService) CountCRVServerAppFWPolicyBinding() {} +func (s *CRService) AddCRVServerAppFWPolicyBinding(binding models.CRVServerAppFWPolicyBinding) error { + payload := map[string]any{"crvserver_appfwpolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, crVServerAppFWPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) DeleteCRVServerAppFWPolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", crVServerAppFWPolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) GetAllCRVServerAppFWPolicyBinding() ([]models.CRVServerAppFWPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, crVServerAppFWPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerAppFWPolicyBinding `json:"crvserver_appfwpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) GetCRVServerAppFWPolicyBinding(name string) ([]models.CRVServerAppFWPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", crVServerAppFWPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerAppFWPolicyBinding `json:"crvserver_appfwpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) CountCRVServerAppFWPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", crVServerAppFWPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"crvserver_appfwpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // crvserver_appqoepolicy_binding -func (s *CRService) AddCRVServerAppQOEPolicyBinding() {} -func (s *CRService) DeleteCRVServerAppQOEPolicyBinding() {} -func (s *CRService) GetAllCRVServerAppQOEPolicyBinding() {} -func (s *CRService) GetCRVServerAppQOEPolicyBinding() {} -func (s *CRService) CountCRVServerAppQOEPolicyBinding() {} +func (s *CRService) AddCRVServerAppQOEPolicyBinding(binding models.CRVServerAppQOEPolicyBinding) error { + payload := map[string]any{"crvserver_appqoepolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, crVServerAppQOEPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) DeleteCRVServerAppQOEPolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", crVServerAppQOEPolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) GetAllCRVServerAppQOEPolicyBinding() ([]models.CRVServerAppQOEPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, crVServerAppQOEPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerAppQOEPolicyBinding `json:"crvserver_appqoepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) GetCRVServerAppQOEPolicyBinding(name string) ([]models.CRVServerAppQOEPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", crVServerAppQOEPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerAppQOEPolicyBinding `json:"crvserver_appqoepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) CountCRVServerAppQOEPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", crVServerAppQOEPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"crvserver_appqoepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // crvserver_binding -func (s *CRService) GetAllCRVServerBinding() {} -func (s *CRService) GetCRVServerBinding() {} +func (s *CRService) GetAllCRVServerBinding() ([]models.CRVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, crVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerBinding `json:"crvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) GetCRVServerBinding(name string) ([]models.CRVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", crVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerBinding `json:"crvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // crvserver_cachepolicy_binding -func (s *CRService) AddCRVServerCachePolicyBinding() {} -func (s *CRService) DeleteCRVServerCachePolicyBinding() {} -func (s *CRService) GetAllCRVServerCachePolicyBinding() {} -func (s *CRService) GetCRVServerCachePolicyBinding() {} -func (s *CRService) CountCRVServerCachePolicyBinding() {} +func (s *CRService) AddCRVServerCachePolicyBinding(binding models.CRVServerCachePolicyBinding) error { + payload := map[string]any{"crvserver_cachepolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, crVServerCachePolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) DeleteCRVServerCachePolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", crVServerCachePolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) GetAllCRVServerCachePolicyBinding() ([]models.CRVServerCachePolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, crVServerCachePolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerCachePolicyBinding `json:"crvserver_cachepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) GetCRVServerCachePolicyBinding(name string) ([]models.CRVServerCachePolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", crVServerCachePolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerCachePolicyBinding `json:"crvserver_cachepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) CountCRVServerCachePolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", crVServerCachePolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"crvserver_cachepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // crvserver_cmppolicy_binding -func (s *CRService) AddCRVServerCMPPolicyBinding() {} -func (s *CRService) DeleteCRVServerCMPPolicyBinding() {} -func (s *CRService) GetAllCRVServerCMPPolicyBinding() {} -func (s *CRService) GetCRVServerCMPPolicyBinding() {} -func (s *CRService) CountCRVServerCMPPolicyBinding() {} +func (s *CRService) AddCRVServerCMPPolicyBinding(binding models.CRVServerCMPPolicyBinding) error { + payload := map[string]any{"crvserver_cmppolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, crVServerCMPPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) DeleteCRVServerCMPPolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", crVServerCMPPolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) GetAllCRVServerCMPPolicyBinding() ([]models.CRVServerCMPPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, crVServerCMPPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerCMPPolicyBinding `json:"crvserver_cmppolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) GetCRVServerCMPPolicyBinding(name string) ([]models.CRVServerCMPPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", crVServerCMPPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerCMPPolicyBinding `json:"crvserver_cmppolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) CountCRVServerCMPPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", crVServerCMPPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"crvserver_cmppolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // crvserver_crpolicy_binding -func (s *CRService) AddCRVServerCRPolicyBinding() {} -func (s *CRService) DeleteCRVServerCRPolicyBinding() {} -func (s *CRService) GetAllCRVServerCRPolicyBinding() {} -func (s *CRService) GetCRVServerCRPolicyBinding() {} -func (s *CRService) CountCRVServerCRPolicyBinding() {} +func (s *CRService) AddCRVServerCRPolicyBinding(binding models.CRVServerCRPolicyBinding) error { + payload := map[string]any{"crvserver_crpolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, crVServerCRPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) DeleteCRVServerCRPolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", crVServerCRPolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) GetAllCRVServerCRPolicyBinding() ([]models.CRVServerCRPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, crVServerCRPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerCRPolicyBinding `json:"crvserver_crpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) GetCRVServerCRPolicyBinding(name string) ([]models.CRVServerCRPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", crVServerCRPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerCRPolicyBinding `json:"crvserver_crpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) CountCRVServerCRPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", crVServerCRPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"crvserver_crpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // crvserver_cspolicy_binding -func (s *CRService) AddCRVServerCSPolicyBinding() {} -func (s *CRService) DeleteCRVServerCSPolicyBinding() {} -func (s *CRService) GetAllCRVServerCSPolicyBinding() {} -func (s *CRService) GetCRVServerCSPolicyBinding() {} -func (s *CRService) CountCRVServerCSPolicyBinding() {} +func (s *CRService) AddCRVServerCSPolicyBinding(binding models.CRVServerCSPolicyBinding) error { + payload := map[string]any{"crvserver_cspolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, crVServerCSPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) DeleteCRVServerCSPolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", crVServerCSPolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) GetAllCRVServerCSPolicyBinding() ([]models.CRVServerCSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, crVServerCSPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerCSPolicyBinding `json:"crvserver_cspolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) GetCRVServerCSPolicyBinding(name string) ([]models.CRVServerCSPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", crVServerCSPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerCSPolicyBinding `json:"crvserver_cspolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) CountCRVServerCSPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", crVServerCSPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"crvserver_cspolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // crvserver_feopolicy_binding -func (s *CRService) AddCRVServerFEOPolicyBinding() {} -func (s *CRService) DeleteCRVServerFEOPolicyBinding() {} -func (s *CRService) GetAllCRVServerFEOPolicyBinding() {} -func (s *CRService) GetCRVServerFEOPolicyBinding() {} -func (s *CRService) CountCRVServerFEOPolicyBinding() {} +func (s *CRService) AddCRVServerFEOPolicyBinding(binding models.CRVServerFEOPolicyBinding) error { + payload := map[string]any{"crvserver_feopolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, crVServerFEOPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) DeleteCRVServerFEOPolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", crVServerFEOPolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) GetAllCRVServerFEOPolicyBinding() ([]models.CRVServerFEOPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, crVServerFEOPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerFEOPolicyBinding `json:"crvserver_feopolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) GetCRVServerFEOPolicyBinding(name string) ([]models.CRVServerFEOPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", crVServerFEOPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerFEOPolicyBinding `json:"crvserver_feopolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) CountCRVServerFEOPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", crVServerFEOPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"crvserver_feopolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // crvserver_icapolicy_binding -func (s *CRService) AddCRVServerICAPolicyBinding() {} -func (s *CRService) DeleteCRVServerICAPolicyBinding() {} -func (s *CRService) GetAllCRVServerICAPolicyBinding() {} -func (s *CRService) GetCRVServerICAPolicyBinding() {} -func (s *CRService) CountCRVServerICAPolicyBinding() {} +func (s *CRService) AddCRVServerICAPolicyBinding(binding models.CRVServerICAPolicyBinding) error { + payload := map[string]any{"crvserver_icapolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, crVServerICAPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) DeleteCRVServerICAPolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", crVServerICAPolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) GetAllCRVServerICAPolicyBinding() ([]models.CRVServerICAPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, crVServerICAPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerICAPolicyBinding `json:"crvserver_icapolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) GetCRVServerICAPolicyBinding(name string) ([]models.CRVServerICAPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", crVServerICAPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerICAPolicyBinding `json:"crvserver_icapolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) CountCRVServerICAPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", crVServerICAPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"crvserver_icapolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // crvserver_lbvserver_binding -func (s *CRService) AddCRVServerLBVServerBinding() {} -func (s *CRService) DeleteCRVServerLBVServerBinding() {} -func (s *CRService) GetAllCRVServerLBVServerBinding() {} -func (s *CRService) GetCRVServerLBVServerBinding() {} -func (s *CRService) CountCRVServerLBVServerBinding() {} +func (s *CRService) AddCRVServerLBVServerBinding(binding models.CRVServerLBVServerBinding) error { + payload := map[string]any{"crvserver_lbvserver_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, crVServerLBVServerBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) DeleteCRVServerLBVServerBinding(name string, lbvserver string) error { + reqURL := fmt.Sprintf("%s/%s?args=lbvserver:%s", crVServerLBVServerBindingURL, url.QueryEscape(name), url.QueryEscape(lbvserver)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) GetAllCRVServerLBVServerBinding() ([]models.CRVServerLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, crVServerLBVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerLBVServerBinding `json:"crvserver_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) GetCRVServerLBVServerBinding(name string) ([]models.CRVServerLBVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", crVServerLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerLBVServerBinding `json:"crvserver_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) CountCRVServerLBVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", crVServerLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"crvserver_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // crvserver_policymap_binding -func (s *CRService) AddCRVServerPolicyMapBinding() {} -func (s *CRService) DeleteCRVServerPolicyMapBinding() {} -func (s *CRService) GetAllCRVServerPolicyMapBinding() {} -func (s *CRService) GetCRVServerPolicyMapBinding() {} -func (s *CRService) CountCRVServerPolicyMapBinding() {} +func (s *CRService) AddCRVServerPolicyMapBinding(binding models.CRVServerPolicyMapBinding) error { + payload := map[string]any{"crvserver_policymap_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, crVServerPolicyMapBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) DeleteCRVServerPolicyMapBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", crVServerPolicyMapBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) GetAllCRVServerPolicyMapBinding() ([]models.CRVServerPolicyMapBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, crVServerPolicyMapBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerPolicyMapBinding `json:"crvserver_policymap_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) GetCRVServerPolicyMapBinding(name string) ([]models.CRVServerPolicyMapBinding, error) { + reqURL := fmt.Sprintf("%s/%s", crVServerPolicyMapBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerPolicyMapBinding `json:"crvserver_policymap_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) CountCRVServerPolicyMapBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", crVServerPolicyMapBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"crvserver_policymap_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // crvserver_responderpolicy_binding -func (s *CRService) AddCRVServerResponderPolicyBinding() {} -func (s *CRService) DeleteCRVServerResponderPolicyBinding() {} -func (s *CRService) GetAllCRVServerResponderPolicyBinding() {} -func (s *CRService) GetCRVServerResponderPolicyBinding() {} -func (s *CRService) CountCRVServerResponderPolicyBinding() {} +func (s *CRService) AddCRVServerResponderPolicyBinding(binding models.CRVServerResponderPolicyBinding) error { + payload := map[string]any{"crvserver_responderpolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, crVServerResponderPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) DeleteCRVServerResponderPolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", crVServerResponderPolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) GetAllCRVServerResponderPolicyBinding() ([]models.CRVServerResponderPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, crVServerResponderPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerResponderPolicyBinding `json:"crvserver_responderpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) GetCRVServerResponderPolicyBinding(name string) ([]models.CRVServerResponderPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", crVServerResponderPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerResponderPolicyBinding `json:"crvserver_responderpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) CountCRVServerResponderPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", crVServerResponderPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"crvserver_responderpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // crvserver_rewritepolicy_binding -func (s *CRService) AddCRVServerRewritePolcyBinding() {} -func (s *CRService) DeleteCRVServerRewritePolcyBinding() {} -func (s *CRService) GetAllCRVServerRewritePolcyBinding() {} -func (s *CRService) GetCRVServerRewritePolcyBinding() {} -func (s *CRService) CountCRVServerRewritePolcyBinding() {} +func (s *CRService) AddCRVServerRewritePolicyBinding(binding models.CRVServerRewritePolicyBinding) error { + payload := map[string]any{"crvserver_rewritepolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, crVServerRewritePolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) DeleteCRVServerRewritePolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", crVServerRewritePolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) GetAllCRVServerRewritePolicyBinding() ([]models.CRVServerRewritePolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, crVServerRewritePolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerRewritePolicyBinding `json:"crvserver_rewritepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) GetCRVServerRewritePolicyBinding(name string) ([]models.CRVServerRewritePolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", crVServerRewritePolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerRewritePolicyBinding `json:"crvserver_rewritepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) CountCRVServerRewritePolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", crVServerRewritePolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"crvserver_rewritepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // crvserver_spilloverpolicy_binding -func (s *CRService) AddCRVServerSpilloverPolicyBinding() {} -func (s *CRService) DeleteCRVServerSpilloverPolicyBinding() {} -func (s *CRService) GetAllCRVServerSpilloverPolicyBinding() {} -func (s *CRService) GetCRVServerSpilloverPolicyBinding() {} -func (s *CRService) CountCRVServerSpilloverPolicyBinding() {} +func (s *CRService) AddCRVServerSpilloverPolicyBinding(binding models.CRVServerSpilloverPolicyBinding) error { + payload := map[string]any{"crvserver_spilloverpolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, crVServerSpilloverPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) DeleteCRVServerSpilloverPolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", crVServerSpilloverPolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CRService) GetAllCRVServerSpilloverPolicyBinding() ([]models.CRVServerSpilloverPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, crVServerSpilloverPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerSpilloverPolicyBinding `json:"crvserver_spilloverpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) GetCRVServerSpilloverPolicyBinding(name string) ([]models.CRVServerSpilloverPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", crVServerSpilloverPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CRVServerSpilloverPolicyBinding `json:"crvserver_spilloverpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CRService) CountCRVServerSpilloverPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", crVServerSpilloverPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"crvserver_spilloverpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} diff --git a/nitrogo/cs.go b/nitrogo/cs.go index 80a9e8a..7f687d5 100644 --- a/nitrogo/cs.go +++ b/nitrogo/cs.go @@ -1,240 +1,3027 @@ package nitrogo -// Content Switching configuration. Content Switching feature that enables you to direct traffic to servers on the basis of content. +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + csActionURL = "/nitro/v1/config/csaction" + csParameterURL = "/nitro/v1/config/csparameter" + csPolicyURL = "/nitro/v1/config/cspolicy" + csPolicyLabelURL = "/nitro/v1/config/cspolicylabel" + csPolicyLabelBindingURL = "/nitro/v1/config/cspolicylabel_binding" + csPolicyLabelCSPolicyBindingURL = "/nitro/v1/config/cspolicylabel_cspolicy_binding" + csPolicyBindingURL = "/nitro/v1/config/cspolicy_binding" + csPolicyCRVServerBindingURL = "/nitro/v1/config/cspolicy_crvserver_binding" + csPolicyCSPolicyLabelBindingURL = "/nitro/v1/config/cspolicy_cspolicylabel_binding" + csPolicyCSVServerBindingURL = "/nitro/v1/config/cspolicy_csvserver_binding" + csVServerURL = "/nitro/v1/config/csvserver" + csVServerAnalyticsProfileBindingURL = "/nitro/v1/config/csvserver_analyticsprofile_binding" + csVServerAppFlowPolicyBindingURL = "/nitro/v1/config/csvserver_appflowpolicy_binding" + csVServerAppFWPolicyBindingURL = "/nitro/v1/config/csvserver_appfwpolicy_binding" + csVServerAppQOEPolicyBindingURL = "/nitro/v1/config/csvserver_appqoepolicy_binding" + csVServerAuditNSLogPolicyBindingURL = "/nitro/v1/config/csvserver_auditnslogpolicy_binding" + csVServerAuditSyslogPolicyBindingURL = "/nitro/v1/config/csvserver_auditsyslogpolicy_binding" + csVServerAuthorizationPolicyBindingURL = "/nitro/v1/config/csvserver_authorizationpolicy_binding" + csVServerBindingURL = "/nitro/v1/config/csvserver_binding" + csVServerBotPolicyBindingURL = "/nitro/v1/config/csvserver_botpolicy_binding" + csVServerCachePolicyBindingURL = "/nitro/v1/config/csvserver_cachepolicy_binding" + csVServerCMPPolicyBindingURL = "/nitro/v1/config/csvserver_cmppolicy_binding" + csVServerContentInspectionPolicyBindingURL = "/nitro/v1/config/csvserver_contentinspectionpolicy_binding" + csVServerCSPolicyBindingURL = "/nitro/v1/config/csvserver_cspolicy_binding" + csVServerDomainBindingURL = "/nitro/v1/config/csvserver_domain_binding" + csVServerFEOPolicyBindingURL = "/nitro/v1/config/csvserver_feopolicy_binding" + csVServerGSLBVServerBindingURL = "/nitro/v1/config/csvserver_gslbvserver_binding" + csVServerLBVServerBindingURL = "/nitro/v1/config/csvserver_lbvserver_binding" + csVServerResponderPolicyBindingURL = "/nitro/v1/config/csvserver_responderpolicy_binding" + csVServerRewritePolicyBindingURL = "/nitro/v1/config/csvserver_rewritepolicy_binding" + csVServerSpilloverPolicyBindingURL = "/nitro/v1/config/csvserver_spilloverpolicy_binding" + csVServerTMTrafficPolicyBindingURL = "/nitro/v1/config/csvserver_tmtrafficpolicy_binding" + csVServerTransformPolicyBindingURL = "/nitro/v1/config/csvserver_transformpolicy_binding" + csVServerVPNVServerBindingURL = "/nitro/v1/config/csvserver_vpnvserver_binding" +) + +// Content Switching configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/cs/cs type CSService struct { client *Client } // csaction -func (s *CSService) AddCSAction() {} -func (s *CSService) DeleteCSAction() {} -func (s *CSService) UpdateCSAction() {} -func (s *CSService) UnsetCSAction() {} -func (s *CSService) GetAllCSAction() {} -func (s *CSService) GetCSAction() {} -func (s *CSService) CountCSAction() {} -func (s *CSService) RenameCSAction() {} +func (s *CSService) AddCSAction(action models.CSAction) error { + payload := map[string]any{"csaction": action} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, csActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DeleteCSAction(name string) error { + reqURL := fmt.Sprintf("%s/%s", csActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) UpdateCSAction(action models.CSAction) error { + payload := map[string]any{"csaction": action} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, csActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) UnsetCSAction(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"csaction": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, csActionURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) RenameCSAction(name string, newName string) error { + payload := map[string]any{ + "csaction": map[string]string{ + "name": name, + "newname": newName, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, csActionURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSAction() ([]models.CSAction, error) { + req, err := s.client.NewRequest(http.MethodGet, csActionURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Actions []models.CSAction `json:"csaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Actions, nil +} + +func (s *CSService) GetCSAction(name string) ([]models.CSAction, error) { + reqURL := fmt.Sprintf("%s/%s", csActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Actions []models.CSAction `json:"csaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Actions, nil +} + +func (s *CSService) CountCSAction() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, csActionURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Actions []struct { + Count float64 `json:"__count"` + } `json:"csaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Actions) > 0 { + return result.Actions[0].Count, nil + } + return 0, nil +} // csparameter -func (s *CSService) UpdateCSParameter() {} -func (s *CSService) UnsetCSParameter() {} -func (s *CSService) GetAllCSParameter() {} +func (s *CSService) UpdateCSParameter(param models.CSParameter) error { + payload := map[string]any{"csparameter": param} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, csParameterURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) UnsetCSParameter(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"csparameter": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, csParameterURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSParameter() (models.CSParameter, error) { + req, err := s.client.NewRequest(http.MethodGet, csParameterURL, nil) + if err != nil { + return models.CSParameter{}, err + } + resp, err := s.client.Do(req) + if err != nil { + return models.CSParameter{}, err + } + var result struct { + Params []models.CSParameter `json:"csparameter"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return models.CSParameter{}, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Params) > 0 { + return result.Params[0], nil + } + return models.CSParameter{}, nil +} // cspolicy -func (s *CSService) AddCSPolicy() {} -func (s *CSService) DeleteCSPolicy() {} -func (s *CSService) UpdateCSPolicy() {} -func (s *CSService) UnsetCSPolicy() {} -func (s *CSService) GetAllCSPolicy() {} -func (s *CSService) GetCSPolicy() {} -func (s *CSService) CountCSPolicy() {} -func (s *CSService) RenameCSPolicy() {} +func (s *CSService) AddCSPolicy(policy models.CSPolicy) error { + payload := map[string]any{"cspolicy": policy} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, csPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DeleteCSPolicy(policyName string) error { + reqURL := fmt.Sprintf("%s/%s", csPolicyURL, url.QueryEscape(policyName)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) UpdateCSPolicy(policy models.CSPolicy) error { + payload := map[string]any{"cspolicy": policy} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, csPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) UnsetCSPolicy(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"cspolicy": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, csPolicyURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) RenameCSPolicy(policyName string, newName string) error { + payload := map[string]any{ + "cspolicy": map[string]string{ + "policyname": policyName, + "newname": newName, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, csPolicyURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSPolicy() ([]models.CSPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, csPolicyURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Policies []models.CSPolicy `json:"cspolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Policies, nil +} + +func (s *CSService) GetCSPolicy(policyName string) ([]models.CSPolicy, error) { + reqURL := fmt.Sprintf("%s/%s", csPolicyURL, url.QueryEscape(policyName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Policies []models.CSPolicy `json:"cspolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Policies, nil +} + +func (s *CSService) CountCSPolicy() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, csPolicyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Policies []struct { + Count float64 `json:"__count"` + } `json:"cspolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Policies) > 0 { + return result.Policies[0].Count, nil + } + return 0, nil +} // cspolicylabel -func (s *CSService) AddCSPolicyLabel() {} -func (s *CSService) DeleteCSPolicyLabel() {} -func (s *CSService) GetAllCSPolicyLabel() {} -func (s *CSService) GetCSPolicyLabel() {} -func (s *CSService) CountCSPolicyLabel() {} -func (s *CSService) RenameCSPolicyLabel() {} +func (s *CSService) AddCSPolicyLabel(label models.CSPolicyLabel) error { + payload := map[string]any{"cspolicylabel": label} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, csPolicyLabelURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DeleteCSPolicyLabel(labelName string) error { + reqURL := fmt.Sprintf("%s/%s", csPolicyLabelURL, url.QueryEscape(labelName)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) RenameCSPolicyLabel(labelName string, newName string) error { + payload := map[string]any{ + "cspolicylabel": map[string]string{ + "labelname": labelName, + "newname": newName, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, csPolicyLabelURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSPolicyLabel() ([]models.CSPolicyLabel, error) { + req, err := s.client.NewRequest(http.MethodGet, csPolicyLabelURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Labels []models.CSPolicyLabel `json:"cspolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Labels, nil +} + +func (s *CSService) GetCSPolicyLabel(labelName string) ([]models.CSPolicyLabel, error) { + reqURL := fmt.Sprintf("%s/%s", csPolicyLabelURL, url.QueryEscape(labelName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Labels []models.CSPolicyLabel `json:"cspolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Labels, nil +} + +func (s *CSService) CountCSPolicyLabel() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, csPolicyLabelURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Labels []struct { + Count float64 `json:"__count"` + } `json:"cspolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Labels) > 0 { + return result.Labels[0].Count, nil + } + return 0, nil +} // cspolicylabel_binding -func (s *CSService) GetAllCSPolicyLabelBinding() {} -func (s *CSService) GetCSPolicyLabelBinding() {} +func (s *CSService) GetAllCSPolicyLabelBinding() ([]models.CSPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csPolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSPolicyLabelBinding `json:"cspolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSPolicyLabelBinding(labelName string) ([]models.CSPolicyLabelBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csPolicyLabelBindingURL, url.QueryEscape(labelName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSPolicyLabelBinding `json:"cspolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // cspolicylabel_cspolicy_binding -func (s *CSService) AddCSPolicyLabelCSPolicyBinding() {} -func (s *CSService) DeleteCSPolicyLabelCSPolicyBinding() {} -func (s *CSService) GetAllCSPolicyLabelCSPolicyBinding() {} -func (s *CSService) GetCSPolicyLabelCSPolicyBinding() {} -func (s *CSService) CountCSPolicyLabelCSPolicyBinding() {} +func (s *CSService) AddCSPolicyLabelCSPolicyBinding(binding models.CSPolicyLabelCSPolicyBinding) error { + payload := map[string]any{"cspolicylabel_cspolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, csPolicyLabelCSPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DeleteCSPolicyLabelCSPolicyBinding(labelName string, policyName string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,priority:%d", csPolicyLabelCSPolicyBindingURL, url.QueryEscape(labelName), url.QueryEscape(policyName), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSPolicyLabelCSPolicyBinding() ([]models.CSPolicyLabelCSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csPolicyLabelCSPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSPolicyLabelCSPolicyBinding `json:"cspolicylabel_cspolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSPolicyLabelCSPolicyBinding(labelName string) ([]models.CSPolicyLabelCSPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csPolicyLabelCSPolicyBindingURL, url.QueryEscape(labelName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSPolicyLabelCSPolicyBinding `json:"cspolicylabel_cspolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) CountCSPolicyLabelCSPolicyBinding(labelName string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", csPolicyLabelCSPolicyBindingURL, url.QueryEscape(labelName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"cspolicylabel_cspolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // cspolicy_binding -func (s *CSService) GetAllCSPolicyBinding() {} -func (s *CSService) GetCSPolicyBinding() {} +func (s *CSService) GetAllCSPolicyBinding() ([]models.CSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSPolicyBinding `json:"cspolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSPolicyBinding(policyName string) ([]models.CSPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csPolicyBindingURL, url.QueryEscape(policyName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSPolicyBinding `json:"cspolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // cspolicy_crvserver_binding -func (s *CSService) GetAllCSPolicyCRVServerBinding() {} -func (s *CSService) GetCSPolicyCRVServerBinding() {} -func (s *CSService) CountCSPolicyCRVServerBinding() {} +func (s *CSService) GetAllCSPolicyCRVServerBinding() ([]models.CSPolicyCRVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csPolicyCRVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSPolicyCRVServerBinding `json:"cspolicy_crvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSPolicyCRVServerBinding(policyName string) ([]models.CSPolicyCRVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csPolicyCRVServerBindingURL, url.QueryEscape(policyName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSPolicyCRVServerBinding `json:"cspolicy_crvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) CountCSPolicyCRVServerBinding(policyName string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", csPolicyCRVServerBindingURL, url.QueryEscape(policyName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"cspolicy_crvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // cspolicy_cspolicylabel_binding -func (s *CSService) GetAllCSPolicyCSPolicyLabelBinding() {} -func (s *CSService) GetCSPolicyCSPolicyLabelBinding() {} -func (s *CSService) CountCSPolicyCSPolicyLabelBinding() {} +func (s *CSService) GetAllCSPolicyCSPolicyLabelBinding() ([]models.CSPolicyCSPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csPolicyCSPolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSPolicyCSPolicyLabelBinding `json:"cspolicy_cspolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSPolicyCSPolicyLabelBinding(policyName string) ([]models.CSPolicyCSPolicyLabelBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csPolicyCSPolicyLabelBindingURL, url.QueryEscape(policyName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSPolicyCSPolicyLabelBinding `json:"cspolicy_cspolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) CountCSPolicyCSPolicyLabelBinding(policyName string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", csPolicyCSPolicyLabelBindingURL, url.QueryEscape(policyName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"cspolicy_cspolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // cspolicy_csvserver_binding -func (s *CSService) GetAllCSPolicyCSVServerBinding() {} -func (s *CSService) GetCSPolicyCSVServerBinding() {} -func (s *CSService) CountCSPolicyCSVServerBinding() {} +func (s *CSService) GetAllCSPolicyCSVServerBinding() ([]models.CSPolicyCSVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csPolicyCSVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSPolicyCSVServerBinding `json:"cspolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSPolicyCSVServerBinding(policyName string) ([]models.CSPolicyCSVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csPolicyCSVServerBindingURL, url.QueryEscape(policyName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSPolicyCSVServerBinding `json:"cspolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) CountCSPolicyCSVServerBinding(policyName string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", csPolicyCSVServerBindingURL, url.QueryEscape(policyName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"cspolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // csvserver -func (s *CSService) AddCSVServer() {} -func (s *CSService) DeleteCSVServer() {} -func (s *CSService) UpdateCSVServer() {} -func (s *CSService) UnsetCSVServer() {} -func (s *CSService) EnableCSVServer() {} -func (s *CSService) DisableCSVServer() {} -func (s *CSService) GetAllCSVServer() {} -func (s *CSService) GetCSVServer() {} -func (s *CSService) CountCSVServer() {} -func (s *CSService) RenameCSVServer() {} +func (s *CSService) AddCSVServer(vserver models.CSVServer) error { + payload := map[string]any{"csvserver": vserver} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, csVServerURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DeleteCSVServer(name string) error { + reqURL := fmt.Sprintf("%s/%s", csVServerURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) UpdateCSVServer(vserver models.CSVServer) error { + payload := map[string]any{"csvserver": vserver} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, csVServerURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) UnsetCSVServer(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"csvserver": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, csVServerURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) EnableCSVServer(name string) error { + payload := map[string]any{ + "csvserver": map[string]string{"name": name}, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, csVServerURL+"?action=enable", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DisableCSVServer(name string) error { + payload := map[string]any{ + "csvserver": map[string]string{"name": name}, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, csVServerURL+"?action=disable", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) RenameCSVServer(name string, newName string) error { + payload := map[string]any{ + "csvserver": map[string]string{ + "name": name, + "newname": newName, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, csVServerURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSVServer() ([]models.CSVServer, error) { + req, err := s.client.NewRequest(http.MethodGet, csVServerURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + VServers []models.CSVServer `json:"csvserver"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.VServers, nil +} + +func (s *CSService) GetCSVServer(name string) ([]models.CSVServer, error) { + reqURL := fmt.Sprintf("%s/%s", csVServerURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + VServers []models.CSVServer `json:"csvserver"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.VServers, nil +} + +func (s *CSService) CountCSVServer() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, csVServerURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + VServers []struct { + Count float64 `json:"__count"` + } `json:"csvserver"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.VServers) > 0 { + return result.VServers[0].Count, nil + } + return 0, nil +} // csvserver_analyticsprofile_binding -func (s *CSService) AddCSVServerAnalyticsProfileBinding() {} -func (s *CSService) DeleteCSVServerAnalyticsProfileBinding() {} -func (s *CSService) GetAllCSVServerAnalyticsProfileBinding() {} -func (s *CSService) GetCSVServerAnalyticsProfileBinding() {} -func (s *CSService) CountCSVServerAnalyticsProfileBinding() {} +func (s *CSService) AddCSVServerAnalyticsProfileBinding(binding models.CSVServerAnalyticsProfileBinding) error { + payload := map[string]any{"csvserver_analyticsprofile_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, csVServerAnalyticsProfileBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DeleteCSVServerAnalyticsProfileBinding(name string, analyticsProfile string) error { + reqURL := fmt.Sprintf("%s/%s?args=analyticsprofile:%s", csVServerAnalyticsProfileBindingURL, url.QueryEscape(name), url.QueryEscape(analyticsProfile)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSVServerAnalyticsProfileBinding() ([]models.CSVServerAnalyticsProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csVServerAnalyticsProfileBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerAnalyticsProfileBinding `json:"csvserver_analyticsprofile_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSVServerAnalyticsProfileBinding(name string) ([]models.CSVServerAnalyticsProfileBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csVServerAnalyticsProfileBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerAnalyticsProfileBinding `json:"csvserver_analyticsprofile_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) CountCSVServerAnalyticsProfileBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", csVServerAnalyticsProfileBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"csvserver_analyticsprofile_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // csvserver_appflowpolicy_binding -func (s *CSService) AddCSVServerAppFlowPolicyBinding() {} -func (s *CSService) DeleteCSVServerAppFlowPolicyBinding() {} -func (s *CSService) GetAllCSVServerAppFlowPolicyBinding() {} -func (s *CSService) GetCSVServerAppFlowPolicyBinding() {} -func (s *CSService) CountCSVServerAppFlowPolicyBinding() {} +func (s *CSService) AddCSVServerAppFlowPolicyBinding(binding models.CSVServerAppFlowPolicyBinding) error { + payload := map[string]any{"csvserver_appflowpolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, csVServerAppFlowPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DeleteCSVServerAppFlowPolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", csVServerAppFlowPolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSVServerAppFlowPolicyBinding() ([]models.CSVServerAppFlowPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csVServerAppFlowPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerAppFlowPolicyBinding `json:"csvserver_appflowpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSVServerAppFlowPolicyBinding(name string) ([]models.CSVServerAppFlowPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csVServerAppFlowPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerAppFlowPolicyBinding `json:"csvserver_appflowpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) CountCSVServerAppFlowPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", csVServerAppFlowPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"csvserver_appflowpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // csvserver_appfwpolicy_binding -func (s *CSService) AddCSVServerAppFWPolicyBinding() {} -func (s *CSService) DeleteCSVServerAppFWPolicyBinding() {} -func (s *CSService) GetAllCSVServerAppFWPolicyBinding() {} -func (s *CSService) GetCSVServerAppFWPolicyBinding() {} -func (s *CSService) CountCSVServerAppFWPolicyBinding() {} +func (s *CSService) AddCSVServerAppFWPolicyBinding(binding models.CSVServerAppFWPolicyBinding) error { + payload := map[string]any{"csvserver_appfwpolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, csVServerAppFWPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DeleteCSVServerAppFWPolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", csVServerAppFWPolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSVServerAppFWPolicyBinding() ([]models.CSVServerAppFWPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csVServerAppFWPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerAppFWPolicyBinding `json:"csvserver_appfwpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSVServerAppFWPolicyBinding(name string) ([]models.CSVServerAppFWPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csVServerAppFWPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerAppFWPolicyBinding `json:"csvserver_appfwpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) CountCSVServerAppFWPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", csVServerAppFWPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"csvserver_appfwpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // csvserver_appqoepolicy_binding -func (s *CSService) AddCSVServerAppQOEPolicyBinding() {} -func (s *CSService) DeleteCSVServerAppQOEPolicyBinding() {} -func (s *CSService) GetAllCSVServerAppQOEPolicyBinding() {} -func (s *CSService) GetCSVServerAppQOEPolicyBinding() {} -func (s *CSService) CountCSVServerAppQOEPolicyBinding() {} +func (s *CSService) AddCSVServerAppQOEPolicyBinding(binding models.CSVServerAppQOEPolicyBinding) error { + payload := map[string]any{"csvserver_appqoepolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, csVServerAppQOEPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DeleteCSVServerAppQOEPolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", csVServerAppQOEPolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSVServerAppQOEPolicyBinding() ([]models.CSVServerAppQOEPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csVServerAppQOEPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerAppQOEPolicyBinding `json:"csvserver_appqoepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSVServerAppQOEPolicyBinding(name string) ([]models.CSVServerAppQOEPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csVServerAppQOEPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerAppQOEPolicyBinding `json:"csvserver_appqoepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) CountCSVServerAppQOEPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", csVServerAppQOEPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"csvserver_appqoepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // csvserver_auditnslogpolicy_binding -func (s *CSService) AddCSVServerAuditNSLogPolicyBinding() {} -func (s *CSService) DeleteCSVServerAuditNSLogPolicyBinding() {} -func (s *CSService) GetAllCSVServerAuditNSLogPolicyBinding() {} -func (s *CSService) GetCSVServerAuditNSLogPolicyBinding() {} -func (s *CSService) CountCSVServerAuditNSLogPolicyBinding() {} +func (s *CSService) AddCSVServerAuditNSLogPolicyBinding(binding models.CSVServerAuditNSLogPolicyBinding) error { + payload := map[string]any{"csvserver_auditnslogpolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, csVServerAuditNSLogPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DeleteCSVServerAuditNSLogPolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", csVServerAuditNSLogPolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSVServerAuditNSLogPolicyBinding() ([]models.CSVServerAuditNSLogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csVServerAuditNSLogPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerAuditNSLogPolicyBinding `json:"csvserver_auditnslogpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSVServerAuditNSLogPolicyBinding(name string) ([]models.CSVServerAuditNSLogPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csVServerAuditNSLogPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerAuditNSLogPolicyBinding `json:"csvserver_auditnslogpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) CountCSVServerAuditNSLogPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", csVServerAuditNSLogPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"csvserver_auditnslogpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // csvserver_auditsyslogpolicy_binding -func (s *CSService) AddCSVServerAuditSyslogPolicyBinding() {} -func (s *CSService) DeleteCSVServerAuditSyslogPolicyBinding() {} -func (s *CSService) GetAllCSVServerAuditSyslogPolicyBinding() {} -func (s *CSService) GetCSVServerAuditSyslogPolicyBinding() {} -func (s *CSService) CountCSVServerAuditSyslogPolicyBinding() {} +func (s *CSService) AddCSVServerAuditSyslogPolicyBinding(binding models.CSVServerAuditSyslogPolicyBinding) error { + payload := map[string]any{"csvserver_auditsyslogpolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, csVServerAuditSyslogPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DeleteCSVServerAuditSyslogPolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", csVServerAuditSyslogPolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSVServerAuditSyslogPolicyBinding() ([]models.CSVServerAuditSyslogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csVServerAuditSyslogPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerAuditSyslogPolicyBinding `json:"csvserver_auditsyslogpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSVServerAuditSyslogPolicyBinding(name string) ([]models.CSVServerAuditSyslogPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csVServerAuditSyslogPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerAuditSyslogPolicyBinding `json:"csvserver_auditsyslogpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) CountCSVServerAuditSyslogPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", csVServerAuditSyslogPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"csvserver_auditsyslogpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // csvserver_authorizationpolicy_binding -func (s *CSService) AddCSVServerAuthorizationPolicyBinding() {} -func (s *CSService) DeleteCSVServerAuthorizationPolicyBinding() {} -func (s *CSService) GetAllCSVServerAuthorizationPolicyBinding() {} -func (s *CSService) GetCSVServerAuthorizationPolicyBinding() {} -func (s *CSService) CountCSVServerAuthorizationPolicyBinding() {} +func (s *CSService) AddCSVServerAuthorizationPolicyBinding(binding models.CSVServerAuthorizationPolicyBinding) error { + payload := map[string]any{"csvserver_authorizationpolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, csVServerAuthorizationPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DeleteCSVServerAuthorizationPolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", csVServerAuthorizationPolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSVServerAuthorizationPolicyBinding() ([]models.CSVServerAuthorizationPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csVServerAuthorizationPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerAuthorizationPolicyBinding `json:"csvserver_authorizationpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSVServerAuthorizationPolicyBinding(name string) ([]models.CSVServerAuthorizationPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csVServerAuthorizationPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerAuthorizationPolicyBinding `json:"csvserver_authorizationpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) CountCSVServerAuthorizationPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", csVServerAuthorizationPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"csvserver_authorizationpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // csvserver_binding -func (s *CSService) GetAllCSVServerBinding() {} -func (s *CSService) GetCSVServerBinding() {} +func (s *CSService) GetAllCSVServerBinding() ([]models.CSVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerBinding `json:"csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSVServerBinding(name string) ([]models.CSVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerBinding `json:"csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // csvserver_botpolicy_binding -func (s *CSService) AddCSVServerBotPolicyBinding() {} -func (s *CSService) DeleteCSVServerBotPolicyBinding() {} -func (s *CSService) GetAllCSVServerBotPolicyBinding() {} -func (s *CSService) GetCSVServerBotPolicyBinding() {} -func (s *CSService) CountCSVServerBotPolicyBinding() {} +func (s *CSService) AddCSVServerBotPolicyBinding(binding models.CSVServerBotPolicyBinding) error { + payload := map[string]any{"csvserver_botpolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, csVServerBotPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DeleteCSVServerBotPolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", csVServerBotPolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSVServerBotPolicyBinding() ([]models.CSVServerBotPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csVServerBotPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerBotPolicyBinding `json:"csvserver_botpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSVServerBotPolicyBinding(name string) ([]models.CSVServerBotPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csVServerBotPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerBotPolicyBinding `json:"csvserver_botpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) CountCSVServerBotPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", csVServerBotPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"csvserver_botpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // csvserver_cachepolicy_binding -func (s *CSService) AddCSVServerCachePolicyBinding() {} -func (s *CSService) DeleteCSVServerCachePolicyBinding() {} -func (s *CSService) GetAllCSVServerCachePolicyBinding() {} -func (s *CSService) GetCSVServerCachePolicyBinding() {} -func (s *CSService) CountCSVServerCachePolicyBinding() {} +func (s *CSService) AddCSVServerCachePolicyBinding(binding models.CSVServerCachePolicyBinding) error { + payload := map[string]any{"csvserver_cachepolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, csVServerCachePolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DeleteCSVServerCachePolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", csVServerCachePolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSVServerCachePolicyBinding() ([]models.CSVServerCachePolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csVServerCachePolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerCachePolicyBinding `json:"csvserver_cachepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSVServerCachePolicyBinding(name string) ([]models.CSVServerCachePolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csVServerCachePolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerCachePolicyBinding `json:"csvserver_cachepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) CountCSVServerCachePolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", csVServerCachePolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"csvserver_cachepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // csvserver_cmppolicy_binding -func (s *CSService) AddCSVServerCMPPolicyBinding() {} -func (s *CSService) DeleteCSVServerCMPPolicyBinding() {} -func (s *CSService) GetAllCSVServerCMPPolicyBinding() {} -func (s *CSService) GetCSVServerCMPPolicyBinding() {} -func (s *CSService) CountCSVServerCMPPolicyBinding() {} +func (s *CSService) AddCSVServerCMPPolicyBinding(binding models.CSVServerCMPPolicyBinding) error { + payload := map[string]any{"csvserver_cmppolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, csVServerCMPPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DeleteCSVServerCMPPolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", csVServerCMPPolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSVServerCMPPolicyBinding() ([]models.CSVServerCMPPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csVServerCMPPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerCMPPolicyBinding `json:"csvserver_cmppolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSVServerCMPPolicyBinding(name string) ([]models.CSVServerCMPPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csVServerCMPPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerCMPPolicyBinding `json:"csvserver_cmppolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) CountCSVServerCMPPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", csVServerCMPPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"csvserver_cmppolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // csvserver_contentinspectionpolicy_binding -func (s *CSService) AddCSVServerContentInspectionPolicyBinding() {} -func (s *CSService) DeleteCSVServerContentInspectionPolicyBinding() {} -func (s *CSService) GetAllCSVServerContentInspectionPolicyBinding() {} -func (s *CSService) GetCSVServerContentInspectionPolicyBinding() {} -func (s *CSService) CountCSVServerContentInspectionPolicyBinding() {} +func (s *CSService) AddCSVServerContentInspectionPolicyBinding(binding models.CSVServerContentInspectionPolicyBinding) error { + payload := map[string]any{"csvserver_contentinspectionpolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, csVServerContentInspectionPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DeleteCSVServerContentInspectionPolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", csVServerContentInspectionPolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSVServerContentInspectionPolicyBinding() ([]models.CSVServerContentInspectionPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csVServerContentInspectionPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerContentInspectionPolicyBinding `json:"csvserver_contentinspectionpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSVServerContentInspectionPolicyBinding(name string) ([]models.CSVServerContentInspectionPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csVServerContentInspectionPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerContentInspectionPolicyBinding `json:"csvserver_contentinspectionpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) CountCSVServerContentInspectionPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", csVServerContentInspectionPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"csvserver_contentinspectionpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // csvserver_cspolicy_binding -func (s *CSService) AddCSVServerCSPolicyBinding() {} -func (s *CSService) DeleteCSVServerCSPolicyBinding() {} -func (s *CSService) GetAllCSVServerCSPolicyBinding() {} -func (s *CSService) GetCSVServerCSPolicyBinding() {} -func (s *CSService) CountCSVServerCSPolicyBinding() {} +func (s *CSService) AddCSVServerCSPolicyBinding(binding models.CSVServerCSPolicyBinding) error { + payload := map[string]any{"csvserver_cspolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, csVServerCSPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DeleteCSVServerCSPolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", csVServerCSPolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSVServerCSPolicyBinding() ([]models.CSVServerCSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csVServerCSPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerCSPolicyBinding `json:"csvserver_cspolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSVServerCSPolicyBinding(name string) ([]models.CSVServerCSPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csVServerCSPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerCSPolicyBinding `json:"csvserver_cspolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) CountCSVServerCSPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", csVServerCSPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"csvserver_cspolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // csvserver_domain_binding -func (s *CSService) AddCSVServerDomainBinding() {} -func (s *CSService) DeleteCSVServerDomainBinding() {} -func (s *CSService) GetAllCSVServerDomainBinding() {} -func (s *CSService) GetCSVServerDomainBinding() {} -func (s *CSService) CountCSVServerDomainBinding() {} +func (s *CSService) AddCSVServerDomainBinding(binding models.CSVServerDomainBinding) error { + payload := map[string]any{"csvserver_domain_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, csVServerDomainBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DeleteCSVServerDomainBinding(name string, domainName string) error { + reqURL := fmt.Sprintf("%s/%s?args=domainname:%s", csVServerDomainBindingURL, url.QueryEscape(name), url.QueryEscape(domainName)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSVServerDomainBinding() ([]models.CSVServerDomainBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csVServerDomainBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerDomainBinding `json:"csvserver_domain_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSVServerDomainBinding(name string) ([]models.CSVServerDomainBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csVServerDomainBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerDomainBinding `json:"csvserver_domain_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) CountCSVServerDomainBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", csVServerDomainBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"csvserver_domain_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // csvserver_feopolicy_binding -func (s *CSService) AddCSVServerFeoPolicyBinding() {} -func (s *CSService) DeleteCSVServerFeoPolicyBinding() {} -func (s *CSService) GetAllCSVServerFeoPolicyBinding() {} -func (s *CSService) GetCSVServerFeoPolicyBinding() {} -func (s *CSService) CountCSVServerFeoPolicyBinding() {} +func (s *CSService) AddCSVServerFEOPolicyBinding(binding models.CSVServerFEOPolicyBinding) error { + payload := map[string]any{"csvserver_feopolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, csVServerFEOPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DeleteCSVServerFEOPolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", csVServerFEOPolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSVServerFEOPolicyBinding() ([]models.CSVServerFEOPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csVServerFEOPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerFEOPolicyBinding `json:"csvserver_feopolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSVServerFEOPolicyBinding(name string) ([]models.CSVServerFEOPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csVServerFEOPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerFEOPolicyBinding `json:"csvserver_feopolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) CountCSVServerFEOPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", csVServerFEOPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"csvserver_feopolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // csvserver_gslbvserver_binding -func (s *CSService) AddCSVServerGSLBVServerBinding() {} -func (s *CSService) DeleteCSVServerGSLBVServerBinding() {} -func (s *CSService) GetAllCSVServerGSLBVServerBinding() {} -func (s *CSService) GetCSVServerGSLBVServerBinding() {} -func (s *CSService) CountCSVServerGSLBVServerBinding() {} +func (s *CSService) AddCSVServerGSLBVServerBinding(binding models.CSVServerGSLBVServerBinding) error { + payload := map[string]any{"csvserver_gslbvserver_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, csVServerGSLBVServerBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DeleteCSVServerGSLBVServerBinding(name string, vserverName string) error { + reqURL := fmt.Sprintf("%s/%s?args=vserver:%s", csVServerGSLBVServerBindingURL, url.QueryEscape(name), url.QueryEscape(vserverName)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSVServerGSLBVServerBinding() ([]models.CSVServerGSLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csVServerGSLBVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerGSLBVServerBinding `json:"csvserver_gslbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSVServerGSLBVServerBinding(name string) ([]models.CSVServerGSLBVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csVServerGSLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerGSLBVServerBinding `json:"csvserver_gslbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) CountCSVServerGSLBVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", csVServerGSLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"csvserver_gslbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // csvserver_lbvserver_binding -func (s *CSService) AddCSVServerLBVServerBinding() {} -func (s *CSService) DeleteCSVServerLBVServerBinding() {} -func (s *CSService) GetAllCSVServerLBVServerBinding() {} -func (s *CSService) GetCSVServerLBVServerBinding() {} -func (s *CSService) CountCSVServerLBVServerBinding() {} +func (s *CSService) AddCSVServerLBVServerBinding(binding models.CSVServerLBVServerBinding) error { + payload := map[string]any{"csvserver_lbvserver_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, csVServerLBVServerBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DeleteCSVServerLBVServerBinding(name string, lbvserver string) error { + reqURL := fmt.Sprintf("%s/%s?args=lbvserver:%s", csVServerLBVServerBindingURL, url.QueryEscape(name), url.QueryEscape(lbvserver)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSVServerLBVServerBinding() ([]models.CSVServerLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csVServerLBVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerLBVServerBinding `json:"csvserver_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSVServerLBVServerBinding(name string) ([]models.CSVServerLBVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csVServerLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerLBVServerBinding `json:"csvserver_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) CountCSVServerLBVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", csVServerLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"csvserver_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // csvserver_responderpolicy_binding -func (s *CSService) AddCSVServerResponderPolicyBinding() {} -func (s *CSService) DeleteCSVServerResponderPolicyBinding() {} -func (s *CSService) GetAllCSVServerResponderPolicyBinding() {} -func (s *CSService) GetCSVServerResponderPolicyBinding() {} -func (s *CSService) CountCSVServerResponderPolicyBinding() {} +func (s *CSService) AddCSVServerResponderPolicyBinding(binding models.CSVServerResponderPolicyBinding) error { + payload := map[string]any{"csvserver_responderpolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, csVServerResponderPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DeleteCSVServerResponderPolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", csVServerResponderPolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSVServerResponderPolicyBinding() ([]models.CSVServerResponderPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csVServerResponderPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerResponderPolicyBinding `json:"csvserver_responderpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSVServerResponderPolicyBinding(name string) ([]models.CSVServerResponderPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csVServerResponderPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerResponderPolicyBinding `json:"csvserver_responderpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) CountCSVServerResponderPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", csVServerResponderPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"csvserver_responderpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // csvserver_rewritepolicy_binding -func (s *CSService) AddCSVServerRewritePolicyBinding() {} -func (s *CSService) DeleteCSVServerRewritePolicyBinding() {} -func (s *CSService) GetAllCSVServerRewritePolicyBinding() {} -func (s *CSService) GetCSVServerRewritePolicyBinding() {} -func (s *CSService) CountCSVServerRewritePolicyBinding() {} +func (s *CSService) AddCSVServerRewritePolicyBinding(binding models.CSVServerRewritePolicyBinding) error { + payload := map[string]any{"csvserver_rewritepolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, csVServerRewritePolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DeleteCSVServerRewritePolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", csVServerRewritePolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSVServerRewritePolicyBinding() ([]models.CSVServerRewritePolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csVServerRewritePolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerRewritePolicyBinding `json:"csvserver_rewritepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSVServerRewritePolicyBinding(name string) ([]models.CSVServerRewritePolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csVServerRewritePolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerRewritePolicyBinding `json:"csvserver_rewritepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) CountCSVServerRewritePolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", csVServerRewritePolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"csvserver_rewritepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // csvserver_spilloverpolicy_binding -func (s *CSService) AddCSVServerSpilloverPolicyBinding() {} -func (s *CSService) DeleteCSVServerSpilloverPolicyBinding() {} -func (s *CSService) GetAllCSVServerSpilloverPolicyBinding() {} -func (s *CSService) GetCSVServerSpilloverPolicyBinding() {} -func (s *CSService) CountCSVServerSpilloverPolicyBinding() {} +func (s *CSService) AddCSVServerSpilloverPolicyBinding(binding models.CSVServerSpilloverPolicyBinding) error { + payload := map[string]any{"csvserver_spilloverpolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, csVServerSpilloverPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DeleteCSVServerSpilloverPolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", csVServerSpilloverPolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSVServerSpilloverPolicyBinding() ([]models.CSVServerSpilloverPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csVServerSpilloverPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerSpilloverPolicyBinding `json:"csvserver_spilloverpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSVServerSpilloverPolicyBinding(name string) ([]models.CSVServerSpilloverPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csVServerSpilloverPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerSpilloverPolicyBinding `json:"csvserver_spilloverpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) CountCSVServerSpilloverPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", csVServerSpilloverPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"csvserver_spilloverpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // csvserver_tmtrafficpolicy_binding -func (s *CSService) AddCSVServerTMTrafficPolicyBinding() {} -func (s *CSService) DeleteCSVServerTMTrafficPolicyBinding() {} -func (s *CSService) GetAllCSVServerTMTrafficPolicyBinding() {} -func (s *CSService) GetCSVServerTMTrafficPolicyBinding() {} -func (s *CSService) CountCSVServerTMTrafficPolicyBinding() {} +func (s *CSService) AddCSVServerTMTrafficPolicyBinding(binding models.CSVServerTMTrafficPolicyBinding) error { + payload := map[string]any{"csvserver_tmtrafficpolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, csVServerTMTrafficPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DeleteCSVServerTMTrafficPolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", csVServerTMTrafficPolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSVServerTMTrafficPolicyBinding() ([]models.CSVServerTMTrafficPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csVServerTMTrafficPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerTMTrafficPolicyBinding `json:"csvserver_tmtrafficpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSVServerTMTrafficPolicyBinding(name string) ([]models.CSVServerTMTrafficPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csVServerTMTrafficPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerTMTrafficPolicyBinding `json:"csvserver_tmtrafficpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) CountCSVServerTMTrafficPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", csVServerTMTrafficPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"csvserver_tmtrafficpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // csvserver_transformpolicy_binding -func (s *CSService) AddCSVServerTransformPolicyBinding() {} -func (s *CSService) DeleteCSVServerTransformPolicyBinding() {} -func (s *CSService) GetAllCSVServerTransformPolicyBinding() {} -func (s *CSService) GetCSVServerTransformPolicyBinding() {} -func (s *CSService) CountCSVServerTransformPolicyBinding() {} - -// csvserver_vpnserver_binding -func (s *CSService) AddCSVServerVPNVServerBinding() {} -func (s *CSService) DeleteCSVServerVPNVServerBinding() {} -func (s *CSService) GetAllCSVServerVPNVServerBinding() {} -func (s *CSService) GetCSVServerVPNVServerBinding() {} -func (s *CSService) CountCSVServerVPNVServerBinding() {} +func (s *CSService) AddCSVServerTransformPolicyBinding(binding models.CSVServerTransformPolicyBinding) error { + payload := map[string]any{"csvserver_transformpolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, csVServerTransformPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DeleteCSVServerTransformPolicyBinding(name string, policyName string, bindPoint string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,bindpoint:%s,priority:%d", csVServerTransformPolicyBindingURL, url.QueryEscape(name), url.QueryEscape(policyName), url.QueryEscape(bindPoint), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSVServerTransformPolicyBinding() ([]models.CSVServerTransformPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csVServerTransformPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerTransformPolicyBinding `json:"csvserver_transformpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSVServerTransformPolicyBinding(name string) ([]models.CSVServerTransformPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csVServerTransformPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerTransformPolicyBinding `json:"csvserver_transformpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) CountCSVServerTransformPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", csVServerTransformPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"csvserver_transformpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} + +// csvserver_vpnvserver_binding +func (s *CSService) AddCSVServerVPNVServerBinding(binding models.CSVServerVPNVServerBinding) error { + payload := map[string]any{"csvserver_vpnvserver_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, csVServerVPNVServerBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) DeleteCSVServerVPNVServerBinding(name string, vserver string) error { + reqURL := fmt.Sprintf("%s/%s?args=vserver:%s", csVServerVPNVServerBindingURL, url.QueryEscape(name), url.QueryEscape(vserver)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *CSService) GetAllCSVServerVPNVServerBinding() ([]models.CSVServerVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, csVServerVPNVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerVPNVServerBinding `json:"csvserver_vpnvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) GetCSVServerVPNVServerBinding(name string) ([]models.CSVServerVPNVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", csVServerVPNVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.CSVServerVPNVServerBinding `json:"csvserver_vpnvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *CSService) CountCSVServerVPNVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", csVServerVPNVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"csvserver_vpnvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} diff --git a/nitrogo/db.go b/nitrogo/db.go index 6f958b2..d103de4 100644 --- a/nitrogo/db.go +++ b/nitrogo/db.go @@ -1,5 +1,19 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + dbDBProfileURL = "/nitro/v1/config/dbdbprofile" + dbUserURL = "/nitro/v1/config/dbuser" +) + // All the commands associated with database user // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/db/db type DBService struct { @@ -9,20 +23,276 @@ type DBService struct { // dbdbprofile // Configuration for DB profile resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/db/dbdbprofile -func (s *DBService) AddDBDBProfile() {} -func (s *DBService) DeleteDBDBProfile() {} -func (s *DBService) UpdateDBDBProfile() {} -func (s *DBService) UnsetDBDBProfile() {} -func (s *DBService) GetAllDBDBProfile() {} -func (s *DBService) GetDBDBProfile() {} -func (s *DBService) CountDBDBProfile() {} + +func (s *DBService) AddDBDBProfile(profile models.DBDBProfile) error { + payload := map[string]any{ + "dbdbprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, dbDBProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *DBService) DeleteDBDBProfile(name string) error { + url := fmt.Sprintf("%s/%s", dbDBProfileURL, name) + req, err := s.client.NewRequest(http.MethodDelete, url, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *DBService) UpdateDBDBProfile(profile models.DBDBProfile) error { + payload := map[string]any{ + "dbdbprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, dbDBProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *DBService) UnsetDBDBProfile(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "dbdbprofile": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, dbDBProfileURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *DBService) GetAllDBDBProfile() ([]models.DBDBProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, dbDBProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + DBDBProfiles []models.DBDBProfile `json:"dbdbprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.DBDBProfiles, nil +} + +func (s *DBService) GetDBDBProfile(name string) ([]models.DBDBProfile, error) { + url := fmt.Sprintf("%s/%s", dbDBProfileURL, name) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + DBDBProfiles []models.DBDBProfile `json:"dbdbprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.DBDBProfiles, nil +} + +func (s *DBService) CountDBDBProfile() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, dbDBProfileURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + DBDBProfiles []struct { + Count float64 `json:"__count"` + } `json:"dbdbprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.DBDBProfiles) > 0 { + return result.DBDBProfiles[0].Count, nil + } + + return 0, nil +} // dbuser // Configuration for DB user resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/db/dbuser -func (s *DBService) AddDBUser() {} -func (s *DBService) DeleteDBUser() {} -func (s *DBService) UpdateDBUser() {} -func (s *DBService) GetAllDBUser() {} -func (s *DBService) GetDBUser() {} -func (s *DBService) CountDBUser() {} + +func (s *DBService) AddDBUser(user models.DBUser) error { + payload := map[string]any{ + "dbuser": user, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, dbUserURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *DBService) DeleteDBUser(username string) error { + url := fmt.Sprintf("%s/%s", dbUserURL, username) + req, err := s.client.NewRequest(http.MethodDelete, url, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *DBService) UpdateDBUser(user models.DBUser) error { + payload := map[string]any{ + "dbuser": user, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, dbUserURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *DBService) GetAllDBUser() ([]models.DBUser, error) { + req, err := s.client.NewRequest(http.MethodGet, dbUserURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + DBUsers []models.DBUser `json:"dbuser"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.DBUsers, nil +} + +func (s *DBService) GetDBUser(username string) ([]models.DBUser, error) { + url := fmt.Sprintf("%s/%s", dbUserURL, username) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + DBUsers []models.DBUser `json:"dbuser"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.DBUsers, nil +} + +func (s *DBService) CountDBUser() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, dbUserURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + DBUsers []struct { + Count float64 `json:"__count"` + } `json:"dbuser"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.DBUsers) > 0 { + return result.DBUsers[0].Count, nil + } + + return 0, nil +} diff --git a/nitrogo/dns.go b/nitrogo/dns.go index 4c6ad1a..e9e2e43 100644 --- a/nitrogo/dns.go +++ b/nitrogo/dns.go @@ -1,5 +1,59 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + dnsAAAARecURL = "/nitro/v1/config/dnsaaaarec" + dnsActionURL = "/nitro/v1/config/dnsaction" + dnsAction64URL = "/nitro/v1/config/dnsaction64" + dnsAddRecURL = "/nitro/v1/config/dnsaddrec" + dnsCNameRecURL = "/nitro/v1/config/dnscnamerec" + dnsGlobalBindingURL = "/nitro/v1/config/dnsglobal_binding" + dnsGlobalDNSPolicyBindingURL = "/nitro/v1/config/dnsglobal_dnspolicy_binding" + dnsKeyURL = "/nitro/v1/config/dnskey" + dnsMXRecURL = "/nitro/v1/config/dnsmxrec" + dnsNameServerURL = "/nitro/v1/config/dnsnameserver" + dnsNAPTRRecURL = "/nitro/v1/config/dnsnaptrrec" + dnsNSECRecURL = "/nitro/v1/config/dnsnsecrec" + dnsNSRecURL = "/nitro/v1/config/dnsnsrec" + dnsParameterURL = "/nitro/v1/config/dnsparameter" + dnsPolicyURL = "/nitro/v1/config/dnspolicy" + dnsPolicy64URL = "/nitro/v1/config/dnspolicy64" + dnsPolicy64BindingURL = "/nitro/v1/config/dnspolicy64_binding" + dnsPolicy64LBVServerBindingURL = "/nitro/v1/config/dnspolicy64_lbvserver_binding" + dnsPolicyLabelURL = "/nitro/v1/config/dnspolicylabel" + dnsPolicyLabelBindingURL = "/nitro/v1/config/dnspolicylabel_binding" + dnsPolicyLabelDNSPolicyBindingURL = "/nitro/v1/config/dnspolicylabel_dnspolicy_binding" + dnsPolicyLabelPolicyBindingBindingURL = "/nitro/v1/config/dnspolicylabel_policybinding_binding" + dnsPolicyBindingURL = "/nitro/v1/config/dnspolicy_binding" + dnsPolicyDNSGlobalBindingURL = "/nitro/v1/config/dnspolicy_dnsglobal_binding" + dnsPolicyDNSPolicyLabelBindingURL = "/nitro/v1/config/dnspolicy_dnspolicylabel_binding" + dnsProfileURL = "/nitro/v1/config/dnsprofile" + dnsProxyRecordsURL = "/nitro/v1/config/dnsproxyrecords" + dnsPTRRecURL = "/nitro/v1/config/dnsptrrec" + dnsSOARecURL = "/nitro/v1/config/dnssoarec" + dnsSRVRecURL = "/nitro/v1/config/dnssrvrec" + dnsSubnetCacheURL = "/nitro/v1/config/dnssubnetcache" + dnsSuffixURL = "/nitro/v1/config/dnssuffix" + dnsTXTRecURL = "/nitro/v1/config/dnstxtrec" + dnsViewURL = "/nitro/v1/config/dnsview" + dnsViewBindingURL = "/nitro/v1/config/dnsview_binding" + dnsViewDNSPolicyBindingURL = "/nitro/v1/config/dnsview_dnspolicy_binding" + dnsViewGSLBServiceBindingURL = "/nitro/v1/config/dnsview_gslbservice_binding" + dnsZoneURL = "/nitro/v1/config/dnszone" + dnsZoneBindingURL = "/nitro/v1/config/dnszone_binding" + dnsZoneDNSKeyBindingURL = "/nitro/v1/config/dnszone_dnskey_binding" + dnsZoneDomainBindingURL = "/nitro/v1/config/dnszone_domain_binding" +) + // Domain Name Service(DNS) configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/dns/dns type DNSService struct { @@ -7,268 +61,3329 @@ type DNSService struct { } // dnsaaaarec -func (s *DNSService) AddDNSAAAARec() {} -func (s *DNSService) DeleteDNSAAAARec() {} -func (s *DNSService) GetAllDNSAAAARec() {} -func (s *DNSService) CountDNSAAAARec() {} +func (s *DNSService) AddDNSAAAARec(rec models.DNSAAAARec) error { + payload := map[string]any{"dnsaaaarec": rec} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsAAAARecURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) DeleteDNSAAAARec(hostname string) error { + reqURL := fmt.Sprintf("%s/%s", dnsAAAARecURL, url.QueryEscape(hostname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) GetAllDNSAAAARec() ([]models.DNSAAAARec, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsAAAARecURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSAAAARec `json:"dnsaaaarec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSAAAARec() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsAAAARecURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnsaaaarec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnsaction -func (s *DNSService) AddDNSAction() {} -func (s *DNSService) DeleteDNSAction() {} -func (s *DNSService) UpdateDNSAction() {} -func (s *DNSService) UnsetDNSAction() {} -func (s *DNSService) GetAllDNSAction() {} -func (s *DNSService) GetDNSAction() {} -func (s *DNSService) CountDNSAction() {} +func (s *DNSService) AddDNSAction(action models.DNSAction) error { + payload := map[string]any{"dnsaction": action} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) DeleteDNSAction(actionName string) error { + reqURL := fmt.Sprintf("%s/%s", dnsActionURL, url.QueryEscape(actionName)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) UpdateDNSAction(action models.DNSAction) error { + payload := map[string]any{"dnsaction": action} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, dnsActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) UnsetDNSAction(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"dnsaction": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsActionURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) GetAllDNSAction() ([]models.DNSAction, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsActionURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSAction `json:"dnsaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSAction(actionName string) ([]models.DNSAction, error) { + reqURL := fmt.Sprintf("%s/%s", dnsActionURL, url.QueryEscape(actionName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSAction `json:"dnsaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSAction() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsActionURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnsaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnsaction64 -func (s *DNSService) AddDNSAction64() {} -func (s *DNSService) DeleteDNSAction64() {} -func (s *DNSService) UpdateDNSAction64() {} -func (s *DNSService) UnsetDNSAction64() {} -func (s *DNSService) GetAllDNSAction64() {} -func (s *DNSService) GetDNSAction64() {} -func (s *DNSService) CountDNSAction64() {} +func (s *DNSService) AddDNSAction64(action models.DNSAction64) error { + payload := map[string]any{"dnsaction64": action} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsAction64URL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) DeleteDNSAction64(actionName string) error { + reqURL := fmt.Sprintf("%s/%s", dnsAction64URL, url.QueryEscape(actionName)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) UpdateDNSAction64(action models.DNSAction64) error { + payload := map[string]any{"dnsaction64": action} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, dnsAction64URL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) UnsetDNSAction64(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"dnsaction64": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsAction64URL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) GetAllDNSAction64() ([]models.DNSAction64, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsAction64URL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSAction64 `json:"dnsaction64"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSAction64(actionName string) ([]models.DNSAction64, error) { + reqURL := fmt.Sprintf("%s/%s", dnsAction64URL, url.QueryEscape(actionName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSAction64 `json:"dnsaction64"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSAction64() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsAction64URL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnsaction64"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnsaddrec -func (s *DNSService) AddDNSAddRec() {} -func (s *DNSService) DeleteDNSAddRec() {} -func (s *DNSService) GetAllDNSAddRec() {} -func (s *DNSService) GetDNSAddRec() {} -func (s *DNSService) CountDNSAddRec() {} +func (s *DNSService) AddDNSAddRec(rec models.DNSAddRec) error { + payload := map[string]any{"dnsaddrec": rec} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsAddRecURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) DeleteDNSAddRec(hostname string) error { + reqURL := fmt.Sprintf("%s/%s", dnsAddRecURL, url.QueryEscape(hostname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) GetAllDNSAddRec() ([]models.DNSAddRec, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsAddRecURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSAddRec `json:"dnsaddrec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSAddRec(hostname string) ([]models.DNSAddRec, error) { + reqURL := fmt.Sprintf("%s/%s", dnsAddRecURL, url.QueryEscape(hostname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSAddRec `json:"dnsaddrec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSAddRec() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsAddRecURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnsaddrec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnscnamerec -func (s *DNSService) AddDNSCNameRec() {} -func (s *DNSService) DeleteDNSCNameRec() {} -func (s *DNSService) GetAllDNSCNameRec() {} -func (s *DNSService) GetDNSCNameRec() {} -func (s *DNSService) CountDNSCNameRec() {} +func (s *DNSService) AddDNSCNameRec(rec models.DNSCnameRec) error { + payload := map[string]any{"dnscnamerec": rec} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsCNameRecURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) DeleteDNSCNameRec(aliasName string) error { + reqURL := fmt.Sprintf("%s/%s", dnsCNameRecURL, url.QueryEscape(aliasName)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) GetAllDNSCNameRec() ([]models.DNSCnameRec, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsCNameRecURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSCnameRec `json:"dnscnamerec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSCNameRec(aliasName string) ([]models.DNSCnameRec, error) { + reqURL := fmt.Sprintf("%s/%s", dnsCNameRecURL, url.QueryEscape(aliasName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSCnameRec `json:"dnscnamerec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSCNameRec() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsCNameRecURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnscnamerec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnsglobal_binding -func (s *DNSService) GetDNSGlobalBinding() {} +func (s *DNSService) GetDNSGlobalBinding() ([]models.DNSGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSGlobalBinding `json:"dnsglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} // dnsglobal_dnspolicy_binding -func (s *DNSService) AddDNSGlobalDNSPolicyBinding() {} -func (s *DNSService) DeleteDNSGlobalDNSPolicyBinding() {} -func (s *DNSService) GetDNSGlobalDNSPolicyBinding() {} -func (s *DNSService) CountDNSGlobalDNSPolicyBinding() {} +func (s *DNSService) AddDNSGlobalDNSPolicyBinding(binding models.DNSGlobalDNSPolicyBinding) error { + payload := map[string]any{"dnsglobal_dnspolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, dnsGlobalDNSPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) DeleteDNSGlobalDNSPolicyBinding(policyname string, typefield string) error { + reqURL := fmt.Sprintf("%s/%s?args=type:%s", dnsGlobalDNSPolicyBindingURL, url.QueryEscape(policyname), url.QueryEscape(typefield)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) GetDNSGlobalDNSPolicyBinding() ([]models.DNSGlobalDNSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsGlobalDNSPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSGlobalDNSPolicyBinding `json:"dnsglobal_dnspolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSGlobalDNSPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsGlobalDNSPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnsglobal_dnspolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnskey -func (s *DNSService) AddDNSKey() {} -func (s *DNSService) DeleteDNSKey() {} -func (s *DNSService) UpdateDNSKey() {} -func (s *DNSService) UnsetDNSKey() {} -func (s *DNSService) GetAllDNSKey() {} -func (s *DNSService) GetDNSKey() {} -func (s *DNSService) CountDNSKey() {} -func (s *DNSService) CreateDNSKey() {} -func (s *DNSService) ImportDNSKey() {} +func (s *DNSService) AddDNSKey(key models.DNSKey) error { + payload := map[string]any{"dnskey": key} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsKeyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) DeleteDNSKey(keyName string) error { + reqURL := fmt.Sprintf("%s/%s", dnsKeyURL, url.QueryEscape(keyName)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) UpdateDNSKey(key models.DNSKey) error { + payload := map[string]any{"dnskey": key} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, dnsKeyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) UnsetDNSKey(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"dnskey": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsKeyURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) GetAllDNSKey() ([]models.DNSKey, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsKeyURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSKey `json:"dnskey"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSKey(keyName string) ([]models.DNSKey, error) { + reqURL := fmt.Sprintf("%s/%s", dnsKeyURL, url.QueryEscape(keyName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSKey `json:"dnskey"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSKey() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsKeyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnskey"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} + +func (s *DNSService) CreateDNSKey(key models.DNSKey) error { + payload := map[string]any{"dnskey": key} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsKeyURL+"?action=create", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) ImportDNSKey(key models.DNSKey) error { + payload := map[string]any{"dnskey": key} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsKeyURL+"?action=import", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} // dnsmxrec -func (s *DNSService) AddDNSMXRec() {} -func (s *DNSService) DeleteDNSMXRec() {} -func (s *DNSService) UpdateDNSMXRec() {} -func (s *DNSService) UnsetDNSMXRec() {} -func (s *DNSService) GetAllDNSMXRec() {} -func (s *DNSService) GetDNSMXRec() {} -func (s *DNSService) CountDNSMXRec() {} +func (s *DNSService) AddDNSMXRec(rec models.DNSMXRec) error { + payload := map[string]any{"dnsmxrec": rec} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsMXRecURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) DeleteDNSMXRec(domain string) error { + reqURL := fmt.Sprintf("%s/%s", dnsMXRecURL, url.QueryEscape(domain)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) UpdateDNSMXRec(rec models.DNSMXRec) error { + payload := map[string]any{"dnsmxrec": rec} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, dnsMXRecURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) UnsetDNSMXRec(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"dnsmxrec": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsMXRecURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) GetAllDNSMXRec() ([]models.DNSMXRec, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsMXRecURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSMXRec `json:"dnsmxrec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSMXRec(domain string) ([]models.DNSMXRec, error) { + reqURL := fmt.Sprintf("%s/%s", dnsMXRecURL, url.QueryEscape(domain)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSMXRec `json:"dnsmxrec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSMXRec() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsMXRecURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnsmxrec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnsnameserver -func (s *DNSService) AddDNSNameServer() {} -func (s *DNSService) DeleteDNSNameServer() {} -func (s *DNSService) UpdateDNSNameServer() {} -func (s *DNSService) UnsetDNSNameServer() {} -func (s *DNSService) EnableDNSNameServer() {} -func (s *DNSService) DisableDNSNameServer() {} -func (s *DNSService) GetAllDNSNameServer() {} -func (s *DNSService) CountDNSNameServer() {} +func (s *DNSService) AddDNSNameServer(server models.DNSNameServer) error { + payload := map[string]any{"dnsnameserver": server} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsNameServerURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) DeleteDNSNameServer(ip string) error { + reqURL := fmt.Sprintf("%s/%s", dnsNameServerURL, url.QueryEscape(ip)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) UpdateDNSNameServer(server models.DNSNameServer) error { + payload := map[string]any{"dnsnameserver": server} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, dnsNameServerURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) UnsetDNSNameServer(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"dnsnameserver": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsNameServerURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) EnableDNSNameServer(ip string) error { + payload := map[string]any{ + "dnsnameserver": map[string]string{"ip": ip}, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsNameServerURL+"?action=enable", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) DisableDNSNameServer(ip string) error { + payload := map[string]any{ + "dnsnameserver": map[string]string{"ip": ip}, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsNameServerURL+"?action=disable", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) GetAllDNSNameServer() ([]models.DNSNameServer, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsNameServerURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSNameServer `json:"dnsnameserver"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSNameServer() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsNameServerURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnsnameserver"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnsnaptrrec -func (s *DNSService) AddDNSNAPTRRec() {} -func (s *DNSService) DeleteDNSNAPTRRec() {} -func (s *DNSService) GetAllDNSNAPTRRec() {} -func (s *DNSService) GetDNSNAPTRRec() {} -func (s *DNSService) CountDNSNAPTRRec() {} +func (s *DNSService) AddDNSNAPTRRec(rec models.DNSNaptrRec) error { + payload := map[string]any{"dnsnaptrrec": rec} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsNAPTRRecURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) DeleteDNSNAPTRRec(domain string) error { + reqURL := fmt.Sprintf("%s/%s", dnsNAPTRRecURL, url.QueryEscape(domain)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) GetAllDNSNAPTRRec() ([]models.DNSNaptrRec, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsNAPTRRecURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSNaptrRec `json:"dnsnaptrrec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSNAPTRRec(domain string) ([]models.DNSNaptrRec, error) { + reqURL := fmt.Sprintf("%s/%s", dnsNAPTRRecURL, url.QueryEscape(domain)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSNaptrRec `json:"dnsnaptrrec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSNAPTRRec() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsNAPTRRecURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnsnaptrrec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnsnsecrec -func (s *DNSService) GetAllDNSNSECRec() {} -func (s *DNSService) GetDNSNSEcRec() {} -func (s *DNSService) CountDNSNSECRec() {} +func (s *DNSService) GetAllDNSNSECRec() ([]models.DNSNSECRec, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsNSECRecURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSNSECRec `json:"dnsnsecrec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSNSEcRec(hostname string) ([]models.DNSNSECRec, error) { + reqURL := fmt.Sprintf("%s/%s", dnsNSECRecURL, url.QueryEscape(hostname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSNSECRec `json:"dnsnsecrec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSNSECRec() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsNSECRecURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnsnsecrec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnsnsrec -func (s *DNSService) AddDNSNSRec() {} -func (s *DNSService) DeleteDNSNSRec() {} -func (s *DNSService) GetAllDNSNSRec() {} -func (s *DNSService) GetDNSNSRec() {} -func (s *DNSService) CountDNSNSRec() {} +func (s *DNSService) AddDNSNSRec(rec models.DNSNSRec) error { + payload := map[string]any{"dnsnsrec": rec} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsNSRecURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) DeleteDNSNSRec(domain string) error { + reqURL := fmt.Sprintf("%s/%s", dnsNSRecURL, url.QueryEscape(domain)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) GetAllDNSNSRec() ([]models.DNSNSRec, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsNSRecURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSNSRec `json:"dnsnsrec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSNSRec(domain string) ([]models.DNSNSRec, error) { + reqURL := fmt.Sprintf("%s/%s", dnsNSRecURL, url.QueryEscape(domain)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSNSRec `json:"dnsnsrec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSNSRec() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsNSRecURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnsnsrec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnsparameter -func (s *DNSService) UpdateDNSParameter() {} -func (s *DNSService) UnsetDNSParameter() {} -func (s *DNSService) GetAllDNSParameter() {} +func (s *DNSService) UpdateDNSParameter(param models.DNSParameter) error { + payload := map[string]any{"dnsparameter": param} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, dnsParameterURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) UnsetDNSParameter(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"dnsparameter": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsParameterURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) GetAllDNSParameter() (models.DNSParameter, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsParameterURL, nil) + if err != nil { + return models.DNSParameter{}, err + } + resp, err := s.client.Do(req) + if err != nil { + return models.DNSParameter{}, err + } + var result struct { + Items []models.DNSParameter `json:"dnsparameter"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return models.DNSParameter{}, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0], nil + } + return models.DNSParameter{}, nil +} // dnspolicy -func (s *DNSService) AddDNSPolicy() {} -func (s *DNSService) DeleteDNSPolicy() {} -func (s *DNSService) UpdateDNSPolicy() {} -func (s *DNSService) UnsetDNSPolicy() {} -func (s *DNSService) GetAllDNSPolicy() {} -func (s *DNSService) GetDNSPolicy() {} -func (s *DNSService) CountDNSPolicy() {} +func (s *DNSService) AddDNSPolicy(policy models.DNSPolicy) error { + payload := map[string]any{"dnspolicy": policy} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) DeleteDNSPolicy(name string) error { + reqURL := fmt.Sprintf("%s/%s", dnsPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) UpdateDNSPolicy(policy models.DNSPolicy) error { + payload := map[string]any{"dnspolicy": policy} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, dnsPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) UnsetDNSPolicy(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"dnspolicy": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsPolicyURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) GetAllDNSPolicy() ([]models.DNSPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsPolicyURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSPolicy `json:"dnspolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSPolicy(name string) ([]models.DNSPolicy, error) { + reqURL := fmt.Sprintf("%s/%s", dnsPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSPolicy `json:"dnspolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSPolicy() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsPolicyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnspolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnspolicy64 -func (s *DNSService) AddDNSPolicy64() {} -func (s *DNSService) DeleteDNSPolicy64() {} -func (s *DNSService) UpdateDNSPolicy64() {} -func (s *DNSService) GetAllDNSPolicy64() {} -func (s *DNSService) GetDNSPolicy64() {} -func (s *DNSService) CountDNSPolicy64() {} +func (s *DNSService) AddDNSPolicy64(policy models.DNSPolicy64) error { + payload := map[string]any{"dnspolicy64": policy} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsPolicy64URL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) DeleteDNSPolicy64(name string) error { + reqURL := fmt.Sprintf("%s/%s", dnsPolicy64URL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) UpdateDNSPolicy64(policy models.DNSPolicy64) error { + payload := map[string]any{"dnspolicy64": policy} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, dnsPolicy64URL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) GetAllDNSPolicy64() ([]models.DNSPolicy64, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsPolicy64URL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSPolicy64 `json:"dnspolicy64"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSPolicy64(name string) ([]models.DNSPolicy64, error) { + reqURL := fmt.Sprintf("%s/%s", dnsPolicy64URL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSPolicy64 `json:"dnspolicy64"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSPolicy64() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsPolicy64URL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnspolicy64"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnspolicy64_binding -func (s *DNSService) GetAllDNSPolicy64Binding() {} -func (s *DNSService) GetDNSPolicy64Binding() {} +func (s *DNSService) GetAllDNSPolicy64Binding() ([]models.DNSPolicy64Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsPolicy64BindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSPolicy64Binding `json:"dnspolicy64_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSPolicy64Binding(name string) ([]models.DNSPolicy64Binding, error) { + reqURL := fmt.Sprintf("%s/%s", dnsPolicy64BindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSPolicy64Binding `json:"dnspolicy64_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} // dnspolicy64_lbvserver_binding -func (s *DNSService) GetAllDNSPolicy64LBVServerBinding() {} -func (s *DNSService) GetDNSPolicy64LBVServerBinding() {} -func (s *DNSService) CountDNSPolicy64LBVServerBinding() {} +func (s *DNSService) GetAllDNSPolicy64LBVServerBinding() ([]models.DNSPolicy64LBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsPolicy64LBVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSPolicy64LBVServerBinding `json:"dnspolicy64_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSPolicy64LBVServerBinding(name string) ([]models.DNSPolicy64LBVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", dnsPolicy64LBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSPolicy64LBVServerBinding `json:"dnspolicy64_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSPolicy64LBVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", dnsPolicy64LBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnspolicy64_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnspolicylabel -func (s *DNSService) AddDNSPolicyLabel() {} -func (s *DNSService) DeleteDNSPolicyLabel() {} -func (s *DNSService) GetAllDNSPolicyLabel() {} -func (s *DNSService) GetDNSPolicyLabel() {} -func (s *DNSService) CountDNSPolicyLabel() {} -func (s *DNSService) RenameDNSPolicyLabel() {} +func (s *DNSService) AddDNSPolicyLabel(label models.DNSPolicyLabel) error { + payload := map[string]any{"dnspolicylabel": label} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsPolicyLabelURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) DeleteDNSPolicyLabel(labelName string) error { + reqURL := fmt.Sprintf("%s/%s", dnsPolicyLabelURL, url.QueryEscape(labelName)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) GetAllDNSPolicyLabel() ([]models.DNSPolicyLabel, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsPolicyLabelURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSPolicyLabel `json:"dnspolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSPolicyLabel(labelName string) ([]models.DNSPolicyLabel, error) { + reqURL := fmt.Sprintf("%s/%s", dnsPolicyLabelURL, url.QueryEscape(labelName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSPolicyLabel `json:"dnspolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSPolicyLabel() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsPolicyLabelURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnspolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} + +func (s *DNSService) RenameDNSPolicyLabel(name string, newName string) error { + payload := map[string]any{ + "dnspolicylabel": map[string]string{ + "labelname": name, + "newname": newName, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsPolicyLabelURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} // dnspolicylabel_binding -func (s *DNSService) GetAllDNSPolicyLabelBinding() {} -func (s *DNSService) GetDNSPolicyLabelBinding() {} +func (s *DNSService) GetAllDNSPolicyLabelBinding() ([]models.DNSPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsPolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSPolicyLabelBinding `json:"dnspolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSPolicyLabelBinding(labelName string) ([]models.DNSPolicyLabelBinding, error) { + reqURL := fmt.Sprintf("%s/%s", dnsPolicyLabelBindingURL, url.QueryEscape(labelName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSPolicyLabelBinding `json:"dnspolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} // dnspolicylabel_dnspolicy_binding -func (s *DNSService) AddDNSPolicyLabelDNSPolicyBinding() {} -func (s *DNSService) DeleteDNSPolicyLabelDNSPolicyBinding() {} -func (s *DNSService) GetAllDNSPolicyLabelDNSPolicyBinding() {} -func (s *DNSService) GetDNSPolicyLabelDNSPolicyBinding() {} -func (s *DNSService) CountDNSPolicyLabelDNSPolicyBinding() {} +func (s *DNSService) AddDNSPolicyLabelDNSPolicyBinding(binding models.DNSPolicyLabelDNSPolicyBinding) error { + payload := map[string]any{"dnspolicylabel_dnspolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, dnsPolicyLabelDNSPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) DeleteDNSPolicyLabelDNSPolicyBinding(labelName string, policyName string) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s", dnsPolicyLabelDNSPolicyBindingURL, url.QueryEscape(labelName), url.QueryEscape(policyName)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) GetAllDNSPolicyLabelDNSPolicyBinding() ([]models.DNSPolicyLabelDNSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsPolicyLabelDNSPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSPolicyLabelDNSPolicyBinding `json:"dnspolicylabel_dnspolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSPolicyLabelDNSPolicyBinding(labelName string) ([]models.DNSPolicyLabelDNSPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", dnsPolicyLabelDNSPolicyBindingURL, url.QueryEscape(labelName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSPolicyLabelDNSPolicyBinding `json:"dnspolicylabel_dnspolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSPolicyLabelDNSPolicyBinding(labelName string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", dnsPolicyLabelDNSPolicyBindingURL, url.QueryEscape(labelName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnspolicylabel_dnspolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnspolicylabel_policybinding_binding -func (s *DNSService) GetAllDNSPolicyLabelPolicyBindingBinding() {} -func (s *DNSService) GetDNSPolicyLabelPolicyBindingBinding() {} -func (s *DNSService) CountDNSPolicyLabelPolicyBindingBinding() {} +func (s *DNSService) GetAllDNSPolicyLabelPolicyBindingBinding() ([]models.DNSPolicyLabelPolicyBindingBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsPolicyLabelPolicyBindingBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSPolicyLabelPolicyBindingBinding `json:"dnspolicylabel_policybinding_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSPolicyLabelPolicyBindingBinding(labelName string) ([]models.DNSPolicyLabelPolicyBindingBinding, error) { + reqURL := fmt.Sprintf("%s/%s", dnsPolicyLabelPolicyBindingBindingURL, url.QueryEscape(labelName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSPolicyLabelPolicyBindingBinding `json:"dnspolicylabel_policybinding_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSPolicyLabelPolicyBindingBinding(labelName string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", dnsPolicyLabelPolicyBindingBindingURL, url.QueryEscape(labelName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnspolicylabel_policybinding_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnspolicy_binding -func (s *DNSService) GetAllDNSPolicyBinding() {} -func (s *DNSService) GetDNSPolicyBinding() {} +func (s *DNSService) GetAllDNSPolicyBinding() ([]models.DNSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSPolicyBinding `json:"dnspolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSPolicyBinding(name string) ([]models.DNSPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", dnsPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSPolicyBinding `json:"dnspolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} // dnspolicy_dnsglobal_binding -func (s *DNSService) GetAllDNSPolicyDNSGlobalBinding() {} -func (s *DNSService) GetDNSPolicyDNSGlobalBinding() {} -func (s *DNSService) CountDNSPolicyDNSGlobalBinding() {} +func (s *DNSService) GetAllDNSPolicyDNSGlobalBinding() ([]models.DNSPolicyDNSGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsPolicyDNSGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSPolicyDNSGlobalBinding `json:"dnspolicy_dnsglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSPolicyDNSGlobalBinding(name string) ([]models.DNSPolicyDNSGlobalBinding, error) { + reqURL := fmt.Sprintf("%s/%s", dnsPolicyDNSGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSPolicyDNSGlobalBinding `json:"dnspolicy_dnsglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSPolicyDNSGlobalBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", dnsPolicyDNSGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnspolicy_dnsglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnspolicy_dnspolicylabel_binding -func (s *DNSService) GetAllDNSPolicyDNSPolicyLabelBinding() {} -func (s *DNSService) GetDNSPolicyDNSPolicyLabelBinding() {} -func (s *DNSService) CountDNSPolicyDNSPolicyLabelBinding() {} +func (s *DNSService) GetAllDNSPolicyDNSPolicyLabelBinding() ([]models.DNSPolicyDNSPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsPolicyDNSPolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSPolicyDNSPolicyLabelBinding `json:"dnspolicy_dnspolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSPolicyDNSPolicyLabelBinding(name string) ([]models.DNSPolicyDNSPolicyLabelBinding, error) { + reqURL := fmt.Sprintf("%s/%s", dnsPolicyDNSPolicyLabelBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSPolicyDNSPolicyLabelBinding `json:"dnspolicy_dnspolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSPolicyDNSPolicyLabelBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", dnsPolicyDNSPolicyLabelBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnspolicy_dnspolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnsprofile -func (s *DNSService) AddDNSProfile() {} -func (s *DNSService) DeleteDNSProfile() {} -func (s *DNSService) UpdateDNSProfile() {} -func (s *DNSService) UnsetDNSProfile() {} -func (s *DNSService) GetAllDNSProfile() {} -func (s *DNSService) GetDNSProfile() {} -func (s *DNSService) CountDNSProfile() {} +func (s *DNSService) AddDNSProfile(profile models.DNSProfile) error { + payload := map[string]any{"dnsprofile": profile} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) DeleteDNSProfile(name string) error { + reqURL := fmt.Sprintf("%s/%s", dnsProfileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) UpdateDNSProfile(profile models.DNSProfile) error { + payload := map[string]any{"dnsprofile": profile} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, dnsProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) UnsetDNSProfile(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"dnsprofile": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsProfileURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) GetAllDNSProfile() ([]models.DNSProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsProfileURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSProfile `json:"dnsprofile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSProfile(name string) ([]models.DNSProfile, error) { + reqURL := fmt.Sprintf("%s/%s", dnsProfileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSProfile `json:"dnsprofile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSProfile() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsProfileURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnsprofile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnsproxyrecords -func (s *DNSService) FlushDNSProxyRecords() {} +func (s *DNSService) FlushDNSProxyRecords() error { + req, err := s.client.NewRequest(http.MethodPost, dnsProxyRecordsURL+"?action=flush", nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} // dnsptrrec -func (s *DNSService) AddDNSPTRRec() {} -func (s *DNSService) DeleteDNSPTRRec() {} -func (s *DNSService) GetAllDNSPTRRec() {} -func (s *DNSService) GetDNSPTRRec() {} -func (s *DNSService) CountDNSPTRRec() {} +func (s *DNSService) AddDNSPTRRec(rec models.DNSPtrRec) error { + payload := map[string]any{"dnsptrrec": rec} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsPTRRecURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) DeleteDNSPTRRec(reverseDomain string) error { + reqURL := fmt.Sprintf("%s/%s", dnsPTRRecURL, url.QueryEscape(reverseDomain)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) GetAllDNSPTRRec() ([]models.DNSPtrRec, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsPTRRecURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSPtrRec `json:"dnsptrrec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSPTRRec(reverseDomain string) ([]models.DNSPtrRec, error) { + reqURL := fmt.Sprintf("%s/%s", dnsPTRRecURL, url.QueryEscape(reverseDomain)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSPtrRec `json:"dnsptrrec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSPTRRec() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsPTRRecURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnsptrrec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnssoarec -func (s *DNSService) AddDNSSOARec() {} -func (s *DNSService) DeleteDNSSOARec() {} -func (s *DNSService) UpdateDNSSOARec() {} -func (s *DNSService) UnsetDNSSOARec() {} -func (s *DNSService) GetAllDNSSOARec() {} -func (s *DNSService) GetDNSSOARec() {} -func (s *DNSService) CountDNSSOARec() {} +func (s *DNSService) AddDNSSOARec(rec models.DNSSOARec) error { + payload := map[string]any{"dnssoarec": rec} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsSOARecURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) DeleteDNSSOARec(domain string) error { + reqURL := fmt.Sprintf("%s/%s", dnsSOARecURL, url.QueryEscape(domain)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) UpdateDNSSOARec(rec models.DNSSOARec) error { + payload := map[string]any{"dnssoarec": rec} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, dnsSOARecURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) UnsetDNSSOARec(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"dnssoarec": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsSOARecURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) GetAllDNSSOARec() ([]models.DNSSOARec, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsSOARecURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSSOARec `json:"dnssoarec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSSOARec(domain string) ([]models.DNSSOARec, error) { + reqURL := fmt.Sprintf("%s/%s", dnsSOARecURL, url.QueryEscape(domain)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSSOARec `json:"dnssoarec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSSOARec() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsSOARecURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnssoarec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnssrvrec -func (s *DNSService) AddDNSSRVRec() {} -func (s *DNSService) DeleteDNSSRVRec() {} -func (s *DNSService) UpdateDNSSRVRec() {} -func (s *DNSService) UnsetDNSSRVRec() {} -func (s *DNSService) GetAllDNSSRVRec() {} -func (s *DNSService) CountDNSSRVRec() {} +func (s *DNSService) AddDNSSRVRec(rec models.DNSSrvRec) error { + payload := map[string]any{"dnssrvrec": rec} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsSRVRecURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) DeleteDNSSRVRec(domain string) error { + reqURL := fmt.Sprintf("%s/%s", dnsSRVRecURL, url.QueryEscape(domain)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) UpdateDNSSRVRec(rec models.DNSSrvRec) error { + payload := map[string]any{"dnssrvrec": rec} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, dnsSRVRecURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) UnsetDNSSRVRec(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"dnssrvrec": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsSRVRecURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) GetAllDNSSRVRec() ([]models.DNSSrvRec, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsSRVRecURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSSrvRec `json:"dnssrvrec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSSRVRec() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsSRVRecURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnssrvrec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnssubnetcache -func (s *DNSService) FlushDNSSubnetCache() {} -func (s *DNSService) GetAllDNSSubnetCache() {} -func (s *DNSService) GetDNSSubnetCache() {} -func (s *DNSService) CountDNSSubnetCache() {} +func (s *DNSService) FlushDNSSubnetCache() error { + req, err := s.client.NewRequest(http.MethodPost, dnsSubnetCacheURL+"?action=flush", nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) GetAllDNSSubnetCache() ([]models.DNSSubnetCache, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsSubnetCacheURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSSubnetCache `json:"dnssubnetcache"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSSubnetCache(hostname string) ([]models.DNSSubnetCache, error) { + reqURL := fmt.Sprintf("%s/%s", dnsSubnetCacheURL, url.QueryEscape(hostname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSSubnetCache `json:"dnssubnetcache"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSSubnetCache() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsSubnetCacheURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnssubnetcache"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnssuffix -func (s *DNSService) AddDNSSuffix() {} -func (s *DNSService) DeleteDNSSuffix() {} -func (s *DNSService) GetAllDNSSuffix() {} -func (s *DNSService) GetDNSSuffix() {} -func (s *DNSService) CountDNSSuffix() {} +func (s *DNSService) AddDNSSuffix(suffix models.DNSSuffix) error { + payload := map[string]any{"dnssuffix": suffix} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsSuffixURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) DeleteDNSSuffix(suffix string) error { + reqURL := fmt.Sprintf("%s/%s", dnsSuffixURL, url.QueryEscape(suffix)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) GetAllDNSSuffix() ([]models.DNSSuffix, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsSuffixURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSSuffix `json:"dnssuffix"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSSuffix(suffix string) ([]models.DNSSuffix, error) { + reqURL := fmt.Sprintf("%s/%s", dnsSuffixURL, url.QueryEscape(suffix)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSSuffix `json:"dnssuffix"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSSuffix() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsSuffixURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnssuffix"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnstxtrec -func (s *DNSService) AddDNSTXTRec() {} -func (s *DNSService) DeleteDNSTXTRec() {} -func (s *DNSService) GetAllDNSTXTRec() {} -func (s *DNSService) GetDNSTXTRec() {} -func (s *DNSService) CountDNSTXTRec() {} +func (s *DNSService) AddDNSTXTRec(rec models.DNSTxtRec) error { + payload := map[string]any{"dnstxtrec": rec} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsTXTRecURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) DeleteDNSTXTRec(domain string) error { + reqURL := fmt.Sprintf("%s/%s", dnsTXTRecURL, url.QueryEscape(domain)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) GetAllDNSTXTRec() ([]models.DNSTxtRec, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsTXTRecURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSTxtRec `json:"dnstxtrec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSTXTRec(domain string) ([]models.DNSTxtRec, error) { + reqURL := fmt.Sprintf("%s/%s", dnsTXTRecURL, url.QueryEscape(domain)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSTxtRec `json:"dnstxtrec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSTXTRec() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsTXTRecURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnstxtrec"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnsview -func (s *DNSService) AddDNSView() {} -func (s *DNSService) DeleteDNSView() {} -func (s *DNSService) GetAllDNSView() {} -func (s *DNSService) GetDNSView() {} -func (s *DNSService) CountDNSView() {} +func (s *DNSService) AddDNSView(view models.DNSView) error { + payload := map[string]any{"dnsview": view} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsViewURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) DeleteDNSView(viewName string) error { + reqURL := fmt.Sprintf("%s/%s", dnsViewURL, url.QueryEscape(viewName)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) GetAllDNSView() ([]models.DNSView, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsViewURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSView `json:"dnsview"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSView(viewName string) ([]models.DNSView, error) { + reqURL := fmt.Sprintf("%s/%s", dnsViewURL, url.QueryEscape(viewName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSView `json:"dnsview"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSView() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsViewURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnsview"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnsview_binding -func (s *DNSService) GetAllDNSViewBinding() {} -func (s *DNSService) GetDNSViewBinding() {} +func (s *DNSService) GetAllDNSViewBinding() ([]models.DNSViewBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsViewBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSViewBinding `json:"dnsview_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSViewBinding(viewName string) ([]models.DNSViewBinding, error) { + reqURL := fmt.Sprintf("%s/%s", dnsViewBindingURL, url.QueryEscape(viewName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSViewBinding `json:"dnsview_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} // dnsview_dnspolicy_binding -func (s *DNSService) GetAllDNSViewDNSPolicyBinding() {} -func (s *DNSService) GetDNSViewDNSPolicyBinding() {} -func (s *DNSService) CountDNSViewDNSPolicyBinding() {} +func (s *DNSService) GetAllDNSViewDNSPolicyBinding() ([]models.DNSViewDNSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsViewDNSPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSViewDNSPolicyBinding `json:"dnsview_dnspolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSViewDNSPolicyBinding(viewName string) ([]models.DNSViewDNSPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", dnsViewDNSPolicyBindingURL, url.QueryEscape(viewName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSViewDNSPolicyBinding `json:"dnsview_dnspolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSViewDNSPolicyBinding(viewName string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", dnsViewDNSPolicyBindingURL, url.QueryEscape(viewName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnsview_dnspolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnsview_gslbservice_binding -func (s *DNSService) GetAllDNSViewGSLBServiceBinding() {} -func (s *DNSService) GetDNSViewGSLBServiceBinding() {} -func (s *DNSService) CountDNSViewGSLBServiceBinding() {} +func (s *DNSService) GetAllDNSViewGSLBServiceBinding() ([]models.DNSViewGSLBServiceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsViewGSLBServiceBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSViewGSLBServiceBinding `json:"dnsview_gslbservice_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSViewGSLBServiceBinding(viewName string) ([]models.DNSViewGSLBServiceBinding, error) { + reqURL := fmt.Sprintf("%s/%s", dnsViewGSLBServiceBindingURL, url.QueryEscape(viewName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSViewGSLBServiceBinding `json:"dnsview_gslbservice_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSViewGSLBServiceBinding(viewName string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", dnsViewGSLBServiceBindingURL, url.QueryEscape(viewName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnsview_gslbservice_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnszone -func (s *DNSService) AddDNSZone() {} -func (s *DNSService) DeleteDNSZone() {} -func (s *DNSService) UpdateDNSZone() {} -func (s *DNSService) UnsetDNSZone() {} -func (s *DNSService) SignDNSZone() {} -func (s *DNSService) UnsignDNSZone() {} -func (s *DNSService) GetAllDNSZone() {} -func (s *DNSService) GetDNSZone() {} -func (s *DNSService) CountDNSZone() {} +func (s *DNSService) AddDNSZone(zone models.DNSZone) error { + payload := map[string]any{"dnszone": zone} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsZoneURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) DeleteDNSZone(zoneName string) error { + reqURL := fmt.Sprintf("%s/%s", dnsZoneURL, url.QueryEscape(zoneName)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) UpdateDNSZone(zone models.DNSZone) error { + payload := map[string]any{"dnszone": zone} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, dnsZoneURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) UnsetDNSZone(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"dnszone": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsZoneURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) SignDNSZone(zone models.DNSZone) error { + payload := map[string]any{"dnszone": zone} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsZoneURL+"?action=sign", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) UnsignDNSZone(zone models.DNSZone) error { + payload := map[string]any{"dnszone": zone} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, dnsZoneURL+"?action=unsign", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *DNSService) GetAllDNSZone() ([]models.DNSZone, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsZoneURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSZone `json:"dnszone"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSZone(zoneName string) ([]models.DNSZone, error) { + reqURL := fmt.Sprintf("%s/%s", dnsZoneURL, url.QueryEscape(zoneName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSZone `json:"dnszone"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSZone() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsZoneURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnszone"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnszone_binding -func (s *DNSService) GetAllDNSZoneBinding() {} -func (s *DNSService) GetDNSZoneBinding() {} +func (s *DNSService) GetAllDNSZoneBinding() ([]models.DNSZoneBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsZoneBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSZoneBinding `json:"dnszone_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSZoneBinding(zoneName string) ([]models.DNSZoneBinding, error) { + reqURL := fmt.Sprintf("%s/%s", dnsZoneBindingURL, url.QueryEscape(zoneName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSZoneBinding `json:"dnszone_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} // dnszone_dnskey_binding -func (s *DNSService) GetAllDNSZoneDNSKeyBinding() {} -func (s *DNSService) GetDNSZoneDNSKeyBinding() {} -func (s *DNSService) CountDNSZoneDNSKeyBinding() {} +func (s *DNSService) GetAllDNSZoneDNSKeyBinding() ([]models.DNSZoneDNSKeyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsZoneDNSKeyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSZoneDNSKeyBinding `json:"dnszone_dnskey_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSZoneDNSKeyBinding(zoneName string) ([]models.DNSZoneDNSKeyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", dnsZoneDNSKeyBindingURL, url.QueryEscape(zoneName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSZoneDNSKeyBinding `json:"dnszone_dnskey_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSZoneDNSKeyBinding(zoneName string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", dnsZoneDNSKeyBindingURL, url.QueryEscape(zoneName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnszone_dnskey_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // dnszone_domain_binding -func (s *DNSService) GetAllDNSZoneDomainBinding() {} -func (s *DNSService) GetDNSZoneDomainBinding() {} -func (s *DNSService) CountDNSZoneDomainBinding() {} +func (s *DNSService) GetAllDNSZoneDomainBinding() ([]models.DNSZoneDomainBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, dnsZoneDomainBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSZoneDomainBinding `json:"dnszone_domain_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) GetDNSZoneDomainBinding(zoneName string) ([]models.DNSZoneDomainBinding, error) { + reqURL := fmt.Sprintf("%s/%s", dnsZoneDomainBindingURL, url.QueryEscape(zoneName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.DNSZoneDomainBinding `json:"dnszone_domain_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *DNSService) CountDNSZoneDomainBinding(zoneName string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", dnsZoneDomainBindingURL, url.QueryEscape(zoneName)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"dnszone_domain_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} diff --git a/nitrogo/feo.go b/nitrogo/feo.go index 47f5857..06846cf 100644 --- a/nitrogo/feo.go +++ b/nitrogo/feo.go @@ -1,5 +1,27 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + feoActionURL = "/nitro/v1/config/feoaction" + feoGlobalBindingURL = "/nitro/v1/config/feoglobal_binding" + feoGlobalFEOPolicyBindingURL = "/nitro/v1/config/feoglobal_feopolicy_binding" + feoParameterURL = "/nitro/v1/config/feoparameter" + feoPolicyURL = "/nitro/v1/config/feopolicy" + feoPolicyBindingURL = "/nitro/v1/config/feopolicy_binding" + feoPolicyCSVServerBindingURL = "/nitro/v1/config/feopolicy_csvserver_binding" + feoPolicyFEOGlobalBindingURL = "/nitro/v1/config/feopolicy_feoglobal_binding" + feoPolicyLBVServerBindingURL = "/nitro/v1/config/feopolicy_lbvserver_binding" +) + // Front end optimization configuration. The system’s feature to optimize Web content for performance. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/feo/feo type FEOService struct { @@ -9,68 +31,777 @@ type FEOService struct { // feoaction // Configuration for Front end optimization action resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/feo/feoaction -func (s *FEOService) AddFEOAction() {} -func (s *FEOService) DeleteFEOAction() {} -func (s *FEOService) UpdateFEOAction() {} -func (s *FEOService) UnsetFEOAction() {} -func (s *FEOService) GetAllFEOAction() {} -func (s *FEOService) GetFEOAction() {} -func (s *FEOService) CountFEOAction() {} + +func (s *FEOService) AddFEOAction(action models.FEOAction) error { + payload := map[string]any{ + "feoaction": action, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, feoActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *FEOService) DeleteFEOAction(name string) error { + urlReq := fmt.Sprintf("%s/%s", feoActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *FEOService) UpdateFEOAction(action models.FEOAction) error { + payload := map[string]any{ + "feoaction": action, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, feoActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *FEOService) UnsetFEOAction(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "feoaction": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, feoActionURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *FEOService) GetAllFEOAction() ([]models.FEOAction, error) { + req, err := s.client.NewRequest(http.MethodGet, feoActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Actions []models.FEOAction `json:"feoaction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Actions, nil +} + +func (s *FEOService) GetFEOAction(name string) ([]models.FEOAction, error) { + urlReq := fmt.Sprintf("%s/%s", feoActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Actions []models.FEOAction `json:"feoaction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Actions, nil +} + +func (s *FEOService) CountFEOAction() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, feoActionURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Actions []struct { + Count float64 `json:"__count"` + } `json:"feoaction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Actions) > 0 { + return result.Actions[0].Count, nil + } + + return 0, nil +} // feoglobal_binding // Binding object which returns the resources bound to feoglobal. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/feo/feoglobal_binding -func (s *FEOService) GetFEOGlobalBinding() {} + +func (s *FEOService) GetFEOGlobalBinding() ([]models.FEOGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, feoGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.FEOGlobalBinding `json:"feoglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} // feoglobal_feopolicy_binding // Binding object showing the feopolicy that can be bound to feoglobal. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/feo/feoglobal_feopolicy_binding -func (s *FEOService) AddFEOGlobalFEOPolicyBinding() {} -func (s *FEOService) DeleteFEOGlobalFEOPolicyBinding() {} -func (s *FEOService) GetFEOGlobalFEOPolicyBinding() {} -func (s *FEOService) CountFEOGlobalFEOPolicyBinding() {} + +func (s *FEOService) AddFEOGlobalFEOPolicyBinding(binding models.FEOGlobalFEOPolicyBinding) error { + payload := map[string]any{ + "feoglobal_feopolicy_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, feoGlobalFEOPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *FEOService) DeleteFEOGlobalFEOPolicyBinding(policyname string) error { + urlReq := fmt.Sprintf("%s?args=policyname:%s", feoGlobalFEOPolicyBindingURL, url.QueryEscape(policyname)) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *FEOService) GetFEOGlobalFEOPolicyBinding() ([]models.FEOGlobalFEOPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, feoGlobalFEOPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.FEOGlobalFEOPolicyBinding `json:"feoglobal_feopolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *FEOService) CountFEOGlobalFEOPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, feoGlobalFEOPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"feoglobal_feopolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} // feoparameter // Configuration for FEO parameter resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/feo/feoparameter -func (s *FEOService) UpdateFEOParameter() {} -func (s *FEOService) UnsetFEOParameter() {} -func (s *FEOService) GetAllFEOParameter() {} + +func (s *FEOService) UpdateFEOParameter(param models.FEOParameter) error { + payload := map[string]any{ + "feoparameter": param, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, feoParameterURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *FEOService) UnsetFEOParameter(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "feoparameter": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, feoParameterURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *FEOService) GetAllFEOParameter() (models.FEOParameter, error) { + req, err := s.client.NewRequest(http.MethodGet, feoParameterURL, nil) + if err != nil { + return models.FEOParameter{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.FEOParameter{}, err + } + + var result struct { + Parameters []models.FEOParameter `json:"feoparameter"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.FEOParameter{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Parameters) > 0 { + return result.Parameters[0], nil + } + + return models.FEOParameter{}, nil +} // feopolicy // Configuration for Front end optimization policy resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/feo/feopolicy -func (s *FEOService) AddFEOPolicy() {} -func (s *FEOService) DeleteFEOPolicy() {} -func (s *FEOService) UpdateFEOPolicy() {} -func (s *FEOService) UnsetFEOPolicy() {} -func (s *FEOService) GetAllFEOPolicy() {} -func (s *FEOService) GetFEOPolicy() {} -func (s *FEOService) CountFEOPolicy() {} + +func (s *FEOService) AddFEOPolicy(policy models.FEOPolicy) error { + payload := map[string]any{ + "feopolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, feoPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *FEOService) DeleteFEOPolicy(name string) error { + urlReq := fmt.Sprintf("%s/%s", feoPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *FEOService) UpdateFEOPolicy(policy models.FEOPolicy) error { + payload := map[string]any{ + "feopolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, feoPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *FEOService) UnsetFEOPolicy(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "feopolicy": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, feoPolicyURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *FEOService) GetAllFEOPolicy() ([]models.FEOPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, feoPolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Policies []models.FEOPolicy `json:"feopolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Policies, nil +} + +func (s *FEOService) GetFEOPolicy(name string) ([]models.FEOPolicy, error) { + urlReq := fmt.Sprintf("%s/%s", feoPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Policies []models.FEOPolicy `json:"feopolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Policies, nil +} + +func (s *FEOService) CountFEOPolicy() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, feoPolicyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Policies []struct { + Count float64 `json:"__count"` + } `json:"feopolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Policies) > 0 { + return result.Policies[0].Count, nil + } + + return 0, nil +} // feopolicy_binding // Binding object which returns the resources bound to feopolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/feo/feopolicy_binding -func (s *FEOService) GetAllFEOPolicyBinding() {} -func (s *FEOService) GetFEOPolicyBinding() {} + +func (s *FEOService) GetAllFEOPolicyBinding() ([]models.FEOPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, feoPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.FEOPolicyBinding `json:"feopolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *FEOService) GetFEOPolicyBinding(name string) ([]models.FEOPolicyBinding, error) { + urlReq := fmt.Sprintf("%s/%s", feoPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.FEOPolicyBinding `json:"feopolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} // feopolicy_csvserver_binding // Binding object showing the csvserver that can be bound to feopolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/feo/feopolicy_csvserver_binding -func (s *FEOService) GetAllFEOPolicyCSVServerBinding() {} -func (s *FEOService) GetFEOPolicyCSVServerBinding() {} -func (s *FEOService) CountFEOPolicyCSVServerBinding() {} + +func (s *FEOService) GetAllFEOPolicyCSVServerBinding() ([]models.FEOPolicyCSVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, feoPolicyCSVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.FEOPolicyCSVServerBinding `json:"feopolicy_csvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *FEOService) GetFEOPolicyCSVServerBinding(name string) ([]models.FEOPolicyCSVServerBinding, error) { + urlReq := fmt.Sprintf("%s/%s", feoPolicyCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.FEOPolicyCSVServerBinding `json:"feopolicy_csvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *FEOService) CountFEOPolicyCSVServerBinding(name string) (float64, error) { + urlReq := fmt.Sprintf("%s/%s?count=yes", feoPolicyCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"feopolicy_csvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} // feopolicy_feoglobal_binding // Binding object showing the feoglobal that can be bound to feopolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/feo/feopolicy_feoglobal_binding -func (s *FEOService) GetAllFEOPolicyFEOGlobalBinding() {} -func (s *FEOService) GetFEOPolicyFEOGlobalBinding() {} -func (s *FEOService) CountFEOPolicyFEOGlobalBinding() {} + +func (s *FEOService) GetAllFEOPolicyFEOGlobalBinding() ([]models.FEOPolicyFEOGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, feoPolicyFEOGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.FEOPolicyFEOGlobalBinding `json:"feopolicy_feoglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *FEOService) GetFEOPolicyFEOGlobalBinding(name string) ([]models.FEOPolicyFEOGlobalBinding, error) { + urlReq := fmt.Sprintf("%s/%s", feoPolicyFEOGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.FEOPolicyFEOGlobalBinding `json:"feopolicy_feoglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *FEOService) CountFEOPolicyFEOGlobalBinding(name string) (float64, error) { + urlReq := fmt.Sprintf("%s/%s?count=yes", feoPolicyFEOGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"feopolicy_feoglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} // feopolicy_lbvserver_binding // Binding object showing the lbvserver that can be bound to feopolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/feo/feopolicy_lbvserver_binding -func (s *FEOService) GetAllFEOPolicyLBVServerBinding() {} -func (s *FEOService) GetFEOPolicyLBVServerBinding() {} -func (s *FEOService) CountFEOPolicyLBVServerBinding() {} + +func (s *FEOService) GetAllFEOPolicyLBVServerBinding() ([]models.FEOPolicyLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, feoPolicyLBVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.FEOPolicyLBVServerBinding `json:"feopolicy_lbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *FEOService) GetFEOPolicyLBVServerBinding(name string) ([]models.FEOPolicyLBVServerBinding, error) { + urlReq := fmt.Sprintf("%s/%s", feoPolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.FEOPolicyLBVServerBinding `json:"feopolicy_lbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *FEOService) CountFEOPolicyLBVServerBinding(name string) (float64, error) { + urlReq := fmt.Sprintf("%s/%s?count=yes", feoPolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"feopolicy_lbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} diff --git a/nitrogo/glsb.go b/nitrogo/glsb.go deleted file mode 100644 index 77320ee..0000000 --- a/nitrogo/glsb.go +++ /dev/null @@ -1,205 +0,0 @@ -package nitrogo - -// Global Server Load Balancing (GSLB) configuration. GSLB feature ensures that client requests are -// directed to a best performing site available in a global enterprise and distributed Internet environment. -// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/gslb/gslb -type GLSBService struct { - client *Client -} - -// gslbconfig -func (s *GLSBService) SyncGSLBConfig() {} - -// gslbdomain -func (s *GLSBService) GetAllGSLBDomain() {} -func (s *GLSBService) GetGSLBDomain() {} -func (s *GLSBService) CountGSLBDomain() {} - -// gslbdomain_binding -func (s *GLSBService) GetAllGSLBDomainBinding() {} -func (s *GLSBService) GetGSLBDomainBinding() {} - -// dslbdomain_gslbservicegroupmember_binding -func (s *GLSBService) GetAllGSLBDomainGSLBServiceGroupMemberBinding() {} -func (s *GLSBService) GetGSLBDomainGSLBServiceGroupMemberBinding() {} -func (s *GLSBService) CountGSLBDomainGSLBServiceGroupMemberBinding() {} - -// gslbdomain_gslbservicegroup_binding -func (s *GLSBService) GetAllGSLBDomainGSLBServiceGroupBinding() {} -func (s *GLSBService) GetGSLBDomainGSLBServiceGroupBinding() {} -func (s *GLSBService) CountGSLBDomainGSLBServiceGroupBinding() {} - -// dslbdomain_gslbservice_binding -func (s *GLSBService) GetAllGSLBDomainGSLBServiceBinding() {} -func (s *GLSBService) GetGSLBDomainGSLBServiceBinding() {} -func (s *GLSBService) CountGSLBDomainGSLBServiceBinding() {} - -// gslbdomain_gslbvserver_binding -func (s *GLSBService) GetAllGSLBDomainGSLBVServerBinding() {} -func (s *GLSBService) GetGSLBDomainGSLBVServerBinding() {} -func (s *GLSBService) CountGSLBDomainGSLBVServerBinding() {} - -// gslbdomain_lbmonitor_binding -func (s *GLSBService) GetAllGSLBDomainLBMonitorBinding() {} -func (s *GLSBService) GetGSLBDomainLBMonitorBinding() {} -func (s *GLSBService) CountGSLBDomainLBMonitorBinding() {} - -// gslbdnsentries -func (s *GLSBService) ClearGSLBDNSEntries() {} -func (s *GLSBService) GetAllGSLBDNSEntries() {} -func (s *GLSBService) CountGSLBDNSEntries() {} - -// gslbdnsentry -func (s *GLSBService) DeleteGSLBDNSEntry() {} - -// gslbparameter -func (s *GLSBService) UpdateGSLBParameter() {} -func (s *GLSBService) UnsetGSLBParameter() {} -func (s *GLSBService) GetAllGSLBParameter() {} - -// gslbrunningconfig -func (s *GLSBService) GetAllGSLBRunningConfig() {} - -// gslbservice -func (s *GLSBService) AddGSLBService() {} -func (s *GLSBService) DeleteGSLBService() {} -func (s *GLSBService) UpdateGSLBService() {} -func (s *GLSBService) UnsetGSLBService() {} -func (s *GLSBService) GetAllGSLBService() {} -func (s *GLSBService) GetGSLBService() {} -func (s *GLSBService) CountGSLBService() {} -func (s *GLSBService) RenameGSLBService() {} - -// gslbservicegroup -func (s *GLSBService) AddGSLBServiceGroup() {} -func (s *GLSBService) DeleteGSLBServiceGroup() {} -func (s *GLSBService) UpdateGSLBServiceGroup() {} -func (s *GLSBService) UnsetGSLBServiceGroup() {} -func (s *GLSBService) EnableGSLBServiceGroup() {} -func (s *GLSBService) DisableGSLBServiceGroup() {} -func (s *GLSBService) GetAllGSLBServiceGroup() {} -func (s *GLSBService) GetGSLBServiceGroup() {} -func (s *GLSBService) CountGSLBServiceGroup() {} -func (s *GLSBService) RenameGSLBServiceGroup() {} - -// gslbservicegroup_binding -func (s *GLSBService) GetAllGSLBServiceGroupBinding() {} -func (s *GLSBService) GetGSLBServiceGroupBinding() {} - -// gslbservicegroup_gslbservicegroupmember_binding -func (s *GLSBService) AddGSLBServiceGroupGSLBServiceGroupMemberBinding() {} -func (s *GLSBService) DeleteGSLBServiceGroupGSLBServiceGroupMemberBinding() {} -func (s *GLSBService) GetAllGSLBServiceGroupGSLBServiceGroupMemberBinding() {} -func (s *GLSBService) GetGSLBServiceGroupGSLBServiceGroupMemberBinding() {} -func (s *GLSBService) CountGSLBServiceGroupGSLBServiceGroupMemberBinding() {} - -// gslbservicegroup_lbmonitor_binding -func (s *GLSBService) AddGSLBServiceGroupLBMonitorBinding() {} -func (s *GLSBService) DeleteGSLBServiceGroupLBMonitorBinding() {} -func (s *GLSBService) GetAllGSLBServiceGroupLBMonitorBinding() {} -func (s *GLSBService) GetGSLBServiceGroupLBMonitorBinding() {} -func (s *GLSBService) CountGSLBServiceGroupLBMonitorBinding() {} - -// gslbservicegroup_servicegroupentitymonbindings_binding -func (s *GLSBService) GetAllGSLBServiceGroupServiceGroupEntityMonBindingsBinding() {} -func (s *GLSBService) GetGSLBServiceGroupServiceGroupEntityMonBindingsBinding() {} -func (s *GLSBService) CountGSLBServiceGroupServiceGroupEntityMonBindingsBinding() {} - -// gslbservice_binding -func (s *GLSBService) GetAllGSLBServiceBinding() {} -func (s *GLSBService) GetGSLBServiceBinding() {} - -// gslbservice_dnsview_binding -func (s *GLSBService) AddGSLBServiceDNSViewBinding() {} -func (s *GLSBService) DeleteGSLBServiceDNSViewBinding() {} -func (s *GLSBService) GetAllGSLBServiceDNSViewBinding() {} -func (s *GLSBService) GetGSLBServiceDNSViewBinding() {} -func (s *GLSBService) CountGSLBServiceDNSViewBinding() {} - -// dslbservice_lbmonitor_binding -func (s *GLSBService) AddGSLBServiceLBMonitorBinding() {} -func (s *GLSBService) DeleteGSLBServiceLBMonitorBinding() {} -func (s *GLSBService) GetAllGSLBServiceLBMonitorBinding() {} -func (s *GLSBService) GetGSLBServiceLBMonitorBinding() {} -func (s *GLSBService) CountGSLBServiceLBMonitorBinding() {} - -// gslbsite -func (s *GLSBService) AddGSLBSite() {} -func (s *GLSBService) DeleteGSLBSite() {} -func (s *GLSBService) UpdateGSLBSite() {} -func (s *GLSBService) UnsetGSLBSite() {} -func (s *GLSBService) GetAllGSLBSite() {} -func (s *GLSBService) GetGSLBSite() {} -func (s *GLSBService) CountGSLBSite() {} -func (s *GLSBService) RenameGSLBSite() {} - -// gslbsite_binding -func (s *GLSBService) GetAllGSLBSiteBinding() {} -func (s *GLSBService) GetGSLBSiteBinding() {} - -// gslbsite_gslbservicegroupmember_binding -func (s *GLSBService) GetAllGSLBSiteGSLBServiceGroupMemberBinding() {} -func (s *GLSBService) GetGSLBSiteGSLBServiceGroupMemberBinding() {} -func (s *GLSBService) CountGSLBSiteGSLBServiceGroupMemberBinding() {} - -// gslbsite_gslbservicegroup_binding -func (s *GLSBService) GetAllGSLBSiteGSLBServiceGroupBinding() {} -func (s *GLSBService) GetGSLBSiteGSLBServiceGroupBinding() {} -func (s *GLSBService) CountGSLBSiteGSLBServiceGroupBinding() {} - -// gslbsite_gslbservice_binding -func (s *GLSBService) GetAllGSLBSiteGSLBServiceBinding() {} -func (s *GLSBService) GetGSLBSiteGSLBServiceBinding() {} -func (s *GLSBService) CountGSLBSiteGSLBServiceBinding() {} - -// gslbsyncstatus -func (s *GLSBService) GetAllGSLBSyncStatus() {} - -// gslbvserver -func (s *GLSBService) AddGSLBVServer() {} -func (s *GLSBService) DeleteGSLBVServer() {} -func (s *GLSBService) UpdateGSLBVServer() {} -func (s *GLSBService) UnsetGSLBVServer() {} -func (s *GLSBService) EnableGSLBVServer() {} -func (s *GLSBService) DisableGSLBVServer() {} -func (s *GLSBService) GetAllGSLBVServer() {} -func (s *GLSBService) GetGSLBVServer() {} -func (s *GLSBService) CountGSLBVServer() {} -func (s *GLSBService) RenameGSLBVServer() {} - -// gslbvserver_binding -func (s *GLSBService) GetAllGSLBVServerBinding() {} -func (s *GLSBService) GetGSLBVServerBinding() {} - -// gslbvserver_domain_binding -func (s *GLSBService) AddGSLBVServerDomainBinding() {} -func (s *GLSBService) DeleteGSLBVServerDomainBinding() {} -func (s *GLSBService) GetAllGSLBVServerDomainBinding() {} -func (s *GLSBService) GetGSLBVServerDomainBinding() {} -func (s *GLSBService) CountGSLBVServerDomainBinding() {} - -// gslbvserver_gslbservicegroupmember_binding -func (s *GLSBService) GetAllGSLBVServerGSLBServiceGroupMemberBinding() {} -func (s *GLSBService) GetGSLBVServerGSLBServiceGroupMemberBinding() {} -func (s *GLSBService) CountGSLBVServerGSLBServiceGroupMemberBinding() {} - -// gslbvserver_gslbservicegroup_binding -func (s *GLSBService) AddGSLBVServerGSLBServiceGroupBinding() {} -func (s *GLSBService) DeleteGSLBVServerGSLBServiceGroupBinding() {} -func (s *GLSBService) GetAllGSLBVServerGSLBServiceGroupBinding() {} -func (s *GLSBService) GetGSLBVServerGSLBServiceGroupBinding() {} -func (s *GLSBService) CountGSLBVServerGSLBServiceGroupBinding() {} - -// gslbvserver_gslbservice_binding -func (s *GLSBService) AddGSLBVServerGSLBServiceBinding() {} -func (s *GLSBService) DeleteGSLBVServerGSLBServiceBinding() {} -func (s *GLSBService) GetAllGSLBVServerGSLBServiceBinding() {} -func (s *GLSBService) GetGSLBVServerGSLBServiceBinding() {} -func (s *GLSBService) CountGSLBVServerGSLBServiceBinding() {} - -// gslbvserver_spilloverpolicy_binding -func (s *GLSBService) AddGSLBVServerSpilloverPolicyBinding() {} -func (s *GLSBService) DeleteGSLBVServerSpilloverPolicyBinding() {} -func (s *GLSBService) GetAllGSLBVServerSpilloverPolicyBinding() {} -func (s *GLSBService) GetGSLBVServerSpilloverPolicyBinding() {} -func (s *GLSBService) CountGSLBVServerSpilloverPolicyBinding() {} diff --git a/nitrogo/gslb.go b/nitrogo/gslb.go new file mode 100644 index 0000000..76f9b71 --- /dev/null +++ b/nitrogo/gslb.go @@ -0,0 +1,2998 @@ +package nitrogo + +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + gslbConfigURL = "/nitro/v1/config/gslbconfig" + gslbDomainURL = "/nitro/v1/config/gslbdomain" + gslbDomainBindingURL = "/nitro/v1/config/gslbdomain_binding" + gslbDomainGSLBServiceGroupMemberBindingURL = "/nitro/v1/config/gslbdomain_gslbservicegroupmember_binding" + gslbDomainGSLBServiceGroupBindingURL = "/nitro/v1/config/gslbdomain_gslbservicegroup_binding" + gslbDomainGSLBServiceBindingURL = "/nitro/v1/config/gslbdomain_gslbservice_binding" + gslbDomainGSLBVServerBindingURL = "/nitro/v1/config/gslbdomain_gslbvserver_binding" + gslbDomainLBMonitorBindingURL = "/nitro/v1/config/gslbdomain_lbmonitor_binding" + gslbDNSEntriesURL = "/nitro/v1/config/gslbdnsentries" + gslbDNSEntryURL = "/nitro/v1/config/gslbdnsentry" + gslbParameterURL = "/nitro/v1/config/gslbparameter" + gslbRunningConfigURL = "/nitro/v1/config/gslbrunningconfig" + gslbServiceURL = "/nitro/v1/config/gslbservice" + gslbServiceGroupURL = "/nitro/v1/config/gslbservicegroup" + gslbServiceGroupBindingURL = "/nitro/v1/config/gslbservicegroup_binding" + gslbServiceGroupGSLBServiceGroupMemberBindingURL = "/nitro/v1/config/gslbservicegroup_gslbservicegroupmember_binding" + gslbServiceGroupLBMonitorBindingURL = "/nitro/v1/config/gslbservicegroup_lbmonitor_binding" + gslbServiceGroupServiceGroupEntityMonBindingsBindingURL = "/nitro/v1/config/gslbservicegroup_servicegroupentitymonbindings_binding" + gslbServiceBindingURL = "/nitro/v1/config/gslbservice_binding" + gslbServiceDNSViewBindingURL = "/nitro/v1/config/gslbservice_dnsview_binding" + gslbServiceLBMonitorBindingURL = "/nitro/v1/config/gslbservice_lbmonitor_binding" + gslbSiteURL = "/nitro/v1/config/gslbsite" + gslbSiteBindingURL = "/nitro/v1/config/gslbsite_binding" + gslbSiteGSLBServiceGroupMemberBindingURL = "/nitro/v1/config/gslbsite_gslbservicegroupmember_binding" + gslbSiteGSLBServiceGroupBindingURL = "/nitro/v1/config/gslbsite_gslbservicegroup_binding" + gslbSiteGSLBServiceBindingURL = "/nitro/v1/config/gslbsite_gslbservice_binding" + gslbSyncStatusURL = "/nitro/v1/config/gslbsyncstatus" + gslbVServerURL = "/nitro/v1/config/gslbvserver" + gslbVServerBindingURL = "/nitro/v1/config/gslbvserver_binding" + gslbVServerDomainBindingURL = "/nitro/v1/config/gslbvserver_domain_binding" + gslbVServerGSLBServiceGroupMemberBindingURL = "/nitro/v1/config/gslbvserver_gslbservicegroupmember_binding" + gslbVServerGSLBServiceGroupBindingURL = "/nitro/v1/config/gslbvserver_gslbservicegroup_binding" + gslbVServerGSLBServiceBindingURL = "/nitro/v1/config/gslbvserver_gslbservice_binding" + gslbVServerSpilloverPolicyBindingURL = "/nitro/v1/config/gslbvserver_spilloverpolicy_binding" +) + +// Global Server Load Balancing (GSLB) configuration. GSLB feature ensures that client requests are +// directed to a best performing site available in a global enterprise and distributed Internet environment. +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/gslb/gslb +type GSLBService struct { + client *Client +} + +// gslbconfig +func (s *GSLBService) SyncGSLBConfig(config models.GSLBConfig) error { + payload := map[string]any{ + "gslbconfig": config, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, gslbConfigURL+"?action=sync", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// gslbdomain +func (s *GSLBService) GetAllGSLBDomain() ([]models.GSLBDomain, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbDomainURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + GSLBDomains []models.GSLBDomain `json:"gslbdomain"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.GSLBDomains, nil +} + +func (s *GSLBService) GetGSLBDomain(name string) (*models.GSLBDomain, error) { + reqURL := fmt.Sprintf("%s/%s", gslbDomainURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + GSLBDomains []models.GSLBDomain `json:"gslbdomain"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.GSLBDomains) == 0 { + return nil, fmt.Errorf("gslbdomain not found") + } + + return &result.GSLBDomains[0], nil +} + +func (s *GSLBService) CountGSLBDomain() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbDomainURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + GSLBDomains []struct { + Count float64 `json:"__count"` + } `json:"gslbdomain"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.GSLBDomains) > 0 { + return result.GSLBDomains[0].Count, nil + } + + return 0, nil +} + +// gslbdomain_binding +func (s *GSLBService) GetAllGSLBDomainBinding() ([]models.GSLBDomainBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbDomainBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBDomainBinding `json:"gslbdomain_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) GetGSLBDomainBinding(name string) (*models.GSLBDomainBinding, error) { + reqURL := fmt.Sprintf("%s/%s", gslbDomainBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBDomainBinding `json:"gslbdomain_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) == 0 { + return nil, fmt.Errorf("gslbdomain_binding not found") + } + + return &result.Bindings[0], nil +} + +// gslbdomain_gslbservicegroupmember_binding +func (s *GSLBService) GetAllGSLBDomainGSLBServiceGroupMemberBinding() ([]models.GSLBDomainGSLBServiceGroupMemberBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbDomainGSLBServiceGroupMemberBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBDomainGSLBServiceGroupMemberBinding `json:"gslbdomain_gslbservicegroupmember_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) GetGSLBDomainGSLBServiceGroupMemberBinding(name string) ([]models.GSLBDomainGSLBServiceGroupMemberBinding, error) { + reqURL := fmt.Sprintf("%s/%s", gslbDomainGSLBServiceGroupMemberBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBDomainGSLBServiceGroupMemberBinding `json:"gslbdomain_gslbservicegroupmember_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) CountGSLBDomainGSLBServiceGroupMemberBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", gslbDomainGSLBServiceGroupMemberBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"gslbdomain_gslbservicegroupmember_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// gslbdomain_gslbservicegroup_binding +func (s *GSLBService) GetAllGSLBDomainGSLBServiceGroupBinding() ([]models.GSLBDomainGSLBServiceGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbDomainGSLBServiceGroupBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBDomainGSLBServiceGroupBinding `json:"gslbdomain_gslbservicegroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) GetGSLBDomainGSLBServiceGroupBinding(name string) ([]models.GSLBDomainGSLBServiceGroupBinding, error) { + reqURL := fmt.Sprintf("%s/%s", gslbDomainGSLBServiceGroupBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBDomainGSLBServiceGroupBinding `json:"gslbdomain_gslbservicegroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) CountGSLBDomainGSLBServiceGroupBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", gslbDomainGSLBServiceGroupBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"gslbdomain_gslbservicegroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// gslbdomain_gslbservice_binding +func (s *GSLBService) GetAllGSLBDomainGSLBServiceBinding() ([]models.GSLBDomainGSLBServiceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbDomainGSLBServiceBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBDomainGSLBServiceBinding `json:"gslbdomain_gslbservice_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) GetGSLBDomainGSLBServiceBinding(name string) ([]models.GSLBDomainGSLBServiceBinding, error) { + reqURL := fmt.Sprintf("%s/%s", gslbDomainGSLBServiceBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBDomainGSLBServiceBinding `json:"gslbdomain_gslbservice_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) CountGSLBDomainGSLBServiceBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", gslbDomainGSLBServiceBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"gslbdomain_gslbservice_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// gslbdomain_gslbvserver_binding +func (s *GSLBService) GetAllGSLBDomainGSLBVServerBinding() ([]models.GSLBDomainGSLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbDomainGSLBVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBDomainGSLBVServerBinding `json:"gslbdomain_gslbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) GetGSLBDomainGSLBVServerBinding(name string) ([]models.GSLBDomainGSLBVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", gslbDomainGSLBVServerBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBDomainGSLBVServerBinding `json:"gslbdomain_gslbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) CountGSLBDomainGSLBVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", gslbDomainGSLBVServerBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"gslbdomain_gslbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// gslbdomain_lbmonitor_binding +func (s *GSLBService) GetAllGSLBDomainLBMonitorBinding() ([]models.GSLBDomainLBMonitorBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbDomainLBMonitorBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBDomainLBMonitorBinding `json:"gslbdomain_lbmonitor_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) GetGSLBDomainLBMonitorBinding(name string) ([]models.GSLBDomainLBMonitorBinding, error) { + reqURL := fmt.Sprintf("%s/%s", gslbDomainLBMonitorBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBDomainLBMonitorBinding `json:"gslbdomain_lbmonitor_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) CountGSLBDomainLBMonitorBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", gslbDomainLBMonitorBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"gslbdomain_lbmonitor_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// gslbdnsentries +func (s *GSLBService) ClearGSLBDNSEntries(resource models.GSLBLDNSEntries) error { + payload := map[string]any{ + "gslbdnsentries": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, gslbDNSEntriesURL+"?action=clear", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) GetAllGSLBDNSEntries() ([]models.GSLBLDNSEntries, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbDNSEntriesURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Entries []models.GSLBLDNSEntries `json:"gslbdnsentries"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Entries, nil +} + +func (s *GSLBService) CountGSLBDNSEntries() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbDNSEntriesURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Entries []struct { + Count float64 `json:"__count"` + } `json:"gslbdnsentries"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Entries) > 0 { + return result.Entries[0].Count, nil + } + + return 0, nil +} + +// gslbdnsentry +func (s *GSLBService) DeleteGSLBDNSEntry(name string) error { + reqURL := fmt.Sprintf("%s/%s", gslbDNSEntryURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// gslbparameter +func (s *GSLBService) UpdateGSLBParameter(resource models.GSLBParameter) error { + payload := map[string]any{ + "gslbparameter": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, gslbParameterURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) UnsetGSLBParameter(resource models.GSLBParameter) error { + payload := map[string]any{ + "gslbparameter": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, gslbParameterURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) GetAllGSLBParameter() (*models.GSLBParameter, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbParameterURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Parameter []models.GSLBParameter `json:"gslbparameter"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Parameter) == 0 { + return nil, fmt.Errorf("gslbparameter not found") + } + + return &result.Parameter[0], nil +} + +// gslbrunningconfig +func (s *GSLBService) GetAllGSLBRunningConfig() ([]models.GSLBRunningConfig, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbRunningConfigURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + RunningConfig []models.GSLBRunningConfig `json:"gslbrunningconfig"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.RunningConfig, nil +} + +// gslbservice +func (s *GSLBService) AddGSLBService(resource models.GSLBService) error { + payload := map[string]any{ + "gslbservice": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, gslbServiceURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) DeleteGSLBService(name string) error { + reqURL := fmt.Sprintf("%s/%s", gslbServiceURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) UpdateGSLBService(resource models.GSLBService) error { + payload := map[string]any{ + "gslbservice": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, gslbServiceURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) UnsetGSLBService(resource models.GSLBService) error { + payload := map[string]any{ + "gslbservice": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, gslbServiceURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) GetAllGSLBService() ([]models.GSLBService, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbServiceURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Services []models.GSLBService `json:"gslbservice"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Services, nil +} + +func (s *GSLBService) GetGSLBService(name string) (*models.GSLBService, error) { + reqURL := fmt.Sprintf("%s/%s", gslbServiceURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Services []models.GSLBService `json:"gslbservice"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Services) == 0 { + return nil, fmt.Errorf("gslbservice not found") + } + + return &result.Services[0], nil +} + +func (s *GSLBService) CountGSLBService() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbServiceURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Services []struct { + Count float64 `json:"__count"` + } `json:"gslbservice"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Services) > 0 { + return result.Services[0].Count, nil + } + + return 0, nil +} + +func (s *GSLBService) RenameGSLBService(resource models.GSLBService) error { + payload := map[string]any{ + "gslbservice": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, gslbServiceURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// gslbservicegroup +func (s *GSLBService) AddGSLBServiceGroup(resource models.GSLBServiceGroup) error { + payload := map[string]any{ + "gslbservicegroup": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, gslbServiceGroupURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) DeleteGSLBServiceGroup(name string) error { + reqURL := fmt.Sprintf("%s/%s", gslbServiceGroupURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) UpdateGSLBServiceGroup(resource models.GSLBServiceGroup) error { + payload := map[string]any{ + "gslbservicegroup": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, gslbServiceGroupURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) UnsetGSLBServiceGroup(resource models.GSLBServiceGroup) error { + payload := map[string]any{ + "gslbservicegroup": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, gslbServiceGroupURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) EnableGSLBServiceGroup(resource models.GSLBServiceGroup) error { + payload := map[string]any{ + "gslbservicegroup": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, gslbServiceGroupURL+"?action=enable", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) DisableGSLBServiceGroup(resource models.GSLBServiceGroup) error { + payload := map[string]any{ + "gslbservicegroup": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, gslbServiceGroupURL+"?action=disable", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) GetAllGSLBServiceGroup() ([]models.GSLBServiceGroup, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbServiceGroupURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Groups []models.GSLBServiceGroup `json:"gslbservicegroup"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Groups, nil +} + +func (s *GSLBService) GetGSLBServiceGroup(name string) (*models.GSLBServiceGroup, error) { + reqURL := fmt.Sprintf("%s/%s", gslbServiceGroupURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Groups []models.GSLBServiceGroup `json:"gslbservicegroup"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Groups) == 0 { + return nil, fmt.Errorf("gslbservicegroup not found") + } + + return &result.Groups[0], nil +} + +func (s *GSLBService) CountGSLBServiceGroup() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbServiceGroupURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Groups []struct { + Count float64 `json:"__count"` + } `json:"gslbservicegroup"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Groups) > 0 { + return result.Groups[0].Count, nil + } + + return 0, nil +} + +func (s *GSLBService) RenameGSLBServiceGroup(resource models.GSLBServiceGroup) error { + payload := map[string]any{ + "gslbservicegroup": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, gslbServiceGroupURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// gslbservicegroup_binding +func (s *GSLBService) GetAllGSLBServiceGroupBinding() ([]models.GSLBServiceGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbServiceGroupBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBServiceGroupBinding `json:"gslbservicegroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) GetGSLBServiceGroupBinding(name string) (*models.GSLBServiceGroupBinding, error) { + reqURL := fmt.Sprintf("%s/%s", gslbServiceGroupBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBServiceGroupBinding `json:"gslbservicegroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) == 0 { + return nil, fmt.Errorf("gslbservicegroup_binding not found") + } + + return &result.Bindings[0], nil +} + +// gslbservicegroup_gslbservicegroupmember_binding +func (s *GSLBService) AddGSLBServiceGroupGSLBServiceGroupMemberBinding(resource models.GSLBServiceGroupGSLBServiceGroupMemberBinding) error { + payload := map[string]any{ + "gslbservicegroup_gslbservicegroupmember_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, gslbServiceGroupGSLBServiceGroupMemberBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) DeleteGSLBServiceGroupGSLBServiceGroupMemberBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", gslbServiceGroupGSLBServiceGroupMemberBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) GetAllGSLBServiceGroupGSLBServiceGroupMemberBinding() ([]models.GSLBServiceGroupGSLBServiceGroupMemberBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbServiceGroupGSLBServiceGroupMemberBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBServiceGroupGSLBServiceGroupMemberBinding `json:"gslbservicegroup_gslbservicegroupmember_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) GetGSLBServiceGroupGSLBServiceGroupMemberBinding(name string) ([]models.GSLBServiceGroupGSLBServiceGroupMemberBinding, error) { + reqURL := fmt.Sprintf("%s/%s", gslbServiceGroupGSLBServiceGroupMemberBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBServiceGroupGSLBServiceGroupMemberBinding `json:"gslbservicegroup_gslbservicegroupmember_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) CountGSLBServiceGroupGSLBServiceGroupMemberBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", gslbServiceGroupGSLBServiceGroupMemberBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"gslbservicegroup_gslbservicegroupmember_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// gslbservicegroup_lbmonitor_binding +func (s *GSLBService) AddGSLBServiceGroupLBMonitorBinding(resource models.GSLBServiceGroupLBMonitorBinding) error { + payload := map[string]any{ + "gslbservicegroup_lbmonitor_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, gslbServiceGroupLBMonitorBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) DeleteGSLBServiceGroupLBMonitorBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", gslbServiceGroupLBMonitorBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) GetAllGSLBServiceGroupLBMonitorBinding() ([]models.GSLBServiceGroupLBMonitorBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbServiceGroupLBMonitorBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBServiceGroupLBMonitorBinding `json:"gslbservicegroup_lbmonitor_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) GetGSLBServiceGroupLBMonitorBinding(name string) ([]models.GSLBServiceGroupLBMonitorBinding, error) { + reqURL := fmt.Sprintf("%s/%s", gslbServiceGroupLBMonitorBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBServiceGroupLBMonitorBinding `json:"gslbservicegroup_lbmonitor_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) CountGSLBServiceGroupLBMonitorBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", gslbServiceGroupLBMonitorBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"gslbservicegroup_lbmonitor_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// gslbservicegroup_servicegroupentitymonbindings_binding +func (s *GSLBService) GetAllGSLBServiceGroupServiceGroupEntityMonBindingsBinding() ([]models.GSLBServiceGroupServiceGroupEntityMonBindingsBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbServiceGroupServiceGroupEntityMonBindingsBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBServiceGroupServiceGroupEntityMonBindingsBinding `json:"gslbservicegroup_servicegroupentitymonbindings_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) GetGSLBServiceGroupServiceGroupEntityMonBindingsBinding(name string) ([]models.GSLBServiceGroupServiceGroupEntityMonBindingsBinding, error) { + reqURL := fmt.Sprintf("%s/%s", gslbServiceGroupServiceGroupEntityMonBindingsBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBServiceGroupServiceGroupEntityMonBindingsBinding `json:"gslbservicegroup_servicegroupentitymonbindings_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) CountGSLBServiceGroupServiceGroupEntityMonBindingsBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", gslbServiceGroupServiceGroupEntityMonBindingsBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"gslbservicegroup_servicegroupentitymonbindings_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// gslbservice_binding +func (s *GSLBService) GetAllGSLBServiceBinding() ([]models.GSLBServiceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbServiceBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBServiceBinding `json:"gslbservice_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) GetGSLBServiceBinding(name string) (*models.GSLBServiceBinding, error) { + reqURL := fmt.Sprintf("%s/%s", gslbServiceBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBServiceBinding `json:"gslbservice_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) == 0 { + return nil, fmt.Errorf("gslbservice_binding not found") + } + + return &result.Bindings[0], nil +} + +// gslbservice_dnsview_binding +func (s *GSLBService) AddGSLBServiceDNSViewBinding(resource models.GSLBServiceDNSViewBinding) error { + payload := map[string]any{ + "gslbservice_dnsview_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, gslbServiceDNSViewBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) DeleteGSLBServiceDNSViewBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", gslbServiceDNSViewBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) GetAllGSLBServiceDNSViewBinding() ([]models.GSLBServiceDNSViewBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbServiceDNSViewBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBServiceDNSViewBinding `json:"gslbservice_dnsview_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) GetGSLBServiceDNSViewBinding(name string) ([]models.GSLBServiceDNSViewBinding, error) { + reqURL := fmt.Sprintf("%s/%s", gslbServiceDNSViewBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBServiceDNSViewBinding `json:"gslbservice_dnsview_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) CountGSLBServiceDNSViewBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", gslbServiceDNSViewBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"gslbservice_dnsview_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// gslbservice_lbmonitor_binding +func (s *GSLBService) AddGSLBServiceLBMonitorBinding(resource models.GSLBServiceLBMonitorBinding) error { + payload := map[string]any{ + "gslbservice_lbmonitor_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, gslbServiceLBMonitorBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) DeleteGSLBServiceLBMonitorBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", gslbServiceLBMonitorBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) GetAllGSLBServiceLBMonitorBinding() ([]models.GSLBServiceLBMonitorBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbServiceLBMonitorBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBServiceLBMonitorBinding `json:"gslbservice_lbmonitor_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) GetGSLBServiceLBMonitorBinding(name string) ([]models.GSLBServiceLBMonitorBinding, error) { + reqURL := fmt.Sprintf("%s/%s", gslbServiceLBMonitorBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBServiceLBMonitorBinding `json:"gslbservice_lbmonitor_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) CountGSLBServiceLBMonitorBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", gslbServiceLBMonitorBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"gslbservice_lbmonitor_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// gslbsite +func (s *GSLBService) AddGSLBSite(resource models.GSLBSite) error { + payload := map[string]any{ + "gslbsite": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, gslbSiteURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) DeleteGSLBSite(name string) error { + reqURL := fmt.Sprintf("%s/%s", gslbSiteURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) UpdateGSLBSite(resource models.GSLBSite) error { + payload := map[string]any{ + "gslbsite": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, gslbSiteURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) UnsetGSLBSite(resource models.GSLBSite) error { + payload := map[string]any{ + "gslbsite": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, gslbSiteURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) GetAllGSLBSite() ([]models.GSLBSite, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbSiteURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Sites []models.GSLBSite `json:"gslbsite"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Sites, nil +} + +func (s *GSLBService) GetGSLBSite(name string) (*models.GSLBSite, error) { + reqURL := fmt.Sprintf("%s/%s", gslbSiteURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Sites []models.GSLBSite `json:"gslbsite"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Sites) == 0 { + return nil, fmt.Errorf("gslbsite not found") + } + + return &result.Sites[0], nil +} + +func (s *GSLBService) CountGSLBSite() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbSiteURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Sites []struct { + Count float64 `json:"__count"` + } `json:"gslbsite"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Sites) > 0 { + return result.Sites[0].Count, nil + } + + return 0, nil +} + +func (s *GSLBService) RenameGSLBSite(resource models.GSLBSite) error { + payload := map[string]any{ + "gslbsite": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, gslbSiteURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// gslbsite_binding +func (s *GSLBService) GetAllGSLBSiteBinding() ([]models.GSLBSiteBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbSiteBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBSiteBinding `json:"gslbsite_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) GetGSLBSiteBinding(name string) (*models.GSLBSiteBinding, error) { + reqURL := fmt.Sprintf("%s/%s", gslbSiteBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBSiteBinding `json:"gslbsite_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) == 0 { + return nil, fmt.Errorf("gslbsite_binding not found") + } + + return &result.Bindings[0], nil +} + +// gslbsite_gslbservicegroupmember_binding +func (s *GSLBService) GetAllGSLBSiteGSLBServiceGroupMemberBinding() ([]models.GSLBSiteGSLBServiceGroupMemberBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbSiteGSLBServiceGroupMemberBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBSiteGSLBServiceGroupMemberBinding `json:"gslbsite_gslbservicegroupmember_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) GetGSLBSiteGSLBServiceGroupMemberBinding(name string) ([]models.GSLBSiteGSLBServiceGroupMemberBinding, error) { + reqURL := fmt.Sprintf("%s/%s", gslbSiteGSLBServiceGroupMemberBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBSiteGSLBServiceGroupMemberBinding `json:"gslbsite_gslbservicegroupmember_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) CountGSLBSiteGSLBServiceGroupMemberBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", gslbSiteGSLBServiceGroupMemberBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"gslbsite_gslbservicegroupmember_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// gslbsite_gslbservicegroup_binding +func (s *GSLBService) GetAllGSLBSiteGSLBServiceGroupBinding() ([]models.GSLBSiteGSLBServiceGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbSiteGSLBServiceGroupBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBSiteGSLBServiceGroupBinding `json:"gslbsite_gslbservicegroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) GetGSLBSiteGSLBServiceGroupBinding(name string) ([]models.GSLBSiteGSLBServiceGroupBinding, error) { + reqURL := fmt.Sprintf("%s/%s", gslbSiteGSLBServiceGroupBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBSiteGSLBServiceGroupBinding `json:"gslbsite_gslbservicegroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) CountGSLBSiteGSLBServiceGroupBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", gslbSiteGSLBServiceGroupBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"gslbsite_gslbservicegroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// gslbsite_gslbservice_binding +func (s *GSLBService) GetAllGSLBSiteGSLBServiceBinding() ([]models.GSLBSiteGSLBServiceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbSiteGSLBServiceBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBSiteGSLBServiceBinding `json:"gslbsite_gslbservice_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) GetGSLBSiteGSLBServiceBinding(name string) ([]models.GSLBSiteGSLBServiceBinding, error) { + reqURL := fmt.Sprintf("%s/%s", gslbSiteGSLBServiceBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBSiteGSLBServiceBinding `json:"gslbsite_gslbservice_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) CountGSLBSiteGSLBServiceBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", gslbSiteGSLBServiceBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"gslbsite_gslbservice_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// gslbsyncstatus +func (s *GSLBService) GetAllGSLBSyncStatus() ([]models.GSLBSyncStatus, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbSyncStatusURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Status []models.GSLBSyncStatus `json:"gslbsyncstatus"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Status, nil +} + +// gslbvserver +func (s *GSLBService) AddGSLBVServer(resource models.GSLBVServer) error { + payload := map[string]any{ + "gslbvserver": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, gslbVServerURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) DeleteGSLBVServer(name string) error { + reqURL := fmt.Sprintf("%s/%s", gslbVServerURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) UpdateGSLBVServer(resource models.GSLBVServer) error { + payload := map[string]any{ + "gslbvserver": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, gslbVServerURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) UnsetGSLBVServer(resource models.GSLBVServer) error { + payload := map[string]any{ + "gslbvserver": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, gslbVServerURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) EnableGSLBVServer(resource models.GSLBVServer) error { + payload := map[string]any{ + "gslbvserver": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, gslbVServerURL+"?action=enable", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) DisableGSLBVServer(resource models.GSLBVServer) error { + payload := map[string]any{ + "gslbvserver": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, gslbVServerURL+"?action=disable", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) GetAllGSLBVServer() ([]models.GSLBVServer, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbVServerURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + VServers []models.GSLBVServer `json:"gslbvserver"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.VServers, nil +} + +func (s *GSLBService) GetGSLBVServer(name string) (*models.GSLBVServer, error) { + reqURL := fmt.Sprintf("%s/%s", gslbVServerURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + VServers []models.GSLBVServer `json:"gslbvserver"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.VServers) == 0 { + return nil, fmt.Errorf("gslbvserver not found") + } + + return &result.VServers[0], nil +} + +func (s *GSLBService) CountGSLBVServer() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbVServerURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + VServers []struct { + Count float64 `json:"__count"` + } `json:"gslbvserver"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.VServers) > 0 { + return result.VServers[0].Count, nil + } + + return 0, nil +} + +func (s *GSLBService) RenameGSLBVServer(resource models.GSLBVServer) error { + payload := map[string]any{ + "gslbvserver": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, gslbVServerURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// gslbvserver_binding +func (s *GSLBService) GetAllGSLBVServerBinding() ([]models.GSLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBVServerBinding `json:"gslbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) GetGSLBVServerBinding(name string) (*models.GSLBVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", gslbVServerBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBVServerBinding `json:"gslbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) == 0 { + return nil, fmt.Errorf("gslbvserver_binding not found") + } + + return &result.Bindings[0], nil +} + +// gslbvserver_domain_binding +func (s *GSLBService) AddGSLBVServerDomainBinding(resource models.GSLBVServerDomainBinding) error { + payload := map[string]any{ + "gslbvserver_domain_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, gslbVServerDomainBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) DeleteGSLBVServerDomainBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", gslbVServerDomainBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) GetAllGSLBVServerDomainBinding() ([]models.GSLBVServerDomainBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbVServerDomainBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBVServerDomainBinding `json:"gslbvserver_domain_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) GetGSLBVServerDomainBinding(name string) ([]models.GSLBVServerDomainBinding, error) { + reqURL := fmt.Sprintf("%s/%s", gslbVServerDomainBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBVServerDomainBinding `json:"gslbvserver_domain_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) CountGSLBVServerDomainBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", gslbVServerDomainBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"gslbvserver_domain_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// gslbvserver_gslbservicegroupmember_binding +func (s *GSLBService) GetAllGSLBVServerGSLBServiceGroupMemberBinding() ([]models.GSLBVServerGSLBServiceGroupMemberBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbVServerGSLBServiceGroupMemberBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBVServerGSLBServiceGroupMemberBinding `json:"gslbvserver_gslbservicegroupmember_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) GetGSLBVServerGSLBServiceGroupMemberBinding(name string) ([]models.GSLBVServerGSLBServiceGroupMemberBinding, error) { + reqURL := fmt.Sprintf("%s/%s", gslbVServerGSLBServiceGroupMemberBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBVServerGSLBServiceGroupMemberBinding `json:"gslbvserver_gslbservicegroupmember_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) CountGSLBVServerGSLBServiceGroupMemberBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", gslbVServerGSLBServiceGroupMemberBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"gslbvserver_gslbservicegroupmember_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// gslbvserver_gslbservicegroup_binding +func (s *GSLBService) AddGSLBVServerGSLBServiceGroupBinding(resource models.GSLBVServerGSLBServiceGroupBinding) error { + payload := map[string]any{ + "gslbvserver_gslbservicegroup_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, gslbVServerGSLBServiceGroupBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) DeleteGSLBVServerGSLBServiceGroupBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", gslbVServerGSLBServiceGroupBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) GetAllGSLBVServerGSLBServiceGroupBinding() ([]models.GSLBVServerGSLBServiceGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbVServerGSLBServiceGroupBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBVServerGSLBServiceGroupBinding `json:"gslbvserver_gslbservicegroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) GetGSLBVServerGSLBServiceGroupBinding(name string) ([]models.GSLBVServerGSLBServiceGroupBinding, error) { + reqURL := fmt.Sprintf("%s/%s", gslbVServerGSLBServiceGroupBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBVServerGSLBServiceGroupBinding `json:"gslbvserver_gslbservicegroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) CountGSLBVServerGSLBServiceGroupBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", gslbVServerGSLBServiceGroupBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"gslbvserver_gslbservicegroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// gslbvserver_gslbservice_binding +func (s *GSLBService) AddGSLBVServerGSLBServiceBinding(resource models.GSLBVServerGSLBServiceBinding) error { + payload := map[string]any{ + "gslbvserver_gslbservice_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, gslbVServerGSLBServiceBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) DeleteGSLBVServerGSLBServiceBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", gslbVServerGSLBServiceBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) GetAllGSLBVServerGSLBServiceBinding() ([]models.GSLBVServerGSLBServiceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbVServerGSLBServiceBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBVServerGSLBServiceBinding `json:"gslbvserver_gslbservice_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) GetGSLBVServerGSLBServiceBinding(name string) ([]models.GSLBVServerGSLBServiceBinding, error) { + reqURL := fmt.Sprintf("%s/%s", gslbVServerGSLBServiceBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBVServerGSLBServiceBinding `json:"gslbvserver_gslbservice_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) CountGSLBVServerGSLBServiceBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", gslbVServerGSLBServiceBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"gslbvserver_gslbservice_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// gslbvserver_spilloverpolicy_binding +func (s *GSLBService) AddGSLBVServerSpilloverPolicyBinding(resource models.GSLBVServerSpilloverPolicyBinding) error { + payload := map[string]any{ + "gslbvserver_spilloverpolicy_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, gslbVServerSpilloverPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) DeleteGSLBVServerSpilloverPolicyBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", gslbVServerSpilloverPolicyBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *GSLBService) GetAllGSLBVServerSpilloverPolicyBinding() ([]models.GSLBVServerSpilloverPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, gslbVServerSpilloverPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBVServerSpilloverPolicyBinding `json:"gslbvserver_spilloverpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) GetGSLBVServerSpilloverPolicyBinding(name string) ([]models.GSLBVServerSpilloverPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", gslbVServerSpilloverPolicyBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.GSLBVServerSpilloverPolicyBinding `json:"gslbvserver_spilloverpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *GSLBService) CountGSLBVServerSpilloverPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", gslbVServerSpilloverPolicyBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"gslbvserver_spilloverpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} diff --git a/nitrogo/ha.go b/nitrogo/ha.go index 8b3483c..103afab 100644 --- a/nitrogo/ha.go +++ b/nitrogo/ha.go @@ -1,5 +1,27 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + haFilesURL = "/nitro/v1/config/hafiles" + haNodeURL = "/nitro/v1/config/hanode" + haNodeBindingURL = "/nitro/v1/config/hanode_binding" + haNodeCIBindingURL = "/nitro/v1/config/hanode_ci_binding" + haNodeFISBindingURL = "/nitro/v1/config/hanode_fis_binding" + haNodePartialFailureInterfacesBindingURL = "/nitro/v1/config/hanode_partialfailureinterfaces_binding" + haNodeRouteMonitor6BindingURL = "/nitro/v1/config/hanode_routemonitor6_binding" + haNodeRouteMonitorBindingURL = "/nitro/v1/config/hanode_routemonitor_binding" + haSyncURL = "/nitro/v1/config/hasync" + haSyncFailuresURL = "/nitro/v1/config/hasyncfailures" +) + // Configuration for failover resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/ha/hafailover type HAService struct { @@ -7,52 +29,716 @@ type HAService struct { } // hafiles -func (s *HAService) SyncHAFiles() {} + +func (s *HAService) SyncHAFiles(files models.HAFiles) error { + payload := map[string]any{ + "hafiles": files, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, haFilesURL+"?action=sync", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} // hanode -func (s *HAService) AddHANode() {} -func (s *HAService) DeleteHANode() {} -func (s *HAService) UpdateHANode() {} -func (s *HAService) UnsetHANode() {} -func (s *HAService) GetAllHANode() {} -func (s *HAService) GetHANode() {} -func (s *HAService) CountHANode() {} + +func (s *HAService) AddHANode(node models.HANode) error { + payload := map[string]any{ + "hanode": node, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, haNodeURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *HAService) DeleteHANode(id int) error { + url := fmt.Sprintf("%s/%d", haNodeURL, id) + req, err := s.client.NewRequest(http.MethodDelete, url, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *HAService) UpdateHANode(node models.HANode) error { + payload := map[string]any{ + "hanode": node, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, haNodeURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *HAService) UnsetHANode(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "hanode": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, haNodeURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *HAService) GetAllHANode() ([]models.HANode, error) { + req, err := s.client.NewRequest(http.MethodGet, haNodeURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + HANodes []models.HANode `json:"hanode"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.HANodes, nil +} + +func (s *HAService) GetHANode(id int) ([]models.HANode, error) { + url := fmt.Sprintf("%s/%d", haNodeURL, id) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + HANodes []models.HANode `json:"hanode"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.HANodes, nil +} + +func (s *HAService) CountHANode() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, haNodeURL+"?view=count", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + HANodes []struct { + Count float64 `json:"__count"` + } `json:"hanode"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.HANodes) > 0 { + return result.HANodes[0].Count, nil + } + + return 0, nil +} // hanode_binding -func (s *HAService) GetAllHANodeBinding() {} -func (s *HAService) GetHANodeBinding() {} + +func (s *HAService) GetAllHANodeBinding() ([]models.HANodeBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, haNodeBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.HANodeBinding `json:"hanode_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *HAService) GetHANodeBinding(id int) ([]models.HANodeBinding, error) { + url := fmt.Sprintf("%s/%d", haNodeBindingURL, id) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.HANodeBinding `json:"hanode_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} // hanode_ci_binding -func (s *HAService) GetAllHANodeCIBinding() {} -func (s *HAService) GetHANodeCIBinding() {} -func (s *HAService) CountHANodeCIBinding() {} + +func (s *HAService) GetAllHANodeCIBinding() ([]models.HANodeCIBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, haNodeCIBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.HANodeCIBinding `json:"hanode_ci_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *HAService) GetHANodeCIBinding(id int) ([]models.HANodeCIBinding, error) { + url := fmt.Sprintf("%s/%d", haNodeCIBindingURL, id) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.HANodeCIBinding `json:"hanode_ci_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *HAService) CountHANodeCIBinding(id int) (float64, error) { + url := fmt.Sprintf("%s/%d?count=yes", haNodeCIBindingURL, id) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"hanode_ci_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} // hanode_fis_binding -func (s *HAService) GetAllHANodeFISBinding() {} -func (s *HAService) GetHANodeFISBinding() {} -func (s *HAService) CountHANodeFISBinding() {} + +func (s *HAService) GetAllHANodeFISBinding() ([]models.HANodeFISBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, haNodeFISBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.HANodeFISBinding `json:"hanode_fis_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *HAService) GetHANodeFISBinding(id int) ([]models.HANodeFISBinding, error) { + url := fmt.Sprintf("%s/%d", haNodeFISBindingURL, id) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.HANodeFISBinding `json:"hanode_fis_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *HAService) CountHANodeFISBinding(id int) (float64, error) { + url := fmt.Sprintf("%s/%d?count=yes", haNodeFISBindingURL, id) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"hanode_fis_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} // hanode_partialfailureinterfaces_binding -func (s *HAService) GetAllHANodePartialFailureInterfacesBinding() {} -func (s *HAService) GetHANodePartialFailureInterfacesBinding() {} -func (s *HAService) CountHANodePartialFailureInterfacesBinding() {} + +func (s *HAService) GetAllHANodePartialFailureInterfacesBinding() ([]models.HANodePartialFailureInterfacesBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, haNodePartialFailureInterfacesBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.HANodePartialFailureInterfacesBinding `json:"hanode_partialfailureinterfaces_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *HAService) GetHANodePartialFailureInterfacesBinding(id int) ([]models.HANodePartialFailureInterfacesBinding, error) { + url := fmt.Sprintf("%s/%d", haNodePartialFailureInterfacesBindingURL, id) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.HANodePartialFailureInterfacesBinding `json:"hanode_partialfailureinterfaces_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *HAService) CountHANodePartialFailureInterfacesBinding(id int) (float64, error) { + url := fmt.Sprintf("%s/%d?count=yes", haNodePartialFailureInterfacesBindingURL, id) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"hanode_partialfailureinterfaces_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} // hanode_routemonitor6_binding -func (s *HAService) AddHANodeRouteMonitor6Binding() {} -func (s *HAService) DeleteHANodeRouteMonitor6Binding() {} -func (s *HAService) GetAllHANodeRouteMonitor6Binding() {} -func (s *HAService) GetHANodeRouteMonitor6Binding() {} -func (s *HAService) CountHANodeRouteMonitor6Binding() {} + +func (s *HAService) AddHANodeRouteMonitor6Binding(binding models.HANodeRouteMonitor6Binding) error { + payload := map[string]any{ + "hanode_routemonitor6_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, haNodeRouteMonitor6BindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *HAService) DeleteHANodeRouteMonitor6Binding(id int, routemonitor string) error { + urlReq := fmt.Sprintf("%s/%d?args=routemonitor:%s", haNodeRouteMonitor6BindingURL, id, routemonitor) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *HAService) GetAllHANodeRouteMonitor6Binding() ([]models.HANodeRouteMonitor6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, haNodeRouteMonitor6BindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.HANodeRouteMonitor6Binding `json:"hanode_routemonitor6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *HAService) GetHANodeRouteMonitor6Binding(id int) ([]models.HANodeRouteMonitor6Binding, error) { + url := fmt.Sprintf("%s/%d", haNodeRouteMonitor6BindingURL, id) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.HANodeRouteMonitor6Binding `json:"hanode_routemonitor6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *HAService) CountHANodeRouteMonitor6Binding(id int) (float64, error) { + url := fmt.Sprintf("%s/%d?count=yes", haNodeRouteMonitor6BindingURL, id) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"hanode_routemonitor6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} // hanode_routemonitor_binding -func (s *HAService) AddHANodeRouteMonitorBinding() {} -func (s *HAService) DeleteHANodeRouteMonitorBinding() {} -func (s *HAService) GetAllHANodeRouteMonitorBinding() {} -func (s *HAService) GetHANodeRouteMonitorBinding() {} -func (s *HAService) CountHANodeRouteMonitorBinding() {} + +func (s *HAService) AddHANodeRouteMonitorBinding(binding models.HANodeRouteMonitorBinding) error { + payload := map[string]any{ + "hanode_routemonitor_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, haNodeRouteMonitorBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *HAService) DeleteHANodeRouteMonitorBinding(id int, routemonitor string) error { + urlReq := fmt.Sprintf("%s/%d?args=routemonitor:%s", haNodeRouteMonitorBindingURL, id, routemonitor) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *HAService) GetAllHANodeRouteMonitorBinding() ([]models.HANodeRouteMonitorBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, haNodeRouteMonitorBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.HANodeRouteMonitorBinding `json:"hanode_routemonitor_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *HAService) GetHANodeRouteMonitorBinding(id int) ([]models.HANodeRouteMonitorBinding, error) { + url := fmt.Sprintf("%s/%d", haNodeRouteMonitorBindingURL, id) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.HANodeRouteMonitorBinding `json:"hanode_routemonitor_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *HAService) CountHANodeRouteMonitorBinding(id int) (float64, error) { + url := fmt.Sprintf("%s/%d?count=yes", haNodeRouteMonitorBindingURL, id) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"hanode_routemonitor_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} // hasync -func (s *HAService) ForceHASync() {} + +func (s *HAService) ForceHASync(sync models.HASync) error { + payload := map[string]any{ + "hasync": sync, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, haSyncURL+"?action=Force", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} // hasyncfailures -func (s *HAService) GetAllHASyncFailures() {} + +func (s *HAService) GetAllHASyncFailures() ([]models.HASyncFailures, error) { + req, err := s.client.NewRequest(http.MethodGet, haSyncFailuresURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + HASyncFailures []models.HASyncFailures `json:"hasyncfailures"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.HASyncFailures, nil +} diff --git a/nitrogo/ica.go b/nitrogo/ica.go index 39b0b09..f071e81 100644 --- a/nitrogo/ica.go +++ b/nitrogo/ica.go @@ -1,78 +1,1129 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + icaAccessProfileURL = "/nitro/v1/config/icaaccessprofile" + icaActionURL = "/nitro/v1/config/icaaction" + icaGlobalBindingURL = "/nitro/v1/config/icaglobal_binding" + icaGlobalICAPolicyBindingURL = "/nitro/v1/config/icaglobal_icapolicy_binding" + icaLatencyProfileURL = "/nitro/v1/config/icalatencyprofile" + icaParameterURL = "/nitro/v1/config/icaparameter" + icaPolicyURL = "/nitro/v1/config/icapolicy" + icaPolicyBindingURL = "/nitro/v1/config/icapolicy_binding" + icaPolicyCRVServerBindingURL = "/nitro/v1/config/icapolicy_crvserver_binding" + icaPolicyICAGlobalBindingURL = "/nitro/v1/config/icapolicy_icaglobal_binding" + icaPolicyVPNVServerBindingURL = "/nitro/v1/config/icapolicy_vpnvserver_binding" +) + // ICA configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/ica/ica type ICAService struct { client *Client } -// ucaaccessprofile -func (s *ICAService) AddICAAccessProfile() {} -func (s *ICAService) DeleteICAAccessProfile() {} -func (s *ICAService) UpdateICAAccessProfile() {} -func (s *ICAService) UnsetICAAccessProfile() {} -func (s *ICAService) GetAllICAAccessProfile() {} -func (s *ICAService) GetICAAccessProfile() {} -func (s *ICAService) CountICAAccessProfile() {} +// icaaccessprofile + +func (s *ICAService) AddICAAccessProfile(profile models.ICAAccessProfile) error { + payload := map[string]any{ + "icaaccessprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, icaAccessProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ICAService) DeleteICAAccessProfile(name string) error { + urlReq := fmt.Sprintf("%s/%s", icaAccessProfileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ICAService) UpdateICAAccessProfile(profile models.ICAAccessProfile) error { + payload := map[string]any{ + "icaaccessprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, icaAccessProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ICAService) UnsetICAAccessProfile(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "icaaccessprofile": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, icaAccessProfileURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ICAService) GetAllICAAccessProfile() ([]models.ICAAccessProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, icaAccessProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Profiles []models.ICAAccessProfile `json:"icaaccessprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Profiles, nil +} + +func (s *ICAService) GetICAAccessProfile(name string) ([]models.ICAAccessProfile, error) { + urlReq := fmt.Sprintf("%s/%s", icaAccessProfileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Profiles []models.ICAAccessProfile `json:"icaaccessprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Profiles, nil +} + +func (s *ICAService) CountICAAccessProfile() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, icaAccessProfileURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Profiles []struct { + Count float64 `json:"__count"` + } `json:"icaaccessprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Profiles) > 0 { + return result.Profiles[0].Count, nil + } + + return 0, nil +} // icaaction -func (s *ICAService) AddICAAction() {} -func (s *ICAService) DeleteICAAction() {} -func (s *ICAService) UpdateICAAction() {} -func (s *ICAService) UnsetICAAction() {} -func (s *ICAService) GetAllICAAction() {} -func (s *ICAService) GetICAAction() {} -func (s *ICAService) CountICAAction() {} -func (s *ICAService) RenameICAAction() {} + +func (s *ICAService) AddICAAction(action models.ICAAction) error { + payload := map[string]any{ + "icaaction": action, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, icaActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ICAService) DeleteICAAction(name string) error { + urlReq := fmt.Sprintf("%s/%s", icaActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ICAService) UpdateICAAction(action models.ICAAction) error { + payload := map[string]any{ + "icaaction": action, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, icaActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ICAService) UnsetICAAction(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "icaaction": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, icaActionURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ICAService) GetAllICAAction() ([]models.ICAAction, error) { + req, err := s.client.NewRequest(http.MethodGet, icaActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Actions []models.ICAAction `json:"icaaction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Actions, nil +} + +func (s *ICAService) GetICAAction(name string) ([]models.ICAAction, error) { + urlReq := fmt.Sprintf("%s/%s", icaActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Actions []models.ICAAction `json:"icaaction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Actions, nil +} + +func (s *ICAService) CountICAAction() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, icaActionURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Actions []struct { + Count float64 `json:"__count"` + } `json:"icaaction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Actions) > 0 { + return result.Actions[0].Count, nil + } + + return 0, nil +} + +func (s *ICAService) RenameICAAction(name string, newname string) error { + payload := map[string]any{ + "icaaction": map[string]string{ + "name": name, + "newname": newname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, icaActionURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} // icaglobal_binding -func (s *ICAService) GetICAGlobalBinding() {} + +func (s *ICAService) GetICAGlobalBinding() ([]models.ICAGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, icaGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.ICAGlobalBinding `json:"icaglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} // icaglobal_icapolicy_binding -func (s *ICAService) AddICAGlobalICAPolicyBinding() {} -func (s *ICAService) DeleteICAGlobalICAPolicyBinding() {} -func (s *ICAService) GetICAGlobalICAPolicyBinding() {} -func (s *ICAService) CountICAGlobalICAPolicyBinding() {} + +func (s *ICAService) AddICAGlobalICAPolicyBinding(binding models.ICAGlobalICAPolicyBinding) error { + payload := map[string]any{ + "icaglobal_icapolicy_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, icaGlobalICAPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ICAService) DeleteICAGlobalICAPolicyBinding(policyname string) error { + urlReq := fmt.Sprintf("%s?args=policyname:%s", icaGlobalICAPolicyBindingURL, url.QueryEscape(policyname)) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ICAService) GetICAGlobalICAPolicyBinding() ([]models.ICAGlobalICAPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, icaGlobalICAPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.ICAGlobalICAPolicyBinding `json:"icaglobal_icapolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *ICAService) CountICAGlobalICAPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, icaGlobalICAPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"icaglobal_icapolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} // icalatencyprofile -func (s *ICAService) AddICALatencyProfile() {} -func (s *ICAService) DeleteICALatencyProfile() {} -func (s *ICAService) UpdateICALatencyProfile() {} -func (s *ICAService) UnsetICALatencyProfile() {} -func (s *ICAService) GetAllICALatencyProfile() {} -func (s *ICAService) GetICALatencyProfile() {} -func (s *ICAService) CountICALatencyProfile() {} + +func (s *ICAService) AddICALatencyProfile(profile models.ICALatencyProfile) error { + payload := map[string]any{ + "icalatencyprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, icaLatencyProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ICAService) DeleteICALatencyProfile(name string) error { + urlReq := fmt.Sprintf("%s/%s", icaLatencyProfileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ICAService) UpdateICALatencyProfile(profile models.ICALatencyProfile) error { + payload := map[string]any{ + "icalatencyprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, icaLatencyProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ICAService) UnsetICALatencyProfile(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "icalatencyprofile": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, icaLatencyProfileURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ICAService) GetAllICALatencyProfile() ([]models.ICALatencyProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, icaLatencyProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Profiles []models.ICALatencyProfile `json:"icalatencyprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Profiles, nil +} + +func (s *ICAService) GetICALatencyProfile(name string) ([]models.ICALatencyProfile, error) { + urlReq := fmt.Sprintf("%s/%s", icaLatencyProfileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Profiles []models.ICALatencyProfile `json:"icalatencyprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Profiles, nil +} + +func (s *ICAService) CountICALatencyProfile() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, icaLatencyProfileURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Profiles []struct { + Count float64 `json:"__count"` + } `json:"icalatencyprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Profiles) > 0 { + return result.Profiles[0].Count, nil + } + + return 0, nil +} // icaparameter -func (s *ICAService) UpdateICAParameter() {} -func (s *ICAService) UnsetICAParameter() {} -func (s *ICAService) GetAllICAParameter() {} + +func (s *ICAService) UpdateICAParameter(param models.ICAParameter) error { + payload := map[string]any{ + "icaparameter": param, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, icaParameterURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ICAService) UnsetICAParameter(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "icaparameter": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, icaParameterURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ICAService) GetAllICAParameter() (models.ICAParameter, error) { + req, err := s.client.NewRequest(http.MethodGet, icaParameterURL, nil) + if err != nil { + return models.ICAParameter{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.ICAParameter{}, err + } + + var result struct { + Parameters []models.ICAParameter `json:"icaparameter"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.ICAParameter{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Parameters) > 0 { + return result.Parameters[0], nil + } + + return models.ICAParameter{}, nil +} // icapolicy -func (s *ICAService) AddICAPolicy() {} -func (s *ICAService) DeleteICAPolicy() {} -func (s *ICAService) UpdateICAPolicy() {} -func (s *ICAService) UnsetICAPolicy() {} -func (s *ICAService) GetAllICAPolicy() {} -func (s *ICAService) GetICAPolicy() {} -func (s *ICAService) CountICAPolicy() {} -func (s *ICAService) RenameICAPolicy() {} + +func (s *ICAService) AddICAPolicy(policy models.ICAPolicy) error { + payload := map[string]any{ + "icapolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, icaPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ICAService) DeleteICAPolicy(name string) error { + urlReq := fmt.Sprintf("%s/%s", icaPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ICAService) UpdateICAPolicy(policy models.ICAPolicy) error { + payload := map[string]any{ + "icapolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, icaPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ICAService) UnsetICAPolicy(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "icapolicy": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, icaPolicyURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ICAService) GetAllICAPolicy() ([]models.ICAPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, icaPolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Policies []models.ICAPolicy `json:"icapolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Policies, nil +} + +func (s *ICAService) GetICAPolicy(name string) ([]models.ICAPolicy, error) { + urlReq := fmt.Sprintf("%s/%s", icaPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Policies []models.ICAPolicy `json:"icapolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Policies, nil +} + +func (s *ICAService) CountICAPolicy() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, icaPolicyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Policies []struct { + Count float64 `json:"__count"` + } `json:"icapolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Policies) > 0 { + return result.Policies[0].Count, nil + } + + return 0, nil +} + +func (s *ICAService) RenameICAPolicy(name string, newname string) error { + payload := map[string]any{ + "icapolicy": map[string]string{ + "name": name, + "newname": newname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, icaPolicyURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} // icapolicy_binding -func (s *ICAService) GetAllICAPolicyBinding() {} -func (s *ICAService) GetICAPolicyBinding() {} + +func (s *ICAService) GetAllICAPolicyBinding() ([]models.ICAPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, icaPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.ICAPolicyBinding `json:"icapolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *ICAService) GetICAPolicyBinding(name string) ([]models.ICAPolicyBinding, error) { + urlReq := fmt.Sprintf("%s/%s", icaPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.ICAPolicyBinding `json:"icapolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} // icapolicy_crvserver_binding -func (s *ICAService) GetAllICAPolicyCRVServerBinding() {} -func (s *ICAService) GetICAPolicyCRVServerBinding() {} -func (s *ICAService) CountICAPolicyCRVServerBinding() {} + +func (s *ICAService) GetAllICAPolicyCRVServerBinding() ([]models.ICAPolicyCRVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, icaPolicyCRVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.ICAPolicyCRVServerBinding `json:"icapolicy_crvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *ICAService) GetICAPolicyCRVServerBinding(name string) ([]models.ICAPolicyCRVServerBinding, error) { + urlReq := fmt.Sprintf("%s/%s", icaPolicyCRVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.ICAPolicyCRVServerBinding `json:"icapolicy_crvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *ICAService) CountICAPolicyCRVServerBinding(name string) (float64, error) { + urlReq := fmt.Sprintf("%s/%s?count=yes", icaPolicyCRVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"icapolicy_crvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} // icapolicy_icaglobal_binding -func (s *ICAService) GetAllICAPolicyICAGlobalBinding() {} -func (s *ICAService) GetICAPolicyICAGlobalBinding() {} -func (s *ICAService) CountICAPolicyICAGlobalBinding() {} + +func (s *ICAService) GetAllICAPolicyICAGlobalBinding() ([]models.ICAPolicyICAGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, icaPolicyICAGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.ICAPolicyICAGlobalBinding `json:"icapolicy_icaglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *ICAService) GetICAPolicyICAGlobalBinding(name string) ([]models.ICAPolicyICAGlobalBinding, error) { + urlReq := fmt.Sprintf("%s/%s", icaPolicyICAGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.ICAPolicyICAGlobalBinding `json:"icapolicy_icaglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *ICAService) CountICAPolicyICAGlobalBinding(name string) (float64, error) { + urlReq := fmt.Sprintf("%s/%s?count=yes", icaPolicyICAGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"icapolicy_icaglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} // icapolicy_vpnvserver_binding -func (s *ICAService) GetAllICAPolicyVPNVServerBinding() {} -func (s *ICAService) GetICAPolicyVPNVServerBinding() {} -func (s *ICAService) CountICAPolicyVPNVServerBinding() {} + +func (s *ICAService) GetAllICAPolicyVPNVServerBinding() ([]models.ICAPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, icaPolicyVPNVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.ICAPolicyVPNVServerBinding `json:"icapolicy_vpnvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *ICAService) GetICAPolicyVPNVServerBinding(name string) ([]models.ICAPolicyVPNVServerBinding, error) { + urlReq := fmt.Sprintf("%s/%s", icaPolicyVPNVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.ICAPolicyVPNVServerBinding `json:"icapolicy_vpnvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *ICAService) CountICAPolicyVPNVServerBinding(name string) (float64, error) { + urlReq := fmt.Sprintf("%s/%s?count=yes", icaPolicyVPNVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"icapolicy_vpnvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} diff --git a/nitrogo/ipsec.go b/nitrogo/ipsec.go index d75c50c..00b263c 100644 --- a/nitrogo/ipsec.go +++ b/nitrogo/ipsec.go @@ -1,5 +1,19 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + ipsecParameterURL = "/nitro/v1/config/ipsecparameter" + ipsecProfileURL = "/nitro/v1/config/ipsecprofile" +) + // IPSEC configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/ipsec/ipsec type IPSECService struct { @@ -9,15 +23,181 @@ type IPSECService struct { // ipsecparameter // Configuration for IPSEC paramter resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/ipsec/ipsecparameter -func (s *IPSECService) UpdateIPSECParamter() {} -func (s *IPSECService) UnsetIPSECParamter() {} -func (s *IPSECService) GetAllIPSECParamter() {} + +func (s *IPSECService) UpdateIPSECParamter(param models.IPSECParameter) error { + payload := map[string]any{ + "ipsecparameter": param, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, ipsecParameterURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *IPSECService) UnsetIPSECParamter(args []string) error { + unsetMap := make(map[string]bool) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "ipsecparameter": unsetMap, + } + + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, ipsecParameterURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *IPSECService) GetAllIPSECParamter() (models.IPSECParameter, error) { + req, err := s.client.NewRequest(http.MethodGet, ipsecParameterURL, nil) + if err != nil { + return models.IPSECParameter{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.IPSECParameter{}, err + } + + var result struct { + IPSECParameters []models.IPSECParameter `json:"ipsecparameter"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.IPSECParameter{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.IPSECParameters) > 0 { + return result.IPSECParameters[0], nil + } + + return models.IPSECParameter{}, nil +} // ipsecprofile // Configuration for IPSEC profile resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/ipsec/ipsecprofile -func (s *IPSECService) AddIPSECProfile() {} -func (s *IPSECService) DeleteIPSECProfile() {} -func (s *IPSECService) GetAllIPSECProfile() {} -func (s *IPSECService) GetIPSECProfile() {} -func (s *IPSECService) CountIPSECProfile() {} + +func (s *IPSECService) AddIPSECProfile(profile models.IPSECProfile) error { + payload := map[string]any{ + "ipsecprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, ipsecProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *IPSECService) DeleteIPSECProfile(name string) error { + url := fmt.Sprintf("%s/%s", ipsecProfileURL, name) + req, err := s.client.NewRequest(http.MethodDelete, url, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *IPSECService) GetAllIPSECProfile() ([]models.IPSECProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, ipsecProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + IPSECProfiles []models.IPSECProfile `json:"ipsecprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.IPSECProfiles, nil +} + +func (s *IPSECService) GetIPSECProfile(name string) ([]models.IPSECProfile, error) { + url := fmt.Sprintf("%s/%s", ipsecProfileURL, name) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + IPSECProfiles []models.IPSECProfile `json:"ipsecprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.IPSECProfiles, nil +} + +func (s *IPSECService) CountIPSECProfile() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, ipsecProfileURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + IPSECProfiles []struct { + Count float64 `json:"__count"` + } `json:"ipsecprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.IPSECProfiles) > 0 { + return result.IPSECProfiles[0].Count, nil + } + + return 0, nil +} diff --git a/nitrogo/ipsecalg.go b/nitrogo/ipsecalg.go index 5acac00..b0ff1ff 100644 --- a/nitrogo/ipsecalg.go +++ b/nitrogo/ipsecalg.go @@ -1,5 +1,19 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + ipsecALGProfileURL = "/nitro/v1/config/ipsecalgprofile" + ipsecALGSessionURL = "/nitro/v1/config/ipsecalgsession" +) + // IPSECALG configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/ipsecalg/ipsecalg type IPSECALGService struct { @@ -9,17 +23,223 @@ type IPSECALGService struct { // ipsecalgprofile // Configuration for IPSEC ALG profile resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/ipsecalg/ipsecalgprofile -func (s *IPSECALGService) AddIPSECALGProfile() {} -func (s *IPSECALGService) DeleteIPSECALGProfile() {} -func (s *IPSECALGService) UpdateIPSECALGProfile() {} -func (s *IPSECALGService) UnsetIPSECALGProfile() {} -func (s *IPSECALGService) GetAllIPSECALGProfile() {} -func (s *IPSECALGService) GetIPSECALGProfile() {} -func (s *IPSECALGService) CountIPSECALGProfile() {} + +func (s *IPSECALGService) AddIPSECALGProfile(profile models.IPSECALGProfile) error { + payload := map[string]any{ + "ipsecalgprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, ipsecALGProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *IPSECALGService) DeleteIPSECALGProfile(name string) error { + url := fmt.Sprintf("%s/%s", ipsecALGProfileURL, name) + req, err := s.client.NewRequest(http.MethodDelete, url, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *IPSECALGService) UpdateIPSECALGProfile(profile models.IPSECALGProfile) error { + payload := map[string]any{ + "ipsecalgprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, ipsecALGProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *IPSECALGService) UnsetIPSECALGProfile(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "ipsecalgprofile": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, ipsecALGProfileURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *IPSECALGService) GetAllIPSECALGProfile() ([]models.IPSECALGProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, ipsecALGProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + IPSECALGProfiles []models.IPSECALGProfile `json:"ipsecalgprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.IPSECALGProfiles, nil +} + +func (s *IPSECALGService) GetIPSECALGProfile(name string) ([]models.IPSECALGProfile, error) { + url := fmt.Sprintf("%s/%s", ipsecALGProfileURL, name) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + IPSECALGProfiles []models.IPSECALGProfile `json:"ipsecalgprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.IPSECALGProfiles, nil +} + +func (s *IPSECALGService) CountIPSECALGProfile() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, ipsecALGProfileURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + IPSECALGProfiles []struct { + Count float64 `json:"__count"` + } `json:"ipsecalgprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.IPSECALGProfiles) > 0 { + return result.IPSECALGProfiles[0].Count, nil + } + + return 0, nil +} // ipsecalgsession // Configuration for IPSEC ALG session resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/ipsecalg/ipsecalgsession -func (s *IPSECALGService) GetAllIPSECALGSession() {} -func (s *IPSECALGService) CountIPSECALGSession() {} -func (s *IPSECALGService) FlushIPSECALGSession() {} + +func (s *IPSECALGService) GetAllIPSECALGSession() ([]models.IPSECALGSession, error) { + req, err := s.client.NewRequest(http.MethodGet, ipsecALGSessionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + IPSECALGSessions []models.IPSECALGSession `json:"ipsecalgsession"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.IPSECALGSessions, nil +} + +func (s *IPSECALGService) CountIPSECALGSession() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, ipsecALGSessionURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + IPSECALGSessions []struct { + Count float64 `json:"__count"` + } `json:"ipsecalgsession"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.IPSECALGSessions) > 0 { + return result.IPSECALGSessions[0].Count, nil + } + + return 0, nil +} + +func (s *IPSECALGService) FlushIPSECALGSession(session models.IPSECALGSession) error { + payload := map[string]any{ + "ipsecalgsession": session, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, ipsecALGSessionURL+"?action=flush", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} diff --git a/nitrogo/lb.go b/nitrogo/lb.go index 46a89a1..5021a2b 100644 --- a/nitrogo/lb.go +++ b/nitrogo/lb.go @@ -1,13 +1,73 @@ package nitrogo import ( + "bytes" "encoding/json" "fmt" "net/http" + "strings" "github.com/AdamJCrawford/NitroGo/nitrogo/models" ) +const ( + lbActionURL = "/nitro/v1/config/lbaction" + lbGlobalBindingURL = "/nitro/v1/config/lbglobal_binding" + lbGlobalLBPolicyBindingURL = "/nitro/v1/config/lbglobal_lbpolicy_binding" + lbGroupURL = "/nitro/v1/config/lbgroup" + lbGroupBindingURL = "/nitro/v1/config/lbgroup_binding" + lbGroupLBVServerBindingURL = "/nitro/v1/config/lbgroup_lbvserver_binding" + lbMetricTableURL = "/nitro/v1/config/lbmetrictable" + lbMetricTableBindingURL = "/nitro/v1/config/lbmetrictable_binding" + lbMetricTableMetricBindingURL = "/nitro/v1/config/lbmetrictable_metric_binding" + lbMonBindingsURL = "/nitro/v1/config/lbmonbindings" + lbMonBindingsBindingURL = "/nitro/v1/config/lbmonbindings_binding" + lbMonBindingsGSLBServiceGroupBindingURL = "/nitro/v1/config/lbmonbindings_gslbservicegroup_binding" + lbMonBindingsServiceBindingURL = "/nitro/v1/config/lbmonbindings_service_binding" + lbMonBindingsServiceGroupBindingURL = "/nitro/v1/config/lbmonbindings_servicegroup_binding" + lbMonitorURL = "/nitro/v1/config/lbmonitor" + lbMonitorBindingURL = "/nitro/v1/config/lbmonitor_binding" + lbMonitorMetricBindingURL = "/nitro/v1/config/lbmonitor_metric_binding" + lbMonitorServiceBindingURL = "/nitro/v1/config/lbmonitor_service_binding" + lbMonitorServiceGroupBindingURL = "/nitro/v1/config/lbmonitor_servicegroup_binding" + lbMonitorSSLCertKeyBindingURL = "/nitro/v1/config/lbmonitor_sslcertkey_binding" + lbParameterURL = "/nitro/v1/config/lbparameter" + lbPersistentSessionsURL = "/nitro/v1/config/lbpersistentsessions" + lbProfileURL = "/nitro/v1/config/lbprofile" + lbRouteURL = "/nitro/v1/config/lbroute" + lbRoute6URL = "/nitro/v1/config/lbroute6" + lbSIPParametersURL = "/nitro/v1/config/lbsipparameters" + lbVServerURL = "/nitro/v1/config/lbvserver" + lbVServerAnalyticsProfileBindingURL = "/nitro/v1/config/lbvserver_analyticsprofile_binding" + lbVServerAppFlowPolicyBindingURL = "/nitro/v1/config/lbvserver_appflowpolicy_binding" + lbVServerAppFWPolicyBindingURL = "/nitro/v1/config/lbvserver_appfwpolicy_binding" + lbVServerAppQOEPolicyBindingURL = "/nitro/v1/config/lbvserver_appqoepolicy_binding" + lbVServerAuditNSLogPolicyBindingURL = "/nitro/v1/config/lbvserver_auditnslogpolicy_binding" + lbVServerAuditSyslogPolicyBindingURL = "/nitro/v1/config/lbvserver_auditsyslogpolicy_binding" + lbVServerAuthorizationPolicyBindingURL = "/nitro/v1/config/lbvserver_authorizationpolicy_binding" + lbVServerBindingURL = "/nitro/v1/config/lbvserver_binding" + lbVServerBotPolicyBindingURL = "/nitro/v1/config/lbvserver_botpolicy_binding" + lbVServerCachePolicyBindingURL = "/nitro/v1/config/lbvserver_cachepolicy_binding" + lbVServerCMPPolicyBindingURL = "/nitro/v1/config/lbvserver_cmppolicy_binding" + lbVServerContentInspectionPolicyBindingURL = "/nitro/v1/config/lbvserver_contentinspectionpolicy_binding" + lbVServerCSVServerBindingURL = "/nitro/v1/config/lbvserver_csvserver_binding" + lbVServerDNSPolicy64BindingURL = "/nitro/v1/config/lbvserver_dnspolicy64_binding" + lbVServerFEOPolicyBindingURL = "/nitro/v1/config/lbvserver_feopolicy_binding" + lbVServerResponderPolicyBindingURL = "/nitro/v1/config/lbvserver_responderpolicy_binding" + lbVServerRewritePolicyBindingURL = "/nitro/v1/config/lbvserver_rewritepolicy_binding" + lbVServerServiceBindingURL = "/nitro/v1/config/lbvserver_service_binding" + lbVServerServiceGroupBindingURL = "/nitro/v1/config/lbvserver_servicegroup_binding" + lbVServerServiceGroupMemberBindingURL = "/nitro/v1/config/lbvserver_servicegroupmember_binding" + lbVServerSpilloverPolicyBindingURL = "/nitro/v1/config/lbvserver_spilloverpolicy_binding" + lbVServerTMTrafficPolicyBindingURL = "/nitro/v1/config/lbvserver_tmtrafficpolicy_binding" + lbVServerTransformPolicyBindingURL = "/nitro/v1/config/lbvserver_transformpolicy_binding" + lbVServerVideoOptimizationDetectionPolicyBindingURL = "/nitro/v1/config/lbvserver_videooptimizationdetectionpolicy_binding" + lbVServerVideoOptimizationPacingPolicyBindingURL = "/nitro/v1/config/lbvserver_videooptimizationpacingpolicy_binding" + lbWLMURL = "/nitro/v1/config/lbwlm" + lbWLMBindingURL = "/nitro/v1/config/lbwlm_binding" + lbWLMLBVServerBindingURL = "/nitro/v1/config/lbwlm_lbvserver_binding" +) + // Load Balancing configuration. The load balancing methods manage the selection of an appropriate physical server in a server farm. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/lb/lb type LBService struct { @@ -17,403 +77,4051 @@ type LBService struct { // lbaction // Configuration for lb action resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/lb/lbaction -func (s *LBService) AddLBAction() {} -func (s *LBService) DeleteLBAction() {} -func (s *LBService) UpdateLBAction() {} -func (s *LBService) UnsetLBAction() {} -func (s *LBService) GetAllLBAction() {} -func (s *LBService) GetLBAction() {} -func (s *LBService) CountLBAction() {} -func (s *LBService) RenameLBAction() {} +func (s *LBService) AddLBAction(resource map[string]any) error { + payload := map[string]any{"lbaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBAction(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", lbActionURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) UpdateLBAction(resource map[string]any) error { + payload := map[string]any{"lbaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, lbActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) UnsetLBAction(resource map[string]any) error { + payload := map[string]any{"lbaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", lbActionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetAllLBAction() ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, lbActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbaction"], nil +} + +func (s *LBService) GetLBAction(name string) (map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbActionURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbaction"]) == 0 { + return nil, fmt.Errorf("lbaction %s not found", name) + } + + return result["lbaction"][0], nil +} + +func (s *LBService) CountLBAction() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lbActionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbaction"]) > 0 { + if count, ok := result["lbaction"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +func (s *LBService) RenameLBAction(name, newName string) error { + payload := map[string]any{"lbaction": map[string]string{"name": name, "newname": newName}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=rename", lbActionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} // lbglobal_binding -func (s *LBService) GetLBGlobalBinding() {} +func (s *LBService) GetLBGlobalBinding() (map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, lbGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if val, ok := result["lbglobal_binding"]; ok { + return val.(map[string]any), nil + } + return nil, fmt.Errorf("lbglobal_binding not found") +} // lbglobal_lbpolicy_binding -func (s *LBService) AddLBGlobalLBPolicyBinding() {} -func (s *LBService) DeleteLBGlobalLBPolicyBinding() {} -func (s *LBService) GetLBGlobalLBPolicyBinding() {} -func (s *LBService) CountLBGlobalLBPolicyBinding() {} +func (s *LBService) AddLBGlobalLBPolicyBinding(resource map[string]any) error { + payload := map[string]any{"lbglobal_lbpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// lbgroup -func (s *LBService) AddLBGroup() {} -func (s *LBService) DeleteLBGroup() {} -func (s *LBService) UpdateLBGroup() {} -func (s *LBService) UnsetLBGroup() {} -func (s *LBService) GetAllLBGroup() {} -func (s *LBService) GetLBGroup() {} -func (s *LBService) CountLBGroup() {} -func (s *LBService) RenameLBGroup() {} + req, err := s.client.NewRequest(http.MethodPost, lbGlobalLBPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } -// lbgroup_binding -func (s *LBService) GetAllLBGroupBinding() {} -func (s *LBService) GetLBGroupBinding() {} + _, err = s.client.Do(req) + return err +} -// lbgroup_lbvserver_binding -func (s *LBService) AddLBGroupLBVServerBinding() {} -func (s *LBService) DeleteLBGroupLBVServerBinding() {} -func (s *LBService) GetAllLBGroupLBVServerBinding() {} -func (s *LBService) GetLBGroupLBVServerBinding() {} -func (s *LBService) CountLBGroupLBVServerBinding() {} +func (s *LBService) DeleteLBGlobalLBPolicyBinding(args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } -// lbmetrictable -func (s *LBService) AddLBMetricTable() {} -func (s *LBService) DeleteLBMetricTable() {} -func (s *LBService) UpdateLBMetricTable() {} -func (s *LBService) GetAllLBMetricTable() {} -func (s *LBService) GetLBMetricTable() {} -func (s *LBService) CountLBMetricTable() {} + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s%s", lbGlobalLBPolicyBindingURL, argsStr), nil) + if err != nil { + return err + } -// lbmetrictable_binding -func (s *LBService) GetAllLBMetricTableBinding() {} -func (s *LBService) GetLBMetricTableBinding() {} + _, err = s.client.Do(req) + return err +} -// lbmetrictable_metric_binding -func (s *LBService) AddLBMetricTableMetricBinding() {} -func (s *LBService) DeleteLBMetricTableMetricBinding() {} -func (s *LBService) GetAllLBMetricTableMetricBinding() {} -func (s *LBService) GetLBMetricTableMetricBinding() {} -func (s *LBService) CountLBMetricTableMetricBinding() {} +func (s *LBService) GetLBGlobalLBPolicyBinding() ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, lbGlobalLBPolicyBindingURL, nil) + if err != nil { + return nil, err + } -// lbmonbindings -func (s *LBService) GetAllLBMonBindings() {} -func (s *LBService) GetLBMonBindings() {} -func (s *LBService) CountLBMonBindings() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// lbmonbindings_binding -func (s *LBService) GetLBMonBindingsBinding() {} + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// lbmonbindings_gslbservicegroup_binding -func (s *LBService) GetLBMonBindingsGSLBServiceGroupBinding() {} -func (s *LBService) CountLBMonBindingsGSLBServiceGroupBinding() {} + return result["lbglobal_lbpolicy_binding"], nil +} -// lbmonbindings_servicegroup_binding -func (s *LBService) GetLBMonBindingsServiceGroupBinding() {} -func (s *LBService) CountLBMonBindingsServiceGroupBinding() {} +func (s *LBService) CountLBGlobalLBPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lbGlobalLBPolicyBindingURL), nil) + if err != nil { + return 0, err + } -// lbmonbindings_service_binding -func (s *LBService) GetLBMonBindingsServiceBinding() {} -func (s *LBService) CountLBMonBindingsServiceBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } -// lbmonitor -func (s *LBService) AddLBMonitor() {} -func (s *LBService) DeleteLBMonitor() {} -func (s *LBService) UpdateLBMonitor() {} -func (s *LBService) UnsetLBMonitor() {} -func (s *LBService) EnableLBMonitor() {} -func (s *LBService) DisableLBMonitor() {} -func (s *LBService) GetAllLBMonitor() {} -func (s *LBService) GetLBMonitor() {} -func (s *LBService) CountLBMonitor() {} + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } -// lbmonitor_binding -func (s *LBService) GetAllLBMonitorBinding() {} -func (s *LBService) GetLBMonitorBinding() {} + if len(result["lbglobal_lbpolicy_binding"]) > 0 { + if count, ok := result["lbglobal_lbpolicy_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} -// lbmonitor_metric_binding -func (s *LBService) AddLBMonitorMetricBinding() {} -func (s *LBService) DeleteLBMonitorMetricBinding() {} -func (s *LBService) GetAllLBMonitorMetricBinding() {} -func (s *LBService) GetLBMonitorMetricBinding() {} -func (s *LBService) CountLBMonitorMetricBinding() {} +// lbgroup +func (s *LBService) AddLBGroup(resource map[string]any) error { + payload := map[string]any{"lbgroup": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// lbmonitor_servicegroup_binding -func (s *LBService) AddLBMonitorServiceGroupBinding() {} -func (s *LBService) DeleteLBMonitorServiceGroupBinding() {} + req, err := s.client.NewRequest(http.MethodPost, lbGroupURL, bytes.NewReader(data)) + if err != nil { + return err + } -// lbmonitor_service_binding -func (s *LBService) AddLBMonitorServiceBinding() {} -func (s *LBService) DeleteLBMonitorServiceBinding() {} + _, err = s.client.Do(req) + return err +} -// lbmonitor_sslcertkey_binding -func (s *LBService) AddLBMonitorSSLCertKeyBinding() {} -func (s *LBService) DeleteLBMonitorSSLCertKeyBinding() {} -func (s *LBService) GetAllLBMonitorSSLCertKeyBinding() {} -func (s *LBService) GetLBMonitorSSLCertKeyBinding() {} -func (s *LBService) CountLBMonitorSSLCertKeyBinding() {} +func (s *LBService) DeleteLBGroup(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", lbGroupURL, name), nil) + if err != nil { + return err + } -// lbparameter -func (s *LBService) UpdateLBParameter() {} -func (s *LBService) UnsetLBParameter() {} -func (s *LBService) GetAllLBParameter() {} + _, err = s.client.Do(req) + return err +} -// lbpersistentsessions -func (s *LBService) GetAllLBPersistentSessions() {} -func (s *LBService) CountLBPersistentSessions() {} -func (s *LBService) ClearLBPersistentSessions() {} +func (s *LBService) UpdateLBGroup(resource map[string]any) error { + payload := map[string]any{"lbgroup": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// lbprofile -func (s *LBService) AddLBProfile() {} -func (s *LBService) DeleteLBProfile() {} -func (s *LBService) UpdateLBProfile() {} -func (s *LBService) UnsetLBProfile() {} -func (s *LBService) GetAllLBProfile() {} -func (s *LBService) GetLBProfile() {} -func (s *LBService) CountLBProfile() {} + req, err := s.client.NewRequest(http.MethodPut, lbGroupURL, bytes.NewReader(data)) + if err != nil { + return err + } -// lbroute -func (s *LBService) AddLBRoute() {} -func (s *LBService) DeleteLBRoute() {} -func (s *LBService) GetAllLBRoute() {} -func (s *LBService) CountLBRoute() {} + _, err = s.client.Do(req) + return err +} -// lbroute6 -func (s *LBService) AddLBRoute6() {} -func (s *LBService) DeleteLBRoute6() {} -func (s *LBService) GetAllLBRoute6() {} -func (s *LBService) CountLBRoute6() {} +func (s *LBService) UnsetLBGroup(resource map[string]any) error { + payload := map[string]any{"lbgroup": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// lbsipparameters -func (s *LBService) UpdateLBSIPParameters() {} -func (s *LBService) UnsetLBSIPParameters() {} -func (s *LBService) GetAllLBSIPParameters() {} + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", lbGroupURL), bytes.NewReader(data)) + if err != nil { + return err + } -// lbvserver -func (s *LBService) AddLBVServer() {} -func (s *LBService) DeleteLBVServer() {} -func (s *LBService) UpdateLBVServer() {} -func (s *LBService) UnsetLBVServer() {} -func (s *LBService) EnableLBVServer() {} -func (s *LBService) DisableLBVServer() {} -func (s *LBService) GetAllLBVServer() ([]models.LBVServer, error) { - u := "nitro/v1/config/lbvserver" - v := []models.LBVServer{} + _, err = s.client.Do(req) + return err +} - req, err := s.client.NewRequest(http.MethodGet, u, nil) +func (s *LBService) GetAllLBGroup() ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, lbGroupURL, nil) if err != nil { - return v, err + return nil, err } resp, err := s.client.Do(req) if err != nil { - return v, err + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) } - data, err := json.Marshal(resp["lbvserver"]) + return result["lbgroup"], nil +} + +func (s *LBService) GetLBGroup(name string) (map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbGroupURL, name), nil) if err != nil { - return v, err + return nil, err } - err = json.Unmarshal(data, &v) + resp, err := s.client.Do(req) if err != nil { - return v, fmt.Errorf("failed to unmarshal: %w", err) + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbgroup"]) == 0 { + return nil, fmt.Errorf("lbgroup %s not found", name) } - return v, nil + return result["lbgroup"][0], nil } -func (s *LBService) GetLBVServer() {} -func (s *LBService) CountLBVServer() {} -func (s *LBService) RenameLBVServer() {} -// lbvserver_analyticsprofile_binding -func (s *LBService) AddLBVServerAnalyticsProfileBinding() {} -func (s *LBService) DeleteLBVServerAnalyticsProfileBinding() {} -func (s *LBService) GetAllLBVServerAnalyticsProfileBinding() {} -func (s *LBService) GetLBVServerAnalyticsProfileBinding() {} -func (s *LBService) CountLBVServerAnalyticsProfileBinding() {} +func (s *LBService) CountLBGroup() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lbGroupURL), nil) + if err != nil { + return 0, err + } -// lbvserver_appflowpolicy_binding -func (s *LBService) AddLBVServerAppFlowPolicyBinding() {} -func (s *LBService) DeleteLBVServerAppFlowPolicyBinding() {} -func (s *LBService) GetAllLBVServerAppFlowPolicyBinding() {} -func (s *LBService) GetLBVServerAppFlowPolicyBinding() {} -func (s *LBService) CountLBVServerAppFlowPolicyBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } -// lbvserver_appfwpolicy_binding -func (s *LBService) AddLBVServerAppFWPolicyBinding() {} -func (s *LBService) DeleteLBVServerAppFWPolicyBinding() {} -func (s *LBService) GetAllLBVServerAppFWPolicyBinding() {} -func (s *LBService) GetLBVServerAppFWPolicyBinding() {} -func (s *LBService) CountLBVServerAppFWPolicyBinding() {} + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } -// lbvserver_appqoepolicy_binding -func (s *LBService) AddLBVServerAppQOEPolicyBinding() {} -func (s *LBService) DeleteLBVServerAppQOEPolicyBinding() {} -func (s *LBService) GetAllLBVServerAppQOEPolicyBinding() {} -func (s *LBService) GetLBVServerAppQOEPolicyBinding() {} -func (s *LBService) CountLBVServerAppQOEPolicyBinding() {} + if len(result["lbgroup"]) > 0 { + if count, ok := result["lbgroup"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} -// lbvserver_auditnslogpolicy_binding -func (s *LBService) AddLBVServerAuditNSLogPolicyBinding() {} -func (s *LBService) DeleteLBVServerAuditNSLogPolicyBinding() {} -func (s *LBService) GetAllLBVServerAuditNSLogPolicyBinding() {} -func (s *LBService) GetLBVServerAuditNSLogPolicyBinding() {} -func (s *LBService) CountLBVServerAuditNSLogPolicyBinding() {} +func (s *LBService) RenameLBGroup(name, newName string) error { + payload := map[string]any{"lbgroup": map[string]string{"name": name, "newname": newName}} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// lbvserver_auditsyslogpolicy_binding -func (s *LBService) AddLBVServerAuditSyslogPolicyBinding() {} -func (s *LBService) DeleteLBVServerAuditSyslogPolicyBinding() {} -func (s *LBService) GetAllLBVServerAuditSyslogPolicyBinding() {} -func (s *LBService) GetLBVServerAuditSyslogPolicyBinding() {} -func (s *LBService) CountLBVServerAuditSyslogPolicyBinding() {} + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=rename", lbGroupURL), bytes.NewReader(data)) + if err != nil { + return err + } -// lbvserver_authorizationpolicy_binding -func (s *LBService) AddLBVServerAuthorizationPolicyBinding() {} -func (s *LBService) DeleteLBVServerAuthorizationPolicyBinding() {} -func (s *LBService) GetAllLBVServerAuthorizationPolicyBinding() {} -func (s *LBService) GetLBVServerAuthorizationPolicyBinding() {} -func (s *LBService) CountLBVServerAuthorizationPolicyBinding() {} + _, err = s.client.Do(req) + return err +} -// lbvserver_binding -func (s *LBService) GetAllLBVServerBinding() {} -func (s *LBService) GetLBVServerBinding() {} +// lbgroup_binding +func (s *LBService) GetLBGroupBinding(name string) (map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbGroupBindingURL, name), nil) + if err != nil { + return nil, err + } -// lbvserver_botpolicy_binding -func (s *LBService) AddLBVServerBotPolicyBinding() {} -func (s *LBService) DeleteLBVServerBotPolicyBinding() {} -func (s *LBService) GetAllLBVServerBotPolicyBinding() {} -func (s *LBService) GetLBVServerBotPolicyBinding() {} -func (s *LBService) CountLBVServerBotPolicyBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// lbvserver_cachepolicy_binding -func (s *LBService) AddLBVServerCachePolicyBinding() {} -func (s *LBService) DeleteLBVServerCachePolicyBinding() {} -func (s *LBService) GetAllLBVServerCachePolicyBinding() {} -func (s *LBService) GetLBVServerCachePolicyBinding() {} -func (s *LBService) CountLBVServerCachePolicyBinding() {} + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// lbvserver_cmppolicy_binding -func (s *LBService) AddLBVServerCMPPolicyBinding() {} -func (s *LBService) DeleteLBVServerCMPPolicyBinding() {} -func (s *LBService) GetAllLBVServerCMPPolicyBinding() {} -func (s *LBService) GetLBVServerCMPPolicyBinding() {} -func (s *LBService) CountLBVServerCMPPolicyBinding() {} + if len(result["lbgroup_binding"]) == 0 { + return nil, fmt.Errorf("lbgroup_binding %s not found", name) + } -// lbvserver_contentinspectionpolicy_binding -func (s *LBService) AddLBVServerContentInspectionPolicyBinding() {} -func (s *LBService) DeleteLBVServerContentInspectionPolicyBinding() {} -func (s *LBService) GetAllLBVServerContentInspectionPolicyBinding() {} -func (s *LBService) GetLBVServerContentInspectionPolicyBinding() {} -func (s *LBService) CountLBVServerContentInspectionPolicyBinding() {} + return result["lbgroup_binding"][0], nil +} -// lbvserver_csvserver_binding -func (s *LBService) GetAllLBVServerCSVServerBinding() {} -func (s *LBService) GetLBVServerCSVServerBinding() {} -func (s *LBService) CountLBVServerCSVServerBinding() {} +// lbgroup_lbvserver_binding +func (s *LBService) AddLBGroupLBVServerBinding(resource map[string]any) error { + payload := map[string]any{"lbgroup_lbvserver_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// lbvserver_dnspolicy64_binding -func (s *LBService) AddLBVServerDNSPolicy64Binding() {} -func (s *LBService) DeleteLBVServerDNSPolicy64Binding() {} -func (s *LBService) GetAllLBVServerDNSPolicy64Binding() {} -func (s *LBService) GetLBVServerDNSPolicy64Binding() {} -func (s *LBService) CountLBVServerDNSPolicy64Binding() {} + req, err := s.client.NewRequest(http.MethodPost, lbGroupLBVServerBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } -// lbvserver_feopolicy_binding -func (s *LBService) AddLBVServerFEOPolicyBinding() {} -func (s *LBService) DeleteLBVServerFEOPolicyBinding() {} -func (s *LBService) GetAllLBVServerFEOPolicyBinding() {} -func (s *LBService) GetLBVServerFEOPolicyBinding() {} -func (s *LBService) CountLBVServerFEOPolicyBinding() {} + _, err = s.client.Do(req) + return err +} -// lbvserver_responderpolicy_binding -func (s *LBService) AddLBVServerResponderPolicyBinding() {} -func (s *LBService) DeleteLBVServerResponderPolicyBinding() {} -func (s *LBService) GetAllLBVServerResponderPolicyBinding() {} -func (s *LBService) GetLBVServerResponderPolicyBinding() {} -func (s *LBService) CountLBVServerResponderPolicyBinding() {} +func (s *LBService) DeleteLBGroupLBVServerBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } -// lbvserver_rewritepolicy_binding -func (s *LBService) AddLBVServerRewritePolicyBinding() {} -func (s *LBService) DeleteLBVServerRewritePolicyBinding() {} -func (s *LBService) GetAllLBVServerRewritePolicyBinding() {} -func (s *LBService) GetLBVServerRewritePolicyBinding() {} -func (s *LBService) CountLBVServerRewritePolicyBinding() {} + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbGroupLBVServerBindingURL, name, argsStr), nil) + if err != nil { + return err + } -// lbvserver_servicegroupmember_binding -func (s *LBService) GetAllLBVServerServiceGroupMemberBinding() {} -func (s *LBService) GetLBVServerServiceGroupMemberBinding(lbvserver string) ([]models.LBVServerServiceGroupMemberBinding, error) { - u := fmt.Sprintf("nitro/v1/config/lbvserver_servicegroupmember_binding/%s", lbvserver) - v := []models.LBVServerServiceGroupMemberBinding{} + _, err = s.client.Do(req) + return err +} - req, err := s.client.NewRequest(http.MethodGet, u, nil) +func (s *LBService) GetLBGroupLBVServerBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbGroupLBVServerBindingURL, name), nil) if err != nil { - return v, err + return nil, err } resp, err := s.client.Do(req) if err != nil { - return v, err + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) } - data, err := json.Marshal(resp["lbvserver_servicegroupmember_binding"]) + return result["lbgroup_lbvserver_binding"], nil +} + +func (s *LBService) CountLBGroupLBVServerBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbGroupLBVServerBindingURL, name), nil) if err != nil { - return v, err + return 0, err } - err = json.Unmarshal(data, &v) + resp, err := s.client.Do(req) if err != nil { - return v, fmt.Errorf("failed to unmarshal: %w", err) + return 0, err } - return v, nil + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbgroup_lbvserver_binding"]) > 0 { + if count, ok := result["lbgroup_lbvserver_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") } -func (s *LBService) CountLBVServerServiceGroupMemberBinding() {} -// lbvserver_servicegroup_binding -func (s *LBService) AddLBVServerServiceGroupBinding() {} -func (s *LBService) DeleteLBVServerServiceGroupBinding() {} -func (s *LBService) GetAllLBVServerServiceGroupBinding() {} -func (s *LBService) GetLBVServerServiceGroupBinding() {} -func (s *LBService) CountLBVServerServiceGroupBinding() {} +// lbmetrictable +func (s *LBService) AddLBMetricTable(resource map[string]any) error { + payload := map[string]any{"lbmetrictable": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// lbvserver_service_binding -func (s *LBService) AddLBVServerServiceBinding() {} -func (s *LBService) DeleteLBVServerServiceBinding() {} -func (s *LBService) GetAllLBVServerServiceBinding() {} -func (s *LBService) GetLBVServerServiceBinding() {} -func (s *LBService) CountLBVServerServiceBinding() {} + req, err := s.client.NewRequest(http.MethodPost, lbMetricTableURL, bytes.NewReader(data)) + if err != nil { + return err + } -// lbvserver_spilloverpolicy_binding -func (s *LBService) AddLBVServerSpilloverPolicyBinding() {} -func (s *LBService) DeleteLBVServerSpilloverPolicyBinding() {} -func (s *LBService) GetAllLBVServerSpilloverPolicyBinding() {} -func (s *LBService) GetLBVServerSpilloverPolicyBinding() {} -func (s *LBService) CountLBVServerSpilloverPolicyBinding() {} + _, err = s.client.Do(req) + return err +} -// lbvserver_tmtrafficpolicy_binding -func (s *LBService) AddLBVServerTMTrafficPolicyBinding() {} -func (s *LBService) DeleteLBVServerTMTrafficPolicyBinding() {} -func (s *LBService) GetAllLBVServerTMTrafficPolicyBinding() {} -func (s *LBService) GetLBVServerTMTrafficPolicyBinding() {} -func (s *LBService) CountLBVServerTMTrafficPolicyBinding() {} +func (s *LBService) DeleteLBMetricTable(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", lbMetricTableURL, name), nil) + if err != nil { + return err + } -// lbvserver_transformpolicy_binding -func (s *LBService) AddLBVServerTransformPolicyBinding() {} -func (s *LBService) DeleteLBVServerTransformPolicyBinding() {} -func (s *LBService) GetAllLBVServerTransformPolicyBinding() {} -func (s *LBService) GetLBVServerTransformPolicyBinding() {} -func (s *LBService) CountLBVServerTransformPolicyBinding() {} + _, err = s.client.Do(req) + return err +} -// lbvserver_videooptimizationdetectionpolicy_binding -func (s *LBService) AddLBVServerVideoOptimizationDetectionPolicyBinding() {} -func (s *LBService) DeleteLBVServerVideoOptimizationDetectionPolicyBinding() {} -func (s *LBService) GetAllLBVServerVideoOptimizationDetectionPolicyBinding() {} -func (s *LBService) GetLBVServerVideoOptimizationDetectionPolicyBinding() {} -func (s *LBService) CountLBVServerVideoOptimizationDetectionPolicyBinding() {} +func (s *LBService) UpdateLBMetricTable(resource map[string]any) error { + payload := map[string]any{"lbmetrictable": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// lbvserver_videooptimizationpacingpolicy_binding -func (s *LBService) AddLBVServerVideoOptimizationPacingPolicyBinding() {} -func (s *LBService) DeleteLBVServerVideoOptimizationPacingPolicyBinding() {} -func (s *LBService) GetAllLBVServerVideoOptimizationPacingPolicyBinding() {} -func (s *LBService) GetLBVServerVideoOptimizationPacingPolicyBinding() {} -func (s *LBService) CountLBVServerVideoOptimizationPacingPolicyBinding() {} + req, err := s.client.NewRequest(http.MethodPut, lbMetricTableURL, bytes.NewReader(data)) + if err != nil { + return err + } -// lbwlm -func (s *LBService) AddLBWLM() {} -func (s *LBService) DeleteLBWLM() {} -func (s *LBService) UpdateLBWLM() {} -func (s *LBService) UnsetLBWLM() {} -func (s *LBService) GetAllLBWLM() {} -func (s *LBService) GetLBWLM() {} -func (s *LBService) CountLBWLM() {} + _, err = s.client.Do(req) + return err +} -// lbwlm_binding -func (s *LBService) GetAllLBWLMBinding() {} -func (s *LBService) GetLBWLMBinding() {} +func (s *LBService) GetAllLBMetricTable() ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, lbMetricTableURL, nil) + if err != nil { + return nil, err + } -// lbwlm_lbvserver_binding -func (s *LBService) AddLBWLMLBVServerBinding() {} -func (s *LBService) DeleteLBWLMLBVServerBinding() {} -func (s *LBService) GetAllLBWLMLBVServerBinding() {} -func (s *LBService) GetLBWLMLBVServerBinding() {} -func (s *LBService) CountLBWLMLBVServerBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbmetrictable"], nil +} + +func (s *LBService) GetLBMetricTable(name string) (map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbMetricTableURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbmetrictable"]) == 0 { + return nil, fmt.Errorf("lbmetrictable %s not found", name) + } + + return result["lbmetrictable"][0], nil +} + +func (s *LBService) CountLBMetricTable() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lbMetricTableURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbmetrictable"]) > 0 { + if count, ok := result["lbmetrictable"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbmetrictable_binding +func (s *LBService) GetLBMetricTableBinding(name string) (map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbMetricTableBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbmetrictable_binding"]) == 0 { + return nil, fmt.Errorf("lbmetrictable_binding %s not found", name) + } + + return result["lbmetrictable_binding"][0], nil +} + +// lbmetrictable_metric_binding +func (s *LBService) AddLBMetricTableMetricBinding(resource map[string]any) error { + payload := map[string]any{"lbmetrictable_metric_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbMetricTableMetricBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBMetricTableMetricBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbMetricTableMetricBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetLBMetricTableMetricBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbMetricTableMetricBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbmetrictable_metric_binding"], nil +} + +func (s *LBService) CountLBMetricTableMetricBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbMetricTableMetricBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbmetrictable_metric_binding"]) > 0 { + if count, ok := result["lbmetrictable_metric_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbmonbindings +func (s *LBService) GetAllLBMonBindings() ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, lbMonBindingsURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbmonbindings"], nil +} + +func (s *LBService) GetLBMonBindings(name string) (map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbMonBindingsURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbmonbindings"]) == 0 { + return nil, fmt.Errorf("lbmonbindings %s not found", name) + } + + return result["lbmonbindings"][0], nil +} + +func (s *LBService) CountLBMonBindings() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lbMonBindingsURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbmonbindings"]) > 0 { + if count, ok := result["lbmonbindings"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbmonbindings_binding +func (s *LBService) GetLBMonBindingsBinding(name string) (map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbMonBindingsBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbmonbindings_binding"]) == 0 { + return nil, fmt.Errorf("lbmonbindings_binding %s not found", name) + } + + return result["lbmonbindings_binding"][0], nil +} + +// lbmonbindings_gslbservicegroup_binding +func (s *LBService) GetLBMonBindingsGSLBServiceGroupBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbMonBindingsGSLBServiceGroupBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbmonbindings_gslbservicegroup_binding"], nil +} + +func (s *LBService) CountLBMonBindingsGSLBServiceGroupBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbMonBindingsGSLBServiceGroupBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbmonbindings_gslbservicegroup_binding"]) > 0 { + if count, ok := result["lbmonbindings_gslbservicegroup_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbmonbindings_servicegroup_binding +func (s *LBService) GetLBMonBindingsServiceGroupBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbMonBindingsServiceGroupBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbmonbindings_servicegroup_binding"], nil +} + +func (s *LBService) CountLBMonBindingsServiceGroupBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbMonBindingsServiceGroupBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbmonbindings_servicegroup_binding"]) > 0 { + if count, ok := result["lbmonbindings_servicegroup_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbmonbindings_service_binding +func (s *LBService) GetLBMonBindingsServiceBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbMonBindingsServiceBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbmonbindings_service_binding"], nil +} + +func (s *LBService) CountLBMonBindingsServiceBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbMonBindingsServiceBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbmonbindings_service_binding"]) > 0 { + if count, ok := result["lbmonbindings_service_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbmonitor +func (s *LBService) AddLBMonitor(resource map[string]any) error { + payload := map[string]any{"lbmonitor": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbMonitorURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBMonitor(name string, resource map[string]any) error { + // lbmonitor delete might require type, so we allow resource map for query params or payload if needed. + // Standard delete is by name. + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", lbMonitorURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) UpdateLBMonitor(resource map[string]any) error { + payload := map[string]any{"lbmonitor": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, lbMonitorURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) UnsetLBMonitor(resource map[string]any) error { + payload := map[string]any{"lbmonitor": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", lbMonitorURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) EnableLBMonitor(name string) error { + payload := map[string]any{"lbmonitor": map[string]string{"monitorname": name}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=enable", lbMonitorURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DisableLBMonitor(name string) error { + payload := map[string]any{"lbmonitor": map[string]string{"monitorname": name}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=disable", lbMonitorURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetAllLBMonitor() ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, lbMonitorURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbmonitor"], nil +} + +func (s *LBService) GetLBMonitor(name string) (map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbMonitorURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbmonitor"]) == 0 { + return nil, fmt.Errorf("lbmonitor %s not found", name) + } + + return result["lbmonitor"][0], nil +} + +func (s *LBService) CountLBMonitor() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lbMonitorURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbmonitor"]) > 0 { + if count, ok := result["lbmonitor"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbmonitor_binding +func (s *LBService) GetLBMonitorBinding(name string) (map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbMonitorBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbmonitor_binding"]) == 0 { + return nil, fmt.Errorf("lbmonitor_binding %s not found", name) + } + + return result["lbmonitor_binding"][0], nil +} + +// lbmonitor_metric_binding +func (s *LBService) AddLBMonitorMetricBinding(resource map[string]any) error { + payload := map[string]any{"lbmonitor_metric_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbMonitorMetricBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBMonitorMetricBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbMonitorMetricBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetLBMonitorMetricBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbMonitorMetricBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbmonitor_metric_binding"], nil +} + +func (s *LBService) CountLBMonitorMetricBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbMonitorMetricBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbmonitor_metric_binding"]) > 0 { + if count, ok := result["lbmonitor_metric_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbmonitor_servicegroup_binding +func (s *LBService) AddLBMonitorServiceGroupBinding(resource map[string]any) error { + payload := map[string]any{"lbmonitor_servicegroup_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbMonitorServiceGroupBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBMonitorServiceGroupBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbMonitorServiceGroupBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// lbmonitor_service_binding +func (s *LBService) AddLBMonitorServiceBinding(resource map[string]any) error { + payload := map[string]any{"lbmonitor_service_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbMonitorServiceBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBMonitorServiceBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbMonitorServiceBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// lbmonitor_sslcertkey_binding +func (s *LBService) AddLBMonitorSSLCertKeyBinding(resource map[string]any) error { + payload := map[string]any{"lbmonitor_sslcertkey_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbMonitorSSLCertKeyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBMonitorSSLCertKeyBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbMonitorSSLCertKeyBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetLBMonitorSSLCertKeyBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbMonitorSSLCertKeyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbmonitor_sslcertkey_binding"], nil +} + +func (s *LBService) CountLBMonitorSSLCertKeyBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbMonitorSSLCertKeyBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbmonitor_sslcertkey_binding"]) > 0 { + if count, ok := result["lbmonitor_sslcertkey_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbparameter +func (s *LBService) UpdateLBParameter(resource map[string]any) error { + payload := map[string]any{"lbparameter": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, lbParameterURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) UnsetLBParameter(resource map[string]any) error { + payload := map[string]any{"lbparameter": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", lbParameterURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetAllLBParameter() (map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, lbParameterURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if val, ok := result["lbparameter"]; ok { + return val.(map[string]any), nil + } + return nil, fmt.Errorf("lbparameter not found in response") +} + +// lbpersistentsessions +func (s *LBService) GetAllLBPersistentSessions() ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, lbPersistentSessionsURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbpersistentsessions"], nil +} + +func (s *LBService) CountLBPersistentSessions() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lbPersistentSessionsURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbpersistentsessions"]) > 0 { + if count, ok := result["lbpersistentsessions"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +func (s *LBService) ClearLBPersistentSessions(resource map[string]any) error { + payload := map[string]any{"lbpersistentsessions": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=clear", lbPersistentSessionsURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// lbprofile +func (s *LBService) AddLBProfile(resource map[string]any) error { + payload := map[string]any{"lbprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBProfile(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", lbProfileURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) UpdateLBProfile(resource map[string]any) error { + payload := map[string]any{"lbprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, lbProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) UnsetLBProfile(resource map[string]any) error { + payload := map[string]any{"lbprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", lbProfileURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetAllLBProfile() ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, lbProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbprofile"], nil +} + +func (s *LBService) GetLBProfile(name string) (map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbProfileURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbprofile"]) == 0 { + return nil, fmt.Errorf("lbprofile %s not found", name) + } + + return result["lbprofile"][0], nil +} + +func (s *LBService) CountLBProfile() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lbProfileURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbprofile"]) > 0 { + if count, ok := result["lbprofile"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbroute +func (s *LBService) AddLBRoute(resource map[string]any) error { + payload := map[string]any{"lbroute": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbRouteURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBRoute(network string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbRouteURL, network, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetAllLBRoute() ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, lbRouteURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbroute"], nil +} + +func (s *LBService) CountLBRoute() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lbRouteURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbroute"]) > 0 { + if count, ok := result["lbroute"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbroute6 +func (s *LBService) AddLBRoute6(resource map[string]any) error { + payload := map[string]any{"lbroute6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbRoute6URL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBRoute6(network string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbRoute6URL, network, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetAllLBRoute6() ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, lbRoute6URL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbroute6"], nil +} + +func (s *LBService) CountLBRoute6() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lbRoute6URL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbroute6"]) > 0 { + if count, ok := result["lbroute6"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbsipparameters +func (s *LBService) UpdateLBSIPParameters(resource map[string]any) error { + payload := map[string]any{"lbsipparameters": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, lbSIPParametersURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) UnsetLBSIPParameters(resource map[string]any) error { + payload := map[string]any{"lbsipparameters": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", lbSIPParametersURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetAllLBSIPParameters() (map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, lbSIPParametersURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if val, ok := result["lbsipparameters"]; ok { + return val.(map[string]any), nil + } + return nil, fmt.Errorf("lbsipparameters not found in response") +} + +// lbvserver +func (s *LBService) AddLBVServer(resource map[string]any) error { + payload := map[string]any{"lbvserver": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbVServerURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBVServer(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", lbVServerURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) UpdateLBVServer(resource map[string]any) error { + payload := map[string]any{"lbvserver": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, lbVServerURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) UnsetLBVServer(resource map[string]any) error { + payload := map[string]any{"lbvserver": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", lbVServerURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) EnableLBVServer(name string) error { + payload := map[string]any{"lbvserver": map[string]string{"name": name}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=enable", lbVServerURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DisableLBVServer(name string) error { + payload := map[string]any{"lbvserver": map[string]string{"name": name}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=disable", lbVServerURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetAllLBVServer() ([]models.LBVServer, error) { + req, err := s.client.NewRequest(http.MethodGet, lbVServerURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + LBVServer []models.LBVServer `json:"lbvserver"` + } + + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.LBVServer, nil +} + +func (s *LBService) GetLBVServer(name string) (models.LBVServer, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbVServerURL, name), nil) + if err != nil { + return models.LBVServer{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.LBVServer{}, err + } + + var result struct { + LBVServer []models.LBVServer `json:"lbvserver"` + } + + if err := json.Unmarshal(resp, &result); err != nil { + return models.LBVServer{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.LBVServer) == 0 { + return models.LBVServer{}, fmt.Errorf("lbvserver %s not found", name) + } + + return result.LBVServer[0], nil +} + +func (s *LBService) CountLBVServer() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lbVServerURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbvserver"]) > 0 { + if count, ok := result["lbvserver"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +func (s *LBService) RenameLBVServer(name, newName string) error { + payload := map[string]any{"lbvserver": map[string]string{"name": name, "newname": newName}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=rename", lbVServerURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// lbvserver_analyticsprofile_binding +func (s *LBService) AddLBVServerAnalyticsProfileBinding(resource map[string]any) error { + payload := map[string]any{"lbvserver_analyticsprofile_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbVServerAnalyticsProfileBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBVServerAnalyticsProfileBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbVServerAnalyticsProfileBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetLBVServerAnalyticsProfileBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbVServerAnalyticsProfileBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbvserver_analyticsprofile_binding"], nil +} + +func (s *LBService) CountLBVServerAnalyticsProfileBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbVServerAnalyticsProfileBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbvserver_analyticsprofile_binding"]) > 0 { + if count, ok := result["lbvserver_analyticsprofile_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbvserver_appflowpolicy_binding +func (s *LBService) AddLBVServerAppFlowPolicyBinding(resource map[string]any) error { + payload := map[string]any{"lbvserver_appflowpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbVServerAppFlowPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBVServerAppFlowPolicyBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbVServerAppFlowPolicyBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetLBVServerAppFlowPolicyBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbVServerAppFlowPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbvserver_appflowpolicy_binding"], nil +} + +func (s *LBService) CountLBVServerAppFlowPolicyBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbVServerAppFlowPolicyBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbvserver_appflowpolicy_binding"]) > 0 { + if count, ok := result["lbvserver_appflowpolicy_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbvserver_appfwpolicy_binding +func (s *LBService) AddLBVServerAppFWPolicyBinding(resource map[string]any) error { + payload := map[string]any{"lbvserver_appfwpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbVServerAppFWPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBVServerAppFWPolicyBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbVServerAppFWPolicyBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetLBVServerAppFWPolicyBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbVServerAppFWPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbvserver_appfwpolicy_binding"], nil +} + +func (s *LBService) CountLBVServerAppFWPolicyBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbVServerAppFWPolicyBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbvserver_appfwpolicy_binding"]) > 0 { + if count, ok := result["lbvserver_appfwpolicy_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbvserver_appqoepolicy_binding +func (s *LBService) AddLBVServerAppQOEPolicyBinding(resource map[string]any) error { + payload := map[string]any{"lbvserver_appqoepolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbVServerAppQOEPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBVServerAppQOEPolicyBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbVServerAppQOEPolicyBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetLBVServerAppQOEPolicyBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbVServerAppQOEPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbvserver_appqoepolicy_binding"], nil +} + +func (s *LBService) CountLBVServerAppQOEPolicyBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbVServerAppQOEPolicyBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbvserver_appqoepolicy_binding"]) > 0 { + if count, ok := result["lbvserver_appqoepolicy_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbvserver_auditnslogpolicy_binding +func (s *LBService) AddLBVServerAuditNSLogPolicyBinding(resource map[string]any) error { + payload := map[string]any{"lbvserver_auditnslogpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbVServerAuditNSLogPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBVServerAuditNSLogPolicyBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbVServerAuditNSLogPolicyBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetLBVServerAuditNSLogPolicyBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbVServerAuditNSLogPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbvserver_auditnslogpolicy_binding"], nil +} + +func (s *LBService) CountLBVServerAuditNSLogPolicyBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbVServerAuditNSLogPolicyBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbvserver_auditnslogpolicy_binding"]) > 0 { + if count, ok := result["lbvserver_auditnslogpolicy_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbvserver_auditsyslogpolicy_binding +func (s *LBService) AddLBVServerAuditSyslogPolicyBinding(resource map[string]any) error { + payload := map[string]any{"lbvserver_auditsyslogpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbVServerAuditSyslogPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBVServerAuditSyslogPolicyBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbVServerAuditSyslogPolicyBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetLBVServerAuditSyslogPolicyBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbVServerAuditSyslogPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbvserver_auditsyslogpolicy_binding"], nil +} + +func (s *LBService) CountLBVServerAuditSyslogPolicyBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbVServerAuditSyslogPolicyBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbvserver_auditsyslogpolicy_binding"]) > 0 { + if count, ok := result["lbvserver_auditsyslogpolicy_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbvserver_authorizationpolicy_binding +func (s *LBService) AddLBVServerAuthorizationPolicyBinding(resource map[string]any) error { + payload := map[string]any{"lbvserver_authorizationpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbVServerAuthorizationPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBVServerAuthorizationPolicyBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbVServerAuthorizationPolicyBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetLBVServerAuthorizationPolicyBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbVServerAuthorizationPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbvserver_authorizationpolicy_binding"], nil +} + +func (s *LBService) CountLBVServerAuthorizationPolicyBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbVServerAuthorizationPolicyBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbvserver_authorizationpolicy_binding"]) > 0 { + if count, ok := result["lbvserver_authorizationpolicy_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbvserver_binding +func (s *LBService) GetLBVServerBinding(name string) (map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbvserver_binding"]) == 0 { + return nil, fmt.Errorf("lbvserver_binding %s not found", name) + } + + return result["lbvserver_binding"][0], nil +} + +// lbvserver_botpolicy_binding +func (s *LBService) AddLBVServerBotPolicyBinding(resource map[string]any) error { + payload := map[string]any{"lbvserver_botpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbVServerBotPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBVServerBotPolicyBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbVServerBotPolicyBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetLBVServerBotPolicyBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbVServerBotPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbvserver_botpolicy_binding"], nil +} + +func (s *LBService) CountLBVServerBotPolicyBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbVServerBotPolicyBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbvserver_botpolicy_binding"]) > 0 { + if count, ok := result["lbvserver_botpolicy_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbvserver_cachepolicy_binding +func (s *LBService) AddLBVServerCachePolicyBinding(resource map[string]any) error { + payload := map[string]any{"lbvserver_cachepolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbVServerCachePolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBVServerCachePolicyBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbVServerCachePolicyBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetLBVServerCachePolicyBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbVServerCachePolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbvserver_cachepolicy_binding"], nil +} + +func (s *LBService) CountLBVServerCachePolicyBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbVServerCachePolicyBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbvserver_cachepolicy_binding"]) > 0 { + if count, ok := result["lbvserver_cachepolicy_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbvserver_cmppolicy_binding +func (s *LBService) AddLBVServerCMPPolicyBinding(resource map[string]any) error { + payload := map[string]any{"lbvserver_cmppolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbVServerCMPPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBVServerCMPPolicyBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbVServerCMPPolicyBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetLBVServerCMPPolicyBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbVServerCMPPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbvserver_cmppolicy_binding"], nil +} + +func (s *LBService) CountLBVServerCMPPolicyBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbVServerCMPPolicyBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbvserver_cmppolicy_binding"]) > 0 { + if count, ok := result["lbvserver_cmppolicy_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbvserver_contentinspectionpolicy_binding +func (s *LBService) AddLBVServerContentInspectionPolicyBinding(resource map[string]any) error { + payload := map[string]any{"lbvserver_contentinspectionpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbVServerContentInspectionPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBVServerContentInspectionPolicyBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbVServerContentInspectionPolicyBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetLBVServerContentInspectionPolicyBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbVServerContentInspectionPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbvserver_contentinspectionpolicy_binding"], nil +} + +func (s *LBService) CountLBVServerContentInspectionPolicyBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbVServerContentInspectionPolicyBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbvserver_contentinspectionpolicy_binding"]) > 0 { + if count, ok := result["lbvserver_contentinspectionpolicy_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbvserver_csvserver_binding +func (s *LBService) GetLBVServerCSVServerBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbVServerCSVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbvserver_csvserver_binding"], nil +} + +func (s *LBService) CountLBVServerCSVServerBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbVServerCSVServerBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbvserver_csvserver_binding"]) > 0 { + if count, ok := result["lbvserver_csvserver_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbvserver_dnspolicy64_binding +func (s *LBService) AddLBVServerDNSPolicy64Binding(resource map[string]any) error { + payload := map[string]any{"lbvserver_dnspolicy64_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbVServerDNSPolicy64BindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBVServerDNSPolicy64Binding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbVServerDNSPolicy64BindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetLBVServerDNSPolicy64Binding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbVServerDNSPolicy64BindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbvserver_dnspolicy64_binding"], nil +} + +func (s *LBService) CountLBVServerDNSPolicy64Binding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbVServerDNSPolicy64BindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbvserver_dnspolicy64_binding"]) > 0 { + if count, ok := result["lbvserver_dnspolicy64_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbvserver_feopolicy_binding +func (s *LBService) AddLBVServerFEOPolicyBinding(resource map[string]any) error { + payload := map[string]any{"lbvserver_feopolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbVServerFEOPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBVServerFEOPolicyBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbVServerFEOPolicyBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetLBVServerFEOPolicyBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbVServerFEOPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbvserver_feopolicy_binding"], nil +} + +func (s *LBService) CountLBVServerFEOPolicyBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbVServerFEOPolicyBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbvserver_feopolicy_binding"]) > 0 { + if count, ok := result["lbvserver_feopolicy_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbvserver_responderpolicy_binding +func (s *LBService) AddLBVServerResponderPolicyBinding(resource map[string]any) error { + payload := map[string]any{"lbvserver_responderpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbVServerResponderPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBVServerResponderPolicyBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbVServerResponderPolicyBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetLBVServerResponderPolicyBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbVServerResponderPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbvserver_responderpolicy_binding"], nil +} + +func (s *LBService) CountLBVServerResponderPolicyBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbVServerResponderPolicyBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbvserver_responderpolicy_binding"]) > 0 { + if count, ok := result["lbvserver_responderpolicy_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbvserver_rewritepolicy_binding +func (s *LBService) AddLBVServerRewritePolicyBinding(resource map[string]any) error { + payload := map[string]any{"lbvserver_rewritepolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbVServerRewritePolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBVServerRewritePolicyBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbVServerRewritePolicyBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetLBVServerRewritePolicyBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbVServerRewritePolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbvserver_rewritepolicy_binding"], nil +} + +func (s *LBService) CountLBVServerRewritePolicyBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbVServerRewritePolicyBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbvserver_rewritepolicy_binding"]) > 0 { + if count, ok := result["lbvserver_rewritepolicy_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbvserver_servicegroupmember_binding +func (s *LBService) GetLBVServerServiceGroupMemberBinding(lbvserver string) ([]models.LBVServerServiceGroupMemberBinding, error) { + u := fmt.Sprintf("%s/%s", lbVServerServiceGroupMemberBindingURL, lbvserver) + + req, err := s.client.NewRequest(http.MethodGet, u, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Binding []models.LBVServerServiceGroupMemberBinding `json:"lbvserver_servicegroupmember_binding"` + } + + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Binding, nil +} + +func (s *LBService) CountLBVServerServiceGroupMemberBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbVServerServiceGroupMemberBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbvserver_servicegroupmember_binding"]) > 0 { + if count, ok := result["lbvserver_servicegroupmember_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbvserver_servicegroup_binding +func (s *LBService) AddLBVServerServiceGroupBinding(resource map[string]any) error { + payload := map[string]any{"lbvserver_servicegroup_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbVServerServiceGroupBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBVServerServiceGroupBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbVServerServiceGroupBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetLBVServerServiceGroupBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbVServerServiceGroupBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbvserver_servicegroup_binding"], nil +} + +func (s *LBService) CountLBVServerServiceGroupBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbVServerServiceGroupBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbvserver_servicegroup_binding"]) > 0 { + if count, ok := result["lbvserver_servicegroup_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbvserver_service_binding +func (s *LBService) AddLBVServerServiceBinding(resource map[string]any) error { + payload := map[string]any{"lbvserver_service_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbVServerServiceBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBVServerServiceBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbVServerServiceBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetLBVServerServiceBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbVServerServiceBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbvserver_service_binding"], nil +} + +func (s *LBService) CountLBVServerServiceBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbVServerServiceBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbvserver_service_binding"]) > 0 { + if count, ok := result["lbvserver_service_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbvserver_spilloverpolicy_binding +func (s *LBService) AddLBVServerSpilloverPolicyBinding(resource map[string]any) error { + payload := map[string]any{"lbvserver_spilloverpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbVServerSpilloverPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBVServerSpilloverPolicyBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbVServerSpilloverPolicyBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetLBVServerSpilloverPolicyBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbVServerSpilloverPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbvserver_spilloverpolicy_binding"], nil +} + +func (s *LBService) CountLBVServerSpilloverPolicyBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbVServerSpilloverPolicyBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbvserver_spilloverpolicy_binding"]) > 0 { + if count, ok := result["lbvserver_spilloverpolicy_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbvserver_tmtrafficpolicy_binding +func (s *LBService) AddLBVServerTMTrafficPolicyBinding(resource map[string]any) error { + payload := map[string]any{"lbvserver_tmtrafficpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbVServerTMTrafficPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBVServerTMTrafficPolicyBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbVServerTMTrafficPolicyBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetLBVServerTMTrafficPolicyBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbVServerTMTrafficPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbvserver_tmtrafficpolicy_binding"], nil +} + +func (s *LBService) CountLBVServerTMTrafficPolicyBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbVServerTMTrafficPolicyBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbvserver_tmtrafficpolicy_binding"]) > 0 { + if count, ok := result["lbvserver_tmtrafficpolicy_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbvserver_transformpolicy_binding +func (s *LBService) AddLBVServerTransformPolicyBinding(resource map[string]any) error { + payload := map[string]any{"lbvserver_transformpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbVServerTransformPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBVServerTransformPolicyBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbVServerTransformPolicyBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetLBVServerTransformPolicyBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbVServerTransformPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbvserver_transformpolicy_binding"], nil +} + +func (s *LBService) CountLBVServerTransformPolicyBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbVServerTransformPolicyBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbvserver_transformpolicy_binding"]) > 0 { + if count, ok := result["lbvserver_transformpolicy_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbvserver_videooptimizationdetectionpolicy_binding +func (s *LBService) AddLBVServerVideoOptimizationDetectionPolicyBinding(resource map[string]any) error { + payload := map[string]any{"lbvserver_videooptimizationdetectionpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbVServerVideoOptimizationDetectionPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBVServerVideoOptimizationDetectionPolicyBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbVServerVideoOptimizationDetectionPolicyBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetLBVServerVideoOptimizationDetectionPolicyBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbVServerVideoOptimizationDetectionPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbvserver_videooptimizationdetectionpolicy_binding"], nil +} + +func (s *LBService) CountLBVServerVideoOptimizationDetectionPolicyBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbVServerVideoOptimizationDetectionPolicyBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbvserver_videooptimizationdetectionpolicy_binding"]) > 0 { + if count, ok := result["lbvserver_videooptimizationdetectionpolicy_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbvserver_videooptimizationpacingpolicy_binding +func (s *LBService) AddLBVServerVideoOptimizationPacingPolicyBinding(resource map[string]any) error { + payload := map[string]any{"lbvserver_videooptimizationpacingpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbVServerVideoOptimizationPacingPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBVServerVideoOptimizationPacingPolicyBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbVServerVideoOptimizationPacingPolicyBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetLBVServerVideoOptimizationPacingPolicyBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbVServerVideoOptimizationPacingPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbvserver_videooptimizationpacingpolicy_binding"], nil +} + +func (s *LBService) CountLBVServerVideoOptimizationPacingPolicyBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbVServerVideoOptimizationPacingPolicyBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbvserver_videooptimizationpacingpolicy_binding"]) > 0 { + if count, ok := result["lbvserver_videooptimizationpacingpolicy_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbwlm +func (s *LBService) AddLBWLM(resource map[string]any) error { + payload := map[string]any{"lbwlm": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbWLMURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBWLM(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", lbWLMURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) UpdateLBWLM(resource map[string]any) error { + payload := map[string]any{"lbwlm": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, lbWLMURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) UnsetLBWLM(resource map[string]any) error { + payload := map[string]any{"lbwlm": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", lbWLMURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetAllLBWLM() ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, lbWLMURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbwlm"], nil +} + +func (s *LBService) GetLBWLM(name string) (map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbWLMURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbwlm"]) == 0 { + return nil, fmt.Errorf("lbwlm %s not found", name) + } + + return result["lbwlm"][0], nil +} + +func (s *LBService) CountLBWLM() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lbWLMURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbwlm"]) > 0 { + if count, ok := result["lbwlm"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} + +// lbwlm_binding +func (s *LBService) GetLBWLMBinding(name string) (map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbWLMBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbwlm_binding"]) == 0 { + return nil, fmt.Errorf("lbwlm_binding %s not found", name) + } + + return result["lbwlm_binding"][0], nil +} + +// lbwlm_lbvserver_binding +func (s *LBService) AddLBWLMLBVServerBinding(resource map[string]any) error { + payload := map[string]any{"lbwlm_lbvserver_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lbWLMLBVServerBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) DeleteLBWLMLBVServerBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lbWLMLBVServerBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LBService) GetLBWLMLBVServerBinding(name string) ([]map[string]any, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lbWLMLBVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result["lbwlm_lbvserver_binding"], nil +} + +func (s *LBService) CountLBWLMLBVServerBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lbWLMLBVServerBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result map[string][]map[string]any + if err := json.Unmarshal(resp, &result); err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result["lbwlm_lbvserver_binding"]) > 0 { + if count, ok := result["lbwlm_lbvserver_binding"][0]["__count"].(float64); ok { + return int(count), nil + } + } + return 0, fmt.Errorf("failed to parse count") +} diff --git a/nitrogo/lldp.go b/nitrogo/lldp.go index 8b63e0f..a59b217 100644 --- a/nitrogo/lldp.go +++ b/nitrogo/lldp.go @@ -1,5 +1,19 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + lldpNeighborsURL = "/nitro/v1/config/lldpneighbors" + lldpParamURL = "/nitro/v1/config/lldpparam" +) + // Link Layer Discovery Protocol. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/lldp/lldp type LLDPService struct { @@ -9,14 +23,170 @@ type LLDPService struct { // lldpneighbors // Configuration for lldp neighbors resource // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/lldp/lldpneighbors -func (s *LLDPService) GetAllLLDPNeighbors() {} -func (s *LLDPService) GetLLDPNeighbors() {} -func (s *LLDPService) CountLLDPNeighbors() {} -func (s *LLDPService) ClearLLDPNeighbors() {} + +func (s *LLDPService) GetAllLLDPNeighbors() ([]models.LLDPNeighbors, error) { + req, err := s.client.NewRequest(http.MethodGet, lldpNeighborsURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + LLDPNeighbors []models.LLDPNeighbors `json:"lldpneighbors"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.LLDPNeighbors, nil +} + +func (s *LLDPService) GetLLDPNeighbors(ifnum string) ([]models.LLDPNeighbors, error) { + url := lldpNeighborsURL + "/" + ifnum + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + LLDPNeighbors []models.LLDPNeighbors `json:"lldpneighbors"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.LLDPNeighbors, nil +} + +func (s *LLDPService) CountLLDPNeighbors() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, lldpNeighborsURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + LLDPNeighbors []struct { + Count float64 `json:"__count"` + } `json:"lldpneighbors"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.LLDPNeighbors) > 0 { + return result.LLDPNeighbors[0].Count, nil + } + + return 0, nil +} + +func (s *LLDPService) ClearLLDPNeighbors(neighbor models.LLDPNeighbors) error { + payload := map[string]any{ + "lldpneighbors": neighbor, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, lldpNeighborsURL+"?action=clear", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} // lldpparam // Configuration for lldp params resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/lldp/lldpparam -func (s *LLDPService) UpdateLLDPParam() {} -func (s *LLDPService) UnsetLLDPParam() {} -func (s *LLDPService) GetAllLLDPParam() {} + +func (s *LLDPService) UpdateLLDPParam(param models.LLDPParam) error { + payload := map[string]any{ + "lldpparam": param, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, lldpParamURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LLDPService) UnsetLLDPParam(args []string) error { + unsetMap := make(map[string]bool) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "lldpparam": unsetMap, + } + + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, lldpParamURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LLDPService) GetAllLLDPParam() (models.LLDPParam, error) { + req, err := s.client.NewRequest(http.MethodGet, lldpParamURL, nil) + if err != nil { + return models.LLDPParam{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.LLDPParam{}, err + } + + var result struct { + LLDPParams []models.LLDPParam `json:"lldpparam"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.LLDPParam{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.LLDPParams) > 0 { + return result.LLDPParams[0], nil + } + + return models.LLDPParam{}, nil +} diff --git a/nitrogo/lsn.go b/nitrogo/lsn.go index c3e0b94..561149b 100644 --- a/nitrogo/lsn.go +++ b/nitrogo/lsn.go @@ -1,285 +1,4180 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "strings" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + lsnAppsAttributesURL = "/nitro/v1/config/lsnappsattributes" + lsnAppsProfileURL = "/nitro/v1/config/lsnappsprofile" + lsnAppsProfileBindingURL = "/nitro/v1/config/lsnappsprofile_binding" + lsnAppsProfileLSNAppsAttributesBindingURL = "/nitro/v1/config/lsnappsprofile_lsnappsattributes_binding" + lsnAppsProfilePortBindingURL = "/nitro/v1/config/lsnappsprofile_port_binding" + lsnClientURL = "/nitro/v1/config/lsnclient" + lsnClientBindingURL = "/nitro/v1/config/lsnclient_binding" + lsnClientNetwork6BindingURL = "/nitro/v1/config/lsnclient_network6_binding" + lsnClientNetworkBindingURL = "/nitro/v1/config/lsnclient_network_binding" + lsnClientNSACL6BindingURL = "/nitro/v1/config/lsnclient_nsacl6_binding" + lsnClientNSACLBindingURL = "/nitro/v1/config/lsnclient_nsacl_binding" + lsnDeterministicNATURL = "/nitro/v1/config/lsndeterministicnat" + lsnGroupURL = "/nitro/v1/config/lsngroup" + lsnGroupBindingURL = "/nitro/v1/config/lsngroup_binding" + lsnGroupIPSecALGProfileBindingURL = "/nitro/v1/config/lsngroup_ipsecalgprofile_binding" + lsnGroupLSNAppsProfileBindingURL = "/nitro/v1/config/lsngroup_lsnappsprofile_binding" + lsnGroupLSNHTTPHDRLogProfileBindingURL = "/nitro/v1/config/lsngroup_lsnhttphdrlogprofile_binding" + lsnGroupLSNLogProfileBindingURL = "/nitro/v1/config/lsngroup_lsnlogprofile_binding" + lsnGroupLSNPoolBindingURL = "/nitro/v1/config/lsngroup_lsnpool_binding" + lsnGroupLSNRTSPALGProfileBindingURL = "/nitro/v1/config/lsngroup_lsnrtspalgprofile_binding" + lsnGroupLSNSIPALGProfileBindingURL = "/nitro/v1/config/lsngroup_lsnsipalgprofile_binding" + lsnGroupLSNTransportProfileBindingURL = "/nitro/v1/config/lsngroup_lsntransportprofile_binding" + lsnGroupPCPServerBindingURL = "/nitro/v1/config/lsngroup_pcpserver_binding" + lsnHTTPHDRLogProfileURL = "/nitro/v1/config/lsnhttphdrlogprofile" + lsnIP6ProfileURL = "/nitro/v1/config/lsnip6profile" + lsnLogProfileURL = "/nitro/v1/config/lsnlogprofile" + lsnParameterURL = "/nitro/v1/config/lsnparameter" + lsnPoolURL = "/nitro/v1/config/lsnpool" + lsnPoolBindingURL = "/nitro/v1/config/lsnpool_binding" + lsnPoolLSNIPBindingURL = "/nitro/v1/config/lsnpool_lsnip_binding" + lsnRTSPALGProfileURL = "/nitro/v1/config/lsnrtspalgprofile" + lsnRTSPALGSessionURL = "/nitro/v1/config/lsnrtspalgsession" + lsnRTSPALGSessionBindingURL = "/nitro/v1/config/lsnrtspalgsession_binding" + lsnRTSPALGSessionDataChannelBindingURL = "/nitro/v1/config/lsnrtspalgsession_datachannel_binding" + lsnSessionURL = "/nitro/v1/config/lsnsession" + lsnSIPALGCallURL = "/nitro/v1/config/lsnsipalgcall" + lsnSIPALGCallBindingURL = "/nitro/v1/config/lsnsipalgcall_binding" + lsnSIPALGCallControlChannelBindingURL = "/nitro/v1/config/lsnsipalgcall_controlchannel_binding" + lsnSIPALGCallDataChannelBindingURL = "/nitro/v1/config/lsnsipalgcall_datachannel_binding" + lsnSIPALGProfileURL = "/nitro/v1/config/lsnsipalgprofile" + lsnStaticURL = "/nitro/v1/config/lsnstatic" + lsnTransportProfileURL = "/nitro/v1/config/lsntransportprofile" +) + // Large Scale NAT commands type LSNService struct { client *Client } // lsnappsattributes -func (s *LSNService) AddLSNAppsAttributes() {} -func (s *LSNService) DeleteLSNAppsAttributes() {} -func (s *LSNService) UpdateLSNAppsAttributes() {} -func (s *LSNService) UnsetLSNAppsAttributes() {} -func (s *LSNService) GetAllLSNAppsAttributes() {} -func (s *LSNService) GetLSNAppsAttributes() {} -func (s *LSNService) CountLSNAppsAttributes() {} +func (s *LSNService) AddLSNAppsAttributes(resource models.LSNAppsAttributes) error { + payload := map[string]any{"lsnappsattributes": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lsnAppsAttributesURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) DeleteLSNAppsAttributes(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", lsnAppsAttributesURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) UpdateLSNAppsAttributes(resource models.LSNAppsAttributes) error { + payload := map[string]any{"lsnappsattributes": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, lsnAppsAttributesURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) UnsetLSNAppsAttributes(resource models.LSNAppsAttributes) error { + payload := map[string]any{"lsnappsattributes": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", lsnAppsAttributesURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) GetAllLSNAppsAttributes() ([]models.LSNAppsAttributes, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnAppsAttributesURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNAppsAttributes `json:"lsnappsattributes"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNAppsAttributes(name string) (models.LSNAppsAttributes, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnAppsAttributesURL, name), nil) + if err != nil { + return models.LSNAppsAttributes{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.LSNAppsAttributes{}, err + } + + var result struct { + Data []models.LSNAppsAttributes `json:"lsnappsattributes"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.LSNAppsAttributes{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.LSNAppsAttributes{}, fmt.Errorf("lsnappsattributes %s not found", name) + } + + return result.Data[0], nil +} + +func (s *LSNService) CountLSNAppsAttributes() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lsnAppsAttributesURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNAppsAttributes `json:"lsnappsattributes"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} // lsnappsprofile -func (s *LSNService) AddLSNAppsProfile() {} -func (s *LSNService) DeleteLSNAppsProfile() {} -func (s *LSNService) UpdateLSNAppsProfile() {} -func (s *LSNService) UnsetLSNAppsProfile() {} -func (s *LSNService) GetAllLSNAppsProfile() {} -func (s *LSNService) GetLSNAppsProfile() {} -func (s *LSNService) CountLSNAppsProfile() {} +func (s *LSNService) AddLSNAppsProfile(resource models.LSNAppsProfile) error { + payload := map[string]any{"lsnappsprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lsnAppsProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) DeleteLSNAppsProfile(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", lsnAppsProfileURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) UpdateLSNAppsProfile(resource models.LSNAppsProfile) error { + payload := map[string]any{"lsnappsprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, lsnAppsProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) UnsetLSNAppsProfile(resource models.LSNAppsProfile) error { + payload := map[string]any{"lsnappsprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", lsnAppsProfileURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) GetAllLSNAppsProfile() ([]models.LSNAppsProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnAppsProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNAppsProfile `json:"lsnappsprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNAppsProfile(name string) (models.LSNAppsProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnAppsProfileURL, name), nil) + if err != nil { + return models.LSNAppsProfile{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.LSNAppsProfile{}, err + } + + var result struct { + Data []models.LSNAppsProfile `json:"lsnappsprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.LSNAppsProfile{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.LSNAppsProfile{}, fmt.Errorf("lsnappsprofile %s not found", name) + } + + return result.Data[0], nil +} + +func (s *LSNService) CountLSNAppsProfile() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lsnAppsProfileURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNAppsProfile `json:"lsnappsprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} // lsnappsprofile_binding -func (s *LSNService) GetAllLSNAppsProfileBinding() {} -func (s *LSNService) GetLSNAppsProfileBinding() {} +func (s *LSNService) GetAllLSNAppsProfileBinding() ([]models.LSNAppsProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnAppsProfileBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNAppsProfileBinding `json:"lsnappsprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNAppsProfileBinding(name string) (models.LSNAppsProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnAppsProfileBindingURL, name), nil) + if err != nil { + return models.LSNAppsProfileBinding{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.LSNAppsProfileBinding{}, err + } + + var result struct { + Data []models.LSNAppsProfileBinding `json:"lsnappsprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.LSNAppsProfileBinding{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.LSNAppsProfileBinding{}, fmt.Errorf("lsnappsprofile_binding %s not found", name) + } + + return result.Data[0], nil +} // lsnappsprofile_lsnappsattributes_binding -func (s *LSNService) AddLSNAppsProfileLSNAppsAttributesBinding() {} -func (s *LSNService) DeleteLSNAppsProfileLSNAppsAttributesBinding() {} -func (s *LSNService) GetAllLSNAppsProfileLSNAppsAttributesBinding() {} -func (s *LSNService) GetLSNAppsProfileLSNAppsAttributesBinding() {} -func (s *LSNService) CountLSNAppsProfileLSNAppsAttributesBinding() {} +func (s *LSNService) AddLSNAppsProfileLSNAppsAttributesBinding(resource models.LSNAppsProfileLSNAppsAttributesBinding) error { + payload := map[string]any{"lsnappsprofile_lsnappsattributes_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lsnAppsProfileLSNAppsAttributesBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) DeleteLSNAppsProfileLSNAppsAttributesBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lsnAppsProfileLSNAppsAttributesBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) GetAllLSNAppsProfileLSNAppsAttributesBinding() ([]models.LSNAppsProfileLSNAppsAttributesBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnAppsProfileLSNAppsAttributesBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNAppsProfileLSNAppsAttributesBinding `json:"lsnappsprofile_lsnappsattributes_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNAppsProfileLSNAppsAttributesBinding(name string) ([]models.LSNAppsProfileLSNAppsAttributesBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnAppsProfileLSNAppsAttributesBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNAppsProfileLSNAppsAttributesBinding `json:"lsnappsprofile_lsnappsattributes_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) CountLSNAppsProfileLSNAppsAttributesBinding(appsprofilename string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lsnAppsProfileLSNAppsAttributesBindingURL, appsprofilename), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNAppsProfileLSNAppsAttributesBinding `json:"lsnappsprofile_lsnappsattributes_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} // lsnappsprofile_port_binding -func (s *LSNService) AddLSNAppsProfilePortBinding() {} -func (s *LSNService) DeleteLSNAppsProfilePortBinding() {} -func (s *LSNService) GetAllLSNAppsProfilePortBinding() {} -func (s *LSNService) GetLSNAppsProfilePortBinding() {} -func (s *LSNService) CountLSNAppsProfilePortBinding() {} +func (s *LSNService) AddLSNAppsProfilePortBinding(resource models.LSNAppsProfilePortBinding) error { + payload := map[string]any{"lsnappsprofile_port_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lsnAppsProfilePortBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) DeleteLSNAppsProfilePortBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lsnAppsProfilePortBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) GetAllLSNAppsProfilePortBinding() ([]models.LSNAppsProfilePortBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnAppsProfilePortBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNAppsProfilePortBinding `json:"lsnappsprofile_port_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNAppsProfilePortBinding(name string) ([]models.LSNAppsProfilePortBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnAppsProfilePortBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNAppsProfilePortBinding `json:"lsnappsprofile_port_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) CountLSNAppsProfilePortBinding(appsprofilename string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lsnAppsProfilePortBindingURL, appsprofilename), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNAppsProfilePortBinding `json:"lsnappsprofile_port_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} // lsnclient -func (s *LSNService) AddLSNClient() {} -func (s *LSNService) DeleteLSNClient() {} -func (s *LSNService) GetAllLSNClient() {} -func (s *LSNService) GetLSNClient() {} -func (s *LSNService) CountLSNClient() {} +func (s *LSNService) AddLSNClient(resource models.LSNClient) error { + payload := map[string]any{"lsnclient": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lsnClientURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) DeleteLSNClient(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", lsnClientURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) GetAllLSNClient() ([]models.LSNClient, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnClientURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNClient `json:"lsnclient"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNClient(name string) (models.LSNClient, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnClientURL, name), nil) + if err != nil { + return models.LSNClient{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.LSNClient{}, err + } + + var result struct { + Data []models.LSNClient `json:"lsnclient"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.LSNClient{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.LSNClient{}, fmt.Errorf("lsnclient %s not found", name) + } + + return result.Data[0], nil +} + +func (s *LSNService) CountLSNClient() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lsnClientURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNClient `json:"lsnclient"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} // lsnclient_binding -func (s *LSNService) GetAllLSNClientBinding() {} -func (s *LSNService) GetLSNClientBinding() {} +func (s *LSNService) GetAllLSNClientBinding() ([]models.LSNClientBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnClientBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNClientBinding `json:"lsnclient_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNClientBinding(name string) (models.LSNClientBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnClientBindingURL, name), nil) + if err != nil { + return models.LSNClientBinding{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.LSNClientBinding{}, err + } + + var result struct { + Data []models.LSNClientBinding `json:"lsnclient_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.LSNClientBinding{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.LSNClientBinding{}, fmt.Errorf("lsnclient_binding %s not found", name) + } + + return result.Data[0], nil +} // lsnclient_network6_binding -func (s *LSNService) AddLSNClientNetwork6Binding() {} -func (s *LSNService) DeleteLSNClientNetwork6Binding() {} -func (s *LSNService) GetAllLSNClientNetwork6Binding() {} -func (s *LSNService) GetLSNClientNetwork6Binding() {} -func (s *LSNService) CountLSNClientNetwork6Binding() {} +func (s *LSNService) AddLSNClientNetwork6Binding(resource models.LSNClientNetwork6Binding) error { + payload := map[string]any{"lsnclient_network6_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lsnClientNetwork6BindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) DeleteLSNClientNetwork6Binding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lsnClientNetwork6BindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) GetAllLSNClientNetwork6Binding() ([]models.LSNClientNetwork6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnClientNetwork6BindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNClientNetwork6Binding `json:"lsnclient_network6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNClientNetwork6Binding(name string) ([]models.LSNClientNetwork6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnClientNetwork6BindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNClientNetwork6Binding `json:"lsnclient_network6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) CountLSNClientNetwork6Binding(clientname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lsnClientNetwork6BindingURL, clientname), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNClientNetwork6Binding `json:"lsnclient_network6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} // lsnclient_network_binding -func (s *LSNService) AddLSNClientNetworkBinding() {} -func (s *LSNService) DeleteLSNClientNetworkBinding() {} -func (s *LSNService) GetAllLSNClientNetworkBinding() {} -func (s *LSNService) GetLSNClientNetworkBinding() {} -func (s *LSNService) CountLSNClientNetworkBinding() {} +func (s *LSNService) AddLSNClientNetworkBinding(resource models.LSNClientNetworkBinding) error { + payload := map[string]any{"lsnclient_network_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lsnClientNetworkBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) DeleteLSNClientNetworkBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lsnClientNetworkBindingURL, name, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) GetAllLSNClientNetworkBinding() ([]models.LSNClientNetworkBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnClientNetworkBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNClientNetworkBinding `json:"lsnclient_network_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNClientNetworkBinding(name string) ([]models.LSNClientNetworkBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnClientNetworkBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNClientNetworkBinding `json:"lsnclient_network_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) CountLSNClientNetworkBinding(clientname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lsnClientNetworkBindingURL, clientname), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNClientNetworkBinding `json:"lsnclient_network_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} // lsnclient_nsacl6_binding -func (s *LSNService) AddLSNClientNSACL6Binding() {} -func (s *LSNService) DeleteLSNClientNSACL6Binding() {} -func (s *LSNService) GetAllLSNClientNSACL6Binding() {} -func (s *LSNService) GetLSNClientNSACL6Binding() {} -func (s *LSNService) CountLSNClientNSACL6Binding() {} +func (s *LSNService) AddLSNClientNSACL6Binding(resource models.LSNClientNSACL6Binding) error { + payload := map[string]any{"lsnclient_nsacl6_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// lsnclient_nsacl_binding -func (s *LSNService) AddLSNClientNSACLBinding() {} -func (s *LSNService) DeleteLSNClientNSACLBinding() {} -func (s *LSNService) GetAllLSNClientNSACLBinding() {} -func (s *LSNService) GetLSNClientNSACLBinding() {} -func (s *LSNService) CountLSNClientNSACLBinding() {} + req, err := s.client.NewRequest(http.MethodPost, lsnClientNSACL6BindingURL, bytes.NewReader(data)) + if err != nil { + return err + } -// lsndeterministicnat -func (s *LSNService) GetAllLSNDeterministicNAT() {} -func (s *LSNService) CountLSNDeterministicNAT() {} + _, err = s.client.Do(req) + return err +} -// lsngroup -func (s *LSNService) AddLSNGroup() {} -func (s *LSNService) DeleteLSNGroup() {} -func (s *LSNService) UpdateLSNGroup() {} -func (s *LSNService) UnsetLSNGroup() {} -func (s *LSNService) GetAllLSNGroup() {} -func (s *LSNService) GetLSNGroup() {} -func (s *LSNService) CountLSNGroup() {} +func (s *LSNService) DeleteLSNClientNSACL6Binding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lsnClientNSACL6BindingURL, name, argsStr), nil) + if err != nil { + return err + } -// lsngroup_binding -func (s *LSNService) GetAllLSNGroupBinding() {} -func (s *LSNService) GetLSNGroupBinding() {} + _, err = s.client.Do(req) + return err +} -// lsngroup_ipsecalgprofile_binding -func (s *LSNService) AddLSNGroupIPSecALGProfileBinding() {} -func (s *LSNService) DeleteLSNGroupIPSecALGProfileBinding() {} -func (s *LSNService) GetAllLSNGroupIPSecALGProfileBinding() {} -func (s *LSNService) GetLSNGroupIPSecALGProfileBinding() {} -func (s *LSNService) CountLSNGroupIPSecALGProfileBinding() {} +func (s *LSNService) GetAllLSNClientNSACL6Binding() ([]models.LSNClientNSACL6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnClientNSACL6BindingURL, nil) + if err != nil { + return nil, err + } -// lsngroup_lsnappsprofile_binding -func (s *LSNService) AddLSNGroupLSNAppsProfileBinding() {} -func (s *LSNService) DeleteLSNGroupLSNAppsProfileBinding() {} -func (s *LSNService) GetAllLSNGroupLSNAppsProfileBinding() {} -func (s *LSNService) GetLSNGroupLSNAppsProfileBinding() {} -func (s *LSNService) CountLSNGroupLSNAppsProfileBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// lsngroup_lsnhttphdrlogprofile_binding -func (s *LSNService) AddLSNGroupLSNHTTPHDRLogProfileBinding() {} -func (s *LSNService) DeleteLSNGroupLSNHTTPHDRLogProfileBinding() {} -func (s *LSNService) GetAllLSNGroupLSNHTTPHDRLogProfileBinding() {} -func (s *LSNService) GetLSNGroupLSNHTTPHDRLogProfileBinding() {} -func (s *LSNService) CountLSNGroupLSNHTTPHDRLogProfileBinding() {} + var result struct { + Data []models.LSNClientNSACL6Binding `json:"lsnclient_nsacl6_binding"` + } -// lsngroup_lsnlogprofile_binding -func (s *LSNService) AddLSNGroupLSNLogProfileBinding() {} -func (s *LSNService) DeleteLSNGroupLSNLogProfileBinding() {} -func (s *LSNService) GetAllLSNGroupLSNLogProfileBinding() {} -func (s *LSNService) GetLSNGroupLSNLogProfileBinding() {} -func (s *LSNService) CountLSNGroupLSNLogProfileBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// lsngroup_lsnpool_binding -func (s *LSNService) AddLSNGroupLSNPoolBinding() {} -func (s *LSNService) DeleteLSNGroupLSNPoolBinding() {} -func (s *LSNService) GetAllLSNGroupLSNPoolBinding() {} -func (s *LSNService) GetLSNGroupLSNPoolBinding() {} -func (s *LSNService) CountLSNGroupLSNPoolBinding() {} + return result.Data, nil +} -// lsngroup_lsnrtspalgprofile_binding -func (s *LSNService) AddLSNGroupLSNRTSPALGProfileBinding() {} -func (s *LSNService) DeleteLSNGroupLSNRTSPALGProfileBinding() {} -func (s *LSNService) GetAllLSNGroupLSNRTSPALGProfileBinding() {} -func (s *LSNService) GetLSNGroupLSNRTSPALGProfileBinding() {} -func (s *LSNService) CountLSNGroupLSNRTSPALGProfileBinding() {} +func (s *LSNService) GetLSNClientNSACL6Binding(name string) ([]models.LSNClientNSACL6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnClientNSACL6BindingURL, name), nil) + if err != nil { + return nil, err + } -// lsngroup_lsnsipalgprofile_binding -func (s *LSNService) AddKSBGroupLSNSIPALGProfileBinding() {} -func (s *LSNService) DeleteKSBGroupLSNSIPALGProfileBinding() {} -func (s *LSNService) GetAllKSBGroupLSNSIPALGProfileBinding() {} -func (s *LSNService) GetKSBGroupLSNSIPALGProfileBinding() {} -func (s *LSNService) CountKSBGroupLSNSIPALGProfileBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// lsngroup_lsntransportprofile_binding -func (s *LSNService) AddLSNGroupLSNTransportProfileBinding() {} -func (s *LSNService) DeleteLSNGroupLSNTransportProfileBinding() {} -func (s *LSNService) GetAllLSNGroupLSNTransportProfileBinding() {} -func (s *LSNService) GetLSNGroupLSNTransportProfileBinding() {} -func (s *LSNService) CountLSNGroupLSNTransportProfileBinding() {} + var result struct { + Data []models.LSNClientNSACL6Binding `json:"lsnclient_nsacl6_binding"` + } -// lsngroup_pcpserver_binding -func (s *LSNService) AddLSNGroupPCPServerBinding() {} -func (s *LSNService) DeleteLSNGroupPCPServerBinding() {} -func (s *LSNService) GetAllLSNGroupPCPServerBinding() {} -func (s *LSNService) GetLSNGroupPCPServerBinding() {} -func (s *LSNService) CountLSNGroupPCPServerBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// lsnhttphdrlogprofile -func (s *LSNService) AddLSNHTTPHDRLogProfile() {} -func (s *LSNService) DeleteLSNHTTPHDRLogProfile() {} -func (s *LSNService) UpdateLSNHTTPHDRLogProfile() {} -func (s *LSNService) UnsetLSNHTTPHDRLogProfile() {} -func (s *LSNService) GetAllLSNHTTPHDRLogProfile() {} -func (s *LSNService) GetLSNHTTPHDRLogProfile() {} -func (s *LSNService) CountLSNHTTPHDRLogProfile() {} + return result.Data, nil +} -// lsnip6profile -func (s *LSNService) AddLSNIP6Profile() {} -func (s *LSNService) DeleteLSNIP6Profile() {} -func (s *LSNService) GetAllLSNIP6Profile() {} -func (s *LSNService) GetLSNIP6Profile() {} -func (s *LSNService) CountLSNIP6Profile() {} +func (s *LSNService) CountLSNClientNSACL6Binding(clientname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lsnClientNSACL6BindingURL, clientname), nil) + if err != nil { + return 0, err + } -// lsnlogprofile -func (s *LSNService) AddLSNLogProfile() {} -func (s *LSNService) DeleteLSNLogProfile() {} -func (s *LSNService) UpdateLSNLogProfile() {} -func (s *LSNService) UnsetLSNLogProfile() {} -func (s *LSNService) GetAllLSNLogProfile() {} -func (s *LSNService) GetLSNLogProfile() {} -func (s *LSNService) CountLSNLogProfile() {} + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } -// lsnparameter -func (s *LSNService) UpdateLSNParameter() {} -func (s *LSNService) UnsetLSNParameter() {} -func (s *LSNService) GetAllLSNParameter() {} + var result struct { + Data []models.LSNClientNSACL6Binding `json:"lsnclient_nsacl6_binding"` + } -// lsnpool -func (s *LSNService) AddLSNPool() {} -func (s *LSNService) DeleteLSNPool() {} -func (s *LSNService) UpdateLSNPool() {} -func (s *LSNService) UnsetLSNPool() {} -func (s *LSNService) GetAllLSNPool() {} -func (s *LSNService) GetLSNPool() {} -func (s *LSNService) CountLSNPool() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } -// lsnpool_binding -func (s *LSNService) GetAllLSNPoolBinding() {} -func (s *LSNService) GetLSNPoolBinding() {} + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} -// lsnpool_lsnip_binding -func (s *LSNService) AddLSNPoolLSNIPBinding() {} -func (s *LSNService) DeleteLSNPoolLSNIPBinding() {} -func (s *LSNService) GetAllLSNPoolLSNIPBinding() {} -func (s *LSNService) GetLSNPoolLSNIPBinding() {} -func (s *LSNService) CountLSNPoolLSNIPBinding() {} +// lsnclient_nsacl_binding +func (s *LSNService) AddLSNClientNSACLBinding(resource models.LSNClientNSACLBinding) error { + payload := map[string]any{"lsnclient_nsacl_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// lsnrtspalgprofile -func (s *LSNService) AddLSNRTSPALGProfile() {} -func (s *LSNService) DeleteLSNRTSPALGProfile() {} -func (s *LSNService) UpdateLSNRTSPALGProfile() {} -func (s *LSNService) UnsetLSNRTSPALGProfile() {} -func (s *LSNService) GetAllLSNRTSPALGProfile() {} -func (s *LSNService) GetLSNRTSPALGProfile() {} -func (s *LSNService) CountLSNRTSPALGProfile() {} + req, err := s.client.NewRequest(http.MethodPost, lsnClientNSACLBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } -// lsnrtspalgsession -func (s *LSNService) GetAllLSNRTSPALGSession() {} -func (s *LSNService) GetLSNRTSPALGSession() {} -func (s *LSNService) CountLSNRTSPALGSession() {} -func (s *LSNService) FlushLSNRTSPALGSession() {} + _, err = s.client.Do(req) + return err +} -// lsnrtspalgsession_binding -func (s *LSNService) GetAllLSNRTSPALGSessionBinding() {} -func (s *LSNService) GetLSNRTSPALGSessionBinding() {} +func (s *LSNService) DeleteLSNClientNSACLBinding(name string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lsnClientNSACLBindingURL, name, argsStr), nil) + if err != nil { + return err + } -// lsnrtspalgsession_datachannel_binding -func (s *LSNService) GetAllLSNRTSPALGSessionDataChannelBinding() {} -func (s *LSNService) GetLSNRTSPALGSessionDataChannelBinding() {} -func (s *LSNService) CountLSNRTSPALGSessionDataChannelBinding() {} + _, err = s.client.Do(req) + return err +} -// lsnsession -func (s *LSNService) GetAllLSNSession() {} -func (s *LSNService) CountLSNSession() {} -func (s *LSNService) FlushLSNSession() {} +func (s *LSNService) GetAllLSNClientNSACLBinding() ([]models.LSNClientNSACLBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnClientNSACLBindingURL, nil) + if err != nil { + return nil, err + } -// lsnsipalgcall -func (s *LSNService) GetAllLSNSIPALGCall() {} -func (s *LSNService) GetLSNSIPALGCall() {} -func (s *LSNService) CountLSNSIPALGCall() {} -func (s *LSNService) FlushLSNSIPALGCall() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// lsnsipalgcall_binding -func (s *LSNService) GetAllLSNSIPALGCallBinding() {} -func (s *LSNService) GetLSNSIPALGCallBinding() {} + var result struct { + Data []models.LSNClientNSACLBinding `json:"lsnclient_nsacl_binding"` + } -// lsnsipalgcall_controlchannel_binding -func (s *LSNService) GetAllLSNSIPALGCallControlChannelBinding() {} -func (s *LSNService) GetLSNSIPALGCallControlChannelBinding() {} -func (s *LSNService) CountLSNSIPALGCallControlChannelBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// lsnsipalgcall_datachannel_binding -func (s *LSNService) GetAllLSNSIPALGCallDataChannelBinding() {} -func (s *LSNService) GetLSNSIPALGCallDataChannelBinding() {} -func (s *LSNService) CountLSNSIPALGCallDataChannelBinding() {} + return result.Data, nil +} -// lsnsipalgprofile -func (s *LSNService) AddLSNSIPALGProfile() {} -func (s *LSNService) DeleteLSNSIPALGProfile() {} -func (s *LSNService) UpdateLSNSIPALGProfile() {} -func (s *LSNService) UnsetLSNSIPALGProfile() {} -func (s *LSNService) GetAllLSNSIPALGProfile() {} -func (s *LSNService) GetLSNSIPALGProfile() {} -func (s *LSNService) CountLSNSIPALGProfile() {} +func (s *LSNService) GetLSNClientNSACLBinding(name string) ([]models.LSNClientNSACLBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnClientNSACLBindingURL, name), nil) + if err != nil { + return nil, err + } -// lsnstatic -func (s *LSNService) AddLSNStatic() {} -func (s *LSNService) DeleteLSNStatic() {} -func (s *LSNService) GetAllLSNStatic() {} -func (s *LSNService) GetLSNStatic() {} -func (s *LSNService) CountLSNStatic() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// lsntransportprofile -func (s *LSNService) AddLSNTransportProfile() {} -func (s *LSNService) DeleteLSNTransportProfile() {} -func (s *LSNService) UpdateLSNTransportProfile() {} -func (s *LSNService) UnsetLSNTransportProfile() {} -func (s *LSNService) GetAllLSNTransportProfile() {} -func (s *LSNService) GetLSNTransportProfile() {} -func (s *LSNService) CountLSNTransportProfile() {} + var result struct { + Data []models.LSNClientNSACLBinding `json:"lsnclient_nsacl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) CountLSNClientNSACLBinding(clientname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lsnClientNSACLBindingURL, clientname), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNClientNSACLBinding `json:"lsnclient_nsacl_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// lsndeterministicnat +func (s *LSNService) GetAllLSNDeterministicNAT() ([]models.LSNDeterministicNAT, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnDeterministicNATURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNDeterministicNAT `json:"lsndeterministicnat"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) CountLSNDeterministicNAT() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lsnDeterministicNATURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNDeterministicNAT `json:"lsndeterministicnat"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// lsngroup +func (s *LSNService) AddLSNGroup(resource models.LSNGroup) error { + payload := map[string]any{"lsngroup": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lsnGroupURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) DeleteLSNGroup(groupname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", lsnGroupURL, groupname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) UpdateLSNGroup(resource models.LSNGroup) error { + payload := map[string]any{"lsngroup": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, lsnGroupURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) UnsetLSNGroup(resource models.LSNGroup) error { + payload := map[string]any{"lsngroup": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", lsnGroupURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) GetAllLSNGroup() ([]models.LSNGroup, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnGroupURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNGroup `json:"lsngroup"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNGroup(groupname string) (models.LSNGroup, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnGroupURL, groupname), nil) + if err != nil { + return models.LSNGroup{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.LSNGroup{}, err + } + + var result struct { + Data []models.LSNGroup `json:"lsngroup"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.LSNGroup{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.LSNGroup{}, fmt.Errorf("lsngroup %s not found", groupname) + } + + return result.Data[0], nil +} + +func (s *LSNService) CountLSNGroup() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lsnGroupURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNGroup `json:"lsngroup"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// lsngroup_binding +func (s *LSNService) GetAllLSNGroupBinding() ([]models.LSNGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnGroupBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNGroupBinding `json:"lsngroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNGroupBinding(groupname string) (models.LSNGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnGroupBindingURL, groupname), nil) + if err != nil { + return models.LSNGroupBinding{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.LSNGroupBinding{}, err + } + + var result struct { + Data []models.LSNGroupBinding `json:"lsngroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.LSNGroupBinding{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.LSNGroupBinding{}, fmt.Errorf("lsngroup_binding %s not found", groupname) + } + + return result.Data[0], nil +} + +// lsngroup_ipsecalgprofile_binding +func (s *LSNService) AddLSNGroupIPSecALGProfileBinding(resource models.LSNGroupIPSECALGProfileBinding) error { + payload := map[string]any{"lsngroup_ipsecalgprofile_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lsnGroupIPSecALGProfileBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) DeleteLSNGroupIPSecALGProfileBinding(groupname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lsnGroupIPSecALGProfileBindingURL, groupname, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) GetAllLSNGroupIPSecALGProfileBinding() ([]models.LSNGroupIPSECALGProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnGroupIPSecALGProfileBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNGroupIPSECALGProfileBinding `json:"lsngroup_ipsecalgprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNGroupIPSecALGProfileBinding(groupname string) ([]models.LSNGroupIPSECALGProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnGroupIPSecALGProfileBindingURL, groupname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNGroupIPSECALGProfileBinding `json:"lsngroup_ipsecalgprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) CountLSNGroupIPSecALGProfileBinding(groupname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lsnGroupIPSecALGProfileBindingURL, groupname), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNGroupIPSECALGProfileBinding `json:"lsngroup_ipsecalgprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// lsngroup_lsnappsprofile_binding +func (s *LSNService) AddLSNGroupLSNAppsProfileBinding(resource models.LSNGroupLSNAppsProfileBinding) error { + payload := map[string]any{"lsngroup_lsnappsprofile_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lsnGroupLSNAppsProfileBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) DeleteLSNGroupLSNAppsProfileBinding(groupname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lsnGroupLSNAppsProfileBindingURL, groupname, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) GetAllLSNGroupLSNAppsProfileBinding() ([]models.LSNGroupLSNAppsProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnGroupLSNAppsProfileBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNGroupLSNAppsProfileBinding `json:"lsngroup_lsnappsprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNGroupLSNAppsProfileBinding(groupname string) ([]models.LSNGroupLSNAppsProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnGroupLSNAppsProfileBindingURL, groupname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNGroupLSNAppsProfileBinding `json:"lsngroup_lsnappsprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) CountLSNGroupLSNAppsProfileBinding(groupname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lsnGroupLSNAppsProfileBindingURL, groupname), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNGroupLSNAppsProfileBinding `json:"lsngroup_lsnappsprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// lsngroup_lsnhttphdrlogprofile_binding +func (s *LSNService) AddLSNGroupLSNHTTPHDRLogProfileBinding(resource models.LSNGroupLSNHTTPHdrLogProfileBinding) error { + payload := map[string]any{"lsngroup_lsnhttphdrlogprofile_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lsnGroupLSNHTTPHDRLogProfileBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) DeleteLSNGroupLSNHTTPHDRLogProfileBinding(groupname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lsnGroupLSNHTTPHDRLogProfileBindingURL, groupname, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) GetAllLSNGroupLSNHTTPHDRLogProfileBinding() ([]models.LSNGroupLSNHTTPHdrLogProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnGroupLSNHTTPHDRLogProfileBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNGroupLSNHTTPHdrLogProfileBinding `json:"lsngroup_lsnhttphdrlogprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNGroupLSNHTTPHDRLogProfileBinding(groupname string) ([]models.LSNGroupLSNHTTPHdrLogProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnGroupLSNHTTPHDRLogProfileBindingURL, groupname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNGroupLSNHTTPHdrLogProfileBinding `json:"lsngroup_lsnhttphdrlogprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) CountLSNGroupLSNHTTPHDRLogProfileBinding(groupname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lsnGroupLSNHTTPHDRLogProfileBindingURL, groupname), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNGroupLSNHTTPHdrLogProfileBinding `json:"lsngroup_lsnhttphdrlogprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// lsngroup_lsnlogprofile_binding +func (s *LSNService) AddLSNGroupLSNLogProfileBinding(resource models.LSNGroupLSNLogProfileBinding) error { + payload := map[string]any{"lsngroup_lsnlogprofile_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lsnGroupLSNLogProfileBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) DeleteLSNGroupLSNLogProfileBinding(groupname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lsnGroupLSNLogProfileBindingURL, groupname, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) GetAllLSNGroupLSNLogProfileBinding() ([]models.LSNGroupLSNLogProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnGroupLSNLogProfileBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNGroupLSNLogProfileBinding `json:"lsngroup_lsnlogprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNGroupLSNLogProfileBinding(groupname string) ([]models.LSNGroupLSNLogProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnGroupLSNLogProfileBindingURL, groupname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNGroupLSNLogProfileBinding `json:"lsngroup_lsnlogprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) CountLSNGroupLSNLogProfileBinding(groupname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lsnGroupLSNLogProfileBindingURL, groupname), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNGroupLSNLogProfileBinding `json:"lsngroup_lsnlogprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// lsngroup_lsnpool_binding +func (s *LSNService) AddLSNGroupLSNPoolBinding(resource models.LSNGroupLSNPoolBinding) error { + payload := map[string]any{"lsngroup_lsnpool_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lsnGroupLSNPoolBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) DeleteLSNGroupLSNPoolBinding(groupname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lsnGroupLSNPoolBindingURL, groupname, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) GetAllLSNGroupLSNPoolBinding() ([]models.LSNGroupLSNPoolBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnGroupLSNPoolBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNGroupLSNPoolBinding `json:"lsngroup_lsnpool_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNGroupLSNPoolBinding(groupname string) ([]models.LSNGroupLSNPoolBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnGroupLSNPoolBindingURL, groupname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNGroupLSNPoolBinding `json:"lsngroup_lsnpool_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) CountLSNGroupLSNPoolBinding(groupname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lsnGroupLSNPoolBindingURL, groupname), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNGroupLSNPoolBinding `json:"lsngroup_lsnpool_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// lsngroup_lsnrtspalgprofile_binding +func (s *LSNService) AddLSNGroupLSNRTSPALGProfileBinding(resource models.LSNGroupLSNRTSPALGProfileBinding) error { + payload := map[string]any{"lsngroup_lsnrtspalgprofile_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lsnGroupLSNRTSPALGProfileBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) DeleteLSNGroupLSNRTSPALGProfileBinding(groupname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lsnGroupLSNRTSPALGProfileBindingURL, groupname, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) GetAllLSNGroupLSNRTSPALGProfileBinding() ([]models.LSNGroupLSNRTSPALGProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnGroupLSNRTSPALGProfileBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNGroupLSNRTSPALGProfileBinding `json:"lsngroup_lsnrtspalgprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNGroupLSNRTSPALGProfileBinding(groupname string) ([]models.LSNGroupLSNRTSPALGProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnGroupLSNRTSPALGProfileBindingURL, groupname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNGroupLSNRTSPALGProfileBinding `json:"lsngroup_lsnrtspalgprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) CountLSNGroupLSNRTSPALGProfileBinding(groupname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lsnGroupLSNRTSPALGProfileBindingURL, groupname), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNGroupLSNRTSPALGProfileBinding `json:"lsngroup_lsnrtspalgprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// lsngroup_lsnsipalgprofile_binding +func (s *LSNService) AddLSNGroupLSNSIPALGProfileBinding(resource models.LSNGroupLSNSIPALGProfileBinding) error { + payload := map[string]any{"lsngroup_lsnsipalgprofile_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lsnGroupLSNSIPALGProfileBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) DeleteLSNGroupLSNSIPALGProfileBinding(groupname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lsnGroupLSNSIPALGProfileBindingURL, groupname, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) GetAllLSNGroupLSNSIPALGProfileBinding() ([]models.LSNGroupLSNSIPALGProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnGroupLSNSIPALGProfileBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNGroupLSNSIPALGProfileBinding `json:"lsngroup_lsnsipalgprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNGroupLSNSIPALGProfileBinding(groupname string) ([]models.LSNGroupLSNSIPALGProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnGroupLSNSIPALGProfileBindingURL, groupname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNGroupLSNSIPALGProfileBinding `json:"lsngroup_lsnsipalgprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) CountLSNGroupLSNSIPALGProfileBinding(groupname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lsnGroupLSNSIPALGProfileBindingURL, groupname), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNGroupLSNSIPALGProfileBinding `json:"lsngroup_lsnsipalgprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// lsngroup_lsntransportprofile_binding +func (s *LSNService) AddLSNGroupLSNTransportProfileBinding(resource models.LSNGroupLSNTransportProfileBinding) error { + payload := map[string]any{"lsngroup_lsntransportprofile_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lsnGroupLSNTransportProfileBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) DeleteLSNGroupLSNTransportProfileBinding(groupname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lsnGroupLSNTransportProfileBindingURL, groupname, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) GetAllLSNGroupLSNTransportProfileBinding() ([]models.LSNGroupLSNTransportProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnGroupLSNTransportProfileBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNGroupLSNTransportProfileBinding `json:"lsngroup_lsntransportprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNGroupLSNTransportProfileBinding(groupname string) ([]models.LSNGroupLSNTransportProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnGroupLSNTransportProfileBindingURL, groupname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNGroupLSNTransportProfileBinding `json:"lsngroup_lsntransportprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) CountLSNGroupLSNTransportProfileBinding(groupname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lsnGroupLSNTransportProfileBindingURL, groupname), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNGroupLSNTransportProfileBinding `json:"lsngroup_lsntransportprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// lsngroup_pcpserver_binding +func (s *LSNService) AddLSNGroupPCPServerBinding(resource models.LSNGroupPCPServerBinding) error { + payload := map[string]any{"lsngroup_pcpserver_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lsnGroupPCPServerBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) DeleteLSNGroupPCPServerBinding(groupname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lsnGroupPCPServerBindingURL, groupname, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) GetAllLSNGroupPCPServerBinding() ([]models.LSNGroupPCPServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnGroupPCPServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNGroupPCPServerBinding `json:"lsngroup_pcpserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNGroupPCPServerBinding(groupname string) ([]models.LSNGroupPCPServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnGroupPCPServerBindingURL, groupname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNGroupPCPServerBinding `json:"lsngroup_pcpserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) CountLSNGroupPCPServerBinding(groupname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lsnGroupPCPServerBindingURL, groupname), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNGroupPCPServerBinding `json:"lsngroup_pcpserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// lsnhttphdrlogprofile +func (s *LSNService) AddLSNHTTPHDRLogProfile(resource models.LSNHTTPHdrLogProfile) error { + payload := map[string]any{"lsnhttphdrlogprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lsnHTTPHDRLogProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) DeleteLSNHTTPHDRLogProfile(httphdrlogprofilename string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", lsnHTTPHDRLogProfileURL, httphdrlogprofilename), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) UpdateLSNHTTPHDRLogProfile(resource models.LSNHTTPHdrLogProfile) error { + payload := map[string]any{"lsnhttphdrlogprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, lsnHTTPHDRLogProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) UnsetLSNHTTPHDRLogProfile(resource models.LSNHTTPHdrLogProfile) error { + payload := map[string]any{"lsnhttphdrlogprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", lsnHTTPHDRLogProfileURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) GetAllLSNHTTPHDRLogProfile() ([]models.LSNHTTPHdrLogProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnHTTPHDRLogProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNHTTPHdrLogProfile `json:"lsnhttphdrlogprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNHTTPHDRLogProfile(httphdrlogprofilename string) (models.LSNHTTPHdrLogProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnHTTPHDRLogProfileURL, httphdrlogprofilename), nil) + if err != nil { + return models.LSNHTTPHdrLogProfile{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.LSNHTTPHdrLogProfile{}, err + } + + var result struct { + Data []models.LSNHTTPHdrLogProfile `json:"lsnhttphdrlogprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.LSNHTTPHdrLogProfile{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.LSNHTTPHdrLogProfile{}, fmt.Errorf("lsnhttphdrlogprofile %s not found", httphdrlogprofilename) + } + + return result.Data[0], nil +} + +func (s *LSNService) CountLSNHTTPHDRLogProfile() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lsnHTTPHDRLogProfileURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNHTTPHdrLogProfile `json:"lsnhttphdrlogprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// lsnip6profile +func (s *LSNService) AddLSNIP6Profile(resource models.LSNIP6Profile) error { + payload := map[string]any{"lsnip6profile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lsnIP6ProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) DeleteLSNIP6Profile(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", lsnIP6ProfileURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) GetAllLSNIP6Profile() ([]models.LSNIP6Profile, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnIP6ProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNIP6Profile `json:"lsnip6profile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNIP6Profile(name string) (models.LSNIP6Profile, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnIP6ProfileURL, name), nil) + if err != nil { + return models.LSNIP6Profile{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.LSNIP6Profile{}, err + } + + var result struct { + Data []models.LSNIP6Profile `json:"lsnip6profile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.LSNIP6Profile{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.LSNIP6Profile{}, fmt.Errorf("lsnip6profile %s not found", name) + } + + return result.Data[0], nil +} + +func (s *LSNService) CountLSNIP6Profile() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lsnIP6ProfileURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNIP6Profile `json:"lsnip6profile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// lsnlogprofile +func (s *LSNService) AddLSNLogProfile(resource models.LSNLogProfile) error { + payload := map[string]any{"lsnlogprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lsnLogProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) DeleteLSNLogProfile(logprofilename string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", lsnLogProfileURL, logprofilename), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) UpdateLSNLogProfile(resource models.LSNLogProfile) error { + payload := map[string]any{"lsnlogprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, lsnLogProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) UnsetLSNLogProfile(resource models.LSNLogProfile) error { + payload := map[string]any{"lsnlogprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", lsnLogProfileURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) GetAllLSNLogProfile() ([]models.LSNLogProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnLogProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNLogProfile `json:"lsnlogprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNLogProfile(logprofilename string) (models.LSNLogProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnLogProfileURL, logprofilename), nil) + if err != nil { + return models.LSNLogProfile{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.LSNLogProfile{}, err + } + + var result struct { + Data []models.LSNLogProfile `json:"lsnlogprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.LSNLogProfile{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.LSNLogProfile{}, fmt.Errorf("lsnlogprofile %s not found", logprofilename) + } + + return result.Data[0], nil +} + +func (s *LSNService) CountLSNLogProfile() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lsnLogProfileURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNLogProfile `json:"lsnlogprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// lsnparameter +func (s *LSNService) UpdateLSNParameter(resource models.LSNParameter) error { + payload := map[string]any{"lsnparameter": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, lsnParameterURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) UnsetLSNParameter(resource models.LSNParameter) error { + payload := map[string]any{"lsnparameter": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", lsnParameterURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) GetAllLSNParameter() (models.LSNParameter, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnParameterURL, nil) + if err != nil { + return models.LSNParameter{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.LSNParameter{}, err + } + + var result struct { + Data models.LSNParameter `json:"lsnparameter"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.LSNParameter{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// lsnpool +func (s *LSNService) AddLSNPool(resource models.LSNPool) error { + payload := map[string]any{"lsnpool": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lsnPoolURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) DeleteLSNPool(poolname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", lsnPoolURL, poolname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) UpdateLSNPool(resource models.LSNPool) error { + payload := map[string]any{"lsnpool": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, lsnPoolURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) UnsetLSNPool(resource models.LSNPool) error { + payload := map[string]any{"lsnpool": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", lsnPoolURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) GetAllLSNPool() ([]models.LSNPool, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnPoolURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNPool `json:"lsnpool"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNPool(poolname string) (models.LSNPool, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnPoolURL, poolname), nil) + if err != nil { + return models.LSNPool{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.LSNPool{}, err + } + + var result struct { + Data []models.LSNPool `json:"lsnpool"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.LSNPool{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.LSNPool{}, fmt.Errorf("lsnpool %s not found", poolname) + } + + return result.Data[0], nil +} + +func (s *LSNService) CountLSNPool() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lsnPoolURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNPool `json:"lsnpool"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// lsnpool_binding +func (s *LSNService) GetAllLSNPoolBinding() ([]models.LSNPoolBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnPoolBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNPoolBinding `json:"lsnpool_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNPoolBinding(poolname string) (models.LSNPoolBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnPoolBindingURL, poolname), nil) + if err != nil { + return models.LSNPoolBinding{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.LSNPoolBinding{}, err + } + + var result struct { + Data []models.LSNPoolBinding `json:"lsnpool_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.LSNPoolBinding{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.LSNPoolBinding{}, fmt.Errorf("lsnpool_binding %s not found", poolname) + } + + return result.Data[0], nil +} + +// lsnpool_lsnip_binding +func (s *LSNService) AddLSNPoolLSNIPBinding(resource models.LSNPoolLSNIPBinding) error { + payload := map[string]any{"lsnpool_lsnip_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lsnPoolLSNIPBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) DeleteLSNPoolLSNIPBinding(poolname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", lsnPoolLSNIPBindingURL, poolname, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) GetAllLSNPoolLSNIPBinding() ([]models.LSNPoolLSNIPBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnPoolLSNIPBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNPoolLSNIPBinding `json:"lsnpool_lsnip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNPoolLSNIPBinding(poolname string) ([]models.LSNPoolLSNIPBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnPoolLSNIPBindingURL, poolname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNPoolLSNIPBinding `json:"lsnpool_lsnip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) CountLSNPoolLSNIPBinding(poolname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lsnPoolLSNIPBindingURL, poolname), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNPoolLSNIPBinding `json:"lsnpool_lsnip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// lsnrtspalgprofile +func (s *LSNService) AddLSNRTSPALGProfile(resource models.LSNRTSPALGProfile) error { + payload := map[string]any{"lsnrtspalgprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lsnRTSPALGProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) DeleteLSNRTSPALGProfile(profilename string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", lsnRTSPALGProfileURL, profilename), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) UpdateLSNRTSPALGProfile(resource models.LSNRTSPALGProfile) error { + payload := map[string]any{"lsnrtspalgprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, lsnRTSPALGProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) UnsetLSNRTSPALGProfile(resource models.LSNRTSPALGProfile) error { + payload := map[string]any{"lsnrtspalgprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", lsnRTSPALGProfileURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) GetAllLSNRTSPALGProfile() ([]models.LSNRTSPALGProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnRTSPALGProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNRTSPALGProfile `json:"lsnrtspalgprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNRTSPALGProfile(profilename string) (models.LSNRTSPALGProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnRTSPALGProfileURL, profilename), nil) + if err != nil { + return models.LSNRTSPALGProfile{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.LSNRTSPALGProfile{}, err + } + + var result struct { + Data []models.LSNRTSPALGProfile `json:"lsnrtspalgprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.LSNRTSPALGProfile{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.LSNRTSPALGProfile{}, fmt.Errorf("lsnrtspalgprofile %s not found", profilename) + } + + return result.Data[0], nil +} + +func (s *LSNService) CountLSNRTSPALGProfile() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lsnRTSPALGProfileURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNRTSPALGProfile `json:"lsnrtspalgprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// lsnrtspalgsession +func (s *LSNService) GetAllLSNRTSPALGSession() ([]models.LSNRTSPALGSession, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnRTSPALGSessionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNRTSPALGSession `json:"lsnrtspalgsession"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNRTSPALGSession(sessionid string) (models.LSNRTSPALGSession, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnRTSPALGSessionURL, sessionid), nil) + if err != nil { + return models.LSNRTSPALGSession{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.LSNRTSPALGSession{}, err + } + + var result struct { + Data []models.LSNRTSPALGSession `json:"lsnrtspalgsession"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.LSNRTSPALGSession{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.LSNRTSPALGSession{}, fmt.Errorf("lsnrtspalgsession %s not found", sessionid) + } + + return result.Data[0], nil +} + +func (s *LSNService) CountLSNRTSPALGSession() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lsnRTSPALGSessionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNRTSPALGSession `json:"lsnrtspalgsession"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +func (s *LSNService) FlushLSNRTSPALGSession(resource models.LSNRTSPALGSession) error { + payload := map[string]any{"lsnrtspalgsession": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=flush", lsnRTSPALGSessionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// lsnrtspalgsession_binding +func (s *LSNService) GetAllLSNRTSPALGSessionBinding() ([]models.LSNRTSPALGSessionBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnRTSPALGSessionBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNRTSPALGSessionBinding `json:"lsnrtspalgsession_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNRTSPALGSessionBinding(sessionid string) (models.LSNRTSPALGSessionBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnRTSPALGSessionBindingURL, sessionid), nil) + if err != nil { + return models.LSNRTSPALGSessionBinding{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.LSNRTSPALGSessionBinding{}, err + } + + var result struct { + Data []models.LSNRTSPALGSessionBinding `json:"lsnrtspalgsession_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.LSNRTSPALGSessionBinding{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.LSNRTSPALGSessionBinding{}, fmt.Errorf("lsnrtspalgsession_binding %s not found", sessionid) + } + + return result.Data[0], nil +} + +// lsnrtspalgsession_datachannel_binding +func (s *LSNService) GetAllLSNRTSPALGSessionDataChannelBinding() ([]models.LSNRTSPALGSessionDataChannelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnRTSPALGSessionDataChannelBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNRTSPALGSessionDataChannelBinding `json:"lsnrtspalgsession_datachannel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNRTSPALGSessionDataChannelBinding(sessionid string) ([]models.LSNRTSPALGSessionDataChannelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnRTSPALGSessionDataChannelBindingURL, sessionid), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNRTSPALGSessionDataChannelBinding `json:"lsnrtspalgsession_datachannel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) CountLSNRTSPALGSessionDataChannelBinding(sessionid string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lsnRTSPALGSessionDataChannelBindingURL, sessionid), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNRTSPALGSessionDataChannelBinding `json:"lsnrtspalgsession_datachannel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// lsnsession +func (s *LSNService) GetAllLSNSession() ([]models.LSNSession, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnSessionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNSession `json:"lsnsession"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) CountLSNSession() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lsnSessionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNSession `json:"lsnsession"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +func (s *LSNService) FlushLSNSession(resource models.LSNSession) error { + payload := map[string]any{"lsnsession": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=flush", lsnSessionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// lsnsipalgcall +func (s *LSNService) GetAllLSNSIPALGCall() ([]models.LSNSIPALGCall, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnSIPALGCallURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNSIPALGCall `json:"lsnsipalgcall"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNSIPALGCall(callid string) (models.LSNSIPALGCall, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnSIPALGCallURL, callid), nil) + if err != nil { + return models.LSNSIPALGCall{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.LSNSIPALGCall{}, err + } + + var result struct { + Data []models.LSNSIPALGCall `json:"lsnsipalgcall"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.LSNSIPALGCall{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.LSNSIPALGCall{}, fmt.Errorf("lsnsipalgcall %s not found", callid) + } + + return result.Data[0], nil +} + +func (s *LSNService) CountLSNSIPALGCall() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lsnSIPALGCallURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNSIPALGCall `json:"lsnsipalgcall"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +func (s *LSNService) FlushLSNSIPALGCall(resource models.LSNSIPALGCall) error { + payload := map[string]any{"lsnsipalgcall": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=flush", lsnSIPALGCallURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// lsnsipalgcall_binding +func (s *LSNService) GetAllLSNSIPALGCallBinding() ([]models.LSNSIPALGCallBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnSIPALGCallBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNSIPALGCallBinding `json:"lsnsipalgcall_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNSIPALGCallBinding(callid string) (models.LSNSIPALGCallBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnSIPALGCallBindingURL, callid), nil) + if err != nil { + return models.LSNSIPALGCallBinding{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.LSNSIPALGCallBinding{}, err + } + + var result struct { + Data []models.LSNSIPALGCallBinding `json:"lsnsipalgcall_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.LSNSIPALGCallBinding{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.LSNSIPALGCallBinding{}, fmt.Errorf("lsnsipalgcall_binding %s not found", callid) + } + + return result.Data[0], nil +} + +// lsnsipalgcall_controlchannel_binding +func (s *LSNService) GetAllLSNSIPALGCallControlChannelBinding() ([]models.LSNSIPALGCallControlChannelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnSIPALGCallControlChannelBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNSIPALGCallControlChannelBinding `json:"lsnsipalgcall_controlchannel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNSIPALGCallControlChannelBinding(callid string) ([]models.LSNSIPALGCallControlChannelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnSIPALGCallControlChannelBindingURL, callid), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNSIPALGCallControlChannelBinding `json:"lsnsipalgcall_controlchannel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) CountLSNSIPALGCallControlChannelBinding(callid string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lsnSIPALGCallControlChannelBindingURL, callid), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNSIPALGCallControlChannelBinding `json:"lsnsipalgcall_controlchannel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// lsnsipalgcall_datachannel_binding +func (s *LSNService) GetAllLSNSIPALGCallDataChannelBinding() ([]models.LSNSIPALGCallDataChannelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnSIPALGCallDataChannelBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNSIPALGCallDataChannelBinding `json:"lsnsipalgcall_datachannel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNSIPALGCallDataChannelBinding(callid string) ([]models.LSNSIPALGCallDataChannelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnSIPALGCallDataChannelBindingURL, callid), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNSIPALGCallDataChannelBinding `json:"lsnsipalgcall_datachannel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) CountLSNSIPALGCallDataChannelBinding(callid string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", lsnSIPALGCallDataChannelBindingURL, callid), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNSIPALGCallDataChannelBinding `json:"lsnsipalgcall_datachannel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// lsnsipalgprofile +func (s *LSNService) AddLSNSIPALGProfile(resource models.LSNSIPALGProfile) error { + payload := map[string]any{"lsnsipalgprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lsnSIPALGProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) DeleteLSNSIPALGProfile(sipalgprofilename string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", lsnSIPALGProfileURL, sipalgprofilename), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) UpdateLSNSIPALGProfile(resource models.LSNSIPALGProfile) error { + payload := map[string]any{"lsnsipalgprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, lsnSIPALGProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) UnsetLSNSIPALGProfile(resource models.LSNSIPALGProfile) error { + payload := map[string]any{"lsnsipalgprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", lsnSIPALGProfileURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) GetAllLSNSIPALGProfile() ([]models.LSNSIPALGProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnSIPALGProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNSIPALGProfile `json:"lsnsipalgprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNSIPALGProfile(sipalgprofilename string) (models.LSNSIPALGProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnSIPALGProfileURL, sipalgprofilename), nil) + if err != nil { + return models.LSNSIPALGProfile{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.LSNSIPALGProfile{}, err + } + + var result struct { + Data []models.LSNSIPALGProfile `json:"lsnsipalgprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.LSNSIPALGProfile{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.LSNSIPALGProfile{}, fmt.Errorf("lsnsipalgprofile %s not found", sipalgprofilename) + } + + return result.Data[0], nil +} + +func (s *LSNService) CountLSNSIPALGProfile() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lsnSIPALGProfileURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNSIPALGProfile `json:"lsnsipalgprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// lsnstatic +func (s *LSNService) AddLSNStatic(resource models.LSNStatic) error { + payload := map[string]any{"lsnstatic": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lsnStaticURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) DeleteLSNStatic(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", lsnStaticURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) GetAllLSNStatic() ([]models.LSNStatic, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnStaticURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNStatic `json:"lsnstatic"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNStatic(name string) (models.LSNStatic, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnStaticURL, name), nil) + if err != nil { + return models.LSNStatic{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.LSNStatic{}, err + } + + var result struct { + Data []models.LSNStatic `json:"lsnstatic"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.LSNStatic{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.LSNStatic{}, fmt.Errorf("lsnstatic %s not found", name) + } + + return result.Data[0], nil +} + +func (s *LSNService) CountLSNStatic() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lsnStaticURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNStatic `json:"lsnstatic"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// lsntransportprofile +func (s *LSNService) AddLSNTransportProfile(resource models.LSNTransportProfile) error { + payload := map[string]any{"lsntransportprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, lsnTransportProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) DeleteLSNTransportProfile(transportprofilename string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", lsnTransportProfileURL, transportprofilename), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) UpdateLSNTransportProfile(resource models.LSNTransportProfile) error { + payload := map[string]any{"lsntransportprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, lsnTransportProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) UnsetLSNTransportProfile(resource models.LSNTransportProfile) error { + payload := map[string]any{"lsntransportprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", lsnTransportProfileURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *LSNService) GetAllLSNTransportProfile() ([]models.LSNTransportProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, lsnTransportProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LSNTransportProfile `json:"lsntransportprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *LSNService) GetLSNTransportProfile(transportprofilename string) (models.LSNTransportProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lsnTransportProfileURL, transportprofilename), nil) + if err != nil { + return models.LSNTransportProfile{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.LSNTransportProfile{}, err + } + + var result struct { + Data []models.LSNTransportProfile `json:"lsntransportprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.LSNTransportProfile{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return models.LSNTransportProfile{}, fmt.Errorf("lsntransportprofile %s not found", transportprofilename) + } + + return result.Data[0], nil +} + +func (s *LSNService) CountLSNTransportProfile() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lsnTransportProfileURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LSNTransportProfile `json:"lsntransportprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} diff --git a/nitrogo/models/aaa.go b/nitrogo/models/aaa.go new file mode 100644 index 0000000..acec119 --- /dev/null +++ b/nitrogo/models/aaa.go @@ -0,0 +1,528 @@ +package models + +// aaa configuration structs +type AAACertParams struct { + DefaultAuthenticationGroup string `json:"defaultauthenticationgroup,omitempty"` + GroupNameField string `json:"groupnamefield,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + TwoFactor string `json:"twofactor,omitempty"` + UsernameField string `json:"usernamefield,omitempty"` +} + +type AAAGlobalAAAPreAuthenticationPolicyBinding struct { + BindPolicyType int `json:"bindpolicytype,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AAAGlobalAuthenticationNegotiateActionBinding struct { + Count float64 `json:"__count,omitempty"` + WindowsProfile string `json:"windowsprofile,omitempty"` +} + +type AAAGlobalBinding struct { + AAAGlobalAAAPreAuthenticationPolicyBinding []any `json:"aaaglobal_aaapreauthenticationpolicy_binding,omitempty"` + AAAGlobalAuthenticationNegotiateActionBinding []any `json:"aaaglobal_authenticationnegotiateaction_binding,omitempty"` +} + +type AAAGroup struct { + Count float64 `json:"__count,omitempty"` + GroupName string `json:"groupname,omitempty"` + LoggedIn bool `json:"loggedin,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type AAAGroupAAAUserBinding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupName string `json:"groupname,omitempty"` + Username string `json:"username,omitempty"` +} + +type AAAGroupAuditNSLogPolicyBinding struct { + ActType int `json:"acttype,omitempty"` + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupName string `json:"groupname,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type AAAGroupAuditSyslogPolicyBinding struct { + ActType int `json:"acttype,omitempty"` + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupName string `json:"groupname,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type AAAGroupAuthorizationPolicyBinding struct { + ActType int `json:"acttype,omitempty"` + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupName string `json:"groupname,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type AAAGroupBinding struct { + AAAGroupAAAUserBinding []any `json:"aaagroup_aaauser_binding,omitempty"` + AAAGroupAuditNSLogPolicyBinding []any `json:"aaagroup_auditnslogpolicy_binding,omitempty"` + AAAGroupAuditSyslogPolicyBinding []any `json:"aaagroup_auditsyslogpolicy_binding,omitempty"` + AAAGroupAuthorizationPolicyBinding []any `json:"aaagroup_authorizationpolicy_binding,omitempty"` + AAAGroupIntranetIP6Binding []any `json:"aaagroup_intranetip6_binding,omitempty"` + AAAGroupIntranetIPBinding []any `json:"aaagroup_intranetip_binding,omitempty"` + AAAGroupTMSessionPolicyBinding []any `json:"aaagroup_tmsessionpolicy_binding,omitempty"` + AAAGroupVPNIntranetApplicationBinding []any `json:"aaagroup_vpnintranetapplication_binding,omitempty"` + AAAGroupVPNSecurePrivateAccessProfileBinding []any `json:"aaagroup_vpnsecureprivateaccessprofile_binding,omitempty"` + AAAGroupVPNSessionPolicyBinding []any `json:"aaagroup_vpnsessionpolicy_binding,omitempty"` + AAAGroupVPNTrafficPolicyBinding []any `json:"aaagroup_vpntrafficpolicy_binding,omitempty"` + AAAGroupVPNURLBinding []any `json:"aaagroup_vpnurl_binding,omitempty"` + AAAGroupVPNURLPolicyBinding []any `json:"aaagroup_vpnurlpolicy_binding,omitempty"` + GroupName string `json:"groupname,omitempty"` +} + +type AAAGroupIntranetIP6Binding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupName string `json:"groupname,omitempty"` + IntranetIP6 string `json:"intranetip6,omitempty"` + NumAddr int `json:"numaddr,omitempty"` +} + +type AAAGroupIntranetIPBinding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupName string `json:"groupname,omitempty"` + IntranetIP string `json:"intranetip,omitempty"` + Netmask string `json:"netmask,omitempty"` +} + +type AAAGroupTMSessionPolicyBinding struct { + ActType int `json:"acttype,omitempty"` + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupName string `json:"groupname,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type AAAGroupVPNIntranetApplicationBinding struct { + ActType int `json:"acttype,omitempty"` + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupName string `json:"groupname,omitempty"` + IntranetApplication string `json:"intranetapplication,omitempty"` +} + +type AAAGroupVPNSecurePrivateAccessProfileBinding struct { + ActType int `json:"acttype,omitempty"` + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupName string `json:"groupname,omitempty"` + SecurePrivateAccessProfile string `json:"secureprivateaccessprofile,omitempty"` +} + +type AAAGroupVPNSessionPolicyBinding struct { + ActType int `json:"acttype,omitempty"` + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupName string `json:"groupname,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type AAAGroupVPNTrafficPolicyBinding struct { + ActType int `json:"acttype,omitempty"` + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupName string `json:"groupname,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type AAAGroupVPNURLBinding struct { + ActType int `json:"acttype,omitempty"` + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupName string `json:"groupname,omitempty"` + URLName string `json:"urlname,omitempty"` +} + +type AAAGroupVPNURLPolicyBinding struct { + ActType int `json:"acttype,omitempty"` + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupName string `json:"groupname,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type AAAKCDAccount struct { + CACert string `json:"cacert,omitempty"` + Count float64 `json:"__count,omitempty"` + DelegatedUser string `json:"delegateduser,omitempty"` + EnterpriseRealm string `json:"enterpriserealm,omitempty"` + KCDAccount string `json:"kcdaccount,omitempty"` + KCDPassword string `json:"kcdpassword,omitempty"` + KCDSPN string `json:"kcdspn,omitempty"` + KeyTab string `json:"keytab,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Principle string `json:"principle,omitempty"` + RealmStr string `json:"realmstr,omitempty"` + SaltExpression string `json:"saltexpression,omitempty"` + ServiceSPN string `json:"servicespn,omitempty"` + UserCert string `json:"usercert,omitempty"` + UserRealm string `json:"userrealm,omitempty"` +} + +type AAALDAPParams struct { + AuthTimeout int `json:"authtimeout,omitempty"` + Builtin []string `json:"builtin,omitempty"` + DefaultAuthenticationGroup string `json:"defaultauthenticationgroup,omitempty"` + Feature string `json:"feature,omitempty"` + GroupAttrName string `json:"groupattrname,omitempty"` + GroupAuthName string `json:"groupauthname,omitempty"` + GroupNameIdentifier string `json:"groupnameidentifier,omitempty"` + GroupSearchAttribute string `json:"groupsearchattribute,omitempty"` + GroupSearchFilter string `json:"groupsearchfilter,omitempty"` + GroupSearchSubAttribute string `json:"groupsearchsubattribute,omitempty"` + LDAPBase string `json:"ldapbase,omitempty"` + LDAPBindDN string `json:"ldapbinddn,omitempty"` + LDAPBindDNPassword string `json:"ldapbinddnpassword,omitempty"` + LDAPLoginName string `json:"ldaploginname,omitempty"` + MaxNestingLevel int `json:"maxnestinglevel,omitempty"` + NestedGroupExtraction string `json:"nestedgroupextraction,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PasswdChange string `json:"passwdchange,omitempty"` + SearchFilter string `json:"searchfilter,omitempty"` + SecType string `json:"sectype,omitempty"` + ServerIP string `json:"serverip,omitempty"` + ServerPort int `json:"serverport,omitempty"` + SSONameAttribute string `json:"ssonameattribute,omitempty"` + SubAttributeName string `json:"subattributename,omitempty"` + SvrType string `json:"svrtype,omitempty"` +} + +type AAAOTPParameter struct { + Encryption string `json:"encryption,omitempty"` + MaxOTPDevices int `json:"maxotpdevices,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type AAAParameter struct { + AAADLogLevel string `json:"aaadloglevel,omitempty"` + AAADNATIP string `json:"aaadnatip,omitempty"` + AAASessionLogLevel string `json:"aaasessionloglevel,omitempty"` + APITokenCache string `json:"apitokencache,omitempty"` + Builtin []string `json:"builtin,omitempty"` + ClassicEndpoints string `json:"classicendpoints,omitempty"` + DefaultAuthType string `json:"defaultauthtype,omitempty"` + DefaultCSPHeader string `json:"defaultcspheader,omitempty"` + DynAddr string `json:"dynaddr,omitempty"` + EnableEnhancedAuthFeedback string `json:"enableenhancedauthfeedback,omitempty"` + EnableSessionStickiness string `json:"enablesessionstickiness,omitempty"` + EnableStaticPageCaching string `json:"enablestaticpagecaching,omitempty"` + EnhancedEPA string `json:"enhancedepa,omitempty"` + FailedLoginTimeout int `json:"failedlogintimeout,omitempty"` + Feature string `json:"feature,omitempty"` + FTMode string `json:"ftmode,omitempty"` + HTTPOnlyCookie string `json:"httponlycookie,omitempty"` + LoginEncryption string `json:"loginencryption,omitempty"` + MaxAAAUsers int `json:"maxaaausers,omitempty"` + MaxKBQuestions int `json:"maxkbquestions,omitempty"` + MaxLoginAttempts int `json:"maxloginattempts,omitempty"` + MaxSAMLDeflateSize int `json:"maxsamldeflatesize,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PersistentLoginAttempts string `json:"persistentloginattempts,omitempty"` + PwdExpiryNotificationDays int `json:"pwdexpirynotificationdays,omitempty"` + SameSite string `json:"samesite,omitempty"` + SecurityInsights string `json:"securityinsights,omitempty"` + TokenIntrospectionInterval int `json:"tokenintrospectioninterval,omitempty"` + WAFProtection []string `json:"wafprotection,omitempty"` + WebViewEndpoints string `json:"webviewendpoints,omitempty"` +} + +type AAAPreAuthenticationAction struct { + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + DefaultEPAGroup string `json:"defaultepagroup,omitempty"` + DeleteFiles string `json:"deletefiles,omitempty"` + Feature string `json:"feature,omitempty"` + KillProcess string `json:"killprocess,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PreAuthenticationAction string `json:"preauthenticationaction,omitempty"` +} + +type AAAPreAuthenticationParameter struct { + Builtin []string `json:"builtin,omitempty"` + DeleteFiles string `json:"deletefiles,omitempty"` + Feature string `json:"feature,omitempty"` + KillProcess string `json:"killprocess,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PreAuthenticationAction string `json:"preauthenticationaction,omitempty"` + Rule string `json:"rule,omitempty"` +} + +type AAAPreAuthenticationPolicy struct { + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ReqAction string `json:"reqaction,omitempty"` + Rule string `json:"rule,omitempty"` +} + +type AAAPreAuthenticationPolicyAAAGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AAAPreAuthenticationPolicyBinding struct { + AAAPreAuthenticationPolicyAAAGlobalBinding []any `json:"aaapreauthenticationpolicy_aaaglobal_binding,omitempty"` + AAAPreAuthenticationPolicyVPNVServerBinding []any `json:"aaapreauthenticationpolicy_vpnvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type AAAPreAuthenticationPolicyVPNVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AAARADIUSParams struct { + Accounting string `json:"accounting,omitempty"` + Authentication string `json:"authentication,omitempty"` + AuthServRetry int `json:"authservretry,omitempty"` + AuthTimeout int `json:"authtimeout,omitempty"` + Builtin []string `json:"builtin,omitempty"` + CallingStationID string `json:"callingstationid,omitempty"` + DefaultAuthenticationGroup string `json:"defaultauthenticationgroup,omitempty"` + Feature string `json:"feature,omitempty"` + GroupAuthName string `json:"groupauthname,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + IPAttributeType int `json:"ipattributetype,omitempty"` + IPVendorID int `json:"ipvendorid,omitempty"` + MessageAuthenticator string `json:"messageauthenticator,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PassEncoding string `json:"passencoding,omitempty"` + PwdAttributeType int `json:"pwdattributetype,omitempty"` + PwdVendorID int `json:"pwdvendorid,omitempty"` + RadAttributeType int `json:"radattributetype,omitempty"` + RadGroupSeparator string `json:"radgroupseparator,omitempty"` + RadGroupsPrefix string `json:"radgroupsprefix,omitempty"` + RadKey string `json:"radkey,omitempty"` + RadNASID string `json:"radnasid,omitempty"` + RadNASIP string `json:"radnasip,omitempty"` + RadVendorID int `json:"radvendorid,omitempty"` + ServerIP string `json:"serverip,omitempty"` + ServerPort int `json:"serverport,omitempty"` + TunnelEndpointClientIP string `json:"tunnelendpointclientip,omitempty"` +} + +type AAASession struct { + All bool `json:"all,omitempty"` + Count float64 `json:"__count,omitempty"` + DestIP string `json:"destip,omitempty"` + DestPort int `json:"destport,omitempty"` + GroupName string `json:"groupname,omitempty"` + IIP string `json:"iip,omitempty"` + IntranetIP string `json:"intranetip,omitempty"` + IntranetIP6 string `json:"intranetip6,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + Netmask string `json:"netmask,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + PEID int `json:"peid,omitempty"` + Port int `json:"port,omitempty"` + PrivateIP string `json:"privateip,omitempty"` + PrivatePort int `json:"privateport,omitempty"` + PublicIP string `json:"publicip,omitempty"` + PublicPort int `json:"publicport,omitempty"` + SessionKey string `json:"sessionkey,omitempty"` + Username string `json:"username,omitempty"` +} + +type AAASSOProfile struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Password string `json:"password,omitempty"` + Username string `json:"username,omitempty"` +} + +type AAATACACSParams struct { + Accounting string `json:"accounting,omitempty"` + AuditFailedCmds string `json:"auditfailedcmds,omitempty"` + Authorization string `json:"authorization,omitempty"` + AuthTimeout int `json:"authtimeout,omitempty"` + Builtin []string `json:"builtin,omitempty"` + DefaultAuthenticationGroup string `json:"defaultauthenticationgroup,omitempty"` + Feature string `json:"feature,omitempty"` + GroupAttrName string `json:"groupattrname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ServerIP string `json:"serverip,omitempty"` + ServerPort int `json:"serverport,omitempty"` + TACACSSecret string `json:"tacacssecret,omitempty"` +} + +type AAAUser struct { + Count float64 `json:"__count,omitempty"` + LoggedIn bool `json:"loggedin,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Password string `json:"password,omitempty"` + Username string `json:"username,omitempty"` +} + +type AAAUserAAAGroupBinding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupName string `json:"groupname,omitempty"` + Username string `json:"username,omitempty"` +} + +type AAAUserAuditNSLogPolicyBinding struct { + ActType int `json:"acttype,omitempty"` + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` + Username string `json:"username,omitempty"` +} + +type AAAUserAuditSyslogPolicyBinding struct { + ActType int `json:"acttype,omitempty"` + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` + Username string `json:"username,omitempty"` +} + +type AAAUserAuthorizationPolicyBinding struct { + ActType int `json:"acttype,omitempty"` + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` + Username string `json:"username,omitempty"` +} + +type AAAUserBinding struct { + AAAUserAAAGroupBinding []any `json:"aaauser_aaagroup_binding,omitempty"` + AAAUserAuditNSLogPolicyBinding []any `json:"aaauser_auditnslogpolicy_binding,omitempty"` + AAAUserAuditSyslogPolicyBinding []any `json:"aaauser_auditsyslogpolicy_binding,omitempty"` + AAAUserAuthorizationPolicyBinding []any `json:"aaauser_authorizationpolicy_binding,omitempty"` + AAAUserIntranetIP6Binding []any `json:"aaauser_intranetip6_binding,omitempty"` + AAAUserIntranetIPBinding []any `json:"aaauser_intranetip_binding,omitempty"` + AAAUserTMSessionPolicyBinding []any `json:"aaauser_tmsessionpolicy_binding,omitempty"` + AAAUserVPNIntranetApplicationBinding []any `json:"aaauser_vpnintranetapplication_binding,omitempty"` + AAAUserVPNSecurePrivateAccessProfileBinding []any `json:"aaauser_vpnsecureprivateaccessprofile_binding,omitempty"` + AAAUserVPNSessionPolicyBinding []any `json:"aaauser_vpnsessionpolicy_binding,omitempty"` + AAAUserVPNTrafficPolicyBinding []any `json:"aaauser_vpntrafficpolicy_binding,omitempty"` + AAAUserVPNURLBinding []any `json:"aaauser_vpnurl_binding,omitempty"` + AAAUserVPNURLPolicyBinding []any `json:"aaauser_vpnurlpolicy_binding,omitempty"` + Username string `json:"username,omitempty"` +} + +type AAAUserIntranetIP6Binding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + IntranetIP6 string `json:"intranetip6,omitempty"` + NumAddr int `json:"numaddr,omitempty"` + Username string `json:"username,omitempty"` +} + +type AAAUserIntranetIPBinding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + IntranetIP string `json:"intranetip,omitempty"` + Netmask string `json:"netmask,omitempty"` + Username string `json:"username,omitempty"` +} + +type AAAUserTMSessionPolicyBinding struct { + ActType int `json:"acttype,omitempty"` + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` + Username string `json:"username,omitempty"` +} + +type AAAUserVPNIntranetApplicationBinding struct { + ActType int `json:"acttype,omitempty"` + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + IntranetApplication string `json:"intranetapplication,omitempty"` + Username string `json:"username,omitempty"` +} + +type AAAUserVPNSecurePrivateAccessProfileBinding struct { + ActType int `json:"acttype,omitempty"` + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + SecurePrivateAccessProfile string `json:"secureprivateaccessprofile,omitempty"` + Username string `json:"username,omitempty"` +} + +type AAAUserVPNSessionPolicyBinding struct { + ActType int `json:"acttype,omitempty"` + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` + Username string `json:"username,omitempty"` +} + +type AAAUserVPNTrafficPolicyBinding struct { + ActType int `json:"acttype,omitempty"` + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` + Username string `json:"username,omitempty"` +} + +type AAAUserVPNURLBinding struct { + ActType int `json:"acttype,omitempty"` + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + URLName string `json:"urlname,omitempty"` + Username string `json:"username,omitempty"` +} + +type AAAUserVPNURLPolicyBinding struct { + ActType int `json:"acttype,omitempty"` + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` + Username string `json:"username,omitempty"` +} diff --git a/nitrogo/models/adm.go b/nitrogo/models/adm.go new file mode 100644 index 0000000..111afd2 --- /dev/null +++ b/nitrogo/models/adm.go @@ -0,0 +1,8 @@ +package models + +// adm configuration structs +type ADMParameter struct { + ADMServiceConnect string `json:"admserviceconnect,omitempty"` + LowTouchOnBoard string `json:"lowtouchonboard,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} diff --git a/nitrogo/models/analytics.go b/nitrogo/models/analytics.go new file mode 100644 index 0000000..0d0458a --- /dev/null +++ b/nitrogo/models/analytics.go @@ -0,0 +1,57 @@ +package models + +// analytics configuration structs +type AnalyticsGlobalAnalyticsProfileBinding struct { + AnalyticsProfile string `json:"analyticsprofile,omitempty"` +} + +type AnalyticsGlobalBinding struct { + AnalyticsGlobalAnalyticsProfileBinding []any `json:"analyticsglobal_analyticsprofile_binding,omitempty"` +} + +type AnalyticsProfile struct { + AllHTTPHeaders string `json:"allhttpheaders,omitempty"` + AnalyticsAuthToken string `json:"analyticsauthtoken,omitempty"` + AnalyticsEndpointContentType string `json:"analyticsendpointcontenttype,omitempty"` + AnalyticsEndpointMetadata string `json:"analyticsendpointmetadata,omitempty"` + AnalyticsEndpointURL string `json:"analyticsendpointurl,omitempty"` + AuditLogs string `json:"auditlogs,omitempty"` + Collectors string `json:"collectors,omitempty"` + Count float64 `json:"__count,omitempty"` + CQAReporting string `json:"cqareporting,omitempty"` + DataFormatFile string `json:"dataformatfile,omitempty"` + Events string `json:"events,omitempty"` + GRPCStatus string `json:"grpcstatus,omitempty"` + HTTPAuthentication string `json:"httpauthentication,omitempty"` + HTTPClientSideMeasurements string `json:"httpclientsidemeasurements,omitempty"` + HTTPContentType string `json:"httpcontenttype,omitempty"` + HTTPCookie string `json:"httpcookie,omitempty"` + HTTPCustomHeaders []string `json:"httpcustomheaders,omitempty"` + HTTPDomainName string `json:"httpdomainname,omitempty"` + HTTPHost string `json:"httphost,omitempty"` + HTTPLocation string `json:"httplocation,omitempty"` + HTTPMethod string `json:"httpmethod,omitempty"` + HTTPPageTracking string `json:"httppagetracking,omitempty"` + HTTPReferer string `json:"httpreferer,omitempty"` + HTTPSetCookie string `json:"httpsetcookie,omitempty"` + HTTPSetCookie2 string `json:"httpsetcookie2,omitempty"` + HTTPURL string `json:"httpurl,omitempty"` + HTTPURLQuery string `json:"httpurlquery,omitempty"` + HTTPUserAgent string `json:"httpuseragent,omitempty"` + HTTPVia string `json:"httpvia,omitempty"` + HTTPXForwardedForHeader string `json:"httpxforwardedforheader,omitempty"` + IntegratedCache string `json:"integratedcache,omitempty"` + ManagementLog []string `json:"managementlog,omitempty"` + Metrics string `json:"metrics,omitempty"` + MetricsExportFrequency int `json:"metricsexportfrequency,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OutputMode string `json:"outputmode,omitempty"` + RefCnt int `json:"refcnt,omitempty"` + SchemaFile string `json:"schemafile,omitempty"` + ServeMode string `json:"servemode,omitempty"` + TCPBurstReporting string `json:"tcpburstreporting,omitempty"` + TopN string `json:"topn,omitempty"` + TypeField string `json:"type,omitempty"` + URLCategory string `json:"urlcategory,omitempty"` +} diff --git a/nitrogo/models/api.go b/nitrogo/models/api.go new file mode 100644 index 0000000..e714aff --- /dev/null +++ b/nitrogo/models/api.go @@ -0,0 +1,53 @@ +package models + +// api configuration structs +type APISpecFile struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Overwrite bool `json:"overwrite,omitempty"` + Src string `json:"src,omitempty"` +} + +type APIProfileAPISpecBinding struct { + APISpec string `json:"apispec,omitempty"` + Name string `json:"name,omitempty"` +} + +type APISpec struct { + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + Encrypted bool `json:"encrypted,omitempty"` + File string `json:"file,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NSAppVersion string `json:"nsappversion,omitempty"` + Ready string `json:"ready,omitempty"` + SkipValidation string `json:"skipvalidation,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type APISpecSpecEndpointBinding struct { + APIName string `json:"apiname,omitempty"` + APIService string `json:"apiservice,omitempty"` + HTTPMethod string `json:"httpmethod,omitempty"` + HTTPURLPath string `json:"httpurlpath,omitempty"` + Name string `json:"name,omitempty"` +} + +type APIProfile struct { + APIVisibility string `json:"apivisibility,omitempty"` + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type APIProfileBinding struct { + APIProfileAPISpecBinding []any `json:"apiprofile_apispec_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type APISpecBinding struct { + APISpecSpecEndpointBinding []any `json:"apispec_specendpoint_binding,omitempty"` + Name string `json:"name,omitempty"` +} diff --git a/nitrogo/models/app.go b/nitrogo/models/app.go new file mode 100644 index 0000000..a0ed202 --- /dev/null +++ b/nitrogo/models/app.go @@ -0,0 +1,8 @@ +package models + +// app configuration structs +type Application struct { + AppName string `json:"appname,omitempty"` + AppTemplateFileName string `json:"apptemplatefilename,omitempty"` + DeploymentFileName string `json:"deploymentfilename,omitempty"` +} diff --git a/nitrogo/models/appflow.go b/nitrogo/models/appflow.go new file mode 100644 index 0000000..5a82a59 --- /dev/null +++ b/nitrogo/models/appflow.go @@ -0,0 +1,229 @@ +package models + +// appflow configuration structs +type AppFlowParam struct { + AAAUsername string `json:"aaausername,omitempty"` + AnalyticsAuthToken string `json:"analyticsauthtoken,omitempty"` + AppNameRefresh int `json:"appnamerefresh,omitempty"` + AuditLogs string `json:"auditlogs,omitempty"` + Builtin []string `json:"builtin,omitempty"` + CacheInsight string `json:"cacheinsight,omitempty"` + ClientTrafficOnly string `json:"clienttrafficonly,omitempty"` + ConnectionChaining string `json:"connectionchaining,omitempty"` + CQAReporting string `json:"cqareporting,omitempty"` + DistributedTracing string `json:"distributedtracing,omitempty"` + DistTracingSamplingRate int `json:"disttracingsamplingrate,omitempty"` + EmailAddress string `json:"emailaddress,omitempty"` + Events string `json:"events,omitempty"` + Feature string `json:"feature,omitempty"` + FlowRecordInterval int `json:"flowrecordinterval,omitempty"` + GXSessionReporting string `json:"gxsessionreporting,omitempty"` + HTTPAuthorization string `json:"httpauthorization,omitempty"` + HTTPContentType string `json:"httpcontenttype,omitempty"` + HTTPCookie string `json:"httpcookie,omitempty"` + HTTPDomain string `json:"httpdomain,omitempty"` + HTTPHost string `json:"httphost,omitempty"` + HTTPLocation string `json:"httplocation,omitempty"` + HTTPMethod string `json:"httpmethod,omitempty"` + HTTPQueryWithURL string `json:"httpquerywithurl,omitempty"` + HTTPReferer string `json:"httpreferer,omitempty"` + HTTPSetCookie string `json:"httpsetcookie,omitempty"` + HTTPSetCookie2 string `json:"httpsetcookie2,omitempty"` + HTTPURL string `json:"httpurl,omitempty"` + HTTPUserAgent string `json:"httpuseragent,omitempty"` + HTTPVia string `json:"httpvia,omitempty"` + HTTPXForwardedFor string `json:"httpxforwardedfor,omitempty"` + IdentifierName string `json:"identifiername,omitempty"` + IdentifierSessionName string `json:"identifiersessionname,omitempty"` + LogStreamOverNSIP string `json:"logstreamovernsip,omitempty"` + LSNLogging string `json:"lsnlogging,omitempty"` + Metrics string `json:"metrics,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ObservationDomainID int `json:"observationdomainid,omitempty"` + ObservationDomainName string `json:"observationdomainname,omitempty"` + ObservationPointID int `json:"observationpointid,omitempty"` + SecurityInsightRecordInterval int `json:"securityinsightrecordinterval,omitempty"` + SecurityInsightTraffic string `json:"securityinsighttraffic,omitempty"` + SkipCacheRedirectionHTTPTransaction string `json:"skipcacheredirectionhttptransaction,omitempty"` + SubscriberAwareness string `json:"subscriberawareness,omitempty"` + SubscriberIDObfuscation string `json:"subscriberidobfuscation,omitempty"` + SubscriberIDObfuscationAlgo string `json:"subscriberidobfuscationalgo,omitempty"` + TCPAttackCounterInterval int `json:"tcpattackcounterinterval,omitempty"` + TCPBurstReporting string `json:"tcpburstreporting,omitempty"` + TCPBurstReportingThreshold int `json:"tcpburstreportingthreshold,omitempty"` + TemplateRefresh int `json:"templaterefresh,omitempty"` + TimeSeriesOverNSIP string `json:"timeseriesovernsip,omitempty"` + UDPPMTU int `json:"udppmtu,omitempty"` + URLCategory string `json:"urlcategory,omitempty"` + UsageRecordInterval int `json:"usagerecordinterval,omitempty"` + VideoInsight string `json:"videoinsight,omitempty"` + WebSaaSAppUsageReporting string `json:"websaasappusagereporting,omitempty"` +} + +type AppFlowGlobalBinding struct { + AppFlowGlobalAppFlowPolicyBinding []any `json:"appflowglobal_appflowpolicy_binding,omitempty"` +} + +type AppFlowPolicyAppFlowGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AppFlowPolicyLabel struct { + Count float64 `json:"__count,omitempty"` + Description string `json:"description,omitempty"` + FlowType int `json:"flowtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Hits int `json:"hits,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyLabelType string `json:"policylabeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AppFlowPolicyLabelBinding struct { + AppFlowPolicyLabelAppFlowPolicyBinding []any `json:"appflowpolicylabel_appflowpolicy_binding,omitempty"` + LabelName string `json:"labelname,omitempty"` +} + +type AppFlowPolicyVPNVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AppFlowGlobalAppFlowPolicyBinding struct { + FlowType int `json:"flowtype,omitempty"` + GlobalBindType string `json:"globalbindtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type AppFlowPolicyAppFlowPolicyLabelBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AppFlowActionBinding struct { + AppFlowActionAnalyticsProfileBinding []any `json:"appflowaction_analyticsprofile_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type AppFlowPolicyLabelAppFlowPolicyBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AppFlowPolicyBinding struct { + AppFlowPolicyAppFlowGlobalBinding []any `json:"appflowpolicy_appflowglobal_binding,omitempty"` + AppFlowPolicyAppFlowPolicyLabelBinding []any `json:"appflowpolicy_appflowpolicylabel_binding,omitempty"` + AppFlowPolicyCSVServerBinding []any `json:"appflowpolicy_csvserver_binding,omitempty"` + AppFlowPolicyLBVServerBinding []any `json:"appflowpolicy_lbvserver_binding,omitempty"` + AppFlowPolicyVPNVServerBinding []any `json:"appflowpolicy_vpnvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type AppFlowPolicyLBVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AppFlowAction struct { + BotInsight string `json:"botinsight,omitempty"` + CIInsight string `json:"ciinsight,omitempty"` + ClientSideMeasurements string `json:"clientsidemeasurements,omitempty"` + Collectors []string `json:"collectors,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Description string `json:"description,omitempty"` + DistributionAlgorithm string `json:"distributionalgorithm,omitempty"` + Hits int `json:"hits,omitempty"` + MetricsLog bool `json:"metricslog,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PageTracking string `json:"pagetracking,omitempty"` + ReferenceCount int `json:"referencecount,omitempty"` + SecurityInsight string `json:"securityinsight,omitempty"` + TransactionLog string `json:"transactionlog,omitempty"` + VideoAnalytics string `json:"videoanalytics,omitempty"` + WebInsight string `json:"webinsight,omitempty"` +} + +type AppFlowPolicy struct { + Action string `json:"action,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Description string `json:"description,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule string `json:"rule,omitempty"` + UndefAction string `json:"undefaction,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type AppFlowPolicyCSVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AppFlowCollector struct { + Count float64 `json:"__count,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + Name string `json:"name,omitempty"` + NetProfile string `json:"netprofile,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Port int `json:"port,omitempty"` + State string `json:"state,omitempty"` + Transport string `json:"transport,omitempty"` +} + +type AppFlowActionAnalyticsProfileBinding struct { + AnalyticsProfile string `json:"analyticsprofile,omitempty"` + Name string `json:"name,omitempty"` +} diff --git a/nitrogo/models/appfw.go b/nitrogo/models/appfw.go new file mode 100644 index 0000000..9341a18 --- /dev/null +++ b/nitrogo/models/appfw.go @@ -0,0 +1,1167 @@ +package models + +// appfw configuration structs +type AppFWXMLErrorPage struct { + Comment string `json:"comment,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Overwrite bool `json:"overwrite,omitempty"` + Response string `json:"response,omitempty"` + Src string `json:"src,omitempty"` +} + +type AppFWPolicyLBVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AppFWGRPCWebTextContentType struct { + Count float64 `json:"__count,omitempty"` + GRPCWebTextContentTypeValue string `json:"grpcwebtextcontenttypevalue,omitempty"` + IsRegex string `json:"isregex,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type AppFWGlobalAppFWPolicyBinding struct { + FlowType int `json:"flowtype,omitempty"` + GlobalBindType string `json:"globalbindtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyName string `json:"policyname,omitempty"` + PolicyType string `json:"policytype,omitempty"` + Priority int `json:"priority,omitempty"` + State string `json:"state,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type AppFWProfileCookieConsistencyBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + Comment string `json:"comment,omitempty"` + CookieConsistency string `json:"cookieconsistency,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + IsRegex string `json:"isregex,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` +} + +type AppFWProfileXMLDOSURLBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + Comment string `json:"comment,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` + XMLBlockDTD string `json:"xmlblockdtd,omitempty"` + XMLBlockExternalEntities string `json:"xmlblockexternalentities,omitempty"` + XMLBlockPI string `json:"xmlblockpi,omitempty"` + XMLDOSURL string `json:"xmldosurl,omitempty"` + XMLMaxAttributeNameLength int `json:"xmlmaxattributenamelength,omitempty"` + XMLMaxAttributeNameLengthCheck string `json:"xmlmaxattributenamelengthcheck,omitempty"` + XMLMaxAttributes int `json:"xmlmaxattributes,omitempty"` + XMLMaxAttributesCheck string `json:"xmlmaxattributescheck,omitempty"` + XMLMaxAttributeValueLength int `json:"xmlmaxattributevaluelength,omitempty"` + XMLMaxAttributeValueLengthCheck string `json:"xmlmaxattributevaluelengthcheck,omitempty"` + XMLMaxCharDataLength int `json:"xmlmaxchardatalength,omitempty"` + XMLMaxCharDataLengthCheck string `json:"xmlmaxchardatalengthcheck,omitempty"` + XMLMaxElementChildren int `json:"xmlmaxelementchildren,omitempty"` + XMLMaxElementChildrenCheck string `json:"xmlmaxelementchildrencheck,omitempty"` + XMLMaxElementDepth int `json:"xmlmaxelementdepth,omitempty"` + XMLMaxElementDepthCheck string `json:"xmlmaxelementdepthcheck,omitempty"` + XMLMaxElementNameLength int `json:"xmlmaxelementnamelength,omitempty"` + XMLMaxElementNameLengthCheck string `json:"xmlmaxelementnamelengthcheck,omitempty"` + XMLMaxElements int `json:"xmlmaxelements,omitempty"` + XMLMaxElementsCheck string `json:"xmlmaxelementscheck,omitempty"` + XMLMaxEntityExpansionDepth int `json:"xmlmaxentityexpansiondepth,omitempty"` + XMLMaxEntityExpansionDepthCheck string `json:"xmlmaxentityexpansiondepthcheck,omitempty"` + XMLMaxEntityExpansions int `json:"xmlmaxentityexpansions,omitempty"` + XMLMaxEntityExpansionsCheck string `json:"xmlmaxentityexpansionscheck,omitempty"` + XMLMaxFileSize int `json:"xmlmaxfilesize,omitempty"` + XMLMaxFileSizeCheck string `json:"xmlmaxfilesizecheck,omitempty"` + XMLMaxNamespaces int `json:"xmlmaxnamespaces,omitempty"` + XMLMaxNamespacesCheck string `json:"xmlmaxnamespacescheck,omitempty"` + XMLMaxNamespaceURILength int `json:"xmlmaxnamespaceurilength,omitempty"` + XMLMaxNamespaceURILengthCheck string `json:"xmlmaxnamespaceurilengthcheck,omitempty"` + XMLMaxNodes int `json:"xmlmaxnodes,omitempty"` + XMLMaxNodesCheck string `json:"xmlmaxnodescheck,omitempty"` + XMLMaxSOAPArrayRank int `json:"xmlmaxsoaparrayrank,omitempty"` + XMLMaxSOAPArraySize int `json:"xmlmaxsoaparraysize,omitempty"` + XMLMinFileSize int `json:"xmlminfilesize,omitempty"` + XMLMinFileSizeCheck string `json:"xmlminfilesizecheck,omitempty"` + XMLSOAPArrayCheck string `json:"xmlsoaparraycheck,omitempty"` +} + +type AppFWProfileDenyURLBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + Comment string `json:"comment,omitempty"` + DenyURL string `json:"denyurl,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` +} + +type AppFWSignatures struct { + Action []string `json:"action,omitempty"` + AutoEnableNewSignatures string `json:"autoenablenewsignatures,omitempty"` + Category string `json:"category,omitempty"` + Comment string `json:"comment,omitempty"` + Enabled string `json:"enabled,omitempty"` + EncryptedVersion int `json:"encryptedversion,omitempty"` + Merge bool `json:"merge,omitempty"` + MergeDefault bool `json:"mergedefault,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Overwrite bool `json:"overwrite,omitempty"` + PreserveDefActions bool `json:"preservedefactions,omitempty"` + Response string `json:"response,omitempty"` + RuleID []any `json:"ruleid,omitempty"` + SHA1 string `json:"sha1,omitempty"` + Src string `json:"src,omitempty"` + VendorType string `json:"vendortype,omitempty"` + XSLT string `json:"xslt,omitempty"` +} + +type AppFWProfileFieldFormatBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + Comment string `json:"comment,omitempty"` + FieldFormat string `json:"fieldformat,omitempty"` + FieldFormatMaxLength int `json:"fieldformatmaxlength,omitempty"` + FieldFormatMinLength int `json:"fieldformatminlength,omitempty"` + FieldType string `json:"fieldtype,omitempty"` + FormActionURLFF string `json:"formactionurl_ff,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + IsRegexFF string `json:"isregex_ff,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` +} + +type AppFWProfileLogExpressionBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + ASLogExpression string `json:"as_logexpression,omitempty"` + Comment string `json:"comment,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + LogExpression string `json:"logexpression,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` +} + +type AppFWJSONErrorPage struct { + Comment string `json:"comment,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Overwrite bool `json:"overwrite,omitempty"` + Response string `json:"response,omitempty"` + Src string `json:"src,omitempty"` +} + +type AppFWProfileJSONDOSURLBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + Comment string `json:"comment,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + JSONDOSURL string `json:"jsondosurl,omitempty"` + JSONMaxArrayLength int `json:"jsonmaxarraylength,omitempty"` + JSONMaxArrayLengthCheck string `json:"jsonmaxarraylengthcheck,omitempty"` + JSONMaxContainerDepth int `json:"jsonmaxcontainerdepth,omitempty"` + JSONMaxContainerDepthCheck string `json:"jsonmaxcontainerdepthcheck,omitempty"` + JSONMaxDocumentLength int `json:"jsonmaxdocumentlength,omitempty"` + JSONMaxDocumentLengthCheck string `json:"jsonmaxdocumentlengthcheck,omitempty"` + JSONMaxObjectKeyCount int `json:"jsonmaxobjectkeycount,omitempty"` + JSONMaxObjectKeyCountCheck string `json:"jsonmaxobjectkeycountcheck,omitempty"` + JSONMaxObjectKeyLength int `json:"jsonmaxobjectkeylength,omitempty"` + JSONMaxObjectKeyLengthCheck string `json:"jsonmaxobjectkeylengthcheck,omitempty"` + JSONMaxStringLength int `json:"jsonmaxstringlength,omitempty"` + JSONMaxStringLengthCheck string `json:"jsonmaxstringlengthcheck,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` +} + +type AppFWPolicy struct { + Builtin []string `json:"builtin,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + LogAction string `json:"logaction,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PolicyType string `json:"policytype,omitempty"` + ProfileName string `json:"profilename,omitempty"` + Rule string `json:"rule,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type AppFWProfileFakeAccountBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + Comment string `json:"comment,omitempty"` + FakeAccount string `json:"fakeaccount,omitempty"` + FormExpression string `json:"formexpression,omitempty"` + FormURLFAD string `json:"formurl_fad,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + IsFieldNameRegex string `json:"isfieldnameregex,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` + Tag string `json:"tag,omitempty"` +} + +type AppFWProfileJSONCMDURLBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + ASValueExprJSONCMD string `json:"as_value_expr_json_cmd,omitempty"` + ASValueTypeJSONCMD string `json:"as_value_type_json_cmd,omitempty"` + Comment string `json:"comment,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + IsKeyRegexJSONCMD string `json:"iskeyregex_json_cmd,omitempty"` + IsValueRegexJSONCMD string `json:"isvalueregex_json_cmd,omitempty"` + JSONCMDURL string `json:"jsoncmdurl,omitempty"` + KeyNameJSONCMD string `json:"keyname_json_cmd,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` +} + +type AppFWConfidField struct { + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + FieldName string `json:"fieldname,omitempty"` + IsRegex string `json:"isregex,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + State string `json:"state,omitempty"` + URL string `json:"url,omitempty"` +} + +type AppFWGlobalAuditNSLogPolicyBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + PolicyType string `json:"policytype,omitempty"` + Priority int `json:"priority,omitempty"` + State string `json:"state,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type AppFWProfileXMLValidationURLBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + Comment string `json:"comment,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` + XMLAdditionalSOAPHeaders string `json:"xmladditionalsoapheaders,omitempty"` + XMLEndpointCheck string `json:"xmlendpointcheck,omitempty"` + XMLRequestSchema string `json:"xmlrequestschema,omitempty"` + XMLResponseSchema string `json:"xmlresponseschema,omitempty"` + XMLValidateResponse string `json:"xmlvalidateresponse,omitempty"` + XMLValidateSOAPEnvelope string `json:"xmlvalidatesoapenvelope,omitempty"` + XMLValidationURL string `json:"xmlvalidationurl,omitempty"` + XMLWSDL string `json:"xmlwsdl,omitempty"` +} + +type AppFWProfileAppFWConfidFieldBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + CFFieldURL string `json:"cffield_url,omitempty"` + Comment string `json:"comment,omitempty"` + ConfidField string `json:"confidfield,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + IsRegexCFField string `json:"isregex_cffield,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` +} + +type AppFWProfileCrossSiteScriptingBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + ASScanLocationXSS string `json:"as_scan_location_xss,omitempty"` + ASValueExprXSS string `json:"as_value_expr_xss,omitempty"` + ASValueTypeXSS string `json:"as_value_type_xss,omitempty"` + Comment string `json:"comment,omitempty"` + CrossSiteScripting string `json:"crosssitescripting,omitempty"` + FormActionURLXSS string `json:"formactionurl_xss,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + IsRegexXSS string `json:"isregex_xss,omitempty"` + IsValueRegexXSS string `json:"isvalueregex_xss,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` +} + +type AppFWTransactionRecords struct { + AppFWSessionID string `json:"appfwsessionid,omitempty"` + ClientIP string `json:"clientip,omitempty"` + Count float64 `json:"__count,omitempty"` + DestIP string `json:"destip,omitempty"` + EndTime string `json:"endtime,omitempty"` + HTTPTransactionID int `json:"httptransactionid,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + PacketEngineID int `json:"packetengineid,omitempty"` + ProfileName string `json:"profilename,omitempty"` + RequestContentLength int `json:"requestcontentlength,omitempty"` + RequestMaxProcessingTime int `json:"requestmaxprocessingtime,omitempty"` + RequestYields int `json:"requestyields,omitempty"` + ResponseContentLength int `json:"responsecontentlength,omitempty"` + ResponseMaxProcessingTime int `json:"responsemaxprocessingtime,omitempty"` + ResponseYields int `json:"responseyields,omitempty"` + StartTime string `json:"starttime,omitempty"` + URL string `json:"url,omitempty"` +} + +type AppFWProfileBinding struct { + AppFWProfileAppFWConfidFieldBinding []any `json:"appfwprofile_appfwconfidfield_binding,omitempty"` + AppFWProfileBlockKeywordBinding []any `json:"appfwprofile_blockkeyword_binding,omitempty"` + AppFWProfileBypassListBinding []any `json:"appfwprofile_bypasslist_binding,omitempty"` + AppFWProfileCMDInjectionBinding []any `json:"appfwprofile_cmdinjection_binding,omitempty"` + AppFWProfileContentTypeBinding []any `json:"appfwprofile_contenttype_binding,omitempty"` + AppFWProfileCookieConsistencyBinding []any `json:"appfwprofile_cookieconsistency_binding,omitempty"` + AppFWProfileCreditCardNumberBinding []any `json:"appfwprofile_creditcardnumber_binding,omitempty"` + AppFWProfileCrossSiteScriptingBinding []any `json:"appfwprofile_crosssitescripting_binding,omitempty"` + AppFWProfileCSRFTagBinding []any `json:"appfwprofile_csrftag_binding,omitempty"` + AppFWProfileDenyListBinding []any `json:"appfwprofile_denylist_binding,omitempty"` + AppFWProfileDenyURLBinding []any `json:"appfwprofile_denyurl_binding,omitempty"` + AppFWProfileExcludeRESContentTypeBinding []any `json:"appfwprofile_excluderescontenttype_binding,omitempty"` + AppFWProfileFakeAccountBinding []any `json:"appfwprofile_fakeaccount_binding,omitempty"` + AppFWProfileFieldConsistencyBinding []any `json:"appfwprofile_fieldconsistency_binding,omitempty"` + AppFWProfileFieldFormatBinding []any `json:"appfwprofile_fieldformat_binding,omitempty"` + AppFWProfileFileUploadTypeBinding []any `json:"appfwprofile_fileuploadtype_binding,omitempty"` + AppFWProfileGRPCValidationBinding []any `json:"appfwprofile_grpcvalidation_binding,omitempty"` + AppFWProfileJSONBlockKeywordBinding []any `json:"appfwprofile_jsonblockkeyword_binding,omitempty"` + AppFWProfileJSONCMDURLBinding []any `json:"appfwprofile_jsoncmdurl_binding,omitempty"` + AppFWProfileJSONDOSURLBinding []any `json:"appfwprofile_jsondosurl_binding,omitempty"` + AppFWProfileJSONSQLURLBinding []any `json:"appfwprofile_jsonsqlurl_binding,omitempty"` + AppFWProfileJSONXSSURLBinding []any `json:"appfwprofile_jsonxssurl_binding,omitempty"` + AppFWProfileLogExpressionBinding []any `json:"appfwprofile_logexpression_binding,omitempty"` + AppFWProfileRESTValidationBinding []any `json:"appfwprofile_restvalidation_binding,omitempty"` + AppFWProfileSafeObjectBinding []any `json:"appfwprofile_safeobject_binding,omitempty"` + AppFWProfileSQLInjectionBinding []any `json:"appfwprofile_sqlinjection_binding,omitempty"` + AppFWProfileStartURLBinding []any `json:"appfwprofile_starturl_binding,omitempty"` + AppFWProfileTrustedLearningClientsBinding []any `json:"appfwprofile_trustedlearningclients_binding,omitempty"` + AppFWProfileXMLAttachmentURLBinding []any `json:"appfwprofile_xmlattachmenturl_binding,omitempty"` + AppFWProfileXMLDOSURLBinding []any `json:"appfwprofile_xmldosurl_binding,omitempty"` + AppFWProfileXMLSQLInjectionBinding []any `json:"appfwprofile_xmlsqlinjection_binding,omitempty"` + AppFWProfileXMLValidationURLBinding []any `json:"appfwprofile_xmlvalidationurl_binding,omitempty"` + AppFWProfileXMLWSIURLBinding []any `json:"appfwprofile_xmlwsiurl_binding,omitempty"` + AppFWProfileXMLXSSBinding []any `json:"appfwprofile_xmlxss_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type AppFWProfileCSRFTagBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + Comment string `json:"comment,omitempty"` + CSRFFormActionURL string `json:"csrfformactionurl,omitempty"` + CSRFTag string `json:"csrftag,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` +} + +type AppFWWSDL struct { + Comment string `json:"comment,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Overwrite bool `json:"overwrite,omitempty"` + Response string `json:"response,omitempty"` + Src string `json:"src,omitempty"` +} + +type AppFWPolicyLabel struct { + Count float64 `json:"__count,omitempty"` + Description string `json:"description,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Hits int `json:"hits,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyLabelType string `json:"policylabeltype,omitempty"` + PolicyType string `json:"policytype,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AppFWProtoFile struct { + Comment string `json:"comment,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Overwrite bool `json:"overwrite,omitempty"` + Response string `json:"response,omitempty"` + Src string `json:"src,omitempty"` +} + +type AppFWGlobalAuditSyslogPolicyBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + PolicyType string `json:"policytype,omitempty"` + Priority int `json:"priority,omitempty"` + State string `json:"state,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type AppFWGlobalBinding struct { + AppFWGlobalAppFWPolicyBinding []any `json:"appfwglobal_appfwpolicy_binding,omitempty"` + AppFWGlobalAuditNSLogPolicyBinding []any `json:"appfwglobal_auditnslogpolicy_binding,omitempty"` + AppFWGlobalAuditSyslogPolicyBinding []any `json:"appfwglobal_auditsyslogpolicy_binding,omitempty"` +} + +type AppFWProfileJSONXSSURLBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + ASValueExprJSONXSS string `json:"as_value_expr_json_xss,omitempty"` + ASValueTypeJSONXSS string `json:"as_value_type_json_xss,omitempty"` + Comment string `json:"comment,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + IsKeyRegexJSONXSS string `json:"iskeyregex_json_xss,omitempty"` + IsValueRegexJSONXSS string `json:"isvalueregex_json_xss,omitempty"` + JSONXSSURL string `json:"jsonxssurl,omitempty"` + KeyNameJSONXSS string `json:"keyname_json_xss,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` +} + +type AppFWProfileFileUploadTypeBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + ASFileUploadTypesURL string `json:"as_fileuploadtypes_url,omitempty"` + Comment string `json:"comment,omitempty"` + FileType []string `json:"filetype,omitempty"` + FileUploadType string `json:"fileuploadtype,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + IsNameRegex string `json:"isnameregex,omitempty"` + IsRegexFileUploadTypesURL string `json:"isregex_fileuploadtypes_url,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` +} + +type AppFWProfileXMLAttachmentURLBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + Comment string `json:"comment,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` + XMLAttachmentContentType string `json:"xmlattachmentcontenttype,omitempty"` + XMLAttachmentContentTypeCheck string `json:"xmlattachmentcontenttypecheck,omitempty"` + XMLAttachmentURL string `json:"xmlattachmenturl,omitempty"` + XMLMaxAttachmentSize int `json:"xmlmaxattachmentsize,omitempty"` + XMLMaxAttachmentSizeCheck string `json:"xmlmaxattachmentsizecheck,omitempty"` +} + +type AppFWURLEncodedFormContentType struct { + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + IsRegex string `json:"isregex,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + URLEncodedFormContentTypeValue string `json:"urlencodedformcontenttypevalue,omitempty"` +} + +type AppFWPolicyBinding struct { + AppFWPolicyAppFWGlobalBinding []any `json:"appfwpolicy_appfwglobal_binding,omitempty"` + AppFWPolicyAppFWPolicyLabelBinding []any `json:"appfwpolicy_appfwpolicylabel_binding,omitempty"` + AppFWPolicyCSVServerBinding []any `json:"appfwpolicy_csvserver_binding,omitempty"` + AppFWPolicyLBVServerBinding []any `json:"appfwpolicy_lbvserver_binding,omitempty"` + AppFWPolicyVPNVServerBinding []any `json:"appfwpolicy_vpnvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type AppFWProfileFieldConsistencyBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + Comment string `json:"comment,omitempty"` + FieldConsistency string `json:"fieldconsistency,omitempty"` + FormActionURLFFC string `json:"formactionurl_ffc,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + IsRegexFFC string `json:"isregex_ffc,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` +} + +type AppFWXMLSchema struct { + Comment string `json:"comment,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Overwrite bool `json:"overwrite,omitempty"` + Response string `json:"response,omitempty"` + Src string `json:"src,omitempty"` +} + +type AppFWArchive struct { + Comment string `json:"comment,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Response string `json:"response,omitempty"` + Src string `json:"src,omitempty"` + Target string `json:"target,omitempty"` +} + +type AppFWPolicyAppFWPolicyLabelBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AppFWProfileBlockKeywordBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + ASBlockKeywordFormURL string `json:"as_blockkeyword_formurl,omitempty"` + ASFieldNameIsRegexBlockKeyword string `json:"as_fieldname_isregex_blockkeyword,omitempty"` + BlockKeyword string `json:"blockkeyword,omitempty"` + BlockKeywordType string `json:"blockkeywordtype,omitempty"` + Comment string `json:"comment,omitempty"` + FieldName string `json:"fieldname,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` +} + +type AppFWSettings struct { + Builtin []string `json:"builtin,omitempty"` + CEFLogging string `json:"ceflogging,omitempty"` + CentralizedLearning string `json:"centralizedlearning,omitempty"` + ClientIPLoggingHeader string `json:"clientiploggingheader,omitempty"` + CookieFlags string `json:"cookieflags,omitempty"` + CookiePostEncryptPrefix string `json:"cookiepostencryptprefix,omitempty"` + DefaultProfile string `json:"defaultprofile,omitempty"` + EntityDecoding string `json:"entitydecoding,omitempty"` + Feature string `json:"feature,omitempty"` + GeoLocationLogging string `json:"geolocationlogging,omitempty"` + ImportSizeLimit int `json:"importsizelimit,omitempty"` + Learning string `json:"learning,omitempty"` + LearnRateLimit int `json:"learnratelimit,omitempty"` + LogMalformedReq string `json:"logmalformedreq,omitempty"` + MalformedReqAction []string `json:"malformedreqaction,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ProxyPassword string `json:"proxypassword,omitempty"` + ProxyPort int `json:"proxyport,omitempty"` + ProxyServer string `json:"proxyserver,omitempty"` + ProxyUsername string `json:"proxyusername,omitempty"` + SessionCookieName string `json:"sessioncookiename,omitempty"` + SessionLifetime int `json:"sessionlifetime,omitempty"` + SessionLimit int `json:"sessionlimit,omitempty"` + SessionTimeout int `json:"sessiontimeout,omitempty"` + SignatureAutoUpdate string `json:"signatureautoupdate,omitempty"` + SignatureURL string `json:"signatureurl,omitempty"` + UndefAction string `json:"undefaction,omitempty"` + UseConfigurableSecretKey string `json:"useconfigurablesecretkey,omitempty"` +} + +type AppFWPolicyCSVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AppFWProfileCMDInjectionBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + ASScanLocationCMD string `json:"as_scan_location_cmd,omitempty"` + ASValueExprCMD string `json:"as_value_expr_cmd,omitempty"` + ASValueTypeCMD string `json:"as_value_type_cmd,omitempty"` + CMDInjection string `json:"cmdinjection,omitempty"` + Comment string `json:"comment,omitempty"` + FormActionURLCMD string `json:"formactionurl_cmd,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + IsRegexCMD string `json:"isregex_cmd,omitempty"` + IsValueRegexCMD string `json:"isvalueregex_cmd,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` +} + +type AppFWPolicyLabelPolicyBindingBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AppFWProfileStartURLBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + Comment string `json:"comment,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + StartURL string `json:"starturl,omitempty"` + State string `json:"state,omitempty"` +} + +type AppFWProfileJSONBlockKeywordBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + Comment string `json:"comment,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + IsKeyRegexJSONBlockKeyword string `json:"iskeyregex_json_blockkeyword,omitempty"` + JSONBlockKeyword string `json:"jsonblockkeyword,omitempty"` + JSONBlockKeywordType string `json:"jsonblockkeywordtype,omitempty"` + JSONBlockKeywordURL string `json:"jsonblockkeywordurl,omitempty"` + KeyNameJSONBlockKeyword string `json:"keyname_json_blockkeyword,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` +} + +type AppFWFieldType struct { + Builtin []string `json:"builtin,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NoCharMaps bool `json:"nocharmaps,omitempty"` + Priority int `json:"priority,omitempty"` + Regex string `json:"regex,omitempty"` +} + +type AppFWLearningData struct { + ASScanLocationSQL string `json:"as_scan_location_sql,omitempty"` + ASScanLocationXSS string `json:"as_scan_location_xss,omitempty"` + ASValueExprSQL string `json:"as_value_expr_sql,omitempty"` + ASValueExprXSS string `json:"as_value_expr_xss,omitempty"` + ASValueTypeSQL string `json:"as_value_type_sql,omitempty"` + ASValueTypeXSS string `json:"as_value_type_xss,omitempty"` + ContentType string `json:"contenttype,omitempty"` + CookieConsistency string `json:"cookieconsistency,omitempty"` + Count float64 `json:"__count,omitempty"` + CreditCardNumber string `json:"creditcardnumber,omitempty"` + CreditCardNumberURL string `json:"creditcardnumberurl,omitempty"` + CrossSiteScripting string `json:"crosssitescripting,omitempty"` + CSRFFormOriginURL string `json:"csrfformoriginurl,omitempty"` + CSRFTag string `json:"csrftag,omitempty"` + Data string `json:"data,omitempty"` + FieldConsistency string `json:"fieldconsistency,omitempty"` + FieldFormat string `json:"fieldformat,omitempty"` + FieldFormatCharMapPCRE string `json:"fieldformatcharmappcre,omitempty"` + FieldFormatMaxLength int `json:"fieldformatmaxlength,omitempty"` + FieldFormatMinLength int `json:"fieldformatminlength,omitempty"` + FieldType string `json:"fieldtype,omitempty"` + FormActionURLFF string `json:"formactionurl_ff,omitempty"` + FormActionURLFFC string `json:"formactionurl_ffc,omitempty"` + FormActionURLSQL string `json:"formactionurl_sql,omitempty"` + FormActionURLXSS string `json:"formactionurl_xss,omitempty"` + Hits int `json:"hits,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ProfileName string `json:"profilename,omitempty"` + SecurityCheck string `json:"securitycheck,omitempty"` + SQLInjection string `json:"sqlinjection,omitempty"` + StartURL string `json:"starturl,omitempty"` + Target string `json:"target,omitempty"` + TotalXMLRequests bool `json:"totalxmlrequests,omitempty"` + URL string `json:"url,omitempty"` + Value string `json:"value,omitempty"` + ValueType string `json:"value_type,omitempty"` + XMLAttachmentCheck string `json:"xmlattachmentcheck,omitempty"` + XMLDOSCheck string `json:"xmldoscheck,omitempty"` + XMLWSICheck string `json:"xmlwsicheck,omitempty"` +} + +type AppFWPolicyLabelAppFWPolicyBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AppFWPolicyVPNVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AppFWProfileXMLSQLInjectionBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + ASScanLocationXMLSQL string `json:"as_scan_location_xmlsql,omitempty"` + Comment string `json:"comment,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + IsRegexXMLSQL string `json:"isregex_xmlsql,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` + XMLSQLInjection string `json:"xmlsqlinjection,omitempty"` +} + +type AppFWGRPCWebJSONContentType struct { + Count float64 `json:"__count,omitempty"` + GRPCWebJSONContentTypeValue string `json:"grpcwebjsoncontenttypevalue,omitempty"` + IsRegex string `json:"isregex,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type AppFWProfileTrustedLearningClientsBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + Comment string `json:"comment,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` + TrustedLearningClients string `json:"trustedlearningclients,omitempty"` +} + +type AppFWProfileCreditCardNumberBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + Comment string `json:"comment,omitempty"` + CreditCardNumber string `json:"creditcardnumber,omitempty"` + CreditCardNumberURL string `json:"creditcardnumberurl,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` +} + +type AppFWProfileExcludeRESContentTypeBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + Comment string `json:"comment,omitempty"` + ExcludeRESContentType string `json:"excluderescontenttype,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` +} + +type AppFWJSONContentType struct { + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + IsRegex string `json:"isregex,omitempty"` + JSONContentTypeValue string `json:"jsoncontenttypevalue,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type AppFWProfileSQLInjectionBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + ASScanLocationSQL string `json:"as_scan_location_sql,omitempty"` + ASValueExprSQL string `json:"as_value_expr_sql,omitempty"` + ASValueTypeSQL string `json:"as_value_type_sql,omitempty"` + Comment string `json:"comment,omitempty"` + FormActionURLSQL string `json:"formactionurl_sql,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + IsRegexSQL string `json:"isregex_sql,omitempty"` + IsValueRegexSQL string `json:"isvalueregex_sql,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + SQLInjection string `json:"sqlinjection,omitempty"` + State string `json:"state,omitempty"` +} + +type AppFWProfileRESTValidationBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + Comment string `json:"comment,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RESTValidationAction string `json:"rest_validation_action,omitempty"` + RESTValidation string `json:"restvalidation,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` +} + +type AppFWGRPCContentType struct { + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + GRPCContentTypeValue string `json:"grpccontenttypevalue,omitempty"` + IsRegex string `json:"isregex,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type AppFWProfileBypassListBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + ASBypassList string `json:"as_bypass_list,omitempty"` + ASBypassListAction string `json:"as_bypass_list_action,omitempty"` + ASBypassListLocation string `json:"as_bypass_list_location,omitempty"` + ASBypassListValueType string `json:"as_bypass_list_value_type,omitempty"` + Comment string `json:"comment,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` +} + +type AppFWHTMLErrorPage struct { + Comment string `json:"comment,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Overwrite bool `json:"overwrite,omitempty"` + Response string `json:"response,omitempty"` + Src string `json:"src,omitempty"` +} + +type AppFWProfileSafeObjectBinding struct { + Action []string `json:"action,omitempty"` + AlertOnly string `json:"alertonly,omitempty"` + ASExpression string `json:"as_expression,omitempty"` + Comment string `json:"comment,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + MaxMatchLength int `json:"maxmatchlength,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + SafeObject string `json:"safeobject,omitempty"` + State string `json:"state,omitempty"` +} + +type AppFWProfileGRPCValidationBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + Comment string `json:"comment,omitempty"` + GRPCRelaxValidationAction string `json:"grpc_relax_validation_action,omitempty"` + GRPCValidation string `json:"grpcvalidation,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` +} + +type AppFWProfileXMLWSIURLBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + Comment string `json:"comment,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` + XMLWSIChecks string `json:"xmlwsichecks,omitempty"` + XMLWSIURL string `json:"xmlwsiurl,omitempty"` +} + +type AppFWPolicyAppFWGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AppFWProfileDenyListBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + ASDenyList string `json:"as_deny_list,omitempty"` + ASDenyListAction []string `json:"as_deny_list_action,omitempty"` + ASDenyListLocation string `json:"as_deny_list_location,omitempty"` + ASDenyListValueType string `json:"as_deny_list_value_type,omitempty"` + Comment string `json:"comment,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` +} + +type AppFWPolicyLabelBinding struct { + AppFWPolicyLabelAppFWPolicyBinding []any `json:"appfwpolicylabel_appfwpolicy_binding,omitempty"` + AppFWPolicyLabelPolicyBindingBinding []any `json:"appfwpolicylabel_policybinding_binding,omitempty"` + LabelName string `json:"labelname,omitempty"` +} + +type AppFWProfile struct { + AddCookieFlags string `json:"addcookieflags,omitempty"` + APISpec string `json:"apispec,omitempty"` + ArchiveName string `json:"archivename,omitempty"` + ASProfBypassListEnable string `json:"as_prof_bypass_list_enable,omitempty"` + ASProfDenyListEnable string `json:"as_prof_deny_list_enable,omitempty"` + Augment bool `json:"augment,omitempty"` + BlockKeywordAction []string `json:"blockkeywordaction,omitempty"` + BufferOverflowAction []string `json:"bufferoverflowaction,omitempty"` + BufferOverflowMaxCookieLength int `json:"bufferoverflowmaxcookielength,omitempty"` + BufferOverflowMaxHeaderLength int `json:"bufferoverflowmaxheaderlength,omitempty"` + BufferOverflowMaxQueryLength int `json:"bufferoverflowmaxquerylength,omitempty"` + BufferOverflowMaxTotalHeaderLength int `json:"bufferoverflowmaxtotalheaderlength,omitempty"` + BufferOverflowMaxURLLength int `json:"bufferoverflowmaxurllength,omitempty"` + Builtin bool `json:"builtin,omitempty"` + CanonicalizeHTMLResponse string `json:"canonicalizehtmlresponse,omitempty"` + CEFLogging string `json:"ceflogging,omitempty"` + CheckRequestHeaders string `json:"checkrequestheaders,omitempty"` + ClientIPExpression string `json:"clientipexpression,omitempty"` + CMDInjectionAction []string `json:"cmdinjectionaction,omitempty"` + CMDInjectionGrammar string `json:"cmdinjectiongrammar,omitempty"` + CMDInjectionType string `json:"cmdinjectiontype,omitempty"` + Comment string `json:"comment,omitempty"` + ContentTypeAction []string `json:"contenttypeaction,omitempty"` + CookieConsistencyAction []string `json:"cookieconsistencyaction,omitempty"` + CookieEncryption string `json:"cookieencryption,omitempty"` + CookieHijackingAction []string `json:"cookiehijackingaction,omitempty"` + CookieProxying string `json:"cookieproxying,omitempty"` + CookieSameSiteAttribute string `json:"cookiesamesiteattribute,omitempty"` + CookieTransforms string `json:"cookietransforms,omitempty"` + Count float64 `json:"__count,omitempty"` + CreditCard []string `json:"creditcard,omitempty"` + CreditCardAction []string `json:"creditcardaction,omitempty"` + CreditCardMaxAllowed int `json:"creditcardmaxallowed,omitempty"` + CreditCardXOut string `json:"creditcardxout,omitempty"` + CrossSiteScriptingAction []string `json:"crosssitescriptingaction,omitempty"` + CrossSiteScriptingCheckCompleteURLs string `json:"crosssitescriptingcheckcompleteurls,omitempty"` + CrossSiteScriptingTransformUnsafeHTML string `json:"crosssitescriptingtransformunsafehtml,omitempty"` + CSRFTag string `json:"csrftag,omitempty"` + CSRFTagAction []string `json:"csrftagaction,omitempty"` + CustomSettings string `json:"customsettings,omitempty"` + DefaultCharset string `json:"defaultcharset,omitempty"` + DefaultFieldFormatMaxLength int `json:"defaultfieldformatmaxlength,omitempty"` + DefaultFieldFormatMaxOccurrences int `json:"defaultfieldformatmaxoccurrences,omitempty"` + DefaultFieldFormatMinLength int `json:"defaultfieldformatminlength,omitempty"` + DefaultFieldFormatType string `json:"defaultfieldformattype,omitempty"` + Defaults string `json:"defaults,omitempty"` + DenyURLAction []string `json:"denyurlaction,omitempty"` + DoSecureCreditCardLogging string `json:"dosecurecreditcardlogging,omitempty"` + DynamicLearning []string `json:"dynamiclearning,omitempty"` + EnableFormTagging string `json:"enableformtagging,omitempty"` + ErrorURL string `json:"errorurl,omitempty"` + ExcludeFileUploadFromChecks string `json:"excludefileuploadfromchecks,omitempty"` + ExemptClosureURLsFromSecurityChecks string `json:"exemptclosureurlsfromsecuritychecks,omitempty"` + FakeAccountDetection string `json:"fakeaccountdetection,omitempty"` + FieldConsistencyAction []string `json:"fieldconsistencyaction,omitempty"` + FieldFormatAction []string `json:"fieldformataction,omitempty"` + FieldScan string `json:"fieldscan,omitempty"` + FieldScanLimit int `json:"fieldscanlimit,omitempty"` + FileUploadMaxNum int `json:"fileuploadmaxnum,omitempty"` + FileUploadTypesAction []string `json:"fileuploadtypesaction,omitempty"` + GeoLocationLogging string `json:"geolocationlogging,omitempty"` + GRPCAction []string `json:"grpcaction,omitempty"` + HTMLErrorObject string `json:"htmlerrorobject,omitempty"` + HTMLErrorStatusCode int `json:"htmlerrorstatuscode,omitempty"` + HTMLErrorStatusMessage string `json:"htmlerrorstatusmessage,omitempty"` + ImportProfileName string `json:"importprofilename,omitempty"` + InferContentTypeXMLPayloadAction []string `json:"infercontenttypexmlpayloadaction,omitempty"` + InsertCookieSameSiteAttribute string `json:"insertcookiesamesiteattribute,omitempty"` + InspectContentTypes []string `json:"inspectcontenttypes,omitempty"` + InspectQueryContentTypes []string `json:"inspectquerycontenttypes,omitempty"` + InvalidPercentHandling string `json:"invalidpercenthandling,omitempty"` + JSONBlockKeywordAction []string `json:"jsonblockkeywordaction,omitempty"` + JSONCMDInjectionAction []string `json:"jsoncmdinjectionaction,omitempty"` + JSONCMDInjectionGrammar string `json:"jsoncmdinjectiongrammar,omitempty"` + JSONCMDInjectionType string `json:"jsoncmdinjectiontype,omitempty"` + JSONDOSAction []string `json:"jsondosaction,omitempty"` + JSONErrorObject string `json:"jsonerrorobject,omitempty"` + JSONErrorStatusCode int `json:"jsonerrorstatuscode,omitempty"` + JSONErrorStatusMessage string `json:"jsonerrorstatusmessage,omitempty"` + JSONFieldScan string `json:"jsonfieldscan,omitempty"` + JSONFieldScanLimit int `json:"jsonfieldscanlimit,omitempty"` + JSONMessageScan string `json:"jsonmessagescan,omitempty"` + JSONMessageScanLimit int `json:"jsonmessagescanlimit,omitempty"` + JSONSQLInjectionAction []string `json:"jsonsqlinjectionaction,omitempty"` + JSONSQLInjectionGrammar string `json:"jsonsqlinjectiongrammar,omitempty"` + JSONSQLInjectionType string `json:"jsonsqlinjectiontype,omitempty"` + JSONXSSAction []string `json:"jsonxssaction,omitempty"` + Learning string `json:"learning,omitempty"` + LogEveryPolicyHit string `json:"logeverypolicyhit,omitempty"` + MatchURLString string `json:"matchurlstring,omitempty"` + MessageScan string `json:"messagescan,omitempty"` + MessageScanLimit int `json:"messagescanlimit,omitempty"` + MessageScanLimitContentTypes []string `json:"messagescanlimitcontenttypes,omitempty"` + MultipleHeaderAction []string `json:"multipleheaderaction,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OptimizePartialReqs string `json:"optimizepartialreqs,omitempty"` + Overwrite bool `json:"overwrite,omitempty"` + PercentDecodeRecursively string `json:"percentdecoderecursively,omitempty"` + PostBodyLimit int `json:"postbodylimit,omitempty"` + PostBodyLimitAction []string `json:"postbodylimitaction,omitempty"` + PostBodyLimitSignature int `json:"postbodylimitsignature,omitempty"` + ProtoFileObject string `json:"protofileobject,omitempty"` + RefererHeaderCheck string `json:"refererheadercheck,omitempty"` + RelaxationRules bool `json:"relaxationrules,omitempty"` + ReplaceURLString string `json:"replaceurlstring,omitempty"` + RequestContentType string `json:"requestcontenttype,omitempty"` + ResponseContentType string `json:"responsecontenttype,omitempty"` + RESTAction []string `json:"restaction,omitempty"` + RFCProfile string `json:"rfcprofile,omitempty"` + SemicolonFieldSeparator string `json:"semicolonfieldseparator,omitempty"` + SessionCookieName string `json:"sessioncookiename,omitempty"` + SessionlessFieldConsistency string `json:"sessionlessfieldconsistency,omitempty"` + SessionlessURLClosure string `json:"sessionlessurlclosure,omitempty"` + Signatures string `json:"signatures,omitempty"` + SQLInjectionAction []string `json:"sqlinjectionaction,omitempty"` + SQLInjectionCheckSQLWildChars string `json:"sqlinjectionchecksqlwildchars,omitempty"` + SQLInjectionGrammar string `json:"sqlinjectiongrammar,omitempty"` + SQLInjectionOnlyCheckFieldsWithSQLChars string `json:"sqlinjectiononlycheckfieldswithsqlchars,omitempty"` + SQLInjectionParseComments string `json:"sqlinjectionparsecomments,omitempty"` + SQLInjectionRuleType string `json:"sqlinjectionruletype,omitempty"` + SQLInjectionTransformSpecialChars string `json:"sqlinjectiontransformspecialchars,omitempty"` + SQLInjectionType string `json:"sqlinjectiontype,omitempty"` + StartURLAction []string `json:"starturlaction,omitempty"` + StartURLClosure string `json:"starturlclosure,omitempty"` + State string `json:"state,omitempty"` + Streaming string `json:"streaming,omitempty"` + StripComments string `json:"stripcomments,omitempty"` + StripHTMLComments string `json:"striphtmlcomments,omitempty"` + StripXMLComments string `json:"stripxmlcomments,omitempty"` + Trace string `json:"trace,omitempty"` + TypeField []string `json:"type,omitempty"` + URLDecodeRequestCookies string `json:"urldecoderequestcookies,omitempty"` + UseHTMLErrorObject string `json:"usehtmlerrorobject,omitempty"` + VerboseLogLevel string `json:"verboseloglevel,omitempty"` + XMLAttachmentAction []string `json:"xmlattachmentaction,omitempty"` + XMLDOSAction []string `json:"xmldosaction,omitempty"` + XMLErrorObject string `json:"xmlerrorobject,omitempty"` + XMLErrorStatusCode int `json:"xmlerrorstatuscode,omitempty"` + XMLErrorStatusMessage string `json:"xmlerrorstatusmessage,omitempty"` + XMLFormatAction []string `json:"xmlformataction,omitempty"` + XMLSOAPFaultAction []string `json:"xmlsoapfaultaction,omitempty"` + XMLSQLInjectionAction []string `json:"xmlsqlinjectionaction,omitempty"` + XMLSQLInjectionCheckSQLWildChars string `json:"xmlsqlinjectionchecksqlwildchars,omitempty"` + XMLSQLInjectionOnlyCheckFieldsWithSQLChars string `json:"xmlsqlinjectiononlycheckfieldswithsqlchars,omitempty"` + XMLSQLInjectionParseComments string `json:"xmlsqlinjectionparsecomments,omitempty"` + XMLSQLInjectionType string `json:"xmlsqlinjectiontype,omitempty"` + XMLValidationAction []string `json:"xmlvalidationaction,omitempty"` + XMLWSIAction []string `json:"xmlwsiaction,omitempty"` + XMLXSSAction []string `json:"xmlxssaction,omitempty"` +} + +type AppFWXMLContentType struct { + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + IsRegex string `json:"isregex,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + XMLContentTypeValue string `json:"xmlcontenttypevalue,omitempty"` +} + +type AppFWMultipartFormContentType struct { + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + IsRegex string `json:"isregex,omitempty"` + MultipartFormContentTypeValue string `json:"multipartformcontenttypevalue,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type AppFWLearningSettings struct { + ContentTypeAutoDeployGracePeriod int `json:"contenttypeautodeploygraceperiod,omitempty"` + ContentTypeMinThreshold int `json:"contenttypeminthreshold,omitempty"` + ContentTypePercentThreshold int `json:"contenttypepercentthreshold,omitempty"` + CookieConsistencyAutoDeployGracePeriod int `json:"cookieconsistencyautodeploygraceperiod,omitempty"` + CookieConsistencyMinThreshold int `json:"cookieconsistencyminthreshold,omitempty"` + CookieConsistencyPercentThreshold int `json:"cookieconsistencypercentthreshold,omitempty"` + Count float64 `json:"__count,omitempty"` + CreditCardNumberMinThreshold int `json:"creditcardnumberminthreshold,omitempty"` + CreditCardNumberPercentThreshold int `json:"creditcardnumberpercentthreshold,omitempty"` + CrossSiteScriptingAutoDeployGracePeriod int `json:"crosssitescriptingautodeploygraceperiod,omitempty"` + CrossSiteScriptingMinThreshold int `json:"crosssitescriptingminthreshold,omitempty"` + CrossSiteScriptingPercentThreshold int `json:"crosssitescriptingpercentthreshold,omitempty"` + CSRFTagAutoDeployGracePeriod int `json:"csrftagautodeploygraceperiod,omitempty"` + CSRFTagMinThreshold int `json:"csrftagminthreshold,omitempty"` + CSRFTagPercentThreshold int `json:"csrftagpercentthreshold,omitempty"` + FieldConsistencyAutoDeployGracePeriod int `json:"fieldconsistencyautodeploygraceperiod,omitempty"` + FieldConsistencyMinThreshold int `json:"fieldconsistencyminthreshold,omitempty"` + FieldConsistencyPercentThreshold int `json:"fieldconsistencypercentthreshold,omitempty"` + FieldFormatAutoDeployGracePeriod int `json:"fieldformatautodeploygraceperiod,omitempty"` + FieldFormatMinThreshold int `json:"fieldformatminthreshold,omitempty"` + FieldFormatPercentThreshold int `json:"fieldformatpercentthreshold,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ProfileName string `json:"profilename,omitempty"` + SQLInjectionAutoDeployGracePeriod int `json:"sqlinjectionautodeploygraceperiod,omitempty"` + SQLInjectionMinThreshold int `json:"sqlinjectionminthreshold,omitempty"` + SQLInjectionPercentThreshold int `json:"sqlinjectionpercentthreshold,omitempty"` + StartURLAutoDeployGracePeriod int `json:"starturlautodeploygraceperiod,omitempty"` + StartURLMinThreshold int `json:"starturlminthreshold,omitempty"` + StartURLPercentThreshold int `json:"starturlpercentthreshold,omitempty"` + XMLAttachmentMinThreshold int `json:"xmlattachmentminthreshold,omitempty"` + XMLAttachmentPercentThreshold int `json:"xmlattachmentpercentthreshold,omitempty"` + XMLWSIMinThreshold int `json:"xmlwsiminthreshold,omitempty"` + XMLWSIPercentThreshold int `json:"xmlwsipercentthreshold,omitempty"` +} + +type AppFWProfileXMLXSSBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + ASScanLocationXMLXSS string `json:"as_scan_location_xmlxss,omitempty"` + Comment string `json:"comment,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + IsRegexXMLXSS string `json:"isregex_xmlxss,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` + XMLXSS string `json:"xmlxss,omitempty"` +} + +type AppFWProfileContentTypeBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + Comment string `json:"comment,omitempty"` + ContentType string `json:"contenttype,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` +} + +type AppFWProfileJSONSQLURLBinding struct { + AlertOnly string `json:"alertonly,omitempty"` + ASValueExprJSONSQL string `json:"as_value_expr_json_sql,omitempty"` + ASValueTypeJSONSQL string `json:"as_value_type_json_sql,omitempty"` + Comment string `json:"comment,omitempty"` + IsAutoDeployed string `json:"isautodeployed,omitempty"` + IsKeyRegexJSONSQL string `json:"iskeyregex_json_sql,omitempty"` + IsValueRegexJSONSQL string `json:"isvalueregex_json_sql,omitempty"` + JSONSQLURL string `json:"jsonsqlurl,omitempty"` + KeyNameJSONSQL string `json:"keyname_json_sql,omitempty"` + Name string `json:"name,omitempty"` + ResourceID string `json:"resourceid,omitempty"` + RuleType string `json:"ruletype,omitempty"` + State string `json:"state,omitempty"` +} + +type AppFWCustomSettings struct { + Name string `json:"name,omitempty"` + Target string `json:"target,omitempty"` +} diff --git a/nitrogo/models/appqoe.go b/nitrogo/models/appqoe.go new file mode 100644 index 0000000..b44f3f8 --- /dev/null +++ b/nitrogo/models/appqoe.go @@ -0,0 +1,61 @@ +package models + +// appqoe configuration structs +type AppQOECustomResp struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Src string `json:"src,omitempty"` +} + +type AppQOEPolicyLBVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BindPriority int `json:"bindpriority,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Name string `json:"name,omitempty"` +} + +type AppQOEParameter struct { + AvgWaitingClient int `json:"avgwaitingclient,omitempty"` + DosAttackThresh int `json:"dosattackthresh,omitempty"` + MaxAltRespBandwidth int `json:"maxaltrespbandwidth,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + SessionLife int `json:"sessionlife,omitempty"` +} + +type AppQOEAction struct { + AltContentPath string `json:"altcontentpath,omitempty"` + AltContentSvcName string `json:"altcontentsvcname,omitempty"` + Count float64 `json:"__count,omitempty"` + CustomFile string `json:"customfile,omitempty"` + Delay int `json:"delay,omitempty"` + DosAction string `json:"dosaction,omitempty"` + DosTrigExpression string `json:"dostrigexpression,omitempty"` + Hits int `json:"hits,omitempty"` + MaxConn int `json:"maxconn,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NumRetries int `json:"numretries,omitempty"` + PolQDepth int `json:"polqdepth,omitempty"` + Priority string `json:"priority,omitempty"` + PriQDepth int `json:"priqdepth,omitempty"` + RespondWith string `json:"respondwith,omitempty"` + RetryOnReset string `json:"retryonreset,omitempty"` + RetryOnTimeout int `json:"retryontimeout,omitempty"` + TCPProfile string `json:"tcpprofile,omitempty"` +} + +type AppQOEPolicyBinding struct { + AppQOEPolicyLBVServerBinding []any `json:"appqoepolicy_lbvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type AppQOEPolicy struct { + Action string `json:"action,omitempty"` + Count float64 `json:"__count,omitempty"` + Hits int `json:"hits,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule string `json:"rule,omitempty"` +} diff --git a/nitrogo/models/audit.go b/nitrogo/models/audit.go new file mode 100644 index 0000000..0569b93 --- /dev/null +++ b/nitrogo/models/audit.go @@ -0,0 +1,373 @@ +package models + +// audit configuration structs +type AuditSyslogAction struct { + ACL string `json:"acl,omitempty"` + ALG string `json:"alg,omitempty"` + AppFlowExport string `json:"appflowexport,omitempty"` + Builtin []string `json:"builtin,omitempty"` + ContentInspectionLog string `json:"contentinspectionlog,omitempty"` + Count float64 `json:"__count,omitempty"` + DateFormat string `json:"dateformat,omitempty"` + DNS string `json:"dns,omitempty"` + DomainResolveNow bool `json:"domainresolvenow,omitempty"` + DomainResolveRetry int `json:"domainresolveretry,omitempty"` + Feature string `json:"feature,omitempty"` + HTTPAuthToken string `json:"httpauthtoken,omitempty"` + HTTPEndpointURL string `json:"httpendpointurl,omitempty"` + IP string `json:"ip,omitempty"` + LBVServerName string `json:"lbvservername,omitempty"` + LogFacility string `json:"logfacility,omitempty"` + LogLevel []string `json:"loglevel,omitempty"` + LSN string `json:"lsn,omitempty"` + ManagementLog []string `json:"managementlog,omitempty"` + MaxLogDataSizeToHold int `json:"maxlogdatasizetohold,omitempty"` + MgmtLogLevel []string `json:"mgmtloglevel,omitempty"` + Name string `json:"name,omitempty"` + NetProfile string `json:"netprofile,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ProtocolViolations string `json:"protocolviolations,omitempty"` + ServerDomainName string `json:"serverdomainname,omitempty"` + ServerIP string `json:"serverip,omitempty"` + ServerPort int `json:"serverport,omitempty"` + SSLInterception string `json:"sslinterception,omitempty"` + StreamAnalytics string `json:"streamanalytics,omitempty"` + SubscriberLog string `json:"subscriberlog,omitempty"` + SyslogCompliance string `json:"syslogcompliance,omitempty"` + TCP string `json:"tcp,omitempty"` + TCPProfileName string `json:"tcpprofilename,omitempty"` + TimeZone string `json:"timezone,omitempty"` + Transport string `json:"transport,omitempty"` + URLFiltering string `json:"urlfiltering,omitempty"` + UserDefinedAuditLog string `json:"userdefinedauditlog,omitempty"` +} + +type AuditSyslogParams struct { + ACL string `json:"acl,omitempty"` + ALG string `json:"alg,omitempty"` + AppFlowExport string `json:"appflowexport,omitempty"` + Builtin []string `json:"builtin,omitempty"` + ContentInspectionLog string `json:"contentinspectionlog,omitempty"` + DateFormat string `json:"dateformat,omitempty"` + DNS string `json:"dns,omitempty"` + Feature string `json:"feature,omitempty"` + LogFacility string `json:"logfacility,omitempty"` + LogLevel []string `json:"loglevel,omitempty"` + LSN string `json:"lsn,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ProtocolViolations string `json:"protocolviolations,omitempty"` + ServerIP string `json:"serverip,omitempty"` + ServerPort int `json:"serverport,omitempty"` + SSLInterception string `json:"sslinterception,omitempty"` + StreamAnalytics string `json:"streamanalytics,omitempty"` + SubscriberLog string `json:"subscriberlog,omitempty"` + TCP string `json:"tcp,omitempty"` + TimeZone string `json:"timezone,omitempty"` + URLFiltering string `json:"urlfiltering,omitempty"` + UserDefinedAuditLog string `json:"userdefinedauditlog,omitempty"` +} + +type AuditSyslogPolicyVPNVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuditNSLogPolicyAuditNSLogGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuditSyslogPolicyAAAGroupBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuditSyslogPolicyRNATGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuditNSLogPolicyVPNVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuditNSLogPolicyAuthenticationVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuditNSLogPolicyVPNGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuditNSLogPolicyTMGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuditNSLogPolicyLBVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuditNSLogAction struct { + ACL string `json:"acl,omitempty"` + ALG string `json:"alg,omitempty"` + AppFlowExport string `json:"appflowexport,omitempty"` + Builtin []string `json:"builtin,omitempty"` + ContentInspectionLog string `json:"contentinspectionlog,omitempty"` + Count float64 `json:"__count,omitempty"` + DateFormat string `json:"dateformat,omitempty"` + DomainResolveNow bool `json:"domainresolvenow,omitempty"` + DomainResolveRetry int `json:"domainresolveretry,omitempty"` + Feature string `json:"feature,omitempty"` + IP string `json:"ip,omitempty"` + LogFacility string `json:"logfacility,omitempty"` + LogLevel []string `json:"loglevel,omitempty"` + LSN string `json:"lsn,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ProtocolViolations string `json:"protocolviolations,omitempty"` + ServerDomainName string `json:"serverdomainname,omitempty"` + ServerIP string `json:"serverip,omitempty"` + ServerPort int `json:"serverport,omitempty"` + SSLInterception string `json:"sslinterception,omitempty"` + SubscriberLog string `json:"subscriberlog,omitempty"` + TCP string `json:"tcp,omitempty"` + TimeZone string `json:"timezone,omitempty"` + URLFiltering string `json:"urlfiltering,omitempty"` + UserDefinedAuditLog string `json:"userdefinedauditlog,omitempty"` +} + +type AuditSyslogPolicy struct { + Action string `json:"action,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + ExpressionType string `json:"expressiontype,omitempty"` + Feature string `json:"feature,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule string `json:"rule,omitempty"` +} + +type AuditMessageAction struct { + BypassSafetyCheck string `json:"bypasssafetycheck,omitempty"` + Count float64 `json:"__count,omitempty"` + Hits int `json:"hits,omitempty"` + LogLevel string `json:"loglevel,omitempty"` + LogLevel1 string `json:"loglevel1,omitempty"` + LogToNewNSLog string `json:"logtonewnslog,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ReferenceCount int `json:"referencecount,omitempty"` + StringBuilderExpr string `json:"stringbuilderexpr,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type AuditSyslogPolicyVPNGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuditMessages struct { + Count float64 `json:"__count,omitempty"` + LogLevel []string `json:"loglevel,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NumOfMesgs int `json:"numofmesgs,omitempty"` + Value string `json:"value,omitempty"` +} + +type AuditNSLogPolicy struct { + Action string `json:"action,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + ExpressionType string `json:"expressiontype,omitempty"` + Feature string `json:"feature,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule string `json:"rule,omitempty"` +} + +type AuditNSLogGlobalAuditNSLogPolicyBinding struct { + Builtin []string `json:"builtin,omitempty"` + GlobalBindType string `json:"globalbindtype,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuditNSLogPolicySystemGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuditSyslogPolicySystemGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuditNSLogPolicyAppFWGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuditSyslogPolicyTMGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuditNSLogPolicyBinding struct { + AuditNSLogPolicyAAAGroupBinding []any `json:"auditnslogpolicy_aaagroup_binding,omitempty"` + AuditNSLogPolicyAAAUserBinding []any `json:"auditnslogpolicy_aaauser_binding,omitempty"` + AuditNSLogPolicyAppFWGlobalBinding []any `json:"auditnslogpolicy_appfwglobal_binding,omitempty"` + AuditNSLogPolicyAuditNSLogGlobalBinding []any `json:"auditnslogpolicy_auditnslogglobal_binding,omitempty"` + AuditNSLogPolicyAuthenticationVServerBinding []any `json:"auditnslogpolicy_authenticationvserver_binding,omitempty"` + AuditNSLogPolicyCSVServerBinding []any `json:"auditnslogpolicy_csvserver_binding,omitempty"` + AuditNSLogPolicyLBVServerBinding []any `json:"auditnslogpolicy_lbvserver_binding,omitempty"` + AuditNSLogPolicySystemGlobalBinding []any `json:"auditnslogpolicy_systemglobal_binding,omitempty"` + AuditNSLogPolicyTMGlobalBinding []any `json:"auditnslogpolicy_tmglobal_binding,omitempty"` + AuditNSLogPolicyVPNGlobalBinding []any `json:"auditnslogpolicy_vpnglobal_binding,omitempty"` + AuditNSLogPolicyVPNVServerBinding []any `json:"auditnslogpolicy_vpnvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type AuditSyslogPolicyBinding struct { + AuditSyslogPolicyAAAGroupBinding []any `json:"auditsyslogpolicy_aaagroup_binding,omitempty"` + AuditSyslogPolicyAAAUserBinding []any `json:"auditsyslogpolicy_aaauser_binding,omitempty"` + AuditSyslogPolicyAuditSyslogGlobalBinding []any `json:"auditsyslogpolicy_auditsyslogglobal_binding,omitempty"` + AuditSyslogPolicyAuthenticationVServerBinding []any `json:"auditsyslogpolicy_authenticationvserver_binding,omitempty"` + AuditSyslogPolicyCSVServerBinding []any `json:"auditsyslogpolicy_csvserver_binding,omitempty"` + AuditSyslogPolicyLBVServerBinding []any `json:"auditsyslogpolicy_lbvserver_binding,omitempty"` + AuditSyslogPolicyRNATGlobalBinding []any `json:"auditsyslogpolicy_rnatglobal_binding,omitempty"` + AuditSyslogPolicySystemGlobalBinding []any `json:"auditsyslogpolicy_systemglobal_binding,omitempty"` + AuditSyslogPolicyTMGlobalBinding []any `json:"auditsyslogpolicy_tmglobal_binding,omitempty"` + AuditSyslogPolicyVPNGlobalBinding []any `json:"auditsyslogpolicy_vpnglobal_binding,omitempty"` + AuditSyslogPolicyVPNVServerBinding []any `json:"auditsyslogpolicy_vpnvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type AuditSyslogGlobalAuditSyslogPolicyBinding struct { + Builtin []string `json:"builtin,omitempty"` + Feature string `json:"feature,omitempty"` + GlobalBindType string `json:"globalbindtype,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuditSyslogGlobalBinding struct { + AuditSyslogGlobalAuditSyslogPolicyBinding []any `json:"auditsyslogglobal_auditsyslogpolicy_binding,omitempty"` +} + +type AuditSyslogPolicyCSVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuditNSLogPolicyAAAGroupBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuditSyslogPolicyLBVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuditNSLogPolicyAAAUserBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuditSyslogPolicyAuditSyslogGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuditNSLogParams struct { + ACL string `json:"acl,omitempty"` + ALG string `json:"alg,omitempty"` + AppFlowExport string `json:"appflowexport,omitempty"` + Builtin []string `json:"builtin,omitempty"` + ContentInspectionLog string `json:"contentinspectionlog,omitempty"` + DateFormat string `json:"dateformat,omitempty"` + Feature string `json:"feature,omitempty"` + LogFacility string `json:"logfacility,omitempty"` + LogLevel []string `json:"loglevel,omitempty"` + LSN string `json:"lsn,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ProtocolViolations string `json:"protocolviolations,omitempty"` + ServerIP string `json:"serverip,omitempty"` + ServerPort int `json:"serverport,omitempty"` + SSLInterception string `json:"sslinterception,omitempty"` + SubscriberLog string `json:"subscriberlog,omitempty"` + TCP string `json:"tcp,omitempty"` + TimeZone string `json:"timezone,omitempty"` + URLFiltering string `json:"urlfiltering,omitempty"` + UserDefinedAuditLog string `json:"userdefinedauditlog,omitempty"` +} + +type AuditNSLogPolicyCSVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuditSyslogPolicyAAAUserBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuditNSLogGlobalBinding struct { + AuditNSLogGlobalAuditNSLogPolicyBinding []any `json:"auditnslogglobal_auditnslogpolicy_binding,omitempty"` +} + +type AuditSyslogPolicyAuthenticationVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} diff --git a/nitrogo/models/authentication.go b/nitrogo/models/authentication.go new file mode 100644 index 0000000..789550d --- /dev/null +++ b/nitrogo/models/authentication.go @@ -0,0 +1,1512 @@ +package models + +// authentication configuration structs +type AuthenticationDFAPolicyBinding struct { + AuthenticationDFAPolicyVPNVServerBinding []any `json:"authenticationdfapolicy_vpnvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type AuthenticationWebAuthPolicy struct { + Action string `json:"action,omitempty"` + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule string `json:"rule,omitempty"` +} + +type AuthenticationLDAPPolicyBinding struct { + AuthenticationLDAPPolicyAuthenticationVServerBinding []any `json:"authenticationldappolicy_authenticationvserver_binding,omitempty"` + AuthenticationLDAPPolicySystemGlobalBinding []any `json:"authenticationldappolicy_systemglobal_binding,omitempty"` + AuthenticationLDAPPolicyVPNGlobalBinding []any `json:"authenticationldappolicy_vpnglobal_binding,omitempty"` + AuthenticationLDAPPolicyVPNVServerBinding []any `json:"authenticationldappolicy_vpnvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type AuthenticationWebAuthPolicyVPNVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationPolicySystemGlobalBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Name string `json:"name,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationNegotiatePolicy struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ReqAction string `json:"reqaction,omitempty"` + Rule string `json:"rule,omitempty"` +} + +type AuthenticationCertPolicyAuthenticationVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationLDAPPolicy struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ReqAction string `json:"reqaction,omitempty"` + Rule string `json:"rule,omitempty"` +} + +type AuthenticationSmartAccessProfile struct { + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Tags string `json:"tags,omitempty"` +} + +type AuthenticationLocalPolicySystemGlobalBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationPushService struct { + Count float64 `json:"__count,omitempty"` + CertEndpoint string `json:"certendpoint,omitempty"` + ClientID string `json:"clientid,omitempty"` + ClientSecret string `json:"clientsecret,omitempty"` + CustomerID string `json:"customerid,omitempty"` + HubName string `json:"hubname,omitempty"` + Name string `json:"name,omitempty"` + Namespace string `json:"Namespace,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PushCloudServerStatus string `json:"pushcloudserverstatus,omitempty"` + PushServiceStatus string `json:"pushservicestatus,omitempty"` + RefreshInterval int `json:"refreshinterval,omitempty"` + ServiceKey string `json:"servicekey,omitempty"` + ServiceKeyName string `json:"servicekeyname,omitempty"` + SigningKey string `json:"signingkey,omitempty"` + SigningKeyName string `json:"signingkeyname,omitempty"` + TrustService string `json:"trustservice,omitempty"` +} + +type AuthenticationStoreFrontAuthAction struct { + Count float64 `json:"__count,omitempty"` + DefaultAuthenticationGroup string `json:"defaultauthenticationgroup,omitempty"` + Domain string `json:"domain,omitempty"` + Failure int `json:"failure,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ServerURL string `json:"serverurl,omitempty"` + Success int `json:"success,omitempty"` +} + +type AuthenticationWebAuthPolicyBinding struct { + AuthenticationWebAuthPolicyAuthenticationVServerBinding []any `json:"authenticationwebauthpolicy_authenticationvserver_binding,omitempty"` + AuthenticationWebAuthPolicySystemGlobalBinding []any `json:"authenticationwebauthpolicy_systemglobal_binding,omitempty"` + AuthenticationWebAuthPolicyVPNGlobalBinding []any `json:"authenticationwebauthpolicy_vpnglobal_binding,omitempty"` + AuthenticationWebAuthPolicyVPNVServerBinding []any `json:"authenticationwebauthpolicy_vpnvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type AuthenticationLocalPolicyAuthenticationVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationWebAuthPolicyAuthenticationVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationSmartAccessPolicy struct { + Action string `json:"action,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Hits int `json:"hits,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule string `json:"rule,omitempty"` +} + +type AuthenticationSAMLIDPPolicyBinding struct { + AuthenticationSAMLIDPPolicyAuthenticationVServerBinding []any `json:"authenticationsamlidppolicy_authenticationvserver_binding,omitempty"` + AuthenticationSAMLIDPPolicyVPNVServerBinding []any `json:"authenticationsamlidppolicy_vpnvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type AuthenticationOAuthIDPPolicy struct { + Action string `json:"action,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Hits int `json:"hits,omitempty"` + LogAction string `json:"logaction,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule string `json:"rule,omitempty"` + UndefAction string `json:"undefaction,omitempty"` +} + +type AuthenticationVServerBinding struct { + AuthenticationVServerAuditNSLogPolicyBinding []any `json:"authenticationvserver_auditnslogpolicy_binding,omitempty"` + AuthenticationVServerAuditSyslogPolicyBinding []any `json:"authenticationvserver_auditsyslogpolicy_binding,omitempty"` + AuthenticationVServerAuthenticationCertPolicyBinding []any `json:"authenticationvserver_authenticationcertpolicy_binding,omitempty"` + AuthenticationVServerAuthenticationLDAPPolicyBinding []any `json:"authenticationvserver_authenticationldappolicy_binding,omitempty"` + AuthenticationVServerAuthenticationLocalPolicyBinding []any `json:"authenticationvserver_authenticationlocalpolicy_binding,omitempty"` + AuthenticationVServerAuthenticationLoginSchemaPolicyBinding []any `json:"authenticationvserver_authenticationloginschemapolicy_binding,omitempty"` + AuthenticationVServerAuthenticationNegotiatePolicyBinding []any `json:"authenticationvserver_authenticationnegotiatepolicy_binding,omitempty"` + AuthenticationVServerAuthenticationOAuthIDPPolicyBinding []any `json:"authenticationvserver_authenticationoauthidppolicy_binding,omitempty"` + AuthenticationVServerAuthenticationPolicyBinding []any `json:"authenticationvserver_authenticationpolicy_binding,omitempty"` + AuthenticationVServerAuthenticationRADIUSPolicyBinding []any `json:"authenticationvserver_authenticationradiuspolicy_binding,omitempty"` + AuthenticationVServerAuthenticationSAMLIDPPolicyBinding []any `json:"authenticationvserver_authenticationsamlidppolicy_binding,omitempty"` + AuthenticationVServerAuthenticationSAMLPolicyBinding []any `json:"authenticationvserver_authenticationsamlpolicy_binding,omitempty"` + AuthenticationVServerAuthenticationSmartAccessPolicyBinding []any `json:"authenticationvserver_authenticationsmartaccesspolicy_binding,omitempty"` + AuthenticationVServerAuthenticationTACACSPolicyBinding []any `json:"authenticationvserver_authenticationtacacspolicy_binding,omitempty"` + AuthenticationVServerAuthenticationWebAuthPolicyBinding []any `json:"authenticationvserver_authenticationwebauthpolicy_binding,omitempty"` + AuthenticationVServerCachePolicyBinding []any `json:"authenticationvserver_cachepolicy_binding,omitempty"` + AuthenticationVServerCSPolicyBinding []any `json:"authenticationvserver_cspolicy_binding,omitempty"` + AuthenticationVServerResponderPolicyBinding []any `json:"authenticationvserver_responderpolicy_binding,omitempty"` + AuthenticationVServerRewritePolicyBinding []any `json:"authenticationvserver_rewritepolicy_binding,omitempty"` + AuthenticationVServerTMSessionPolicyBinding []any `json:"authenticationvserver_tmsessionpolicy_binding,omitempty"` + AuthenticationVServerVPNPortalThemeBinding []any `json:"authenticationvserver_vpnportaltheme_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type AuthenticationLocalPolicyBinding struct { + AuthenticationLocalPolicyAuthenticationVServerBinding []any `json:"authenticationlocalpolicy_authenticationvserver_binding,omitempty"` + AuthenticationLocalPolicySystemGlobalBinding []any `json:"authenticationlocalpolicy_systemglobal_binding,omitempty"` + AuthenticationLocalPolicyVPNGlobalBinding []any `json:"authenticationlocalpolicy_vpnglobal_binding,omitempty"` + AuthenticationLocalPolicyVPNVServerBinding []any `json:"authenticationlocalpolicy_vpnvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type AuthenticationSmartAccessPolicyBinding struct { + AuthenticationSmartAccessPolicyAuthenticationVServerBinding []any `json:"authenticationsmartaccesspolicy_authenticationvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type AuthenticationVServerAuthenticationWebAuthPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type AuthenticationVServerAuditSyslogPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type AuthenticationRADIUSPolicyAuthenticationVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationSAMLIDPPolicy struct { + Action string `json:"action,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Hits int `json:"hits,omitempty"` + LogAction string `json:"logaction,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule string `json:"rule,omitempty"` + UndefAction string `json:"undefaction,omitempty"` +} + +type AuthenticationRADIUSAction struct { + Count float64 `json:"__count,omitempty"` + Accounting string `json:"accounting,omitempty"` + Authentication string `json:"authentication,omitempty"` + AuthServRetry int `json:"authservretry,omitempty"` + AuthTimeout int `json:"authtimeout,omitempty"` + CallingStationID string `json:"callingstationid,omitempty"` + DefaultAuthenticationGroup string `json:"defaultauthenticationgroup,omitempty"` + Failure int `json:"failure,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + IPAttributeType int `json:"ipattributetype,omitempty"` + IPVendorID int `json:"ipvendorid,omitempty"` + MessageAuthenticator string `json:"messageauthenticator,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PassEncoding string `json:"passencoding,omitempty"` + PwdAttributeType int `json:"pwdattributetype,omitempty"` + PwdVendorID int `json:"pwdvendorid,omitempty"` + RadAttributeType int `json:"radattributetype,omitempty"` + RadGroupSeparator string `json:"radgroupseparator,omitempty"` + RadGroupsPrefix string `json:"radgroupsprefix,omitempty"` + RadKey string `json:"radkey,omitempty"` + RadNASID string `json:"radnasid,omitempty"` + RadNASIP string `json:"radnasip,omitempty"` + RadVendorID int `json:"radvendorid,omitempty"` + ServerIP string `json:"serverip,omitempty"` + ServerName string `json:"servername,omitempty"` + ServerPort int `json:"serverport,omitempty"` + Success int `json:"success,omitempty"` + TargetLBVServer string `json:"targetlbvserver,omitempty"` + Transport string `json:"transport,omitempty"` + TunnelEndpointClientIP string `json:"tunnelendpointclientip,omitempty"` +} + +type AuthenticationAzureKeyVault struct { + Count float64 `json:"__count,omitempty"` + Authentication string `json:"authentication,omitempty"` + ClientID string `json:"clientid,omitempty"` + ClientSecret string `json:"clientsecret,omitempty"` + DefaultAuthenticationGroup string `json:"defaultauthenticationgroup,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PushService string `json:"pushservice,omitempty"` + RefreshInterval int `json:"refreshinterval,omitempty"` + ServiceKeyName string `json:"servicekeyname,omitempty"` + SignatureAlg string `json:"signaturealg,omitempty"` + TenantID string `json:"tenantid,omitempty"` + TokenEndpoint string `json:"tokenendpoint,omitempty"` + VaultName string `json:"vaultname,omitempty"` +} + +type AuthenticationEmailAction struct { + Content string `json:"content,omitempty"` + Count float64 `json:"__count,omitempty"` + DefaultAuthenticationGroup string `json:"defaultauthenticationgroup,omitempty"` + EmailAddress string `json:"emailaddress,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Password string `json:"password,omitempty"` + ServerURL string `json:"serverurl,omitempty"` + Timeout int `json:"timeout,omitempty"` + TypeField string `json:"type,omitempty"` + Username string `json:"username,omitempty"` +} + +type AuthenticationVServerTMSessionPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type AuthenticationTACACSPolicy struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ReqAction string `json:"reqaction,omitempty"` + Rule string `json:"rule,omitempty"` +} + +type AuthenticationLDAPPolicyAuthenticationVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationNegotiatePolicyBinding struct { + AuthenticationNegotiatePolicyAuthenticationVServerBinding []any `json:"authenticationnegotiatepolicy_authenticationvserver_binding,omitempty"` + AuthenticationNegotiatePolicyVPNGlobalBinding []any `json:"authenticationnegotiatepolicy_vpnglobal_binding,omitempty"` + AuthenticationNegotiatePolicyVPNVServerBinding []any `json:"authenticationnegotiatepolicy_vpnvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type AuthenticationSmartAccessPolicyAuthenticationVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationLoginSchemaPolicyVPNVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationNegotiatePolicyAuthenticationVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationSAMLAction struct { + Count float64 `json:"__count,omitempty"` + ArtifactResolutionServiceURL string `json:"artifactresolutionserviceurl,omitempty"` + Attribute1 string `json:"attribute1,omitempty"` + Attribute10 string `json:"attribute10,omitempty"` + Attribute11 string `json:"attribute11,omitempty"` + Attribute12 string `json:"attribute12,omitempty"` + Attribute13 string `json:"attribute13,omitempty"` + Attribute14 string `json:"attribute14,omitempty"` + Attribute15 string `json:"attribute15,omitempty"` + Attribute16 string `json:"attribute16,omitempty"` + Attribute2 string `json:"attribute2,omitempty"` + Attribute3 string `json:"attribute3,omitempty"` + Attribute4 string `json:"attribute4,omitempty"` + Attribute5 string `json:"attribute5,omitempty"` + Attribute6 string `json:"attribute6,omitempty"` + Attribute7 string `json:"attribute7,omitempty"` + Attribute8 string `json:"attribute8,omitempty"` + Attribute9 string `json:"attribute9,omitempty"` + AttributeConsumingServiceIndex int `json:"attributeconsumingserviceindex,omitempty"` + Attributes string `json:"attributes,omitempty"` + Audience string `json:"audience,omitempty"` + AuthnCtxClassRef []string `json:"authnctxclassref,omitempty"` + CustomAuthnCtxClassRef string `json:"customauthnctxclassref,omitempty"` + DefaultAuthenticationGroup string `json:"defaultauthenticationgroup,omitempty"` + DigestMethod string `json:"digestmethod,omitempty"` + EnforceUsername string `json:"enforceusername,omitempty"` + ForceAuthn string `json:"forceauthn,omitempty"` + GroupNameField string `json:"groupnamefield,omitempty"` + LogoutBinding string `json:"logoutbinding,omitempty"` + LogoutURL string `json:"logouturl,omitempty"` + MetadataImportStatus string `json:"metadataimportstatus,omitempty"` + MetadataRefreshInterval int `json:"metadatarefreshinterval,omitempty"` + MetadataURL string `json:"metadataurl,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PreferredBindType []string `json:"preferredbindtype,omitempty"` + RelayStateRule string `json:"relaystaterule,omitempty"` + RequestedAuthnContext string `json:"requestedauthncontext,omitempty"` + SAMLAcsIndex int `json:"samlacsindex,omitempty"` + SAMLBinding string `json:"samlbinding,omitempty"` + SAMLIDPCertName string `json:"samlidpcertname,omitempty"` + SAMLIssuerName string `json:"samlissuername,omitempty"` + SAMLRedirectURL string `json:"samlredirecturl,omitempty"` + SAMLRejectUnsignedAssertion string `json:"samlrejectunsignedassertion,omitempty"` + SAMLSigningCertName string `json:"samlsigningcertname,omitempty"` + SAMLTwoFactor string `json:"samltwofactor,omitempty"` + SAMLUserField string `json:"samluserfield,omitempty"` + SendThumbprint string `json:"sendthumbprint,omitempty"` + SignatureAlg string `json:"signaturealg,omitempty"` + SkewTime int `json:"skewtime,omitempty"` + StateChecks string `json:"statechecks,omitempty"` + StoreSAMLResponse string `json:"storesamlresponse,omitempty"` +} + +type AuthenticationVServerVPNPortalThemeBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + Name string `json:"name,omitempty"` + PortalTheme string `json:"portaltheme,omitempty"` +} + +type AuthenticationLocalPolicyVPNGlobalBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationLoginSchemaPolicy struct { + Count float64 `json:"__count,omitempty"` + Action string `json:"action,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Comment string `json:"comment,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + LogAction string `json:"logaction,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule string `json:"rule,omitempty"` + UndefAction string `json:"undefaction,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type AuthenticationLoginSchemaPolicyBinding struct { + AuthenticationLoginSchemaPolicyAuthenticationVServerBinding []any `json:"authenticationloginschemapolicy_authenticationvserver_binding,omitempty"` + AuthenticationLoginSchemaPolicyVPNVServerBinding []any `json:"authenticationloginschemapolicy_vpnvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type AuthenticationProtectedUserAction struct { + Count float64 `json:"__count,omitempty"` + MaxConcurrentUsers int `json:"maxconcurrentusers,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + RealmStr string `json:"realmstr,omitempty"` +} + +type AuthenticationPolicyAuthenticationVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Name string `json:"name,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationSAMLPolicyVPNGlobalBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationTACACSAction struct { + Count float64 `json:"__count,omitempty"` + Accounting string `json:"accounting,omitempty"` + Attribute1 string `json:"attribute1,omitempty"` + Attribute10 string `json:"attribute10,omitempty"` + Attribute11 string `json:"attribute11,omitempty"` + Attribute12 string `json:"attribute12,omitempty"` + Attribute13 string `json:"attribute13,omitempty"` + Attribute14 string `json:"attribute14,omitempty"` + Attribute15 string `json:"attribute15,omitempty"` + Attribute16 string `json:"attribute16,omitempty"` + Attribute2 string `json:"attribute2,omitempty"` + Attribute3 string `json:"attribute3,omitempty"` + Attribute4 string `json:"attribute4,omitempty"` + Attribute5 string `json:"attribute5,omitempty"` + Attribute6 string `json:"attribute6,omitempty"` + Attribute7 string `json:"attribute7,omitempty"` + Attribute8 string `json:"attribute8,omitempty"` + Attribute9 string `json:"attribute9,omitempty"` + Attributes string `json:"attributes,omitempty"` + AuditFailedCmds string `json:"auditfailedcmds,omitempty"` + Authorization string `json:"authorization,omitempty"` + AuthTimeout int `json:"authtimeout,omitempty"` + DefaultAuthenticationGroup string `json:"defaultauthenticationgroup,omitempty"` + Failure int `json:"failure,omitempty"` + GroupAttrName string `json:"groupattrname,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ServerIP string `json:"serverip,omitempty"` + ServerPort int `json:"serverport,omitempty"` + Success int `json:"success,omitempty"` + TACACSSecret string `json:"tacacssecret,omitempty"` +} + +type AuthenticationCertPolicyVPNVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationVServerAuthenticationLoginSchemaPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type AuthenticationSAMLIDPPolicyAuthenticationVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationNegotiatePolicyVPNGlobalBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationSAMLPolicyBinding struct { + AuthenticationSAMLPolicyAuthenticationVServerBinding []any `json:"authenticationsamlpolicy_authenticationvserver_binding,omitempty"` + AuthenticationSAMLPolicyVPNGlobalBinding []any `json:"authenticationsamlpolicy_vpnglobal_binding,omitempty"` + AuthenticationSAMLPolicyVPNVServerBinding []any `json:"authenticationsamlpolicy_vpnvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type AuthenticationVServerAuthenticationLocalPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type AuthenticationRADIUSPolicySystemGlobalBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationVServer struct { + Count float64 `json:"__count,omitempty"` + AppFlowLog string `json:"appflowlog,omitempty"` + Authentication string `json:"authentication,omitempty"` + AuthenticationDomain string `json:"authenticationdomain,omitempty"` + BackupVServer string `json:"backupvserver,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + CacheType string `json:"cachetype,omitempty"` + CacheVServer string `json:"cachevserver,omitempty"` + CertKeyNames string `json:"certkeynames,omitempty"` + CltTimeout int `json:"clttimeout,omitempty"` + Comment string `json:"comment,omitempty"` + CurAAAUsers int `json:"curaaausers,omitempty"` + CurState string `json:"curstate,omitempty"` + DisablePrimaryOnDown string `json:"disableprimaryondown,omitempty"` + DownStateFlush string `json:"downstateflush,omitempty"` + FailedLoginTimeout int `json:"failedlogintimeout,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + HTTPProfileName string `json:"httpprofilename,omitempty"` + IP string `json:"ip,omitempty"` + IPv46 string `json:"ipv46,omitempty"` + ListenPolicy string `json:"listenpolicy,omitempty"` + ListenPriority int `json:"listenpriority,omitempty"` + MaxLoginAttempts int `json:"maxloginattempts,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NGName string `json:"ngname,omitempty"` + Policy string `json:"policy,omitempty"` + Port int `json:"port,omitempty"` + Precedence string `json:"precedence,omitempty"` + Priority int `json:"priority,omitempty"` + Range int `json:"range,omitempty"` + Redirect string `json:"redirect,omitempty"` + RedirectURL string `json:"redirecturl,omitempty"` + SameSite string `json:"samesite,omitempty"` + Secondary bool `json:"secondary,omitempty"` + ServiceName string `json:"servicename,omitempty"` + ServiceType string `json:"servicetype,omitempty"` + SOMethod string `json:"somethod,omitempty"` + SOPersistence string `json:"sopersistence,omitempty"` + SOPersistenceTimeout int `json:"sopersistencetimeout,omitempty"` + SOThreshold int `json:"sothreshold,omitempty"` + State string `json:"state,omitempty"` + Status int `json:"status,omitempty"` + TCPProfileName string `json:"tcpprofilename,omitempty"` + TD int `json:"td,omitempty"` + TypeField string `json:"type,omitempty"` + Value string `json:"value,omitempty"` + VSType int `json:"vstype,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type AuthenticationNoAuthAction struct { + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + DefaultAuthenticationGroup string `json:"defaultauthenticationgroup,omitempty"` + Feature string `json:"feature,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type AuthenticationNegotiatePolicyVPNVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationSAMLPolicyVPNVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationAuthNProfile struct { + Count float64 `json:"__count,omitempty"` + AuthenticationDomain string `json:"authenticationdomain,omitempty"` + AuthenticationHost string `json:"authenticationhost,omitempty"` + AuthenticationLevel int `json:"authenticationlevel,omitempty"` + AuthNVSName string `json:"authnvsname,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type AuthenticationCaptchaAction struct { + Count float64 `json:"__count,omitempty"` + DefaultAuthenticationGroup string `json:"defaultauthenticationgroup,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ScoreThreshold int `json:"scorethreshold,omitempty"` + SecretKey string `json:"secretkey,omitempty"` + ServerURL string `json:"serverurl,omitempty"` + SiteKey string `json:"sitekey,omitempty"` +} + +type AuthenticationRADIUSPolicyBinding struct { + AuthenticationRADIUSPolicyAuthenticationVServerBinding []any `json:"authenticationradiuspolicy_authenticationvserver_binding,omitempty"` + AuthenticationRADIUSPolicySystemGlobalBinding []any `json:"authenticationradiuspolicy_systemglobal_binding,omitempty"` + AuthenticationRADIUSPolicyVPNGlobalBinding []any `json:"authenticationradiuspolicy_vpnglobal_binding,omitempty"` + AuthenticationRADIUSPolicyVPNVServerBinding []any `json:"authenticationradiuspolicy_vpnvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type AuthenticationTACACSPolicyBinding struct { + AuthenticationTACACSPolicyAuthenticationVServerBinding []any `json:"authenticationtacacspolicy_authenticationvserver_binding,omitempty"` + AuthenticationTACACSPolicySystemGlobalBinding []any `json:"authenticationtacacspolicy_systemglobal_binding,omitempty"` + AuthenticationTACACSPolicyVPNGlobalBinding []any `json:"authenticationtacacspolicy_vpnglobal_binding,omitempty"` + AuthenticationTACACSPolicyVPNVServerBinding []any `json:"authenticationtacacspolicy_vpnvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type AuthenticationSAMLPolicy struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ReqAction string `json:"reqaction,omitempty"` + Rule string `json:"rule,omitempty"` +} + +type AuthenticationLDAPPolicyVPNVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationWebAuthPolicyVPNGlobalBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationLocalPolicy struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ReqAction string `json:"reqaction,omitempty"` + Rule string `json:"rule,omitempty"` +} + +type AuthenticationVServerAuthenticationRADIUSPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type AuthenticationLoginSchemaPolicyAuthenticationVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationLocalPolicyVPNVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationVServerAuthenticationSAMLPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type AuthenticationSAMLIDPPolicyVPNVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationOAuthIDPPolicyAuthenticationVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationCitrixAuthAction struct { + Authentication string `json:"authentication,omitempty"` + AuthenticationType string `json:"authenticationtype,omitempty"` + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type AuthenticationVServerAuthenticationCertPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type AuthenticationPolicyLabelBinding struct { + AuthenticationPolicyLabelAuthenticationPolicyBinding []any `json:"authenticationpolicylabel_authenticationpolicy_binding,omitempty"` + LabelName string `json:"labelname,omitempty"` +} + +type AuthenticationDFAPolicy struct { + Action string `json:"action,omitempty"` + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule string `json:"rule,omitempty"` +} + +type AuthenticationTACACSPolicyVPNVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationRADIUSPolicyVPNGlobalBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationVServerAuthenticationLDAPPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type AuthenticationOAuthIDPProfile struct { + Count float64 `json:"__count,omitempty"` + Attributes string `json:"attributes,omitempty"` + Audience string `json:"audience,omitempty"` + ClientID string `json:"clientid,omitempty"` + ClientSecret string `json:"clientsecret,omitempty"` + ConfigService string `json:"configservice,omitempty"` + DefaultAuthenticationGroup string `json:"defaultauthenticationgroup,omitempty"` + EncryptToken string `json:"encrypttoken,omitempty"` + Issuer string `json:"issuer,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OAuthStatus string `json:"oauthstatus,omitempty"` + RedirectURL string `json:"redirecturl,omitempty"` + RefreshInterval int `json:"refreshinterval,omitempty"` + RelyingPartyMetadataURL string `json:"relyingpartymetadataurl,omitempty"` + SendPassword string `json:"sendpassword,omitempty"` + SignatureAlg string `json:"signaturealg,omitempty"` + SignatureService string `json:"signatureservice,omitempty"` + SkewTime int `json:"skewtime,omitempty"` +} + +type AuthenticationTACACSPolicySystemGlobalBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationEPAAction struct { + Count float64 `json:"__count,omitempty"` + CSecExpr string `json:"csecexpr,omitempty"` + DefaultEPAGroup string `json:"defaultepagroup,omitempty"` + DeleteFiles string `json:"deletefiles,omitempty"` + DevicePosture string `json:"deviceposture,omitempty"` + KillProcess string `json:"killprocess,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + QuarantineGroup string `json:"quarantinegroup,omitempty"` +} + +type AuthenticationPolicyBinding struct { + AuthenticationPolicyAuthenticationPolicyLabelBinding []any `json:"authenticationpolicy_authenticationpolicylabel_binding,omitempty"` + AuthenticationPolicyAuthenticationVServerBinding []any `json:"authenticationpolicy_authenticationvserver_binding,omitempty"` + AuthenticationPolicySystemGlobalBinding []any `json:"authenticationpolicy_systemglobal_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type AuthenticationCertPolicyVPNGlobalBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationDFAPolicyVPNVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationWebAuthAction struct { + Attribute1 string `json:"attribute1,omitempty"` + Attribute10 string `json:"attribute10,omitempty"` + Attribute11 string `json:"attribute11,omitempty"` + Attribute12 string `json:"attribute12,omitempty"` + Attribute13 string `json:"attribute13,omitempty"` + Attribute14 string `json:"attribute14,omitempty"` + Attribute15 string `json:"attribute15,omitempty"` + Attribute16 string `json:"attribute16,omitempty"` + Attribute2 string `json:"attribute2,omitempty"` + Attribute3 string `json:"attribute3,omitempty"` + Attribute4 string `json:"attribute4,omitempty"` + Attribute5 string `json:"attribute5,omitempty"` + Attribute6 string `json:"attribute6,omitempty"` + Attribute7 string `json:"attribute7,omitempty"` + Attribute8 string `json:"attribute8,omitempty"` + Attribute9 string `json:"attribute9,omitempty"` + Count float64 `json:"__count,omitempty"` + DefaultAuthenticationGroup string `json:"defaultauthenticationgroup,omitempty"` + FullReqExpr string `json:"fullreqexpr,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Scheme string `json:"scheme,omitempty"` + ServerIP string `json:"serverip,omitempty"` + ServerPort int `json:"serverport,omitempty"` + SuccessRule string `json:"successrule,omitempty"` +} + +type AuthenticationPolicyLabel struct { + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Description string `json:"description,omitempty"` + FlowType int `json:"flowtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Hits int `json:"hits,omitempty"` + LabelName string `json:"labelname,omitempty"` + LoginSchema string `json:"loginschema,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type AuthenticationRADIUSPolicy struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ReqAction string `json:"reqaction,omitempty"` + Rule string `json:"rule,omitempty"` +} + +type AuthenticationVServerAuthenticationOAuthIDPPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type AuthenticationVServerRewritePolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type AuthenticationDFAAction struct { + ClientID string `json:"clientid,omitempty"` + Count float64 `json:"__count,omitempty"` + DefaultAuthenticationGroup string `json:"defaultauthenticationgroup,omitempty"` + Failure int `json:"failure,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Passphrase string `json:"passphrase,omitempty"` + ServerURL string `json:"serverurl,omitempty"` + Success int `json:"success,omitempty"` +} + +type AuthenticationOAuthIDPPolicyBinding struct { + AuthenticationOAuthIDPPolicyAuthenticationVServerBinding []any `json:"authenticationoauthidppolicy_authenticationvserver_binding,omitempty"` + AuthenticationOAuthIDPPolicyVPNVServerBinding []any `json:"authenticationoauthidppolicy_vpnvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type AuthenticationVServerCachePolicyBinding struct { + Count float64 `json:"__count,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type AuthenticationVServerAuthenticationNegotiatePolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type AuthenticationTACACSPolicyAuthenticationVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationTACACSPolicyVPNGlobalBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationVServerAuthenticationSAMLIDPPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type AuthenticationVServerAuthenticationTACACSPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type AuthenticationLDAPAction struct { + Count float64 `json:"__count,omitempty"` + AlternateEmailAttr string `json:"alternateemailattr,omitempty"` + Attribute1 string `json:"attribute1,omitempty"` + Attribute10 string `json:"attribute10,omitempty"` + Attribute11 string `json:"attribute11,omitempty"` + Attribute12 string `json:"attribute12,omitempty"` + Attribute13 string `json:"attribute13,omitempty"` + Attribute14 string `json:"attribute14,omitempty"` + Attribute15 string `json:"attribute15,omitempty"` + Attribute16 string `json:"attribute16,omitempty"` + Attribute2 string `json:"attribute2,omitempty"` + Attribute3 string `json:"attribute3,omitempty"` + Attribute4 string `json:"attribute4,omitempty"` + Attribute5 string `json:"attribute5,omitempty"` + Attribute6 string `json:"attribute6,omitempty"` + Attribute7 string `json:"attribute7,omitempty"` + Attribute8 string `json:"attribute8,omitempty"` + Attribute9 string `json:"attribute9,omitempty"` + Attributes string `json:"attributes,omitempty"` + Authentication string `json:"authentication,omitempty"` + AuthTimeout int `json:"authtimeout,omitempty"` + CloudAttributes string `json:"cloudattributes,omitempty"` + DefaultAuthenticationGroup string `json:"defaultauthenticationgroup,omitempty"` + Email string `json:"email,omitempty"` + Failure int `json:"failure,omitempty"` + FollowReferrals string `json:"followreferrals,omitempty"` + GroupAttrName string `json:"groupattrname,omitempty"` + GroupNameIdentifier string `json:"groupnameidentifier,omitempty"` + GroupSearchAttribute string `json:"groupsearchattribute,omitempty"` + GroupSearchFilter string `json:"groupsearchfilter,omitempty"` + GroupSearchSubAttribute string `json:"groupsearchsubattribute,omitempty"` + KBAttribute string `json:"kbattribute,omitempty"` + LDAPBase string `json:"ldapbase,omitempty"` + LDAPBindDN string `json:"ldapbinddn,omitempty"` + LDAPBindDNPassword string `json:"ldapbinddnpassword,omitempty"` + LDAPHostname string `json:"ldaphostname,omitempty"` + LDAPLoginName string `json:"ldaploginname,omitempty"` + MaxLDAPReferrals int `json:"maxldapreferrals,omitempty"` + MaxNestingLevel int `json:"maxnestinglevel,omitempty"` + MSSRVRecordLocation string `json:"mssrvrecordlocation,omitempty"` + Name string `json:"name,omitempty"` + NestedGroupExtraction string `json:"nestedgroupextraction,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OTPSecret string `json:"otpsecret,omitempty"` + PasswdChange string `json:"passwdchange,omitempty"` + PushService string `json:"pushservice,omitempty"` + ReferralDNSLookup string `json:"referraldnslookup,omitempty"` + RequireUser string `json:"requireuser,omitempty"` + SearchFilter string `json:"searchfilter,omitempty"` + SecType string `json:"sectype,omitempty"` + ServerIP string `json:"serverip,omitempty"` + ServerName string `json:"servername,omitempty"` + ServerPort int `json:"serverport,omitempty"` + SSHPublicKey string `json:"sshpublickey,omitempty"` + SSONameAttribute string `json:"ssonameattribute,omitempty"` + SubAttributeName string `json:"subattributename,omitempty"` + Success int `json:"success,omitempty"` + SvrType string `json:"svrtype,omitempty"` + ValidateServerCert string `json:"validateservercert,omitempty"` +} + +type AuthenticationVServerAuthenticationPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type AuthenticationCertPolicyBinding struct { + AuthenticationCertPolicyAuthenticationVServerBinding []any `json:"authenticationcertpolicy_authenticationvserver_binding,omitempty"` + AuthenticationCertPolicyVPNGlobalBinding []any `json:"authenticationcertpolicy_vpnglobal_binding,omitempty"` + AuthenticationCertPolicyVPNVServerBinding []any `json:"authenticationcertpolicy_vpnvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type AuthenticationWebAuthPolicySystemGlobalBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationVServerAuditNSLogPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type AuthenticationSAMLPolicyAuthenticationVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationOAuthAction struct { + Count float64 `json:"__count,omitempty"` + AllowedAlgorithms []string `json:"allowedalgorithms,omitempty"` + Attribute1 string `json:"attribute1,omitempty"` + Attribute10 string `json:"attribute10,omitempty"` + Attribute11 string `json:"attribute11,omitempty"` + Attribute12 string `json:"attribute12,omitempty"` + Attribute13 string `json:"attribute13,omitempty"` + Attribute14 string `json:"attribute14,omitempty"` + Attribute15 string `json:"attribute15,omitempty"` + Attribute16 string `json:"attribute16,omitempty"` + Attribute2 string `json:"attribute2,omitempty"` + Attribute3 string `json:"attribute3,omitempty"` + Attribute4 string `json:"attribute4,omitempty"` + Attribute5 string `json:"attribute5,omitempty"` + Attribute6 string `json:"attribute6,omitempty"` + Attribute7 string `json:"attribute7,omitempty"` + Attribute8 string `json:"attribute8,omitempty"` + Attribute9 string `json:"attribute9,omitempty"` + Attributes string `json:"attributes,omitempty"` + Audience string `json:"audience,omitempty"` + Authentication string `json:"authentication,omitempty"` + AuthorizationEndpoint string `json:"authorizationendpoint,omitempty"` + CertEndpoint string `json:"certendpoint,omitempty"` + CertFilePath string `json:"certfilepath,omitempty"` + ClientID string `json:"clientid,omitempty"` + ClientSecret string `json:"clientsecret,omitempty"` + DefaultAuthenticationGroup string `json:"defaultauthenticationgroup,omitempty"` + GrantType string `json:"granttype,omitempty"` + GraphEndpoint string `json:"graphendpoint,omitempty"` + IDTokenDecryptEndpoint string `json:"idtokendecryptendpoint,omitempty"` + IntrospectURL string `json:"introspecturl,omitempty"` + IntuneDeviceIDExpression string `json:"intunedeviceidexpression,omitempty"` + Issuer string `json:"issuer,omitempty"` + MetadataURL string `json:"metadataurl,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OAuthMiscFlags []string `json:"oauthmiscflags,omitempty"` + OAuthStatus string `json:"oauthstatus,omitempty"` + OAuthType string `json:"oauthtype,omitempty"` + PKCE string `json:"pkce,omitempty"` + RefreshInterval int `json:"refreshinterval,omitempty"` + RequestAttribute string `json:"requestattribute,omitempty"` + ResourceURI string `json:"resourceuri,omitempty"` + SkewTime int `json:"skewtime,omitempty"` + TenantID string `json:"tenantid,omitempty"` + TokenEndpoint string `json:"tokenendpoint,omitempty"` + TokenEndpointAuthMethod string `json:"tokenendpointauthmethod,omitempty"` + UserInfoURL string `json:"userinfourl,omitempty"` + UsernameField string `json:"usernamefield,omitempty"` +} + +type AuthenticationNegotiateAction struct { + Count float64 `json:"__count,omitempty"` + DefaultAuthenticationGroup string `json:"defaultauthenticationgroup,omitempty"` + Domain string `json:"domain,omitempty"` + DomainUser string `json:"domainuser,omitempty"` + DomainUserPasswd string `json:"domainuserpasswd,omitempty"` + KCDSPN string `json:"kcdspn,omitempty"` + KeyTab string `json:"keytab,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NTLMPath string `json:"ntlmpath,omitempty"` + OU string `json:"ou,omitempty"` +} + +type AuthenticationLDAPPolicySystemGlobalBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationLoginSchema struct { + Count float64 `json:"__count,omitempty"` + AuthenticationSchema string `json:"authenticationschema,omitempty"` + AuthenticationStrength int `json:"authenticationstrength,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Feature string `json:"feature,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PasswdExpression string `json:"passwdexpression,omitempty"` + PasswordCredentialIndex int `json:"passwordcredentialindex,omitempty"` + SSOCredentials string `json:"ssocredentials,omitempty"` + UserCredentialIndex int `json:"usercredentialindex,omitempty"` + UserExpression string `json:"userexpression,omitempty"` +} + +type AuthenticationPolicyLabelAuthenticationPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationRADIUSPolicyVPNVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationCertAction struct { + Count float64 `json:"__count,omitempty"` + DefaultAuthenticationGroup string `json:"defaultauthenticationgroup,omitempty"` + GroupNameField string `json:"groupnamefield,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + TwoFactor string `json:"twofactor,omitempty"` + UsernameField string `json:"usernamefield,omitempty"` +} + +type AuthenticationADFSProxyProfile struct { + ADFSTrustStatus string `json:"adfstruststatus,omitempty"` + CertKeyName string `json:"certkeyname,omitempty"` + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Password string `json:"password,omitempty"` + ServerURL string `json:"serverurl,omitempty"` + Username string `json:"username,omitempty"` +} + +type AuthenticationVServerResponderPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type AuthenticationVServerCSPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type AuthenticationPolicyAuthenticationPolicyLabelBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Name string `json:"name,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationOAuthIDPPolicyVPNVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationPolicy struct { + Action string `json:"action,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Description string `json:"description,omitempty"` + Hits int `json:"hits,omitempty"` + LogAction string `json:"logaction,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PolicySubType string `json:"policysubtype,omitempty"` + Rule string `json:"rule,omitempty"` + UndefAction string `json:"undefaction,omitempty"` +} + +type AuthenticationSAMLIDPProfile struct { + Count float64 `json:"__count,omitempty"` + ACSURLRule string `json:"acsurlrule,omitempty"` + AssertionConsumerServiceURL string `json:"assertionconsumerserviceurl,omitempty"` + Attribute1 string `json:"attribute1,omitempty"` + Attribute10 string `json:"attribute10,omitempty"` + Attribute10Expr string `json:"attribute10expr,omitempty"` + Attribute10Format string `json:"attribute10format,omitempty"` + Attribute10FriendlyName string `json:"attribute10friendlyname,omitempty"` + Attribute11 string `json:"attribute11,omitempty"` + Attribute11Expr string `json:"attribute11expr,omitempty"` + Attribute11Format string `json:"attribute11format,omitempty"` + Attribute11FriendlyName string `json:"attribute11friendlyname,omitempty"` + Attribute12 string `json:"attribute12,omitempty"` + Attribute12Expr string `json:"attribute12expr,omitempty"` + Attribute12Format string `json:"attribute12format,omitempty"` + Attribute12FriendlyName string `json:"attribute12friendlyname,omitempty"` + Attribute13 string `json:"attribute13,omitempty"` + Attribute13Expr string `json:"attribute13expr,omitempty"` + Attribute13Format string `json:"attribute13format,omitempty"` + Attribute13FriendlyName string `json:"attribute13friendlyname,omitempty"` + Attribute14 string `json:"attribute14,omitempty"` + Attribute14Expr string `json:"attribute14expr,omitempty"` + Attribute14Format string `json:"attribute14format,omitempty"` + Attribute14FriendlyName string `json:"attribute14friendlyname,omitempty"` + Attribute15 string `json:"attribute15,omitempty"` + Attribute15Expr string `json:"attribute15expr,omitempty"` + Attribute15Format string `json:"attribute15format,omitempty"` + Attribute15FriendlyName string `json:"attribute15friendlyname,omitempty"` + Attribute16 string `json:"attribute16,omitempty"` + Attribute16Expr string `json:"attribute16expr,omitempty"` + Attribute16Format string `json:"attribute16format,omitempty"` + Attribute16FriendlyName string `json:"attribute16friendlyname,omitempty"` + Attribute1Expr string `json:"attribute1expr,omitempty"` + Attribute1Format string `json:"attribute1format,omitempty"` + Attribute1FriendlyName string `json:"attribute1friendlyname,omitempty"` + Attribute2 string `json:"attribute2,omitempty"` + Attribute2Expr string `json:"attribute2expr,omitempty"` + Attribute2Format string `json:"attribute2format,omitempty"` + Attribute2FriendlyName string `json:"attribute2friendlyname,omitempty"` + Attribute3 string `json:"attribute3,omitempty"` + Attribute3Expr string `json:"attribute3expr,omitempty"` + Attribute3Format string `json:"attribute3format,omitempty"` + Attribute3FriendlyName string `json:"attribute3friendlyname,omitempty"` + Attribute4 string `json:"attribute4,omitempty"` + Attribute4Expr string `json:"attribute4expr,omitempty"` + Attribute4Format string `json:"attribute4format,omitempty"` + Attribute4FriendlyName string `json:"attribute4friendlyname,omitempty"` + Attribute5 string `json:"attribute5,omitempty"` + Attribute5Expr string `json:"attribute5expr,omitempty"` + Attribute5Format string `json:"attribute5format,omitempty"` + Attribute5FriendlyName string `json:"attribute5friendlyname,omitempty"` + Attribute6 string `json:"attribute6,omitempty"` + Attribute6Expr string `json:"attribute6expr,omitempty"` + Attribute6Format string `json:"attribute6format,omitempty"` + Attribute6FriendlyName string `json:"attribute6friendlyname,omitempty"` + Attribute7 string `json:"attribute7,omitempty"` + Attribute7Expr string `json:"attribute7expr,omitempty"` + Attribute7Format string `json:"attribute7format,omitempty"` + Attribute7FriendlyName string `json:"attribute7friendlyname,omitempty"` + Attribute8 string `json:"attribute8,omitempty"` + Attribute8Expr string `json:"attribute8expr,omitempty"` + Attribute8Format string `json:"attribute8format,omitempty"` + Attribute8FriendlyName string `json:"attribute8friendlyname,omitempty"` + Attribute9 string `json:"attribute9,omitempty"` + Attribute9Expr string `json:"attribute9expr,omitempty"` + Attribute9Format string `json:"attribute9format,omitempty"` + Attribute9FriendlyName string `json:"attribute9friendlyname,omitempty"` + Audience string `json:"audience,omitempty"` + DefaultAuthenticationGroup string `json:"defaultauthenticationgroup,omitempty"` + DigestMethod string `json:"digestmethod,omitempty"` + EncryptAssertion string `json:"encryptassertion,omitempty"` + EncryptionAlgorithm string `json:"encryptionalgorithm,omitempty"` + KeyTransportAlg string `json:"keytransportalg,omitempty"` + LogoutBinding string `json:"logoutbinding,omitempty"` + MetadataImportStatus string `json:"metadataimportstatus,omitempty"` + MetadataRefreshInterval int `json:"metadatarefreshinterval,omitempty"` + MetadataURL string `json:"metadataurl,omitempty"` + Name string `json:"name,omitempty"` + NameIDExpr string `json:"nameidexpr,omitempty"` + NameIDFormat string `json:"nameidformat,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + RejectUnsignedRequests string `json:"rejectunsignedrequests,omitempty"` + SAMLBinding string `json:"samlbinding,omitempty"` + SAMLIDPCertName string `json:"samlidpcertname,omitempty"` + SAMLIssuerName string `json:"samlissuername,omitempty"` + SAMLSigningCertVersion string `json:"samlsigningcertversion,omitempty"` + SAMLSPCertName string `json:"samlspcertname,omitempty"` + SAMLSPCertVersion string `json:"samlspcertversion,omitempty"` + SendPassword string `json:"sendpassword,omitempty"` + ServiceProviderID string `json:"serviceproviderid,omitempty"` + SignAssertion string `json:"signassertion,omitempty"` + SignatureAlg string `json:"signaturealg,omitempty"` + SignatureService string `json:"signatureservice,omitempty"` + SkewTime int `json:"skewtime,omitempty"` + SPLogoutURL string `json:"splogouturl,omitempty"` +} + +type AuthenticationLDAPPolicyVPNGlobalBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthenticationVServerAuthenticationSmartAccessPolicyBinding struct { + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type AuthenticationCertPolicy struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ReqAction string `json:"reqaction,omitempty"` + Rule string `json:"rule,omitempty"` +} diff --git a/nitrogo/models/authorization.go b/nitrogo/models/authorization.go new file mode 100644 index 0000000..dedf2bc --- /dev/null +++ b/nitrogo/models/authorization.go @@ -0,0 +1,90 @@ +package models + +// authorization configuration structs +type AuthorizationPolicyAuthorizationPolicyLabelBinding struct { + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthorizationPolicyLabelAuthorizationPolicyBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthorizationPolicyCSVServerBinding struct { + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthorizationPolicyBinding struct { + AuthorizationPolicyAAAGroupBinding []any `json:"authorizationpolicy_aaagroup_binding,omitempty"` + AuthorizationPolicyAAAUserBinding []any `json:"authorizationpolicy_aaauser_binding,omitempty"` + AuthorizationPolicyAuthorizationPolicyLabelBinding []any `json:"authorizationpolicy_authorizationpolicylabel_binding,omitempty"` + AuthorizationPolicyCSVServerBinding []any `json:"authorizationpolicy_csvserver_binding,omitempty"` + AuthorizationPolicyLBVServerBinding []any `json:"authorizationpolicy_lbvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type AuthorizationPolicyLBVServerBinding struct { + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthorizationPolicyLabel struct { + Count float64 `json:"__count,omitempty"` + Description string `json:"description,omitempty"` + FlowType int `json:"flowtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Hits int `json:"hits,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthorizationPolicyAAAGroupBinding struct { + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AuthorizationPolicy struct { + Action string `json:"action,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + Count float64 `json:"__count,omitempty"` + ExpressionType string `json:"expressiontype,omitempty"` + Hits int `json:"hits,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule string `json:"rule,omitempty"` +} + +type AuthorizationAction struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type AuthorizationPolicyLabelBinding struct { + AuthorizationPolicyLabelAuthorizationPolicyBinding []any `json:"authorizationpolicylabel_authorizationpolicy_binding,omitempty"` + LabelName string `json:"labelname,omitempty"` +} + +type AuthorizationPolicyAAAUserBinding struct { + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} diff --git a/nitrogo/models/autoscale.go b/nitrogo/models/autoscale.go new file mode 100644 index 0000000..c7eb4a7 --- /dev/null +++ b/nitrogo/models/autoscale.go @@ -0,0 +1,50 @@ +package models + +// autoscale configuration structs +type AutoscaleProfile struct { + APIKey string `json:"apikey,omitempty"` + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + SharedSecret string `json:"sharedsecret,omitempty"` + TypeField string `json:"type,omitempty"` + URL string `json:"url,omitempty"` +} + +type AutoscaleAction struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Parameters string `json:"parameters,omitempty"` + ProfileName string `json:"profilename,omitempty"` + QuietTime int `json:"quiettime,omitempty"` + TypeField string `json:"type,omitempty"` + VMDestroyGracePeriod int `json:"vmdestroygraceperiod,omitempty"` + VServer string `json:"vserver,omitempty"` +} + +type AutoscalePolicyNSTimerBinding struct { + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type AutoscalePolicyBinding struct { + AutoscalePolicyNSTimerBinding []any `json:"autoscalepolicy_nstimer_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type AutoscalePolicy struct { + Action string `json:"action,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Hits int `json:"hits,omitempty"` + LogAction string `json:"logaction,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Priority int `json:"priority,omitempty"` + Rule string `json:"rule,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} diff --git a/nitrogo/models/azure.go b/nitrogo/models/azure.go new file mode 100644 index 0000000..7271614 --- /dev/null +++ b/nitrogo/models/azure.go @@ -0,0 +1,22 @@ +package models + +// azure configuration structs +type AzureKeyVault struct { + AzureApplication string `json:"azureapplication,omitempty"` + AzureVaultName string `json:"azurevaultname,omitempty"` + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + State string `json:"state,omitempty"` +} + +type AzureApplication struct { + ClientID string `json:"clientid,omitempty"` + ClientSecret string `json:"clientsecret,omitempty"` + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + TenantID string `json:"tenantid,omitempty"` + TokenEndpoint string `json:"tokenendpoint,omitempty"` + VaultResource string `json:"vaultresource,omitempty"` +} diff --git a/nitrogo/models/basic.go b/nitrogo/models/basic.go index e0773cf..291b12e 100644 --- a/nitrogo/models/basic.go +++ b/nitrogo/models/basic.go @@ -1,75 +1,552 @@ -// Derived from Citrix ADC Nitro Go SDK (https://github.com/netscaler/adc-nitro-go) -// Originally licensed under the Apache License, Version 2.0 -// Modifications by Adam Crawford, 2025 - package models -type ServiceGroupBinding struct { - ServiceGroupName string `json:"servicegroupname,omitempty"` - ServiceGroupLBMonitorBinding []ServiceGroupLBMonitorBinding `json:"servicegroup_lbmonitor_binding,omitempty"` - ServiceGroupServiceGroupEntityMonBindingsBinding []ServiceGroupServiceGroupEntityMonBindingsBinding `json:"servicegroup_servicegroupentitymonbindings_binding,omitempty"` - ServiceGroupServiceGroupMemberBinding []ServiceGroupServiceGroupMemberBinding `json:"servicegroup_servicegroupmember_binding,omitempty"` +// basic configuration structs +type ServerGSLBServiceGroupBinding struct { + AppFlowLog string `json:"appflowlog,omitempty"` + BoundTD int `json:"boundtd,omitempty"` + CIP string `json:"cip,omitempty"` + CIPHeader string `json:"cipheader,omitempty"` + CltTimeout int `json:"clttimeout,omitempty"` + CustomServerID string `json:"customserverid,omitempty"` + DownStateFlush string `json:"downstateflush,omitempty"` + DupPort int `json:"dup_port,omitempty"` + DupSvcType string `json:"dup_svctype,omitempty"` + MaxBandwidth int `json:"maxbandwidth,omitempty"` + MaxClient int `json:"maxclient,omitempty"` + MaxReq int `json:"maxreq,omitempty"` + MonThreshold int `json:"monthreshold,omitempty"` + Name string `json:"name,omitempty"` + Port int `json:"port,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` + ServiceIPAddress string `json:"serviceipaddress,omitempty"` + ServiceIPStr string `json:"serviceipstr,omitempty"` + SvcType string `json:"svctype,omitempty"` + SvrCfgFlags int `json:"svrcfgflags,omitempty"` + SvrState string `json:"svrstate,omitempty"` + SvrTimeout int `json:"svrtimeout,omitempty"` +} + +type ServerServiceBinding struct { + Name string `json:"name,omitempty"` + Port int `json:"port,omitempty"` + ServiceIPAddress string `json:"serviceipaddress,omitempty"` + ServiceIPStr string `json:"serviceipstr,omitempty"` + ServiceName string `json:"servicename,omitempty"` + SvcType string `json:"svctype,omitempty"` + SvrState string `json:"svrstate,omitempty"` +} + +type ServiceGroupBindings struct { + Count float64 `json:"__count,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Port int `json:"port,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` + State string `json:"state,omitempty"` + SvrState string `json:"svrstate,omitempty"` + VServerName string `json:"vservername,omitempty"` +} + +type LocationParameter struct { + Builtin []string `json:"builtin,omitempty"` + Context string `json:"context,omitempty"` + Custom int `json:"custom,omitempty"` + Custom6 int `json:"custom6,omitempty"` + DatabaseMode string `json:"databasemode,omitempty"` + Entries int `json:"entries,omitempty"` + Entries6 int `json:"entries6,omitempty"` + Errors int `json:"errors,omitempty"` + Errors6 int `json:"errors6,omitempty"` + Feature string `json:"feature,omitempty"` + Flags int `json:"flags,omitempty"` + Flushing string `json:"flushing,omitempty"` + Format string `json:"format,omitempty"` + Format6 string `json:"format6,omitempty"` + Lines int `json:"lines,omitempty"` + Lines6 int `json:"lines6,omitempty"` + Loading string `json:"loading,omitempty"` + LocationFile string `json:"Locationfile,omitempty"` + LocationFile6 string `json:"locationfile6,omitempty"` + MatchWildcardToAny string `json:"matchwildcardtoany,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Q1Label string `json:"q1label,omitempty"` + Q2Label string `json:"q2label,omitempty"` + Q3Label string `json:"q3label,omitempty"` + Q4Label string `json:"q4label,omitempty"` + Q5Label string `json:"q5label,omitempty"` + Q6Label string `json:"q6label,omitempty"` + Static int `json:"Static,omitempty"` + Static6 int `json:"static6,omitempty"` + Status int `json:"status,omitempty"` + Warnings int `json:"warnings,omitempty"` + Warnings6 int `json:"warnings6,omitempty"` +} + +type LocationData struct { } type ServiceGroupServiceGroupEntityMonBindingsBinding struct { - CustomServerid string `json:"customserverid,omitempty"` - Dbsttl int `json:"dbsttl,omitempty"` - Hashid int `json:"hashid,omitempty"` + CustomServerID string `json:"customserverid,omitempty"` + DBSTTL int `json:"dbsttl,omitempty"` + HashID int `json:"hashid,omitempty"` LastResponse string `json:"lastresponse,omitempty"` MonitorName string `json:"monitor_name,omitempty"` - MonitorCurrentFailedProbes string `json:"monitorcurrentfailedprobes,omitempty"` MonitorState string `json:"monitor_state,omitempty"` - MonitorTotalFailedProbes string `json:"monitortotalfailedprobes,omitempty"` - MonitorTotalProbes string `json:"monitortotalprobes,omitempty"` + MonitorCurrentFailedProbes int `json:"monitorcurrentfailedprobes,omitempty"` + MonitorTotalFailedProbes int `json:"monitortotalfailedprobes,omitempty"` + MonitorTotalProbes int `json:"monitortotalprobes,omitempty"` NameServer string `json:"nameserver,omitempty"` Order int `json:"order,omitempty"` Passive bool `json:"passive,omitempty"` Port int `json:"port,omitempty"` - ResponseTime string `json:"responsetime,omitempty"` - Serverid int `json:"serverid,omitempty"` + ResponseTime int `json:"responsetime,omitempty"` + ServerID int `json:"serverid,omitempty"` ServiceGroupEntName2 string `json:"servicegroupentname2,omitempty"` ServiceGroupName string `json:"servicegroupname,omitempty"` State string `json:"state,omitempty"` Weight int `json:"weight,omitempty"` } +type ServiceGroupBinding struct { + ServiceGroupLBMonitorBinding []any `json:"servicegroup_lbmonitor_binding,omitempty"` + ServiceGroupServiceGroupEntityMonBindingsBinding []any `json:"servicegroup_servicegroupentitymonbindings_binding,omitempty"` + ServiceGroupServiceGroupMemberBinding []any `json:"servicegroup_servicegroupmember_binding,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` +} + +type ServiceGroupLBMonitorBinding struct { + CustomServerID string `json:"customserverid,omitempty"` + DBSTTL int `json:"dbsttl,omitempty"` + HashID int `json:"hashid,omitempty"` + MonitorName string `json:"monitor_name,omitempty"` + MonState string `json:"monstate,omitempty"` + MonWeight int `json:"monweight,omitempty"` + NameServer string `json:"nameserver,omitempty"` + Order int `json:"order,omitempty"` + Passive bool `json:"passive,omitempty"` + Port int `json:"port,omitempty"` + ServerID int `json:"serverid,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` + State string `json:"state,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type ServiceBinding struct { + Name string `json:"name,omitempty"` + ServiceLBMonitorBinding []any `json:"service_lbmonitor_binding,omitempty"` +} + +type RADIUSNode struct { + Count float64 `json:"__count,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodePrefix string `json:"nodeprefix,omitempty"` + RADKey string `json:"radkey,omitempty"` +} + +type SVCBindings struct { + Count float64 `json:"__count,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Port int `json:"port,omitempty"` + ServiceName string `json:"servicename,omitempty"` + SvrState string `json:"svrstate,omitempty"` + VServerName string `json:"vservername,omitempty"` +} + type ServiceGroupServiceGroupMemberBinding struct { - CustomServerid string `json:"customserverid,omitempty"` - Dbsttl int `json:"dbsttl,omitempty"` + CustomServerID string `json:"customserverid,omitempty"` + DBSTTL int `json:"dbsttl,omitempty"` Delay int `json:"delay,omitempty"` Graceful string `json:"graceful,omitempty"` - Hashid string `json:"hashid,omitempty"` + HashID int `json:"hashid,omitempty"` IP string `json:"ip,omitempty"` NameServer string `json:"nameserver,omitempty"` Order int `json:"order,omitempty"` OrderStr string `json:"orderstr,omitempty"` Port int `json:"port,omitempty"` - Serverid string `json:"serverid,omitempty"` + ServerID int `json:"serverid,omitempty"` ServerName string `json:"servername,omitempty"` ServiceGroupName string `json:"servicegroupname,omitempty"` State string `json:"state,omitempty"` StateChangeTimeSec string `json:"statechangetimesec,omitempty"` - SvcitmPriority int `json:"svcitmpriority,omitempty"` + SvcItmPriority int `json:"svcitmpriority,omitempty"` SvrState string `json:"svrstate,omitempty"` - TicksSinceLastStateChange string `json:"tickssincelaststatechange,omitempty"` - TROFSDelay string `json:"trofsdelay,omitempty"` + TicksSinceLastStateChange int `json:"tickssincelaststatechange,omitempty"` + TROFSDelay int `json:"trofsdelay,omitempty"` TROFSReason string `json:"trofsreason,omitempty"` - Weight string `json:"weight,omitempty"` + Weight int `json:"weight,omitempty"` } -type ServiceGroupLBMonitorBinding struct { - CustomServerid string `json:"customserverid,omitempty"` - Dbsttl int `json:"dbsttl,omitempty"` - Hashid int `json:"hashid,omitempty"` - MonitorName string `json:"monitor_name,omitempty"` - MonState string `json:"monstate,omitempty"` - MonWeight string `json:"monweight,omitempty"` - NameServer string `json:"nameserver,omitempty"` - Order int `json:"order,omitempty"` - Passive bool `json:"passive,omitempty"` +type VServer struct { + BackupVServer string `json:"backupvserver,omitempty"` + Cacheable string `json:"cacheable,omitempty"` + CltTimeout int `json:"clttimeout,omitempty"` + Name string `json:"name,omitempty"` + PushVServer string `json:"pushvserver,omitempty"` + RedirectURL string `json:"redirecturl,omitempty"` + SOMethod string `json:"somethod,omitempty"` + SOPersistence string `json:"sopersistence,omitempty"` + SOPersistenceTimeout int `json:"sopersistencetimeout,omitempty"` + SOThreshold int `json:"sothreshold,omitempty"` +} + +type NSTrace struct { + CapDropPkt string `json:"capdroppkt,omitempty"` + CapSSLKeys string `json:"capsslkeys,omitempty"` + DoRuntimeCleanup string `json:"doruntimecleanup,omitempty"` + FileID string `json:"fileid,omitempty"` + FileName string `json:"filename,omitempty"` + FileSize int `json:"filesize,omitempty"` + Filter string `json:"filter,omitempty"` + InMemoryTrace string `json:"inmemorytrace,omitempty"` + Link string `json:"link,omitempty"` + Merge string `json:"merge,omitempty"` + Mode []string `json:"mode,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NF int `json:"nf,omitempty"` + NodeID int `json:"nodeid,omitempty"` + Nodes []any `json:"nodes,omitempty"` + PerNIC string `json:"pernic,omitempty"` + Scope string `json:"scope,omitempty"` + Size int `json:"size,omitempty"` + SkipLocalSSH string `json:"skiplocalssh,omitempty"` + SkipRPC string `json:"skiprpc,omitempty"` + State string `json:"state,omitempty"` + Time int `json:"time,omitempty"` + TraceBuffers int `json:"tracebuffers,omitempty"` + TraceFormat string `json:"traceformat,omitempty"` + TraceLocation string `json:"tracelocation,omitempty"` +} + +type LocationFile struct { + CurLocFileStatus string `json:"curlocfilestatus,omitempty"` + Format string `json:"format,omitempty"` + LocationFile string `json:"Locationfile,omitempty"` + LocFileStatusStr string `json:"locfilestatusstr,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PrevLocationFile string `json:"prevlocationfile,omitempty"` + PrevLocFileFormat string `json:"prevlocfileformat,omitempty"` + PrevLocFileStatus string `json:"prevlocfilestatus,omitempty"` + Src string `json:"src,omitempty"` +} + +type ServerGSLBServiceBinding struct { + Name string `json:"name,omitempty"` Port int `json:"port,omitempty"` - Serverid int `json:"serverid,omitempty"` + ServiceIPAddress string `json:"serviceipaddress,omitempty"` + ServiceIPStr string `json:"serviceipstr,omitempty"` + ServiceName string `json:"servicename,omitempty"` + SvcType string `json:"svctype,omitempty"` + SvrState string `json:"svrstate,omitempty"` +} + +type ExtendedMemoryParam struct { + MaxMemLimit int `json:"maxmemlimit,omitempty"` + MemLimit int `json:"memlimit,omitempty"` + MemLimitActive int `json:"memlimitactive,omitempty"` + MinRequiredMemory int `json:"minrequiredmemory,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type Service struct { + AccessDown string `json:"accessdown,omitempty"` + All bool `json:"all,omitempty"` + AppFlowLog string `json:"appflowlog,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Cacheable string `json:"cacheable,omitempty"` + CacheType string `json:"cachetype,omitempty"` + CIP string `json:"cip,omitempty"` + CIPHeader string `json:"cipheader,omitempty"` + CKA string `json:"cka,omitempty"` + ClearTextPort int `json:"cleartextport,omitempty"` + ClMonOwner int `json:"clmonowner,omitempty"` + ClMonView int `json:"clmonview,omitempty"` + CltTimeout int `json:"clttimeout,omitempty"` + CMP string `json:"cmp,omitempty"` + Comment string `json:"comment,omitempty"` + ContentInspectionProfileName string `json:"contentinspectionprofilename,omitempty"` + Count float64 `json:"__count,omitempty"` + CustomServerID string `json:"customserverid,omitempty"` + Delay int `json:"delay,omitempty"` + DNSProfileName string `json:"dnsprofilename,omitempty"` + DownStateFlush string `json:"downstateflush,omitempty"` + DupState string `json:"dup_state,omitempty"` + Feature string `json:"feature,omitempty"` + Graceful string `json:"graceful,omitempty"` + GSLB string `json:"gslb,omitempty"` + HashID int `json:"hashid,omitempty"` + HealthMonitor string `json:"healthmonitor,omitempty"` + HTTPProfileName string `json:"httpprofilename,omitempty"` + Internal bool `json:"Internal,omitempty"` + IP string `json:"ip,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + LastResponse string `json:"lastresponse,omitempty"` + MaxBandwidth int `json:"maxbandwidth,omitempty"` + MaxClient int `json:"maxclient,omitempty"` + MaxReq int `json:"maxreq,omitempty"` + MonConnectionClose string `json:"monconnectionclose,omitempty"` + MonitorNameSvc string `json:"monitor_name_svc,omitempty"` + MonitorState string `json:"monitor_state,omitempty"` + MonStatCode int `json:"monstatcode,omitempty"` + MonStatParam1 int `json:"monstatparam1,omitempty"` + MonStatParam2 int `json:"monstatparam2,omitempty"` + MonStatParam3 int `json:"monstatparam3,omitempty"` + MonThreshold int `json:"monthreshold,omitempty"` + MonUserStatusMesg string `json:"monuserstatusmesg,omitempty"` + Name string `json:"name,omitempty"` + NetProfile string `json:"netprofile,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NoDefaultBindings string `json:"nodefaultbindings,omitempty"` + NumOfConnections int `json:"numofconnections,omitempty"` + OracleServerVersion string `json:"oracleserverversion,omitempty"` + PathMonitor string `json:"pathmonitor,omitempty"` + PathMonitorIndv string `json:"pathmonitorindv,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Port int `json:"port,omitempty"` + ProcessLocal string `json:"processlocal,omitempty"` + PublicIP string `json:"publicip,omitempty"` + PublicPort int `json:"publicport,omitempty"` + QUICProfileName string `json:"quicprofilename,omitempty"` + ResponseTime int `json:"responsetime,omitempty"` + RTSPSessionIDRemap string `json:"rtspsessionidremap,omitempty"` + ServerID int `json:"serverid,omitempty"` + ServerName string `json:"servername,omitempty"` + ServiceConfType bool `json:"serviceconftype,omitempty"` + ServiceConfType2 string `json:"serviceconftype2,omitempty"` + ServiceIPStr string `json:"serviceipstr,omitempty"` + ServiceType string `json:"servicetype,omitempty"` + SP string `json:"sp,omitempty"` + State string `json:"state,omitempty"` + StateChangeTimeMsec int `json:"statechangetimemsec,omitempty"` + StateChangeTimeSec string `json:"statechangetimesec,omitempty"` + StateUpdateReason int `json:"stateupdatereason,omitempty"` + SvrState string `json:"svrstate,omitempty"` + SvrTimeout int `json:"svrtimeout,omitempty"` + TCPB string `json:"tcpb,omitempty"` + TCPProfileName string `json:"tcpprofilename,omitempty"` + TD int `json:"td,omitempty"` + TicksSinceLastStateChange int `json:"tickssincelaststatechange,omitempty"` + UseProxyPort string `json:"useproxyport,omitempty"` + USIP string `json:"usip,omitempty"` + Value string `json:"value,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type ServerServiceGroupBinding struct { + AppFlowLog string `json:"appflowlog,omitempty"` + BoundTD int `json:"boundtd,omitempty"` + Cacheable string `json:"cacheable,omitempty"` + CIP string `json:"cip,omitempty"` + CIPHeader string `json:"cipheader,omitempty"` + CKA string `json:"cka,omitempty"` + CltTimeout int `json:"clttimeout,omitempty"` + CMP string `json:"cmp,omitempty"` + CustomServerID string `json:"customserverid,omitempty"` + DownStateFlush string `json:"downstateflush,omitempty"` + DupPort int `json:"dup_port,omitempty"` + DupSvcType string `json:"dup_svctype,omitempty"` + MaxBandwidth int `json:"maxbandwidth,omitempty"` + MaxClient int `json:"maxclient,omitempty"` + MaxReq int `json:"maxreq,omitempty"` + MonThreshold int `json:"monthreshold,omitempty"` + Name string `json:"name,omitempty"` + Port int `json:"port,omitempty"` + ServiceGroupEntName2 string `json:"servicegroupentname2,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` + ServiceIPAddress string `json:"serviceipaddress,omitempty"` + ServiceIPStr string `json:"serviceipstr,omitempty"` + SP string `json:"sp,omitempty"` + SvcItmActSvcs int `json:"svcitmactsvcs,omitempty"` + SvcItmBoundSvcs int `json:"svcitmboundsvcs,omitempty"` + SvcItmPriority int `json:"svcitmpriority,omitempty"` + SvcType string `json:"svctype,omitempty"` + SvrCfgFlags int `json:"svrcfgflags,omitempty"` + SvrState string `json:"svrstate,omitempty"` + SvrTimeout int `json:"svrtimeout,omitempty"` + TCPB string `json:"tcpb,omitempty"` + USIP string `json:"usip,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type DBSMonitors struct { +} + +type LocationFile6 struct { + Count float64 `json:"__count,omitempty"` + CurLocFileStatus string `json:"curlocfilestatus,omitempty"` + Format string `json:"format,omitempty"` + LocationFile string `json:"Locationfile,omitempty"` + LocFileStatusStr string `json:"locfilestatusstr,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PrevLocationFile string `json:"prevlocationfile,omitempty"` + PrevLocFileFormat string `json:"prevlocfileformat,omitempty"` + PrevLocFileStatus string `json:"prevlocfilestatus,omitempty"` + Src string `json:"src,omitempty"` +} + +type ServiceGroup struct { + AppFlowLog string `json:"appflowlog,omitempty"` + AutoDelayedTROFS string `json:"autodelayedtrofs,omitempty"` + AutoDisableDelay int `json:"autodisabledelay,omitempty"` + AutoDisableGraceful string `json:"autodisablegraceful,omitempty"` + AutoScale string `json:"autoscale,omitempty"` + Bootstrap string `json:"bootstrap,omitempty"` + Cacheable string `json:"cacheable,omitempty"` + CacheType string `json:"cachetype,omitempty"` + CIP string `json:"cip,omitempty"` + CIPHeader string `json:"cipheader,omitempty"` + CKA string `json:"cka,omitempty"` + ClMonOwner int `json:"clmonowner,omitempty"` + ClMonView int `json:"clmonview,omitempty"` + CltTimeout int `json:"clttimeout,omitempty"` + CMP string `json:"cmp,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + CustomServerID string `json:"customserverid,omitempty"` + DBSTTL int `json:"dbsttl,omitempty"` + Delay int `json:"delay,omitempty"` + DownStateFlush string `json:"downstateflush,omitempty"` + DupWeight int `json:"dup_weight,omitempty"` + Graceful string `json:"graceful,omitempty"` + GroupCount int `json:"groupcount,omitempty"` + HashID int `json:"hashid,omitempty"` + HealthMonitor string `json:"healthmonitor,omitempty"` + HTTPProfileName string `json:"httpprofilename,omitempty"` + IncludeMembers bool `json:"includemembers,omitempty"` + IP string `json:"ip,omitempty"` + MaxBandwidth int `json:"maxbandwidth,omitempty"` + MaxClient int `json:"maxclient,omitempty"` + MaxReq int `json:"maxreq,omitempty"` + MemberPort int `json:"memberport,omitempty"` + MonConnectionClose string `json:"monconnectionclose,omitempty"` + MonitorNameSvc string `json:"monitor_name_svc,omitempty"` + MonStatCode int `json:"monstatcode,omitempty"` + MonStatParam1 int `json:"monstatparam1,omitempty"` + MonStatParam2 int `json:"monstatparam2,omitempty"` + MonStatParam3 int `json:"monstatparam3,omitempty"` + MonThreshold int `json:"monthreshold,omitempty"` + MonUserStatusMesg string `json:"monuserstatusmesg,omitempty"` + NameServer string `json:"nameserver,omitempty"` + NetProfile string `json:"netprofile,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NoDefaultBindings string `json:"nodefaultbindings,omitempty"` + NumOfConnections int `json:"numofconnections,omitempty"` + Order int `json:"order,omitempty"` + PathMonitor string `json:"pathmonitor,omitempty"` + PathMonitorIndv string `json:"pathmonitorindv,omitempty"` + Port int `json:"port,omitempty"` + QUICProfileName string `json:"quicprofilename,omitempty"` + RTSPSessionIDRemap string `json:"rtspsessionidremap,omitempty"` + ServerID int `json:"serverid,omitempty"` + ServerName string `json:"servername,omitempty"` + ServiceConfType bool `json:"serviceconftype,omitempty"` + ServiceGroupEffectiveState string `json:"servicegroupeffectivestate,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` + ServiceIPStr string `json:"serviceipstr,omitempty"` + ServiceType string `json:"servicetype,omitempty"` + SP string `json:"sp,omitempty"` + State string `json:"state,omitempty"` + StateChangeTimeMsec int `json:"statechangetimemsec,omitempty"` + StateUpdateReason int `json:"stateupdatereason,omitempty"` + SvcItmActSvcs int `json:"svcitmactsvcs,omitempty"` + SvcItmBoundSvcs int `json:"svcitmboundsvcs,omitempty"` + SvrState string `json:"svrstate,omitempty"` + SvrTimeout int `json:"svrtimeout,omitempty"` + TCPB string `json:"tcpb,omitempty"` + TCPProfileName string `json:"tcpprofilename,omitempty"` + TD int `json:"td,omitempty"` + TopicName string `json:"topicname,omitempty"` + UseProxyPort string `json:"useproxyport,omitempty"` + USIP string `json:"usip,omitempty"` + Value string `json:"value,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type ServerBinding struct { + Name string `json:"name,omitempty"` + ServerGSLBServiceBinding []any `json:"server_gslbservice_binding,omitempty"` + ServerGSLBServiceGroupBinding []any `json:"server_gslbservicegroup_binding,omitempty"` + ServerServiceBinding []any `json:"server_service_binding,omitempty"` + ServerServiceGroupBinding []any `json:"server_servicegroup_binding,omitempty"` +} + +type ServiceLBMonitorBinding struct { + DupState string `json:"dup_state,omitempty"` + DupWeight int `json:"dup_weight,omitempty"` + FailedProbes int `json:"failedprobes,omitempty"` + LastResponse string `json:"lastresponse,omitempty"` + MonitorName string `json:"monitor_name,omitempty"` + MonitorState string `json:"monitor_state,omitempty"` + MonitorCurrentFailedProbes int `json:"monitorcurrentfailedprobes,omitempty"` + MonitorTotalFailedProbes int `json:"monitortotalfailedprobes,omitempty"` + MonitorTotalProbes int `json:"monitortotalprobes,omitempty"` + MonStatCode int `json:"monstatcode,omitempty"` + MonState string `json:"monstate,omitempty"` + MonStatParam1 int `json:"monstatparam1,omitempty"` + MonStatParam2 int `json:"monstatparam2,omitempty"` + MonStatParam3 int `json:"monstatparam3,omitempty"` + Name string `json:"name,omitempty"` + Passive bool `json:"passive,omitempty"` + ResponseTime int `json:"responsetime,omitempty"` + TotalFailedProbes int `json:"totalfailedprobes,omitempty"` + TotalProbes int `json:"totalprobes,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type ServiceGroupServiceGroupMemberListBinding struct { + FailedMembers []any `json:"failedmembers,omitempty"` + Members []any `json:"members,omitempty"` ServiceGroupName string `json:"servicegroupname,omitempty"` - State string `json:"state,omitempty"` - Weight string `json:"weight,omitempty"` +} + +type Server struct { + AutoScale string `json:"autoscale,omitempty"` + Cacheable string `json:"cacheable,omitempty"` + CKA string `json:"cka,omitempty"` + CMP string `json:"cmp,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Delay int `json:"delay,omitempty"` + Domain string `json:"domain,omitempty"` + DomainResolveNow bool `json:"domainresolvenow,omitempty"` + DomainResolveRetry int `json:"domainresolveretry,omitempty"` + Graceful string `json:"graceful,omitempty"` + Internal bool `json:"Internal,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + IPv6Address string `json:"ipv6address,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + QueryType string `json:"querytype,omitempty"` + SP string `json:"sp,omitempty"` + State string `json:"state,omitempty"` + StateChangeTimeSec string `json:"statechangetimesec,omitempty"` + TCPB string `json:"tcpb,omitempty"` + TD int `json:"td,omitempty"` + TicksSinceLastStateChange int `json:"tickssincelaststatechange,omitempty"` + TranslationIP string `json:"translationip,omitempty"` + TranslationMask string `json:"translationmask,omitempty"` + USIP string `json:"usip,omitempty"` +} + +type Location struct { + Count float64 `json:"__count,omitempty"` + IPFrom string `json:"ipfrom,omitempty"` + IPTo string `json:"ipto,omitempty"` + Latitude int `json:"latitude,omitempty"` + Longitude int `json:"longitude,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PreferredLocation string `json:"preferredlocation,omitempty"` + Q1Label string `json:"q1label,omitempty"` + Q2Label string `json:"q2label,omitempty"` + Q3Label string `json:"q3label,omitempty"` + Q4Label string `json:"q4label,omitempty"` + Q5Label string `json:"q5label,omitempty"` + Q6Label string `json:"q6label,omitempty"` +} + +type Reporting struct { + State string `json:"state,omitempty"` } diff --git a/nitrogo/models/bfd.go b/nitrogo/models/bfd.go new file mode 100644 index 0000000..38f7f5b --- /dev/null +++ b/nitrogo/models/bfd.go @@ -0,0 +1,28 @@ +package models + +// bfd configuration structs +type BFDSession struct { + AdminDown bool `json:"admindown,omitempty"` + Count float64 `json:"__count,omitempty"` + CurrentOwnerPE int `json:"currentownerpe,omitempty"` + LocalDiagnotic int `json:"localdiagnotic,omitempty"` + LocalDiscriminator int `json:"localdiscriminator,omitempty"` + LocalIP string `json:"localip,omitempty"` + LocalPort int `json:"localport,omitempty"` + MinimumReceiveInterval int `json:"minimumreceiveinterval,omitempty"` + MinimumTransmitInterval int `json:"minimumtransmitinterval,omitempty"` + MultiHop bool `json:"multihop,omitempty"` + Multiplier int `json:"multiplier,omitempty"` + NegotiatedMinimumReceiveInterval int `json:"negotiatedminimumreceiveinterval,omitempty"` + NegotiatedMinimumTransmitInterval int `json:"negotiatedminimumtransmitinterval,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OriginalOwnerPE int `json:"originalownerpe,omitempty"` + OwnerNode int `json:"ownernode,omitempty"` + Passive bool `json:"passive,omitempty"` + RemoteDiscriminator int `json:"remotediscriminator,omitempty"` + RemoteIP string `json:"remoteip,omitempty"` + RemoteMultiplier int `json:"remotemultiplier,omitempty"` + RemotePort int `json:"remoteport,omitempty"` + State string `json:"state,omitempty"` + VLAN int `json:"vlan,omitempty"` +} diff --git a/nitrogo/models/bot.go b/nitrogo/models/bot.go new file mode 100644 index 0000000..d4ac51f --- /dev/null +++ b/nitrogo/models/bot.go @@ -0,0 +1,302 @@ +package models + +// bot configuration structs +type BotProfile struct { + AddCookieFlags string `json:"addcookieflags,omitempty"` + BotEnableBlackList string `json:"bot_enable_black_list,omitempty"` + BotEnableIPReputation string `json:"bot_enable_ip_reputation,omitempty"` + BotEnableRateLimit string `json:"bot_enable_rate_limit,omitempty"` + BotEnableTPS string `json:"bot_enable_tps,omitempty"` + BotEnableWhiteList string `json:"bot_enable_white_list,omitempty"` + Builtin []string `json:"builtin,omitempty"` + ClientIPExpression string `json:"clientipexpression,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + DeviceFingerprint string `json:"devicefingerprint,omitempty"` + DeviceFingerprintAction []string `json:"devicefingerprintaction,omitempty"` + DeviceFingerprintMobile []string `json:"devicefingerprintmobile,omitempty"` + DFPRequestLimit int `json:"dfprequestlimit,omitempty"` + ErrorURL string `json:"errorurl,omitempty"` + Feature string `json:"feature,omitempty"` + HeadlessBrowserDetection string `json:"headlessbrowserdetection,omitempty"` + KMDetection string `json:"kmdetection,omitempty"` + KMEventsPostBodyLimit int `json:"kmeventspostbodylimit,omitempty"` + KMJavascriptName string `json:"kmjavascriptname,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + SessionCookieName string `json:"sessioncookiename,omitempty"` + SessionTimeout int `json:"sessiontimeout,omitempty"` + Signature string `json:"signature,omitempty"` + SignatureMultipleUserAgentHeaderAction []string `json:"signaturemultipleuseragentheaderaction,omitempty"` + SignatureNoUserAgentHeaderAction []string `json:"signaturenouseragentheaderaction,omitempty"` + SpoofedReqAction []string `json:"spoofedreqaction,omitempty"` + Trap string `json:"trap,omitempty"` + TrapAction []string `json:"trapaction,omitempty"` + TrapURL string `json:"trapurl,omitempty"` + VerboseLogLevel string `json:"verboseloglevel,omitempty"` +} + +type BotPolicyCSVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type BotProfileKMDetectionExprBinding struct { + BotBindComment string `json:"bot_bind_comment,omitempty"` + BotKMDetectionEnabled string `json:"bot_km_detection_enabled,omitempty"` + BotKMExpressionName string `json:"bot_km_expression_name,omitempty"` + BotKMExpressionValue string `json:"bot_km_expression_value,omitempty"` + KMDetectionExpr bool `json:"kmdetectionexpr,omitempty"` + LogMessage string `json:"logmessage,omitempty"` + Name string `json:"name,omitempty"` +} + +type BotProfileIPReputationBinding struct { + BotBindComment string `json:"bot_bind_comment,omitempty"` + BotIPRepAction []string `json:"bot_iprep_action,omitempty"` + BotIPRepEnabled string `json:"bot_iprep_enabled,omitempty"` + BotIPReputation bool `json:"bot_ipreputation,omitempty"` + Category string `json:"category,omitempty"` + LogMessage string `json:"logmessage,omitempty"` + Name string `json:"name,omitempty"` +} + +type BotSignature struct { + Comment string `json:"comment,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Overwrite bool `json:"overwrite,omitempty"` + Response string `json:"response,omitempty"` + Src string `json:"src,omitempty"` +} + +type BotPolicyLBVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type BotSettings struct { + Builtin []string `json:"builtin,omitempty"` + DefaultNonIntrusiveProfile string `json:"defaultnonintrusiveprofile,omitempty"` + DefaultProfile string `json:"defaultprofile,omitempty"` + DFPRequestLimit int `json:"dfprequestlimit,omitempty"` + Feature string `json:"feature,omitempty"` + JavascriptName string `json:"javascriptname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ProxyPassword string `json:"proxypassword,omitempty"` + ProxyPort int `json:"proxyport,omitempty"` + ProxyServer string `json:"proxyserver,omitempty"` + ProxyUsername string `json:"proxyusername,omitempty"` + SessionCookieName string `json:"sessioncookiename,omitempty"` + SessionTimeout int `json:"sessiontimeout,omitempty"` + SignatureAutoUpdate string `json:"signatureautoupdate,omitempty"` + SignatureURL string `json:"signatureurl,omitempty"` + TrapURLAutoGenerate string `json:"trapurlautogenerate,omitempty"` + TrapURLInterval int `json:"trapurlinterval,omitempty"` + TrapURLLength int `json:"trapurllength,omitempty"` +} + +type BotPolicyLabelBinding struct { + BotPolicyLabelBotPolicyBinding []any `json:"botpolicylabel_botpolicy_binding,omitempty"` + BotPolicyLabelPolicyBindingBinding []any `json:"botpolicylabel_policybinding_binding,omitempty"` + LabelName string `json:"labelname,omitempty"` +} + +type BotGlobalBotPolicyBinding struct { + FlowType int `json:"flowtype,omitempty"` + GlobalBindType string `json:"globalbindtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type BotPolicyBinding struct { + BotPolicyBotGlobalBinding []any `json:"botpolicy_botglobal_binding,omitempty"` + BotPolicyBotPolicyLabelBinding []any `json:"botpolicy_botpolicylabel_binding,omitempty"` + BotPolicyCSVServerBinding []any `json:"botpolicy_csvserver_binding,omitempty"` + BotPolicyLBVServerBinding []any `json:"botpolicy_lbvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type BotProfileTrapInsertionURLBinding struct { + BotBindComment string `json:"bot_bind_comment,omitempty"` + BotTrapURL string `json:"bot_trap_url,omitempty"` + BotTrapURLInsertionEnabled string `json:"bot_trap_url_insertion_enabled,omitempty"` + LogMessage string `json:"logmessage,omitempty"` + Name string `json:"name,omitempty"` + TrapInsertionURL bool `json:"trapinsertionurl,omitempty"` +} + +type BotProfileBinding struct { + BotProfileBlacklistBinding []any `json:"botprofile_blacklist_binding,omitempty"` + BotProfileCaptchaBinding []any `json:"botprofile_captcha_binding,omitempty"` + BotProfileIPReputationBinding []any `json:"botprofile_ipreputation_binding,omitempty"` + BotProfileKMDetectionExprBinding []any `json:"botprofile_kmdetectionexpr_binding,omitempty"` + BotProfileLogExpressionBinding []any `json:"botprofile_logexpression_binding,omitempty"` + BotProfileRateLimitBinding []any `json:"botprofile_ratelimit_binding,omitempty"` + BotProfileTPSBinding []any `json:"botprofile_tps_binding,omitempty"` + BotProfileTrapInsertionURLBinding []any `json:"botprofile_trapinsertionurl_binding,omitempty"` + BotProfileWhitelistBinding []any `json:"botprofile_whitelist_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type BotPolicy struct { + Builtin []string `json:"builtin,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + LogAction string `json:"logaction,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ProfileName string `json:"profilename,omitempty"` + Rule string `json:"rule,omitempty"` + UndefAction string `json:"undefaction,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type BotPolicyLabelBotPolicyBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type BotProfileWhitelistBinding struct { + BotBindComment string `json:"bot_bind_comment,omitempty"` + BotWhitelist bool `json:"bot_whitelist,omitempty"` + BotWhitelistEnabled string `json:"bot_whitelist_enabled,omitempty"` + BotWhitelistType string `json:"bot_whitelist_type,omitempty"` + BotWhitelistValue string `json:"bot_whitelist_value,omitempty"` + Log string `json:"log,omitempty"` + LogMessage string `json:"logmessage,omitempty"` + Name string `json:"name,omitempty"` +} + +type BotGlobalBinding struct { + BotGlobalBotPolicyBinding []any `json:"botglobal_botpolicy_binding,omitempty"` +} + +type BotProfileLogExpressionBinding struct { + BotBindComment string `json:"bot_bind_comment,omitempty"` + BotLogExpressionEnabled string `json:"bot_log_expression_enabled,omitempty"` + BotLogExpressionName string `json:"bot_log_expression_name,omitempty"` + BotLogExpressionValue string `json:"bot_log_expression_value,omitempty"` + LogExpression bool `json:"logexpression,omitempty"` + LogMessage string `json:"logmessage,omitempty"` + Name string `json:"name,omitempty"` +} + +type BotPolicyLabel struct { + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Hits int `json:"hits,omitempty"` + LabelName string `json:"labelname,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NumPol int `json:"numpol,omitempty"` +} + +type BotProfileCaptchaBinding struct { + BotBindComment string `json:"bot_bind_comment,omitempty"` + BotCaptchaAction []string `json:"bot_captcha_action,omitempty"` + BotCaptchaEnabled string `json:"bot_captcha_enabled,omitempty"` + BotCaptchaURL string `json:"bot_captcha_url,omitempty"` + CaptchaResource bool `json:"captcharesource,omitempty"` + GracePeriod int `json:"graceperiod,omitempty"` + LogMessage string `json:"logmessage,omitempty"` + MutePeriod int `json:"muteperiod,omitempty"` + Name string `json:"name,omitempty"` + RequestSizeLimit int `json:"requestsizelimit,omitempty"` + RetryAttempts int `json:"retryattempts,omitempty"` + WaitTime int `json:"waittime,omitempty"` +} + +type BotPolicyBotGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type BotPolicyBotPolicyLabelBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type BotPolicyLabelPolicyBindingBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type BotProfileTPSBinding struct { + BotBindComment string `json:"bot_bind_comment,omitempty"` + BotTPS bool `json:"bot_tps,omitempty"` + BotTPSAction []string `json:"bot_tps_action,omitempty"` + BotTPSEnabled string `json:"bot_tps_enabled,omitempty"` + BotTPSType string `json:"bot_tps_type,omitempty"` + LogMessage string `json:"logmessage,omitempty"` + Name string `json:"name,omitempty"` + Percentage int `json:"percentage,omitempty"` + Threshold int `json:"threshold,omitempty"` +} + +type BotProfileRateLimitBinding struct { + BotBindComment string `json:"bot_bind_comment,omitempty"` + BotRateLimitAction []string `json:"bot_rate_limit_action,omitempty"` + BotRateLimitEnabled string `json:"bot_rate_limit_enabled,omitempty"` + BotRateLimitType string `json:"bot_rate_limit_type,omitempty"` + BotRateLimitURL string `json:"bot_rate_limit_url,omitempty"` + BotRateLimit bool `json:"bot_ratelimit,omitempty"` + Condition string `json:"condition,omitempty"` + CookieName string `json:"cookiename,omitempty"` + CountryCode string `json:"countrycode,omitempty"` + LimitType string `json:"limittype,omitempty"` + LogMessage string `json:"logmessage,omitempty"` + Name string `json:"name,omitempty"` + Rate int `json:"rate,omitempty"` + TimeSlice int `json:"timeslice,omitempty"` +} + +type BotProfileBlacklistBinding struct { + BotBindComment string `json:"bot_bind_comment,omitempty"` + BotBlacklist bool `json:"bot_blacklist,omitempty"` + BotBlacklistAction []string `json:"bot_blacklist_action,omitempty"` + BotBlacklistEnabled string `json:"bot_blacklist_enabled,omitempty"` + BotBlacklistType string `json:"bot_blacklist_type,omitempty"` + BotBlacklistValue string `json:"bot_blacklist_value,omitempty"` + LogMessage string `json:"logmessage,omitempty"` + Name string `json:"name,omitempty"` +} diff --git a/nitrogo/models/cache.go b/nitrogo/models/cache.go new file mode 100644 index 0000000..9ad9227 --- /dev/null +++ b/nitrogo/models/cache.go @@ -0,0 +1,304 @@ +package models + +// cache configuration structs +type CachePolicyCSVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type CacheGlobalBinding struct { + CacheGlobalCachePolicyBinding []any `json:"cacheglobal_cachepolicy_binding,omitempty"` +} + +type CachePolicyCachePolicyLabelBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type CachePolicy struct { + Action string `json:"action,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Flags int `json:"flags,omitempty"` + Hits int `json:"hits,omitempty"` + InvalGroups []string `json:"invalgroups,omitempty"` + InvalObjects []string `json:"invalobjects,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Rule string `json:"rule,omitempty"` + StoreInGroup string `json:"storeingroup,omitempty"` + UndefAction string `json:"undefaction,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type CachePolicyCacheGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type CachePolicyLBVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type CacheParameter struct { + CacheEvictionPolicy string `json:"cacheevictionpolicy,omitempty"` + DiskLimit int `json:"disklimit,omitempty"` + EnableBypass string `json:"enablebypass,omitempty"` + EnableHAObjPersist string `json:"enablehaobjpersist,omitempty"` + MaxDiskLimit int `json:"maxdisklimit,omitempty"` + MaxMemLimit int `json:"maxmemlimit,omitempty"` + MaxPostLen int `json:"maxpostlen,omitempty"` + MemLimit int `json:"memlimit,omitempty"` + MemLimitActive int `json:"memlimitactive,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PrefetchCur int `json:"prefetchcur,omitempty"` + PrefetchMaxPending int `json:"prefetchmaxpending,omitempty"` + UndefAction string `json:"undefaction,omitempty"` + VerifyUsing string `json:"verifyusing,omitempty"` + Via string `json:"via,omitempty"` +} + +type CachePolicyLabelPolicyBindingBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type CachePolicyBinding struct { + CachePolicyCacheGlobalBinding []any `json:"cachepolicy_cacheglobal_binding,omitempty"` + CachePolicyCachePolicyLabelBinding []any `json:"cachepolicy_cachepolicylabel_binding,omitempty"` + CachePolicyCSVServerBinding []any `json:"cachepolicy_csvserver_binding,omitempty"` + CachePolicyLBVServerBinding []any `json:"cachepolicy_lbvserver_binding,omitempty"` + PolicyName string `json:"policyname,omitempty"` +} + +type CacheSelector struct { + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Flags int `json:"flags,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule []string `json:"rule,omitempty"` + SelectorName string `json:"selectorname,omitempty"` +} + +type CachePolicyLabel struct { + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + Evaluates string `json:"evaluates,omitempty"` + Feature string `json:"feature,omitempty"` + FlowType int `json:"flowtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Hits int `json:"hits,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NumPol int `json:"numpol,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type CacheGlobalCachePolicyBinding struct { + FlowType int `json:"flowtype,omitempty"` + GlobalBindType string `json:"globalbindtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NumPol int `json:"numpol,omitempty"` + Policy string `json:"policy,omitempty"` + PrecedeDefRules string `json:"precededefrules,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type CacheObject struct { + CacheCellAppFWMetadataExists string `json:"cachecellappfwmetadataexists,omitempty"` + CacheCellBaseFile string `json:"cachecellbasefile,omitempty"` + CacheCellComplex string `json:"cachecellcomplex,omitempty"` + CacheCellCompressionFormat string `json:"cachecellcompressionformat,omitempty"` + CacheCellCurMisses int `json:"cachecellcurmisses,omitempty"` + CacheCellCurReaders int `json:"cachecellcurreaders,omitempty"` + CacheCellDestIPVerified string `json:"cachecelldestipverified,omitempty"` + CacheCellDHits int `json:"cachecelldhits,omitempty"` + CacheCellETagInserted string `json:"cachecelletaginserted,omitempty"` + CacheCellExpires int `json:"cachecellexpires,omitempty"` + CacheCellExpiresMillisec int `json:"cachecellexpiresmillisec,omitempty"` + CacheCellFWPxyObj string `json:"cachecellfwpxyobj,omitempty"` + CacheCellHits int `json:"cachecellhits,omitempty"` + CacheCellHTTP11 string `json:"cachecellhttp11,omitempty"` + CacheCellMinHit int `json:"cachecellminhit,omitempty"` + CacheCellMinHitFlag string `json:"cachecellminhitflag,omitempty"` + CacheCellMisses int `json:"cachecellmisses,omitempty"` + CacheCellPollEveryTime string `json:"cachecellpolleverytime,omitempty"` + CacheCellReadyWithLastByte string `json:"cachecellreadywithlastbyte,omitempty"` + CacheCellReqTime int `json:"cachecellreqtime,omitempty"` + CacheCellResBadSize string `json:"cachecellresbadsize,omitempty"` + CacheCellResTime int `json:"cachecellrestime,omitempty"` + CacheCellWeakETag string `json:"cachecellweaketag,omitempty"` + CacheControl string `json:"cachecontrol,omitempty"` + CacheCurAge int `json:"cachecurage,omitempty"` + CacheDirName string `json:"cachedirname,omitempty"` + CacheETag string `json:"cacheetag,omitempty"` + CacheFileName string `json:"cachefilename,omitempty"` + CacheInDisk string `json:"cacheindisk,omitempty"` + CacheInMemory string `json:"cacheinmemory,omitempty"` + CacheInSecondary string `json:"cacheinsecondary,omitempty"` + CacheResDate string `json:"cacheresdate,omitempty"` + CacheResHdrSize int `json:"cachereshdrsize,omitempty"` + CacheResLastMod string `json:"cachereslastmod,omitempty"` + CacheResSize int `json:"cacheressize,omitempty"` + CacheURLs string `json:"cacheurls,omitempty"` + CEFlags int `json:"ceflags,omitempty"` + ContentGroup string `json:"contentgroup,omitempty"` + Count float64 `json:"__count,omitempty"` + DestIPv46 string `json:"destipv46,omitempty"` + DestPort int `json:"destport,omitempty"` + Flushed string `json:"flushed,omitempty"` + Group string `json:"group,omitempty"` + GroupName string `json:"groupname,omitempty"` + HitParams []string `json:"hitparams,omitempty"` + HitValues []string `json:"hitvalues,omitempty"` + Host string `json:"host,omitempty"` + HTTPCalloutCell string `json:"httpcalloutcell,omitempty"` + HTTPCalloutName string `json:"httpcalloutname,omitempty"` + HTTPCalloutResult string `json:"httpcalloutresult,omitempty"` + HTTPMethod string `json:"httpmethod,omitempty"` + HTTPStatus int `json:"httpstatus,omitempty"` + HTTPStatusOutput int `json:"httpstatusoutput,omitempty"` + IgnoreMarkerObjects string `json:"ignoremarkerobjects,omitempty"` + IncludeNotReadyObjects string `json:"includenotreadyobjects,omitempty"` + Locator int `json:"locator,omitempty"` + LocatorShow int `json:"locatorshow,omitempty"` + MarkerReason string `json:"markerreason,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + Policy int `json:"policy,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Port int `json:"port,omitempty"` + Prefetch string `json:"prefetch,omitempty"` + PrefetchPeriod int `json:"prefetchperiod,omitempty"` + PrefetchPeriodMillisec int `json:"prefetchperiodmillisec,omitempty"` + ReturnType string `json:"returntype,omitempty"` + Rule []string `json:"rule,omitempty"` + SelectorName []string `json:"selectorname,omitempty"` + SelectorValue []string `json:"selectorvalue,omitempty"` + ToSecondary string `json:"tosecondary,omitempty"` + TotalObjs int `json:"totalobjs,omitempty"` + URL string `json:"url,omitempty"` + WarnBucketSkip int `json:"warnbucketskip,omitempty"` +} + +type CachePolicyLabelBinding struct { + CachePolicyLabelCachePolicyBinding []any `json:"cachepolicylabel_cachepolicy_binding,omitempty"` + CachePolicyLabelPolicyBindingBinding []any `json:"cachepolicylabel_policybinding_binding,omitempty"` + LabelName string `json:"labelname,omitempty"` +} + +type CachePolicyLabelCachePolicyBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type CacheContentGroup struct { + AbsExpiry []string `json:"absexpiry,omitempty"` + AbsExpiryGMT []string `json:"absexpirygmt,omitempty"` + AlwaysEvalPolicies string `json:"alwaysevalpolicies,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Cache304Hits int `json:"cache304hits,omitempty"` + CacheCells int `json:"cachecells,omitempty"` + CacheControl string `json:"cachecontrol,omitempty"` + CacheGroupIncarnation int `json:"cachegroupincarnation,omitempty"` + CacheNon304Hits int `json:"cachenon304hits,omitempty"` + CacheNumInvalPolicy int `json:"cachenuminvalpolicy,omitempty"` + Count float64 `json:"__count,omitempty"` + DiskLimit int `json:"disklimit,omitempty"` + ExpireAtLastByte string `json:"expireatlastbyte,omitempty"` + Feature string `json:"feature,omitempty"` + Flags int `json:"flags,omitempty"` + FlashCache string `json:"flashcache,omitempty"` + HeurExpiryParam int `json:"heurexpiryparam,omitempty"` + HitParams []string `json:"hitparams,omitempty"` + HitSelector string `json:"hitselector,omitempty"` + Host string `json:"host,omitempty"` + IgnoreParamValueCase string `json:"ignoreparamvaluecase,omitempty"` + IgnoreReloadReq string `json:"ignorereloadreq,omitempty"` + IgnoreReqCachingHdrs string `json:"ignorereqcachinghdrs,omitempty"` + InsertAge string `json:"insertage,omitempty"` + InsertETag string `json:"insertetag,omitempty"` + InsertVia string `json:"insertvia,omitempty"` + InvalParams []string `json:"invalparams,omitempty"` + InvalRestrictedToHost string `json:"invalrestrictedtohost,omitempty"` + InvalSelector string `json:"invalselector,omitempty"` + LazyDNSResolve string `json:"lazydnsresolve,omitempty"` + MarkerCells int `json:"markercells,omitempty"` + MatchCookies string `json:"matchcookies,omitempty"` + MaxResSize int `json:"maxressize,omitempty"` + MemDUsage int `json:"memdusage,omitempty"` + MemLimit int `json:"memlimit,omitempty"` + MemUsage int `json:"memusage,omitempty"` + MinHits int `json:"minhits,omitempty"` + MinResSize int `json:"minressize,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Persist string `json:"persist,omitempty"` + PersistHA string `json:"persistha,omitempty"` + Pinned string `json:"pinned,omitempty"` + PolicyName []string `json:"policyname,omitempty"` + PollEveryTime string `json:"polleverytime,omitempty"` + Prefetch string `json:"prefetch,omitempty"` + PrefetchCur int `json:"prefetchcur,omitempty"` + PrefetchMaxPending int `json:"prefetchmaxpending,omitempty"` + PrefetchPeriod int `json:"prefetchperiod,omitempty"` + PrefetchPeriodMillisec int `json:"prefetchperiodmillisec,omitempty"` + Query string `json:"query,omitempty"` + QuickAbortSize int `json:"quickabortsize,omitempty"` + RelExpiry int `json:"relexpiry,omitempty"` + RelExpiryMillisec int `json:"relexpirymillisec,omitempty"` + RemoveCookies string `json:"removecookies,omitempty"` + SelectorValue string `json:"selectorvalue,omitempty"` + ToSecondary string `json:"tosecondary,omitempty"` + TypeField string `json:"type,omitempty"` + WeakNegRelExpiry int `json:"weaknegrelexpiry,omitempty"` + WeakPosRelExpiry int `json:"weakposrelexpiry,omitempty"` +} + +type CacheForwardProxy struct { + Count float64 `json:"__count,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Port int `json:"port,omitempty"` +} diff --git a/nitrogo/models/cloud.go b/nitrogo/models/cloud.go new file mode 100644 index 0000000..e1992d2 --- /dev/null +++ b/nitrogo/models/cloud.go @@ -0,0 +1,88 @@ +package models + +// cloud configuration structs +type CloudCredential struct { + ApplicationID string `json:"applicationid,omitempty"` + ApplicationSecret string `json:"applicationsecret,omitempty"` + IsSet int `json:"isset,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + TenantIdentifier string `json:"tenantidentifier,omitempty"` +} + +type CloudNGSParameter struct { + AllowDTLS12 string `json:"allowdtls12,omitempty"` + AllowedUDTVersion string `json:"allowedudtversion,omitempty"` + BlockOnAllowedNGSTktProf string `json:"blockonallowedngstktprof,omitempty"` + CSVServerTicketingDecouple string `json:"csvserverticketingdecouple,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type CloudAWSParam struct { + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + RoleARN string `json:"rolearn,omitempty"` +} + +type CloudParameter struct { + ActivationCode string `json:"activationcode,omitempty"` + ConnectorResidence string `json:"connectorresidence,omitempty"` + ControlConnectionStatus string `json:"controlconnectionstatus,omitempty"` + ControllerFQDN string `json:"controllerfqdn,omitempty"` + ControllerPort int `json:"controllerport,omitempty"` + CustomerID string `json:"customerid,omitempty"` + Deployment string `json:"deployment,omitempty"` + InstanceID string `json:"instanceid,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ResourceLocation string `json:"resourcelocation,omitempty"` +} + +type CloudAllowedNGSTicketProfile struct { + Count float64 `json:"__count,omitempty"` + Creator string `json:"creator,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type CloudService struct { + Response string `json:"response,omitempty"` +} + +type CloudParamInternal struct { + Count float64 `json:"__count,omitempty"` + IAMPerm string `json:"iamperm,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NonFTUMode string `json:"nonftumode,omitempty"` +} + +type CloudProfile struct { + AzurePollPeriod int `json:"azurepollperiod,omitempty"` + AzureTagName string `json:"azuretagname,omitempty"` + AzureTagValue string `json:"azuretagvalue,omitempty"` + BoundServiceGroupSvcType string `json:"boundservicegroupsvctype,omitempty"` + Count float64 `json:"__count,omitempty"` + Delay int `json:"delay,omitempty"` + Graceful string `json:"graceful,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Port int `json:"port,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` + ServiceType string `json:"servicetype,omitempty"` + TypeField string `json:"type,omitempty"` + VServerName string `json:"vservername,omitempty"` + VSvrBindSvcPort int `json:"vsvrbindsvcport,omitempty"` +} + +type CloudAutoscaleGroup struct { + AZCount int `json:"azcount,omitempty"` + AZNames []string `json:"aznames,omitempty"` + Count float64 `json:"__count,omitempty"` + Graceful string `json:"graceful,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type CloudVServerIP struct { + Count float64 `json:"__count,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} diff --git a/nitrogo/models/cloudtunnel.go b/nitrogo/models/cloudtunnel.go new file mode 100644 index 0000000..beb84f7 --- /dev/null +++ b/nitrogo/models/cloudtunnel.go @@ -0,0 +1,28 @@ +package models + +// cloudtunnel configuration structs +type CloudTunnelParameter struct { + ControllerFQDN string `json:"controllerfqdn,omitempty"` + FQDN string `json:"fqdn,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ResourceLocation string `json:"resourcelocation,omitempty"` + SubnetResourceLocationMappings string `json:"subnetresourcelocationmappings,omitempty"` +} + +type CloudTunnelVServer struct { + CacheType string `json:"cachetype,omitempty"` + Count float64 `json:"__count,omitempty"` + EffectiveState string `json:"effectivestate,omitempty"` + IP string `json:"ip,omitempty"` + IPPattern string `json:"ippattern,omitempty"` + IPv46 string `json:"ipv46,omitempty"` + ListenPolicy string `json:"listenpolicy,omitempty"` + ListenPriority int `json:"listenpriority,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Port int `json:"port,omitempty"` + Range int `json:"range,omitempty"` + ServiceType string `json:"servicetype,omitempty"` + State string `json:"state,omitempty"` + TypeField string `json:"type,omitempty"` +} diff --git a/nitrogo/models/cluster.go b/nitrogo/models/cluster.go new file mode 100644 index 0000000..8f9d343 --- /dev/null +++ b/nitrogo/models/cluster.go @@ -0,0 +1,219 @@ +package models + +// cluster configuration structs +type ClusterNodeBinding struct { + ClusterNodeRouteMonitorBinding []any `json:"clusternode_routemonitor_binding,omitempty"` + NodeID int `json:"nodeid,omitempty"` +} + +type ClusterNode struct { + Backplane string `json:"backplane,omitempty"` + CfgFlags int `json:"cfgflags,omitempty"` + ClearNodeGroupConfig string `json:"clearnodegroupconfig,omitempty"` + ClusterHealth string `json:"clusterhealth,omitempty"` + Count float64 `json:"__count,omitempty"` + Delay int `json:"delay,omitempty"` + DisabledIfaces string `json:"disabledifaces,omitempty"` + EffectiveState string `json:"effectivestate,omitempty"` + EnabledIfaces string `json:"enabledifaces,omitempty"` + Force bool `json:"force,omitempty"` + HAMonIfaces string `json:"hamonifaces,omitempty"` + Health string `json:"health,omitempty"` + IfacesList []string `json:"ifaceslist,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + IsConfigurationCoordinator bool `json:"isconfigurationcoordinator,omitempty"` + IsLocalNode bool `json:"islocalnode,omitempty"` + MasterState string `json:"masterstate,omitempty"` + Name string `json:"name,omitempty"` + Netmask string `json:"netmask,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeGroup string `json:"nodegroup,omitempty"` + NodeID int `json:"nodeid,omitempty"` + NodeJumboNotSupported bool `json:"nodejumbonotsupported,omitempty"` + NodeLicenseMismatch bool `json:"nodelicensemismatch,omitempty"` + NodeList []any `json:"nodelist,omitempty"` + NodeRSSKeyMismatch bool `json:"nodersskeymismatch,omitempty"` + OperationalSyncState string `json:"operationalsyncstate,omitempty"` + PartialFailIfaces string `json:"partialfailifaces,omitempty"` + Priority int `json:"priority,omitempty"` + RouteMonitor string `json:"routemonitor,omitempty"` + State string `json:"state,omitempty"` + SyncFailureReason string `json:"syncfailurereason,omitempty"` + SyncState string `json:"syncstate,omitempty"` + TunnelMode string `json:"tunnelmode,omitempty"` +} + +type ClusterNodeGroupStreamIdentifierBinding struct { + IdentifierName string `json:"identifiername,omitempty"` + Name string `json:"name,omitempty"` +} + +type Cluster struct { + Clip string `json:"clip,omitempty"` + Password string `json:"password,omitempty"` +} + +type ClusterInstance struct { + AdminState string `json:"adminstate,omitempty"` + BackplaneBasedView string `json:"backplanebasedview,omitempty"` + CLID int `json:"clid,omitempty"` + ClusterCLIPFailure bool `json:"clusterclipfailure,omitempty"` + ClusterHBHMacErrorDetected bool `json:"clusterhbhmacerrordetected,omitempty"` + ClusterNoHeartbeatOnNode bool `json:"clusternoheartbeatonnode,omitempty"` + ClusterNoLinksetMBF bool `json:"clusternolinksetmbf,omitempty"` + ClusterNoSpottedIP bool `json:"clusternospottedip,omitempty"` + ClusterProxyARP string `json:"clusterproxyarp,omitempty"` + ClusterTunnelModeMismatch bool `json:"clustertunnelmodemismatch,omitempty"` + Count float64 `json:"__count,omitempty"` + DeadInterval int `json:"deadinterval,omitempty"` + DFDRetainL2Params string `json:"dfdretainl2params,omitempty"` + HelloInterval int `json:"hellointerval,omitempty"` + HeterogeneousFlag string `json:"heterogeneousflag,omitempty"` + Inc string `json:"inc,omitempty"` + JumboNotSupported bool `json:"jumbonotsupported,omitempty"` + LicenseMismatch bool `json:"licensemismatch,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeGroup string `json:"nodegroup,omitempty"` + NodeGroupStateWarning bool `json:"nodegroupstatewarning,omitempty"` + NodePENumMismatch bool `json:"nodepenummismatch,omitempty"` + OperationalPropState string `json:"operationalpropstate,omitempty"` + OperationalState string `json:"operationalstate,omitempty"` + PENumMismatch bool `json:"penummismatch,omitempty"` + Preemption string `json:"preemption,omitempty"` + ProcessLocal string `json:"processlocal,omitempty"` + PropState string `json:"propstate,omitempty"` + QuorumType string `json:"quorumtype,omitempty"` + RetainConnectionsOnCluster string `json:"retainconnectionsoncluster,omitempty"` + RSSKeyMismatch bool `json:"rsskeymismatch,omitempty"` + SecureHeartbeats string `json:"secureheartbeats,omitempty"` + Status string `json:"status,omitempty"` + SyncStatusStrictMode string `json:"syncstatusstrictmode,omitempty"` + ValidMTU int `json:"validmtu,omitempty"` +} + +type ClusterNodeRouteMonitorBinding struct { + Netmask string `json:"netmask,omitempty"` + NodeID int `json:"nodeid,omitempty"` + RouteMonitor string `json:"routemonitor,omitempty"` + RouteMonState int `json:"routemonstate,omitempty"` +} + +type ClusterNodeGroupGSLBVServerBinding struct { + Name string `json:"name,omitempty"` + VServer string `json:"vserver,omitempty"` +} + +type ClusterNodeGroupBinding struct { + ClusterNodeGroupAuthenticationVServerBinding []any `json:"clusternodegroup_authenticationvserver_binding,omitempty"` + ClusterNodeGroupClusterNodeBinding []any `json:"clusternodegroup_clusternode_binding,omitempty"` + ClusterNodeGroupCRVServerBinding []any `json:"clusternodegroup_crvserver_binding,omitempty"` + ClusterNodeGroupCSVServerBinding []any `json:"clusternodegroup_csvserver_binding,omitempty"` + ClusterNodeGroupGSLBSiteBinding []any `json:"clusternodegroup_gslbsite_binding,omitempty"` + ClusterNodeGroupGSLBVServerBinding []any `json:"clusternodegroup_gslbvserver_binding,omitempty"` + ClusterNodeGroupLBVServerBinding []any `json:"clusternodegroup_lbvserver_binding,omitempty"` + ClusterNodeGroupNSLimitIdentifierBinding []any `json:"clusternodegroup_nslimitidentifier_binding,omitempty"` + ClusterNodeGroupServiceBinding []any `json:"clusternodegroup_service_binding,omitempty"` + ClusterNodeGroupStreamIdentifierBinding []any `json:"clusternodegroup_streamidentifier_binding,omitempty"` + ClusterNodeGroupVPNVServerBinding []any `json:"clusternodegroup_vpnvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type ClusterNodeGroupAuthenticationVServerBinding struct { + Name string `json:"name,omitempty"` + VServer string `json:"vserver,omitempty"` +} + +type ClusterNodeGroupLBVServerBinding struct { + Name string `json:"name,omitempty"` + VServer string `json:"vserver,omitempty"` +} + +type ClusterNodeGroupCRVServerBinding struct { + Name string `json:"name,omitempty"` + VServer string `json:"vserver,omitempty"` +} + +type ClusterNodeGroupNSLimitIdentifierBinding struct { + IdentifierName string `json:"identifiername,omitempty"` + Name string `json:"name,omitempty"` +} + +type ClusterSync struct { +} + +type ClusterNodeGroupGSLBSiteBinding struct { + GSLBSite string `json:"gslbsite,omitempty"` + Name string `json:"name,omitempty"` +} + +type ClusterNodeGroupServiceBinding struct { + Name string `json:"name,omitempty"` + Service string `json:"service,omitempty"` +} + +type ClusterNodeGroup struct { + ActiveList []any `json:"activelist,omitempty"` + BackupList []any `json:"backuplist,omitempty"` + BackupNodeMask int `json:"backupnodemask,omitempty"` + BoundedEntitiesCntFromPE int `json:"boundedentitiescntfrompe,omitempty"` + Count float64 `json:"__count,omitempty"` + CurrentNodeMask int `json:"currentnodemask,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Priority int `json:"priority,omitempty"` + State string `json:"state,omitempty"` + Sticky string `json:"sticky,omitempty"` + Strict string `json:"strict,omitempty"` +} + +type ClusterNodeGroupClusterNodeBinding struct { + Name string `json:"name,omitempty"` + Node int `json:"node,omitempty"` +} + +type ClusterSyncFailures struct { + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type ClusterPropStatus struct { + CmdStrs string `json:"cmdstrs,omitempty"` + Count float64 `json:"__count,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + NumPropCmdFailed int `json:"numpropcmdfailed,omitempty"` +} + +type ClusterInstanceBinding struct { + CLID int `json:"clid,omitempty"` + ClusterInstanceClusterNodeBinding []any `json:"clusterinstance_clusternode_binding,omitempty"` +} + +type ClusterFiles struct { + Mode []string `json:"mode,omitempty"` +} + +type ClusterInstanceClusterNodeBinding struct { + CLID int `json:"clid,omitempty"` + ClusterHealth string `json:"clusterhealth,omitempty"` + EffectiveState string `json:"effectivestate,omitempty"` + Health string `json:"health,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + IsConfigurationCoordinator bool `json:"isconfigurationcoordinator,omitempty"` + IsLocalNode bool `json:"islocalnode,omitempty"` + MasterState string `json:"masterstate,omitempty"` + NodeID int `json:"nodeid,omitempty"` + NodeJumboNotSupported bool `json:"nodejumbonotsupported,omitempty"` + NodeLicenseMismatch bool `json:"nodelicensemismatch,omitempty"` + NodeRSSKeyMismatch bool `json:"nodersskeymismatch,omitempty"` + State string `json:"state,omitempty"` +} + +type ClusterNodeGroupVPNVServerBinding struct { + Name string `json:"name,omitempty"` + VServer string `json:"vserver,omitempty"` +} + +type ClusterNodeGroupCSVServerBinding struct { + Name string `json:"name,omitempty"` + VServer string `json:"vserver,omitempty"` +} diff --git a/nitrogo/models/cmp.go b/nitrogo/models/cmp.go new file mode 100644 index 0000000..9b18d9d --- /dev/null +++ b/nitrogo/models/cmp.go @@ -0,0 +1,173 @@ +package models + +// cmp configuration structs +type CMPParameter struct { + AddVaryHeader string `json:"addvaryheader,omitempty"` + Builtin []string `json:"builtin,omitempty"` + CMPBypassPct int `json:"cmpbypasspct,omitempty"` + CMPLevel string `json:"cmplevel,omitempty"` + CMPOnPush string `json:"cmponpush,omitempty"` + ExternalCache string `json:"externalcache,omitempty"` + Feature string `json:"feature,omitempty"` + HeurExpiry string `json:"heurexpiry,omitempty"` + HeurExpiryHistWt int `json:"heurexpiryhistwt,omitempty"` + HeurExpiryThres int `json:"heurexpirythres,omitempty"` + MinResSize int `json:"minressize,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PolicyType string `json:"policytype,omitempty"` + QuantumSize int `json:"quantumsize,omitempty"` + RandomGzipFilename string `json:"randomgzipfilename,omitempty"` + RandomGzipFilenameMaxLength int `json:"randomgzipfilenamemaxlength,omitempty"` + RandomGzipFilenameMinLength int `json:"randomgzipfilenameminlength,omitempty"` + ServerCMP string `json:"servercmp,omitempty"` + VaryHeaderValue string `json:"varyheadervalue,omitempty"` +} + +type CMPGlobalBinding struct { + CMPGlobalCMPPolicyBinding []any `json:"cmpglobal_cmppolicy_binding,omitempty"` +} + +type CMPPolicyBinding struct { + CMPPolicyCMPGlobalBinding []any `json:"cmppolicy_cmpglobal_binding,omitempty"` + CMPPolicyCMPPolicyLabelBinding []any `json:"cmppolicy_cmppolicylabel_binding,omitempty"` + CMPPolicyCRVServerBinding []any `json:"cmppolicy_crvserver_binding,omitempty"` + CMPPolicyCSVServerBinding []any `json:"cmppolicy_csvserver_binding,omitempty"` + CMPPolicyLBVServerBinding []any `json:"cmppolicy_lbvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type CMPPolicyLabelPolicyBindingBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type CMPPolicyCMPPolicyLabelBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type CMPGlobalCMPPolicyBinding struct { + GlobalBindType string `json:"globalbindtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type CMPPolicy struct { + Builtin []string `json:"builtin,omitempty"` + ClientTransactions int `json:"clienttransactions,omitempty"` + ClientTTLB int `json:"clientttlb,omitempty"` + Count float64 `json:"__count,omitempty"` + Description string `json:"description,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + IsDefault bool `json:"isdefault,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ReqAction string `json:"reqaction,omitempty"` + ResAction string `json:"resaction,omitempty"` + Rule string `json:"rule,omitempty"` + RxBytes int `json:"rxbytes,omitempty"` + ServerTransactions int `json:"servertransactions,omitempty"` + ServerTTLB int `json:"serverttlb,omitempty"` + TxBytes int `json:"txbytes,omitempty"` +} + +type CMPAction struct { + AddVaryHeader string `json:"addvaryheader,omitempty"` + Builtin []string `json:"builtin,omitempty"` + CMPType string `json:"cmptype,omitempty"` + Count float64 `json:"__count,omitempty"` + DeltaType string `json:"deltatype,omitempty"` + Feature string `json:"feature,omitempty"` + IsDefault bool `json:"isdefault,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + VaryHeaderValue string `json:"varyheadervalue,omitempty"` +} + +type CMPPolicyCMPGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type CMPPolicyLabel struct { + Count float64 `json:"__count,omitempty"` + Description string `json:"description,omitempty"` + FlowType int `json:"flowtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Hits int `json:"hits,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NumPol int `json:"numpol,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type CMPPolicyCRVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type CMPPolicyLBVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type CMPPolicyLabelCMPPolicyBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type CMPPolicyCSVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type CMPPolicyLabelBinding struct { + CMPPolicyLabelCMPPolicyBinding []any `json:"cmppolicylabel_cmppolicy_binding,omitempty"` + CMPPolicyLabelPolicyBindingBinding []any `json:"cmppolicylabel_policybinding_binding,omitempty"` + LabelName string `json:"labelname,omitempty"` +} diff --git a/nitrogo/models/contentinspection.go b/nitrogo/models/contentinspection.go new file mode 100644 index 0000000..a75fb09 --- /dev/null +++ b/nitrogo/models/contentinspection.go @@ -0,0 +1,192 @@ +package models + +// contentinspection configuration structs +type ContentInspectionPolicyContentInspectionGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type ContentInspectionPolicyLabel struct { + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + FlowType int `json:"flowtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Hits int `json:"hits,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + IsDefault bool `json:"isdefault,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NumPol int `json:"numpol,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type ContentInspectionWasmProfile struct { + AnomalousDataSize int `json:"anomalousdatasize,omitempty"` + AnomalousTTFBTime int `json:"anomalousttfbtime,omitempty"` + Count float64 `json:"__count,omitempty"` + MaxBodyLen int `json:"maxbodylen,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Timeout int `json:"timeout,omitempty"` + TimeoutAction string `json:"timeoutaction,omitempty"` + WasmModule string `json:"wasmmodule,omitempty"` +} + +type ContentInspectionPolicyLabelPolicyBindingBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type ContentInspectionPolicyCSVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type ContentInspectionCallout struct { + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Hits int `json:"hits,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ProfileName string `json:"profilename,omitempty"` + ResultExpr string `json:"resultexpr,omitempty"` + ReturnType string `json:"returntype,omitempty"` + ServerIP string `json:"serverip,omitempty"` + ServerName string `json:"servername,omitempty"` + ServerPort int `json:"serverport,omitempty"` + TypeField string `json:"type,omitempty"` + UndefHits int `json:"undefhits,omitempty"` + UndefReason string `json:"undefreason,omitempty"` +} + +type ContentInspectionProfile struct { + Count float64 `json:"__count,omitempty"` + EgressInterface string `json:"egressinterface,omitempty"` + EgressVLAN int `json:"egressvlan,omitempty"` + IngressInterface string `json:"ingressinterface,omitempty"` + IngressVLAN int `json:"ingressvlan,omitempty"` + IPTunnel string `json:"iptunnel,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type ContentInspectionGlobalContentInspectionPolicyBinding struct { + FlowType int `json:"flowtype,omitempty"` + GlobalBindType string `json:"globalbindtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type ContentInspectionParameter struct { + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + UndefAction string `json:"undefaction,omitempty"` +} + +type ContentInspectionPolicyLabelBinding struct { + ContentInspectionPolicyLabelContentInspectionPolicyBinding []any `json:"contentinspectionpolicylabel_contentinspectionpolicy_binding,omitempty"` + ContentInspectionPolicyLabelPolicyBindingBinding []any `json:"contentinspectionpolicylabel_policybinding_binding,omitempty"` + LabelName string `json:"labelname,omitempty"` +} + +type ContentInspectionAction struct { + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + ICAPProfileName string `json:"icapprofilename,omitempty"` + IfServerDown string `json:"ifserverdown,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ReferenceCount int `json:"referencecount,omitempty"` + ReqTimeout int `json:"reqtimeout,omitempty"` + ReqTimeoutAction string `json:"reqtimeoutaction,omitempty"` + ServerIP string `json:"serverip,omitempty"` + ServerName string `json:"servername,omitempty"` + ServerPort int `json:"serverport,omitempty"` + TypeField string `json:"type,omitempty"` + UndefHits int `json:"undefhits,omitempty"` + WasmProfileName string `json:"wasmprofilename,omitempty"` +} + +type ContentInspectionPolicyLBVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type ContentInspectionGlobalBinding struct { + ContentInspectionGlobalContentInspectionPolicyBinding []any `json:"contentinspectionglobal_contentinspectionpolicy_binding,omitempty"` +} + +type ContentInspectionPolicyContentInspectionPolicyLabelBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type ContentInspectionPolicyBinding struct { + ContentInspectionPolicyContentInspectionGlobalBinding []any `json:"contentinspectionpolicy_contentinspectionglobal_binding,omitempty"` + ContentInspectionPolicyContentInspectionPolicyLabelBinding []any `json:"contentinspectionpolicy_contentinspectionpolicylabel_binding,omitempty"` + ContentInspectionPolicyCSVServerBinding []any `json:"contentinspectionpolicy_csvserver_binding,omitempty"` + ContentInspectionPolicyLBVServerBinding []any `json:"contentinspectionpolicy_lbvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type ContentInspectionPolicyLabelContentInspectionPolicyBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type ContentInspectionPolicy struct { + Action string `json:"action,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + LogAction string `json:"logaction,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule string `json:"rule,omitempty"` + UndefAction string `json:"undefaction,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} diff --git a/nitrogo/models/cr.go b/nitrogo/models/cr.go new file mode 100644 index 0000000..4ac68c6 --- /dev/null +++ b/nitrogo/models/cr.go @@ -0,0 +1,322 @@ +package models + +// cr configuration structs +type CRVServerAppQOEPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetVServer string `json:"targetvserver,omitempty"` +} + +type CRVServerCRPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Hits int `json:"hits,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PIPolicyHits int `json:"pipolicyhits,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetVServer string `json:"targetvserver,omitempty"` +} + +type CRVServerCachePolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetVServer string `json:"targetvserver,omitempty"` +} + +type CRPolicyBinding struct { + CRPolicyCRVServerBinding []any `json:"crpolicy_crvserver_binding,omitempty"` + PolicyName string `json:"policyname,omitempty"` +} + +type CRVServerCMPPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Inherited string `json:"inherited,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetVServer string `json:"targetvserver,omitempty"` +} + +type CRVServerAnalyticsProfileBinding struct { + AnalyticsProfile string `json:"analyticsprofile,omitempty"` + Name string `json:"name,omitempty"` +} + +type CRVServerLBVServerBinding struct { + Hits int `json:"hits,omitempty"` + LBVServer string `json:"lbvserver,omitempty"` + Name string `json:"name,omitempty"` +} + +type CRVServerAppFlowPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetVServer string `json:"targetvserver,omitempty"` +} + +type CRVServerFEOPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetVServer string `json:"targetvserver,omitempty"` +} + +type CRVServerICAPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetVServer string `json:"targetvserver,omitempty"` +} + +type CRVServerResponderPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetVServer string `json:"targetvserver,omitempty"` +} + +type CRAction struct { + Builtin []string `json:"builtin,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + CRType string `json:"crtype,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + IsDefault bool `json:"isdefault,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ReferenceCount int `json:"referencecount,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type CRVServerAppFWPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetVServer string `json:"targetvserver,omitempty"` +} + +type CRVServerPolicyMapBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetVServer string `json:"targetvserver,omitempty"` +} + +type CRVServerRewritePolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetVServer string `json:"targetvserver,omitempty"` +} + +type CRVServerSpilloverPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetVServer string `json:"targetvserver,omitempty"` +} + +type CRPolicy struct { + Action string `json:"action,omitempty"` + ActivePolicy bool `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + IsDefault bool `json:"isdefault,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + LogAction string `json:"logaction,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + Rule string `json:"rule,omitempty"` + VSType int `json:"vstype,omitempty"` +} + +type CRVServerBinding struct { + CRVServerAnalyticsProfileBinding []any `json:"crvserver_analyticsprofile_binding,omitempty"` + CRVServerAppFlowPolicyBinding []any `json:"crvserver_appflowpolicy_binding,omitempty"` + CRVServerAppFWPolicyBinding []any `json:"crvserver_appfwpolicy_binding,omitempty"` + CRVServerAppQOEPolicyBinding []any `json:"crvserver_appqoepolicy_binding,omitempty"` + CRVServerCachePolicyBinding []any `json:"crvserver_cachepolicy_binding,omitempty"` + CRVServerCMPPolicyBinding []any `json:"crvserver_cmppolicy_binding,omitempty"` + CRVServerCRPolicyBinding []any `json:"crvserver_crpolicy_binding,omitempty"` + CRVServerCSPolicyBinding []any `json:"crvserver_cspolicy_binding,omitempty"` + CRVServerFEOPolicyBinding []any `json:"crvserver_feopolicy_binding,omitempty"` + CRVServerICAPolicyBinding []any `json:"crvserver_icapolicy_binding,omitempty"` + CRVServerLBVServerBinding []any `json:"crvserver_lbvserver_binding,omitempty"` + CRVServerPolicyMapBinding []any `json:"crvserver_policymap_binding,omitempty"` + CRVServerResponderPolicyBinding []any `json:"crvserver_responderpolicy_binding,omitempty"` + CRVServerRewritePolicyBinding []any `json:"crvserver_rewritepolicy_binding,omitempty"` + CRVServerSpilloverPolicyBinding []any `json:"crvserver_spilloverpolicy_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type CRVServer struct { + AppFlowLog string `json:"appflowlog,omitempty"` + ARP string `json:"arp,omitempty"` + Authentication string `json:"authentication,omitempty"` + BackendSSL string `json:"backendssl,omitempty"` + BackupVServer string `json:"backupvserver,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + CacheType string `json:"cachetype,omitempty"` + CacheVServer string `json:"cachevserver,omitempty"` + CltTimeout int `json:"clttimeout,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + CurState string `json:"curstate,omitempty"` + DestinationVServer string `json:"destinationvserver,omitempty"` + DisablePrimaryOnDown string `json:"disableprimaryondown,omitempty"` + DisallowServiceAccess string `json:"disallowserviceaccess,omitempty"` + DNSVServerName string `json:"dnsvservername,omitempty"` + Domain string `json:"domain,omitempty"` + DownStateFlush string `json:"downstateflush,omitempty"` + Format string `json:"format,omitempty"` + Ghost string `json:"ghost,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + HomePage string `json:"homepage,omitempty"` + HTTPProfileName string `json:"httpprofilename,omitempty"` + ICMPVSRResponse string `json:"icmpvsrresponse,omitempty"` + Invoke bool `json:"invoke,omitempty"` + IP string `json:"ip,omitempty"` + IPSet string `json:"ipset,omitempty"` + IPv46 string `json:"ipv46,omitempty"` + L2Conn string `json:"l2conn,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + LBVServer string `json:"lbvserver,omitempty"` + ListenPolicy string `json:"listenpolicy,omitempty"` + ListenPriority int `json:"listenpriority,omitempty"` + MapField string `json:"map,omitempty"` + Name string `json:"name,omitempty"` + NetProfile string `json:"netprofile,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NGName string `json:"ngname,omitempty"` + NoDefaultBindings string `json:"nodefaultbindings,omitempty"` + OnPolicyMatch string `json:"onpolicymatch,omitempty"` + OriginUSIP string `json:"originusip,omitempty"` + PIPolicyHits int `json:"pipolicyhits,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Port int `json:"port,omitempty"` + Precedence string `json:"precedence,omitempty"` + Priority int `json:"priority,omitempty"` + ProbePort int `json:"probeport,omitempty"` + ProbeProtocol string `json:"probeprotocol,omitempty"` + ProbeSuccessResponseCode string `json:"probesuccessresponsecode,omitempty"` + Range int `json:"range,omitempty"` + Redirect string `json:"redirect,omitempty"` + RedirectURL string `json:"redirecturl,omitempty"` + Reuse string `json:"reuse,omitempty"` + RHIState string `json:"rhistate,omitempty"` + Rule string `json:"rule,omitempty"` + ServiceName string `json:"servicename,omitempty"` + ServiceType string `json:"servicetype,omitempty"` + SOMethod string `json:"somethod,omitempty"` + SOPersistence string `json:"sopersistence,omitempty"` + SOPersistenceTimeout int `json:"sopersistencetimeout,omitempty"` + SOThreshold int `json:"sothreshold,omitempty"` + SrcIPExpr string `json:"srcipexpr,omitempty"` + State string `json:"state,omitempty"` + Status int `json:"status,omitempty"` + TargetVServer string `json:"targetvserver,omitempty"` + TCPProbePort int `json:"tcpprobeport,omitempty"` + TCPProfileName string `json:"tcpprofilename,omitempty"` + TD int `json:"td,omitempty"` + TypeField string `json:"type,omitempty"` + UseOriginIPPortForCache string `json:"useoriginipportforcache,omitempty"` + UsePortRange string `json:"useportrange,omitempty"` + Value string `json:"value,omitempty"` + Via string `json:"via,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type CRPolicyCRVServerBinding struct { + BindHits int `json:"bindhits,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Hits int `json:"hits,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type CRVServerCSPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Hits int `json:"hits,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PIPolicyHits int `json:"pipolicyhits,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetVServer string `json:"targetvserver,omitempty"` +} diff --git a/nitrogo/models/cs.go b/nitrogo/models/cs.go new file mode 100644 index 0000000..cf9561b --- /dev/null +++ b/nitrogo/models/cs.go @@ -0,0 +1,498 @@ +package models + +// cs configuration structs +type CSVServerTransformPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetLBVServer string `json:"targetlbvserver,omitempty"` +} + +type CSVServerDomainBinding struct { + AppFlowLog string `json:"appflowlog,omitempty"` + BackupIP string `json:"backupip,omitempty"` + CookieDomain string `json:"cookiedomain,omitempty"` + CookieTimeout int `json:"cookietimeout,omitempty"` + DomainName string `json:"domainname,omitempty"` + Name string `json:"name,omitempty"` + SiteDomainTTL int `json:"sitedomainttl,omitempty"` + TTL int `json:"ttl,omitempty"` +} + +type CSVServerBotPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetLBVServer string `json:"targetlbvserver,omitempty"` +} + +type CSParameter struct { + Builtin []string `json:"builtin,omitempty"` + Feature string `json:"feature,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + StateUpdate string `json:"stateupdate,omitempty"` +} + +type CSVServerVPNVServerBinding struct { + Hits int `json:"hits,omitempty"` + Name string `json:"name,omitempty"` + VServer string `json:"vserver,omitempty"` +} + +type CSVServerResponderPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetLBVServer string `json:"targetlbvserver,omitempty"` +} + +type CSPolicy struct { + Action string `json:"action,omitempty"` + ActivePolicy bool `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Count float64 `json:"__count,omitempty"` + Hits int `json:"hits,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + LogAction string `json:"logaction,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + Rule string `json:"rule,omitempty"` + VSType int `json:"vstype,omitempty"` +} + +type CSVServerBinding struct { + CSVServerAnalyticsProfileBinding []any `json:"csvserver_analyticsprofile_binding,omitempty"` + CSVServerAppFlowPolicyBinding []any `json:"csvserver_appflowpolicy_binding,omitempty"` + CSVServerAppFWPolicyBinding []any `json:"csvserver_appfwpolicy_binding,omitempty"` + CSVServerAppQOEPolicyBinding []any `json:"csvserver_appqoepolicy_binding,omitempty"` + CSVServerAuditNSLogPolicyBinding []any `json:"csvserver_auditnslogpolicy_binding,omitempty"` + CSVServerAuditSyslogPolicyBinding []any `json:"csvserver_auditsyslogpolicy_binding,omitempty"` + CSVServerAuthorizationPolicyBinding []any `json:"csvserver_authorizationpolicy_binding,omitempty"` + CSVServerBotPolicyBinding []any `json:"csvserver_botpolicy_binding,omitempty"` + CSVServerCachePolicyBinding []any `json:"csvserver_cachepolicy_binding,omitempty"` + CSVServerCMPPolicyBinding []any `json:"csvserver_cmppolicy_binding,omitempty"` + CSVServerContentInspectionPolicyBinding []any `json:"csvserver_contentinspectionpolicy_binding,omitempty"` + CSVServerCSPolicyBinding []any `json:"csvserver_cspolicy_binding,omitempty"` + CSVServerFEOPolicyBinding []any `json:"csvserver_feopolicy_binding,omitempty"` + CSVServerGSLBDomainBinding []any `json:"csvserver_gslbdomain_binding,omitempty"` + CSVServerGSLBVServerBinding []any `json:"csvserver_gslbvserver_binding,omitempty"` + CSVServerLBVServerBinding []any `json:"csvserver_lbvserver_binding,omitempty"` + CSVServerResponderPolicyBinding []any `json:"csvserver_responderpolicy_binding,omitempty"` + CSVServerRewritePolicyBinding []any `json:"csvserver_rewritepolicy_binding,omitempty"` + CSVServerSpilloverPolicyBinding []any `json:"csvserver_spilloverpolicy_binding,omitempty"` + CSVServerTMTrafficPolicyBinding []any `json:"csvserver_tmtrafficpolicy_binding,omitempty"` + CSVServerTransformPolicyBinding []any `json:"csvserver_transformpolicy_binding,omitempty"` + CSVServerVPNVServerBinding []any `json:"csvserver_vpnvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type CSPolicyCSVServerBinding struct { + Action string `json:"action,omitempty"` + BindHits int `json:"bindhits,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Hits int `json:"hits,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type CSPolicyCSPolicyLabelBinding struct { + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Hits int `json:"hits,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type CSVServerAuditNSLogPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetLBVServer string `json:"targetlbvserver,omitempty"` +} + +type CSVServerAppFlowPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetLBVServer string `json:"targetlbvserver,omitempty"` +} + +type CSVServerAuditSyslogPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetLBVServer string `json:"targetlbvserver,omitempty"` +} + +type CSVServerTMTrafficPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetLBVServer string `json:"targetlbvserver,omitempty"` +} + +type CSVServerCachePolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetLBVServer string `json:"targetlbvserver,omitempty"` +} + +type CSVServerAppFWPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetLBVServer string `json:"targetlbvserver,omitempty"` +} + +type CSVServerCSPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + CookieIPPort string `json:"cookieipport,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Hits int `json:"hits,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PIPolicyHits int `json:"pipolicyhits,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + Rule string `json:"rule,omitempty"` + TargetLBVServer string `json:"targetlbvserver,omitempty"` + VServerID string `json:"vserverid,omitempty"` +} + +type CSVServerAppQOEPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetLBVServer string `json:"targetlbvserver,omitempty"` +} + +type CSVServerSpilloverPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetLBVServer string `json:"targetlbvserver,omitempty"` +} + +type CSVServerAuthorizationPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetLBVServer string `json:"targetlbvserver,omitempty"` +} + +type CSVServerAnalyticsProfileBinding struct { + AnalyticsProfile string `json:"analyticsprofile,omitempty"` + Name string `json:"name,omitempty"` +} + +type CSPolicyCRVServerBinding struct { + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Hits int `json:"hits,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type CSPolicyLabelBinding struct { + CSPolicyLabelCSPolicyBinding []any `json:"cspolicylabel_cspolicy_binding,omitempty"` + LabelName string `json:"labelname,omitempty"` +} + +type CSVServerContentInspectionPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetLBVServer string `json:"targetlbvserver,omitempty"` +} + +type CSPolicyLabel struct { + Count float64 `json:"__count,omitempty"` + CSPolicyLabelType string `json:"cspolicylabeltype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Hits int `json:"hits,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetVServer string `json:"targetvserver,omitempty"` +} + +type CSVServerGSLBVServerBinding struct { + Hits int `json:"hits,omitempty"` + Name string `json:"name,omitempty"` + VServer string `json:"vserver,omitempty"` +} + +type CSVServerFEOPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetLBVServer string `json:"targetlbvserver,omitempty"` +} + +type CSVServerRewritePolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetLBVServer string `json:"targetlbvserver,omitempty"` +} + +type CSVServerCMPPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetLBVServer string `json:"targetlbvserver,omitempty"` +} + +type CSAction struct { + Builtin []string `json:"builtin,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ReferenceCount int `json:"referencecount,omitempty"` + TargetLBVServer string `json:"targetlbvserver,omitempty"` + TargetVServer string `json:"targetvserver,omitempty"` + TargetVServerExpr string `json:"targetvserverexpr,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type CSPolicyLabelCSPolicyBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TargetVServer string `json:"targetvserver,omitempty"` +} + +type CSVServer struct { + APIProfile string `json:"apiprofile,omitempty"` + AppFlowLog string `json:"appflowlog,omitempty"` + Authentication string `json:"authentication,omitempty"` + AuthenticationHost string `json:"authenticationhost,omitempty"` + Authn401 string `json:"authn401,omitempty"` + AuthnProfile string `json:"authnprofile,omitempty"` + AuthnVSName string `json:"authnvsname,omitempty"` + BackupIP string `json:"backupip,omitempty"` + BackupPersistenceTimeout int `json:"backuppersistencetimeout,omitempty"` + BackupVServer string `json:"backupvserver,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + Cacheable string `json:"cacheable,omitempty"` + CacheType string `json:"cachetype,omitempty"` + CacheVServer string `json:"cachevserver,omitempty"` + CaseSensitive string `json:"casesensitive,omitempty"` + CltTimeout int `json:"clttimeout,omitempty"` + Comment string `json:"comment,omitempty"` + CookieDomain string `json:"cookiedomain,omitempty"` + CookieName string `json:"cookiename,omitempty"` + CookieTimeout int `json:"cookietimeout,omitempty"` + Count float64 `json:"__count,omitempty"` + CurState string `json:"curstate,omitempty"` + DBProfileName string `json:"dbprofilename,omitempty"` + DisablePrimaryOnDown string `json:"disableprimaryondown,omitempty"` + DNSOverHTTPS string `json:"dnsoverhttps,omitempty"` + DNSProfileName string `json:"dnsprofilename,omitempty"` + DNSRecordType string `json:"dnsrecordtype,omitempty"` + DNSVServerName string `json:"dnsvservername,omitempty"` + Domain string `json:"domain,omitempty"` + DomainName string `json:"domainname,omitempty"` + DownStateFlush string `json:"downstateflush,omitempty"` + DTLS string `json:"dtls,omitempty"` + Gt2gb string `json:"gt2gb,omitempty"` + HomePage string `json:"homepage,omitempty"` + HTTPProfileName string `json:"httpprofilename,omitempty"` + HTTPSRedirectURL string `json:"httpsredirecturl,omitempty"` + ICMPVsrResponse string `json:"icmpvsrresponse,omitempty"` + InsertVServerIPPort string `json:"insertvserveripport,omitempty"` + IP string `json:"ip,omitempty"` + IPMask string `json:"ipmask,omitempty"` + IPPattern string `json:"ippattern,omitempty"` + IPSet string `json:"ipset,omitempty"` + IPv46 string `json:"ipv46,omitempty"` + L2Conn string `json:"l2conn,omitempty"` + LBVServer string `json:"lbvserver,omitempty"` + ListenPolicy string `json:"listenpolicy,omitempty"` + ListenPriority int `json:"listenpriority,omitempty"` + MSSQLServerVersion string `json:"mssqlserverversion,omitempty"` + MySQLCharacterSet int `json:"mysqlcharacterset,omitempty"` + MySQLProtocolVersion int `json:"mysqlprotocolversion,omitempty"` + MySQLServerCapabilities int `json:"mysqlservercapabilities,omitempty"` + MySQLServerVersion string `json:"mysqlserverversion,omitempty"` + Name string `json:"name,omitempty"` + NetProfile string `json:"netprofile,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NgName string `json:"ngname,omitempty"` + NoDefaultBindings string `json:"nodefaultbindings,omitempty"` + OracleServerVersion string `json:"oracleserverversion,omitempty"` + PersistenceBackup string `json:"persistencebackup,omitempty"` + PersistenceID int `json:"persistenceid,omitempty"` + PersistenceType string `json:"persistencetype,omitempty"` + PersistMask string `json:"persistmask,omitempty"` + Port int `json:"port,omitempty"` + Precedence string `json:"precedence,omitempty"` + ProbePort int `json:"probeport,omitempty"` + ProbeProtocol string `json:"probeprotocol,omitempty"` + ProbeSuccessResponseCode string `json:"probesuccessresponsecode,omitempty"` + Push string `json:"push,omitempty"` + PushLabel string `json:"pushlabel,omitempty"` + PushMultiClients string `json:"pushmulticlients,omitempty"` + PushVServer string `json:"pushvserver,omitempty"` + QUICProfileName string `json:"quicprofilename,omitempty"` + Range int `json:"range,omitempty"` + Redirect string `json:"redirect,omitempty"` + RedirectFromPort int `json:"redirectfromport,omitempty"` + RedirectPortRewrite string `json:"redirectportrewrite,omitempty"` + RedirectURL string `json:"redirecturl,omitempty"` + RHIState string `json:"rhistate,omitempty"` + RTSPNAT string `json:"rtspnat,omitempty"` + RuleType int `json:"ruletype,omitempty"` + ServiceName string `json:"servicename,omitempty"` + ServiceType string `json:"servicetype,omitempty"` + SiteDomainTTL int `json:"sitedomainttl,omitempty"` + SOBackupAction string `json:"sobackupaction,omitempty"` + SOMethod string `json:"somethod,omitempty"` + SOPersistence string `json:"sopersistence,omitempty"` + SOPersistenceTimeout int `json:"sopersistencetimeout,omitempty"` + SOThreshold int `json:"sothreshold,omitempty"` + State string `json:"state,omitempty"` + StateChangeTimeMsec int `json:"statechangetimemsec,omitempty"` + StateChangeTimeSec string `json:"statechangetimesec,omitempty"` + StateUpdate string `json:"stateupdate,omitempty"` + Status int `json:"status,omitempty"` + TargetLBVServer string `json:"targetlbvserver,omitempty"` + TargetType string `json:"targettype,omitempty"` + TargetVServer string `json:"targetvserver,omitempty"` + TCPProbePort int `json:"tcpprobeport,omitempty"` + TCPProfileName string `json:"tcpprofilename,omitempty"` + TD int `json:"td,omitempty"` + TicksSinceLastStateChange int `json:"tickssincelaststatechange,omitempty"` + Timeout int `json:"timeout,omitempty"` + TTL int `json:"ttl,omitempty"` + TypeField string `json:"type,omitempty"` + URL string `json:"url,omitempty"` + V6PersistMaskLen int `json:"v6persistmasklen,omitempty"` + Value string `json:"value,omitempty"` + Version int `json:"version,omitempty"` + VIPHeader string `json:"vipheader,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type CSPolicyBinding struct { + CSPolicyCRVServerBinding []any `json:"cspolicy_crvserver_binding,omitempty"` + CSPolicyCSPolicyLabelBinding []any `json:"cspolicy_cspolicylabel_binding,omitempty"` + CSPolicyCSVServerBinding []any `json:"cspolicy_csvserver_binding,omitempty"` + PolicyName string `json:"policyname,omitempty"` +} + +type CSVServerLBVServerBinding struct { + CookieIPPort string `json:"cookieipport,omitempty"` + Hits int `json:"hits,omitempty"` + LBVServer string `json:"lbvserver,omitempty"` + Name string `json:"name,omitempty"` + TargetVServer string `json:"targetvserver,omitempty"` + VServerID string `json:"vserverid,omitempty"` +} diff --git a/nitrogo/models/db.go b/nitrogo/models/db.go new file mode 100644 index 0000000..5c6fbbf --- /dev/null +++ b/nitrogo/models/db.go @@ -0,0 +1,22 @@ +package models + +// db configuration structs +type DBUser struct { + Count float64 `json:"__count,omitempty"` + LoggedIn bool `json:"loggedin,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Password string `json:"password,omitempty"` + Username string `json:"username,omitempty"` +} + +type DBDBProfile struct { + ConMultiplex string `json:"conmultiplex,omitempty"` + Count float64 `json:"__count,omitempty"` + EnableCachingConMuxOff string `json:"enablecachingconmuxoff,omitempty"` + InterpretQuery string `json:"interpretquery,omitempty"` + KCDAccount string `json:"kcdaccount,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + RefCnt int `json:"refcnt,omitempty"` + Stickiness string `json:"stickiness,omitempty"` +} diff --git a/nitrogo/models/dns.go b/nitrogo/models/dns.go new file mode 100644 index 0000000..50612d4 --- /dev/null +++ b/nitrogo/models/dns.go @@ -0,0 +1,521 @@ +package models + +// dns configuration structs +type DNSNSECRec struct { + Count float64 `json:"__count,omitempty"` + ECSSubnet string `json:"ecssubnet,omitempty"` + Hostname string `json:"hostname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NextNSEC string `json:"nextnsec,omitempty"` + NextRecs []string `json:"nextrecs,omitempty"` + TTL int `json:"ttl,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type DNSTxtRec struct { + AuthType string `json:"authtype,omitempty"` + Count float64 `json:"__count,omitempty"` + Domain string `json:"domain,omitempty"` + ECSSubnet string `json:"ecssubnet,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + RecordID int `json:"recordid,omitempty"` + String []string `json:"String,omitempty"` + TTL int `json:"ttl,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type DNSZone struct { + Count float64 `json:"__count,omitempty"` + DNSSECOffload string `json:"dnssecoffload,omitempty"` + Flags int `json:"flags,omitempty"` + KeyName []string `json:"keyname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NSEC string `json:"nsec,omitempty"` + ProxyMode string `json:"proxymode,omitempty"` + TypeField string `json:"type,omitempty"` + ZoneName string `json:"zonename,omitempty"` +} + +type DNSPolicyLabelBinding struct { + DNSPolicyLabelDNSPolicyBinding []any `json:"dnspolicylabel_dnspolicy_binding,omitempty"` + DNSPolicyLabelPolicyBindingBinding []any `json:"dnspolicylabel_policybinding_binding,omitempty"` + LabelName string `json:"labelname,omitempty"` +} + +type DNSDSFile struct { + KeyName string `json:"keyname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type DNSNegativeCacheRecords struct { + Count float64 `json:"__count,omitempty"` + ECSSubnet string `json:"ecssubnet,omitempty"` + Hostname string `json:"hostname,omitempty"` + NegCacheType string `json:"negcachetype,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + PEID int `json:"peid,omitempty"` + QueryType string `json:"querytype,omitempty"` + RDClient string `json:"rdclient,omitempty"` + TTL int `json:"ttl,omitempty"` +} + +type DNSPolicyLabelDNSPolicyBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type DNSPtrRec struct { + AuthType string `json:"authtype,omitempty"` + Count float64 `json:"__count,omitempty"` + Domain string `json:"domain,omitempty"` + ECSSubnet string `json:"ecssubnet,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + ReverseDomain string `json:"reversedomain,omitempty"` + TTL int `json:"ttl,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type DNSZoneDomainBinding struct { + Domain string `json:"domain,omitempty"` + NextRecs []string `json:"nextrecs,omitempty"` + ZoneName string `json:"zonename,omitempty"` +} + +type DNSZoneBinding struct { + DNSZoneDNSKeyBinding []any `json:"dnszone_dnskey_binding,omitempty"` + DNSZoneGSLBDomainBinding []any `json:"dnszone_gslbdomain_binding,omitempty"` + ZoneName string `json:"zonename,omitempty"` +} + +type DNSGlobalDNSPolicyBinding struct { + FlowType int `json:"flowtype,omitempty"` + GlobalBindType string `json:"globalbindtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type DNSNameServer struct { + ClMonOwner int `json:"clmonowner,omitempty"` + ClMonView int `json:"clmonview,omitempty"` + Count float64 `json:"__count,omitempty"` + DNSProfileName string `json:"dnsprofilename,omitempty"` + DNSVServerName string `json:"dnsvservername,omitempty"` + IP string `json:"ip,omitempty"` + Local bool `json:"local,omitempty"` + NameServerState string `json:"nameserverstate,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Port int `json:"port,omitempty"` + ServiceName string `json:"servicename,omitempty"` + State string `json:"state,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type DNSPolicyDNSPolicyLabelBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type DNSSrvRec struct { + AuthType string `json:"authtype,omitempty"` + Count float64 `json:"__count,omitempty"` + Domain string `json:"domain,omitempty"` + ECSSubnet string `json:"ecssubnet,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + Port int `json:"port,omitempty"` + Priority int `json:"priority,omitempty"` + Target string `json:"target,omitempty"` + TTL int `json:"ttl,omitempty"` + TypeField string `json:"type,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type DNSViewBinding struct { + DNSViewDNSPolicyBinding []any `json:"dnsview_dnspolicy_binding,omitempty"` + DNSViewGSLBServiceBinding []any `json:"dnsview_gslbservice_binding,omitempty"` + ViewName string `json:"viewname,omitempty"` +} + +type DNSPolicyLabel struct { + Count float64 `json:"__count,omitempty"` + Description string `json:"description,omitempty"` + FlowType int `json:"flowtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Hits int `json:"hits,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + IsDefault bool `json:"isdefault,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NumPol int `json:"numpol,omitempty"` + Priority int `json:"priority,omitempty"` + Transform string `json:"transform,omitempty"` +} + +type DNSProxyRecords struct { + NegRecType string `json:"negrectype,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type DNSNSRec struct { + AuthType string `json:"authtype,omitempty"` + Count float64 `json:"__count,omitempty"` + Domain string `json:"domain,omitempty"` + ECSSubnet string `json:"ecssubnet,omitempty"` + NameServer string `json:"nameserver,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + TTL int `json:"ttl,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type DNSPolicyDNSGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type DNSPolicy struct { + ActionName string `json:"actionname,omitempty"` + Builtin []string `json:"builtin,omitempty"` + CacheBypass string `json:"cachebypass,omitempty"` + Count float64 `json:"__count,omitempty"` + Description string `json:"description,omitempty"` + Drop string `json:"drop,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + LogAction string `json:"logaction,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PreferredLocation string `json:"preferredlocation,omitempty"` + PreferredLocList []string `json:"preferredloclist,omitempty"` + Rule string `json:"rule,omitempty"` + UndefHits int `json:"undefhits,omitempty"` + ViewName string `json:"viewname,omitempty"` +} + +type DNSAction struct { + ActionName string `json:"actionname,omitempty"` + ActionType string `json:"actiontype,omitempty"` + Builtin []string `json:"builtin,omitempty"` + CacheBypass string `json:"cachebypass,omitempty"` + Count float64 `json:"__count,omitempty"` + DNSProfileName string `json:"dnsprofilename,omitempty"` + Drop string `json:"drop,omitempty"` + Feature string `json:"feature,omitempty"` + IPAddress []string `json:"ipaddress,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PreferredLocList []string `json:"preferredloclist,omitempty"` + TTL int `json:"ttl,omitempty"` + ViewName string `json:"viewname,omitempty"` +} + +type DNSGlobalBinding struct { + DNSGlobalDNSPolicyBinding []any `json:"dnsglobal_dnspolicy_binding,omitempty"` +} + +type DNSSOARec struct { + AuthType string `json:"authtype,omitempty"` + Contact string `json:"contact,omitempty"` + Count float64 `json:"__count,omitempty"` + Domain string `json:"domain,omitempty"` + ECSSubnet string `json:"ecssubnet,omitempty"` + Expire int `json:"expire,omitempty"` + Minimum int `json:"minimum,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + OriginServer string `json:"originserver,omitempty"` + Refresh int `json:"refresh,omitempty"` + Retry int `json:"retry,omitempty"` + Serial int `json:"serial,omitempty"` + TTL int `json:"ttl,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type DNSPolicy64Binding struct { + DNSPolicy64LBVServerBinding []any `json:"dnspolicy64_lbvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type DNSPolicyBinding struct { + DNSPolicyDNSGlobalBinding []any `json:"dnspolicy_dnsglobal_binding,omitempty"` + DNSPolicyDNSPolicyLabelBinding []any `json:"dnspolicy_dnspolicylabel_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type DNSZoneDNSKeyBinding struct { + Expires int `json:"expires,omitempty"` + KeyName []string `json:"keyname,omitempty"` + SigInceptionTime []any `json:"siginceptiontime,omitempty"` + Signed int `json:"signed,omitempty"` + ZoneName string `json:"zonename,omitempty"` +} + +type DNSPolicy64LBVServerBinding struct { + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type DNSSuffix struct { + Count float64 `json:"__count,omitempty"` + DNSSuffix string `json:"Dnssuffix,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type DNSParameter struct { + AutoSaveKeyOps string `json:"autosavekeyops,omitempty"` + Builtin []string `json:"builtin,omitempty"` + CacheECSZeroPrefix string `json:"cacheecszeroprefix,omitempty"` + CacheHitBypass string `json:"cachehitbypass,omitempty"` + CacheNoExpire string `json:"cachenoexpire,omitempty"` + CacheRecords string `json:"cacherecords,omitempty"` + DNS64Timeout int `json:"dns64timeout,omitempty"` + DNSRootReferral string `json:"dnsrootreferral,omitempty"` + DNSSec string `json:"dnssec,omitempty"` + ECSMaxSubnets int `json:"ecsmaxsubnets,omitempty"` + Feature string `json:"feature,omitempty"` + MaxCacheSize int `json:"maxcachesize,omitempty"` + MaxNegativeCacheSize int `json:"maxnegativecachesize,omitempty"` + MaxNegCacheTTL int `json:"maxnegcachettl,omitempty"` + MaxPipeline int `json:"maxpipeline,omitempty"` + MaxTTL int `json:"maxttl,omitempty"` + MaxUDPPacketSize int `json:"maxudppacketsize,omitempty"` + MinTTL int `json:"minttl,omitempty"` + NameLookupPriority string `json:"namelookuppriority,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NXDomainRateLimitThreshold int `json:"nxdomainratelimitthreshold,omitempty"` + NXDomainThresholdCrossed int `json:"nxdomainthresholdcrossed,omitempty"` + Recursion string `json:"recursion,omitempty"` + ResolutionOrder string `json:"resolutionorder,omitempty"` + ResolverMaxActiveResolutions int `json:"resolvermaxactiveresolutions,omitempty"` + ResolverMaxTCPConnections int `json:"resolvermaxtcpconnections,omitempty"` + ResolverMaxTCPTimeout int `json:"resolvermaxtcptimeout,omitempty"` + Retries int `json:"retries,omitempty"` + SplitPktQueryProcessing string `json:"splitpktqueryprocessing,omitempty"` + ZoneTransfer string `json:"zonetransfer,omitempty"` +} + +type DNSAction64 struct { + ActionName string `json:"actionname,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + ExcludeRule string `json:"excluderule,omitempty"` + Feature string `json:"feature,omitempty"` + MappedRule string `json:"mappedrule,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Prefix string `json:"prefix,omitempty"` +} + +type DNSCnameRec struct { + AliasName string `json:"aliasname,omitempty"` + AuthType string `json:"authtype,omitempty"` + CanonicalName string `json:"canonicalname,omitempty"` + Count float64 `json:"__count,omitempty"` + ECSSubnet string `json:"ecssubnet,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + TTL int `json:"ttl,omitempty"` + TypeField string `json:"type,omitempty"` + VServerName string `json:"vservername,omitempty"` +} + +type DNSPolicy64 struct { + Action string `json:"action,omitempty"` + Count float64 `json:"__count,omitempty"` + Description string `json:"description,omitempty"` + Hits int `json:"hits,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule string `json:"rule,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type DNSProfile struct { + CacheECSResponses string `json:"cacheecsresponses,omitempty"` + CacheNegativeResponses string `json:"cachenegativeresponses,omitempty"` + CacheRecords string `json:"cacherecords,omitempty"` + Count float64 `json:"__count,omitempty"` + DNSAnswerSecLogging string `json:"dnsanswerseclogging,omitempty"` + DNSErrorLogging string `json:"dnserrorlogging,omitempty"` + DNSExtendedLogging string `json:"dnsextendedlogging,omitempty"` + DNSProfileName string `json:"dnsprofilename,omitempty"` + DNSQueryLogging string `json:"dnsquerylogging,omitempty"` + DropMultiQueryRequest string `json:"dropmultiqueryrequest,omitempty"` + InsertECS string `json:"insertecs,omitempty"` + MaxCacheableECSPrefixLength int `json:"maxcacheableecsprefixlength,omitempty"` + MaxCacheableECSPrefixLength6 int `json:"maxcacheableecsprefixlength6,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + RecursiveResolution string `json:"recursiveresolution,omitempty"` + ReferenceCount int `json:"referencecount,omitempty"` + ReplaceECS string `json:"replaceecs,omitempty"` +} + +type DNSViewGSLBServiceBinding struct { + GSLBServiceName string `json:"gslbservicename,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + ViewName string `json:"viewname,omitempty"` +} + +type DNSAAAARec struct { + AuthType string `json:"authtype,omitempty"` + Count float64 `json:"__count,omitempty"` + ECSSubnet string `json:"ecssubnet,omitempty"` + Hostname string `json:"hostname,omitempty"` + IPv6Address string `json:"ipv6address,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + TTL int `json:"ttl,omitempty"` + TypeField string `json:"type,omitempty"` + VServerName string `json:"vservername,omitempty"` +} + +type DNSView struct { + Count float64 `json:"__count,omitempty"` + Flags int `json:"flags,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ViewName string `json:"viewname,omitempty"` +} + +type DNSKey struct { + ActivationTimeStr string `json:"activationtimestr,omitempty"` + Algorithm string `json:"algorithm,omitempty"` + AutoRollover string `json:"autorollover,omitempty"` + Count float64 `json:"__count,omitempty"` + CreateTimeStr string `json:"createtimestr,omitempty"` + DeletionTimeStr string `json:"deletiontimestr,omitempty"` + Expires int `json:"expires,omitempty"` + ExpiryTimeStr string `json:"expirytimestr,omitempty"` + FilenamePrefix string `json:"filenameprefix,omitempty"` + KeyName string `json:"keyname,omitempty"` + KeySize int `json:"keysize,omitempty"` + KeyType string `json:"keytype,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NotificationPeriod int `json:"notificationperiod,omitempty"` + Password string `json:"password,omitempty"` + PrivateKey string `json:"privatekey,omitempty"` + PublicKey string `json:"publickey,omitempty"` + Revoke bool `json:"revoke,omitempty"` + RolloverFailRC int `json:"rolloverfailrc,omitempty"` + RolloverMethod string `json:"rollovermethod,omitempty"` + Src string `json:"src,omitempty"` + State string `json:"state,omitempty"` + Tag int `json:"tag,omitempty"` + TTL int `json:"ttl,omitempty"` + TypeField string `json:"type,omitempty"` + Units1 string `json:"units1,omitempty"` + Units2 string `json:"units2,omitempty"` + ZoneName string `json:"zonename,omitempty"` +} + +type DNSNaptrRec struct { + AuthType string `json:"authtype,omitempty"` + Count float64 `json:"__count,omitempty"` + Domain string `json:"domain,omitempty"` + ECSSubnet string `json:"ecssubnet,omitempty"` + Flags string `json:"flags,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + Order int `json:"order,omitempty"` + Preference int `json:"preference,omitempty"` + RecordID int `json:"recordid,omitempty"` + Regexp string `json:"regexp,omitempty"` + Replacement string `json:"replacement,omitempty"` + Services string `json:"services,omitempty"` + TTL int `json:"ttl,omitempty"` + TypeField string `json:"type,omitempty"` + VServerName string `json:"vservername,omitempty"` +} + +type DNSViewDNSPolicyBinding struct { + DNSPolicyName string `json:"dnspolicyname,omitempty"` + ViewName string `json:"viewname,omitempty"` +} + +type DNSSubnetCache struct { + All bool `json:"all,omitempty"` + Count float64 `json:"__count,omitempty"` + ECSSubnet string `json:"ecssubnet,omitempty"` + Hostname string `json:"hostname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NextRecs []string `json:"nextrecs,omitempty"` + NodeID int `json:"nodeid,omitempty"` +} + +type DNSAddRec struct { + AuthType string `json:"authtype,omitempty"` + Count float64 `json:"__count,omitempty"` + ECSSubnet string `json:"ecssubnet,omitempty"` + Hostname string `json:"hostname,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + TTL int `json:"ttl,omitempty"` + TypeField string `json:"type,omitempty"` + VServerName string `json:"vservername,omitempty"` +} + +type DNSMXRec struct { + AuthType string `json:"authtype,omitempty"` + Count float64 `json:"__count,omitempty"` + Domain string `json:"domain,omitempty"` + ECSSubnet string `json:"ecssubnet,omitempty"` + MX string `json:"mx,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + Pref int `json:"pref,omitempty"` + TTL int `json:"ttl,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type DNSCAARec struct { + AuthType string `json:"authtype,omitempty"` + Count float64 `json:"__count,omitempty"` + Domain string `json:"domain,omitempty"` + ECSSubnet string `json:"ecssubnet,omitempty"` + Flag string `json:"flag,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + RecordID int `json:"recordid,omitempty"` + Tag string `json:"tag,omitempty"` + TTL int `json:"ttl,omitempty"` + TypeField string `json:"type,omitempty"` + ValueString string `json:"valuestring,omitempty"` +} + +type DNSPolicyLabelPolicyBindingBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} diff --git a/nitrogo/models/dos.go b/nitrogo/models/dos.go new file mode 100644 index 0000000..c8ecdd0 --- /dev/null +++ b/nitrogo/models/dos.go @@ -0,0 +1,11 @@ +// Derived from Citrix ADC Nitro Go SDK (https://github.com/netscaler/adc-nitro-go) +// Originally licensed under the Apache License, Version 2.0 +// Modifications by Adam Crawford, 2026 + +package models + +type DOSPolicy struct { + Name string `json:"name,omitempty"` + QDepth int `json:"qdepth,omitempty"` + CltDetectRate int `json:"cltdetectrate,omitempty"` +} diff --git a/nitrogo/models/dps.go b/nitrogo/models/dps.go new file mode 100644 index 0000000..45ae245 --- /dev/null +++ b/nitrogo/models/dps.go @@ -0,0 +1,11 @@ +package models + +// dps configuration structs +type DPSParameter struct { + Builtin []string `json:"builtin,omitempty"` + CustomerID string `json:"customerid,omitempty"` + Deployment string `json:"deployment,omitempty"` + Feature string `json:"feature,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ServiceURL string `json:"serviceurl,omitempty"` +} diff --git a/nitrogo/models/endpoint.go b/nitrogo/models/endpoint.go new file mode 100644 index 0000000..1b56182 --- /dev/null +++ b/nitrogo/models/endpoint.go @@ -0,0 +1,11 @@ +package models + +// endpoint configuration structs +type EndpointInfo struct { + Count float64 `json:"__count,omitempty"` + EndpointKind string `json:"endpointkind,omitempty"` + EndpointLabelsJSON string `json:"endpointlabelsjson,omitempty"` + EndpointMetadata string `json:"endpointmetadata,omitempty"` + EndpointName string `json:"endpointname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} diff --git a/nitrogo/models/feo.go b/nitrogo/models/feo.go new file mode 100644 index 0000000..cbbe73a --- /dev/null +++ b/nitrogo/models/feo.go @@ -0,0 +1,109 @@ +package models + +// feo configuration structs +type FEOPolicyCSVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type FEOGlobalBinding struct { + FEOGlobalFEOPolicyBinding []any `json:"feoglobal_feopolicy_binding,omitempty"` +} + +type FEOPolicyFEOGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type FEOPolicyLBVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type FEOPolicy struct { + Action string `json:"action,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule string `json:"rule,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type FEOAction struct { + Builtin []string `json:"builtin,omitempty"` + CacheMaxAge int `json:"cachemaxage,omitempty"` + ClientSideMeasurements bool `json:"clientsidemeasurements,omitempty"` + ConvertImportToLink bool `json:"convertimporttolink,omitempty"` + Count float64 `json:"__count,omitempty"` + CSSCombine bool `json:"csscombine,omitempty"` + CSSFlattenImports bool `json:"cssflattenimports,omitempty"` + CSSImgInline bool `json:"cssimginline,omitempty"` + CSSInline bool `json:"cssinline,omitempty"` + CSSMinify bool `json:"cssminify,omitempty"` + CSSMoveToHead bool `json:"cssmovetohead,omitempty"` + DNSShards []string `json:"dnsshards,omitempty"` + DomainSharding string `json:"domainsharding,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + HTMLMinify bool `json:"htmlminify,omitempty"` + HTMLRmAttribQuotes bool `json:"htmlrmattribquotes,omitempty"` + HTMLRmDefaultAttribs bool `json:"htmlrmdefaultattribs,omitempty"` + HTMLTrimURLs bool `json:"htmltrimurls,omitempty"` + ImgAddDimensions bool `json:"imgadddimensions,omitempty"` + ImgGifToPNG bool `json:"imggiftopng,omitempty"` + ImgInline bool `json:"imginline,omitempty"` + ImgLazyLoad bool `json:"imglazyload,omitempty"` + ImgShrinkForMobile bool `json:"imgshrinkformobile,omitempty"` + ImgShrinkToAttrib bool `json:"imgshrinktoattrib,omitempty"` + ImgToJPEGXR bool `json:"imgtojpegxr,omitempty"` + ImgToWebP bool `json:"imgtowebp,omitempty"` + ImgWeaken bool `json:"imgweaken,omitempty"` + JPGOptimize bool `json:"jpgoptimize,omitempty"` + JPGProgressive bool `json:"jpgprogressive,omitempty"` + JSCombine bool `json:"jscombine,omitempty"` + JSInline bool `json:"jsinline,omitempty"` + JSMinify bool `json:"jsminify,omitempty"` + JSMoveToEnd bool `json:"jsmovetoend,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PageExtendCache bool `json:"pageextendcache,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type FEOPolicyBinding struct { + FEOPolicyCSVServerBinding []any `json:"feopolicy_csvserver_binding,omitempty"` + FEOPolicyFEOGlobalBinding []any `json:"feopolicy_feoglobal_binding,omitempty"` + FEOPolicyLBVServerBinding []any `json:"feopolicy_lbvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type FEOParameter struct { + Builtin []string `json:"builtin,omitempty"` + CSSInlineThresSize int `json:"cssinlinethressize,omitempty"` + Feature string `json:"feature,omitempty"` + ImgInlineThresSize int `json:"imginlinethressize,omitempty"` + JPEGQualityPercent int `json:"jpegqualitypercent,omitempty"` + JSInlineThresSize int `json:"jsinlinethressize,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type FEOGlobalFEOPolicyBinding struct { + GlobalBindType string `json:"globalbindtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} diff --git a/nitrogo/models/filter.go b/nitrogo/models/filter.go new file mode 100644 index 0000000..c570c28 --- /dev/null +++ b/nitrogo/models/filter.go @@ -0,0 +1,113 @@ +// Derived from Citrix ADC Nitro Go SDK (https://github.com/netscaler/adc-nitro-go) +// Originally licensed under the Apache License, Version 2.0 +// Modifications by Adam Crawford, 2026 + +package models + +type FilterPolicyFilterGlobalBinding struct { + BoundTo string `json:"boundto,omitempty"` + Priority int `json:"priority,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + Name string `json:"name,omitempty"` +} + +type FilterPreBodyInjection struct { + PreBody string `json:"prebody,omitempty"` + SystemIID string `json:"systemiid,omitempty"` +} + +type FilterGlobalBinding struct { +} + +type FilterGlobalFilterPolicyBinding struct { + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + State string `json:"state,omitempty"` +} + +type FilterPolicy struct { + Name string `json:"name,omitempty"` + Rule string `json:"rule,omitempty"` + ReqAction string `json:"reqaction,omitempty"` + ResAction string `json:"resaction,omitempty"` + Hits string `json:"hits,omitempty"` +} + +type FilterPolicyLBVServerBinding struct { + BoundTo string `json:"boundto,omitempty"` + Priority int `json:"priority,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + Name string `json:"name,omitempty"` +} + +type FilterHTMLInjectionParameter struct { + Rate int `json:"rate,omitempty"` + Frequency int `json:"frequency,omitempty"` + Strict string `json:"strict,omitempty"` + HTMLSearchLen int `json:"htmlsearchlen,omitempty"` + Builtin string `json:"builtin,omitempty"` + Feature string `json:"feature,omitempty"` +} + +type FilterHTMLInjectionVariable struct { + Variable string `json:"variable,omitempty"` + Value string `json:"value,omitempty"` + Builtin string `json:"builtin,omitempty"` + Feature string `json:"feature,omitempty"` + Type string `json:"type,omitempty"` +} + +type FilterAction struct { + Name string `json:"name,omitempty"` + Qual string `json:"qual,omitempty"` + ServiceName string `json:"servicename,omitempty"` + Value string `json:"value,omitempty"` + RespCode int `json:"respcode,omitempty"` + Page string `json:"page,omitempty"` + IsDefault string `json:"isdefault,omitempty"` + Builtin string `json:"builtin,omitempty"` + Feature string `json:"feature,omitempty"` +} + +type FilterPolicyGlobalBinding struct { + BoundTo string `json:"boundto,omitempty"` + Priority uint32 `json:"priority,omitempty"` + ActivePolicy uint32 `json:"activepolicy,omitempty"` + Name string `json:"name,omitempty"` +} + +type FilterPolicyVServerBinding struct { + BoundTo string `json:"boundto,omitempty"` + Priority uint32 `json:"priority,omitempty"` + ActivePolicy uint32 `json:"activepolicy,omitempty"` + Name string `json:"name,omitempty"` +} + +type FilterPostBodyInjection struct { + PostBody string `json:"postbody,omitempty"` + SystemIID string `json:"systemiid,omitempty"` +} + +type FilterGlobalPolicyBinding struct { + PolicyName string `json:"policyname,omitempty"` + Priority uint32 `json:"priority,omitempty"` + State string `json:"state,omitempty"` +} + +type FilterPolicyBinding struct { + Name string `json:"name,omitempty"` +} + +type FilterPolicyCRVServerBinding struct { + BoundTo string `json:"boundto,omitempty"` + Priority int `json:"priority,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + Name string `json:"name,omitempty"` +} + +type FilterPolicyCSVServerBinding struct { + BoundTo string `json:"boundto,omitempty"` + Priority int `json:"priority,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + Name string `json:"name,omitempty"` +} diff --git a/nitrogo/models/gslb.go b/nitrogo/models/gslb.go new file mode 100644 index 0000000..41aae49 --- /dev/null +++ b/nitrogo/models/gslb.go @@ -0,0 +1,588 @@ +package models + +// gslb configuration structs +type GSLBServiceGroupBinding struct { + GSLBServiceGroupGSLBServiceGroupMemberBinding []any `json:"gslbservicegroup_gslbservicegroupmember_binding,omitempty"` + GSLBServiceGroupLBMonitorBinding []any `json:"gslbservicegroup_lbmonitor_binding,omitempty"` + GSLBServiceGroupServiceGroupEntityMonBindingsBinding []any `json:"gslbservicegroup_servicegroupentitymonbindings_binding,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` +} + +type GSLBServiceGroup struct { + AppFlowLog string `json:"appflowlog,omitempty"` + AutoDelayedTROFS string `json:"autodelayedtrofs,omitempty"` + AutoScale string `json:"autoscale,omitempty"` + CIP string `json:"cip,omitempty"` + CIPHeader string `json:"cipheader,omitempty"` + ClMonOwner int `json:"clmonowner,omitempty"` + ClMonView int `json:"clmonview,omitempty"` + CltTimeout int `json:"clttimeout,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Delay int `json:"delay,omitempty"` + DownStateFlush string `json:"downstateflush,omitempty"` + DupWeight int `json:"dup_weight,omitempty"` + Graceful string `json:"graceful,omitempty"` + GroupCount int `json:"groupcount,omitempty"` + GSLB string `json:"gslb,omitempty"` + HashID int `json:"hashid,omitempty"` + HealthMonitor string `json:"healthmonitor,omitempty"` + IncludeMembers bool `json:"includemembers,omitempty"` + IP string `json:"ip,omitempty"` + MaxBandwidth int `json:"maxbandwidth,omitempty"` + MaxClient int `json:"maxclient,omitempty"` + MonitorNameSvc string `json:"monitor_name_svc,omitempty"` + MonStatCode int `json:"monstatcode,omitempty"` + MonStatParam1 int `json:"monstatparam1,omitempty"` + MonStatParam2 int `json:"monstatparam2,omitempty"` + MonStatParam3 int `json:"monstatparam3,omitempty"` + MonThreshold int `json:"monthreshold,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NoDefaultBindings string `json:"nodefaultbindings,omitempty"` + NumOfConnections int `json:"numofconnections,omitempty"` + Order int `json:"order,omitempty"` + Port int `json:"port,omitempty"` + PublicIP string `json:"publicip,omitempty"` + PublicPort int `json:"publicport,omitempty"` + ServerName string `json:"servername,omitempty"` + ServiceConfType bool `json:"serviceconftype,omitempty"` + ServiceGroupEffectiveState string `json:"servicegroupeffectivestate,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` + ServiceIPStr string `json:"serviceipstr,omitempty"` + ServiceType string `json:"servicetype,omitempty"` + SiteName string `json:"sitename,omitempty"` + SitePersistence string `json:"sitepersistence,omitempty"` + SitePrefix string `json:"siteprefix,omitempty"` + State string `json:"state,omitempty"` + StateChangeTimeMsec int `json:"statechangetimemsec,omitempty"` + StateUpdateReason int `json:"stateupdatereason,omitempty"` + SvrEffGSLBState string `json:"svreffgslbstate,omitempty"` + SvrState string `json:"svrstate,omitempty"` + SvrTimeout int `json:"svrtimeout,omitempty"` + Value string `json:"value,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type GSLBLDNSEntries struct { + Count float64 `json:"__count,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + NumSites int `json:"numsites,omitempty"` + RTT []any `json:"rtt,omitempty"` + SiteName string `json:"sitename,omitempty"` + TTL int `json:"ttl,omitempty"` +} + +type GSLBServiceGroupServiceGroupEntityMonBindingsBinding struct { + HashID int `json:"hashid,omitempty"` + LastResponse string `json:"lastresponse,omitempty"` + MonitorName string `json:"monitor_name,omitempty"` + MonitorState string `json:"monitor_state,omitempty"` + MonitorCurrentFailedProbes int `json:"monitorcurrentfailedprobes,omitempty"` + MonitorTotalFailedProbes int `json:"monitortotalfailedprobes,omitempty"` + MonitorTotalProbes int `json:"monitortotalprobes,omitempty"` + Order int `json:"order,omitempty"` + Passive bool `json:"passive,omitempty"` + Port int `json:"port,omitempty"` + PublicIP string `json:"publicip,omitempty"` + PublicPort int `json:"publicport,omitempty"` + ServiceGroupEntName2 string `json:"servicegroupentname2,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` + SitePrefix string `json:"siteprefix,omitempty"` + State string `json:"state,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type GSLBVServerLBPolicyBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type GSLBVServer struct { + ActiveServices int `json:"activeservices,omitempty"` + AppFlowLog string `json:"appflowlog,omitempty"` + BackupIP string `json:"backupip,omitempty"` + BackupLBMethod string `json:"backuplbmethod,omitempty"` + BackupSessionTimeout int `json:"backupsessiontimeout,omitempty"` + BackupVServer string `json:"backupvserver,omitempty"` + Comment string `json:"comment,omitempty"` + ConsiderEffectiveState string `json:"considereffectivestate,omitempty"` + CookieDomain string `json:"cookie_domain,omitempty"` + CookieTimeout int `json:"cookietimeout,omitempty"` + Count float64 `json:"__count,omitempty"` + CurrentActiveOrder string `json:"currentactiveorder,omitempty"` + CurState string `json:"curstate,omitempty"` + DisablePrimaryOnDown string `json:"disableprimaryondown,omitempty"` + DNSRecordType string `json:"dnsrecordtype,omitempty"` + DomainName string `json:"domainname,omitempty"` + DynamicWeight string `json:"dynamicweight,omitempty"` + ECS string `json:"ecs,omitempty"` + ECSAddrValidation string `json:"ecsaddrvalidation,omitempty"` + EDR string `json:"edr,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Health int `json:"health,omitempty"` + IPType string `json:"iptype,omitempty"` + ISCName string `json:"iscname,omitempty"` + LBMethod string `json:"lbmethod,omitempty"` + LBRRReason int `json:"lbrrreason,omitempty"` + MIR string `json:"mir,omitempty"` + Name string `json:"name,omitempty"` + Netmask string `json:"netmask,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NoDefaultBindings string `json:"nodefaultbindings,omitempty"` + Order int `json:"order,omitempty"` + OrderThreshold int `json:"orderthreshold,omitempty"` + PersistenceID int `json:"persistenceid,omitempty"` + PersistenceType string `json:"persistencetype,omitempty"` + PersistMask string `json:"persistmask,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + Rule string `json:"rule,omitempty"` + ServerName string `json:"servername,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` + ServiceName string `json:"servicename,omitempty"` + ServiceType string `json:"servicetype,omitempty"` + SiteDomainTTL int `json:"sitedomainttl,omitempty"` + SitePersistence string `json:"sitepersistence,omitempty"` + SOBackupAction string `json:"sobackupaction,omitempty"` + SOMethod string `json:"somethod,omitempty"` + SOPersistence string `json:"sopersistence,omitempty"` + SOPersistenceTimeout int `json:"sopersistencetimeout,omitempty"` + SOThreshold int `json:"sothreshold,omitempty"` + State string `json:"state,omitempty"` + StateChangeTimeMsec int `json:"statechangetimemsec,omitempty"` + StateChangeTimeSec string `json:"statechangetimesec,omitempty"` + Status int `json:"status,omitempty"` + TicksSinceLastStateChange int `json:"tickssincelaststatechange,omitempty"` + Timeout int `json:"timeout,omitempty"` + ToggleOrder string `json:"toggleorder,omitempty"` + Tolerance int `json:"tolerance,omitempty"` + TotalServices int `json:"totalservices,omitempty"` + TTL int `json:"ttl,omitempty"` + TypeField string `json:"type,omitempty"` + V6NetmaskLen int `json:"v6netmasklen,omitempty"` + V6PersistMaskLen int `json:"v6persistmasklen,omitempty"` + VSvrBindSvcIP string `json:"vsvrbindsvcip,omitempty"` + VSvrBindSvcPort int `json:"vsvrbindsvcport,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type GSLBDomainLBMonitorBinding struct { + CustomHeaders string `json:"customheaders,omitempty"` + GRPCHealthCheck string `json:"grpchealthcheck,omitempty"` + GRPCServiceName string `json:"grpcservicename,omitempty"` + GRPCStatusCode int `json:"grpcstatuscode,omitempty"` + HTTPRequest string `json:"httprequest,omitempty"` + IPTunnel string `json:"iptunnel,omitempty"` + LastResponse string `json:"lastresponse,omitempty"` + MonitorCurrentFailedProbes int `json:"monitorcurrentfailedprobes,omitempty"` + MonitorName string `json:"monitorname,omitempty"` + MonitorTotalFailedProbes int `json:"monitortotalfailedprobes,omitempty"` + MonitorTotalProbes int `json:"monitortotalprobes,omitempty"` + MonStatCode int `json:"monstatcode,omitempty"` + MonState string `json:"monstate,omitempty"` + Name string `json:"name,omitempty"` + RespCode string `json:"respcode,omitempty"` + ResponseTime int `json:"responsetime,omitempty"` + ServiceName string `json:"servicename,omitempty"` + VServerName string `json:"vservername,omitempty"` +} + +type GSLBParameter struct { + AutomaticConfigSync string `json:"automaticconfigsync,omitempty"` + Builtin []string `json:"builtin,omitempty"` + DropLDNSReq string `json:"dropldnsreq,omitempty"` + Feature string `json:"feature,omitempty"` + Flags int `json:"flags,omitempty"` + GSLBConfigSyncMonitor string `json:"gslbconfigsyncmonitor,omitempty"` + GSLBSvcStateDelayTime int `json:"gslbsvcstatedelaytime,omitempty"` + GSLBSyncInterval int `json:"gslbsyncinterval,omitempty"` + GSLBSyncLocFiles string `json:"gslbsynclocfiles,omitempty"` + GSLBSyncMode string `json:"gslbsyncmode,omitempty"` + GSLBSyncSaveConfigCommand string `json:"gslbsyncsaveconfigcommand,omitempty"` + Incarnation int `json:"incarnation,omitempty"` + LDNSEntryTimeout int `json:"ldnsentrytimeout,omitempty"` + LDNSMask string `json:"ldnsmask,omitempty"` + LDNSProbeOrder []string `json:"ldnsprobeorder,omitempty"` + MEPKeepaliveTimeout int `json:"mepkeepalivetimeout,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OverridePersistencyForOrder string `json:"overridepersistencyfororder,omitempty"` + RTTTolerance int `json:"rtttolerance,omitempty"` + SvcStateLearningTime int `json:"svcstatelearningtime,omitempty"` + UndefAction string `json:"undefaction,omitempty"` + V6LDNSMaskLen int `json:"v6ldnsmasklen,omitempty"` +} + +type GSLBVServerSpilloverPolicyBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type GSLBVServerBinding struct { + GSLBVServerGSLBDomainBinding []any `json:"gslbvserver_gslbdomain_binding,omitempty"` + GSLBVServerGSLBServiceBinding []any `json:"gslbvserver_gslbservice_binding,omitempty"` + GSLBVServerGSLBServiceGroupBinding []any `json:"gslbvserver_gslbservicegroup_binding,omitempty"` + GSLBVServerGSLBServiceGroupMemberBinding []any `json:"gslbvserver_gslbservicegroupmember_binding,omitempty"` + GSLBVServerLBPolicyBinding []any `json:"gslbvserver_lbpolicy_binding,omitempty"` + GSLBVServerSpilloverPolicyBinding []any `json:"gslbvserver_spilloverpolicy_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type GSLBServiceDNSViewBinding struct { + ServiceName string `json:"servicename,omitempty"` + ViewIP string `json:"viewip,omitempty"` + ViewName string `json:"viewname,omitempty"` +} + +type GSLBServiceGroupGSLBServiceGroupMemberBinding struct { + Delay int `json:"delay,omitempty"` + Graceful string `json:"graceful,omitempty"` + GSLBThreshold int `json:"gslbthreshold,omitempty"` + HashID int `json:"hashid,omitempty"` + IP string `json:"ip,omitempty"` + Order int `json:"order,omitempty"` + OrderStr string `json:"orderstr,omitempty"` + Port int `json:"port,omitempty"` + PreferredLocation string `json:"preferredlocation,omitempty"` + PublicIP string `json:"publicip,omitempty"` + PublicPort int `json:"publicport,omitempty"` + ServerName string `json:"servername,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` + SitePrefix string `json:"siteprefix,omitempty"` + State string `json:"state,omitempty"` + StateChangeTimeSec string `json:"statechangetimesec,omitempty"` + SvrState string `json:"svrstate,omitempty"` + Threshold string `json:"threshold,omitempty"` + TicksSinceLastStateChange int `json:"tickssincelaststatechange,omitempty"` + TROFSDelay int `json:"trofsdelay,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type GSLBDomainGSLBServiceGroupBinding struct { + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` +} + +type GSLBDomain struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type GSLBVServerGSLBServiceGroupMemberBinding struct { + CurState string `json:"curstate,omitempty"` + DynamicWeight string `json:"dynamicweight,omitempty"` + GSLBThreshold int `json:"gslbthreshold,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + OrderStr string `json:"orderstr,omitempty"` + Port int `json:"port,omitempty"` + PreferredLocation string `json:"preferredlocation,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` + ServiceType string `json:"servicetype,omitempty"` + SitePersistCookie string `json:"sitepersistcookie,omitempty"` + SvcSitePersistence string `json:"svcsitepersistence,omitempty"` + SvrEffGSLBState string `json:"svreffgslbstate,omitempty"` + ThresholdValue int `json:"thresholdvalue,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type GSLBSiteGSLBServiceBinding struct { + CnameEntry string `json:"cnameentry,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + Port int `json:"port,omitempty"` + ServiceName string `json:"servicename,omitempty"` + ServiceType string `json:"servicetype,omitempty"` + SiteName string `json:"sitename,omitempty"` + State string `json:"state,omitempty"` +} + +type GSLBSiteGSLBServiceGroupMemberBinding struct { + IPAddress string `json:"ipaddress,omitempty"` + Port int `json:"port,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` + ServiceType string `json:"servicetype,omitempty"` + SiteName string `json:"sitename,omitempty"` + State string `json:"state,omitempty"` +} + +type GSLBSiteBinding struct { + GSLBSiteGSLBServiceBinding []any `json:"gslbsite_gslbservice_binding,omitempty"` + GSLBSiteGSLBServiceGroupBinding []any `json:"gslbsite_gslbservicegroup_binding,omitempty"` + GSLBSiteGSLBServiceGroupMemberBinding []any `json:"gslbsite_gslbservicegroupmember_binding,omitempty"` + SiteName string `json:"sitename,omitempty"` +} + +type GSLBDomainGSLBServiceBinding struct { + CnameEntry string `json:"cnameentry,omitempty"` + CumulativeWeight int `json:"cumulativeweight,omitempty"` + DynamicConfWt int `json:"dynamicconfwt,omitempty"` + GSLBThreshold int `json:"gslbthreshold,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + Port int `json:"port,omitempty"` + ServiceName string `json:"servicename,omitempty"` + ServiceType string `json:"servicetype,omitempty"` + State string `json:"state,omitempty"` + SvrEffGSLBState string `json:"svreffgslbstate,omitempty"` + VServerName string `json:"vservername,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type GSLBVServerGSLBServiceGroupBinding struct { + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` +} + +type GSLBSiteGSLBServiceGroupBinding struct { + ServiceGroupName string `json:"servicegroupname,omitempty"` + ServiceType string `json:"servicetype,omitempty"` + SiteName string `json:"sitename,omitempty"` +} + +type GSLBServiceGroupLBMonitorBinding struct { + HashID int `json:"hashid,omitempty"` + MonitorName string `json:"monitor_name,omitempty"` + MonState string `json:"monstate,omitempty"` + MonWeight int `json:"monweight,omitempty"` + Order int `json:"order,omitempty"` + Passive bool `json:"passive,omitempty"` + Port int `json:"port,omitempty"` + PublicIP string `json:"publicip,omitempty"` + PublicPort int `json:"publicport,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` + SitePrefix string `json:"siteprefix,omitempty"` + State string `json:"state,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type GSLBVServerDomainBinding struct { + BackupIP string `json:"backupip,omitempty"` + BackupIPFlag bool `json:"backupipflag,omitempty"` + CookieDomain string `json:"cookie_domain,omitempty"` + CookieDomainFlag bool `json:"cookie_domainflag,omitempty"` + CookieTimeout int `json:"cookietimeout,omitempty"` + DomainName string `json:"domainname,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + SiteDomainTTL int `json:"sitedomainttl,omitempty"` + TTL int `json:"ttl,omitempty"` +} + +type GSLBDomainBinding struct { + GSLBDomainGSLBServiceBinding []any `json:"gslbdomain_gslbservice_binding,omitempty"` + GSLBDomainGSLBServiceGroupBinding []any `json:"gslbdomain_gslbservicegroup_binding,omitempty"` + GSLBDomainGSLBServiceGroupMemberBinding []any `json:"gslbdomain_gslbservicegroupmember_binding,omitempty"` + GSLBDomainGSLBVServerBinding []any `json:"gslbdomain_gslbvserver_binding,omitempty"` + GSLBDomainLBMonitorBinding []any `json:"gslbdomain_lbmonitor_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type GSLBServiceBinding struct { + GSLBServiceDNSViewBinding []any `json:"gslbservice_dnsview_binding,omitempty"` + GSLBServiceLBMonitorBinding []any `json:"gslbservice_lbmonitor_binding,omitempty"` + ServiceName string `json:"servicename,omitempty"` +} + +type GSLBServiceLBMonitorBinding struct { + FailedProbes int `json:"failedprobes,omitempty"` + LastResponse string `json:"lastresponse,omitempty"` + MonitorName string `json:"monitor_name,omitempty"` + MonitorState string `json:"monitor_state,omitempty"` + MonitorCurrentFailedProbes int `json:"monitorcurrentfailedprobes,omitempty"` + MonitorTotalFailedProbes int `json:"monitortotalfailedprobes,omitempty"` + MonitorTotalProbes int `json:"monitortotalprobes,omitempty"` + MonStatCode int `json:"monstatcode,omitempty"` + MonState string `json:"monstate,omitempty"` + MonStatParam1 int `json:"monstatparam1,omitempty"` + MonStatParam2 int `json:"monstatparam2,omitempty"` + MonStatParam3 int `json:"monstatparam3,omitempty"` + ResponseTime int `json:"responsetime,omitempty"` + ServiceName string `json:"servicename,omitempty"` + TotalFailedProbes int `json:"totalfailedprobes,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type GSLBDomainGSLBServiceGroupMemberBinding struct { + GSLBThreshold int `json:"gslbthreshold,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + Port int `json:"port,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` + ServiceType string `json:"servicetype,omitempty"` + SvrEffGSLBState string `json:"svreffgslbstate,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type GSLBService struct { + AppFlowLog string `json:"appflowlog,omitempty"` + CIP string `json:"cip,omitempty"` + CIPHeader string `json:"cipheader,omitempty"` + ClMonOwner int `json:"clmonowner,omitempty"` + ClMonView int `json:"clmonview,omitempty"` + CltTimeout int `json:"clttimeout,omitempty"` + CnameEntry string `json:"cnameentry,omitempty"` + Comment string `json:"comment,omitempty"` + CookieTimeout int `json:"cookietimeout,omitempty"` + Count float64 `json:"__count,omitempty"` + DownStateFlush string `json:"downstateflush,omitempty"` + GLSBSvcHealthDescr string `json:"glsbsvchealthdescr,omitempty"` + GSLB string `json:"gslb,omitempty"` + GSLBSvcHealth int `json:"gslbsvchealth,omitempty"` + GSLBSvcStats int `json:"gslbsvcstats,omitempty"` + GSLBThreshold int `json:"gslbthreshold,omitempty"` + HashID int `json:"hashid,omitempty"` + HealthMonitor string `json:"healthmonitor,omitempty"` + IP string `json:"ip,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + MaxAAAUsers int `json:"maxaaausers,omitempty"` + MaxBandwidth int `json:"maxbandwidth,omitempty"` + MaxClient int `json:"maxclient,omitempty"` + MonitorNameSvc string `json:"monitor_name_svc,omitempty"` + MonitorState string `json:"monitor_state,omitempty"` + MonState string `json:"monstate,omitempty"` + MonThreshold int `json:"monthreshold,omitempty"` + NAPTRDomainTTL int `json:"naptrdomainttl,omitempty"` + NAPTROrder int `json:"naptrorder,omitempty"` + NAPTRPreference int `json:"naptrpreference,omitempty"` + NAPTRReplacement string `json:"naptrreplacement,omitempty"` + NAPTRServices string `json:"naptrservices,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NoDefaultBindings string `json:"nodefaultbindings,omitempty"` + Port int `json:"port,omitempty"` + PreferredLocation string `json:"preferredlocation,omitempty"` + PublicIP string `json:"publicip,omitempty"` + PublicPort int `json:"publicport,omitempty"` + ServerName string `json:"servername,omitempty"` + ServiceName string `json:"servicename,omitempty"` + ServiceType string `json:"servicetype,omitempty"` + SiteName string `json:"sitename,omitempty"` + SitePersistence string `json:"sitepersistence,omitempty"` + SitePrefix string `json:"siteprefix,omitempty"` + State string `json:"state,omitempty"` + StateChangeTimeSec string `json:"statechangetimesec,omitempty"` + SvrEffGSLBState string `json:"svreffgslbstate,omitempty"` + SvrState string `json:"svrstate,omitempty"` + SvrTimeout int `json:"svrtimeout,omitempty"` + Threshold string `json:"threshold,omitempty"` + TicksSinceLastStateChange int `json:"tickssincelaststatechange,omitempty"` + ViewIP string `json:"viewip,omitempty"` + ViewName string `json:"viewname,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type GSLBConfig struct { + Command string `json:"command,omitempty"` + Debug bool `json:"debug,omitempty"` + ForceSync string `json:"forcesync,omitempty"` + NoWarn bool `json:"nowarn,omitempty"` + Preview bool `json:"preview,omitempty"` + SaveConfig bool `json:"saveconfig,omitempty"` +} + +type GSLBRunningConfig struct { + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Response string `json:"response,omitempty"` +} + +type GSLBSite struct { + BackupParentList []string `json:"backupparentlist,omitempty"` + CLIP string `json:"clip,omitempty"` + Count float64 `json:"__count,omitempty"` + CurBackupParentIP string `json:"curbackupparentip,omitempty"` + MetricExchange string `json:"metricexchange,omitempty"` + NAPTRReplacementSuffix string `json:"naptrreplacementsuffix,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NWMetricExchange string `json:"nwmetricexchange,omitempty"` + OldName string `json:"oldname,omitempty"` + ParentSite string `json:"parentsite,omitempty"` + PersistenceMEPStatus string `json:"persistencemepstatus,omitempty"` + PublicCLIP string `json:"publicclip,omitempty"` + PublicIP string `json:"publicip,omitempty"` + SessionExchange string `json:"sessionexchange,omitempty"` + SiteIPAddress string `json:"siteipaddress,omitempty"` + SiteName string `json:"sitename,omitempty"` + SitePassword string `json:"sitepassword,omitempty"` + SiteState string `json:"sitestate,omitempty"` + SiteType string `json:"sitetype,omitempty"` + Status string `json:"status,omitempty"` + TriggerMonitor string `json:"triggermonitor,omitempty"` + Version int `json:"version,omitempty"` +} + +type GSLBSyncStatus struct { + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Response string `json:"response,omitempty"` + Summary bool `json:"summary,omitempty"` +} + +type GSLBLDNSEntry struct { + IPAddress string `json:"ipaddress,omitempty"` +} + +type GSLBVServerGSLBServiceBinding struct { + CnameEntry string `json:"cnameentry,omitempty"` + CumulativeWeight int `json:"cumulativeweight,omitempty"` + CurState string `json:"curstate,omitempty"` + DomainName string `json:"domainname,omitempty"` + DynamicConfWt int `json:"dynamicconfwt,omitempty"` + GSLBBoundSvcType string `json:"gslbboundsvctype,omitempty"` + GSLBThreshold int `json:"gslbthreshold,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + ISCName string `json:"iscname,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + OrderStr string `json:"orderstr,omitempty"` + Port int `json:"port,omitempty"` + PreferredLocation string `json:"preferredlocation,omitempty"` + ServiceName string `json:"servicename,omitempty"` + SitePersistCookie string `json:"sitepersistcookie,omitempty"` + SvcSitePersistence string `json:"svcsitepersistence,omitempty"` + SvrEffGSLBState string `json:"svreffgslbstate,omitempty"` + ThresholdValue int `json:"thresholdvalue,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type GSLBDomainGSLBVServerBinding struct { + BackupLBMethod string `json:"backuplbmethod,omitempty"` + CIP string `json:"cip,omitempty"` + CustomHeaders string `json:"customheaders,omitempty"` + DNSRecordType string `json:"dnsrecordtype,omitempty"` + DynamicWeight string `json:"dynamicweight,omitempty"` + EDR string `json:"edr,omitempty"` + LBMethod string `json:"lbmethod,omitempty"` + MIR string `json:"mir,omitempty"` + Name string `json:"name,omitempty"` + Netmask string `json:"netmask,omitempty"` + PersistenceID int `json:"persistenceid,omitempty"` + PersistenceType string `json:"persistencetype,omitempty"` + PersistMask string `json:"persistmask,omitempty"` + ServiceType string `json:"servicetype,omitempty"` + SiteName string `json:"sitename,omitempty"` + SitePersistence string `json:"sitepersistence,omitempty"` + SitePrefix string `json:"siteprefix,omitempty"` + State string `json:"state,omitempty"` + StateChangeTimeSec string `json:"statechangetimesec,omitempty"` + V6NetmaskLen int `json:"v6netmasklen,omitempty"` + V6PersistMaskLen int `json:"v6persistmasklen,omitempty"` + VServerName string `json:"vservername,omitempty"` +} diff --git a/nitrogo/models/ha.go b/nitrogo/models/ha.go new file mode 100644 index 0000000..d0aed69 --- /dev/null +++ b/nitrogo/models/ha.go @@ -0,0 +1,100 @@ +package models + +// ha configuration structs +type HASyncFailures struct { + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Response string `json:"response,omitempty"` +} + +type HANodeRouteMonitor6Binding struct { + Flags int `json:"flags,omitempty"` + ID int `json:"id,omitempty"` + Netmask string `json:"netmask,omitempty"` + RouteMonitor string `json:"routemonitor,omitempty"` + RouteMonitorState string `json:"routemonitorstate,omitempty"` +} + +type HANodeRouteMonitorBinding struct { + Flags int `json:"flags,omitempty"` + ID int `json:"id,omitempty"` + Netmask string `json:"netmask,omitempty"` + RouteMonitor string `json:"routemonitor,omitempty"` + RouteMonitorState string `json:"routemonitorstate,omitempty"` +} + +type HAFiles struct { + Mode []string `json:"mode,omitempty"` +} + +type HANodeCIBinding struct { + EnaIfaces string `json:"enaifaces,omitempty"` + ID int `json:"id,omitempty"` + RouteMonitor string `json:"routemonitor,omitempty"` +} + +type HAFailover struct { + Force bool `json:"force,omitempty"` +} + +type HANode struct { + CompletedFlipTime int `json:"completedfliptime,omitempty"` + Count float64 `json:"__count,omitempty"` + CurFlips int `json:"curflips,omitempty"` + DeadInterval int `json:"deadinterval,omitempty"` + DisIfaces string `json:"disifaces,omitempty"` + EnaIfaces string `json:"enaifaces,omitempty"` + FailSafe string `json:"failsafe,omitempty"` + Flags int `json:"flags,omitempty"` + HAHeartbeatIfaces string `json:"haheartbeatifaces,omitempty"` + HAMonIfaces string `json:"hamonifaces,omitempty"` + HAProp string `json:"haprop,omitempty"` + HAStatus string `json:"hastatus,omitempty"` + HASync string `json:"hasync,omitempty"` + HASyncFailureReason string `json:"hasyncfailurereason,omitempty"` + HelloInterval int `json:"hellointerval,omitempty"` + ID int `json:"id,omitempty"` + Ifaces string `json:"ifaces,omitempty"` + Inc string `json:"inc,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + MasterStateTime int `json:"masterstatetime,omitempty"` + MaxFlips int `json:"maxflips,omitempty"` + MaxFlipTime int `json:"maxfliptime,omitempty"` + Name string `json:"name,omitempty"` + Netmask string `json:"netmask,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PFIfaces string `json:"pfifaces,omitempty"` + RouteMonitor string `json:"routemonitor,omitempty"` + RouteMonitorState string `json:"routemonitorstate,omitempty"` + RPCNodePassword string `json:"rpcnodepassword,omitempty"` + SSL2 string `json:"ssl2,omitempty"` + State string `json:"state,omitempty"` + SyncStatusStrictMode string `json:"syncstatusstrictmode,omitempty"` + SyncVLAN int `json:"syncvlan,omitempty"` +} + +type HANodeFISBinding struct { + EnaIfaces string `json:"enaifaces,omitempty"` + ID int `json:"id,omitempty"` + Name string `json:"name,omitempty"` + RouteMonitor string `json:"routemonitor,omitempty"` +} + +type HANodeBinding struct { + HANodeCIBinding []any `json:"hanode_ci_binding,omitempty"` + HANodeFISBinding []any `json:"hanode_fis_binding,omitempty"` + HANodePartialFailureInterfacesBinding []any `json:"hanode_partialfailureinterfaces_binding,omitempty"` + HANodeRouteMonitor6Binding []any `json:"hanode_routemonitor6_binding,omitempty"` + HANodeRouteMonitorBinding []any `json:"hanode_routemonitor_binding,omitempty"` + ID int `json:"id,omitempty"` +} + +type HANodePartialFailureInterfacesBinding struct { + ID int `json:"id,omitempty"` + PFIfaces string `json:"pfifaces,omitempty"` + RouteMonitor string `json:"routemonitor,omitempty"` +} + +type HASync struct { + Force bool `json:"force,omitempty"` + Save string `json:"save,omitempty"` +} diff --git a/nitrogo/models/ica.go b/nitrogo/models/ica.go new file mode 100644 index 0000000..7dd0b5b --- /dev/null +++ b/nitrogo/models/ica.go @@ -0,0 +1,130 @@ +package models + +// ica configuration structs +type ICAPolicyCRVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type ICAGlobalICAPolicyBinding struct { + FlowType int `json:"flowtype,omitempty"` + GlobalBindType string `json:"globalbindtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type ICALatencyProfile struct { + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + IsDefault bool `json:"isdefault,omitempty"` + L7LatencyMaxNotifyCount int `json:"l7latencymaxnotifycount,omitempty"` + L7LatencyMonitoring string `json:"l7latencymonitoring,omitempty"` + L7LatencyNotifyInterval int `json:"l7latencynotifyinterval,omitempty"` + L7LatencyThresholdFactor int `json:"l7latencythresholdfactor,omitempty"` + L7LatencyWaitTime int `json:"l7latencywaittime,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + RefCnt int `json:"refcnt,omitempty"` +} + +type ICAAction struct { + AccessProfileName string `json:"accessprofilename,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + IsDefault bool `json:"isdefault,omitempty"` + LatencyProfileName string `json:"latencyprofilename,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ReferenceCount int `json:"referencecount,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type ICAPolicyVPNVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type ICAGlobalBinding struct { + ICAGlobalICAPolicyBinding []any `json:"icaglobal_icapolicy_binding,omitempty"` +} + +type ICAParameter struct { + Builtin []string `json:"builtin,omitempty"` + DFPersistence string `json:"dfpersistence,omitempty"` + EDTLossTolerant string `json:"edtlosstolerant,omitempty"` + EDTPMTUDDF string `json:"edtpmtuddf,omitempty"` + EDTPMTUDDFTimeout int `json:"edtpmtuddftimeout,omitempty"` + EDTPMTUDRediscovery string `json:"edtpmtudrediscovery,omitempty"` + EnableSROnHAFailover string `json:"enablesronhafailover,omitempty"` + HDXInsightNonNSAP string `json:"hdxinsightnonnsap,omitempty"` + InsightOnlyToDirector string `json:"insightonlytodirector,omitempty"` + L7LatencyFrequency int `json:"l7latencyfrequency,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type ICAPolicyICAGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type ICAPolicy struct { + Action string `json:"action,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + LogAction string `json:"logaction,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule string `json:"rule,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type ICAPolicyBinding struct { + ICAPolicyCRVServerBinding []any `json:"icapolicy_crvserver_binding,omitempty"` + ICAPolicyICAGlobalBinding []any `json:"icapolicy_icaglobal_binding,omitempty"` + ICAPolicyVPNVServerBinding []any `json:"icapolicy_vpnvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type ICAAccessProfile struct { + Builtin []string `json:"builtin,omitempty"` + ClientAudioRedirection string `json:"clientaudioredirection,omitempty"` + ClientClipboardRedirection string `json:"clientclipboardredirection,omitempty"` + ClientCOMPortRedirection string `json:"clientcomportredirection,omitempty"` + ClientDriveRedirection string `json:"clientdriveredirection,omitempty"` + ClientPrinterRedirection string `json:"clientprinterredirection,omitempty"` + ClientTwainDeviceRedirection string `json:"clienttwaindeviceredirection,omitempty"` + ClientUSBDriveRedirection string `json:"clientusbdriveredirection,omitempty"` + ConnectClientLPTPorts string `json:"connectclientlptports,omitempty"` + Count float64 `json:"__count,omitempty"` + DragAndDrop string `json:"draganddrop,omitempty"` + Feature string `json:"feature,omitempty"` + FIDO2Redirection string `json:"fido2redirection,omitempty"` + IsDefault bool `json:"isdefault,omitempty"` + LocalRemoteDataSharing string `json:"localremotedatasharing,omitempty"` + MultiStream string `json:"multistream,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + RefCnt int `json:"refcnt,omitempty"` + SmartCardRedirection string `json:"smartcardredirection,omitempty"` + WIARedirection string `json:"wiaredirection,omitempty"` +} diff --git a/nitrogo/models/ipsec.go b/nitrogo/models/ipsec.go new file mode 100644 index 0000000..60a1d72 --- /dev/null +++ b/nitrogo/models/ipsec.go @@ -0,0 +1,38 @@ +package models + +// ipsec configuration structs +type IPSECParameter struct { + EncAlgo []string `json:"encalgo,omitempty"` + HashAlgo []string `json:"hashalgo,omitempty"` + IKERetryInterval int `json:"ikeretryinterval,omitempty"` + IKEVersion string `json:"ikeversion,omitempty"` + Lifetime int `json:"lifetime,omitempty"` + LivenessCheckInterval int `json:"livenesscheckinterval,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PerfectForwardSecrecy string `json:"perfectforwardsecrecy,omitempty"` + ReplayWindowSize int `json:"replaywindowsize,omitempty"` + ResponderOnly string `json:"responderonly,omitempty"` + RetransmissionTime int `json:"retransmissiontime,omitempty"` +} + +type IPSECProfile struct { + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + EncAlgo []string `json:"encalgo,omitempty"` + Feature string `json:"feature,omitempty"` + HashAlgo []string `json:"hashalgo,omitempty"` + IKERetryInterval int `json:"ikeretryinterval,omitempty"` + IKEVersion string `json:"ikeversion,omitempty"` + Lifetime int `json:"lifetime,omitempty"` + LivenessCheckInterval int `json:"livenesscheckinterval,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PeerPublicKey string `json:"peerpublickey,omitempty"` + PerfectForwardSecrecy string `json:"perfectforwardsecrecy,omitempty"` + PrivateKey string `json:"privatekey,omitempty"` + PSK string `json:"psk,omitempty"` + PublicKey string `json:"publickey,omitempty"` + ReplayWindowSize int `json:"replaywindowsize,omitempty"` + ResponderOnly string `json:"responderonly,omitempty"` + RetransmissionTime int `json:"retransmissiontime,omitempty"` +} diff --git a/nitrogo/models/ipsecalg.go b/nitrogo/models/ipsecalg.go new file mode 100644 index 0000000..6b70a9d --- /dev/null +++ b/nitrogo/models/ipsecalg.go @@ -0,0 +1,25 @@ +package models + +// ipsecalg configuration structs +type IPSECALGSession struct { + Count float64 `json:"__count,omitempty"` + DestIP string `json:"destip,omitempty"` + DestIPAlg string `json:"destip_alg,omitempty"` + NATIP string `json:"natip,omitempty"` + NATIPAlg string `json:"natip_alg,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + SourceIP string `json:"sourceip,omitempty"` + SourceIPAlg string `json:"sourceip_alg,omitempty"` + SPIIn int `json:"spiin,omitempty"` + SPIOut int `json:"spiout,omitempty"` +} + +type IPSECALGProfile struct { + ConnFailover string `json:"connfailover,omitempty"` + Count float64 `json:"__count,omitempty"` + ESPGateTimeout int `json:"espgatetimeout,omitempty"` + ESPSessionTimeout int `json:"espsessiontimeout,omitempty"` + IKESessionTimeout int `json:"ikesessiontimeout,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} diff --git a/nitrogo/models/kafka.go b/nitrogo/models/kafka.go new file mode 100644 index 0000000..0b49be6 --- /dev/null +++ b/nitrogo/models/kafka.go @@ -0,0 +1,22 @@ +package models + +// kafka configuration structs +type KafkaCluster struct { + ActiveSvc int `json:"activesvc,omitempty"` + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NumTopics int `json:"numtopics,omitempty"` + TopicName string `json:"topicname,omitempty"` + TotalSvc int `json:"totalsvc,omitempty"` +} + +type KafkaClusterBinding struct { + KafkaClusterServiceGroupBinding []any `json:"kafkacluster_servicegroup_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type KafkaClusterServiceGroupBinding struct { + Name string `json:"name,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` +} diff --git a/nitrogo/models/lb.go b/nitrogo/models/lb.go new file mode 100644 index 0000000..caa8bd3 --- /dev/null +++ b/nitrogo/models/lb.go @@ -0,0 +1,1006 @@ +package models + +// lb configuration structs +type LBVServerRewritePolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type LBVServerFEOPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type LBMonBindings struct { + BoundServiceGroupSvrState string `json:"boundservicegroupsvrstate,omitempty"` + Count float64 `json:"__count,omitempty"` + MonitorName string `json:"monitorname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + State string `json:"state,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type LBVServerCSVServerBinding struct { + CacheType string `json:"cachetype,omitempty"` + CacheVServer string `json:"cachevserver,omitempty"` + Hits int `json:"hits,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + PIPolicyHits int `json:"pipolicyhits,omitempty"` + PolicyName string `json:"policyname,omitempty"` + PolicySubType int `json:"policysubtype,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type LBMonitorBinding struct { + LBMonitorMetricBinding []any `json:"lbmonitor_metric_binding,omitempty"` + LBMonitorSSLCertKeyBinding []any `json:"lbmonitor_sslcertkey_binding,omitempty"` + MonitorName string `json:"monitorname,omitempty"` +} + +type LBMonBindingsBinding struct { + LBMonBindingsGSLBServiceGroupBinding []any `json:"lbmonbindings_gslbservicegroup_binding,omitempty"` + LBMonBindingsServiceBinding []any `json:"lbmonbindings_service_binding,omitempty"` + LBMonBindingsServiceGroupBinding []any `json:"lbmonbindings_servicegroup_binding,omitempty"` + MonitorName string `json:"monitorname,omitempty"` +} + +type LBVServerBotPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type LBRoute6 struct { + Count float64 `json:"__count,omitempty"` + Flags string `json:"flags,omitempty"` + GatewayName string `json:"gatewayname,omitempty"` + Network string `json:"network,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + TD int `json:"td,omitempty"` +} + +type LBPolicyGSLBVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type LBVServerResponderPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type LBMonBindingsServiceBinding struct { + IPAddress string `json:"ipaddress,omitempty"` + MonitorName string `json:"monitorname,omitempty"` + MonSvcState string `json:"monsvcstate,omitempty"` + Port int `json:"port,omitempty"` + ServiceName string `json:"servicename,omitempty"` + ServiceType string `json:"servicetype,omitempty"` + SvrState string `json:"svrstate,omitempty"` +} + +type LBVServerTransformPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type LBAction struct { + Builtin []string `json:"builtin,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ReferenceCount int `json:"referencecount,omitempty"` + TypeField string `json:"type,omitempty"` + UndefHits int `json:"undefhits,omitempty"` + Value []any `json:"value,omitempty"` +} + +type LBVServerAuditSyslogPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type LBGlobalBinding struct { + LBGlobalLBPolicyBinding []any `json:"lbglobal_lbpolicy_binding,omitempty"` +} + +type LBVServerAppFlowPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type LBRoute struct { + Count float64 `json:"__count,omitempty"` + Flags string `json:"flags,omitempty"` + GatewayName string `json:"gatewayname,omitempty"` + Netmask string `json:"netmask,omitempty"` + Network string `json:"network,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + TD int `json:"td,omitempty"` +} + +type LBMonitorServiceBinding struct { + DupState string `json:"dup_state,omitempty"` + DupWeight int `json:"dup_weight,omitempty"` + MonitorName string `json:"monitorname,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` + ServiceName string `json:"servicename,omitempty"` + State string `json:"state,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type LBVServerAppFWPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type LBVServerCachePolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type LBVServerBinding struct { + LBVServerAnalyticsProfileBinding []any `json:"lbvserver_analyticsprofile_binding,omitempty"` + LBVServerAppFlowPolicyBinding []any `json:"lbvserver_appflowpolicy_binding,omitempty"` + LBVServerAppFWPolicyBinding []any `json:"lbvserver_appfwpolicy_binding,omitempty"` + LBVServerAppQOEPolicyBinding []any `json:"lbvserver_appqoepolicy_binding,omitempty"` + LBVServerAuditNSLogPolicyBinding []any `json:"lbvserver_auditnslogpolicy_binding,omitempty"` + LBVServerAuditSyslogPolicyBinding []any `json:"lbvserver_auditsyslogpolicy_binding,omitempty"` + LBVServerAuthorizationPolicyBinding []any `json:"lbvserver_authorizationpolicy_binding,omitempty"` + LBVServerBotPolicyBinding []any `json:"lbvserver_botpolicy_binding,omitempty"` + LBVServerCachePolicyBinding []any `json:"lbvserver_cachepolicy_binding,omitempty"` + LBVServerCMPPolicyBinding []any `json:"lbvserver_cmppolicy_binding,omitempty"` + LBVServerContentInspectionPolicyBinding []any `json:"lbvserver_contentinspectionpolicy_binding,omitempty"` + LBVServerCSVServerBinding []any `json:"lbvserver_csvserver_binding,omitempty"` + LBVServerDNSPolicy64Binding []any `json:"lbvserver_dnspolicy64_binding,omitempty"` + LBVServerFEOPolicyBinding []any `json:"lbvserver_feopolicy_binding,omitempty"` + LBVServerLBPolicyBinding []any `json:"lbvserver_lbpolicy_binding,omitempty"` + LBVServerResponderPolicyBinding []any `json:"lbvserver_responderpolicy_binding,omitempty"` + LBVServerRewritePolicyBinding []any `json:"lbvserver_rewritepolicy_binding,omitempty"` + LBVServerServiceBinding []any `json:"lbvserver_service_binding,omitempty"` + LBVServerServiceGroupBinding []any `json:"lbvserver_servicegroup_binding,omitempty"` + LBVServerServiceGroupMemberBinding []any `json:"lbvserver_servicegroupmember_binding,omitempty"` + LBVServerSpilloverPolicyBinding []any `json:"lbvserver_spilloverpolicy_binding,omitempty"` + LBVServerTMTrafficPolicyBinding []any `json:"lbvserver_tmtrafficpolicy_binding,omitempty"` + LBVServerTransformPolicyBinding []any `json:"lbvserver_transformpolicy_binding,omitempty"` + LBVServerVideoOptimizationDetectionPolicyBinding []any `json:"lbvserver_videooptimizationdetectionpolicy_binding,omitempty"` + LBVServerVideoOptimizationPacingPolicyBinding []any `json:"lbvserver_videooptimizationpacingpolicy_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type LBPolicyLabelPolicyBindingBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type LBVServerContentInspectionPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type LBGlobalLBPolicyBinding struct { + FlowType int `json:"flowtype,omitempty"` + GlobalBindType string `json:"globalbindtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type LBVServerServiceBinding struct { + CookieIPPort string `json:"cookieipport,omitempty"` + CookieName string `json:"cookiename,omitempty"` + CurState string `json:"curstate,omitempty"` + DynamicWeight int `json:"dynamicweight,omitempty"` + IPv46 string `json:"ipv46,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + OrderStr string `json:"orderstr,omitempty"` + Port int `json:"port,omitempty"` + PreferredLocation string `json:"preferredlocation,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` + ServiceName string `json:"servicename,omitempty"` + ServiceType string `json:"servicetype,omitempty"` + VServerID string `json:"vserverid,omitempty"` + VSvrBindSvcIP string `json:"vsvrbindsvcip,omitempty"` + VSvrBindSvcPort int `json:"vsvrbindsvcport,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type LBVServerAppQOEPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type LBPolicyLBGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type LBGroup struct { + BackupPersistenceTimeout int `json:"backuppersistencetimeout,omitempty"` + CookieDomain string `json:"cookiedomain,omitempty"` + CookieName string `json:"cookiename,omitempty"` + Count float64 `json:"__count,omitempty"` + MasterVServer string `json:"mastervserver,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PersistenceBackup string `json:"persistencebackup,omitempty"` + PersistenceType string `json:"persistencetype,omitempty"` + PersistMask string `json:"persistmask,omitempty"` + Rule string `json:"rule,omitempty"` + TD int `json:"td,omitempty"` + Timeout int `json:"timeout,omitempty"` + UseVServerPersistency string `json:"usevserverpersistency,omitempty"` + V6PersistMaskLen int `json:"v6persistmasklen,omitempty"` +} + +type LBPolicyLabelLBPolicyBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type LBSIPParameters struct { + AddrPortVIP string `json:"addrportvip,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Feature string `json:"feature,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + RetryDur int `json:"retrydur,omitempty"` + RNATDstPort int `json:"rnatdstport,omitempty"` + RNATSecureDstPort int `json:"rnatsecuredstport,omitempty"` + RNATSecureSrcPort int `json:"rnatsecuresrcport,omitempty"` + RNATSrcPort int `json:"rnatsrcport,omitempty"` + SIP503RateThreshold int `json:"sip503ratethreshold,omitempty"` +} + +type LBVServerAnalyticsProfileBinding struct { + AnalyticsProfile string `json:"analyticsprofile,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` +} + +type LBWLMLBVServerBinding struct { + VServerName string `json:"vservername,omitempty"` + WLMName string `json:"wlmname,omitempty"` +} + +type LBVServerCMPPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type LBVServer struct { + ActiveServices int `json:"activeservices,omitempty"` + ADFSProxyProfile string `json:"adfsproxyprofile,omitempty"` + APIProfile string `json:"apiprofile,omitempty"` + AppFlowLog string `json:"appflowlog,omitempty"` + Authentication string `json:"authentication,omitempty"` + AuthenticationHost string `json:"authenticationhost,omitempty"` + Authn401 string `json:"authn401,omitempty"` + AuthnProfile string `json:"authnprofile,omitempty"` + AuthnVSName string `json:"authnvsname,omitempty"` + BackupLBMethod string `json:"backuplbmethod,omitempty"` + BackupPersistenceTimeout int `json:"backuppersistencetimeout,omitempty"` + BackupVServer string `json:"backupvserver,omitempty"` + BackupVServerStatus string `json:"backupvserverstatus,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + BypassAAAA string `json:"bypassaaaa,omitempty"` + Cacheable string `json:"cacheable,omitempty"` + CacheVServer string `json:"cachevserver,omitempty"` + CltTimeout int `json:"clttimeout,omitempty"` + Comment string `json:"comment,omitempty"` + ConnFailover string `json:"connfailover,omitempty"` + ConsolidatedLConn string `json:"consolidatedlconn,omitempty"` + ConsolidatedLConnGbl string `json:"consolidatedlconngbl,omitempty"` + CookieDomain string `json:"cookiedomain,omitempty"` + CookieName string `json:"cookiename,omitempty"` + Count float64 `json:"__count,omitempty"` + CurrentActiveOrder string `json:"currentactiveorder,omitempty"` + CurState string `json:"curstate,omitempty"` + DataLength int `json:"datalength,omitempty"` + DataOffset int `json:"dataoffset,omitempty"` + DBProfileName string `json:"dbprofilename,omitempty"` + DBSLB string `json:"dbslb,omitempty"` + DisablePrimaryOnDown string `json:"disableprimaryondown,omitempty"` + DNS64 string `json:"dns64,omitempty"` + DNSOverHTTPS string `json:"dnsoverhttps,omitempty"` + DNSProfileName string `json:"dnsprofilename,omitempty"` + DNSVServerName string `json:"dnsvservername,omitempty"` + Domain string `json:"domain,omitempty"` + DownStateFlush string `json:"downstateflush,omitempty"` + EffectiveState string `json:"effectivestate,omitempty"` + GroupName string `json:"groupname,omitempty"` + Gt2gb string `json:"gt2gb,omitempty"` + HashLength int `json:"hashlength,omitempty"` + Health int `json:"health,omitempty"` + HealthThreshold int `json:"healththreshold,omitempty"` + HomePage string `json:"homepage,omitempty"` + HTTPProfileName string `json:"httpprofilename,omitempty"` + HTTPSRedirectURL string `json:"httpsredirecturl,omitempty"` + ICMPVsrResponse string `json:"icmpvsrresponse,omitempty"` + InsertVServerIPPort string `json:"insertvserveripport,omitempty"` + IPMapping string `json:"ipmapping,omitempty"` + IPMask string `json:"ipmask,omitempty"` + IPPattern string `json:"ippattern,omitempty"` + IPSet string `json:"ipset,omitempty"` + IPv46 string `json:"ipv46,omitempty"` + IsGSLB bool `json:"isgslb,omitempty"` + L2Conn string `json:"l2conn,omitempty"` + LBMethod string `json:"lbmethod,omitempty"` + LBProfileName string `json:"lbprofilename,omitempty"` + LBRRReason int `json:"lbrrreason,omitempty"` + ListenPolicy string `json:"listenpolicy,omitempty"` + ListenPriority int `json:"listenpriority,omitempty"` + M string `json:"m,omitempty"` + MACModeRetainVLAN string `json:"macmoderetainvlan,omitempty"` + MapField string `json:"map,omitempty"` + MaxAutoscaleMembers int `json:"maxautoscalemembers,omitempty"` + MinAutoscaleMembers int `json:"minautoscalemembers,omitempty"` + MSSQLServerVersion string `json:"mssqlserverversion,omitempty"` + MySQLCharacterSet int `json:"mysqlcharacterset,omitempty"` + MySQLProtocolVersion int `json:"mysqlprotocolversion,omitempty"` + MySQLServerCapabilities int `json:"mysqlservercapabilities,omitempty"` + MySQLServerVersion string `json:"mysqlserverversion,omitempty"` + Name string `json:"name,omitempty"` + Netmask string `json:"netmask,omitempty"` + NetProfile string `json:"netprofile,omitempty"` + NewName string `json:"newname,omitempty"` + NewServiceRequest int `json:"newservicerequest,omitempty"` + NewServiceRequestIncrementInterval int `json:"newservicerequestincrementinterval,omitempty"` + NewServiceRequestUnit string `json:"newservicerequestunit,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NgName string `json:"ngname,omitempty"` + NoDefaultBindings string `json:"nodefaultbindings,omitempty"` + OracleServerVersion string `json:"oracleserverversion,omitempty"` + Order int `json:"order,omitempty"` + OrderThreshold int `json:"orderthreshold,omitempty"` + PersistAVPNo []any `json:"persistavpno,omitempty"` + PersistenceBackup string `json:"persistencebackup,omitempty"` + PersistenceType string `json:"persistencetype,omitempty"` + PersistMask string `json:"persistmask,omitempty"` + Port int `json:"port,omitempty"` + Precedence string `json:"precedence,omitempty"` + ProbePort int `json:"probeport,omitempty"` + ProbeProtocol string `json:"probeprotocol,omitempty"` + ProbeSuccessResponseCode string `json:"probesuccessresponsecode,omitempty"` + ProcessLocal string `json:"processlocal,omitempty"` + Push string `json:"push,omitempty"` + PushLabel string `json:"pushlabel,omitempty"` + PushMultiClients string `json:"pushmulticlients,omitempty"` + PushVServer string `json:"pushvserver,omitempty"` + QUICBridgeProfileName string `json:"quicbridgeprofilename,omitempty"` + QUICProfileName string `json:"quicprofilename,omitempty"` + Range int `json:"range,omitempty"` + RecursionAvailable string `json:"recursionavailable,omitempty"` + Redirect string `json:"redirect,omitempty"` + RedirectFromPort int `json:"redirectfromport,omitempty"` + RedirectPortRewrite string `json:"redirectportrewrite,omitempty"` + RedirURL string `json:"redirurl,omitempty"` + RedirURLFlags bool `json:"redirurlflags,omitempty"` + ResRule string `json:"resrule,omitempty"` + RetainConnectionsOnCluster string `json:"retainconnectionsoncluster,omitempty"` + RHIState string `json:"rhistate,omitempty"` + RTSPNAT string `json:"rtspnat,omitempty"` + Rule string `json:"rule,omitempty"` + RuleType int `json:"ruletype,omitempty"` + ServiceName string `json:"servicename,omitempty"` + ServiceType string `json:"servicetype,omitempty"` + Sessionless string `json:"sessionless,omitempty"` + SkipPersistency string `json:"skippersistency,omitempty"` + SOBackupAction string `json:"sobackupaction,omitempty"` + SOMethod string `json:"somethod,omitempty"` + SOPersistence string `json:"sopersistence,omitempty"` + SOPersistenceTimeout int `json:"sopersistencetimeout,omitempty"` + SOThreshold int `json:"sothreshold,omitempty"` + State string `json:"state,omitempty"` + StateChangeTimeMsec int `json:"statechangetimemsec,omitempty"` + StateChangeTimeSec string `json:"statechangetimesec,omitempty"` + StateChangeTimeSeconds int `json:"statechangetimeseconds,omitempty"` + Status int `json:"status,omitempty"` + TCPProbePort int `json:"tcpprobeport,omitempty"` + TCPProfileName string `json:"tcpprofilename,omitempty"` + TD int `json:"td,omitempty"` + ThresholdValue int `json:"thresholdvalue,omitempty"` + TicksSinceLastStateChange int `json:"tickssincelaststatechange,omitempty"` + Timeout int `json:"timeout,omitempty"` + ToggleOrder string `json:"toggleorder,omitempty"` + TOSID int `json:"tosid,omitempty"` + TotalServices int `json:"totalservices,omitempty"` + TROFSPersistence string `json:"trofspersistence,omitempty"` + TypeField string `json:"type,omitempty"` + V6NetmaskLen int `json:"v6netmasklen,omitempty"` + V6PersistMaskLen int `json:"v6persistmasklen,omitempty"` + Value string `json:"value,omitempty"` + Version int `json:"version,omitempty"` + VIPHeader string `json:"vipheader,omitempty"` + VSvrDynConnSOThreshold int `json:"vsvrdynconnsothreshold,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type LBVServerTMTrafficPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type LBMonitor struct { + AcctApplicationID []any `json:"acctapplicationid,omitempty"` + Action string `json:"action,omitempty"` + AlertRetries int `json:"alertretries,omitempty"` + Application string `json:"application,omitempty"` + Attribute string `json:"attribute,omitempty"` + AuthApplicationID []any `json:"authapplicationid,omitempty"` + BaseDN string `json:"basedn,omitempty"` + BindDN string `json:"binddn,omitempty"` + Count float64 `json:"__count,omitempty"` + CustomHeaders string `json:"customheaders,omitempty"` + Database string `json:"database,omitempty"` + DestIP string `json:"destip,omitempty"` + DestPort int `json:"destport,omitempty"` + Deviation int `json:"deviation,omitempty"` + DispatcherIP string `json:"dispatcherip,omitempty"` + DispatcherPort int `json:"dispatcherport,omitempty"` + Domain string `json:"domain,omitempty"` + Downtime int `json:"downtime,omitempty"` + DupState string `json:"dup_state,omitempty"` + DupWeight int `json:"dup_weight,omitempty"` + DynamicInterval int `json:"dynamicinterval,omitempty"` + DynamicResponseTimeout int `json:"dynamicresponsetimeout,omitempty"` + EvalRule string `json:"evalrule,omitempty"` + FailureRetries int `json:"failureretries,omitempty"` + FileName string `json:"filename,omitempty"` + Filter string `json:"filter,omitempty"` + FirmwareRevision int `json:"firmwarerevision,omitempty"` + Group string `json:"group,omitempty"` + GRPCHealthCheck string `json:"grpchealthcheck,omitempty"` + GRPCServiceName string `json:"grpcservicename,omitempty"` + GRPCStatusCode []any `json:"grpcstatuscode,omitempty"` + HostIPAddress string `json:"hostipaddress,omitempty"` + HostName string `json:"hostname,omitempty"` + HTTPRequest string `json:"httprequest,omitempty"` + InBandSecurityID string `json:"inbandsecurityid,omitempty"` + Interval int `json:"interval,omitempty"` + IPAddress []string `json:"ipaddress,omitempty"` + IPTunnel string `json:"iptunnel,omitempty"` + KCDAccount string `json:"kcdaccount,omitempty"` + LASVersion string `json:"lasversion,omitempty"` + LogonPointName string `json:"logonpointname,omitempty"` + LRTM string `json:"lrtm,omitempty"` + LRTMConf int `json:"lrtmconf,omitempty"` + LRTMConfStr string `json:"lrtmconfstr,omitempty"` + MaxForwards int `json:"maxforwards,omitempty"` + Metric string `json:"metric,omitempty"` + MetricTable string `json:"metrictable,omitempty"` + MetricThreshold int `json:"metricthreshold,omitempty"` + MetricWeight int `json:"metricweight,omitempty"` + MonitorName string `json:"monitorname,omitempty"` + MQTTClientIdentifier string `json:"mqttclientidentifier,omitempty"` + MQTTVersion int `json:"mqttversion,omitempty"` + MSSQLProtocolVersion string `json:"mssqlprotocolversion,omitempty"` + MultiMetricTable []string `json:"multimetrictable,omitempty"` + NetProfile string `json:"netprofile,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OracleSID string `json:"oraclesid,omitempty"` + OriginHost string `json:"originhost,omitempty"` + OriginRealm string `json:"originrealm,omitempty"` + Password string `json:"password,omitempty"` + ProductName string `json:"productname,omitempty"` + Query string `json:"query,omitempty"` + QueryType string `json:"querytype,omitempty"` + RADAccountSession string `json:"radaccountsession,omitempty"` + RADAccountType int `json:"radaccounttype,omitempty"` + RADAPN string `json:"radapn,omitempty"` + RADFramedIP string `json:"radframedip,omitempty"` + RADKey string `json:"radkey,omitempty"` + RADMSISDN string `json:"radmsisdn,omitempty"` + RADNASID string `json:"radnasid,omitempty"` + RADNASIP string `json:"radnasip,omitempty"` + Recv string `json:"recv,omitempty"` + RespCode []string `json:"respcode,omitempty"` + RespTimeout int `json:"resptimeout,omitempty"` + RespTimeoutThresh int `json:"resptimeoutthresh,omitempty"` + Retries int `json:"retries,omitempty"` + Reverse string `json:"reverse,omitempty"` + RTSPRequest string `json:"rtsprequest,omitempty"` + ScriptArgs string `json:"scriptargs,omitempty"` + ScriptName string `json:"scriptname,omitempty"` + SecondaryPassword string `json:"secondarypassword,omitempty"` + Secure string `json:"secure,omitempty"` + SecureArgs string `json:"secureargs,omitempty"` + Send string `json:"send,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` + ServiceName string `json:"servicename,omitempty"` + SIPMethod string `json:"sipmethod,omitempty"` + SIPRegURI string `json:"sipreguri,omitempty"` + SIPURI string `json:"sipuri,omitempty"` + SitePath string `json:"sitepath,omitempty"` + SNMPCommunity string `json:"snmpcommunity,omitempty"` + SNMPOID string `json:"Snmpoid,omitempty"` + SNMPThreshold string `json:"snmpthreshold,omitempty"` + SNMPVersion string `json:"snmpversion,omitempty"` + SQLQuery string `json:"sqlquery,omitempty"` + SSLProfile string `json:"sslprofile,omitempty"` + State string `json:"state,omitempty"` + StoreDB string `json:"storedb,omitempty"` + StoreFrontAcctService string `json:"storefrontacctservice,omitempty"` + StoreFrontCheckBackendServices string `json:"storefrontcheckbackendservices,omitempty"` + StoreName string `json:"storename,omitempty"` + SuccessRetries int `json:"successretries,omitempty"` + SupportedVendorIDs []any `json:"supportedvendorids,omitempty"` + TOS string `json:"tos,omitempty"` + TOSID int `json:"tosid,omitempty"` + Transparent string `json:"transparent,omitempty"` + TROFSCode int `json:"trofscode,omitempty"` + TROFSString string `json:"trofsstring,omitempty"` + TypeField string `json:"type,omitempty"` + Units1 string `json:"units1,omitempty"` + Units2 string `json:"units2,omitempty"` + Units3 string `json:"units3,omitempty"` + Units4 string `json:"units4,omitempty"` + Username string `json:"username,omitempty"` + ValidateCred string `json:"validatecred,omitempty"` + VendorID int `json:"vendorid,omitempty"` + VendorSpecificAcctApplicationIDs []any `json:"vendorspecificacctapplicationids,omitempty"` + VendorSpecificAuthApplicationIDs []any `json:"vendorspecificauthapplicationids,omitempty"` + VendorSpecificVendorID int `json:"vendorspecificvendorid,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type LBProfile struct { + ADCCookieAttributeWarningMsg string `json:"adccookieattributewarningmsg,omitempty"` + ComputedADCCookieAttribute string `json:"computedadccookieattribute,omitempty"` + CookiePassphrase string `json:"cookiepassphrase,omitempty"` + Count float64 `json:"__count,omitempty"` + DBSLB string `json:"dbslb,omitempty"` + HTTPOnlyCookieFlag string `json:"httponlycookieflag,omitempty"` + LBHashAlgorithm string `json:"lbhashalgorithm,omitempty"` + LBHashAlgoWinSize int `json:"lbhashalgowinsize,omitempty"` + LBHashFingers int `json:"lbhashfingers,omitempty"` + LBProfileName string `json:"lbprofilename,omitempty"` + LiteralADCCookieAttribute string `json:"literaladccookieattribute,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ProcessLocal string `json:"processlocal,omitempty"` + ProximityFromSelf string `json:"proximityfromself,omitempty"` + StoreMQTTClientIDAndUsername string `json:"storemqttclientidandusername,omitempty"` + UseEncryptedPersistenceCookie string `json:"useencryptedpersistencecookie,omitempty"` + UseSecuredPersistenceCookie string `json:"usesecuredpersistencecookie,omitempty"` + VSvrCount int `json:"vsvrcount,omitempty"` +} + +type LBVServerServiceGroupBinding struct { + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` + ServiceName string `json:"servicename,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type LBWLMBinding struct { + LBWLMLBVServerBinding []any `json:"lbwlm_lbvserver_binding,omitempty"` + WLMName string `json:"wlmname,omitempty"` +} + +type LBMonBindingsGSLBServiceGroupBinding struct { + BoundServiceGroupSvrState string `json:"boundservicegroupsvrstate,omitempty"` + MonitorName string `json:"monitorname,omitempty"` + MonState string `json:"monstate,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` + ServiceType string `json:"servicetype,omitempty"` +} + +type LBPolicy struct { + Action string `json:"action,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + LogAction string `json:"logaction,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule string `json:"rule,omitempty"` + UndefAction string `json:"undefaction,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type LBMonitorServiceGroupBinding struct { + DupState string `json:"dup_state,omitempty"` + DupWeight int `json:"dup_weight,omitempty"` + MonitorName string `json:"monitorname,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` + ServiceName string `json:"servicename,omitempty"` + State string `json:"state,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type LBVServerSpilloverPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type LBWLM struct { + Count float64 `json:"__count,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + KATimeout int `json:"katimeout,omitempty"` + LBUID string `json:"lbuid,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Port int `json:"port,omitempty"` + Secure string `json:"secure,omitempty"` + State string `json:"state,omitempty"` + WLMName string `json:"wlmname,omitempty"` +} + +type LBGroupLBVServerBinding struct { + Name string `json:"name,omitempty"` + VServerName string `json:"vservername,omitempty"` +} + +type LBMetricTableBinding struct { + LBMetricTableMetricBinding []any `json:"lbmetrictable_metric_binding,omitempty"` + MetricTable string `json:"metrictable,omitempty"` +} + +type LBPersistentSessions struct { + CNamePersParam string `json:"cnamepersparam,omitempty"` + Count float64 `json:"__count,omitempty"` + DestIP string `json:"destip,omitempty"` + DestIPv6 string `json:"destipv6,omitempty"` + DestPort int `json:"destport,omitempty"` + Flags bool `json:"flags,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + PersistenceParam string `json:"persistenceparam,omitempty"` + PersistenceParameter string `json:"persistenceparameter,omitempty"` + ReferenceCount int `json:"referencecount,omitempty"` + SrcIP string `json:"srcip,omitempty"` + SrcIPv6 string `json:"srcipv6,omitempty"` + Timeout int `json:"timeout,omitempty"` + TypeField int `json:"type,omitempty"` + TypeString string `json:"typestring,omitempty"` + VServer string `json:"vserver,omitempty"` + VServerName string `json:"vservername,omitempty"` +} + +type LBPolicyLBVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type LBVServerAuditNSLogPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type LBPolicyLabelBinding struct { + LabelName string `json:"labelname,omitempty"` + LBPolicyLabelLBPolicyBinding []any `json:"lbpolicylabel_lbpolicy_binding,omitempty"` + LBPolicyLabelPolicyBindingBinding []any `json:"lbpolicylabel_policybinding_binding,omitempty"` +} + +type LBMetricTableMetricBinding struct { + Metric string `json:"metric,omitempty"` + MetricTable string `json:"metrictable,omitempty"` + MetricType string `json:"metrictype,omitempty"` + SNMPOID string `json:"Snmpoid,omitempty"` +} + +type LBVServerDNSPolicy64Binding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type LBVServerVideoOptimizationPacingPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type LBPolicyLBPolicyLabelBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type LBMonBindingsServiceGroupBinding struct { + BoundServiceGroupSvrState string `json:"boundservicegroupsvrstate,omitempty"` + MonitorName string `json:"monitorname,omitempty"` + MonState string `json:"monstate,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` + ServiceType string `json:"servicetype,omitempty"` +} + +type LBMonitorSSLCertKeyBinding struct { + CA bool `json:"ca,omitempty"` + CertKeyName string `json:"certkeyname,omitempty"` + CRLCheck string `json:"crlcheck,omitempty"` + MonitorName string `json:"monitorname,omitempty"` + OCSPCheck string `json:"ocspcheck,omitempty"` +} + +type LBVServerAuthorizationPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type LBVServerVideoOptimizationDetectionPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type LBPolicyLabel struct { + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Hits int `json:"hits,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyLabelType string `json:"policylabeltype,omitempty"` +} + +type LBPolicyBinding struct { + LBPolicyGSLBVServerBinding []any `json:"lbpolicy_gslbvserver_binding,omitempty"` + LBPolicyLBGlobalBinding []any `json:"lbpolicy_lbglobal_binding,omitempty"` + LBPolicyLBPolicyLabelBinding []any `json:"lbpolicy_lbpolicylabel_binding,omitempty"` + LBPolicyLBVServerBinding []any `json:"lbpolicy_lbvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type LBMonitorMetricBinding struct { + Metric string `json:"metric,omitempty"` + MetricUnit string `json:"metric_unit,omitempty"` + MetricTable string `json:"metrictable,omitempty"` + MetricThreshold int `json:"metricthreshold,omitempty"` + MetricWeight int `json:"metricweight,omitempty"` + MonitorName string `json:"monitorname,omitempty"` +} + +type LBVServerLBPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type LBGroupBinding struct { + LBGroupLBVServerBinding []any `json:"lbgroup_lbvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type LBParameter struct { + ADCCookieAttributeWarningMsg string `json:"adccookieattributewarningmsg,omitempty"` + AllowBoundSvcRemoval string `json:"allowboundsvcremoval,omitempty"` + Builtin []string `json:"builtin,omitempty"` + ComputedADCCookieAttribute string `json:"computedadccookieattribute,omitempty"` + ConsolidatedLConn string `json:"consolidatedlconn,omitempty"` + CookiePassphrase string `json:"cookiepassphrase,omitempty"` + DBSTTL int `json:"dbsttl,omitempty"` + DropMQTTJumboMessage string `json:"dropmqttjumbomessage,omitempty"` + Feature string `json:"feature,omitempty"` + HTTPOnlyCookieFlag string `json:"httponlycookieflag,omitempty"` + LBHashAlgorithm string `json:"lbhashalgorithm,omitempty"` + LBHashAlgoWinSize int `json:"lbhashalgowinsize,omitempty"` + LBHashFingers int `json:"lbhashfingers,omitempty"` + LiteralADCCookieAttribute string `json:"literaladccookieattribute,omitempty"` + MaxPipelineNAT int `json:"maxpipelinenat,omitempty"` + MonitorConnectionClose string `json:"monitorconnectionclose,omitempty"` + MonitorSkipMaxClient string `json:"monitorskipmaxclient,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OverridePersistencyForOrder string `json:"overridepersistencyfororder,omitempty"` + PreferDirectRoute string `json:"preferdirectroute,omitempty"` + ProximityFromSelf string `json:"proximityfromself,omitempty"` + RADIUSMessageAuthenticator string `json:"radiusmessageauthenticator,omitempty"` + RetainServiceState string `json:"retainservicestate,omitempty"` + SessionsThreshold int `json:"sessionsthreshold,omitempty"` + StartupRRFactor int `json:"startuprrfactor,omitempty"` + StoreMQTTClientIDAndUsername string `json:"storemqttclientidandusername,omitempty"` + UndefAction string `json:"undefaction,omitempty"` + UseEncryptedPersistenceCookie string `json:"useencryptedpersistencecookie,omitempty"` + UsePortForHashLB string `json:"useportforhashlb,omitempty"` + UseSecuredPersistenceCookie string `json:"usesecuredpersistencecookie,omitempty"` + VServerSpecificMAC string `json:"vserverspecificmac,omitempty"` +} + +type LBVServerServiceGroupMemberBinding struct { + CookieIPPort string `json:"cookieipport,omitempty"` + CookieName string `json:"cookiename,omitempty"` + CurState string `json:"curstate,omitempty"` + DynamicWeight int `json:"dynamicweight,omitempty"` + IPv46 string `json:"ipv46,omitempty"` + Name string `json:"name,omitempty"` + Order int `json:"order,omitempty"` + OrderStr string `json:"orderstr,omitempty"` + Port int `json:"port,omitempty"` + PreferredLocation string `json:"preferredlocation,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` + ServiceType string `json:"servicetype,omitempty"` + VServerID string `json:"vserverid,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type LBMetricTable struct { + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Metric string `json:"metric,omitempty"` + MetricTable string `json:"metrictable,omitempty"` + MetricType string `json:"metrictype,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + SNMPOID string `json:"Snmpoid,omitempty"` +} diff --git a/nitrogo/models/lbmodels.go b/nitrogo/models/lbmodels.go deleted file mode 100644 index d165c0d..0000000 --- a/nitrogo/models/lbmodels.go +++ /dev/null @@ -1,170 +0,0 @@ -// Derived from Citrix ADC Nitro Go SDK (https://github.com/netscaler/adc-nitro-go) -// Originally licensed under the Apache License, Version 2.0 -// Modifications by Adam Crawford, 2025 - -package models - -type LBVServer struct { - ADFSProxyProfile string `json:"adfsproxyprofile,omitempty"` - APIProfile string `json:"apiprofile,omitempty"` - AppFlowLog string `json:"appflowlog,omitempty"` - Authentication string `json:"authentication,omitempty"` - AuthenticationHost string `json:"authenticationhost,omitempty"` - Authn401 string `json:"authn401,omitempty"` - AuthnProfile string `json:"authnprofile,omitempty"` - AuthnVSName string `json:"authnvsname,omitempty"` - BackupLBMethod string `json:"backuplbmethod,omitempty"` - BackupPersistenceTimeout int `json:"backuppersistencetimeout,omitempty"` - BackupVServer string `json:"backupvserver,omitempty"` - BypassAAAA string `json:"bypassaaaa,omitempty"` - Cacheable string `json:"cacheable,omitempty"` - CltTimeOut string `json:"clttimeout,omitempty"` - Comment string `json:"comment,omitempty"` - ConnFailOver string `json:"connfailover,omitempty"` - CookieName string `json:"cookiename,omitempty"` - DataLength string `json:"datalength,omitempty"` - DataOffset string `json:"dataoffset,omitempty"` - DbProfileName string `json:"dbprofilename,omitempty"` - DbsLB string `json:"dbslb,omitempty"` - DisablePrimaryOnDown string `json:"disableprimaryondown,omitempty"` - DNS64 string `json:"dns64,omitempty"` - DNSOverHTTPS string `json:"dnsoverhttps,omitempty"` - DNSProfileName string `json:"dnsprofilename,omitempty"` - DownStateFlush string `json:"downstateflush,omitempty"` - HashLength int `json:"hashlength,omitempty"` - HealthThreshold string `json:"healththreshold,omitempty"` - HTTPProfileName string `json:"httpprofilename,omitempty"` - HTTPSRedirectURL string `json:"httpsredirecturl,omitempty"` - ICMPVSRresponse string `json:"icmpvsrresponse,omitempty"` - InsertVServerIPPort string `json:"insertvserveripport,omitempty"` - IPMask string `json:"ipmask,omitempty"` - IPPattern string `json:"ippattern,omitempty"` - IPSet string `json:"ipset,omitempty"` - IPv46 string `json:"ipv46,omitempty"` - L2Conn string `json:"l2conn,omitempty"` - LBMethod string `json:"lbmethod,omitempty"` - LBProfileName string `json:"lbprofilename,omitempty"` - ListenPolicy string `json:"listenpolicy,omitempty"` - ListenPriority string `json:"listenpriority,omitempty"` - M string `json:"m,omitempty"` - MACModeRetainVLAN string `json:"macmoderetainvlan,omitempty"` - MaxAutoScaleMembers string `json:"maxautoscalemembers,omitempty"` - MinAutoScaleMembers string `json:"minautoscalemembers,omitempty"` - MSSQLServerVersion string `json:"mssqlserverversion,omitempty"` - MySQLCharacterSet int `json:"mysqlcharacterset,omitempty"` - MySQLProtocolVersion int `json:"mysqlprotocolversion,omitempty"` - MySQLServerCapabilities int `json:"mysqlservercapabilities,omitempty"` - MySQLServerVersion string `json:"mysqlserverversion,omitempty"` - Name string `json:"name,omitempty"` - Netmask string `json:"netmask,omitempty"` - NetProfile string `json:"netprofile,omitempty"` - NewName string `json:"newname,omitempty"` - NewServiceRequest int `json:"newservicerequest,omitempty"` - NewServiceRequestIncrementInterval int `json:"newservicerequestincrementinterval,omitempty"` - NewserviceRequestUnit string `json:"newservicerequestunit,omitempty"` - OracleServerVersion string `json:"oracleserverversion,omitempty"` - Order int `json:"order,omitempty"` - OrderThreshold string `json:"orderthreshold,omitempty"` - PersistAVPNO []int `json:"persistavpno,omitempty"` - PersistenceBackup string `json:"persistencebackup,omitempty"` - PersistenceType string `json:"persistencetype,omitempty"` - PersistMask string `json:"persistmask,omitempty"` - Port int `json:"port,omitempty"` - ProbePort int `json:"probeport,omitempty"` - ProbeProtocol string `json:"probeprotocol,omitempty"` - ProbeSuccessResponsecode string `json:"probesuccessresponsecode,omitempty"` - ProcessLocal string `json:"processlocal,omitempty"` - Push string `json:"push,omitempty"` - PushLabel string `json:"pushlabel,omitempty"` - PushMultiClients string `json:"pushmulticlients,omitempty"` - PushVServer string `json:"pushvserver,omitempty"` - QUICBridgeProfileName string `json:"quicbridgeprofilename,omitempty"` - QUICProfileName string `json:"quicprofilename,omitempty"` - Range string `json:"range,omitempty"` - RecursionAvailable string `json:"recursionavailable,omitempty"` - RedirectFromPort int `json:"redirectfromport,omitempty"` - RedirectPortRewrite string `json:"redirectportrewrite,omitempty"` - RedirURL string `json:"redirurl,omitempty"` - RedirURLFlags bool `json:"redirurlflags,omitempty"` - Resrule string `json:"resrule,omitempty"` - RetainConnectionsonCluster string `json:"retainconnectionsoncluster,omitempty"` - RHIState string `json:"rhistate,omitempty"` - RTSPNAT string `json:"rtspnat,omitempty"` - Rule string `json:"rule,omitempty"` - ServiceName string `json:"servicename,omitempty"` - ServiceType string `json:"servicetype,omitempty"` - Sessionless string `json:"sessionless,omitempty"` - SkipPersistency string `json:"skippersistency,omitempty"` - SoBackupAction string `json:"sobackupaction,omitempty"` - SoMethod string `json:"somethod,omitempty"` - SoPersistence string `json:"sopersistence,omitempty"` - SoPersistenceTimeout string `json:"sopersistencetimeout,omitempty"` - SoThreshold string `json:"sothreshold,omitempty"` - State string `json:"state,omitempty"` - TCPProbePort int `json:"tcpprobeport,omitempty"` - TCPProfileName string `json:"tcpprofilename,omitempty"` - Td string `json:"td,omitempty"` - Timeout int `json:"timeout,omitempty"` - ToggleOrder string `json:"toggleorder,omitempty"` - TOSID int `json:"tosid,omitempty"` - TROFSPersistence string `json:"trofspersistence,omitempty"` - V6NetMaskLen int `json:"v6netmasklen,omitempty"` - V6PersistMaskLen string `json:"v6persistmasklen,omitempty"` - VIPHeader string `json:"vipheader,omitempty"` - Weight int `json:"weight,omitempty"` - - ActiveAervices string `json:"activeservices,omitempty"` - BackupvAerverAtatus string `json:"backupvserverstatus,omitempty"` - BindPoint string `json:"bindpoint,omitempty"` - CacheVServer string `json:"cachevserver,omitempty"` - ConsolidatedLConn string `json:"consolidatedlconn,omitempty"` - ConsolidatedLConngbl string `json:"consolidatedlconngbl,omitempty"` - CookieDomain string `json:"cookiedomain,omitempty"` - CurrentactiveOrder string `json:"currentactiveorder,omitempty"` - CurState string `json:"curstate,omitempty"` - DNSVServerName string `json:"dnsvservername,omitempty"` - Domain string `json:"domain,omitempty"` - EffectiveState string `json:"effectivestate,omitempty"` - GroupName string `json:"groupname,omitempty"` - Gt2GB string `json:"gt2gb,omitempty"` - Health string `json:"health,omitempty"` - Homepage string `json:"homepage,omitempty"` - IPMapping string `json:"ipmapping,omitempty"` - IsGLSB bool `json:"isgslb,omitempty"` - LBRRReason int `json:"lbrrreason,omitempty"` - Map string `json:"map,omitempty"` - NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` - NGName string `json:"ngname,omitempty"` - NodeFaultBindings string `json:"nodefaultbindings,omitempty"` - Precedence string `json:"precedence,omitempty"` - Redirect string `json:"redirect,omitempty"` - Ruletype string `json:"ruletype,omitempty"` - StateChangeTimeMsec string `json:"statechangetimemsec,omitempty"` - StateChangeTimeSec string `json:"statechangetimesec,omitempty"` - StateChangeTimeSeconds string `json:"statechangetimeseconds,omitempty"` - Status int `json:"status,omitempty"` - ThresholdValue int `json:"thresholdvalue,omitempty"` - TicksSinceLastStateChange string `json:"tickssincelaststatechange,omitempty"` - TotalServices string `json:"totalservices,omitempty"` - Type string `json:"type,omitempty"` - Value string `json:"value,omitempty"` - Version int `json:"version,omitempty"` - VSvrDynConnsoThreshold string `json:"vsvrdynconnsothreshold,omitempty"` -} - -type LBVServerServiceGroupMemberBinding struct { - CookieIPPort string `json:"cookieipport,omitempty"` - CookieName string `json:"cookiename,omitempty"` - CurState string `json:"curstate,omitempty"` - DynamicWeight string `json:"dynamicweight,omitempty"` - Ipv46 string `json:"ipv46,omitempty"` - Name string `json:"name,omitempty"` - Order string `json:"order,omitempty"` - OrderStr string `json:"orderstr,omitempty"` - PreferredLocation string `json:"preferredlocation,omitempty"` - Port int `json:"port,omitempty"` - ServiceGroupName string `json:"servicegroupname,omitempty"` - ServiceType string `json:"servicetype,omitempty"` - VServerid string `json:"vserverid,omitempty"` - Weight string `json:"weight,omitempty"` -} diff --git a/nitrogo/models/lldp.go b/nitrogo/models/lldp.go new file mode 100644 index 0000000..2675d90 --- /dev/null +++ b/nitrogo/models/lldp.go @@ -0,0 +1,46 @@ +package models + +// lldp configuration structs +type LLDPParam struct { + HoldTimeTxMult int `json:"holdtimetxmult,omitempty"` + Mode string `json:"mode,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Timer int `json:"timer,omitempty"` +} + +type LLDPNeighbors struct { + AutonegAdvertised string `json:"autonegadvertised,omitempty"` + AutonegEnabled string `json:"autonegenabled,omitempty"` + AutonegMauType string `json:"autonegmautype,omitempty"` + AutonegSupport string `json:"autonegsupport,omitempty"` + ChassisID string `json:"chassisid,omitempty"` + ChassisIDSubtype string `json:"chassisidsubtype,omitempty"` + Count float64 `json:"__count,omitempty"` + Flag int `json:"flag,omitempty"` + IFNum string `json:"ifnum,omitempty"` + IFNumber int `json:"ifnumber,omitempty"` + IFType string `json:"iftype,omitempty"` + LinkAggrCapable string `json:"linkaggrcapable,omitempty"` + LinkAggrEnabled string `json:"linkaggrenabled,omitempty"` + LinkAggrID int `json:"linkaggrid,omitempty"` + MgmtAddress string `json:"mgmtaddress,omitempty"` + MgmtAddressSubtype string `json:"mgmtaddresssubtype,omitempty"` + MTU int `json:"mtu,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + PortDescription string `json:"portdescription,omitempty"` + PortID string `json:"portid,omitempty"` + PortIDSubtype string `json:"portidsubtype,omitempty"` + PortProtoEnabled int `json:"portprotoenabled,omitempty"` + PortProtoID int `json:"portprotoid,omitempty"` + PortProtoSupported int `json:"portprotosupported,omitempty"` + PortVLANID int `json:"portvlanid,omitempty"` + ProtocolID string `json:"protocolid,omitempty"` + Sys string `json:"sys,omitempty"` + SysCapabilities string `json:"syscapabilities,omitempty"` + SysCapEnabled string `json:"syscapenabled,omitempty"` + SysDesc string `json:"sysdesc,omitempty"` + TTL int `json:"ttl,omitempty"` + VLAN string `json:"vlan,omitempty"` + VLANID int `json:"vlanid,omitempty"` +} diff --git a/nitrogo/models/lsn.go b/nitrogo/models/lsn.go new file mode 100644 index 0000000..0d03023 --- /dev/null +++ b/nitrogo/models/lsn.go @@ -0,0 +1,408 @@ +package models + +// lsn configuration structs +type LSNGroupLSNLogProfileBinding struct { + Count float64 `json:"__count,omitempty"` + GroupName string `json:"groupname,omitempty"` + LogProfileName string `json:"logprofilename,omitempty"` +} + +type LSNClientNSACLBinding struct { + ACLName string `json:"aclname,omitempty"` + ClientName string `json:"clientname,omitempty"` + Count float64 `json:"__count,omitempty"` + TD int `json:"td,omitempty"` +} + +type LSNIP6Profile struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NatPrefix string `json:"natprefix,omitempty"` + Network6 string `json:"network6,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type LSNGroupLSNHTTPHdrLogProfileBinding struct { + Count float64 `json:"__count,omitempty"` + GroupName string `json:"groupname,omitempty"` + HTTPHdrLogProfileName string `json:"httphdrlogprofilename,omitempty"` +} + +type LSNGroupLSNTransportProfileBinding struct { + Count float64 `json:"__count,omitempty"` + GroupName string `json:"groupname,omitempty"` + TransportProfileName string `json:"transportprofilename,omitempty"` +} + +type LSNAppsAttributes struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Port string `json:"port,omitempty"` + SessionTimeout int `json:"sessiontimeout,omitempty"` + TransportProtocol string `json:"transportprotocol,omitempty"` +} + +type LSNGroupLSNRTSPALGProfileBinding struct { + Count float64 `json:"__count,omitempty"` + GroupName string `json:"groupname,omitempty"` + RTSPALGProfileName string `json:"rtspalgprofilename,omitempty"` +} + +type LSNClient struct { + ClientName string `json:"clientname,omitempty"` + Count float64 `json:"__count,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type LSNClientNSACL6Binding struct { + ACL6Name string `json:"acl6name,omitempty"` + ClientName string `json:"clientname,omitempty"` + Count float64 `json:"__count,omitempty"` + TD int `json:"td,omitempty"` +} + +type LSNParameter struct { + MaxMemLimit int `json:"maxmemlimit,omitempty"` + MemLimit int `json:"memlimit,omitempty"` + MemLimitActive int `json:"memlimitactive,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + SessionSync string `json:"sessionsync,omitempty"` + SubscrSessionRemoval string `json:"subscrsessionremoval,omitempty"` +} + +type LSNClientNetworkBinding struct { + ClientName string `json:"clientname,omitempty"` + Count float64 `json:"__count,omitempty"` + Netmask string `json:"netmask,omitempty"` + Network string `json:"network,omitempty"` + TD int `json:"td,omitempty"` +} + +type LSNClientNetwork6Binding struct { + ClientName string `json:"clientname,omitempty"` + Count float64 `json:"__count,omitempty"` + Netmask string `json:"netmask,omitempty"` + Network string `json:"network,omitempty"` + Network6 string `json:"network6,omitempty"` + TD int `json:"td,omitempty"` +} + +type LSNAppsProfilePortBinding struct { + AppsProfileName string `json:"appsprofilename,omitempty"` + Count float64 `json:"__count,omitempty"` + LSNPort string `json:"lsnport,omitempty"` +} + +type LSNSession struct { + ClientName string `json:"clientname,omitempty"` + Count float64 `json:"__count,omitempty"` + DestIP string `json:"destip,omitempty"` + DestPort int `json:"destport,omitempty"` + DstTD int `json:"dsttd,omitempty"` + IPv6Address string `json:"ipv6address,omitempty"` + NatIP string `json:"natip,omitempty"` + NatPort int `json:"natport,omitempty"` + NatPort2 int `json:"natport2,omitempty"` + NatPrefix string `json:"natprefix,omitempty"` + NatType string `json:"nattype,omitempty"` + Netmask string `json:"netmask,omitempty"` + Network string `json:"network,omitempty"` + Network6 string `json:"network6,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + SessionEstDir string `json:"sessionestdir,omitempty"` + SrcTD int `json:"srctd,omitempty"` + SubscrIP string `json:"subscrip,omitempty"` + SubscrPort int `json:"subscrport,omitempty"` + TD int `json:"td,omitempty"` + TransportProtocol string `json:"transportprotocol,omitempty"` +} + +type LSNSIPALGProfile struct { + Count float64 `json:"__count,omitempty"` + DataSessionIdleTimeout int `json:"datasessionidletimeout,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OpenContactPinhole string `json:"opencontactpinhole,omitempty"` + OpenRecordRoutePinhole string `json:"openrecordroutepinhole,omitempty"` + OpenRegisterPinhole string `json:"openregisterpinhole,omitempty"` + OpenRoutePinhole string `json:"openroutepinhole,omitempty"` + OpenViaPinhole string `json:"openviapinhole,omitempty"` + RegistrationTimeout int `json:"registrationtimeout,omitempty"` + RPort string `json:"rport,omitempty"` + SIPALGProfileName string `json:"sipalgprofilename,omitempty"` + SIPDstPortRange string `json:"sipdstportrange,omitempty"` + SIPSessionTimeout int `json:"sipsessiontimeout,omitempty"` + SIPSrcPortRange string `json:"sipsrcportrange,omitempty"` + SIPTransportProtocol string `json:"siptransportprotocol,omitempty"` +} + +type LSNRTSPALGSessionBinding struct { + LSNRTSPALGSessionDataChannelBinding []any `json:"lsnrtspalgsession_datachannel_binding,omitempty"` + SessionID string `json:"sessionid,omitempty"` +} + +type LSNLogProfile struct { + AnalyticsProfile string `json:"analyticsprofile,omitempty"` + Count float64 `json:"__count,omitempty"` + LogCompact string `json:"logcompact,omitempty"` + LogIPFIX string `json:"logipfix,omitempty"` + LogProfileName string `json:"logprofilename,omitempty"` + LogSessDeletion string `json:"logsessdeletion,omitempty"` + LogSubscrInfo string `json:"logsubscrinfo,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type LSNGroupIPSECALGProfileBinding struct { + Count float64 `json:"__count,omitempty"` + GroupName string `json:"groupname,omitempty"` + IPSECALGProfile string `json:"ipsecalgprofile,omitempty"` +} + +type LSNGroup struct { + AllocPolicy string `json:"allocpolicy,omitempty"` + ClientName string `json:"clientname,omitempty"` + Count float64 `json:"__count,omitempty"` + FTP string `json:"ftp,omitempty"` + FTPCM string `json:"ftpcm,omitempty"` + GroupID int `json:"groupid,omitempty"` + GroupName string `json:"groupname,omitempty"` + IP6Profile string `json:"ip6profile,omitempty"` + Logging string `json:"logging,omitempty"` + NatType string `json:"nattype,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PortBlockSize int `json:"portblocksize,omitempty"` + PPTP string `json:"pptp,omitempty"` + RTSPALG string `json:"rtspalg,omitempty"` + SessionLogging string `json:"sessionlogging,omitempty"` + SessionSync string `json:"sessionsync,omitempty"` + SIPALG string `json:"sipalg,omitempty"` + SNMPTrapLimit int `json:"snmptraplimit,omitempty"` +} + +type LSNStatic struct { + Count float64 `json:"__count,omitempty"` + DestIP string `json:"destip,omitempty"` + DstTD int `json:"dsttd,omitempty"` + Name string `json:"name,omitempty"` + NatIP string `json:"natip,omitempty"` + NatPort int `json:"natport,omitempty"` + NatType string `json:"nattype,omitempty"` + Network6 string `json:"network6,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Status string `json:"status,omitempty"` + SubscrIP string `json:"subscrip,omitempty"` + SubscrPort int `json:"subscrport,omitempty"` + TD int `json:"td,omitempty"` + TransportProtocol string `json:"transportprotocol,omitempty"` +} + +type LSNTransportProfile struct { + Count float64 `json:"__count,omitempty"` + FinRstTimeout int `json:"finrsttimeout,omitempty"` + GroupSessionLimit int `json:"groupsessionlimit,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PortPreserveParity string `json:"portpreserveparity,omitempty"` + PortPreserveRange string `json:"portpreserverange,omitempty"` + PortQuota int `json:"portquota,omitempty"` + SessionQuota int `json:"sessionquota,omitempty"` + SessionTimeout int `json:"sessiontimeout,omitempty"` + STUNTimeout int `json:"stuntimeout,omitempty"` + SynCheck string `json:"syncheck,omitempty"` + SynIdleTimeout int `json:"synidletimeout,omitempty"` + TransportProfileName string `json:"transportprofilename,omitempty"` + TransportProtocol string `json:"transportprotocol,omitempty"` +} + +type LSNSIPALGCallDataChannelBinding struct { + CallID string `json:"callid,omitempty"` + ChannelFlags int `json:"channelflags,omitempty"` + ChannelIP string `json:"channelip,omitempty"` + ChannelNatIP string `json:"channelnatip,omitempty"` + ChannelNatPort int `json:"channelnatport,omitempty"` + ChannelPort int `json:"channelport,omitempty"` + ChannelProtocol string `json:"channelprotocol,omitempty"` + ChannelTimeout int `json:"channeltimeout,omitempty"` + Count float64 `json:"__count,omitempty"` +} + +type LSNAppsProfileBinding struct { + AppsProfileName string `json:"appsprofilename,omitempty"` + LSNAppsProfileLSNAppsAttributesBinding []any `json:"lsnappsprofile_lsnappsattributes_binding,omitempty"` + LSNAppsProfilePortBinding []any `json:"lsnappsprofile_port_binding,omitempty"` +} + +type LSNPool struct { + Count float64 `json:"__count,omitempty"` + MaxPortReallocTMQ int `json:"maxportrealloctmq,omitempty"` + NatType string `json:"nattype,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PoolName string `json:"poolname,omitempty"` + PortBlockAllocation string `json:"portblockallocation,omitempty"` + PortReallocTimeout int `json:"portrealloctimeout,omitempty"` +} + +type LSNAppsProfileLSNAppsAttributesBinding struct { + AppsAttributesName string `json:"appsattributesname,omitempty"` + AppsProfileName string `json:"appsprofilename,omitempty"` + Count float64 `json:"__count,omitempty"` +} + +type LSNGroupBinding struct { + GroupName string `json:"groupname,omitempty"` + LSNGroupIPSECALGProfileBinding []any `json:"lsngroup_ipsecalgprofile_binding,omitempty"` + LSNGroupLSNAppsProfileBinding []any `json:"lsngroup_lsnappsprofile_binding,omitempty"` + LSNGroupLSNHTTPHdrLogProfileBinding []any `json:"lsngroup_lsnhttphdrlogprofile_binding,omitempty"` + LSNGroupLSNLogProfileBinding []any `json:"lsngroup_lsnlogprofile_binding,omitempty"` + LSNGroupLSNPoolBinding []any `json:"lsngroup_lsnpool_binding,omitempty"` + LSNGroupLSNRTSPALGProfileBinding []any `json:"lsngroup_lsnrtspalgprofile_binding,omitempty"` + LSNGroupLSNSIPALGProfileBinding []any `json:"lsngroup_lsnsipalgprofile_binding,omitempty"` + LSNGroupLSNTransportProfileBinding []any `json:"lsngroup_lsntransportprofile_binding,omitempty"` + LSNGroupPCPServerBinding []any `json:"lsngroup_pcpserver_binding,omitempty"` +} + +type LSNPoolBinding struct { + LSNPoolLSNIPBinding []any `json:"lsnpool_lsnip_binding,omitempty"` + PoolName string `json:"poolname,omitempty"` +} + +type LSNDeterministicNAT struct { + ClientName string `json:"clientname,omitempty"` + Count float64 `json:"__count,omitempty"` + FirstPort int `json:"firstport,omitempty"` + LastPort int `json:"lastport,omitempty"` + NatIP string `json:"natip,omitempty"` + NatIP2 string `json:"natip2,omitempty"` + NatPrefix string `json:"natprefix,omitempty"` + NatType string `json:"nattype,omitempty"` + Network6 string `json:"network6,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + SrcTD int `json:"srctd,omitempty"` + SubscrIP string `json:"subscrip,omitempty"` + SubscrIP2 string `json:"subscrip2,omitempty"` + TD int `json:"td,omitempty"` +} + +type LSNGroupLSNAppsProfileBinding struct { + AppsProfileName string `json:"appsprofilename,omitempty"` + Count float64 `json:"__count,omitempty"` + GroupName string `json:"groupname,omitempty"` +} + +type LSNSIPALGCallBinding struct { + CallID string `json:"callid,omitempty"` + LSNSIPALGCallControlChannelBinding []any `json:"lsnsipalgcall_controlchannel_binding,omitempty"` + LSNSIPALGCallDataChannelBinding []any `json:"lsnsipalgcall_datachannel_binding,omitempty"` +} + +type LSNAppsProfile struct { + AppsProfileName string `json:"appsprofilename,omitempty"` + Count float64 `json:"__count,omitempty"` + Filtering string `json:"filtering,omitempty"` + IPPooling string `json:"ippooling,omitempty"` + L2Info string `json:"l2info,omitempty"` + Mapping string `json:"mapping,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + TCPProxy string `json:"tcpproxy,omitempty"` + TD int `json:"td,omitempty"` + TransportProtocol string `json:"transportprotocol,omitempty"` +} + +type LSNHTTPHdrLogProfile struct { + Count float64 `json:"__count,omitempty"` + HTTPHdrLogProfileName string `json:"httphdrlogprofilename,omitempty"` + LogHost string `json:"loghost,omitempty"` + LogMethod string `json:"logmethod,omitempty"` + LogURL string `json:"logurl,omitempty"` + LogVersion string `json:"logversion,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type LSNSIPALGCallControlChannelBinding struct { + CallID string `json:"callid,omitempty"` + ChannelFlags int `json:"channelflags,omitempty"` + ChannelIP string `json:"channelip,omitempty"` + ChannelNatIP string `json:"channelnatip,omitempty"` + ChannelNatPort int `json:"channelnatport,omitempty"` + ChannelPort int `json:"channelport,omitempty"` + ChannelProtocol string `json:"channelprotocol,omitempty"` + ChannelTimeout int `json:"channeltimeout,omitempty"` + Count float64 `json:"__count,omitempty"` +} + +type LSNGroupLSNPoolBinding struct { + Count float64 `json:"__count,omitempty"` + GroupName string `json:"groupname,omitempty"` + PoolName string `json:"poolname,omitempty"` +} + +type LSNSIPALGCall struct { + CallFlags int `json:"callflags,omitempty"` + CallID string `json:"callid,omitempty"` + CallRefCount int `json:"callrefcount,omitempty"` + CallTimer int `json:"calltimer,omitempty"` + Count float64 `json:"__count,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + XlatIP string `json:"xlatip,omitempty"` +} + +type LSNPoolLSNIPBinding struct { + Count float64 `json:"__count,omitempty"` + LSNIP string `json:"lsnip,omitempty"` + OwnerNode int `json:"ownernode,omitempty"` + PoolName string `json:"poolname,omitempty"` +} + +type LSNRTSPALGSession struct { + CallFlags int `json:"callflags,omitempty"` + CallRefCount int `json:"callrefcount,omitempty"` + CallTimer int `json:"calltimer,omitempty"` + Count float64 `json:"__count,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + SessionID string `json:"sessionid,omitempty"` + XlatIP string `json:"xlatip,omitempty"` +} + +type LSNRTSPALGProfile struct { + Count float64 `json:"__count,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + RTSPALGProfileName string `json:"rtspalgprofilename,omitempty"` + RTSPIdleTimeout int `json:"rtspidletimeout,omitempty"` + RTSPPortRange string `json:"rtspportrange,omitempty"` + RTSPTransportProtocol string `json:"rtsptransportprotocol,omitempty"` +} + +type LSNGroupPCPServerBinding struct { + Count float64 `json:"__count,omitempty"` + GroupName string `json:"groupname,omitempty"` + PCPServer string `json:"pcpserver,omitempty"` +} + +type LSNClientBinding struct { + ClientName string `json:"clientname,omitempty"` + LSNClientNetwork6Binding []any `json:"lsnclient_network6_binding,omitempty"` + LSNClientNetworkBinding []any `json:"lsnclient_network_binding,omitempty"` + LSNClientNSACL6Binding []any `json:"lsnclient_nsacl6_binding,omitempty"` + LSNClientNSACLBinding []any `json:"lsnclient_nsacl_binding,omitempty"` +} + +type LSNRTSPALGSessionDataChannelBinding struct { + ChannelFlags int `json:"channelflags,omitempty"` + ChannelIP string `json:"channelip,omitempty"` + ChannelNatIP string `json:"channelnatip,omitempty"` + ChannelNatPort int `json:"channelnatport,omitempty"` + ChannelPort int `json:"channelport,omitempty"` + ChannelProtocol string `json:"channelprotocol,omitempty"` + ChannelTimeout int `json:"channeltimeout,omitempty"` + Count float64 `json:"__count,omitempty"` + SessionID string `json:"sessionid,omitempty"` +} + +type LSNGroupLSNSIPALGProfileBinding struct { + Count float64 `json:"__count,omitempty"` + GroupName string `json:"groupname,omitempty"` + SIPALGProfileName string `json:"sipalgprofilename,omitempty"` +} diff --git a/nitrogo/models/metrics.go b/nitrogo/models/metrics.go new file mode 100644 index 0000000..85c9c45 --- /dev/null +++ b/nitrogo/models/metrics.go @@ -0,0 +1,84 @@ +package models + +// metrics configuration structs +type MetricsProfileAuthenticationVServerBinding struct { + EntityName string `json:"entityname,omitempty"` + EntityType string `json:"entitytype,omitempty"` + Name string `json:"name,omitempty"` +} + +type MetricsProfileVPNVServerBinding struct { + EntityName string `json:"entityname,omitempty"` + EntityType string `json:"entitytype,omitempty"` + Name string `json:"name,omitempty"` +} + +type MetricsProfileGSLBVServerBinding struct { + EntityName string `json:"entityname,omitempty"` + EntityType string `json:"entitytype,omitempty"` + Name string `json:"name,omitempty"` +} + +type MetricsProfileBinding struct { + MetricsProfileAuthenticationVServerBinding []any `json:"metricsprofile_authenticationvserver_binding,omitempty"` + MetricsProfileCRVServerBinding []any `json:"metricsprofile_crvserver_binding,omitempty"` + MetricsProfileCSVServerBinding []any `json:"metricsprofile_csvserver_binding,omitempty"` + MetricsProfileGSLBVServerBinding []any `json:"metricsprofile_gslbvserver_binding,omitempty"` + MetricsProfileLBVServerBinding []any `json:"metricsprofile_lbvserver_binding,omitempty"` + MetricsProfileServiceBinding []any `json:"metricsprofile_service_binding,omitempty"` + MetricsProfileServiceGroupBinding []any `json:"metricsprofile_servicegroup_binding,omitempty"` + MetricsProfileUserVServerBinding []any `json:"metricsprofile_uservserver_binding,omitempty"` + MetricsProfileVPNVServerBinding []any `json:"metricsprofile_vpnvserver_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type MetricsProfile struct { + Collector string `json:"collector,omitempty"` + Count float64 `json:"__count,omitempty"` + Metrics string `json:"metrics,omitempty"` + MetricsAuthToken string `json:"metricsauthtoken,omitempty"` + MetricsEndpointURL string `json:"metricsendpointurl,omitempty"` + MetricsExportFrequency int `json:"metricsexportfrequency,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OutputMode string `json:"outputmode,omitempty"` + RefCnt int `json:"refcnt,omitempty"` + SchemaFile string `json:"schemafile,omitempty"` + ServeMode string `json:"servemode,omitempty"` +} + +type MetricsProfileCRVServerBinding struct { + EntityName string `json:"entityname,omitempty"` + EntityType string `json:"entitytype,omitempty"` + Name string `json:"name,omitempty"` +} + +type MetricsProfileLBVServerBinding struct { + EntityName string `json:"entityname,omitempty"` + EntityType string `json:"entitytype,omitempty"` + Name string `json:"name,omitempty"` +} + +type MetricsProfileCSVServerBinding struct { + EntityName string `json:"entityname,omitempty"` + EntityType string `json:"entitytype,omitempty"` + Name string `json:"name,omitempty"` +} + +type MetricsProfileServiceGroupBinding struct { + EntityName string `json:"entityname,omitempty"` + EntityType string `json:"entitytype,omitempty"` + Name string `json:"name,omitempty"` +} + +type MetricsProfileServiceBinding struct { + EntityName string `json:"entityname,omitempty"` + EntityType string `json:"entitytype,omitempty"` + Name string `json:"name,omitempty"` +} + +type MetricsProfileUserVServerBinding struct { + EntityName string `json:"entityname,omitempty"` + EntityType string `json:"entitytype,omitempty"` + Name string `json:"name,omitempty"` +} diff --git a/nitrogo/models/network.go b/nitrogo/models/network.go new file mode 100644 index 0000000..778d71a --- /dev/null +++ b/nitrogo/models/network.go @@ -0,0 +1,1302 @@ +package models + +type ChannelInterfaceBinding struct { + Count float64 `json:"__count,omitempty"` + ID string `json:"id,omitempty"` + IFNum []string `json:"ifnum,omitempty"` + LAMode string `json:"lamode,omitempty"` + LRActiveIntf int `json:"lractiveintf,omitempty"` + SlaveDuplex int `json:"slaveduplex,omitempty"` + SlaveFlowCtl int `json:"slaveflowctl,omitempty"` + SlaveMedia int `json:"slavemedia,omitempty"` + SlaveSpeed int `json:"slavespeed,omitempty"` + SlaveState int `json:"slavestate,omitempty"` + SlaveTime int `json:"slavetime,omitempty"` + SVMCmd int `json:"svmcmd,omitempty"` +} + +type MapDMR struct { + BRIPv6Prefix string `json:"bripv6prefix,omitempty"` + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type RNAT6Binding struct { + Name string `json:"name,omitempty"` + RNAT6NSIP6Binding []any `json:"rnat6_nsip6_binding,omitempty"` +} + +type VLANNSIP6Binding struct { + Count float64 `json:"__count,omitempty"` + ID int `json:"id,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + Netmask string `json:"netmask,omitempty"` + OwnerGroup string `json:"ownergroup,omitempty"` + TD int `json:"td,omitempty"` +} + +type ND6RAVariablesOnLinkIPv6PrefixBinding struct { + Count float64 `json:"__count,omitempty"` + IPv6Prefix string `json:"ipv6prefix,omitempty"` + VLAN int `json:"vlan,omitempty"` +} + +type PTP struct { + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + State string `json:"state,omitempty"` +} + +type RNATNSIPBinding struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NatIP string `json:"natip,omitempty"` + OwnerGroup string `json:"ownergroup,omitempty"` + TD int `json:"td,omitempty"` +} + +type VRID6 struct { + All bool `json:"all,omitempty"` + Count float64 `json:"__count,omitempty"` + EffectivePriority int `json:"effectivepriority,omitempty"` + Flags int `json:"flags,omitempty"` + ID int `json:"id,omitempty"` + Ifaces string `json:"ifaces,omitempty"` + IFNum string `json:"ifnum,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OperationalOwnerNode int `json:"operationalownernode,omitempty"` + OwnerNode int `json:"ownernode,omitempty"` + Preemption string `json:"preemption,omitempty"` + PreemptionDelayTimer int `json:"preemptiondelaytimer,omitempty"` + Priority int `json:"priority,omitempty"` + Sharing string `json:"sharing,omitempty"` + State int `json:"state,omitempty"` + TrackIFNumPriority int `json:"trackifnumpriority,omitempty"` + Tracking string `json:"tracking,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type NetProfileNATRuleBinding struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NATRule string `json:"natrule,omitempty"` + Netmask string `json:"netmask,omitempty"` + RewriteIP string `json:"rewriteip,omitempty"` +} + +type IPTunnel struct { + Channel int `json:"channel,omitempty"` + Count float64 `json:"__count,omitempty"` + DestPort int `json:"destport,omitempty"` + EncapIP string `json:"encapip,omitempty"` + GREPayload string `json:"grepayload,omitempty"` + IPSECProfileName string `json:"ipsecprofilename,omitempty"` + IPSECTunnelStatus string `json:"ipsectunnelstatus,omitempty"` + Local string `json:"local,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OwnerGroup string `json:"ownergroup,omitempty"` + Protocol string `json:"protocol,omitempty"` + RefCnt int `json:"refcnt,omitempty"` + Remote string `json:"remote,omitempty"` + RemoteSubnetMask string `json:"remotesubnetmask,omitempty"` + SysName string `json:"sysname,omitempty"` + TOSInherit string `json:"tosinherit,omitempty"` + TunnelType []string `json:"tunneltype,omitempty"` + TypeField int `json:"type,omitempty"` + VLAN int `json:"vlan,omitempty"` + VLANTagging string `json:"vlantagging,omitempty"` + VNID int `json:"vnid,omitempty"` +} + +type NetProfileSrcPortSetBinding struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + SrcPortRange string `json:"srcportrange,omitempty"` +} + +type L2Param struct { + BdgGrpProxyARP string `json:"bdggrpproxyarp,omitempty"` + BdgSetting string `json:"bdgsetting,omitempty"` + BridgeAgeTimeout int `json:"bridgeagetimeout,omitempty"` + GARPOnVRIDIntf string `json:"garponvridintf,omitempty"` + GARPReply string `json:"garpreply,omitempty"` + MacModeFwdMyPkt string `json:"macmodefwdmypkt,omitempty"` + MaxBridgeCollision int `json:"maxbridgecollision,omitempty"` + MBFInstLearning string `json:"mbfinstlearning,omitempty"` + MBFPeerMACUpdate int `json:"mbfpeermacupdate,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ProxyARP string `json:"proxyarp,omitempty"` + ReturnToEthernetSender string `json:"returntoethernetsender,omitempty"` + RstIntfOnHAFO string `json:"rstintfonhafo,omitempty"` + SkipProxyingBSDTraffic string `json:"skipproxyingbsdtraffic,omitempty"` + StopMACMoveUpdate string `json:"stopmacmoveupdate,omitempty"` + UseMyMAC string `json:"usemymac,omitempty"` + UseNetProfileBSDTraffic string `json:"usenetprofilebsdtraffic,omitempty"` +} + +type ND6RAVariablesBinding struct { + ND6RAVariablesOnLinkIPv6PrefixBinding []any `json:"nd6ravariables_onlinkipv6prefix_binding,omitempty"` + VLAN int `json:"vlan,omitempty"` +} + +type BridgeGroup struct { + Count float64 `json:"__count,omitempty"` + DynamicRouting string `json:"dynamicrouting,omitempty"` + Flags bool `json:"flags,omitempty"` + ID int `json:"id,omitempty"` + Ifaces string `json:"ifaces,omitempty"` + IPv6DynamicRouting string `json:"ipv6dynamicrouting,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PartitionName string `json:"partitionname,omitempty"` + PortBitmap int `json:"portbitmap,omitempty"` + RNAT bool `json:"rnat,omitempty"` + TagBitmap int `json:"tagbitmap,omitempty"` + TagIfaces string `json:"tagifaces,omitempty"` +} + +type IPSetNSIP6Binding struct { + Count float64 `json:"__count,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + Name string `json:"name,omitempty"` +} + +type VRID6ChannelBinding struct { + Count float64 `json:"__count,omitempty"` + Flags int `json:"flags,omitempty"` + ID int `json:"id,omitempty"` + IFNum string `json:"ifnum,omitempty"` + VLAN int `json:"vlan,omitempty"` +} + +type ChannelBinding struct { + ChannelInterfaceBinding []any `json:"channel_interface_binding,omitempty"` + ID string `json:"id,omitempty"` +} + +type RNAT6 struct { + ACL6Name string `json:"acl6name,omitempty"` + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + Network string `json:"network,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OwnerGroup string `json:"ownergroup,omitempty"` + RedirectPort int `json:"redirectport,omitempty"` + SrcIPPersistency string `json:"srcippersistency,omitempty"` + TD int `json:"td,omitempty"` +} + +type BridgeGroupNSIP6Binding struct { + Count float64 `json:"__count,omitempty"` + ID int `json:"id,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + Netmask string `json:"netmask,omitempty"` + OwnerGroup string `json:"ownergroup,omitempty"` + RNAT bool `json:"rnat,omitempty"` + TD int `json:"td,omitempty"` +} + +type BridgeGroupVLANBinding struct { + Count float64 `json:"__count,omitempty"` + ID int `json:"id,omitempty"` + RNAT bool `json:"rnat,omitempty"` + VLAN int `json:"vlan,omitempty"` +} + +type ND6RAVariables struct { + CeaseRouterAdv string `json:"ceaserouteradv,omitempty"` + Count float64 `json:"__count,omitempty"` + CurrHopLimit int `json:"currhoplimit,omitempty"` + DefaultLifetime int `json:"defaultlifetime,omitempty"` + LastRtAdvTime int `json:"lastrtadvtime,omitempty"` + LinkMTU int `json:"linkmtu,omitempty"` + ManagedAddrConfig string `json:"managedaddrconfig,omitempty"` + MaxRtAdvInterval int `json:"maxrtadvinterval,omitempty"` + MinRtAdvInterval int `json:"minrtadvinterval,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NextRtAdvDelay int `json:"nextrtadvdelay,omitempty"` + OnlyUnicastRtAdvResponse string `json:"onlyunicastrtadvresponse,omitempty"` + OtherAddrConfig string `json:"otheraddrconfig,omitempty"` + ReachableTime int `json:"reachabletime,omitempty"` + RetransTime int `json:"retranstime,omitempty"` + SendRouterAdv string `json:"sendrouteradv,omitempty"` + SrcLinkLayerAddrOption string `json:"srclinklayeraddroption,omitempty"` + VLAN int `json:"vlan,omitempty"` +} + +type VRIDNSIPBinding struct { + Count float64 `json:"__count,omitempty"` + Flags int `json:"flags,omitempty"` + ID int `json:"id,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` +} + +type VLANInterfaceBinding struct { + Count float64 `json:"__count,omitempty"` + ID int `json:"id,omitempty"` + IFNum string `json:"ifnum,omitempty"` + OwnerGroup string `json:"ownergroup,omitempty"` + Tagged bool `json:"tagged,omitempty"` +} + +type IP6TunnelParam struct { + DropFrag string `json:"dropfrag,omitempty"` + DropFragCPUThreshold int `json:"dropfragcputhreshold,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + SrcIP string `json:"srcip,omitempty"` + SrcIPRoundRobin string `json:"srciproundrobin,omitempty"` + UseClientSourceIP string `json:"useclientsourceipv6,omitempty"` +} + +type VRID6TrackInterfaceBinding struct { + Count float64 `json:"__count,omitempty"` + Flags int `json:"flags,omitempty"` + ID int `json:"id,omitempty"` + TrackIFNum string `json:"trackifnum,omitempty"` +} + +type RNATGlobalAuditSyslogPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + All bool `json:"all,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type ARPParam struct { + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + SpoofValidation string `json:"spoofvalidation,omitempty"` + Timeout int `json:"timeout,omitempty"` +} + +type Channel struct { + ActFlowCtl string `json:"actflowctl,omitempty"` + ActSpeed string `json:"actspeed,omitempty"` + ActThroughput int `json:"actthroughput,omitempty"` + ActualMTU int `json:"actualmtu,omitempty"` + Autoneg int `json:"autoneg,omitempty"` + AutonegResult int `json:"autonegresult,omitempty"` + Backplane string `json:"backplane,omitempty"` + BandwidthHigh int `json:"bandwidthhigh,omitempty"` + BandwidthNormal int `json:"bandwidthnormal,omitempty"` + BdgMuted int `json:"bdgmuted,omitempty"` + ClearTime int `json:"cleartime,omitempty"` + ConnDistr string `json:"conndistr,omitempty"` + Count float64 `json:"__count,omitempty"` + Description string `json:"description,omitempty"` + DeviceName string `json:"devicename,omitempty"` + Downtime int `json:"downtime,omitempty"` + Duplex string `json:"duplex,omitempty"` + FCtls int `json:"fctls,omitempty"` + Flags int `json:"flags,omitempty"` + FlowCtl string `json:"flowctl,omitempty"` + HAHeartbeat string `json:"haheartbeat,omitempty"` + HAMonitor string `json:"hamonitor,omitempty"` + HangDetect int `json:"hangdetect,omitempty"` + HangReset int `json:"hangreset,omitempty"` + Hangs int `json:"hangs,omitempty"` + ID string `json:"id,omitempty"` + IFAlias string `json:"ifalias,omitempty"` + IFNum []string `json:"ifnum,omitempty"` + InDisc int `json:"indisc,omitempty"` + IntfState int `json:"intfstate,omitempty"` + LACPActorAggregation string `json:"lacpactoraggregation,omitempty"` + LACPActorCollecting string `json:"lacpactorcollecting,omitempty"` + LACPActorDistributing string `json:"lacpactordistributing,omitempty"` + LACPActorInSync string `json:"lacpactorinsync,omitempty"` + LACPActorPortNo int `json:"lacpactorportno,omitempty"` + LACPActorPriority int `json:"lacpactorpriority,omitempty"` + LACPMode string `json:"lacpmode,omitempty"` + LACPPartnerAggregation string `json:"lacppartneraggregation,omitempty"` + LACPPartnerCollecting string `json:"lacppartnercollecting,omitempty"` + LACPPartnerDefaulted string `json:"lacppartnerdefaulted,omitempty"` + LACPPartnerDistributing string `json:"lacppartnerdistributing,omitempty"` + LACPPartnerExpired string `json:"lacppartnerexpired,omitempty"` + LACPPartnerInSync string `json:"lacppartnerinsync,omitempty"` + LACPPartnerKey int `json:"lacppartnerkey,omitempty"` + LACPPartnerPortNo int `json:"lacppartnerportno,omitempty"` + LACPPartnerPriority int `json:"lacppartnerpriority,omitempty"` + LACPPartnerState string `json:"lacppartnerstate,omitempty"` + LACPPartnerSystemMAC string `json:"lacppartnersystemmac,omitempty"` + LACPPartnerSystemPriority int `json:"lacppartnersystempriority,omitempty"` + LACPPartnerTimeout string `json:"lacppartnertimeout,omitempty"` + LACPPortMuxState string `json:"lacpportmuxstate,omitempty"` + LACPPortRxStat string `json:"lacpportrxstat,omitempty"` + LACPPortSelectState string `json:"lacpportselectstate,omitempty"` + LACPTimeout string `json:"lacptimeout,omitempty"` + LAMAC string `json:"lamac,omitempty"` + LAMode string `json:"lamode,omitempty"` + LinkRedundancy string `json:"linkredundancy,omitempty"` + LinkState int `json:"linkstate,omitempty"` + LLDPMode string `json:"lldpmode,omitempty"` + LRMinThroughput int `json:"lrminthroughput,omitempty"` + MAC string `json:"mac,omitempty"` + MACDistr string `json:"macdistr,omitempty"` + Media string `json:"media,omitempty"` + Mode string `json:"mode,omitempty"` + MTU int `json:"mtu,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OutDisc int `json:"outdisc,omitempty"` + ReqDuplex string `json:"reqduplex,omitempty"` + ReqFlowControl string `json:"reqflowcontrol,omitempty"` + ReqMedia string `json:"reqmedia,omitempty"` + ReqSpeed string `json:"reqspeed,omitempty"` + ReqThroughput int `json:"reqthroughput,omitempty"` + RxBytes int `json:"rxbytes,omitempty"` + RxDrops int `json:"rxdrops,omitempty"` + RxErrors int `json:"rxerrors,omitempty"` + RxPackets int `json:"rxpackets,omitempty"` + RxStalls int `json:"rxstalls,omitempty"` + Speed string `json:"speed,omitempty"` + State string `json:"state,omitempty"` + StsStalls int `json:"stsstalls,omitempty"` + TagAll string `json:"tagall,omitempty"` + Tagged int `json:"tagged,omitempty"` + TaggedAny int `json:"taggedany,omitempty"` + TaggedAutoLearn int `json:"taggedautolearn,omitempty"` + Throughput int `json:"throughput,omitempty"` + Trunk string `json:"trunk,omitempty"` + TxBytes int `json:"txbytes,omitempty"` + TxDrops int `json:"txdrops,omitempty"` + TxErrors int `json:"txerrors,omitempty"` + TxPackets int `json:"txpackets,omitempty"` + TxStalls int `json:"txstalls,omitempty"` + Unit int `json:"unit,omitempty"` + Uptime int `json:"uptime,omitempty"` + VLAN int `json:"vlan,omitempty"` + VMAC string `json:"vmac,omitempty"` + VMAC6 string `json:"vmac6,omitempty"` +} + +type NetProfile struct { + BadIPActionThreshold int `json:"badipactionthreshold,omitempty"` + Count float64 `json:"__count,omitempty"` + MBF string `json:"mbf,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OverrideLSN string `json:"overridelsn,omitempty"` + ProxyProtocol string `json:"proxyprotocol,omitempty"` + ProxyProtocolAfterTLSHandshake string `json:"proxyprotocolaftertlshandshake,omitempty"` + ProxyProtocolTLVOptions []string `json:"proxyprotocoltlvoptions,omitempty"` + ProxyProtocolTxVersion string `json:"proxyprotocoltxversion,omitempty"` + SrcIP string `json:"srcip,omitempty"` + SrcIPPersistency string `json:"srcippersistency,omitempty"` + TD int `json:"td,omitempty"` +} + +type VXLANNSIPBinding struct { + Count float64 `json:"__count,omitempty"` + ID int `json:"id,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + Netmask string `json:"netmask,omitempty"` +} + +type RNAT struct { + ACLName string `json:"aclname,omitempty"` + ConnFailover string `json:"connfailover,omitempty"` + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NatIP string `json:"natip,omitempty"` + Netmask string `json:"netmask,omitempty"` + Network string `json:"network,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OwnerGroup string `json:"ownergroup,omitempty"` + RedirectPort int `json:"redirectport,omitempty"` + SrcIPPersistency string `json:"srcippersistency,omitempty"` + TD int `json:"td,omitempty"` + UseProxyPort string `json:"useproxyport,omitempty"` +} + +type AppALGParam struct { + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PPTPGREIdleTimeout int `json:"pptpgreidletimeout,omitempty"` +} + +type IPTunnelParam struct { + DropFrag string `json:"dropfrag,omitempty"` + DropFragCPUThreshold int `json:"dropfragcputhreshold,omitempty"` + EnableStrictRx string `json:"enablestrictrx,omitempty"` + EnableStrictTx string `json:"enablestricttx,omitempty"` + MAC string `json:"mac,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + SrcIP string `json:"srcip,omitempty"` + SrcIPRoundRobin string `json:"srciproundrobin,omitempty"` + UseClientSourceIP string `json:"useclientsourceip,omitempty"` +} + +type VRIDNSIP6Binding struct { + Count float64 `json:"__count,omitempty"` + Flags int `json:"flags,omitempty"` + ID int `json:"id,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` +} + +type BridgeGroupBinding struct { + BridgeGroupNSIP6Binding []any `json:"bridgegroup_nsip6_binding,omitempty"` + BridgeGroupNSIPBinding []any `json:"bridgegroup_nsip_binding,omitempty"` + BridgeGroupVLANBinding []any `json:"bridgegroup_vlan_binding,omitempty"` + ID int `json:"id,omitempty"` +} + +type IPSet struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + TD int `json:"td,omitempty"` +} + +type ARP struct { + All bool `json:"all,omitempty"` + Channel int `json:"channel,omitempty"` + ControlPlane bool `json:"controlplane,omitempty"` + Count float64 `json:"__count,omitempty"` + Flags int `json:"flags,omitempty"` + IFNum string `json:"ifnum,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + MAC string `json:"mac,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + OwnerNode int `json:"ownernode,omitempty"` + State int `json:"state,omitempty"` + TD int `json:"td,omitempty"` + Timeout int `json:"timeout,omitempty"` + TypeField string `json:"type,omitempty"` + VLAN int `json:"vlan,omitempty"` + VTEP string `json:"vtep,omitempty"` + VXLAN int `json:"vxlan,omitempty"` +} + +type INATParam struct { + Count float64 `json:"__count,omitempty"` + Nat46FragHeader string `json:"nat46fragheader,omitempty"` + Nat46IgnoreTOS string `json:"nat46ignoretos,omitempty"` + Nat46V6MTU int `json:"nat46v6mtu,omitempty"` + Nat46V6Prefix string `json:"nat46v6prefix,omitempty"` + Nat46ZeroChecksum string `json:"nat46zerochecksum,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + TD int `json:"td,omitempty"` +} + +type L3Param struct { + ACLLogTime int `json:"acllogtime,omitempty"` + AllowClassEIPv4 string `json:"allowclasseipv4,omitempty"` + DropDFFlag string `json:"dropdfflag,omitempty"` + DropIPFragments string `json:"dropipfragments,omitempty"` + DynamicRouting string `json:"dynamicrouting,omitempty"` + ExternalLoopback string `json:"externalloopback,omitempty"` + ForwardICMPFragments string `json:"forwardicmpfragments,omitempty"` + ICMPGenRateThreshold int `json:"icmpgenratethreshold,omitempty"` + ImplicitACLAllow string `json:"implicitaclallow,omitempty"` + ImplicitPBR string `json:"implicitpbr,omitempty"` + IPv6DynamicRouting string `json:"ipv6dynamicrouting,omitempty"` + MIPRoundRobin string `json:"miproundrobin,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OverrideRNAT string `json:"overridernat,omitempty"` + SrcNat string `json:"srcnat,omitempty"` + TNLPmtuWOConn string `json:"tnlpmtuwoconn,omitempty"` + USIPServerStrayPkt string `json:"usipserverstraypkt,omitempty"` +} + +type NAT64Param struct { + Count float64 `json:"__count,omitempty"` + Nat64FragHeader string `json:"nat64fragheader,omitempty"` + Nat64IgnoreTOS string `json:"nat64ignoretos,omitempty"` + Nat64V6MTU int `json:"nat64v6mtu,omitempty"` + Nat64ZeroChecksum string `json:"nat64zerochecksum,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + TD int `json:"td,omitempty"` +} + +type LACP struct { + ClusterMAC string `json:"clustermac,omitempty"` + ClusterSysPriority int `json:"clustersyspriority,omitempty"` + Count float64 `json:"__count,omitempty"` + DeviceName string `json:"devicename,omitempty"` + Flags int `json:"flags,omitempty"` + LACPKey int `json:"lacpkey,omitempty"` + MAC string `json:"mac,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OwnerNode int `json:"ownernode,omitempty"` + SysPriority int `json:"syspriority,omitempty"` +} + +type MapDomain struct { + Count float64 `json:"__count,omitempty"` + MapDMRName string `json:"mapdmrname,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type ForwardingSession struct { + ACL6Name string `json:"acl6name,omitempty"` + ACLName string `json:"aclname,omitempty"` + ConnFailover string `json:"connfailover,omitempty"` + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + Netmask string `json:"netmask,omitempty"` + Network string `json:"network,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ProcessLocal string `json:"processlocal,omitempty"` + SourceRouteCache string `json:"sourceroutecache,omitempty"` + TD int `json:"td,omitempty"` +} + +type Route6 struct { + Active bool `json:"active,omitempty"` + Advertise string `json:"advertise,omitempty"` + BGP bool `json:"bgp,omitempty"` + Connected bool `json:"connected,omitempty"` + Cost int `json:"cost,omitempty"` + Count float64 `json:"__count,omitempty"` + Data bool `json:"data,omitempty"` + Data1 string `json:"data1,omitempty"` + Detail bool `json:"detail,omitempty"` + Distance int `json:"distance,omitempty"` + Dynamic bool `json:"dynamic,omitempty"` + FailedProbes int `json:"failedprobes,omitempty"` + Flags bool `json:"flags,omitempty"` + Gateway string `json:"gateway,omitempty"` + GatewayName string `json:"gatewayname,omitempty"` + ISIS bool `json:"isis,omitempty"` + Mgmt bool `json:"mgmt,omitempty"` + Monitor string `json:"monitor,omitempty"` + MonStatCode int `json:"monstatcode,omitempty"` + MonStatParam1 int `json:"monstatparam1,omitempty"` + MonStatParam2 int `json:"monstatparam2,omitempty"` + MonStatParam3 int `json:"monstatparam3,omitempty"` + MSR string `json:"msr,omitempty"` + Network string `json:"network,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OSPFv3 bool `json:"ospfv3,omitempty"` + OwnerGroup string `json:"ownergroup,omitempty"` + Permanent bool `json:"permanent,omitempty"` + RARoute bool `json:"raroute,omitempty"` + Retain int `json:"retain,omitempty"` + RIP bool `json:"rip,omitempty"` + RouteOwners []string `json:"routeowners,omitempty"` + RouteType string `json:"routetype,omitempty"` + State int `json:"state,omitempty"` + Static bool `json:"Static,omitempty"` + TD int `json:"td,omitempty"` + TotalFailedProbes int `json:"totalfailedprobes,omitempty"` + TotalProbes int `json:"totalprobes,omitempty"` + TypeField bool `json:"type,omitempty"` + VLAN int `json:"vlan,omitempty"` + VXLAN int `json:"vxlan,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type VLANLinkSetBinding struct { + Count float64 `json:"__count,omitempty"` + ID int `json:"id,omitempty"` + IFNum string `json:"ifnum,omitempty"` + OwnerGroup string `json:"ownergroup,omitempty"` + Tagged bool `json:"tagged,omitempty"` +} + +type VLANChannelBinding struct { + Count float64 `json:"__count,omitempty"` + ID int `json:"id,omitempty"` + IFNum string `json:"ifnum,omitempty"` + OwnerGroup string `json:"ownergroup,omitempty"` + Tagged bool `json:"tagged,omitempty"` +} + +type FISBinding struct { + FISChannelBinding []any `json:"fis_channel_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type VXLANIPTunnelBinding struct { + Count float64 `json:"__count,omitempty"` + ID int `json:"id,omitempty"` + Tunnel string `json:"tunnel,omitempty"` +} + +type NetProfileBinding struct { + Name string `json:"name,omitempty"` + NetProfileNATRuleBinding []any `json:"netprofile_natrule_binding,omitempty"` + NetProfileSrcPortSetBinding []any `json:"netprofile_srcportset_binding,omitempty"` +} + +type VXLANVLANMapVXLANBinding struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + VLAN []string `json:"vlan,omitempty"` + VXLAN int `json:"vxlan,omitempty"` +} + +type NetBridge struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + VXLANVLANMap string `json:"vxlanvlanmap,omitempty"` +} + +type VRIDParam struct { + DeadInterval int `json:"deadinterval,omitempty"` + HelloInterval int `json:"hellointerval,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + SendToMaster string `json:"sendtomaster,omitempty"` +} + +type VXLANSrcIPBinding struct { + Count float64 `json:"__count,omitempty"` + ID int `json:"id,omitempty"` + SrcIP string `json:"srcip,omitempty"` +} + +type IPSetBinding struct { + IPSetNSIP6Binding []any `json:"ipset_nsip6_binding,omitempty"` + IPSetNSIPBinding []any `json:"ipset_nsip_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type NAT64 struct { + ACL6Name string `json:"acl6name,omitempty"` + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NetProfile string `json:"netprofile,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type RNATSession struct { + ACLName string `json:"aclname,omitempty"` + NatIP string `json:"natip,omitempty"` + Netmask string `json:"netmask,omitempty"` + Network string `json:"network,omitempty"` +} + +type VXLAN struct { + Count float64 `json:"__count,omitempty"` + DynamicRouting string `json:"dynamicrouting,omitempty"` + ID int `json:"id,omitempty"` + InnerVLANTagging string `json:"innervlantagging,omitempty"` + IPv6DynamicRouting string `json:"ipv6dynamicrouting,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PartitionName string `json:"partitionname,omitempty"` + Port int `json:"port,omitempty"` + Protocol string `json:"protocol,omitempty"` + TD int `json:"td,omitempty"` + TypeField string `json:"type,omitempty"` + VLAN int `json:"vlan,omitempty"` +} + +type FISInterfaceBinding struct { + IFNum string `json:"ifnum,omitempty"` + Name string `json:"name,omitempty"` + OwnerNode int `json:"ownernode,omitempty"` +} + +type VRIDChannelBinding struct { + Count float64 `json:"__count,omitempty"` + Flags int `json:"flags,omitempty"` + ID int `json:"id,omitempty"` + IFNum string `json:"ifnum,omitempty"` + VLAN int `json:"vlan,omitempty"` +} + +type VRIDBinding struct { + ID int `json:"id,omitempty"` + VRIDChannelBinding []any `json:"vrid_channel_binding,omitempty"` + VRIDInterfaceBinding []any `json:"vrid_interface_binding,omitempty"` + VRIDNSIP6Binding []any `json:"vrid_nsip6_binding,omitempty"` + VRIDNSIPBinding []any `json:"vrid_nsip_binding,omitempty"` + VRIDTrackInterfaceBinding []any `json:"vrid_trackinterface_binding,omitempty"` +} + +type NetBridgeIPTunnelBinding struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + Tunnel string `json:"tunnel,omitempty"` +} + +type IPSetNSIPBinding struct { + Count float64 `json:"__count,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + Name string `json:"name,omitempty"` +} + +type VLANNSIPBinding struct { + Count float64 `json:"__count,omitempty"` + ID int `json:"id,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + Netmask string `json:"netmask,omitempty"` + OwnerGroup string `json:"ownergroup,omitempty"` + TD int `json:"td,omitempty"` +} + +type LinkSetInterfaceBinding struct { + Count float64 `json:"__count,omitempty"` + ID string `json:"id,omitempty"` + IFNum string `json:"ifnum,omitempty"` +} + +type VRIDTrackInterfaceBinding struct { + Count float64 `json:"__count,omitempty"` + Flags int `json:"flags,omitempty"` + ID int `json:"id,omitempty"` + TrackIFNum string `json:"trackifnum,omitempty"` +} + +type VRID6Binding struct { + ID int `json:"id,omitempty"` + VRID6ChannelBinding []any `json:"vrid6_channel_binding,omitempty"` + VRID6InterfaceBinding []any `json:"vrid6_interface_binding,omitempty"` + VRID6NSIP6Binding []any `json:"vrid6_nsip6_binding,omitempty"` + VRID6NSIPBinding []any `json:"vrid6_nsip_binding,omitempty"` + VRID6TrackInterfaceBinding []any `json:"vrid6_trackinterface_binding,omitempty"` +} + +type NetBridgeNSIPBinding struct { + Count float64 `json:"__count,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + Name string `json:"name,omitempty"` + Netmask string `json:"netmask,omitempty"` +} + +type RSSKeyType struct { + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + RSSType string `json:"rsstype,omitempty"` +} + +type MapBMRBMRV4NetworkBinding struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + Netmask string `json:"netmask,omitempty"` + Network string `json:"network,omitempty"` +} + +type RNAT6NSIP6Binding struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NatIP6 string `json:"natip6,omitempty"` + OwnerGroup string `json:"ownergroup,omitempty"` + TD int `json:"td,omitempty"` +} + +type Route struct { + Adv bool `json:"adv,omitempty"` + AdvBGP bool `json:"advbgp,omitempty"` + Advertise string `json:"advertise,omitempty"` + AdvISIS bool `json:"advisis,omitempty"` + AdvOSPF bool `json:"advospf,omitempty"` + AdvRIP bool `json:"advrip,omitempty"` + BGP bool `json:"bgp,omitempty"` + Cost int `json:"cost,omitempty"` + Cost1 int `json:"cost1,omitempty"` + Count float64 `json:"__count,omitempty"` + Data bool `json:"data,omitempty"` + Data0 bool `json:"data0,omitempty"` + Detail bool `json:"detail,omitempty"` + DHCP bool `json:"dhcp,omitempty"` + Direct bool `json:"direct,omitempty"` + Distance int `json:"distance,omitempty"` + Dynamic bool `json:"dynamic,omitempty"` + FailedProbes int `json:"failedprobes,omitempty"` + Flags bool `json:"flags,omitempty"` + Gateway string `json:"gateway,omitempty"` + GatewayName string `json:"gatewayname,omitempty"` + ISIS bool `json:"isis,omitempty"` + LBRoute bool `json:"lbroute,omitempty"` + Mgmt bool `json:"mgmt,omitempty"` + Monitor string `json:"monitor,omitempty"` + MonStatCode int `json:"monstatcode,omitempty"` + MonStatParam1 int `json:"monstatparam1,omitempty"` + MonStatParam2 int `json:"monstatparam2,omitempty"` + MonStatParam3 int `json:"monstatparam3,omitempty"` + MSR string `json:"msr,omitempty"` + NAT bool `json:"nat,omitempty"` + Netmask string `json:"netmask,omitempty"` + Network string `json:"network,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OSPF bool `json:"ospf,omitempty"` + OwnerGroup string `json:"ownergroup,omitempty"` + Permanent bool `json:"permanent,omitempty"` + Protocol []string `json:"protocol,omitempty"` + Retain int `json:"retain,omitempty"` + RIP bool `json:"rip,omitempty"` + RouteOwners []string `json:"routeowners,omitempty"` + RouteType string `json:"routetype,omitempty"` + State int `json:"state,omitempty"` + Static bool `json:"Static,omitempty"` + TD int `json:"td,omitempty"` + TotalFailedProbes int `json:"totalfailedprobes,omitempty"` + TotalProbes int `json:"totalprobes,omitempty"` + Tunnel bool `json:"tunnel,omitempty"` + TypeField bool `json:"type,omitempty"` + VLAN int `json:"vlan,omitempty"` + Weight int `json:"weight,omitempty"` +} + +type NetBridgeBinding struct { + Name string `json:"name,omitempty"` + NetBridgeIPTunnelBinding []any `json:"netbridge_iptunnel_binding,omitempty"` + NetBridgeNSIP6Binding []any `json:"netbridge_nsip6_binding,omitempty"` + NetBridgeNSIPBinding []any `json:"netbridge_nsip_binding,omitempty"` + NetBridgeVLANBinding []any `json:"netbridge_vlan_binding,omitempty"` +} + +type LinkSetChannelBinding struct { + Count float64 `json:"__count,omitempty"` + ID string `json:"id,omitempty"` + IFNum string `json:"ifnum,omitempty"` +} + +type IP6Tunnel struct { + Count float64 `json:"__count,omitempty"` + EncapIP string `json:"encapip,omitempty"` + Local string `json:"local,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OwnerGroup string `json:"ownergroup,omitempty"` + Remote string `json:"remote,omitempty"` + RemoteIP string `json:"remoteip,omitempty"` + TypeField int `json:"type,omitempty"` +} + +type L4Param struct { + L2ConnMethod string `json:"l2connmethod,omitempty"` + L4Switch string `json:"l4switch,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type VXLANVLANMap struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type MapBMRBinding struct { + MapBMRBMRV4NetworkBinding []any `json:"mapbmr_bmrv4network_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type VRIDInterfaceBinding struct { + Count float64 `json:"__count,omitempty"` + Flags int `json:"flags,omitempty"` + ID int `json:"id,omitempty"` + IFNum string `json:"ifnum,omitempty"` + VLAN int `json:"vlan,omitempty"` +} + +type BridgeTable struct { + BridgeAge int `json:"bridgeage,omitempty"` + Channel int `json:"channel,omitempty"` + ControlPlane bool `json:"controlplane,omitempty"` + Count float64 `json:"__count,omitempty"` + DeviceVLAN int `json:"devicevlan,omitempty"` + Flags int `json:"flags,omitempty"` + IFNum string `json:"ifnum,omitempty"` + MAC string `json:"mac,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + TypeField string `json:"type,omitempty"` + VLAN int `json:"vlan,omitempty"` + VNI int `json:"vni,omitempty"` + VTEP string `json:"vtep,omitempty"` + VXLAN int `json:"vxlan,omitempty"` +} + +type VXLANVLANMapBinding struct { + Name string `json:"name,omitempty"` + VXLANVLANMapVXLANBinding []any `json:"vxlanvlanmap_vxlan_binding,omitempty"` +} + +type VRID struct { + All bool `json:"all,omitempty"` + Count float64 `json:"__count,omitempty"` + EffectivePriority int `json:"effectivepriority,omitempty"` + Flags int `json:"flags,omitempty"` + ID int `json:"id,omitempty"` + Ifaces string `json:"ifaces,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OperationalOwnerNode int `json:"operationalownernode,omitempty"` + OwnerNode int `json:"ownernode,omitempty"` + Preemption string `json:"preemption,omitempty"` + PreemptionDelayTimer int `json:"preemptiondelaytimer,omitempty"` + Priority int `json:"priority,omitempty"` + Sharing string `json:"sharing,omitempty"` + State int `json:"state,omitempty"` + TrackIFNumPriority int `json:"trackifnumpriority,omitempty"` + Tracking string `json:"tracking,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type NetBridgeNSIP6Binding struct { + Count float64 `json:"__count,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + Name string `json:"name,omitempty"` + Netmask string `json:"netmask,omitempty"` +} + +type INAT struct { + ConnFailover string `json:"connfailover,omitempty"` + Count float64 `json:"__count,omitempty"` + Flags int `json:"flags,omitempty"` + FTP string `json:"ftp,omitempty"` + Mode string `json:"mode,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PrivateIP string `json:"privateip,omitempty"` + ProxyIP string `json:"proxyip,omitempty"` + PublicIP string `json:"publicip,omitempty"` + TCPProxy string `json:"tcpproxy,omitempty"` + TD int `json:"td,omitempty"` + TFTP string `json:"tftp,omitempty"` + UseProxyPort string `json:"useproxyport,omitempty"` + USIP string `json:"usip,omitempty"` + USNIP string `json:"usnip,omitempty"` +} + +type RNATRetainSourcePortSetBinding struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + RetainSourcePortRange string `json:"retainsourceportrange,omitempty"` +} + +type VLAN struct { + AliasName string `json:"aliasname,omitempty"` + Count float64 `json:"__count,omitempty"` + DynamicRouting string `json:"dynamicrouting,omitempty"` + ID int `json:"id,omitempty"` + Ifaces string `json:"ifaces,omitempty"` + IFNum string `json:"ifnum,omitempty"` + IPv6DynamicRouting string `json:"ipv6dynamicrouting,omitempty"` + LinkLocalIPv6Addr string `json:"linklocalipv6addr,omitempty"` + LSBitmap int `json:"lsbitmap,omitempty"` + LSTagBitmap int `json:"lstagbitmap,omitempty"` + MTU int `json:"mtu,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PartitionName string `json:"partitionname,omitempty"` + PortBitmap int `json:"portbitmap,omitempty"` + RNAT bool `json:"rnat,omitempty"` + SDXVLAN string `json:"sdxvlan,omitempty"` + Sharing string `json:"sharing,omitempty"` + TagBitmap int `json:"tagbitmap,omitempty"` + Tagged bool `json:"tagged,omitempty"` + TagIfaces string `json:"tagifaces,omitempty"` + VLANTD int `json:"vlantd,omitempty"` + VXLAN int `json:"vxlan,omitempty"` +} + +type PortAllocation struct { + Count float64 `json:"__count,omitempty"` + DestIP string `json:"destip,omitempty"` + DestPort int `json:"destport,omitempty"` + FreePorts int `json:"freeports,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + Protocol int `json:"protocol,omitempty"` + SrcIP string `json:"srcip,omitempty"` +} + +type RNATParam struct { + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + SrcIPPersistency string `json:"srcippersistency,omitempty"` + TCPProxy string `json:"tcpproxy,omitempty"` +} + +type VRID6NSIP6Binding struct { + Count float64 `json:"__count,omitempty"` + Flags int `json:"flags,omitempty"` + ID int `json:"id,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` +} + +type VXLANNSIP6Binding struct { + Count float64 `json:"__count,omitempty"` + ID int `json:"id,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + Netmask string `json:"netmask,omitempty"` +} + +type VLANBinding struct { + ID int `json:"id,omitempty"` + VLANChannelBinding []any `json:"vlan_channel_binding,omitempty"` + VLANInterfaceBinding []any `json:"vlan_interface_binding,omitempty"` + VLANLinkSetBinding []any `json:"vlan_linkset_binding,omitempty"` + VLANNSIP6Binding []any `json:"vlan_nsip6_binding,omitempty"` + VLANNSIPBinding []any `json:"vlan_nsip_binding,omitempty"` +} + +type RNATBinding struct { + Name string `json:"name,omitempty"` + RNATNSIPBinding []any `json:"rnat_nsip_binding,omitempty"` + RNATRetainSourcePortSetBinding []any `json:"rnat_retainsourceportset_binding,omitempty"` +} + +type NetBridgeVLANBinding struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + VLAN int `json:"vlan,omitempty"` +} + +type Interface struct { + ActDuplex string `json:"actduplex,omitempty"` + ActFlowCtl string `json:"actflowctl,omitempty"` + ActMedia string `json:"actmedia,omitempty"` + ActSpeed string `json:"actspeed,omitempty"` + ActThroughput int `json:"actthroughput,omitempty"` + ActualMTU int `json:"actualmtu,omitempty"` + ActualRingSize int `json:"actualringsize,omitempty"` + Autoneg string `json:"autoneg,omitempty"` + AutonegResult int `json:"autonegresult,omitempty"` + Backplane string `json:"backplane,omitempty"` + BandwidthHigh int `json:"bandwidthhigh,omitempty"` + BandwidthNormal int `json:"bandwidthnormal,omitempty"` + BdgMacMoved int `json:"bdgmacmoved,omitempty"` + BdgMuted int `json:"bdgmuted,omitempty"` + ClearTime int `json:"cleartime,omitempty"` + Count float64 `json:"__count,omitempty"` + Description string `json:"description,omitempty"` + DeviceName string `json:"devicename,omitempty"` + Downtime int `json:"downtime,omitempty"` + Duplex string `json:"duplex,omitempty"` + FCtls int `json:"fctls,omitempty"` + Flags int `json:"flags,omitempty"` + FlowCtl string `json:"flowctl,omitempty"` + HAHeartbeat string `json:"haheartbeat,omitempty"` + HAMonitor string `json:"hamonitor,omitempty"` + HangDetect int `json:"hangdetect,omitempty"` + HangReset int `json:"hangreset,omitempty"` + Hangs int `json:"hangs,omitempty"` + ID string `json:"id,omitempty"` + IFAlias string `json:"ifalias,omitempty"` + IFNum []string `json:"ifnum,omitempty"` + InDisc int `json:"indisc,omitempty"` + IntfState int `json:"intfstate,omitempty"` + IntfType string `json:"intftype,omitempty"` + LACPActorAggregation string `json:"lacpactoraggregation,omitempty"` + LACPActorCollecting string `json:"lacpactorcollecting,omitempty"` + LACPActorDistributing string `json:"lacpactordistributing,omitempty"` + LACPActorInSync string `json:"lacpactorinsync,omitempty"` + LACPActorMode string `json:"lacpactormode,omitempty"` + LACPActorPortNo int `json:"lacpactorportno,omitempty"` + LACPActorPriority int `json:"lacpactorpriority,omitempty"` + LACPActorTimeout string `json:"lacpactortimeout,omitempty"` + LACPKey int `json:"lacpkey,omitempty"` + LACPMode string `json:"lacpmode,omitempty"` + LACPPartnerAggregation string `json:"lacppartneraggregation,omitempty"` + LACPPartnerCollecting string `json:"lacppartnercollecting,omitempty"` + LACPPartnerDefaulted string `json:"lacppartnerdefaulted,omitempty"` + LACPPartnerDistributing string `json:"lacppartnerdistributing,omitempty"` + LACPPartnerExpired string `json:"lacppartnerexpired,omitempty"` + LACPPartnerInSync string `json:"lacppartnerinsync,omitempty"` + LACPPartnerKey int `json:"lacppartnerkey,omitempty"` + LACPPartnerPortNo int `json:"lacppartnerportno,omitempty"` + LACPPartnerPriority int `json:"lacppartnerpriority,omitempty"` + LACPPartnerState string `json:"lacppartnerstate,omitempty"` + LACPPartnerSystemMAC string `json:"lacppartnersystemmac,omitempty"` + LACPPartnerSystemPriority int `json:"lacppartnersystempriority,omitempty"` + LACPPartnerTimeout string `json:"lacppartnertimeout,omitempty"` + LACPPortMuxState string `json:"lacpportmuxstate,omitempty"` + LACPPortRxStat string `json:"lacpportrxstat,omitempty"` + LACPPortSelectState string `json:"lacpportselectstate,omitempty"` + LACPPriority int `json:"lacppriority,omitempty"` + LACPTimeout string `json:"lacptimeout,omitempty"` + LAGType string `json:"lagtype,omitempty"` + LinkRedundancy string `json:"linkredundancy,omitempty"` + LinkState int `json:"linkstate,omitempty"` + LLDPMode string `json:"lldpmode,omitempty"` + LRActiveIntf int `json:"lractiveintf,omitempty"` + LRSetPriority int `json:"lrsetpriority,omitempty"` + MAC string `json:"mac,omitempty"` + MACDistr string `json:"macdistr,omitempty"` + Media string `json:"media,omitempty"` + Mode string `json:"mode,omitempty"` + MTU int `json:"mtu,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OutDisc int `json:"outdisc,omitempty"` + ReqDuplex string `json:"reqduplex,omitempty"` + ReqFlowControl string `json:"reqflowcontrol,omitempty"` + ReqMedia string `json:"reqmedia,omitempty"` + ReqSpeed string `json:"reqspeed,omitempty"` + ReqThroughput int `json:"reqthroughput,omitempty"` + RingSize int `json:"ringsize,omitempty"` + RingType string `json:"ringtype,omitempty"` + RxBytes int `json:"rxbytes,omitempty"` + RxDrops int `json:"rxdrops,omitempty"` + RxErrors int `json:"rxerrors,omitempty"` + RxPackets int `json:"rxpackets,omitempty"` + RxStalls int `json:"rxstalls,omitempty"` + SlaveDuplex int `json:"slaveduplex,omitempty"` + SlaveFlowCtl int `json:"slaveflowctl,omitempty"` + SlaveMedia int `json:"slavemedia,omitempty"` + SlaveSpeed int `json:"slavespeed,omitempty"` + SlaveState int `json:"slavestate,omitempty"` + SlaveTime int `json:"slavetime,omitempty"` + Speed string `json:"speed,omitempty"` + State string `json:"state,omitempty"` + StsStalls int `json:"stsstalls,omitempty"` + SVMCmd int `json:"svmcmd,omitempty"` + TagAll string `json:"tagall,omitempty"` + Tagged int `json:"tagged,omitempty"` + TaggedAny int `json:"taggedany,omitempty"` + TaggedAutoLearn int `json:"taggedautolearn,omitempty"` + Throughput int `json:"throughput,omitempty"` + Trunk string `json:"trunk,omitempty"` + TrunkAllowedVLAN []string `json:"trunkallowedvlan,omitempty"` + TrunkMode string `json:"trunkmode,omitempty"` + TxBytes int `json:"txbytes,omitempty"` + TxDrops int `json:"txdrops,omitempty"` + TxErrors int `json:"txerrors,omitempty"` + TxPackets int `json:"txpackets,omitempty"` + TxStalls int `json:"txstalls,omitempty"` + Unit int `json:"unit,omitempty"` + Uptime int `json:"uptime,omitempty"` + VLAN int `json:"vlan,omitempty"` + VMAC string `json:"vmac,omitempty"` + VMAC6 string `json:"vmac6,omitempty"` +} + +type ND6 struct { + Channel int `json:"channel,omitempty"` + ControlPlane bool `json:"controlplane,omitempty"` + Count float64 `json:"__count,omitempty"` + Flags int `json:"flags,omitempty"` + IFNum string `json:"ifnum,omitempty"` + MAC string `json:"mac,omitempty"` + Neighbor string `json:"neighbor,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + State string `json:"state,omitempty"` + TD int `json:"td,omitempty"` + Timeout int `json:"timeout,omitempty"` + VLAN int `json:"vlan,omitempty"` + VTEP string `json:"vtep,omitempty"` + VXLAN int `json:"vxlan,omitempty"` +} + +type InterfacePair struct { + Count float64 `json:"__count,omitempty"` + ID int `json:"id,omitempty"` + Ifaces string `json:"ifaces,omitempty"` + IFNum []string `json:"ifnum,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type MapBMR struct { + Count float64 `json:"__count,omitempty"` + EABitLength int `json:"eabitlength,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PSIDLength int `json:"psidlength,omitempty"` + PSIDOffset int `json:"psidoffset,omitempty"` + RuleIPv6Prefix string `json:"ruleipv6prefix,omitempty"` +} + +type VxlanBinding struct { + ID int `json:"id,omitempty"` + VxlanIPTunnelBinding []any `json:"vxlan_iptunnel_binding,omitempty"` + VxlanNSIP6Binding []any `json:"vxlan_nsip6_binding,omitempty"` + VxlanNSIPBinding []any `json:"vxlan_nsip_binding,omitempty"` + VxlanSrcIPBinding []any `json:"vxlan_srcip_binding,omitempty"` +} + +type FIS struct { + Count float64 `json:"__count,omitempty"` + Ifaces string `json:"ifaces,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OwnerNode int `json:"ownernode,omitempty"` +} + +type LinkSet struct { + Count float64 `json:"__count,omitempty"` + ID string `json:"id,omitempty"` + IFNum string `json:"ifnum,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type BridgeGroupNSIPBinding struct { + Count float64 `json:"__count,omitempty"` + ID int `json:"id,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + Netmask string `json:"netmask,omitempty"` + OwnerGroup string `json:"ownergroup,omitempty"` + RNAT bool `json:"rnat,omitempty"` + TD int `json:"td,omitempty"` +} + +type OnLinkIPv6Prefix struct { + AutonomusPrefix string `json:"autonomusprefix,omitempty"` + Count float64 `json:"__count,omitempty"` + DecrementPrefixLifetimes string `json:"decrementprefixlifetimes,omitempty"` + DepricatePrefix string `json:"depricateprefix,omitempty"` + IPv6Prefix string `json:"ipv6prefix,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OnLinkPrefix string `json:"onlinkprefix,omitempty"` + PrefixCurrPreferredLft int `json:"prefixcurrpreferredlft,omitempty"` + PrefixCurrValidLft int `json:"prefixcurrvalidelft,omitempty"` + PrefixPreferredLifetime int `json:"prefixpreferredlifetime,omitempty"` + PrefixValidLifetime int `json:"prefixvalidelifetime,omitempty"` +} + +type VRID6NSIPBinding struct { + Count float64 `json:"__count,omitempty"` + Flags int `json:"flags,omitempty"` + ID int `json:"id,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` +} + +type CI struct { + Count float64 `json:"__count,omitempty"` + Ifaces string `json:"ifaces,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type IPv6 struct { + BaseReachTime int `json:"basereachtime,omitempty"` + Count float64 `json:"__count,omitempty"` + DODAD string `json:"dodad,omitempty"` + NatPrefix string `json:"natprefix,omitempty"` + NDBaseReachTime int `json:"ndbasereachtime,omitempty"` + NDReachTime int `json:"ndreachtime,omitempty"` + NDRetransmissionTime int `json:"ndretransmissiontime,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + RALearning string `json:"ralearning,omitempty"` + ReachTime int `json:"reachtime,omitempty"` + RetransmissionTime int `json:"retransmissiontime,omitempty"` + RouterRedirection string `json:"routerredirection,omitempty"` + TD int `json:"td,omitempty"` + USIPNatPrefix string `json:"usipnatprefix,omitempty"` +} + +type LinkSetBinding struct { + ID string `json:"id,omitempty"` + LinkSetChannelBinding []any `json:"linkset_channel_binding,omitempty"` + LinkSetInterfaceBinding []any `json:"linkset_interface_binding,omitempty"` +} + +type VRID6InterfaceBinding struct { + Count float64 `json:"__count,omitempty"` + Flags int `json:"flags,omitempty"` + ID int `json:"id,omitempty"` + IFNum string `json:"ifnum,omitempty"` + VLAN int `json:"vlan,omitempty"` +} + +type RNATGlobalBinding struct { + RNATGlobalAuditSyslogPolicyBinding []any `json:"rnatglobal_auditsyslogpolicy_binding,omitempty"` +} + +type FISChannelBinding struct { + Count float64 `json:"__count,omitempty"` + IFNum string `json:"ifnum,omitempty"` + Name string `json:"name,omitempty"` + OwnerNode int `json:"ownernode,omitempty"` +} + +type MapDomainBinding struct { + MapDomainMapBMRBinding []any `json:"mapdomain_mapbmr_binding,omitempty"` + Name string `json:"name,omitempty"` +} + +type MapDomainMapBMRBinding struct { + Count float64 `json:"__count,omitempty"` + MapBMRName string `json:"mapbmrname,omitempty"` + Name string `json:"name,omitempty"` +} diff --git a/nitrogo/models/ns.go b/nitrogo/models/ns.go new file mode 100644 index 0000000..2c69794 --- /dev/null +++ b/nitrogo/models/ns.go @@ -0,0 +1,1828 @@ +package models + +// ns configuration structs +type NSPBR struct { + Action string `json:"action,omitempty"` + Count float64 `json:"__count,omitempty"` + CurState int `json:"curstate,omitempty"` + Data bool `json:"data,omitempty"` + DestIP bool `json:"destip,omitempty"` + DestIPOp string `json:"destipop,omitempty"` + DestIPVal string `json:"destipval,omitempty"` + DestPort bool `json:"destport,omitempty"` + DestPortOp string `json:"destportop,omitempty"` + DestPortVal string `json:"destportval,omitempty"` + Detail bool `json:"detail,omitempty"` + FailedProbes int `json:"failedprobes,omitempty"` + Hits int `json:"hits,omitempty"` + Interface string `json:"Interface,omitempty"` + IPTunnel bool `json:"iptunnel,omitempty"` + IPTunnelName string `json:"iptunnelname,omitempty"` + KernelState string `json:"kernelstate,omitempty"` + Monitor string `json:"monitor,omitempty"` + MonStatCode int `json:"monstatcode,omitempty"` + MonStatParam1 int `json:"monstatparam1,omitempty"` + MonStatParam2 int `json:"monstatparam2,omitempty"` + MonStatParam3 int `json:"monstatparam3,omitempty"` + MSR string `json:"msr,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NextHop bool `json:"nexthop,omitempty"` + NextHopVal string `json:"nexthopval,omitempty"` + OwnerGroup string `json:"ownergroup,omitempty"` + Priority int `json:"priority,omitempty"` + Protocol string `json:"protocol,omitempty"` + ProtocolNumber int `json:"protocolnumber,omitempty"` + SrcIP bool `json:"srcip,omitempty"` + SrcIPOp string `json:"srcipop,omitempty"` + SrcIPVal string `json:"srcipval,omitempty"` + SrcMac string `json:"srcmac,omitempty"` + SrcMacMask string `json:"srcmacmask,omitempty"` + SrcPort bool `json:"srcport,omitempty"` + SrcPortOp string `json:"srcportop,omitempty"` + SrcPortVal string `json:"srcportval,omitempty"` + State string `json:"state,omitempty"` + TargetTD int `json:"targettd,omitempty"` + TD int `json:"td,omitempty"` + TotalFailedProbes int `json:"totalfailedprobes,omitempty"` + TotalProbes int `json:"totalprobes,omitempty"` + VLAN int `json:"vlan,omitempty"` + VXLAN int `json:"vxlan,omitempty"` + VXLANVLANMap string `json:"vxlanvlanmap,omitempty"` +} + +type NSTrafficDomainVXLANBinding struct { + Count float64 `json:"__count,omitempty"` + TD int `json:"td,omitempty"` + VXLAN int `json:"vxlan,omitempty"` +} + +type NSPartition struct { + Count float64 `json:"__count,omitempty"` + Force bool `json:"force,omitempty"` + MaxBandwidth int `json:"maxbandwidth,omitempty"` + MaxConn int `json:"maxconn,omitempty"` + MaxMemLimit int `json:"maxmemlimit,omitempty"` + MinBandwidth int `json:"minbandwidth,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PartitionID int `json:"partitionid,omitempty"` + PartitionMAC string `json:"partitionmac,omitempty"` + PartitionName string `json:"partitionname,omitempty"` + PartitionType string `json:"partitiontype,omitempty"` + PMACInternal bool `json:"pmacinternal,omitempty"` + Save bool `json:"save,omitempty"` +} + +type NSExtensionBinding struct { + Name string `json:"name,omitempty"` + NSExtensionExtensionFunctionBinding []any `json:"nsextension_extensionfunction_binding,omitempty"` +} + +type NSLicense struct { + AAA bool `json:"aaa,omitempty"` + AdaptiveTCP bool `json:"adaptivetcp,omitempty"` + AGEE bool `json:"agee,omitempty"` + APIGateway bool `json:"apigateway,omitempty"` + AppFlow bool `json:"appflow,omitempty"` + AppFlowICA bool `json:"appflowica,omitempty"` + AppFW bool `json:"appfw,omitempty"` + AppQOE bool `json:"appqoe,omitempty"` + BGP bool `json:"bgp,omitempty"` + Bot bool `json:"bot,omitempty"` + CF bool `json:"cf,omitempty"` + CH bool `json:"ch,omitempty"` + CloudBridge bool `json:"cloudbridge,omitempty"` + CloudBridgeAppliance bool `json:"cloudbridgeappliance,omitempty"` + CloudExtenderAppliance bool `json:"cloudextenderappliance,omitempty"` + CloudSubscriptionImage string `json:"cloudsubscriptionimage,omitempty"` + Cluster bool `json:"cluster,omitempty"` + CMP bool `json:"cmp,omitempty"` + ContentAccelerator bool `json:"contentaccelerator,omitempty"` + CQA bool `json:"cqa,omitempty"` + CR bool `json:"cr,omitempty"` + CS bool `json:"cs,omitempty"` + DaysToExpiration int `json:"daystoexpiration,omitempty"` + DaysToLASEnforcement int `json:"daystolasenforcement,omitempty"` + Delta bool `json:"delta,omitempty"` + FICAUsers int `json:"f_ica_users,omitempty"` + FSSLVPNUsers int `json:"f_sslvpn_users,omitempty"` + FEO bool `json:"feo,omitempty"` + ForwardProxy bool `json:"forwardproxy,omitempty"` + GSLB bool `json:"gslb,omitempty"` + GSLBP bool `json:"gslbp,omitempty"` + IC bool `json:"ic,omitempty"` + IPv6PT bool `json:"ipv6pt,omitempty"` + IsEnterpriseLic bool `json:"isenterpriselic,omitempty"` + ISIS bool `json:"isis,omitempty"` + IsPlatinumLic bool `json:"isplatinumlic,omitempty"` + IsSGWYLic bool `json:"issgwylic,omitempty"` + IsStandardLic bool `json:"isstandardlic,omitempty"` + IsSWGLic bool `json:"isswglic,omitempty"` + LB bool `json:"lb,omitempty"` + LicensingMode string `json:"licensingmode,omitempty"` + LSN bool `json:"lsn,omitempty"` + ModelID int `json:"modelid,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NSXN bool `json:"nsxn,omitempty"` + OSPF bool `json:"ospf,omitempty"` + Push bool `json:"push,omitempty"` + RDPProxy bool `json:"rdpproxy,omitempty"` + RemoteContentInspection bool `json:"remotecontentinspection,omitempty"` + Rep bool `json:"rep,omitempty"` + Responder bool `json:"responder,omitempty"` + Rewrite bool `json:"rewrite,omitempty"` + RIP bool `json:"rip,omitempty"` + Routing bool `json:"routing,omitempty"` + SP bool `json:"sp,omitempty"` + SSL bool `json:"ssl,omitempty"` + SSLInterception bool `json:"sslinterception,omitempty"` + SSLVPN bool `json:"sslvpn,omitempty"` + URLFiltering bool `json:"urlfiltering,omitempty"` + VideoOptimization bool `json:"videooptimization,omitempty"` + WL bool `json:"wl,omitempty"` +} + +type NSTestLicense struct { + AAA bool `json:"aaa,omitempty"` + AdaptiveTCP bool `json:"adaptivetcp,omitempty"` + AGEE bool `json:"agee,omitempty"` + APIGateway bool `json:"apigateway,omitempty"` + AppFlow bool `json:"appflow,omitempty"` + AppFlowICA bool `json:"appflowica,omitempty"` + AppFW bool `json:"appfw,omitempty"` + AppQOE bool `json:"appqoe,omitempty"` + BGP bool `json:"bgp,omitempty"` + Bot bool `json:"bot,omitempty"` + CF bool `json:"cf,omitempty"` + CH bool `json:"ch,omitempty"` + CloudBridge bool `json:"cloudbridge,omitempty"` + CloudBridgeAppliance bool `json:"cloudbridgeappliance,omitempty"` + CloudExtenderAppliance bool `json:"cloudextenderappliance,omitempty"` + Cluster bool `json:"cluster,omitempty"` + CMP bool `json:"cmp,omitempty"` + ContentAccelerator bool `json:"contentaccelerator,omitempty"` + CQA bool `json:"cqa,omitempty"` + CR bool `json:"cr,omitempty"` + CS bool `json:"cs,omitempty"` + DaysToExpiration int `json:"daystoexpiration,omitempty"` + Delta bool `json:"delta,omitempty"` + FICAUsers int `json:"f_ica_users,omitempty"` + FSSLVPNUsers int `json:"f_sslvpn_users,omitempty"` + FEO bool `json:"feo,omitempty"` + ForwardProxy bool `json:"forwardproxy,omitempty"` + GSLB bool `json:"gslb,omitempty"` + GSLBP bool `json:"gslbp,omitempty"` + IC bool `json:"ic,omitempty"` + IPv6PT bool `json:"ipv6pt,omitempty"` + IsEnterpriseLic bool `json:"isenterpriselic,omitempty"` + ISIS bool `json:"isis,omitempty"` + IsPlatinumLic bool `json:"isplatinumlic,omitempty"` + IsSGWYLic bool `json:"issgwylic,omitempty"` + IsStandardLic bool `json:"isstandardlic,omitempty"` + IsSWGLic bool `json:"isswglic,omitempty"` + LB bool `json:"lb,omitempty"` + LicensingMode string `json:"licensingmode,omitempty"` + LSN bool `json:"lsn,omitempty"` + ModelID int `json:"modelid,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NSXN bool `json:"nsxn,omitempty"` + OSPF bool `json:"ospf,omitempty"` + Push bool `json:"push,omitempty"` + RDPProxy bool `json:"rdpproxy,omitempty"` + RemoteContentInspection bool `json:"remotecontentinspection,omitempty"` + Rep bool `json:"rep,omitempty"` + Responder bool `json:"responder,omitempty"` + Rewrite bool `json:"rewrite,omitempty"` + RIP bool `json:"rip,omitempty"` + Routing bool `json:"routing,omitempty"` + SP bool `json:"sp,omitempty"` + SSL bool `json:"ssl,omitempty"` + SSLInterception bool `json:"sslinterception,omitempty"` + SSLVPN bool `json:"sslvpn,omitempty"` + URLFiltering bool `json:"urlfiltering,omitempty"` + VideoOptimization bool `json:"videooptimization,omitempty"` + WL bool `json:"wl,omitempty"` +} + +type NSLicenseServerPool struct { + CPXInstanceAvailable int `json:"cpxinstanceavailable,omitempty"` + CPXInstanceTotal int `json:"cpxinstancetotal,omitempty"` + EnterpriseBandwidthAvailable int `json:"enterprisebandwidthavailable,omitempty"` + EnterpriseBandwidthTotal int `json:"enterprisebandwidthtotal,omitempty"` + EnterpriseCPUAvailable int `json:"enterprisecpuavailable,omitempty"` + EnterpriseCPUTotal int `json:"enterprisecputotal,omitempty"` + GetAllLicenses bool `json:"getalllicenses,omitempty"` + InstanceAvailable int `json:"instanceavailable,omitempty"` + InstanceTotal int `json:"instancetotal,omitempty"` + LicenseMode string `json:"licensemode,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PlatinumBandwidthAvailable int `json:"platinumbandwidthavailable,omitempty"` + PlatinumBandwidthTotal int `json:"platinumbandwidthtotal,omitempty"` + PlatinumCPUAvailable int `json:"platinumcpuavailable,omitempty"` + PlatinumCPUTotal int `json:"platinumcputotal,omitempty"` + StandardBandwidthAvailable int `json:"standardbandwidthavailable,omitempty"` + StandardBandwidthTotal int `json:"standardbandwidthtotal,omitempty"` + StandardCPUAvailable int `json:"standardcpuavailable,omitempty"` + StandardCPUTotal int `json:"standardcputotal,omitempty"` + VPX100000EAvailable int `json:"vpx100000eavailable,omitempty"` + VPX100000ETotal int `json:"vpx100000etotal,omitempty"` + VPX100000PAvailable int `json:"vpx100000pavailable,omitempty"` + VPX100000PTotal int `json:"vpx100000ptotal,omitempty"` + VPX100000SAvailable int `json:"vpx100000savailable,omitempty"` + VPX100000STotal int `json:"vpx100000stotal,omitempty"` + VPX10000EAvailable int `json:"vpx10000eavailable,omitempty"` + VPX10000ETotal int `json:"vpx10000etotal,omitempty"` + VPX10000PAvailable int `json:"vpx10000pavailable,omitempty"` + VPX10000PTotal int `json:"vpx10000ptotal,omitempty"` + VPX10000SAvailable int `json:"vpx10000savailable,omitempty"` + VPX10000STotal int `json:"vpx10000stotal,omitempty"` + VPX1000EAvailable int `json:"vpx1000eavailable,omitempty"` + VPX1000ETotal int `json:"vpx1000etotal,omitempty"` + VPX1000PAvailable int `json:"vpx1000pavailable,omitempty"` + VPX1000PTotal int `json:"vpx1000ptotal,omitempty"` + VPX1000SAvailable int `json:"vpx1000savailable,omitempty"` + VPX1000STotal int `json:"vpx1000stotal,omitempty"` + VPX100EAvailable int `json:"vpx100eavailable,omitempty"` + VPX100ETotal int `json:"vpx100etotal,omitempty"` + VPX100PAvailable int `json:"vpx100pavailable,omitempty"` + VPX100PTotal int `json:"vpx100ptotal,omitempty"` + VPX100SAvailable int `json:"vpx100savailable,omitempty"` + VPX100STotal int `json:"vpx100stotal,omitempty"` + VPX10EAvailable int `json:"vpx10eavailable,omitempty"` + VPX10ETotal int `json:"vpx10etotal,omitempty"` + VPX10PAvailable int `json:"vpx10pavailable,omitempty"` + VPX10PTotal int `json:"vpx10ptotal,omitempty"` + VPX10SAvailable int `json:"vpx10savailable,omitempty"` + VPX10STotal int `json:"vpx10stotal,omitempty"` + VPX15000EAvailable int `json:"vpx15000eavailable,omitempty"` + VPX15000ETotal int `json:"vpx15000etotal,omitempty"` + VPX15000PAvailable int `json:"vpx15000pavailable,omitempty"` + VPX15000PTotal int `json:"vpx15000ptotal,omitempty"` + VPX15000SAvailable int `json:"vpx15000savailable,omitempty"` + VPX15000STotal int `json:"vpx15000stotal,omitempty"` + VPX1PAvailable int `json:"vpx1pavailable,omitempty"` + VPX1PTotal int `json:"vpx1ptotal,omitempty"` + VPX1SAvailable int `json:"vpx1savailable,omitempty"` + VPX1STotal int `json:"vpx1stotal,omitempty"` + VPX2000PAvailable int `json:"vpx2000pavailable,omitempty"` + VPX2000PTotal int `json:"vpx2000ptotal,omitempty"` + VPX200EAvailable int `json:"vpx200eavailable,omitempty"` + VPX200ETotal int `json:"vpx200etotal,omitempty"` + VPX200PAvailable int `json:"vpx200pavailable,omitempty"` + VPX200PTotal int `json:"vpx200ptotal,omitempty"` + VPX200SAvailable int `json:"vpx200savailable,omitempty"` + VPX200STotal int `json:"vpx200stotal,omitempty"` + VPX25000EAvailable int `json:"vpx25000eavailable,omitempty"` + VPX25000ETotal int `json:"vpx25000etotal,omitempty"` + VPX25000PAvailable int `json:"vpx25000pavailable,omitempty"` + VPX25000PTotal int `json:"vpx25000ptotal,omitempty"` + VPX25000SAvailable int `json:"vpx25000savailable,omitempty"` + VPX25000STotal int `json:"vpx25000stotal,omitempty"` + VPX25EAvailable int `json:"vpx25eavailable,omitempty"` + VPX25ETotal int `json:"vpx25etotal,omitempty"` + VPX25PAvailable int `json:"vpx25pavailable,omitempty"` + VPX25PTotal int `json:"vpx25ptotal,omitempty"` + VPX25SAvailable int `json:"vpx25savailable,omitempty"` + VPX25STotal int `json:"vpx25stotal,omitempty"` + VPX3000EAvailable int `json:"vpx3000eavailable,omitempty"` + VPX3000ETotal int `json:"vpx3000etotal,omitempty"` + VPX3000PAvailable int `json:"vpx3000pavailable,omitempty"` + VPX3000PTotal int `json:"vpx3000ptotal,omitempty"` + VPX3000SAvailable int `json:"vpx3000savailable,omitempty"` + VPX3000STotal int `json:"vpx3000stotal,omitempty"` + VPX40000EAvailable int `json:"vpx40000eavailable,omitempty"` + VPX40000ETotal int `json:"vpx40000etotal,omitempty"` + VPX40000PAvailable int `json:"vpx40000pavailable,omitempty"` + VPX40000PTotal int `json:"vpx40000ptotal,omitempty"` + VPX40000SAvailable int `json:"vpx40000savailable,omitempty"` + VPX40000STotal int `json:"vpx40000stotal,omitempty"` + VPX4000PAvailable int `json:"vpx4000pavailable,omitempty"` + VPX4000PTotal int `json:"vpx4000ptotal,omitempty"` + VPX5000EAvailable int `json:"vpx5000eavailable,omitempty"` + VPX5000ETotal int `json:"vpx5000etotal,omitempty"` + VPX5000PAvailable int `json:"vpx5000pavailable,omitempty"` + VPX5000PTotal int `json:"vpx5000ptotal,omitempty"` + VPX5000SAvailable int `json:"vpx5000savailable,omitempty"` + VPX5000STotal int `json:"vpx5000stotal,omitempty"` + VPX500EAvailable int `json:"vpx500eavailable,omitempty"` + VPX500ETotal int `json:"vpx500etotal,omitempty"` + VPX500PAvailable int `json:"vpx500pavailable,omitempty"` + VPX500PTotal int `json:"vpx500ptotal,omitempty"` + VPX500SAvailable int `json:"vpx500savailable,omitempty"` + VPX500STotal int `json:"vpx500stotal,omitempty"` + VPX50EAvailable int `json:"vpx50eavailable,omitempty"` + VPX50ETotal int `json:"vpx50etotal,omitempty"` + VPX50PAvailable int `json:"vpx50pavailable,omitempty"` + VPX50PTotal int `json:"vpx50ptotal,omitempty"` + VPX50SAvailable int `json:"vpx50savailable,omitempty"` + VPX50STotal int `json:"vpx50stotal,omitempty"` + VPX5PAvailable int `json:"vpx5pavailable,omitempty"` + VPX5PTotal int `json:"vpx5ptotal,omitempty"` + VPX5SAvailable int `json:"vpx5savailable,omitempty"` + VPX5STotal int `json:"vpx5stotal,omitempty"` + VPX8000EAvailable int `json:"vpx8000eavailable,omitempty"` + VPX8000ETotal int `json:"vpx8000etotal,omitempty"` + VPX8000PAvailable int `json:"vpx8000pavailable,omitempty"` + VPX8000PTotal int `json:"vpx8000ptotal,omitempty"` + VPX8000SAvailable int `json:"vpx8000savailable,omitempty"` + VPX8000STotal int `json:"vpx8000stotal,omitempty"` +} + +type NSConfigView struct { + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + State string `json:"state,omitempty"` +} + +type NSTimerBinding struct { + Name string `json:"name,omitempty"` + NSTimerAutoScalePolicyBinding []any `json:"nstimer_autoscalepolicy_binding,omitempty"` +} + +type NSDiameter struct { + Count float64 `json:"__count,omitempty"` + Identity string `json:"identity,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OwnerNode int `json:"ownernode,omitempty"` + Realm string `json:"realm,omitempty"` + ServerClosePropagation string `json:"serverclosepropagation,omitempty"` +} + +type NSTrafficDomainBridgeGroupBinding struct { + BridgeGroup int `json:"bridgegroup,omitempty"` + Count float64 `json:"__count,omitempty"` + TD int `json:"td,omitempty"` +} + +type NSRollbackCmd struct { + Filename string `json:"filename,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OutType string `json:"outtype,omitempty"` +} + +type NSVPXParam struct { + CloudProductCode string `json:"cloudproductcode,omitempty"` + Count float64 `json:"__count,omitempty"` + CPUYield string `json:"cpuyield,omitempty"` + KVMVirtioMultiQueue string `json:"kvmvirtiomultiqueue,omitempty"` + MasterClockCPU1 string `json:"masterclockcpu1,omitempty"` + MemoryStatus string `json:"memorystatus,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OwnerNode int `json:"ownernode,omitempty"` + TechnicalSupportPIN string `json:"technicalsupportpin,omitempty"` + VPXEnvironment string `json:"vpxenvironment,omitempty"` + VPXOEMCode int `json:"vpxoemcode,omitempty"` +} + +type NSLicenseProxyServer struct { + Count float64 `json:"__count,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Port int `json:"port,omitempty"` + ServerIP string `json:"serverip,omitempty"` + ServerName string `json:"servername,omitempty"` +} + +type NSLimitIdentifierNSLimitSessionsBinding struct { + Count float64 `json:"__count,omitempty"` + LimitIdentifier string `json:"limitidentifier,omitempty"` +} + +type NSPartitionMac struct { + Count float64 `json:"__count,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PartitionMAC string `json:"partitionmac,omitempty"` + PartitionName string `json:"partitionname,omitempty"` +} + +type NSServicePath struct { + Count float64 `json:"__count,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ServicePathName string `json:"servicepathname,omitempty"` +} + +type NSPartitionBinding struct { + NSPartitionBridgeGroupBinding []any `json:"nspartition_bridgegroup_binding,omitempty"` + NSPartitionVlanBinding []any `json:"nspartition_vlan_binding,omitempty"` + NSPartitionVxlanBinding []any `json:"nspartition_vxlan_binding,omitempty"` + PartitionName string `json:"partitionname,omitempty"` +} + +type NSPartitionBridgeGroupBinding struct { + BridgeGroup int `json:"bridgegroup,omitempty"` + Count float64 `json:"__count,omitempty"` + PartitionName string `json:"partitionname,omitempty"` +} + +type NSConnectionTable struct { + AdaptiveTCPProfName string `json:"adaptivetcpprofname,omitempty"` + AdvWnd int `json:"advwnd,omitempty"` + BurstRateControl string `json:"burstratecontrol,omitempty"` + BWEstimate int `json:"bwestimate,omitempty"` + ChannelIDNNM int `json:"channelidnnm,omitempty"` + CongState string `json:"congstate,omitempty"` + ConnID int `json:"connid,omitempty"` + ConnProperties []string `json:"connproperties,omitempty"` + Count float64 `json:"__count,omitempty"` + CQABifAvg int `json:"cqabifavg,omitempty"` + CQACCL int `json:"cqaccl,omitempty"` + CQACSQ int `json:"cqacsq,omitempty"` + CQAAIAI1MSPct int `json:"cqaiai1mspct,omitempty"` + CQAAIAI2MSPct int `json:"cqaiai2mspct,omitempty"` + CQAAIAIAvg int `json:"cqaiaiavg,omitempty"` + CQAAIAISamples int `json:"cqaiaisamples,omitempty"` + CQAISIAvg int `json:"cqaisiavg,omitempty"` + CQALoadDelayAvg int `json:"cqaloaddelayavg,omitempty"` + CQANetClass string `json:"cqanetclass,omitempty"` + CQANoiseDelayAvg int `json:"cqanoisedelayavg,omitempty"` + CQARcvWndAvg int `json:"cqarcvwndavg,omitempty"` + CQARcvWndMin int `json:"cqarcvwndmin,omitempty"` + CQARetxCong int `json:"cqaretxcong,omitempty"` + CQARetxCorr int `json:"cqaretxcorr,omitempty"` + CQARetxPackets int `json:"cqaretxpackets,omitempty"` + CQARTTAvg int `json:"cqarttavg,omitempty"` + CQARTTMax int `json:"cqarttmax,omitempty"` + CQARTTMin int `json:"cqarttmin,omitempty"` + CQASamples int `json:"cqasamples,omitempty"` + CQAThruputAvg int `json:"cqathruputavg,omitempty"` + CreditsInBytes int `json:"creditsinbytes,omitempty"` + DestIP string `json:"destip,omitempty"` + DestPort int `json:"destport,omitempty"` + EntityName string `json:"entityname,omitempty"` + FilterExpression string `json:"filterexpression,omitempty"` + FilterName bool `json:"filtername,omitempty"` + Flavor string `json:"flavor,omitempty"` + HTTPEndSeq int `json:"httpendseq,omitempty"` + HTTPRequest string `json:"httprequest,omitempty"` + HTTPReqVer string `json:"httpreqver,omitempty"` + HTTPRspCode int `json:"httprspcode,omitempty"` + HTTPState string `json:"httpstate,omitempty"` + IdleTime int `json:"idletime,omitempty"` + IRS int `json:"irs,omitempty"` + ISS int `json:"iss,omitempty"` + Link bool `json:"link,omitempty"` + LinkBurstRateControl string `json:"linkburstratecontrol,omitempty"` + LinkBWEstimate int `json:"linkbwestimate,omitempty"` + LinkCongState string `json:"linkcongstate,omitempty"` + LinkConnID int `json:"linkconnid,omitempty"` + LinkCredits int `json:"linkcredits,omitempty"` + LinkDestIP string `json:"linkdestip,omitempty"` + LinkDestPort int `json:"linkdestport,omitempty"` + LinkEntityName string `json:"linkentityname,omitempty"` + LinkFlavor string `json:"linkflavor,omitempty"` + LinkIdleTime int `json:"linkidletime,omitempty"` + LinkMaxRcvBuf int `json:"linkmaxrcvbuf,omitempty"` + LinkMaxSndBuf int `json:"linkmaxsndbuf,omitempty"` + LinkName string `json:"linkname,omitempty"` + LinkNSBRetxQ int `json:"linknsbretxq,omitempty"` + LinkNSBTCPWaitQ int `json:"linknsbtcpwaitq,omitempty"` + LinkNSWSValue int `json:"linknswsvalue,omitempty"` + LinkOptionFlag []string `json:"linkoptionflag,omitempty"` + LinkPeerWSValue int `json:"linkpeerwsvalue,omitempty"` + LinkRateInBytes int `json:"linkrateinbytes,omitempty"` + LinkRateSchedulerQueue int `json:"linkrateschedulerqueue,omitempty"` + LinkRealTimeRTT int `json:"linkrealtimertt,omitempty"` + LinkRTTMin int `json:"linkrttmin,omitempty"` + LinkRxQSize int `json:"linkrxqsize,omitempty"` + LinkSackBlocks int `json:"linksackblocks,omitempty"` + LinkServiceType string `json:"linkservicetype,omitempty"` + LinkSndBuf int `json:"linksndbuf,omitempty"` + LinkSndRecoverLe int `json:"linksndrecoverle,omitempty"` + LinkSourceIP string `json:"linksourceip,omitempty"` + LinkSourcePort int `json:"linksourceport,omitempty"` + LinkState string `json:"linkstate,omitempty"` + LinkTCPMode string `json:"linktcpmode,omitempty"` + LinkTxQSize int `json:"linktxqsize,omitempty"` + Listen bool `json:"listen,omitempty"` + MaxAck int `json:"maxack,omitempty"` + MaxRcvBuf int `json:"maxrcvbuf,omitempty"` + MaxSndBuf int `json:"maxsndbuf,omitempty"` + MsgVersionNNM int `json:"msgversionnnm,omitempty"` + MSS int `json:"mss,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + NSBRetxQ int `json:"nsbretxq,omitempty"` + NSBTCPWaitQ int `json:"nsbtcpwaitq,omitempty"` + NSWSValue int `json:"nswsvalue,omitempty"` + OptionFlags []string `json:"optionflags,omitempty"` + OutOfOrderBlocks int `json:"outoforderblocks,omitempty"` + OutOfOrderBytes int `json:"outoforderbytes,omitempty"` + OutOfOrderFlushedCount int `json:"outoforderflushedcount,omitempty"` + OutOfOrderPkts int `json:"outoforderpkts,omitempty"` + PeerWSValue int `json:"peerwsvalue,omitempty"` + Priority string `json:"priority,omitempty"` + RateInBytes int `json:"rateinbytes,omitempty"` + RateSchedulerQueue int `json:"rateschedulerqueue,omitempty"` + RcvNxt int `json:"rcvnxt,omitempty"` + RcvWnd int `json:"rcvwnd,omitempty"` + RealTimeRTT int `json:"realtimertt,omitempty"` + RetxRetryCnt int `json:"retxretrycnt,omitempty"` + RTTMin int `json:"rttmin,omitempty"` + RTTSmoothed int `json:"rttsmoothed,omitempty"` + RTTVariance int `json:"rttvariance,omitempty"` + RxQSize int `json:"rxqsize,omitempty"` + SackBlocks int `json:"sackblocks,omitempty"` + SndBuf int `json:"sndbuf,omitempty"` + SndCwnd int `json:"sndcwnd,omitempty"` + SndNxt int `json:"sndnxt,omitempty"` + SndRecoverLe int `json:"sndrecoverle,omitempty"` + SndUnack int `json:"sndunack,omitempty"` + SourceIP string `json:"sourceip,omitempty"` + SourceNodeIDNNM int `json:"sourcenodeidnnm,omitempty"` + SourcePort int `json:"sourceport,omitempty"` + State string `json:"state,omitempty"` + SvcType string `json:"svctype,omitempty"` + TargetNodeIDNNM int `json:"targetnodeidnnm,omitempty"` + TCPMode string `json:"tcpmode,omitempty"` + TD int `json:"td,omitempty"` + TRCount int `json:"trcount,omitempty"` + TxQSize int `json:"txqsize,omitempty"` +} + +type NSServicePathNSServiceFunctionBinding struct { + Count float64 `json:"__count,omitempty"` + Index int `json:"index,omitempty"` + ServiceFunction string `json:"servicefunction,omitempty"` + ServicePathName string `json:"servicepathname,omitempty"` +} + +type NSParam struct { + AdvancedAnalyticsStats string `json:"advancedanalyticsstats,omitempty"` + AFTPAllowRandomSourcePort string `json:"aftpallowrandomsourceport,omitempty"` + AutoScaleOption int `json:"autoscaleoption,omitempty"` + CIP string `json:"cip,omitempty"` + CIPHeader string `json:"cipheader,omitempty"` + CookieVersion string `json:"cookieversion,omitempty"` + CRPortRange string `json:"crportrange,omitempty"` + ExclusiveQuotaMaxClient int `json:"exclusivequotamaxclient,omitempty"` + ExclusiveQuotaSpillover int `json:"exclusivequotaspillover,omitempty"` + FTPPortRange string `json:"ftpportrange,omitempty"` + GrantQuotaMaxClient int `json:"grantquotamaxclient,omitempty"` + GrantQuotaSpillover int `json:"grantquotaspillover,omitempty"` + HTTPPort []any `json:"httpport,omitempty"` + ICAPorts []any `json:"icaports,omitempty"` + InternalUserLogin string `json:"internaluserlogin,omitempty"` + IPTTL int `json:"ipttl,omitempty"` + MaxConn int `json:"maxconn,omitempty"` + MaxReq int `json:"maxreq,omitempty"` + MgmtHTTPPort int `json:"mgmthttpport,omitempty"` + MgmtHTTPSPort int `json:"mgmthttpsport,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PMTUMin int `json:"pmtumin,omitempty"` + PMTUTimeout int `json:"pmtutimeout,omitempty"` + ProxyProtocol string `json:"proxyprotocol,omitempty"` + SecureCookie string `json:"securecookie,omitempty"` + SecureICAPorts []any `json:"secureicaports,omitempty"` + ServicePathIngressVlan int `json:"servicepathingressvlan,omitempty"` + TCPCIP string `json:"tcpcip,omitempty"` + TimeZone string `json:"timezone,omitempty"` + UseProxyPort string `json:"useproxyport,omitempty"` +} + +type NSExtensionExtensionFunctionBinding struct { + ActiveExtensionFunction int `json:"activeextensionfunction,omitempty"` + Count float64 `json:"__count,omitempty"` + ExtensionFuncDescription string `json:"extensionfuncdescription,omitempty"` + ExtensionFunctionAllParams []string `json:"extensionfunctionallparams,omitempty"` + ExtensionFunctionAllParamsCount int `json:"extensionfunctionallparamscount,omitempty"` + ExtensionFunctionArgCount int `json:"extensionfunctionargcount,omitempty"` + ExtensionFunctionArgType []string `json:"extensionfunctionargtype,omitempty"` + ExtensionFunctionClasses []string `json:"extensionfunctionclasses,omitempty"` + ExtensionFunctionClassesCount int `json:"extensionfunctionclassescount,omitempty"` + ExtensionFunctionClassType string `json:"extensionfunctionclasstype,omitempty"` + ExtensionFunctionLineNumber int `json:"extensionfunctionlinenumber,omitempty"` + ExtensionFunctionName string `json:"extensionfunctionname,omitempty"` + ExtensionFunctionReturnType string `json:"extensionfunctionreturntype,omitempty"` + Name string `json:"name,omitempty"` +} + +type NSVersion struct { + InstalledVersion bool `json:"installedversion,omitempty"` + Mode int `json:"mode,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Version string `json:"version,omitempty"` +} + +type NSHTTPParam struct { + Builtin []string `json:"builtin,omitempty"` + ConMultiplex string `json:"conmultiplex,omitempty"` + Count float64 `json:"__count,omitempty"` + DropInvalReqs string `json:"dropinvalreqs,omitempty"` + Feature string `json:"feature,omitempty"` + HTTP2ServerSide string `json:"http2serverside,omitempty"` + IgnoreConnectCodingScheme string `json:"ignoreconnectcodingscheme,omitempty"` + InsNSSrvrHdr string `json:"insnssrvrhdr,omitempty"` + LogErrResp string `json:"logerrresp,omitempty"` + MarkConnReqInval string `json:"markconnreqinval,omitempty"` + MarkHTTP09Inval string `json:"markhttp09inval,omitempty"` + MaxReusePool int `json:"maxreusepool,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NSSrvrHdr string `json:"nssrvrhdr,omitempty"` +} + +type NSIP6 struct { + AdvertiseOnDefaultPartition string `json:"advertiseondefaultpartition,omitempty"` + Count float64 `json:"__count,omitempty"` + CurState string `json:"curstate,omitempty"` + DecrementHopLimit string `json:"decrementhoplimit,omitempty"` + DynamicRouting string `json:"dynamicrouting,omitempty"` + FTP string `json:"ftp,omitempty"` + GUI string `json:"gui,omitempty"` + HostRoute string `json:"hostroute,omitempty"` + ICMP string `json:"icmp,omitempty"` + ICMPResponse string `json:"icmpresponse,omitempty"` + IP6HostRtGw string `json:"ip6hostrtgw,omitempty"` + IPType []string `json:"iptype,omitempty"` + IPv6Address string `json:"ipv6address,omitempty"` + MapField string `json:"map,omitempty"` + Metric int `json:"metric,omitempty"` + MgmtAccess string `json:"mgmtaccess,omitempty"` + MPTCPAdvertise string `json:"mptcpadvertise,omitempty"` + ND string `json:"nd,omitempty"` + NDOwner int `json:"ndowner,omitempty"` + NetworkRoute string `json:"networkroute,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OperationalNDOwner int `json:"operationalndowner,omitempty"` + OSPF6LSAType string `json:"ospf6lsatype,omitempty"` + OSPFArea int `json:"ospfarea,omitempty"` + OwnerDownResponse string `json:"ownerdownresponse,omitempty"` + OwnerNode int `json:"ownernode,omitempty"` + RestrictAccess string `json:"restrictaccess,omitempty"` + Scope string `json:"scope,omitempty"` + SNMP string `json:"snmp,omitempty"` + SSH string `json:"ssh,omitempty"` + State string `json:"state,omitempty"` + SystemType string `json:"systemtype,omitempty"` + Tag int `json:"tag,omitempty"` + TD int `json:"td,omitempty"` + Telnet string `json:"telnet,omitempty"` + TypeField string `json:"type,omitempty"` + VIPRtAdv2BSD bool `json:"viprtadv2bsd,omitempty"` + VIPVSerCount int `json:"vipvsercount,omitempty"` + VIPVSerDownCount int `json:"vipvserdowncount,omitempty"` + VLAN int `json:"vlan,omitempty"` + VRID6 int `json:"vrid6,omitempty"` + VServer string `json:"vserver,omitempty"` + VServerRHILevel string `json:"vserverrhilevel,omitempty"` +} + +type NSPartitionVXLANBinding struct { + Count float64 `json:"__count,omitempty"` + PartitionName string `json:"partitionname,omitempty"` + VXLAN int `json:"vxlan,omitempty"` +} + +type NSIP struct { + AdvertiseOnDefaultPartition string `json:"advertiseondefaultpartition,omitempty"` + ARP string `json:"arp,omitempty"` + ARPOwner int `json:"arpowner,omitempty"` + ARPResponse string `json:"arpresponse,omitempty"` + BGP string `json:"bgp,omitempty"` + Count float64 `json:"__count,omitempty"` + DecrementTTL string `json:"decrementttl,omitempty"` + DynamicRouting string `json:"dynamicrouting,omitempty"` + Flags int `json:"flags,omitempty"` + FreePorts int `json:"freeports,omitempty"` + FTP string `json:"ftp,omitempty"` + GUI string `json:"gui,omitempty"` + HostRoute string `json:"hostroute,omitempty"` + HostRtGw string `json:"hostrtgw,omitempty"` + HostRtGwAct string `json:"hostrtgwact,omitempty"` + ICMP string `json:"icmp,omitempty"` + ICMPResponse string `json:"icmpresponse,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + IPType []string `json:"iptype,omitempty"` + Metric int `json:"metric,omitempty"` + MgmtAccess string `json:"mgmtaccess,omitempty"` + MPTCPAdvertise string `json:"mptcpadvertise,omitempty"` + Netmask string `json:"netmask,omitempty"` + NetworkRoute string `json:"networkroute,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OperationalARPOwner int `json:"operationalarpowner,omitempty"` + OSPF string `json:"ospf,omitempty"` + OSPFArea int `json:"ospfarea,omitempty"` + OSPFAreaVal int `json:"ospfareaval,omitempty"` + OSPFLSAType string `json:"ospflsatype,omitempty"` + OwnerDownResponse string `json:"ownerdownresponse,omitempty"` + OwnerNode int `json:"ownernode,omitempty"` + RestrictAccess string `json:"restrictaccess,omitempty"` + RIP string `json:"rip,omitempty"` + SNMP string `json:"snmp,omitempty"` + SSH string `json:"ssh,omitempty"` + State string `json:"state,omitempty"` + Tag int `json:"tag,omitempty"` + TD int `json:"td,omitempty"` + Telnet string `json:"telnet,omitempty"` + TypeField string `json:"type,omitempty"` + VIPRtAdv2BSD bool `json:"viprtadv2bsd,omitempty"` + VIPVSerCount int `json:"vipvsercount,omitempty"` + VIPVSerDownCount int `json:"vipvserdowncount,omitempty"` + VIPVSrvrRHIActiveCount int `json:"vipvsrvrrhiactivecount,omitempty"` + VIPVSrvrRHIActiveUpCount int `json:"vipvsrvrrhiactiveupcount,omitempty"` + VRID int `json:"vrid,omitempty"` + VServer string `json:"vserver,omitempty"` + VServerRHILevel string `json:"vserverrhilevel,omitempty"` +} + +type NSExtension struct { + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Detail string `json:"detail,omitempty"` + FunctionHaltCount int `json:"functionhaltcount,omitempty"` + FunctionHits int `json:"functionhits,omitempty"` + FunctionUndefHits int `json:"functionundefhits,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Overwrite bool `json:"overwrite,omitempty"` + Src string `json:"src,omitempty"` + Trace string `json:"trace,omitempty"` + TraceFunctions string `json:"tracefunctions,omitempty"` + TraceVariables string `json:"tracevariables,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type Shutdown struct { +} + +type NSCapacity struct { + ActualBandwidth int `json:"actualbandwidth,omitempty"` + Bandwidth int `json:"bandwidth,omitempty"` + DaysToExpiration int `json:"daystoexpiration,omitempty"` + Edition string `json:"edition,omitempty"` + InstanceCount int `json:"instancecount,omitempty"` + MaxBandwidth int `json:"maxbandwidth,omitempty"` + MaxVCPUCount int `json:"maxvcpucount,omitempty"` + MinBandwidth int `json:"minbandwidth,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + Password string `json:"password,omitempty"` + Platform string `json:"platform,omitempty"` + Unit string `json:"unit,omitempty"` + Username string `json:"username,omitempty"` + VCPU bool `json:"vcpu,omitempty"` + VCPUCount int `json:"vcpucount,omitempty"` +} + +type NSSavedConfig struct { + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + TextBlob string `json:"textblob,omitempty"` +} + +type NSRPCNode struct { + Count float64 `json:"__count,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Password string `json:"password,omitempty"` + Secure string `json:"secure,omitempty"` + SrcIP string `json:"srcip,omitempty"` + ValidateCert string `json:"validatecert,omitempty"` +} + +type NSAssignment struct { + Add string `json:"Add,omitempty"` + Append string `json:"append,omitempty"` + Clear bool `json:"clear,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Hits int `json:"hits,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ReferenceCount int `json:"referencecount,omitempty"` + Set string `json:"set,omitempty"` + Sub string `json:"sub,omitempty"` + UndefHits int `json:"undefhits,omitempty"` + Variable string `json:"variable,omitempty"` +} + +type NSTCPBufParam struct { + Builtin []string `json:"builtin,omitempty"` + Feature string `json:"feature,omitempty"` + MemLimit int `json:"memlimit,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Size int `json:"size,omitempty"` +} + +type NSRateControl struct { + ICMPThreshold int `json:"icmpthreshold,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + TCPRstThreshold int `json:"tcprstthreshold,omitempty"` + TCPThreshold int `json:"tcpthreshold,omitempty"` + UDPThreshold int `json:"udpthreshold,omitempty"` +} + +type NSLimitSessions struct { + Count float64 `json:"__count,omitempty"` + Detail bool `json:"detail,omitempty"` + Drop int `json:"drop,omitempty"` + Flag int `json:"flag,omitempty"` + Flags int `json:"flags,omitempty"` + Hits int `json:"hits,omitempty"` + LimitIdentifier string `json:"limitidentifier,omitempty"` + MaxBandwidth int `json:"maxbandwidth,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Number []any `json:"number,omitempty"` + ReferenceCount int `json:"referencecount,omitempty"` + SelectorIPv61 string `json:"selectoripv61,omitempty"` + SelectorIPv62 string `json:"selectoripv62,omitempty"` + Timeout int `json:"timeout,omitempty"` + Unit int `json:"unit,omitempty"` +} + +type NSTrafficDomainVLANBinding struct { + Count float64 `json:"__count,omitempty"` + TD int `json:"td,omitempty"` + VLAN int `json:"vlan,omitempty"` +} + +type NSSPParams struct { + BaseThreshold int `json:"basethreshold,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Feature string `json:"feature,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Table0 []any `json:"table0,omitempty"` + Throttle string `json:"throttle,omitempty"` +} + +type NSACLs6 struct { + TypeField string `json:"type,omitempty"` +} + +type NSRunningConfig struct { + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Response string `json:"response,omitempty"` + WithDefaults bool `json:"withdefaults,omitempty"` +} + +type Reboot struct { + Warm bool `json:"warm,omitempty"` +} + +type NSTimer struct { + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Interval int `json:"interval,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Unit string `json:"unit,omitempty"` +} + +type NSCentralManagementServer struct { + ActivationCode string `json:"activationcode,omitempty"` + ADCPassword string `json:"adcpassword,omitempty"` + ADCUsername string `json:"adcusername,omitempty"` + ADMServiceConnectionStatus string `json:"admserviceconnectionstatus,omitempty"` + ADMServiceEnvironment string `json:"admserviceenvironment,omitempty"` + Count float64 `json:"__count,omitempty"` + CustomerID string `json:"customerid,omitempty"` + DeviceProfileName string `json:"deviceprofilename,omitempty"` + InstanceID string `json:"instanceid,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Password string `json:"password,omitempty"` + ServerName string `json:"servername,omitempty"` + TypeField string `json:"type,omitempty"` + Username string `json:"username,omitempty"` + ValidateCert string `json:"validatecert,omitempty"` +} + +type NSEncryptionParams struct { + KeyValue string `json:"keyvalue,omitempty"` + Method string `json:"method,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type NSSourceRouteCacheTable struct { + Count float64 `json:"__count,omitempty"` + InterfaceField string `json:"Interface,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + SourceIP string `json:"sourceip,omitempty"` + SourceMAC string `json:"sourcemac,omitempty"` + VLAN int `json:"vlan,omitempty"` +} + +type NSTimeZone struct { + Count float64 `json:"__count,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Value string `json:"value,omitempty"` +} + +type NSACL6 struct { + ACL6Action string `json:"acl6action,omitempty"` + ACL6Name string `json:"acl6name,omitempty"` + ACLAction string `json:"aclaction,omitempty"` + ACLAssociate []string `json:"aclassociate,omitempty"` + Count float64 `json:"__count,omitempty"` + DestIPOp string `json:"destipop,omitempty"` + DestIPv6 bool `json:"destipv6,omitempty"` + DestIPv6Val string `json:"destipv6val,omitempty"` + DestPort bool `json:"destport,omitempty"` + DestPortOp string `json:"destportop,omitempty"` + DestPortVal string `json:"destportval,omitempty"` + DFDHash string `json:"dfdhash,omitempty"` + DFDPrefix int `json:"dfdprefix,omitempty"` + Established bool `json:"established,omitempty"` + Hits int `json:"hits,omitempty"` + ICMPCode int `json:"icmpcode,omitempty"` + ICMPType int `json:"icmptype,omitempty"` + InterfaceField string `json:"Interface,omitempty"` + KernelState string `json:"kernelstate,omitempty"` + LogState string `json:"logstate,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + Priority int `json:"priority,omitempty"` + Protocol string `json:"protocol,omitempty"` + ProtocolNumber int `json:"protocolnumber,omitempty"` + RateLimit int `json:"ratelimit,omitempty"` + SrcIPOp string `json:"srcipop,omitempty"` + SrcIPv6 bool `json:"srcipv6,omitempty"` + SrcIPv6Val string `json:"srcipv6val,omitempty"` + SrcMAC string `json:"srcmac,omitempty"` + SrcMACMask string `json:"srcmacmask,omitempty"` + SrcPort bool `json:"srcport,omitempty"` + SrcPortOp string `json:"srcportop,omitempty"` + SrcPortVal string `json:"srcportval,omitempty"` + State string `json:"state,omitempty"` + Stateful string `json:"stateful,omitempty"` + TD int `json:"td,omitempty"` + TTL int `json:"ttl,omitempty"` + TypeField string `json:"type,omitempty"` + VLAN int `json:"vlan,omitempty"` + VXLAN int `json:"vxlan,omitempty"` +} + +type NSAppFlowParam struct { + ClientTrafficOnly string `json:"clienttrafficonly,omitempty"` + HTTPCookie string `json:"httpcookie,omitempty"` + HTTPHost string `json:"httphost,omitempty"` + HTTPMethod string `json:"httpmethod,omitempty"` + HTTPReferer string `json:"httpreferer,omitempty"` + HTTPURL string `json:"httpurl,omitempty"` + HTTPUserAgent string `json:"httpuseragent,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + TemplateRefresh int `json:"templaterefresh,omitempty"` + UDPPMTU int `json:"udppmtu,omitempty"` +} + +type NSVariable struct { + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Expires int `json:"expires,omitempty"` + IfFull string `json:"iffull,omitempty"` + IfNoValue string `json:"ifnovalue,omitempty"` + IfValueTooBig string `json:"ifvaluetoobig,omitempty"` + Init string `json:"init,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ReferenceCount int `json:"referencecount,omitempty"` + Scope string `json:"scope,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type NSConsoleLoginPrompt struct { + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PromptString string `json:"promptstring,omitempty"` +} + +type NSHostname struct { + Count float64 `json:"__count,omitempty"` + Hostname string `json:"hostname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OwnerNode int `json:"ownernode,omitempty"` +} + +type NSJob struct { + Count float64 `json:"__count,omitempty"` + ErrorCode int `json:"errorcode,omitempty"` + ID int `json:"id,omitempty"` + Message string `json:"message,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Progress string `json:"progress,omitempty"` + Response string `json:"response,omitempty"` + Status string `json:"status,omitempty"` + TimeElapsed int `json:"timeelapsed,omitempty"` +} + +type NSAppFlowCollector struct { + Count float64 `json:"__count,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Port int `json:"port,omitempty"` +} + +type NSLimitSelector struct { + Count float64 `json:"__count,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule []string `json:"rule,omitempty"` + SelectorName string `json:"selectorname,omitempty"` +} + +type NSTimeout struct { + AnyClient int `json:"anyclient,omitempty"` + AnyServer int `json:"anyserver,omitempty"` + AnyTCPClient int `json:"anytcpclient,omitempty"` + AnyTCPServer int `json:"anytcpserver,omitempty"` + Client int `json:"client,omitempty"` + HalfClose int `json:"halfclose,omitempty"` + HTTPClient int `json:"httpclient,omitempty"` + HTTPServer int `json:"httpserver,omitempty"` + NewConnIdleTimeout int `json:"newconnidletimeout,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NonTCPZombie int `json:"nontcpzombie,omitempty"` + ReducedFinTimeout int `json:"reducedfintimeout,omitempty"` + ReducedRstTimeout int `json:"reducedrsttimeout,omitempty"` + Server int `json:"server,omitempty"` + TCPClient int `json:"tcpclient,omitempty"` + TCPServer int `json:"tcpserver,omitempty"` + Zombie int `json:"zombie,omitempty"` +} + +type NSTCPParam struct { + AckOnPush string `json:"ackonpush,omitempty"` + AutoSynCookieTimeout int `json:"autosyncookietimeout,omitempty"` + Builtin []string `json:"builtin,omitempty"` + CompactTCPOptionNoOp string `json:"compacttcpoptionnoop,omitempty"` + ConnFlushIfNoMem string `json:"connflushifnomem,omitempty"` + ConnFlushThres int `json:"connflushthres,omitempty"` + DelayedAck int `json:"delayedack,omitempty"` + DelinkClientServerOnRst string `json:"delinkclientserveronrst,omitempty"` + DownStateRst string `json:"downstaterst,omitempty"` + EnhancedISNGeneration string `json:"enhancedisngeneration,omitempty"` + Feature string `json:"feature,omitempty"` + InitialCwnd int `json:"initialcwnd,omitempty"` + KAProbeUpdateLastActivity string `json:"kaprobeupdatelastactivity,omitempty"` + LearnVSvrMSS string `json:"learnvsvrmss,omitempty"` + LimitedPersist string `json:"limitedpersist,omitempty"` + MaxBurst int `json:"maxburst,omitempty"` + MaxDynServerProbes int `json:"maxdynserverprobes,omitempty"` + MaxPktPerMSS int `json:"maxpktpermss,omitempty"` + MaxSynAckRetx int `json:"maxsynackretx,omitempty"` + MaxSynHold int `json:"maxsynhold,omitempty"` + MaxSynHoldPerProbe int `json:"maxsynholdperprobe,omitempty"` + MaxTimeWaitConn int `json:"maxtimewaitconn,omitempty"` + MinRTO int `json:"minrto,omitempty"` + MPTCPChecksum string `json:"mptcpchecksum,omitempty"` + MPTCPCloseMPTCPSessionOnLastSFClose string `json:"mptcpclosemptcpsessiononlastsfclose,omitempty"` + MPTCPConCloseOnPassiveSF string `json:"mptcpconcloseonpassivesf,omitempty"` + MPTCPFastCloseOption string `json:"mptcpfastcloseoption,omitempty"` + MPTCPImmediateSFCloseOnFin string `json:"mptcpimmediatesfcloseonfin,omitempty"` + MPTCPMaxPendingSF int `json:"mptcpmaxpendingsf,omitempty"` + MPTCPMaxSF int `json:"mptcpmaxsf,omitempty"` + MPTCPPendingJoinThreshold int `json:"mptcppendingjointhreshold,omitempty"` + MPTCPReliableAddAddr string `json:"mptcpreliableaddaddr,omitempty"` + MPTCPRTOsToSwitchSF int `json:"mptcprtostoswitchsf,omitempty"` + MPTCPSendSFResetOption string `json:"mptcpsendsfresetoption,omitempty"` + MPTCPSFReplaceTimeout int `json:"mptcpsfreplacetimeout,omitempty"` + MPTCPSFTimeout int `json:"mptcpsftimeout,omitempty"` + MPTCPUseBackupOnDSS string `json:"mptcpusebackupondss,omitempty"` + MSSLearnDelay int `json:"msslearndelay,omitempty"` + MSSLearnInterval int `json:"msslearninterval,omitempty"` + Nagle string `json:"nagle,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OOOQSize int `json:"oooqsize,omitempty"` + PktPerRetx int `json:"pktperretx,omitempty"` + RecvBuffSize int `json:"recvbuffsize,omitempty"` + RFC5961ChlgAckLimit int `json:"rfc5961chlgacklimit,omitempty"` + Sack string `json:"sack,omitempty"` + SendResetReasonCode string `json:"sendresetreasoncode,omitempty"` + SlowStartIncr int `json:"slowstartincr,omitempty"` + SynAttackDetection string `json:"synattackdetection,omitempty"` + SynHoldFastGiveUp int `json:"synholdfastgiveup,omitempty"` + TCPFastOpenCookieTimeout int `json:"tcpfastopencookietimeout,omitempty"` + TCPFinTimeout int `json:"tcpfintimeout,omitempty"` + TCPMaxRetries int `json:"tcpmaxretries,omitempty"` + Ws string `json:"ws,omitempty"` + WSVal int `json:"wsval,omitempty"` +} + +type NSServiceFunction struct { + Count float64 `json:"__count,omitempty"` + IngressVLAN int `json:"ingressvlan,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ServiceFunctionName string `json:"servicefunctionname,omitempty"` +} + +type NSChannelParam struct { + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + VFAutoRecover string `json:"vfautorecover,omitempty"` +} + +type NSEncryptionKey struct { + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + IV string `json:"iv,omitempty"` + KeyValue string `json:"keyvalue,omitempty"` + Method string `json:"method,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Padding string `json:"padding,omitempty"` +} + +type NSKeyManagerProxy struct { + Count float64 `json:"__count,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + Port int `json:"port,omitempty"` + ServerIP string `json:"serverip,omitempty"` + ServerName string `json:"servername,omitempty"` + Status int `json:"status,omitempty"` +} + +type NSICAPProfile struct { + Allow204 string `json:"allow204,omitempty"` + ConnectionKeepAlive string `json:"connectionkeepalive,omitempty"` + Count float64 `json:"__count,omitempty"` + HostHeader string `json:"hostheader,omitempty"` + InsertHTTPRequest string `json:"inserthttprequest,omitempty"` + InsertICAPHeaders string `json:"inserticapheaders,omitempty"` + InspectHTTP2 string `json:"inspecthttp2,omitempty"` + LogAction string `json:"logaction,omitempty"` + Mode string `json:"mode,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Preview string `json:"preview,omitempty"` + PreviewLength int `json:"previewlength,omitempty"` + QueryParams string `json:"queryparams,omitempty"` + ReqTimeout int `json:"reqtimeout,omitempty"` + ReqTimeoutAction string `json:"reqtimeoutaction,omitempty"` + URI string `json:"uri,omitempty"` + UserAgent string `json:"useragent,omitempty"` +} + +type NSSimpleACL struct { + ACLAction string `json:"aclaction,omitempty"` + ACLName string `json:"aclname,omitempty"` + Count float64 `json:"__count,omitempty"` + DestPort int `json:"destport,omitempty"` + EstSessions bool `json:"estsessions,omitempty"` + Hits int `json:"hits,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Protocol string `json:"protocol,omitempty"` + SrcIP string `json:"srcip,omitempty"` + TD int `json:"td,omitempty"` + TTL int `json:"ttl,omitempty"` +} + +type NSVariableValues struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + VariableData string `json:"variabledata,omitempty"` + VariableKey string `json:"variablekey,omitempty"` + VariableValue string `json:"variablevalue,omitempty"` +} + +type NSPBRs struct { +} + +type NSWebLogParam struct { + BufferSizeMB int `json:"buffersizemb,omitempty"` + Builtin []string `json:"builtin,omitempty"` + CustomReqHdrs []string `json:"customreqhdrs,omitempty"` + CustomRspHdrs []string `json:"customrsphdrs,omitempty"` + Feature string `json:"feature,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type NSLicenseActivationData struct { + Filename string `json:"filename,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type NSEvents struct { + Count float64 `json:"__count,omitempty"` + Data0 int `json:"data0,omitempty"` + Data1 int `json:"data1,omitempty"` + Data2 int `json:"data2,omitempty"` + Data3 int `json:"data3,omitempty"` + DevID int `json:"devid,omitempty"` + DevName string `json:"devname,omitempty"` + EventCode int `json:"eventcode,omitempty"` + EventNo int `json:"eventno,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Text string `json:"text,omitempty"` + Time int `json:"time,omitempty"` +} + +type NSMigration struct { + Count float64 `json:"__count,omitempty"` + DestIP string `json:"destip,omitempty"` + DestPort int `json:"destport,omitempty"` + DumpSession string `json:"dumpsession,omitempty"` + MigDFDSessionsActive int `json:"migdfdsessionsactive,omitempty"` + MigDFDSessionsActiveRollback int `json:"migdfdsessionsactiverollback,omitempty"` + MigDFDSessionsAllocated int `json:"migdfdsessionsallocated,omitempty"` + MigDFDSessionsAllocatedRollback int `json:"migdfdsessionsallocatedrollback,omitempty"` + MigHAStateFlag int `json:"mighastateflag,omitempty"` + MigL4SessionsActive int `json:"migl4sessionsactive,omitempty"` + MigL4SessionsActiveRollback int `json:"migl4sessionsactiverollback,omitempty"` + MigL4SessionsAllocated int `json:"migl4sessionsallocated,omitempty"` + MigL4SessionsAllocatedRollback int `json:"migl4sessionsallocatedrollback,omitempty"` + MigrationEndTime string `json:"migrationendtime,omitempty"` + MigrationRollbackStartTime string `json:"migrationrollbackstarttime,omitempty"` + MigrationStartTime string `json:"migrationstarttime,omitempty"` + MigrationStatus string `json:"migrationstatus,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + SrcIP string `json:"srcip,omitempty"` + SrcPort int `json:"srcport,omitempty"` + Timeout int `json:"timeout,omitempty"` +} + +type NSHMACKey struct { + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Digest string `json:"digest,omitempty"` + KeyValue string `json:"keyvalue,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type NSPBR6 struct { + Action string `json:"action,omitempty"` + Count float64 `json:"__count,omitempty"` + CurState int `json:"curstate,omitempty"` + Data bool `json:"data,omitempty"` + DestIPOp string `json:"destipop,omitempty"` + DestIPv6 bool `json:"destipv6,omitempty"` + DestIPv6Val string `json:"destipv6val,omitempty"` + DestPort bool `json:"destport,omitempty"` + DestPortOp string `json:"destportop,omitempty"` + DestPortVal string `json:"destportval,omitempty"` + Detail bool `json:"detail,omitempty"` + FailedProbes int `json:"failedprobes,omitempty"` + Hits int `json:"hits,omitempty"` + Interface string `json:"Interface,omitempty"` + IPTunnel string `json:"iptunnel,omitempty"` + KernelState string `json:"kernelstate,omitempty"` + Monitor string `json:"monitor,omitempty"` + MonStatCode int `json:"monstatcode,omitempty"` + MonStatParam1 int `json:"monstatparam1,omitempty"` + MonStatParam2 int `json:"monstatparam2,omitempty"` + MonStatParam3 int `json:"monstatparam3,omitempty"` + MSR string `json:"msr,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NextHop bool `json:"nexthop,omitempty"` + NextHopVal string `json:"nexthopval,omitempty"` + NextHopVLAN int `json:"nexthopvlan,omitempty"` + OwnerGroup string `json:"ownergroup,omitempty"` + Priority int `json:"priority,omitempty"` + Protocol string `json:"protocol,omitempty"` + ProtocolNumber int `json:"protocolnumber,omitempty"` + SrcIPOp string `json:"srcipop,omitempty"` + SrcIPv6 bool `json:"srcipv6,omitempty"` + SrcIPv6Val string `json:"srcipv6val,omitempty"` + SrcMAC string `json:"srcmac,omitempty"` + SrcMACMask string `json:"srcmacmask,omitempty"` + SrcPort bool `json:"srcport,omitempty"` + SrcPortOp string `json:"srcportop,omitempty"` + SrcPortVal string `json:"srcportval,omitempty"` + State string `json:"state,omitempty"` + TD int `json:"td,omitempty"` + TotalFailedProbes int `json:"totalfailedprobes,omitempty"` + TotalProbes int `json:"totalprobes,omitempty"` + VLAN int `json:"vlan,omitempty"` + VXLAN int `json:"vxlan,omitempty"` + VXLANVLANMap string `json:"vxlanvlanmap,omitempty"` +} + +type NSACLs struct { + TypeField string `json:"type,omitempty"` +} + +type NSDHCPParams struct { + DHCPClient string `json:"dhcpclient,omitempty"` + HostRtGw string `json:"hostrtgw,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + Netmask string `json:"netmask,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Running bool `json:"running,omitempty"` + SaveRoute string `json:"saveroute,omitempty"` +} + +type NSSurgeQ struct { + Name string `json:"name,omitempty"` + Port int `json:"port,omitempty"` + ServerName string `json:"servername,omitempty"` +} + +type NSNextGenAPI struct { + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + State string `json:"state,omitempty"` +} + +type NSXMLNamespace struct { + Count float64 `json:"__count,omitempty"` + Description string `json:"description,omitempty"` + Namespace string `json:"Namespace,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Prefix string `json:"prefix,omitempty"` +} + +type NSACL struct { + ACLAction string `json:"aclaction,omitempty"` + ACLAssociate []string `json:"aclassociate,omitempty"` + ACLChildCount int `json:"aclchildcount,omitempty"` + ACLName string `json:"aclname,omitempty"` + Count float64 `json:"__count,omitempty"` + DestIP bool `json:"destip,omitempty"` + DestIPDataset string `json:"destipdataset,omitempty"` + DestIPOp string `json:"destipop,omitempty"` + DestIPVal string `json:"destipval,omitempty"` + DestPort bool `json:"destport,omitempty"` + DestPortDataset string `json:"destportdataset,omitempty"` + DestPortOp string `json:"destportop,omitempty"` + DestPortVal string `json:"destportval,omitempty"` + DFDHash string `json:"dfdhash,omitempty"` + Established bool `json:"established,omitempty"` + Hits int `json:"hits,omitempty"` + ICMPCode int `json:"icmpcode,omitempty"` + ICMPType int `json:"icmptype,omitempty"` + Interface string `json:"Interface,omitempty"` + KernelState string `json:"kernelstate,omitempty"` + LogState string `json:"logstate,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + Priority int `json:"priority,omitempty"` + Protocol string `json:"protocol,omitempty"` + ProtocolNumber int `json:"protocolnumber,omitempty"` + RateLimit int `json:"ratelimit,omitempty"` + SrcIP bool `json:"srcip,omitempty"` + SrcIPDataset string `json:"srcipdataset,omitempty"` + SrcIPOp string `json:"srcipop,omitempty"` + SrcIPVal string `json:"srcipval,omitempty"` + SrcMAC string `json:"srcmac,omitempty"` + SrcMACMask string `json:"srcmacmask,omitempty"` + SrcPort bool `json:"srcport,omitempty"` + SrcPortDataset string `json:"srcportdataset,omitempty"` + SrcPortOp string `json:"srcportop,omitempty"` + SrcPortVal string `json:"srcportval,omitempty"` + State string `json:"state,omitempty"` + Stateful string `json:"stateful,omitempty"` + TD int `json:"td,omitempty"` + TTL int `json:"ttl,omitempty"` + TypeField string `json:"type,omitempty"` + VLAN int `json:"vlan,omitempty"` + VXLAN int `json:"vxlan,omitempty"` +} + +type NSLicenseServer struct { + Count float64 `json:"__count,omitempty"` + DeviceProfileName string `json:"deviceprofilename,omitempty"` + ForceUpdateIP bool `json:"forceupdateip,omitempty"` + GPTimeLeft int `json:"gptimeleft,omitempty"` + Grace int `json:"grace,omitempty"` + LicenseMode string `json:"licensemode,omitempty"` + LicenseServerIP string `json:"licenseserverip,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + Password string `json:"password,omitempty"` + Port int `json:"port,omitempty"` + ServerName string `json:"servername,omitempty"` + Status int `json:"status,omitempty"` + TypeField string `json:"type,omitempty"` + Username string `json:"username,omitempty"` +} + +type NSMgmtParam struct { + HTTPDMaxClients int `json:"httpdmaxclients,omitempty"` + HTTPDMaxReqWorkers int `json:"httpdmaxreqworkers,omitempty"` + MgmtHTTPPort int `json:"mgmthttpport,omitempty"` + MgmtHTTPSPort int `json:"mgmthttpsport,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type NSDHCPIP struct { +} + +type NSTCPProfile struct { + AckAggregation string `json:"ackaggregation,omitempty"` + AckOnPush string `json:"ackonpush,omitempty"` + ApplyAdaptiveTCP string `json:"applyadaptivetcp,omitempty"` + BufferSize int `json:"buffersize,omitempty"` + Builtin []string `json:"builtin,omitempty"` + BurstRateControl string `json:"burstratecontrol,omitempty"` + ClientIPTCPOption string `json:"clientiptcpoption,omitempty"` + ClientIPTCPOptionNumber int `json:"clientiptcpoptionnumber,omitempty"` + Count float64 `json:"__count,omitempty"` + DelayedAck int `json:"delayedack,omitempty"` + DropEstConnOnTimeout string `json:"dropestconnontimeout,omitempty"` + DropHalfClosedConnOnTimeout string `json:"drophalfclosedconnontimeout,omitempty"` + DSack string `json:"dsack,omitempty"` + DupAckThresh int `json:"dupackthresh,omitempty"` + DynamicReceiveBuffering string `json:"dynamicreceivebuffering,omitempty"` + Ecn string `json:"ecn,omitempty"` + EstablishClientConn string `json:"establishclientconn,omitempty"` + Fack string `json:"fack,omitempty"` + Feature string `json:"feature,omitempty"` + Flavor string `json:"flavor,omitempty"` + FRTO string `json:"frto,omitempty"` + Hystart string `json:"hystart,omitempty"` + InitialCwnd int `json:"initialcwnd,omitempty"` + KA string `json:"ka,omitempty"` + KAConnIdleTime int `json:"kaconnidletime,omitempty"` + KAMaxProbes int `json:"kamaxprobes,omitempty"` + KAProbeInterval int `json:"kaprobeinterval,omitempty"` + KAProbeUpdateLastActivity string `json:"kaprobeupdatelastactivity,omitempty"` + MaxBurst int `json:"maxburst,omitempty"` + MaxCwnd int `json:"maxcwnd,omitempty"` + MaxPktPerMSS int `json:"maxpktpermss,omitempty"` + MinRTO int `json:"minrto,omitempty"` + MPCapableCBit string `json:"mpcapablecbit,omitempty"` + MPTCP string `json:"mptcp,omitempty"` + MPTCPDropDataOnPreEstSF string `json:"mptcpdropdataonpreestsf,omitempty"` + MPTCPFastOpen string `json:"mptcpfastopen,omitempty"` + MPTCPSessionTimeout int `json:"mptcpsessiontimeout,omitempty"` + MSS int `json:"mss,omitempty"` + Nagle string `json:"nagle,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OOOQSize int `json:"oooqsize,omitempty"` + PktPerRetx int `json:"pktperretx,omitempty"` + RateQMax int `json:"rateqmax,omitempty"` + RefCnt int `json:"refcnt,omitempty"` + RFC5961Compliance string `json:"rfc5961compliance,omitempty"` + RstMaxAck string `json:"rstmaxack,omitempty"` + RstWindowAttenuate string `json:"rstwindowattenuate,omitempty"` + Sack string `json:"sack,omitempty"` + SendBuffSize int `json:"sendbuffsize,omitempty"` + SendClientPortInTCPOption string `json:"sendclientportintcpoption,omitempty"` + SlowStartIncr int `json:"slowstartincr,omitempty"` + SlowStartThreshold int `json:"slowstartthreshold,omitempty"` + SpoofSynDrop string `json:"spoofsyndrop,omitempty"` + SynCookie string `json:"syncookie,omitempty"` + TailLossProbe string `json:"taillossprobe,omitempty"` + TCPFastOpen string `json:"tcpfastopen,omitempty"` + TCPFastOpenCookieSize int `json:"tcpfastopencookiesize,omitempty"` + TCPMode string `json:"tcpmode,omitempty"` + TCPRate int `json:"tcprate,omitempty"` + TCPSegOffload string `json:"tcpsegoffload,omitempty"` + Timestamp string `json:"timestamp,omitempty"` + Ws string `json:"ws,omitempty"` + WSVal int `json:"wsval,omitempty"` +} + +type NSTrafficDomainBinding struct { + NSTrafficDomainBridgeGroupBinding []any `json:"nstrafficdomain_bridgegroup_binding,omitempty"` + NSTrafficDomainVlanBinding []any `json:"nstrafficdomain_vlan_binding,omitempty"` + NSTrafficDomainVxlanBinding []any `json:"nstrafficdomain_vxlan_binding,omitempty"` + TD int `json:"td,omitempty"` +} + +type NSTimerAutoScalePolicyBinding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Name string `json:"name,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + SampleSize int `json:"samplesize,omitempty"` + Threshold int `json:"threshold,omitempty"` + VServer string `json:"vserver,omitempty"` +} + +type NSMode struct { + BridgeBPDUs bool `json:"bridgebpdus,omitempty"` + CKA bool `json:"cka,omitempty"` + DRAdv bool `json:"dradv,omitempty"` + DRAdv6 bool `json:"dradv6,omitempty"` + Edge bool `json:"edge,omitempty"` + FR bool `json:"fr,omitempty"` + IRAdv bool `json:"iradv,omitempty"` + L2 bool `json:"l2,omitempty"` + L3 bool `json:"l3,omitempty"` + MBF bool `json:"mbf,omitempty"` + MediaClassification bool `json:"mediaclassification,omitempty"` + Mode []string `json:"mode,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PMTUD bool `json:"pmtud,omitempty"` + SingleIP bool `json:"single_ip,omitempty"` + SRAdv bool `json:"sradv,omitempty"` + SRAdv6 bool `json:"sradv6,omitempty"` + TCPB bool `json:"tcpb,omitempty"` + ULFD bool `json:"ulfd,omitempty"` + USIP bool `json:"usip,omitempty"` + USNIP bool `json:"usnip,omitempty"` +} + +type NSSimpleACL6 struct { + ACLAction string `json:"aclaction,omitempty"` + ACLName string `json:"aclname,omitempty"` + Count float64 `json:"__count,omitempty"` + DestPort int `json:"destport,omitempty"` + EstSessions bool `json:"estsessions,omitempty"` + Hits int `json:"hits,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Protocol string `json:"protocol,omitempty"` + SrcIPv6 string `json:"srcipv6,omitempty"` + TD int `json:"td,omitempty"` + TTL int `json:"ttl,omitempty"` +} + +type NSLASLicense struct { + DaysToExpiration int `json:"daystoexpiration,omitempty"` + FileLocation string `json:"filelocation,omitempty"` + Filename string `json:"filename,omitempty"` + FixedBandwidth bool `json:"fixedbandwidth,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + RenewalNext int `json:"renewalnext,omitempty"` + RenewalNextDate string `json:"renewalnextdate,omitempty"` + RenewalPrev int `json:"renewalprev,omitempty"` + RenewalPrevDate string `json:"renewalprevdate,omitempty"` + Status string `json:"status,omitempty"` +} + +type NSConfig struct { + All bool `json:"all,omitempty"` + Async bool `json:"Async,omitempty"` + ChangedPassword bool `json:"changedpassword,omitempty"` + CIP string `json:"cip,omitempty"` + CIPHeader string `json:"cipheader,omitempty"` + Config string `json:"config,omitempty"` + Config1 string `json:"config1,omitempty"` + Config2 string `json:"config2,omitempty"` + ConfigChanged bool `json:"configchanged,omitempty"` + ConfigFile string `json:"configfile,omitempty"` + CookieVersion string `json:"cookieversion,omitempty"` + CRPortRange string `json:"crportrange,omitempty"` + CurrentSystemTime string `json:"currentsytemtime,omitempty"` + ExclusiveQuotaMaxClient int `json:"exclusivequotamaxclient,omitempty"` + ExclusiveQuotaSpillover int `json:"exclusivequotaspillover,omitempty"` + Flags int `json:"flags,omitempty"` + Force bool `json:"force,omitempty"` + FTPPortRange string `json:"ftpportrange,omitempty"` + GrantQuotaMaxClient int `json:"grantquotamaxclient,omitempty"` + GrantQuotaSpillover int `json:"grantquotaspillover,omitempty"` + HTTPPort []any `json:"httpport,omitempty"` + ID int `json:"id,omitempty"` + IFNum []string `json:"ifnum,omitempty"` + IgnoreDeviceSpecific bool `json:"ignoredevicespecific,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + LastConfigChangedTime string `json:"lastconfigchangedtime,omitempty"` + LastConfigSaveTime string `json:"lastconfigsavetime,omitempty"` + Level string `json:"level,omitempty"` + MappedIP string `json:"mappedip,omitempty"` + MaxConn int `json:"maxconn,omitempty"` + MaxReq int `json:"maxreq,omitempty"` + Message string `json:"message,omitempty"` + Netmask string `json:"netmask,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NSVLAN int `json:"nsvlan,omitempty"` + OutType string `json:"outtype,omitempty"` + PMTUMin int `json:"pmtumin,omitempty"` + PMTUTimeout int `json:"pmtutimeout,omitempty"` + PrimaryIP string `json:"primaryip,omitempty"` + PrimaryIP6 string `json:"primaryip6,omitempty"` + Range int `json:"range,omitempty"` + RBAConfig string `json:"rbaconfig,omitempty"` + Response string `json:"response,omitempty"` + ResponseFile string `json:"responsefile,omitempty"` + SecureCookie string `json:"securecookie,omitempty"` + SecureManagementTD int `json:"securemanagementtd,omitempty"` + SecureManagementTraffic string `json:"securemanagementtraffic,omitempty"` + SVMCmd int `json:"svmcmd,omitempty"` + SystemTime int `json:"systemtime,omitempty"` + SystemType string `json:"systemtype,omitempty"` + Tagged string `json:"tagged,omitempty"` + Template bool `json:"template,omitempty"` + TimeZone string `json:"timezone,omitempty"` + WeakPassword bool `json:"weakpassword,omitempty"` +} + +type NSAPTLicense struct { + BindType string `json:"bindtype,omitempty"` + Count float64 `json:"__count,omitempty"` + CountAvailable string `json:"countavailable,omitempty"` + CountTotal string `json:"counttotal,omitempty"` + DateExp string `json:"dateexp,omitempty"` + DatePurchased string `json:"datepurchased,omitempty"` + DateSA string `json:"datesa,omitempty"` + Features []string `json:"features,omitempty"` + ID string `json:"id,omitempty"` + LicenseDir string `json:"licensedir,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Relevance string `json:"relevance,omitempty"` + Response string `json:"response,omitempty"` + SerialNo string `json:"serialno,omitempty"` + SessionID string `json:"sessionid,omitempty"` + UseProxy string `json:"useproxy,omitempty"` +} + +type NSHTTPProfile struct { + AdptTimeout string `json:"adpttimeout,omitempty"` + AllowOnlyWordCharactersAndHyphen string `json:"allowonlywordcharactersandhyphen,omitempty"` + AltSvc string `json:"altsvc,omitempty"` + AltSvcValue string `json:"altsvcvalue,omitempty"` + ApdexCltRespTimeThreshold int `json:"apdexcltresptimethreshold,omitempty"` + ApdexSvrRespTimeThreshold int `json:"apdexsvrresptimethreshold,omitempty"` + Builtin []string `json:"builtin,omitempty"` + ClientIPHdrExpr string `json:"clientiphdrexpr,omitempty"` + CmpOnPush string `json:"cmponpush,omitempty"` + ConMultiplex string `json:"conmultiplex,omitempty"` + Count float64 `json:"__count,omitempty"` + DropExtraCRLF string `json:"dropextracrlf,omitempty"` + DropExtraData string `json:"dropextradata,omitempty"` + DropInvalReqs string `json:"dropinvalreqs,omitempty"` + DropInvalReqsWarning string `json:"dropinvalreqswarning,omitempty"` + Feature string `json:"feature,omitempty"` + GRPCHoldLimit int `json:"grpcholdlimit,omitempty"` + GRPCHoldTimeout int `json:"grpcholdtimeout,omitempty"` + GRPCLengthDelimitation string `json:"grpclengthdelimitation,omitempty"` + HostHeaderValidation string `json:"hostheadervalidation,omitempty"` + HTTP2 string `json:"http2,omitempty"` + HTTP2AltSvcFrame string `json:"http2altsvcframe,omitempty"` + HTTP2Direct string `json:"http2direct,omitempty"` + HTTP2ExtendedConnect string `json:"http2extendedconnect,omitempty"` + HTTP2HeaderTableSize int `json:"http2headertablesize,omitempty"` + HTTP2InitialConnWindowSize int `json:"http2initialconnwindowsize,omitempty"` + HTTP2InitialWindowSize int `json:"http2initialwindowsize,omitempty"` + HTTP2MaxConcurrentStreams int `json:"http2maxconcurrentstreams,omitempty"` + HTTP2MaxEmptyFramesPerMin int `json:"http2maxemptyframespermin,omitempty"` + HTTP2MaxFrameSize int `json:"http2maxframesize,omitempty"` + HTTP2MaxHeaderListSize int `json:"http2maxheaderlistsize,omitempty"` + HTTP2MaxPingFramesPerMin int `json:"http2maxpingframespermin,omitempty"` + HTTP2MaxResetFramesPerMin int `json:"http2maxresetframespermin,omitempty"` + HTTP2MaxRxResetFramesPerMin int `json:"http2maxrxresetframespermin,omitempty"` + HTTP2MaxSettingsFramesPerMin int `json:"http2maxsettingsframespermin,omitempty"` + HTTP2MinSeverConn int `json:"http2minseverconn,omitempty"` + HTTP2StrictCipher string `json:"http2strictcipher,omitempty"` + HTTP3 string `json:"http3,omitempty"` + HTTP3MaxHeaderBlockedStreams int `json:"http3maxheaderblockedstreams,omitempty"` + HTTP3MaxHeaderFieldSectionSize int `json:"http3maxheaderfieldsectionsize,omitempty"` + HTTP3MaxHeaderTableSize int `json:"http3maxheadertablesize,omitempty"` + HTTP3MinSeverConn int `json:"http3minseverconn,omitempty"` + HTTP3WebTransport string `json:"http3webtransport,omitempty"` + HTTPPipelineBuffSize int `json:"httppipelinebuffsize,omitempty"` + IncompHdrDelay int `json:"incomphdrdelay,omitempty"` + MarkConnReqInval string `json:"markconnreqinval,omitempty"` + MarkHTTP09Inval string `json:"markhttp09inval,omitempty"` + MarkHTTPHeaderExtraWSError string `json:"markhttpheaderextrawserror,omitempty"` + MarkRFC7230NonCompliantInval string `json:"markrfc7230noncompliantinval,omitempty"` + MarkTraceReqInval string `json:"marktracereqinval,omitempty"` + MaxDuplicateHeaderFields int `json:"maxduplicateheaderfields,omitempty"` + MaxHeaderFieldLen int `json:"maxheaderfieldlen,omitempty"` + MaxHeaderLen int `json:"maxheaderlen,omitempty"` + MaxReq int `json:"maxreq,omitempty"` + MaxReusePool int `json:"maxreusepool,omitempty"` + MinReusePool int `json:"minreusepool,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PassProtocolUpgrade string `json:"passprotocolupgrade,omitempty"` + PersistentETag string `json:"persistentetag,omitempty"` + RefCnt int `json:"refcnt,omitempty"` + ReqTimeout int `json:"reqtimeout,omitempty"` + ReqTimeoutAction string `json:"reqtimeoutaction,omitempty"` + ReusePoolTimeout int `json:"reusepooltimeout,omitempty"` + RTSPTunnel string `json:"rtsptunnel,omitempty"` + WebLog string `json:"weblog,omitempty"` + WebSocket string `json:"websocket,omitempty"` +} + +type NSFeature struct { + AAA bool `json:"aaa,omitempty"` + AdaptiveTCP bool `json:"adaptivetcp,omitempty"` + APIGateway bool `json:"apigateway,omitempty"` + AppFlow bool `json:"appflow,omitempty"` + AppFW bool `json:"appfw,omitempty"` + AppQOE bool `json:"appqoe,omitempty"` + BGP bool `json:"bgp,omitempty"` + Bot bool `json:"bot,omitempty"` + CF bool `json:"cf,omitempty"` + CH bool `json:"ch,omitempty"` + CI bool `json:"ci,omitempty"` + CloudBridge bool `json:"cloudbridge,omitempty"` + CMP bool `json:"cmp,omitempty"` + ContentAccelerator bool `json:"contentaccelerator,omitempty"` + CQA bool `json:"cqa,omitempty"` + CR bool `json:"cr,omitempty"` + CS bool `json:"cs,omitempty"` + Feature []string `json:"feature,omitempty"` + FEO bool `json:"feo,omitempty"` + ForwardProxy bool `json:"forwardproxy,omitempty"` + GSLB bool `json:"gslb,omitempty"` + IC bool `json:"ic,omitempty"` + IPv6PT bool `json:"ipv6pt,omitempty"` + ISIS bool `json:"isis,omitempty"` + LB bool `json:"lb,omitempty"` + LSN bool `json:"lsn,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OSPF bool `json:"ospf,omitempty"` + Push bool `json:"push,omitempty"` + RDPProxy bool `json:"rdpproxy,omitempty"` + Rep bool `json:"rep,omitempty"` + Responder bool `json:"responder,omitempty"` + Rewrite bool `json:"rewrite,omitempty"` + RIP bool `json:"rip,omitempty"` + SP bool `json:"sp,omitempty"` + SSL bool `json:"ssl,omitempty"` + SSLInterception bool `json:"sslinterception,omitempty"` + SSLVPN bool `json:"sslvpn,omitempty"` + VideoOptimization bool `json:"videooptimization,omitempty"` + WL bool `json:"wl,omitempty"` +} + +type NSServicePathBinding struct { + NSServicePathNSServiceFunctionBinding []any `json:"nsservicepath_nsservicefunction_binding,omitempty"` + ServicePathName string `json:"servicepathname,omitempty"` +} + +type NSLicenseParameters struct { + Alert1GraceTimeout int `json:"alert1gracetimeout,omitempty"` + Alert2GraceTimeout int `json:"alert2gracetimeout,omitempty"` + HeartbeatInterval int `json:"heartbeatinterval,omitempty"` + InventoryRefreshInterval int `json:"inventoryrefreshinterval,omitempty"` + LicenseExpiryAlertTime int `json:"licenseexpiryalerttime,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type NSLimitIdentifier struct { + ComputedTrapTimeSlice int `json:"computedtraptimeslice,omitempty"` + Count float64 `json:"__count,omitempty"` + Drop int `json:"drop,omitempty"` + Hits int `json:"hits,omitempty"` + LimitIdentifier string `json:"limitidentifier,omitempty"` + LimitType string `json:"limittype,omitempty"` + MaxBandwidth int `json:"maxbandwidth,omitempty"` + Mode string `json:"mode,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NGName string `json:"ngname,omitempty"` + ReferenceCount int `json:"referencecount,omitempty"` + Rule []string `json:"rule,omitempty"` + SelectorName string `json:"selectorname,omitempty"` + Threshold int `json:"threshold,omitempty"` + Time int `json:"time,omitempty"` + TimeSlice int `json:"timeslice,omitempty"` + Total int `json:"total,omitempty"` + TrapsComputedInTimeSlice int `json:"trapscomputedintimeslice,omitempty"` + TrapsInTimeSlice int `json:"trapsintimeslice,omitempty"` +} + +type NSHardware struct { + BMCRevision string `json:"bmcrevision,omitempty"` + CPUFrequency int `json:"cpufrequncy,omitempty"` + EncodedSerialNo string `json:"encodedserialno,omitempty"` + Host string `json:"host,omitempty"` + HostID int `json:"hostid,omitempty"` + HWDescription string `json:"hwdescription,omitempty"` + ManufactureDay int `json:"manufactureday,omitempty"` + ManufactureMonth int `json:"manufacturemonth,omitempty"` + ManufactureYear int `json:"manufactureyear,omitempty"` + NetScalerUUID string `json:"netscaleruuid,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + SerialNo string `json:"serialno,omitempty"` + SysID int `json:"sysid,omitempty"` +} + +type NSTrafficDomain struct { + AliasName string `json:"aliasname,omitempty"` + Count float64 `json:"__count,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + State string `json:"state,omitempty"` + TD int `json:"td,omitempty"` + VMAC string `json:"vmac,omitempty"` +} + +type NSPartitionVlanBinding struct { + Count float64 `json:"__count,omitempty"` + PartitionName string `json:"partitionname,omitempty"` + VLAN int `json:"vlan,omitempty"` +} + +type NSCQAParam struct { + HarqRetxDelay int `json:"harqretxdelay,omitempty"` + LR1CoefList string `json:"lr1coeflist,omitempty"` + LR1ProbThresh float64 `json:"lr1probthresh,omitempty"` + LR2CoefList string `json:"lr2coeflist,omitempty"` + LR2ProbThresh float64 `json:"lr2probthresh,omitempty"` + MinRTTNet1 int `json:"minrttnet1,omitempty"` + MinRTTNet2 int `json:"minrttnet2,omitempty"` + MinRTTNet3 int `json:"minrttnet3,omitempty"` + Net1CCLScale string `json:"net1cclscale,omitempty"` + Net1CSQScale string `json:"net1csqscale,omitempty"` + Net1Label string `json:"net1label,omitempty"` + Net1LogCoef string `json:"net1logcoef,omitempty"` + Net2CCLScale string `json:"net2cclscale,omitempty"` + Net2CSQScale string `json:"net2csqscale,omitempty"` + Net2Label string `json:"net2label,omitempty"` + Net2LogCoef string `json:"net2logcoef,omitempty"` + Net3CCLScale string `json:"net3cclscale,omitempty"` + Net3CSQScale string `json:"net3csqscale,omitempty"` + Net3Label string `json:"net3label,omitempty"` + Net3LogCoef string `json:"net3logcoef,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type NSStats struct { + CleanupLevel string `json:"cleanuplevel,omitempty"` +} + +type NSLimitIdentifierBinding struct { + LimitIdentifier string `json:"limitidentifier,omitempty"` + NSLimitIdentifierNSLimitSessionsBinding []any `json:"nslimitidentifier_nslimitsessions_binding,omitempty"` +} diff --git a/nitrogo/models/ntp.go b/nitrogo/models/ntp.go new file mode 100644 index 0000000..1cf8bbb --- /dev/null +++ b/nitrogo/models/ntp.go @@ -0,0 +1,32 @@ +package models + +// ntp configuration structs +type NTPServer struct { + AutoKey bool `json:"autokey,omitempty"` + Count float64 `json:"__count,omitempty"` + Key int `json:"key,omitempty"` + MaxPoll int `json:"maxpoll,omitempty"` + MinPoll int `json:"minpoll,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PreferredNTPServer string `json:"preferredntpserver,omitempty"` + ServerIP string `json:"serverip,omitempty"` + ServerName string `json:"servername,omitempty"` +} + +type NTPParam struct { + Authentication string `json:"authentication,omitempty"` + AutoKeyLogSec int `json:"autokeylogsec,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + RevokeLogSec int `json:"revokelogsec,omitempty"` + TrustedKey []any `json:"trustedkey,omitempty"` +} + +type NTPSync struct { + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + State string `json:"state,omitempty"` +} + +type NTPStatus struct { + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Response string `json:"response,omitempty"` +} diff --git a/nitrogo/models/pcp.go b/nitrogo/models/pcp.go new file mode 100644 index 0000000..24bb7a2 --- /dev/null +++ b/nitrogo/models/pcp.go @@ -0,0 +1,41 @@ +package models + +// pcp configuration structs +type PCPServer struct { + Count float64 `json:"__count,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PCPProfile string `json:"pcpprofile,omitempty"` + Port int `json:"port,omitempty"` +} + +type PCPMap struct { + Count float64 `json:"__count,omitempty"` + NatType string `json:"nattype,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PCPAddr int `json:"pcpaddr,omitempty"` + PCPDstIP string `json:"pcpdstip,omitempty"` + PCPDstPort int `json:"pcpdstport,omitempty"` + PCPLifetime int `json:"pcplifetime,omitempty"` + PCPNatIP string `json:"pcpnatip,omitempty"` + PCPNatPort int `json:"pcpnatport,omitempty"` + PCPNounce int `json:"pcpnounce,omitempty"` + PCPProtocol string `json:"pcpprotocol,omitempty"` + PCPRefCnt int `json:"pcprefcnt,omitempty"` + PCPSrcIP string `json:"pcpsrcip,omitempty"` + PCPSrcPort int `json:"pcpsrcport,omitempty"` + SubscrIP string `json:"subscrip,omitempty"` +} + +type PCPProfile struct { + AnnounceMultiCount int `json:"announcemulticount,omitempty"` + Count float64 `json:"__count,omitempty"` + Mapping string `json:"mapping,omitempty"` + MaxMapLife int `json:"maxmaplife,omitempty"` + MinMapLife int `json:"minmaplife,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Peer string `json:"peer,omitempty"` + ThirdParty string `json:"thirdparty,omitempty"` +} diff --git a/nitrogo/models/policy.go b/nitrogo/models/policy.go new file mode 100644 index 0000000..6e531b3 --- /dev/null +++ b/nitrogo/models/policy.go @@ -0,0 +1,224 @@ +package models + +// policy configuration structs +type PolicyPatsetPatternBinding struct { + Builtin []string `json:"builtin,omitempty"` + Charset string `json:"charset,omitempty"` + Comment string `json:"comment,omitempty"` + Feature string `json:"feature,omitempty"` + Index int `json:"index,omitempty"` + Name string `json:"name,omitempty"` + String string `json:"String,omitempty"` +} + +type PolicyStringMapBinding struct { + Name string `json:"name,omitempty"` + PolicyStringMapPatternBinding []any `json:"policystringmap_pattern_binding,omitempty"` +} + +type PolicyDatasetBinding struct { + Name string `json:"name,omitempty"` + PolicyDatasetValueBinding []any `json:"policydataset_value_binding,omitempty"` +} + +type PolicyStringMapPatternBinding struct { + Comment string `json:"comment,omitempty"` + Key string `json:"key,omitempty"` + Name string `json:"name,omitempty"` + Value string `json:"value,omitempty"` +} + +type PolicyPatsetFile struct { + BindStatus string `json:"bindstatus,omitempty"` + BindStatusCode int `json:"bindstatuscode,omitempty"` + BoundPatterns int `json:"boundpatterns,omitempty"` + Charset string `json:"charset,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Delimiter string `json:"delimiter,omitempty"` + Imported bool `json:"imported,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Overwrite bool `json:"overwrite,omitempty"` + PatsetName string `json:"patsetname,omitempty"` + Src string `json:"src,omitempty"` + TotalPatterns int `json:"totalpatterns,omitempty"` +} + +type PolicyStringMap struct { + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type PolicyPatsetBinding struct { + Name string `json:"name,omitempty"` + PolicyPatsetPatternBinding []any `json:"policypatset_pattern_binding,omitempty"` +} + +type PolicyDatasetValueBinding struct { + Comment string `json:"comment,omitempty"` + EndRange string `json:"endrange,omitempty"` + Index int `json:"index,omitempty"` + Name string `json:"name,omitempty"` + Value string `json:"value,omitempty"` +} + +type PolicyTracing struct { + CaptureSSLHandshakePolicies string `json:"capturesslhandshakepolicies,omitempty"` + ClientIP string `json:"clientip,omitempty"` + Count float64 `json:"__count,omitempty"` + DestIP string `json:"destip,omitempty"` + DestPort int `json:"destport,omitempty"` + Detail string `json:"detail,omitempty"` + FilterExpr string `json:"filterexpr,omitempty"` + IsResponse int `json:"isresponse,omitempty"` + IsUndefPolicy int `json:"isundefpolicy,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + PacketEngineID int `json:"packetengineid,omitempty"` + PolicyNames []string `json:"policynames,omitempty"` + PolicyTracingModule string `json:"policytracingmodule,omitempty"` + PolicyTracingRecordCount int `json:"policytracingrecordcount,omitempty"` + ProtocolType string `json:"protocoltype,omitempty"` + SrcPort int `json:"srcport,omitempty"` + TransactionID string `json:"transactionid,omitempty"` + TransactionTime string `json:"transactiontime,omitempty"` + URL string `json:"url,omitempty"` +} + +type PolicyURLSet struct { + CanaryURL string `json:"canaryurl,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Delimiter string `json:"delimiter,omitempty"` + Imported bool `json:"imported,omitempty"` + Interval int `json:"interval,omitempty"` + MatchedID int `json:"matchedid,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Overwrite bool `json:"overwrite,omitempty"` + PatternCount int `json:"patterncount,omitempty"` + PrivateSet bool `json:"privateset,omitempty"` + RowSeparator string `json:"rowseparator,omitempty"` + SubdomainExactMatch bool `json:"subdomainexactmatch,omitempty"` + URL string `json:"url,omitempty"` +} + +type PolicyEvaluation struct { + Action string `json:"action,omitempty"` + Count float64 `json:"__count,omitempty"` + Expression string `json:"expression,omitempty"` + Input string `json:"input,omitempty"` + IsTruncatedRefResult bool `json:"istruncatedrefresult,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PitActionErrorResult string `json:"pitactionerrorresult,omitempty"` + PitActionEvalTime int `json:"pitactionevaltime,omitempty"` + PitBoolErrorResult string `json:"pitboolerrorresult,omitempty"` + PitBoolEvalTime int `json:"pitboolevaltime,omitempty"` + PitBoolResult bool `json:"pitboolresult,omitempty"` + PitDoubleErrorResult string `json:"pitdoubleerrorresult,omitempty"` + PitDoubleEvalTime int `json:"pitdoubleevaltime,omitempty"` + PitDoubleResult float64 `json:"pitdoubleresult,omitempty"` + PitModifiedInputData string `json:"pitmodifiedinputdata,omitempty"` + PitNewOffsetArray []any `json:"pitnewoffsetarray,omitempty"` + PitNumErrorResult string `json:"pitnumerrorresult,omitempty"` + PitNumEvalTime int `json:"pitnumevaltime,omitempty"` + PitNumResult int `json:"pitnumresult,omitempty"` + PitOffsetErrorResult string `json:"pitoffseterrorresult,omitempty"` + PitOffsetEvalTime int `json:"pitoffsetevaltime,omitempty"` + PitOffsetLengthArray []any `json:"pitoffsetlengtharray,omitempty"` + PitOffsetNewLengthArray []any `json:"pitoffsetnewlengtharray,omitempty"` + PitOffsetResult int `json:"pitoffsetresult,omitempty"` + PitOffsetResultLen int `json:"pitoffsetresultlen,omitempty"` + PitOldOffsetArray []any `json:"pitoldoffsetarray,omitempty"` + PitOperationPerformerArray []string `json:"pitoperationperformerarray,omitempty"` + PitRefErrorResult string `json:"pitreferrorresult,omitempty"` + PitRefEvalTime int `json:"pitrefevaltime,omitempty"` + PitRefResult string `json:"pitrefresult,omitempty"` + PitUlongErrorResult string `json:"pitulongerrorresult,omitempty"` + PitUlongEvalTime int `json:"pitulongevaltime,omitempty"` + PitUlongResult int `json:"pitulongresult,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type PolicyHTTPCallout struct { + BodyExpr string `json:"bodyexpr,omitempty"` + CacheForSecs int `json:"cacheforsecs,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + EffectiveState string `json:"effectivestate,omitempty"` + FullReqExpr string `json:"fullreqexpr,omitempty"` + Headers []string `json:"headers,omitempty"` + Hits int `json:"hits,omitempty"` + HostExpr string `json:"hostexpr,omitempty"` + HTTPMethod string `json:"httpmethod,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Parameters []string `json:"parameters,omitempty"` + Port int `json:"port,omitempty"` + RecursiveCallout int `json:"recursivecallout,omitempty"` + ResultExpr string `json:"resultexpr,omitempty"` + ReturnType string `json:"returntype,omitempty"` + Scheme string `json:"scheme,omitempty"` + SvrState string `json:"svrstate,omitempty"` + UndefHits int `json:"undefhits,omitempty"` + UndefReason string `json:"undefreason,omitempty"` + URLStemExpr string `json:"urlstemexpr,omitempty"` + VServer string `json:"vserver,omitempty"` +} + +type PolicyDataset struct { + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Dynamic string `json:"dynamic,omitempty"` + DynamicOnly bool `json:"dynamiconly,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PatsetFile string `json:"patsetfile,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type PolicyMap struct { + Count float64 `json:"__count,omitempty"` + MapPolicyName string `json:"mappolicyname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + SD string `json:"sd,omitempty"` + SU string `json:"su,omitempty"` + TargetName string `json:"targetname,omitempty"` + TD string `json:"td,omitempty"` + TU string `json:"tu,omitempty"` +} + +type PolicyExpression struct { + Builtin []string `json:"builtin,omitempty"` + ClientSecurityMessage string `json:"clientsecuritymessage,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + IsDefault bool `json:"isdefault,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PIHits int `json:"pihits,omitempty"` + Type1 string `json:"type1,omitempty"` + TypeField string `json:"type,omitempty"` + Value string `json:"value,omitempty"` +} + +type PolicyPatset struct { + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Dynamic string `json:"dynamic,omitempty"` + DynamicOnly bool `json:"dynamiconly,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PatsetFile string `json:"patsetfile,omitempty"` +} + +type PolicyParam struct { + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Timeout int `json:"timeout,omitempty"` +} diff --git a/nitrogo/models/pq.go b/nitrogo/models/pq.go new file mode 100644 index 0000000..85b5fd3 --- /dev/null +++ b/nitrogo/models/pq.go @@ -0,0 +1,26 @@ +// Derived from Citrix ADC Nitro Go SDK (https://github.com/netscaler/adc-nitro-go) +// Originally licensed under the Apache License, Version 2.0 +// Modifications by Adam Crawford, 2026 + +package models + +type PQBinding struct { + VServerName string `json:"vservername,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Rule string `json:"rule,omitempty"` + Priority string `json:"priority,omitempty"` + Weight string `json:"weight,omitempty"` + QDepth string `json:"qdepth,omitempty"` + PolQDepth string `json:"polqdepth,omitempty"` + Hits string `json:"hits,omitempty"` +} + +type PQPolicy struct { + PolicyName string `json:"policyname,omitempty"` + Rule string `json:"rule,omitempty"` + Priority int `json:"priority,omitempty"` + Weight int `json:"weight,omitempty"` + QDepth int `json:"qdepth,omitempty"` + PolQDepth int `json:"polqdepth,omitempty"` + Hits string `json:"hits,omitempty"` +} diff --git a/nitrogo/models/protocol.go b/nitrogo/models/protocol.go new file mode 100644 index 0000000..774a4f7 --- /dev/null +++ b/nitrogo/models/protocol.go @@ -0,0 +1,21 @@ +package models + +// protocol configuration structs +type ProtocolHTTPBand struct { + AccessCount []any `json:"accesscount,omitempty"` + AccessRatio []any `json:"accessratio,omitempty"` + AccessRatioNew []any `json:"accessrationew,omitempty"` + AvgBandSize []any `json:"avgbandsize,omitempty"` + AvgBandSizeNew []any `json:"avgbandsizenew,omitempty"` + BandData []any `json:"banddata,omitempty"` + BandDataNew []any `json:"banddatanew,omitempty"` + BandRange int `json:"bandrange,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + NumberOfBands int `json:"numberofbands,omitempty"` + ReqBandSize int `json:"reqbandsize,omitempty"` + RespBandSize int `json:"respbandsize,omitempty"` + TotalBandSize []any `json:"totalbandsize,omitempty"` + Totals []any `json:"totals,omitempty"` + TypeField string `json:"type,omitempty"` +} diff --git a/nitrogo/models/quic.go b/nitrogo/models/quic.go new file mode 100644 index 0000000..3381c4e --- /dev/null +++ b/nitrogo/models/quic.go @@ -0,0 +1,33 @@ +package models + +// quic configuration structs +type QUICParam struct { + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + QUICSecretTimeout int `json:"quicsecrettimeout,omitempty"` +} + +type QUICProfile struct { + AckDelayExponent int `json:"ackdelayexponent,omitempty"` + ActiveConnectionIDLimit int `json:"activeconnectionidlimit,omitempty"` + ActiveConnectionMigration string `json:"activeconnectionmigration,omitempty"` + Builtin []string `json:"builtin,omitempty"` + CongestionCtrlAlgorithm string `json:"congestionctrlalgorithm,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + InitialMaxData int `json:"initialmaxdata,omitempty"` + InitialMaxStreamDataBidiLocal int `json:"initialmaxstreamdatabidilocal,omitempty"` + InitialMaxStreamDataBidiRemote int `json:"initialmaxstreamdatabidiremote,omitempty"` + InitialMaxStreamDataUni int `json:"initialmaxstreamdatauni,omitempty"` + InitialMaxStreamsBidi int `json:"initialmaxstreamsbidi,omitempty"` + InitialMaxStreamsUni int `json:"initialmaxstreamsuni,omitempty"` + MaxAckDelay int `json:"maxackdelay,omitempty"` + MaxIdleTimeout int `json:"maxidletimeout,omitempty"` + MaxUDPDatagramsPerBurst int `json:"maxudpdatagramsperburst,omitempty"` + MaxUDPPayloadSize int `json:"maxudppayloadsize,omitempty"` + Name string `json:"name,omitempty"` + NewTokenValidityPeriod int `json:"newtokenvalidityperiod,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + RefCnt int `json:"refcnt,omitempty"` + RetryTokenValidityPeriod int `json:"retrytokenvalidityperiod,omitempty"` + StatelessAddressValidation string `json:"statelessaddressvalidation,omitempty"` +} diff --git a/nitrogo/models/quicbridge.go b/nitrogo/models/quicbridge.go new file mode 100644 index 0000000..3de39f0 --- /dev/null +++ b/nitrogo/models/quicbridge.go @@ -0,0 +1,11 @@ +package models + +// quicbridge configuration structs +type QUICBridgeProfile struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + RefCnt int `json:"refcnt,omitempty"` + RoutingAlgorithm string `json:"routingalgorithm,omitempty"` + ServerIDLength int `json:"serveridlength,omitempty"` +} diff --git a/nitrogo/models/rdp.go b/nitrogo/models/rdp.go new file mode 100644 index 0000000..cc3878c --- /dev/null +++ b/nitrogo/models/rdp.go @@ -0,0 +1,54 @@ +package models + +// rdp configuration structs +type RDPClientProfile struct { + AddUsernameInRDPFile string `json:"addusernameinrdpfile,omitempty"` + AudioCaptureMode string `json:"audiocapturemode,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + KeyboardHook string `json:"keyboardhook,omitempty"` + MultiMonitorSupport string `json:"multimonitorsupport,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PSK string `json:"psk,omitempty"` + RandomizeRDPFileName string `json:"randomizerdpfilename,omitempty"` + RDPCookieValidity int `json:"rdpcookievalidity,omitempty"` + RDPCustomParams string `json:"rdpcustomparams,omitempty"` + RDPFileName string `json:"rdpfilename,omitempty"` + RDPHost string `json:"rdphost,omitempty"` + RDPLinkAttribute string `json:"rdplinkattribute,omitempty"` + RDPListener string `json:"rdplistener,omitempty"` + RDPURLOverride string `json:"rdpurloverride,omitempty"` + RDPValidateClientIP string `json:"rdpvalidateclientip,omitempty"` + RedirectClipboard string `json:"redirectclipboard,omitempty"` + RedirectComPorts string `json:"redirectcomports,omitempty"` + RedirectDrives string `json:"redirectdrives,omitempty"` + RedirectPnpDevices string `json:"redirectpnpdevices,omitempty"` + RedirectPrinters string `json:"redirectprinters,omitempty"` + VideoPlaybackMode string `json:"videoplaybackmode,omitempty"` +} + +type RDPServerProfile struct { + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PSK string `json:"psk,omitempty"` + RDPIP string `json:"rdpip,omitempty"` + RDPPort int `json:"rdpport,omitempty"` + RDPRedirection string `json:"rdpredirection,omitempty"` +} + +type RDPConnections struct { + All bool `json:"all,omitempty"` + Count float64 `json:"__count,omitempty"` + EndpointIP string `json:"endpointip,omitempty"` + EndpointPort int `json:"endpointport,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PEID int `json:"peid,omitempty"` + TargetIP string `json:"targetip,omitempty"` + TargetPort int `json:"targetport,omitempty"` + Username string `json:"username,omitempty"` +} diff --git a/nitrogo/models/reputation.go b/nitrogo/models/reputation.go new file mode 100644 index 0000000..1f03c37 --- /dev/null +++ b/nitrogo/models/reputation.go @@ -0,0 +1,10 @@ +package models + +// reputation configuration structs +type ReputationSettings struct { + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ProxyPassword string `json:"proxypassword,omitempty"` + ProxyPort int `json:"proxyport,omitempty"` + ProxyServer string `json:"proxyserver,omitempty"` + ProxyUsername string `json:"proxyusername,omitempty"` +} diff --git a/nitrogo/models/responder.go b/nitrogo/models/responder.go new file mode 100644 index 0000000..cde457a --- /dev/null +++ b/nitrogo/models/responder.go @@ -0,0 +1,183 @@ +package models + +// responder configuration structs +type ResponderGlobalResponderPolicyBinding struct { + FlowType int `json:"flowtype,omitempty"` + GlobalBindType string `json:"globalbindtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type ResponderPolicyCSVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type ResponderPolicyResponderGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type ResponderPolicyResponderPolicyLabelBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type ResponderPolicyCRVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type ResponderPolicyLabelPolicyBindingBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type ResponderHTMLPage struct { + CACertFile string `json:"cacertfile,omitempty"` + Comment string `json:"comment,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Overwrite bool `json:"overwrite,omitempty"` + Response string `json:"response,omitempty"` + Src string `json:"src,omitempty"` +} + +type ResponderAction struct { + Builtin []string `json:"builtin,omitempty"` + BypassSafetyCheck string `json:"bypasssafetycheck,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Headers []string `json:"headers,omitempty"` + Hits int `json:"hits,omitempty"` + HTMLPage string `json:"htmlpage,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ReasonPhrase string `json:"reasonphrase,omitempty"` + ReferenceCount int `json:"referencecount,omitempty"` + ResponseStatusCode int `json:"responsestatuscode,omitempty"` + Target string `json:"target,omitempty"` + TypeField string `json:"type,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type ResponderPolicyLabel struct { + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Hits int `json:"hits,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyLabelType string `json:"policylabeltype,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type ResponderPolicyLBVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type ResponderPolicyLabelResponderPolicyBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type ResponderPolicyLabelBinding struct { + LabelName string `json:"labelname,omitempty"` + ResponderPolicyLabelPolicyBindingBinding []any `json:"responderpolicylabel_policybinding_binding,omitempty"` + ResponderPolicyLabelResponderPolicyBinding []any `json:"responderpolicylabel_responderpolicy_binding,omitempty"` +} + +type ResponderPolicy struct { + Action string `json:"action,omitempty"` + AppFlowAction string `json:"appflowaction,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + LogAction string `json:"logaction,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule string `json:"rule,omitempty"` + UndefAction string `json:"undefaction,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type ResponderPolicyVPNVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type ResponderParam struct { + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Timeout int `json:"timeout,omitempty"` + UndefAction string `json:"undefaction,omitempty"` +} + +type ResponderPolicyBinding struct { + Name string `json:"name,omitempty"` + ResponderPolicyCRVServerBinding []any `json:"responderpolicy_crvserver_binding,omitempty"` + ResponderPolicyCSVServerBinding []any `json:"responderpolicy_csvserver_binding,omitempty"` + ResponderPolicyLBVServerBinding []any `json:"responderpolicy_lbvserver_binding,omitempty"` + ResponderPolicyResponderGlobalBinding []any `json:"responderpolicy_responderglobal_binding,omitempty"` + ResponderPolicyResponderPolicyLabelBinding []any `json:"responderpolicy_responderpolicylabel_binding,omitempty"` + ResponderPolicyVPNVServerBinding []any `json:"responderpolicy_vpnvserver_binding,omitempty"` +} + +type ResponderGlobalBinding struct { + ResponderGlobalResponderPolicyBinding []any `json:"responderglobal_responderpolicy_binding,omitempty"` +} diff --git a/nitrogo/models/rewrite.go b/nitrogo/models/rewrite.go new file mode 100644 index 0000000..8920bde --- /dev/null +++ b/nitrogo/models/rewrite.go @@ -0,0 +1,168 @@ +package models + +// rewrite configuration structs +type RewriteGlobalBinding struct { + RewriteGlobalRewritePolicyBinding []any `json:"rewriteglobal_rewritepolicy_binding,omitempty"` +} + +type RewritePolicy struct { + Action string `json:"action,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Description string `json:"description,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + IsDefault bool `json:"isdefault,omitempty"` + LogAction string `json:"logaction,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule string `json:"rule,omitempty"` + UndefAction string `json:"undefaction,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type RewriteAction struct { + Builtin []string `json:"builtin,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Description string `json:"description,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + IsDefault bool `json:"isdefault,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ReferenceCount int `json:"referencecount,omitempty"` + RefineSearch string `json:"refinesearch,omitempty"` + Search string `json:"search,omitempty"` + StringBuilderExpr string `json:"stringbuilderexpr,omitempty"` + Target string `json:"target,omitempty"` + TypeField string `json:"type,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type RewritePolicyVPNVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type RewritePolicyLBVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type RewritePolicyLabelRewritePolicyBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type RewritePolicyLabelBinding struct { + LabelName string `json:"labelname,omitempty"` + RewritePolicyLabelPolicyBindingBinding []any `json:"rewritepolicylabel_policybinding_binding,omitempty"` + RewritePolicyLabelRewritePolicyBinding []any `json:"rewritepolicylabel_rewritepolicy_binding,omitempty"` +} + +type RewritePolicyCSVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type RewritePolicyRewriteGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type RewritePolicyBinding struct { + Name string `json:"name,omitempty"` + RewritePolicyCSVServerBinding []any `json:"rewritepolicy_csvserver_binding,omitempty"` + RewritePolicyLBVServerBinding []any `json:"rewritepolicy_lbvserver_binding,omitempty"` + RewritePolicyRewriteGlobalBinding []any `json:"rewritepolicy_rewriteglobal_binding,omitempty"` + RewritePolicyRewritePolicyLabelBinding []any `json:"rewritepolicy_rewritepolicylabel_binding,omitempty"` + RewritePolicyVPNVServerBinding []any `json:"rewritepolicy_vpnvserver_binding,omitempty"` +} + +type RewriteParam struct { + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Timeout int `json:"timeout,omitempty"` + UndefAction string `json:"undefaction,omitempty"` +} + +type RewritePolicyLabel struct { + Builtin []string `json:"builtin,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Description string `json:"description,omitempty"` + Feature string `json:"feature,omitempty"` + FlowType int `json:"flowtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Hits int `json:"hits,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + IsDefault bool `json:"isdefault,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NumPol int `json:"numpol,omitempty"` + Priority int `json:"priority,omitempty"` + Transform string `json:"transform,omitempty"` +} + +type RewritePolicyRewritePolicyLabelBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type RewriteGlobalRewritePolicyBinding struct { + FlowType int `json:"flowtype,omitempty"` + GlobalBindType string `json:"globalbindtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type RewritePolicyLabelPolicyBindingBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} diff --git a/nitrogo/models/router.go b/nitrogo/models/router.go new file mode 100644 index 0000000..75f710a --- /dev/null +++ b/nitrogo/models/router.go @@ -0,0 +1,10 @@ +package models + +// router configuration structs +type RouterDynamicRouting struct { + CommandString string `json:"commandstring,omitempty"` + Count float64 `json:"__count,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + Output string `json:"output,omitempty"` +} diff --git a/nitrogo/models/sc.go b/nitrogo/models/sc.go new file mode 100644 index 0000000..e294a88 --- /dev/null +++ b/nitrogo/models/sc.go @@ -0,0 +1,23 @@ +// Derived from Citrix ADC Nitro Go SDK (https://github.com/netscaler/adc-nitro-go) +// Originally licensed under the Apache License, Version 2.0 +// Modifications by Adam Crawford, 2026 + +package models + +type SCPolicy struct { + Name string `json:"name,omitempty"` + URL string `json:"url,omitempty"` + Rule string `json:"rule,omitempty"` + Delay int `json:"delay,omitempty"` + MaxConn int `json:"maxconn,omitempty"` + Action string `json:"action,omitempty"` + AltContentSvcName string `json:"altcontentsvcname,omitempty"` + AltContentPath string `json:"altcontentpath,omitempty"` +} + +type SCParameter struct { + SessionLife int `json:"sessionlife,omitempty"` + VSR string `json:"vsr,omitempty"` + Builtin string `json:"builtin,omitempty"` + Feature string `json:"feature,omitempty"` +} diff --git a/nitrogo/models/smpp.go b/nitrogo/models/smpp.go new file mode 100644 index 0000000..cb52d0b --- /dev/null +++ b/nitrogo/models/smpp.go @@ -0,0 +1,19 @@ +package models + +// smpp configuration structs +type SMPPParam struct { + AddrNPI int `json:"addrnpi,omitempty"` + AddrRange string `json:"addrrange,omitempty"` + AddrTON int `json:"addrton,omitempty"` + ClientMode string `json:"clientmode,omitempty"` + MsgQueue string `json:"msgqueue,omitempty"` + MsgQueueSize int `json:"msgqueuesize,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type SMPPUser struct { + Count float64 `json:"__count,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Password string `json:"password,omitempty"` + Username string `json:"username,omitempty"` +} diff --git a/nitrogo/models/snmp.go b/nitrogo/models/snmp.go new file mode 100644 index 0000000..91dea6e --- /dev/null +++ b/nitrogo/models/snmp.go @@ -0,0 +1,137 @@ +package models + +// snmp configuration structs +type SNMPManager struct { + Count float64 `json:"__count,omitempty"` + Domain string `json:"domain,omitempty"` + DomainResolveRetry int `json:"domainresolveretry,omitempty"` + IP string `json:"ip,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + Netmask string `json:"netmask,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type SNMPAlarm struct { + Count float64 `json:"__count,omitempty"` + Logging string `json:"logging,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NormalValue int `json:"normalvalue,omitempty"` + Severity string `json:"severity,omitempty"` + State string `json:"state,omitempty"` + ThresholdValue int `json:"thresholdvalue,omitempty"` + Time int `json:"time,omitempty"` + Timeout int `json:"timeout,omitempty"` + TrapName string `json:"trapname,omitempty"` +} + +type SNMPOption struct { + CustomTrap string `json:"customtrap,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PartitionNameInTrap string `json:"partitionnameintrap,omitempty"` + SeverityInfoInTrap string `json:"severityinfointrap,omitempty"` + SNMPSet string `json:"snmpset,omitempty"` + SNMPTrapLogging string `json:"snmptraplogging,omitempty"` + SNMPTrapLoggingLevel string `json:"snmptraplogginglevel,omitempty"` +} + +type SNMPEngineID struct { + Count float64 `json:"__count,omitempty"` + DefaultEngineID string `json:"defaultengineid,omitempty"` + EngineID string `json:"engineid,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OwnerNode int `json:"ownernode,omitempty"` +} + +type SNMPMIB struct { + Contact string `json:"contact,omitempty"` + Count float64 `json:"__count,omitempty"` + CustomID string `json:"customid,omitempty"` + Location string `json:"location,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OwnerNode int `json:"ownernode,omitempty"` + SysDesc string `json:"sysdesc,omitempty"` + SysOID string `json:"sysoid,omitempty"` + SysServices int `json:"sysservices,omitempty"` + SysUptime int `json:"sysuptime,omitempty"` +} + +type SNMPCommunity struct { + CommunityName string `json:"communityname,omitempty"` + Count float64 `json:"__count,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Permissions string `json:"permissions,omitempty"` +} + +type SNMPTrapBinding struct { + SNMPTrapSNMPUserBinding []any `json:"snmptrap_snmpuser_binding,omitempty"` + TD int `json:"td,omitempty"` + TrapClass string `json:"trapclass,omitempty"` + TrapDestination string `json:"trapdestination,omitempty"` + Version string `json:"version,omitempty"` +} + +type SNMPUser struct { + AuthPasswd string `json:"authpasswd,omitempty"` + AuthType string `json:"authtype,omitempty"` + Count float64 `json:"__count,omitempty"` + EngineID string `json:"engineid,omitempty"` + Group string `json:"group,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PrivPasswd string `json:"privpasswd,omitempty"` + PrivType string `json:"privtype,omitempty"` + Status string `json:"status,omitempty"` + StorageType string `json:"storagetype,omitempty"` +} + +type SNMPGroup struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ReadViewName string `json:"readviewname,omitempty"` + SecurityLevel string `json:"securitylevel,omitempty"` + Status string `json:"status,omitempty"` + StorageType string `json:"storagetype,omitempty"` +} + +type SNMPTrap struct { + AllPartitions string `json:"allpartitions,omitempty"` + CommunityName string `json:"communityname,omitempty"` + Count float64 `json:"__count,omitempty"` + DestPort int `json:"destport,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Severity string `json:"severity,omitempty"` + SrcIP string `json:"srcip,omitempty"` + TD int `json:"td,omitempty"` + TrapClass string `json:"trapclass,omitempty"` + TrapDestination string `json:"trapdestination,omitempty"` + Version string `json:"version,omitempty"` +} + +type SNMPTrapSNMPUserBinding struct { + SecurityLevel string `json:"securitylevel,omitempty"` + TD int `json:"td,omitempty"` + TrapClass string `json:"trapclass,omitempty"` + TrapDestination string `json:"trapdestination,omitempty"` + Username string `json:"username,omitempty"` + Version string `json:"version,omitempty"` +} + +type SNMPOID struct { + Count float64 `json:"__count,omitempty"` + EntityType string `json:"entitytype,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + SNMPOID string `json:"Snmpoid,omitempty"` +} + +type SNMPView struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Status string `json:"status,omitempty"` + StorageType string `json:"storagetype,omitempty"` + Subtree string `json:"subtree,omitempty"` + TypeField string `json:"type,omitempty"` +} diff --git a/nitrogo/models/spillover.go b/nitrogo/models/spillover.go new file mode 100644 index 0000000..f950c29 --- /dev/null +++ b/nitrogo/models/spillover.go @@ -0,0 +1,63 @@ +package models + +// spillover configuration structs +type SpilloverPolicyGSLBVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type SpilloverPolicy struct { + Action string `json:"action,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule string `json:"rule,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type SpilloverPolicyLBVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type SpilloverPolicyBinding struct { + Name string `json:"name,omitempty"` + SpilloverPolicyCSVServerBinding []any `json:"spilloverpolicy_csvserver_binding,omitempty"` + SpilloverPolicyGSLBVServerBinding []any `json:"spilloverpolicy_gslbvserver_binding,omitempty"` + SpilloverPolicyLBVServerBinding []any `json:"spilloverpolicy_lbvserver_binding,omitempty"` +} + +type SpilloverAction struct { + Action string `json:"action,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type SpilloverPolicyCSVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} diff --git a/nitrogo/models/ssl.go b/nitrogo/models/ssl.go new file mode 100644 index 0000000..508efb0 --- /dev/null +++ b/nitrogo/models/ssl.go @@ -0,0 +1,1274 @@ +package models + +// ssl configuration structs +type SSLCertKeyBundleIntermediateCertLinksBinding struct { + CertKeyBundleName string `json:"certkeybundlename,omitempty"` + ClientCertNotAfter string `json:"clientcertnotafter,omitempty"` + ClientCertNotBefore string `json:"clientcertnotbefore,omitempty"` + DaysToExpiration int `json:"daystoexpiration,omitempty"` + Issuer string `json:"issuer,omitempty"` + PublicKey string `json:"publickey,omitempty"` + PublicKeySize int `json:"publickeysize,omitempty"` + SANDNS string `json:"sandns,omitempty"` + SANIPAdd string `json:"sanipadd,omitempty"` + Serial string `json:"serial,omitempty"` + SignatureAlg string `json:"signaturealg,omitempty"` + Status string `json:"status,omitempty"` + Subject string `json:"subject,omitempty"` +} + +type SSLHPKEKey struct { + Count float64 `json:"__count,omitempty"` + DHKEM string `json:"dhkem,omitempty"` + File string `json:"file,omitempty"` + HPKEKeyName string `json:"hpkekeyname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type SSLPolicyCSVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type SSLCipherBinding struct { + CipherGroupName string `json:"ciphergroupname,omitempty"` + SSLCipherIndividualCipherBinding []any `json:"sslcipher_individualcipher_binding,omitempty"` + SSLCipherSSLCipherSuiteBinding []any `json:"sslcipher_sslciphersuite_binding,omitempty"` + SSLCipherSSLProfileBinding []any `json:"sslcipher_sslprofile_binding,omitempty"` +} + +type SSLPolicySSLPolicyLabelBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type SSLVServerSSLCertKeyBinding struct { + CA bool `json:"ca,omitempty"` + CertKeyName string `json:"certkeyname,omitempty"` + ClearTextPort int `json:"cleartextport,omitempty"` + CRLCheck string `json:"crlcheck,omitempty"` + OCSPCheck string `json:"ocspcheck,omitempty"` + SkipCAName bool `json:"skipcaname,omitempty"` + SNICert bool `json:"snicert,omitempty"` + VServerName string `json:"vservername,omitempty"` +} + +type SSLCRLSerialNumberBinding struct { + CRLName string `json:"crlname,omitempty"` + Date string `json:"date,omitempty"` + Number string `json:"number,omitempty"` +} + +type SSLFIPSKey struct { + Count float64 `json:"__count,omitempty"` + Curve string `json:"curve,omitempty"` + Exponent string `json:"exponent,omitempty"` + FIPSKeyName string `json:"fipskeyname,omitempty"` + Inform string `json:"inform,omitempty"` + IV string `json:"iv,omitempty"` + Key string `json:"key,omitempty"` + KeyType string `json:"keytype,omitempty"` + Modulus int `json:"modulus,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Size int `json:"size,omitempty"` + WrapKeyName string `json:"wrapkeyname,omitempty"` +} + +type SSLCipherSSLProfileBinding struct { + CipherGroupName string `json:"ciphergroupname,omitempty"` + CipherOperation string `json:"cipheroperation,omitempty"` + CipherPriority int `json:"cipherpriority,omitempty"` + CiphGrpAls string `json:"ciphgrpals,omitempty"` + Description string `json:"description,omitempty"` + SSLProfile string `json:"sslprofile,omitempty"` +} + +type SSLFIPSSimTarget struct { + CertFile string `json:"certfile,omitempty"` + KeyVector string `json:"keyvector,omitempty"` + SourceSecret string `json:"sourcesecret,omitempty"` + TargetSecret string `json:"targetsecret,omitempty"` +} + +type SSLServiceSSLPolicyBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + PolInherit int `json:"polinherit,omitempty"` + Priority int `json:"priority,omitempty"` + ServiceName string `json:"servicename,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type SSLProfileSSLCipherSuiteBinding struct { + CipherName string `json:"ciphername,omitempty"` + CipherPriority int `json:"cipherpriority,omitempty"` + Description string `json:"description,omitempty"` + Name string `json:"name,omitempty"` +} + +type SSLPolicySSLServiceBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type SSLVServerBinding struct { + SSLVServerECCCurveBinding []any `json:"sslvserver_ecccurve_binding,omitempty"` + SSLVServerHashicorpBinding []any `json:"sslvserver_hashicorp_binding,omitempty"` + SSLVServerSSLCACertBundleBinding []any `json:"sslvserver_sslcacertbundle_binding,omitempty"` + SSLVServerSSLCertKeyBinding []any `json:"sslvserver_sslcertkey_binding,omitempty"` + SSLVServerSSLCertKeyBundleBinding []any `json:"sslvserver_sslcertkeybundle_binding,omitempty"` + SSLVServerSSLCipherBinding []any `json:"sslvserver_sslcipher_binding,omitempty"` + SSLVServerSSLCipherSuiteBinding []any `json:"sslvserver_sslciphersuite_binding,omitempty"` + SSLVServerSSLPolicyBinding []any `json:"sslvserver_sslpolicy_binding,omitempty"` + VServerName string `json:"vservername,omitempty"` +} + +type SSLECDSAKey struct { + AES256 bool `json:"aes256,omitempty"` + Curve string `json:"curve,omitempty"` + DES bool `json:"des,omitempty"` + DES3 bool `json:"des3,omitempty"` + KeyFile string `json:"keyfile,omitempty"` + KeyForm string `json:"keyform,omitempty"` + Password string `json:"password,omitempty"` + PKCS8 bool `json:"pkcs8,omitempty"` +} + +type SSLServiceGroupSSLCACertBundleBinding struct { + CACertBundleName string `json:"cacertbundlename,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` +} + +type SSLHSMKey struct { + Count float64 `json:"__count,omitempty"` + HSMKeyName string `json:"hsmkeyname,omitempty"` + HSMType string `json:"hsmtype,omitempty"` + Key string `json:"key,omitempty"` + KeyStore string `json:"keystore,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Password string `json:"password,omitempty"` + SerialNum string `json:"serialnum,omitempty"` + State string `json:"state,omitempty"` +} + +type SSLCACertGroupBinding struct { + CACertGroupName string `json:"cacertgroupname,omitempty"` + SSLCACertGroupSSLCertKeyBinding []any `json:"sslcacertgroup_sslcertkey_binding,omitempty"` +} + +type SSLCipherSuite struct { + CipherName string `json:"ciphername,omitempty"` + Count float64 `json:"__count,omitempty"` + Description string `json:"description,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type SSLCRLBinding struct { + CRLName string `json:"crlname,omitempty"` + SSLCRLSerialNumberBinding []any `json:"sslcrl_serialnumber_binding,omitempty"` +} + +type SSLPolicyLabelBinding struct { + LabelName string `json:"labelname,omitempty"` + SSLPolicyLabelSSLPolicyBinding []any `json:"sslpolicylabel_sslpolicy_binding,omitempty"` +} + +type SSLServiceGroupBinding struct { + ServiceGroupName string `json:"servicegroupname,omitempty"` + SSLServiceGroupECCCurveBinding []any `json:"sslservicegroup_ecccurve_binding,omitempty"` + SSLServiceGroupSSLCACertBundleBinding []any `json:"sslservicegroup_sslcacertbundle_binding,omitempty"` + SSLServiceGroupSSLCertKeyBinding []any `json:"sslservicegroup_sslcertkey_binding,omitempty"` + SSLServiceGroupSSLCipherBinding []any `json:"sslservicegroup_sslcipher_binding,omitempty"` + SSLServiceGroupSSLCipherSuiteBinding []any `json:"sslservicegroup_sslciphersuite_binding,omitempty"` +} + +type SSLWrapKey struct { + Count float64 `json:"__count,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Password string `json:"password,omitempty"` + Salt string `json:"salt,omitempty"` + WrapKeyName string `json:"wrapkeyname,omitempty"` +} + +type SSLOCSPResponder struct { + BatchingDelay int `json:"batchingdelay,omitempty"` + BatchingDepth int `json:"batchingdepth,omitempty"` + Cache string `json:"cache,omitempty"` + CacheTimeout int `json:"cachetimeout,omitempty"` + Count float64 `json:"__count,omitempty"` + HTTPMethod string `json:"httpmethod,omitempty"` + InsertClientCert string `json:"insertclientcert,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OCSPAIARefCount int `json:"ocspaiarefcount,omitempty"` + OCSPIPAddrStr string `json:"ocspipaddrstr,omitempty"` + OCSPURLResolveTimeout int `json:"ocspurlresolvetimeout,omitempty"` + Port int `json:"port,omitempty"` + ProducedAtTimeSkew int `json:"producedattimeskew,omitempty"` + ResponderCert string `json:"respondercert,omitempty"` + RespTimeout int `json:"resptimeout,omitempty"` + SigningCert string `json:"signingcert,omitempty"` + TrustResponder bool `json:"trustresponder,omitempty"` + URL string `json:"url,omitempty"` + UseNonce string `json:"usenonce,omitempty"` +} + +type SSLCRL struct { + BaseDN string `json:"basedn,omitempty"` + Binary string `json:"binary,omitempty"` + BindDN string `json:"binddn,omitempty"` + CACert string `json:"cacert,omitempty"` + CACertFile string `json:"cacertfile,omitempty"` + CAKeyFile string `json:"cakeyfile,omitempty"` + Count float64 `json:"__count,omitempty"` + CRLName string `json:"crlname,omitempty"` + CRLPath string `json:"crlpath,omitempty"` + Day int `json:"day,omitempty"` + DaysToExpiration int `json:"daystoexpiration,omitempty"` + Flags int `json:"flags,omitempty"` + GenCRL string `json:"gencrl,omitempty"` + IndexFile string `json:"indexfile,omitempty"` + Inform string `json:"inform,omitempty"` + Interval string `json:"interval,omitempty"` + Issuer string `json:"issuer,omitempty"` + LastUpdate string `json:"lastupdate,omitempty"` + LastUpdateTime int `json:"lastupdatetime,omitempty"` + Method string `json:"method,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NextUpdate string `json:"nextupdate,omitempty"` + Password string `json:"password,omitempty"` + Port int `json:"port,omitempty"` + Refresh string `json:"refresh,omitempty"` + Revoke string `json:"revoke,omitempty"` + Scope string `json:"scope,omitempty"` + Server string `json:"server,omitempty"` + SignatureAlgo string `json:"signaturealgo,omitempty"` + Time string `json:"time,omitempty"` + URL string `json:"url,omitempty"` + Version int `json:"version,omitempty"` +} + +type SSLCertKeyBundleBinding struct { + CertKeyBundleName string `json:"certkeybundlename,omitempty"` + SSLCertKeyBundleIntermediateCertLinksBinding []any `json:"sslcertkeybundle_intermediatecertlinks_binding,omitempty"` + SSLCertKeyBundleSSLVServerBinding []any `json:"sslcertkeybundle_sslvserver_binding,omitempty"` +} + +type SSLProfileSSLCipherBinding struct { + CipherAliasName string `json:"cipheraliasname,omitempty"` + CipherName string `json:"ciphername,omitempty"` + CipherPriority int `json:"cipherpriority,omitempty"` + Description string `json:"description,omitempty"` + Name string `json:"name,omitempty"` +} + +type SSLPolicyLBVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type SSLPKCS8 struct { + KeyFile string `json:"keyfile,omitempty"` + KeyForm string `json:"keyform,omitempty"` + Password string `json:"password,omitempty"` + PKCS8File string `json:"pkcs8file,omitempty"` +} + +type SSLVServerSSLCACertBundleBinding struct { + CACertBundleName string `json:"cacertbundlename,omitempty"` + SkipCACertBundle bool `json:"skipcacertbundle,omitempty"` + VServerName string `json:"vservername,omitempty"` +} + +type SSLProfileBinding struct { + Name string `json:"name,omitempty"` + SSLProfileECCCurveBinding []any `json:"sslprofile_ecccurve_binding,omitempty"` + SSLProfileSSLCertKeyBinding []any `json:"sslprofile_sslcertkey_binding,omitempty"` + SSLProfileSSLCipherBinding []any `json:"sslprofile_sslcipher_binding,omitempty"` + SSLProfileSSLCipherSuiteBinding []any `json:"sslprofile_sslciphersuite_binding,omitempty"` + SSLProfileSSLECHConfigBinding []any `json:"sslprofile_sslechconfig_binding,omitempty"` + SSLProfileSSLVServerBinding []any `json:"sslprofile_sslvserver_binding,omitempty"` +} + +type SSLCertKeyServiceBinding struct { + CA bool `json:"ca,omitempty"` + CertKey string `json:"certkey,omitempty"` + Data int `json:"data,omitempty"` + Service bool `json:"service,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` + ServiceName string `json:"servicename,omitempty"` + Version int `json:"version,omitempty"` +} + +type SSLVServerECCCurveBinding struct { + ECCCurveName string `json:"ecccurvename,omitempty"` + VServerName string `json:"vservername,omitempty"` +} + +type SSLCACertGroup struct { + CACertGroupName string `json:"cacertgroupname,omitempty"` + CACertGroupReferences int `json:"cacertgroupreferences,omitempty"` + Count float64 `json:"__count,omitempty"` + CRLCheck string `json:"crlcheck,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OCSPCheck string `json:"ocspcheck,omitempty"` +} + +type SSLServiceSSLCipherBinding struct { + CipherAliasName string `json:"cipheraliasname,omitempty"` + CipherDefaultOn int `json:"cipherdefaulton,omitempty"` + CipherName string `json:"ciphername,omitempty"` + Description string `json:"description,omitempty"` + ServiceName string `json:"servicename,omitempty"` +} + +type SSLVServerSSLCipherBinding struct { + CipherAliasName string `json:"cipheraliasname,omitempty"` + CipherName string `json:"ciphername,omitempty"` + Description string `json:"description,omitempty"` + VServerName string `json:"vservername,omitempty"` +} + +type SSLDefaultProfile struct { +} + +type SSLCertKeyCRLDistributionBinding struct { + CA bool `json:"ca,omitempty"` + CertKey string `json:"certkey,omitempty"` + Issuer string `json:"issuer,omitempty"` +} + +type SSLCACertBundle struct { + BundleFile string `json:"bundlefile,omitempty"` + CACertBundleName string `json:"cacertbundlename,omitempty"` + Count float64 `json:"__count,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ServerName string `json:"servername,omitempty"` +} + +type SSLDTLSProfile struct { + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + HelloVerifyRequest string `json:"helloverifyrequest,omitempty"` + InitialRetryTimeout int `json:"initialretrytimeout,omitempty"` + MaxBadMACIgnoreCount int `json:"maxbadmacignorecount,omitempty"` + MaxHoldQLen int `json:"maxholdqlen,omitempty"` + MaxPacketSize int `json:"maxpacketsize,omitempty"` + MaxRecordSize int `json:"maxrecordsize,omitempty"` + MaxRetryTime int `json:"maxretrytime,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PMTUDiscovery string `json:"pmtudiscovery,omitempty"` + TerminateSession string `json:"terminatesession,omitempty"` +} + +type SSLCert struct { + CACert string `json:"cacert,omitempty"` + CACertForm string `json:"cacertform,omitempty"` + CAKey string `json:"cakey,omitempty"` + CAKeyForm string `json:"cakeyform,omitempty"` + CASerial string `json:"caserial,omitempty"` + CertFile string `json:"certfile,omitempty"` + CertForm string `json:"certform,omitempty"` + CertType string `json:"certtype,omitempty"` + Days int `json:"days,omitempty"` + KeyFile string `json:"keyfile,omitempty"` + KeyForm string `json:"keyform,omitempty"` + PEMPassphrase string `json:"pempassphrase,omitempty"` + ReqFile string `json:"reqfile,omitempty"` + SubjectAltName string `json:"subjectaltname,omitempty"` +} + +type SSLPolicySSLGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type SSLRSAKey struct { + AES256 bool `json:"aes256,omitempty"` + Bits int `json:"bits,omitempty"` + DES bool `json:"des,omitempty"` + DES3 bool `json:"des3,omitempty"` + Exponent string `json:"exponent,omitempty"` + KeyFile string `json:"keyfile,omitempty"` + KeyForm string `json:"keyform,omitempty"` + Password string `json:"password,omitempty"` + PKCS8 bool `json:"pkcs8,omitempty"` +} + +type SSLServiceECCCurveBinding struct { + ECCCurveName string `json:"ecccurvename,omitempty"` + ServiceName string `json:"servicename,omitempty"` +} + +type SSLServiceSSLCertKeyBinding struct { + CA bool `json:"ca,omitempty"` + CertKeyName string `json:"certkeyname,omitempty"` + ClearTextPort int `json:"cleartextport,omitempty"` + CRLCheck string `json:"crlcheck,omitempty"` + OCSPCheck string `json:"ocspcheck,omitempty"` + ServiceName string `json:"servicename,omitempty"` + SkipCAName bool `json:"skipcaname,omitempty"` + SNICert bool `json:"snicert,omitempty"` +} + +type SSLServiceGroup struct { + CA bool `json:"ca,omitempty"` + CipherRedirect string `json:"cipherredirect,omitempty"` + CipherURL string `json:"cipherurl,omitempty"` + ClearTextPort int `json:"cleartextport,omitempty"` + ClientAuth string `json:"clientauth,omitempty"` + ClientCert string `json:"clientcert,omitempty"` + CommonName string `json:"commonname,omitempty"` + Count float64 `json:"__count,omitempty"` + CRLCheck string `json:"crlcheck,omitempty"` + DH string `json:"dh,omitempty"` + DHCount int `json:"dhcount,omitempty"` + DHFile string `json:"dhfile,omitempty"` + DHKeyExpSizeLimit string `json:"dhkeyexpsizelimit,omitempty"` + ERSA string `json:"ersa,omitempty"` + ERSACount int `json:"ersacount,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NonFIPSCiphers string `json:"nonfipsciphers,omitempty"` + OCSPCheck string `json:"ocspcheck,omitempty"` + OCSPStapling string `json:"ocspstapling,omitempty"` + QUICFlag bool `json:"quicflag,omitempty"` + RedirectPortRewrite string `json:"redirectportrewrite,omitempty"` + SendCloseNotify string `json:"sendclosenotify,omitempty"` + ServerAuth string `json:"serverauth,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` + ServiceName string `json:"servicename,omitempty"` + SessReuse string `json:"sessreuse,omitempty"` + SessTimeout int `json:"sesstimeout,omitempty"` + SNICert bool `json:"snicert,omitempty"` + SNIEnable string `json:"snienable,omitempty"` + SSL2 string `json:"ssl2,omitempty"` + SSL3 string `json:"ssl3,omitempty"` + SSLClientLogs string `json:"sslclientlogs,omitempty"` + SSLProfile string `json:"sslprofile,omitempty"` + SSLRedirect string `json:"sslredirect,omitempty"` + SSLv2Redirect string `json:"sslv2redirect,omitempty"` + SSLv2URL string `json:"sslv2url,omitempty"` + StrictSigDigestCheck string `json:"strictsigdigestcheck,omitempty"` + TLS1 string `json:"tls1,omitempty"` + TLS11 string `json:"tls11,omitempty"` + TLS12 string `json:"tls12,omitempty"` + TLS13 string `json:"tls13,omitempty"` +} + +type SSLProfileSSLVServerBinding struct { + CipherPriority int `json:"cipherpriority,omitempty"` + Description string `json:"description,omitempty"` + Name string `json:"name,omitempty"` + ServiceName string `json:"servicename,omitempty"` +} + +type SSLCertLink struct { + CertKeyName string `json:"certkeyname,omitempty"` + Count float64 `json:"__count,omitempty"` + LinkCertKeyName string `json:"linkcertkeyname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type SSLGlobalSSLPolicyBinding struct { + GlobalBindType string `json:"globalbindtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type SSLCRLFile struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Src string `json:"src,omitempty"` +} + +type SSLCertChainSSLCertKeyBinding struct { + AddSubject bool `json:"addsubject,omitempty"` + CertKeyName string `json:"certkeyname,omitempty"` + IsCA bool `json:"isca,omitempty"` + IsLinked bool `json:"islinked,omitempty"` + LinkCertKeyName string `json:"linkcertkeyname,omitempty"` +} + +type SSLParameter struct { + CRLMemorySizeMB int `json:"crlmemorysizemb,omitempty"` + CryptoDevDisableLimit int `json:"cryptodevdisablelimit,omitempty"` + DefaultProfile string `json:"defaultprofile,omitempty"` + DenySSLReneg string `json:"denysslreneg,omitempty"` + DropReqWithNoHostHeader string `json:"dropreqwithnohostheader,omitempty"` + EncryptTriggerPktCount int `json:"encrypttriggerpktcount,omitempty"` + HeterogeneousSSLHW string `json:"heterogeneoussslhw,omitempty"` + HybridFIPSMode string `json:"hybridfipsmode,omitempty"` + InsertCertSpace string `json:"insertcertspace,omitempty"` + InsertionEncoding string `json:"insertionencoding,omitempty"` + MonTLS1112Disable string `json:"montls1112disable,omitempty"` + NDCPPComplianceCertCheck string `json:"ndcppcompliancecertcheck,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OCSPCachesize int `json:"ocspcachesize,omitempty"` + OperationQueueLimit int `json:"operationqueuelimit,omitempty"` + PushEncTriggerTimeout int `json:"pushenctriggertimeout,omitempty"` + PushFlag int `json:"pushflag,omitempty"` + QuantumSize string `json:"quantumsize,omitempty"` + SendCloseNotify string `json:"sendclosenotify,omitempty"` + SigDigestType []string `json:"sigdigesttype,omitempty"` + SNIHTTPHostMatch string `json:"snihttphostmatch,omitempty"` + SoftwareCryptoThreshold int `json:"softwarecryptothreshold,omitempty"` + SSLIErrorCache string `json:"sslierrorcache,omitempty"` + SSLIMaxErrorCacheMem int `json:"sslimaxerrorcachemem,omitempty"` + SSLTriggerTimeout int `json:"ssltriggertimeout,omitempty"` + StrictCAChecks string `json:"strictcachecks,omitempty"` + SvcTLS1112Disable string `json:"svctls1112disable,omitempty"` + UndefActionControl string `json:"undefactioncontrol,omitempty"` + UndefActionData string `json:"undefactiondata,omitempty"` +} + +type SSLDHParam struct { + Bits int `json:"bits,omitempty"` + DHFile string `json:"dhfile,omitempty"` + Gen string `json:"gen,omitempty"` +} + +type SSLPolicy struct { + Action string `json:"action,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Description string `json:"description,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ReqAction string `json:"reqaction,omitempty"` + Rule string `json:"rule,omitempty"` + UndefAction string `json:"undefaction,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type SSLCertBundle struct { + Count float64 `json:"__count,omitempty"` + InUse string `json:"inuse,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Src string `json:"src,omitempty"` +} + +type SSLCertKeySSLVServerBinding struct { + CA bool `json:"ca,omitempty"` + CertKey string `json:"certkey,omitempty"` + Data int `json:"data,omitempty"` + ServerName string `json:"servername,omitempty"` + Version int `json:"version,omitempty"` + VServer bool `json:"vserver,omitempty"` + VServerName string `json:"vservername,omitempty"` +} + +type SSLCertKeyBundleSSLVServerBinding struct { + CertKeyBundleName string `json:"certkeybundlename,omitempty"` + ServerName string `json:"servername,omitempty"` +} + +type SSLServiceGroupECCCurveBinding struct { + ECCCurveName string `json:"ecccurvename,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` +} + +type SSLProfileSSLCertKeyBinding struct { + CertKeyName string `json:"certkeyname,omitempty"` + CipherPriority int `json:"cipherpriority,omitempty"` + ForgingCACertKey bool `json:"forgingcacertkey,omitempty"` + Name string `json:"name,omitempty"` + SSLICACertKey string `json:"sslicacertkey,omitempty"` +} + +type SSLCertFile struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Src string `json:"src,omitempty"` +} + +type SSLCACertGroupSSLCertKeyBinding struct { + CACertGroupName string `json:"cacertgroupname,omitempty"` + CertKeyName string `json:"certkeyname,omitempty"` + CRLCheck string `json:"crlcheck,omitempty"` + OCSPCheck string `json:"ocspcheck,omitempty"` +} + +type SSLServiceGroupSSLCipherBinding struct { + CipherAliasName string `json:"cipheraliasname,omitempty"` + CipherName string `json:"ciphername,omitempty"` + Description string `json:"description,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` +} + +type SSLCertKey struct { + Builtin []string `json:"builtin,omitempty"` + Bundle string `json:"bundle,omitempty"` + Cert string `json:"cert,omitempty"` + CertificateSource string `json:"certificatesource,omitempty"` + CertificateType []string `json:"certificatetype,omitempty"` + CertKey string `json:"certkey,omitempty"` + CertKeyDigest string `json:"certkeydigest,omitempty"` + CertKeyStatus string `json:"certkeystatus,omitempty"` + ClientCertNotAfter string `json:"clientcertnotafter,omitempty"` + ClientCertNotBefore string `json:"clientcertnotbefore,omitempty"` + Count float64 `json:"__count,omitempty"` + Data int `json:"data,omitempty"` + DaysToExpiration int `json:"daystoexpiration,omitempty"` + DeleteCertKeyFilesOnRemoval string `json:"deletecertkeyfilesonremoval,omitempty"` + DeleteFromDevice bool `json:"deletefromdevice,omitempty"` + ExpiryMonitor string `json:"expirymonitor,omitempty"` + Feature string `json:"feature,omitempty"` + FIPSKey string `json:"fipskey,omitempty"` + HSMKey string `json:"hsmkey,omitempty"` + Inform string `json:"inform,omitempty"` + Issuer string `json:"issuer,omitempty"` + Key string `json:"key,omitempty"` + LinkCertKeyName string `json:"linkcertkeyname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NoDomainCheck bool `json:"nodomaincheck,omitempty"` + NotificationPeriod int `json:"notificationperiod,omitempty"` + OCSPResponseStatus string `json:"ocspresponsestatus,omitempty"` + OCSPStaplingCache bool `json:"ocspstaplingcache,omitempty"` + PassCrypt string `json:"passcrypt,omitempty"` + PassPlain string `json:"passplain,omitempty"` + Password bool `json:"password,omitempty"` + Priority int `json:"priority,omitempty"` + PublicKey string `json:"publickey,omitempty"` + PublicKeySize int `json:"publickeysize,omitempty"` + SANDNS string `json:"sandns,omitempty"` + SANIPAdd string `json:"sanipadd,omitempty"` + Serial string `json:"serial,omitempty"` + ServiceName string `json:"servicename,omitempty"` + SignatureAlg string `json:"signaturealg,omitempty"` + Status string `json:"status,omitempty"` + Subject string `json:"subject,omitempty"` + Version int `json:"version,omitempty"` +} + +type SSLProfileSSLECHConfigBinding struct { + CipherPriority int `json:"cipherpriority,omitempty"` + ECHConfigName string `json:"echconfigname,omitempty"` + Name string `json:"name,omitempty"` +} + +type SSLServiceSSLCipherSuiteBinding struct { + CipherDefaultOn int `json:"cipherdefaulton,omitempty"` + CipherName string `json:"ciphername,omitempty"` + Description string `json:"description,omitempty"` + ServiceName string `json:"servicename,omitempty"` +} + +type SSLCertKeyBundle struct { + BundleFile string `json:"bundlefile,omitempty"` + CertKeyBundleName string `json:"certkeybundlename,omitempty"` + Count float64 `json:"__count,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PassPlain string `json:"passplain,omitempty"` +} + +type SSLCertChainBinding struct { + CertKeyName string `json:"certkeyname,omitempty"` + SSLCertChainSSLCertKeyBinding []any `json:"sslcertchain_sslcertkey_binding,omitempty"` +} + +type SSLCertificateChain struct { + CertKeyName string `json:"certkeyname,omitempty"` + ChainComplete int `json:"chaincomplete,omitempty"` + ChainIssuer string `json:"chainissuer,omitempty"` + ChainLinked []string `json:"chainlinked,omitempty"` + ChainPossibleLinks []string `json:"chainpossiblelinks,omitempty"` + Count float64 `json:"__count,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type SSLProfileECCCurveBinding struct { + CipherPriority int `json:"cipherpriority,omitempty"` + ECCCurveName string `json:"ecccurvename,omitempty"` + Name string `json:"name,omitempty"` +} + +type SSLService struct { + CipherRedirect string `json:"cipherredirect,omitempty"` + CipherURL string `json:"cipherurl,omitempty"` + ClientAuth string `json:"clientauth,omitempty"` + ClientCert string `json:"clientcert,omitempty"` + CommonName string `json:"commonname,omitempty"` + Count float64 `json:"__count,omitempty"` + DH string `json:"dh,omitempty"` + DHCount int `json:"dhcount,omitempty"` + DHFile string `json:"dhfile,omitempty"` + DHKeyExpSizeLimit string `json:"dhkeyexpsizelimit,omitempty"` + DTLS1 string `json:"dtls1,omitempty"` + DTLS12 string `json:"dtls12,omitempty"` + DTLSFlag bool `json:"dtlsflag,omitempty"` + DTLSProfileName string `json:"dtlsprofilename,omitempty"` + ERSA string `json:"ersa,omitempty"` + ERSACount int `json:"ersacount,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NonFIPSCiphers string `json:"nonfipsciphers,omitempty"` + OCSPStapling string `json:"ocspstapling,omitempty"` + PushEncTrigger string `json:"pushenctrigger,omitempty"` + QUICFlag bool `json:"quicflag,omitempty"` + RedirectPortRewrite string `json:"redirectportrewrite,omitempty"` + SendCloseNotify string `json:"sendclosenotify,omitempty"` + ServerAuth string `json:"serverauth,omitempty"` + Service int `json:"service,omitempty"` + ServiceName string `json:"servicename,omitempty"` + SessReuse string `json:"sessreuse,omitempty"` + SessTimeout int `json:"sesstimeout,omitempty"` + SkipCACertBundle bool `json:"skipcacertbundle,omitempty"` + SkipCAName bool `json:"skipcaname,omitempty"` + SNIEnable string `json:"snienable,omitempty"` + SSL2 string `json:"ssl2,omitempty"` + SSL3 string `json:"ssl3,omitempty"` + SSLClientLogs string `json:"sslclientlogs,omitempty"` + SSLProfile string `json:"sslprofile,omitempty"` + SSLRedirect string `json:"sslredirect,omitempty"` + SSLv2Redirect string `json:"sslv2redirect,omitempty"` + SSLv2URL string `json:"sslv2url,omitempty"` + StrictSigDigestCheck string `json:"strictsigdigestcheck,omitempty"` + TLS1 string `json:"tls1,omitempty"` + TLS11 string `json:"tls11,omitempty"` + TLS12 string `json:"tls12,omitempty"` + TLS13 string `json:"tls13,omitempty"` +} + +type SSLProfile struct { + AllowExtendedMasterSecret string `json:"allowextendedmastersecret,omitempty"` + AllowLegacyKDF string `json:"allowlegacykdf,omitempty"` + AllowUnknownSNI string `json:"allowunknownsni,omitempty"` + ALPNProtocol string `json:"alpnprotocol,omitempty"` + Builtin []string `json:"builtin,omitempty"` + CipherName string `json:"ciphername,omitempty"` + CipherPriority int `json:"cipherpriority,omitempty"` + CipherRedirect string `json:"cipherredirect,omitempty"` + CipherURL string `json:"cipherurl,omitempty"` + ClearTextPort int `json:"cleartextport,omitempty"` + ClientAuth string `json:"clientauth,omitempty"` + ClientAuthUseBoundCAChain string `json:"clientauthuseboundcachain,omitempty"` + ClientCert string `json:"clientcert,omitempty"` + CommonName string `json:"commonname,omitempty"` + Count float64 `json:"__count,omitempty"` + CRLCheck string `json:"crlcheck,omitempty"` + DefaultSNI string `json:"defaultsni,omitempty"` + DenySSLReneg string `json:"denysslreneg,omitempty"` + DH string `json:"dh,omitempty"` + DHCount int `json:"dhcount,omitempty"` + DHEKeyExchangeWithPSK string `json:"dhekeyexchangewithpsk,omitempty"` + DHFile string `json:"dhfile,omitempty"` + DHKeyExpSizeLimit string `json:"dhkeyexpsizelimit,omitempty"` + DropReqWithNoHostHeader string `json:"dropreqwithnohostheader,omitempty"` + DynamicClientCert string `json:"dynamicclientcert,omitempty"` + EncryptedClientHello string `json:"encryptedclienthello,omitempty"` + EncryptTriggerPktCount int `json:"encrypttriggerpktcount,omitempty"` + ERSA string `json:"ersa,omitempty"` + ERSACount int `json:"ersacount,omitempty"` + Feature string `json:"feature,omitempty"` + HSTS string `json:"hsts,omitempty"` + IncludeSubdomains string `json:"includesubdomains,omitempty"` + InsertionEncoding string `json:"insertionencoding,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelType string `json:"labeltype,omitempty"` + MaxAge int `json:"maxage,omitempty"` + MaxRenegRate int `json:"maxrenegrate,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NoDefaultBindings string `json:"nodefaultbindings,omitempty"` + NonFIPSCiphers string `json:"nonfipsciphers,omitempty"` + OCSPCheck string `json:"ocspcheck,omitempty"` + OCSPStapling string `json:"ocspstapling,omitempty"` + Preload string `json:"preload,omitempty"` + PrevSessionKeyLifetime int `json:"prevsessionkeylifetime,omitempty"` + PushEncTrigger string `json:"pushenctrigger,omitempty"` + PushEncTriggerTimeout int `json:"pushenctriggertimeout,omitempty"` + PushFlag int `json:"pushflag,omitempty"` + QuantumSize string `json:"quantumsize,omitempty"` + RedirectPortRewrite string `json:"redirectportrewrite,omitempty"` + SendCloseNotify string `json:"sendclosenotify,omitempty"` + ServerAuth string `json:"serverauth,omitempty"` + Service int `json:"service,omitempty"` + SessionKeyLifetime int `json:"sessionkeylifetime,omitempty"` + SessionTicket string `json:"sessionticket,omitempty"` + SessionTicketKeyData string `json:"sessionticketkeydata,omitempty"` + SessionTicketKeyRefresh string `json:"sessionticketkeyrefresh,omitempty"` + SessionTicketLifetime int `json:"sessionticketlifetime,omitempty"` + SessReuse string `json:"sessreuse,omitempty"` + SessTimeout int `json:"sesstimeout,omitempty"` + SkipCAName bool `json:"skipcaname,omitempty"` + SkipClientCertPolicyCheck string `json:"skipclientcertpolicycheck,omitempty"` + SNICert bool `json:"snicert,omitempty"` + SNIEnable string `json:"snienable,omitempty"` + SNIHTTPHostMatch string `json:"snihttphostmatch,omitempty"` + SSL3 string `json:"ssl3,omitempty"` + SSLClientLogs string `json:"sslclientlogs,omitempty"` + SSLIMaxSessPerServer int `json:"sslimaxsessperserver,omitempty"` + SSLInterception string `json:"sslinterception,omitempty"` + SSLIOCSPCheck string `json:"ssliocspcheck,omitempty"` + SSLIReneg string `json:"sslireneg,omitempty"` + SSLIVerifyServerCertForReuse string `json:"ssliverifyservercertforreuse,omitempty"` + SSLLogProfile string `json:"ssllogprofile,omitempty"` + SSLPFObjectType int `json:"sslpfobjecttype,omitempty"` + SSLProfileType string `json:"sslprofiletype,omitempty"` + SSLRedirect string `json:"sslredirect,omitempty"` + SSLTriggerTimeout int `json:"ssltriggertimeout,omitempty"` + StrictCAChecks string `json:"strictcachecks,omitempty"` + StrictSigDigestCheck string `json:"strictsigdigestcheck,omitempty"` + TLS1 string `json:"tls1,omitempty"` + TLS11 string `json:"tls11,omitempty"` + TLS12 string `json:"tls12,omitempty"` + TLS13 string `json:"tls13,omitempty"` + TLS13SessionTicketsPerAuthContext int `json:"tls13sessionticketsperauthcontext,omitempty"` + ZeroRTTEarlyData string `json:"zerorttearlydata,omitempty"` +} + +type SSLZeroTouchParam struct { + ADMConnectivityStatus string `json:"admconnectivitystatus,omitempty"` + HTTPStatusCode string `json:"httpstatuscode,omitempty"` + KeyFileName string `json:"keyfilename,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NextRequestTime string `json:"nextrequesttime,omitempty"` + OCSPBatchingDelay int `json:"ocspbatchingdelay,omitempty"` + OCSPBatchingDepth int `json:"ocspbatchingdepth,omitempty"` + OCSPCacheTimeout int `json:"ocspcachetimeout,omitempty"` + OCSPHTTPMethod string `json:"ocsphttpmethod,omitempty"` + OCSPProducedAtTimeSkew int `json:"ocspproducedattimeskew,omitempty"` + OCSPRespTimeout int `json:"ocspresptimeout,omitempty"` + OCSPTrustResponder string `json:"ocsptrustresponder,omitempty"` + OCSPURLResolveTimeout int `json:"ocspurlresolvetimeout,omitempty"` + OCSPUseNonce string `json:"ocspusenonce,omitempty"` + Passphrase string `json:"passphrase,omitempty"` + RemoteServerIP string `json:"remoteserverip,omitempty"` + RequestTimestamp string `json:"requesttimestamp,omitempty"` + RequestType string `json:"requesttype,omitempty"` + ZeroTouch string `json:"zerotouch,omitempty"` +} + +type SSLPolicyBinding struct { + Name string `json:"name,omitempty"` + SSLPolicyCSVServerBinding []any `json:"sslpolicy_csvserver_binding,omitempty"` + SSLPolicyLBVServerBinding []any `json:"sslpolicy_lbvserver_binding,omitempty"` + SSLPolicySSLGlobalBinding []any `json:"sslpolicy_sslglobal_binding,omitempty"` + SSLPolicySSLPolicyLabelBinding []any `json:"sslpolicy_sslpolicylabel_binding,omitempty"` + SSLPolicySSLServiceBinding []any `json:"sslpolicy_sslservice_binding,omitempty"` + SSLPolicySSLVServerBinding []any `json:"sslpolicy_sslvserver_binding,omitempty"` +} + +type SSLPKCS12 struct { + AES256 bool `json:"aes256,omitempty"` + CertFile string `json:"certfile,omitempty"` + DES bool `json:"des,omitempty"` + DES3 bool `json:"des3,omitempty"` + Export bool `json:"export,omitempty"` + Import bool `json:"Import,omitempty"` + KeyFile string `json:"keyfile,omitempty"` + OutFile string `json:"outfile,omitempty"` + Password string `json:"password,omitempty"` + PEMPassphrase string `json:"pempassphrase,omitempty"` + PKCS12File string `json:"pkcs12file,omitempty"` +} + +type SSLPolicySSLVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type SSLCipherSSLCipherSuiteBinding struct { + CipherGroupName string `json:"ciphergroupname,omitempty"` + CipherName string `json:"ciphername,omitempty"` + CipherOperation string `json:"cipheroperation,omitempty"` + CipherPriority int `json:"cipherpriority,omitempty"` + CiphGrpAls string `json:"ciphgrpals,omitempty"` + Description string `json:"description,omitempty"` +} + +type SSLKeyFile struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Password string `json:"password,omitempty"` + Src string `json:"src,omitempty"` +} + +type SSLPolicyLabelSSLPolicyBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type SSLDynamicClientCertCache struct { +} + +type SSLGlobalBinding struct { + SSLGlobalSSLPolicyBinding []any `json:"sslglobal_sslpolicy_binding,omitempty"` +} + +type SSLServiceSSLCACertBundleBinding struct { + CACertBundleName string `json:"cacertbundlename,omitempty"` + ServiceName string `json:"servicename,omitempty"` + SkipCACertBundle bool `json:"skipcacertbundle,omitempty"` +} + +type SSLCipherIndividualCipherBinding struct { + CipherGroupName string `json:"ciphergroupname,omitempty"` + CipherName string `json:"ciphername,omitempty"` + CipherOperation string `json:"cipheroperation,omitempty"` + CipherPriority int `json:"cipherpriority,omitempty"` + CiphGrpAls string `json:"ciphgrpals,omitempty"` + Description string `json:"description,omitempty"` +} + +type SSLVServerSSLCertKeyBundleBinding struct { + CertKeyBundleName string `json:"certkeybundlename,omitempty"` + SNICertKeyBundle bool `json:"snicertkeybundle,omitempty"` + VServerName string `json:"vservername,omitempty"` +} + +type SSLCertKeySSLOCSPResponderBinding struct { + CA bool `json:"ca,omitempty"` + CertKey string `json:"certkey,omitempty"` + OCSPResponder string `json:"ocspresponder,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type SSLDHFile struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Src string `json:"src,omitempty"` +} + +type SSLVServerSSLCipherSuiteBinding struct { + CipherName string `json:"ciphername,omitempty"` + Description string `json:"description,omitempty"` + VServerName string `json:"vservername,omitempty"` +} + +type SSLVServerHashicorpBinding struct { + Vault string `json:"vault,omitempty"` + VServerName string `json:"vservername,omitempty"` +} + +type SSLFIPS struct { + CoresEnabled int `json:"coresenabled,omitempty"` + CoresMax int `json:"coresmax,omitempty"` + EraseData string `json:"erasedata,omitempty"` + FIPSFW string `json:"fipsfw,omitempty"` + FIPSHWMajorVersion int `json:"fipshwmajorversion,omitempty"` + FIPSHWMinorVersion int `json:"fipshwminorversion,omitempty"` + FIPSHWVersionString string `json:"fipshwversionstring,omitempty"` + FirmwareReleaseDate string `json:"firmwarereleasedate,omitempty"` + Flag int `json:"flag,omitempty"` + FlashMemoryFree int `json:"flashmemoryfree,omitempty"` + FlashMemoryTotal int `json:"flashmemorytotal,omitempty"` + HSMLabel string `json:"hsmlabel,omitempty"` + InitHSM string `json:"inithsm,omitempty"` + MajorVersion int `json:"majorversion,omitempty"` + MinorVersion int `json:"minorversion,omitempty"` + Model string `json:"model,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OldSOPassword string `json:"oldsopassword,omitempty"` + Serial int `json:"serial,omitempty"` + SerialNo string `json:"serialno,omitempty"` + SOPassword string `json:"sopassword,omitempty"` + SRAMFree int `json:"sramfree,omitempty"` + SRAMTotal int `json:"sramtotal,omitempty"` + State int `json:"state,omitempty"` + Status int `json:"status,omitempty"` + UserPassword string `json:"userpassword,omitempty"` +} + +type SSLAction struct { + Builtin []string `json:"builtin,omitempty"` + CACertGrpName string `json:"cacertgrpname,omitempty"` + CertFingerprintDigest string `json:"certfingerprintdigest,omitempty"` + CertFingerprintHeader string `json:"certfingerprintheader,omitempty"` + CertHashHeader string `json:"certhashheader,omitempty"` + CertHeader string `json:"certheader,omitempty"` + CertIssuerHeader string `json:"certissuerheader,omitempty"` + CertNotAfterHeader string `json:"certnotafterheader,omitempty"` + CertNotBeforeHeader string `json:"certnotbeforeheader,omitempty"` + CertSerialHeader string `json:"certserialheader,omitempty"` + CertSubjectHeader string `json:"certsubjectheader,omitempty"` + Cipher string `json:"cipher,omitempty"` + CipherHeader string `json:"cipherheader,omitempty"` + ClientAuth string `json:"clientauth,omitempty"` + ClientCert string `json:"clientcert,omitempty"` + ClientCertFingerprint string `json:"clientcertfingerprint,omitempty"` + ClientCertHash string `json:"clientcerthash,omitempty"` + ClientCertIssuer string `json:"clientcertissuer,omitempty"` + ClientCertNotAfter string `json:"clientcertnotafter,omitempty"` + ClientCertNotBefore string `json:"clientcertnotbefore,omitempty"` + ClientCertSerialNumber string `json:"clientcertserialnumber,omitempty"` + ClientCertSubject string `json:"clientcertsubject,omitempty"` + ClientCertVerification string `json:"clientcertverification,omitempty"` + Count float64 `json:"__count,omitempty"` + Description string `json:"description,omitempty"` + Feature string `json:"feature,omitempty"` + Forward string `json:"forward,omitempty"` + Hits int `json:"hits,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OCSPCache string `json:"ocspcache,omitempty"` + OCSPCertValidation string `json:"ocspcertvalidation,omitempty"` + OCSPStapling string `json:"ocspstapling,omitempty"` + OWASupport string `json:"owasupport,omitempty"` + ReferenceCount int `json:"referencecount,omitempty"` + SessionID string `json:"sessionid,omitempty"` + SessionIDHeader string `json:"sessionidheader,omitempty"` + SSLLogProfile string `json:"ssllogprofile,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type SSLServiceGroupSSLCipherSuiteBinding struct { + CipherName string `json:"ciphername,omitempty"` + Description string `json:"description,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` +} + +type SSLLogProfile struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + SSLLogClAuth string `json:"ssllogclauth,omitempty"` + SSLLogClAuthFailures string `json:"ssllogclauthfailures,omitempty"` + SSLLogHS string `json:"sslloghs,omitempty"` + SSLLogHSFailures string `json:"sslloghsfailures,omitempty"` +} + +type SSLFIPSSimSource struct { + CertFile string `json:"certfile,omitempty"` + SourceSecret string `json:"sourcesecret,omitempty"` + TargetSecret string `json:"targetsecret,omitempty"` +} + +type SSLServiceGroupSSLCertKeyBinding struct { + CA bool `json:"ca,omitempty"` + CertKeyName string `json:"certkeyname,omitempty"` + CRLCheck string `json:"crlcheck,omitempty"` + OCSPCheck string `json:"ocspcheck,omitempty"` + ServiceGroupName string `json:"servicegroupname,omitempty"` + SNICert bool `json:"snicert,omitempty"` +} + +type SSLCertReq struct { + ChallengePassword string `json:"challengepassword,omitempty"` + CommonName string `json:"commonname,omitempty"` + CompanyName string `json:"companyname,omitempty"` + CountryName string `json:"countryname,omitempty"` + DigestMethod string `json:"digestmethod,omitempty"` + EmailAddress string `json:"emailaddress,omitempty"` + FIPSKeyName string `json:"fipskeyname,omitempty"` + KeyFile string `json:"keyfile,omitempty"` + KeyForm string `json:"keyform,omitempty"` + LocalityName string `json:"localityname,omitempty"` + OrganizationName string `json:"organizationname,omitempty"` + OrganizationUnitName string `json:"organizationunitname,omitempty"` + PEMPassphrase string `json:"pempassphrase,omitempty"` + ReqFile string `json:"reqfile,omitempty"` + StateName string `json:"statename,omitempty"` + SubjectAltName string `json:"subjectaltname,omitempty"` +} + +type SSLCACertBundleBinding struct { + CACertBundleName string `json:"cacertbundlename,omitempty"` + SSLCACertBundleIntermediateCACertListBinding []any `json:"sslcacertbundle_intermediatecacertlist_binding,omitempty"` +} + +type SSLServiceBinding struct { + ServiceName string `json:"servicename,omitempty"` + SSLServiceECCCurveBinding []any `json:"sslservice_ecccurve_binding,omitempty"` + SSLServiceSSLCACertBundleBinding []any `json:"sslservice_sslcacertbundle_binding,omitempty"` + SSLServiceSSLCertKeyBinding []any `json:"sslservice_sslcertkey_binding,omitempty"` + SSLServiceSSLCipherBinding []any `json:"sslservice_sslcipher_binding,omitempty"` + SSLServiceSSLCipherSuiteBinding []any `json:"sslservice_sslciphersuite_binding,omitempty"` + SSLServiceSSLPolicyBinding []any `json:"sslservice_sslpolicy_binding,omitempty"` +} + +type SSLCipher struct { + CipherGroupName string `json:"ciphergroupname,omitempty"` + CipherName string `json:"ciphername,omitempty"` + CipherPriority int `json:"cipherpriority,omitempty"` + CiphGrpAlias string `json:"ciphgrpalias,omitempty"` + Count float64 `json:"__count,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + SSLProfile string `json:"sslprofile,omitempty"` +} + +type SSLCertChain struct { + CertKeyName string `json:"certkeyname,omitempty"` + Count float64 `json:"__count,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type SSLCertKeyBinding struct { + CertKey string `json:"certkey,omitempty"` + SSLCertKeyCRLDistributionBinding []any `json:"sslcertkey_crldistribution_binding,omitempty"` + SSLCertKeyServiceBinding []any `json:"sslcertkey_service_binding,omitempty"` + SSLCertKeySSLOCSPResponderBinding []any `json:"sslcertkey_sslocspresponder_binding,omitempty"` + SSLCertKeySSLProfileBinding []any `json:"sslcertkey_sslprofile_binding,omitempty"` + SSLCertKeySSLVServerBinding []any `json:"sslcertkey_sslvserver_binding,omitempty"` +} + +type SSLPolicyLabel struct { + Count float64 `json:"__count,omitempty"` + Description string `json:"description,omitempty"` + FlowType int `json:"flowtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Hits int `json:"hits,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type SSLCertKeySSLProfileBinding struct { + CA bool `json:"ca,omitempty"` + CertKey string `json:"certkey,omitempty"` + SSLProfile string `json:"sslprofile,omitempty"` +} + +type SSLVServerSSLPolicyBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + PolInherit int `json:"polinherit,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` + VServerName string `json:"vservername,omitempty"` +} + +type SSLECHConfig struct { + Count float64 `json:"__count,omitempty"` + ECHCipher string `json:"echcipher,omitempty"` + ECHConfigID int `json:"echconfigid,omitempty"` + ECHConfigName string `json:"echconfigname,omitempty"` + ECHPublicName string `json:"echpublicname,omitempty"` + HPKEKeyName string `json:"hpkekeyname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Version int `json:"version,omitempty"` +} + +type SSLCACertBundleIntermediateCACertListBinding struct { + CACertBundleName string `json:"cacertbundlename,omitempty"` + ClientCertNotAfter string `json:"clientcertnotafter,omitempty"` + ClientCertNotBefore string `json:"clientcertnotbefore,omitempty"` + DaysToExpiration int `json:"daystoexpiration,omitempty"` + Issuer string `json:"issuer,omitempty"` + PublicKey string `json:"publickey,omitempty"` + PublicKeySize int `json:"publickeysize,omitempty"` + SANDNS string `json:"sandns,omitempty"` + SANIPAdd string `json:"sanipadd,omitempty"` + Serial string `json:"serial,omitempty"` + SignatureAlg string `json:"signaturealg,omitempty"` + Status string `json:"status,omitempty"` + Subject string `json:"subject,omitempty"` +} + +type SSLVServer struct { + CA bool `json:"ca,omitempty"` + CipherRedirect string `json:"cipherredirect,omitempty"` + CipherURL string `json:"cipherurl,omitempty"` + ClearTextPort int `json:"cleartextport,omitempty"` + ClientAuth string `json:"clientauth,omitempty"` + ClientCert string `json:"clientcert,omitempty"` + Count float64 `json:"__count,omitempty"` + CRLCheck string `json:"crlcheck,omitempty"` + DefaultSNI string `json:"defaultsni,omitempty"` + DH string `json:"dh,omitempty"` + DHCount int `json:"dhcount,omitempty"` + DHEKeyExchangeWithPSK string `json:"dhekeyexchangewithpsk,omitempty"` + DHFile string `json:"dhfile,omitempty"` + DHKeyExpSizeLimit string `json:"dhkeyexpsizelimit,omitempty"` + DTLS1 string `json:"dtls1,omitempty"` + DTLS12 string `json:"dtls12,omitempty"` + DTLSFlag bool `json:"dtlsflag,omitempty"` + DTLSProfileName string `json:"dtlsprofilename,omitempty"` + ERSA string `json:"ersa,omitempty"` + ERSACount int `json:"ersacount,omitempty"` + HSTS string `json:"hsts,omitempty"` + IncludeSubdomains string `json:"includesubdomains,omitempty"` + MaxAge int `json:"maxage,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NonFIPSCiphers string `json:"nonfipsciphers,omitempty"` + OCSPCheck string `json:"ocspcheck,omitempty"` + OCSPStapling string `json:"ocspstapling,omitempty"` + Preload string `json:"preload,omitempty"` + PushEncTrigger string `json:"pushenctrigger,omitempty"` + QUICFlag bool `json:"quicflag,omitempty"` + RedirectPortRewrite string `json:"redirectportrewrite,omitempty"` + SendCloseNotify string `json:"sendclosenotify,omitempty"` + Service int `json:"service,omitempty"` + SessReuse string `json:"sessreuse,omitempty"` + SessTimeout int `json:"sesstimeout,omitempty"` + SkipCACertBundle bool `json:"skipcacertbundle,omitempty"` + SkipCAName bool `json:"skipcaname,omitempty"` + SNICert bool `json:"snicert,omitempty"` + SNIEnable string `json:"snienable,omitempty"` + SSL2 string `json:"ssl2,omitempty"` + SSL3 string `json:"ssl3,omitempty"` + SSLClientLogs string `json:"sslclientlogs,omitempty"` + SSLProfile string `json:"sslprofile,omitempty"` + SSLRedirect string `json:"sslredirect,omitempty"` + SSLv2Redirect string `json:"sslv2redirect,omitempty"` + SSLv2URL string `json:"sslv2url,omitempty"` + StrictSigDigestCheck string `json:"strictsigdigestcheck,omitempty"` + TLS1 string `json:"tls1,omitempty"` + TLS11 string `json:"tls11,omitempty"` + TLS12 string `json:"tls12,omitempty"` + TLS13 string `json:"tls13,omitempty"` + TLS13SessionTicketsPerAuthContext int `json:"tls13sessionticketsperauthcontext,omitempty"` + VServerName string `json:"vservername,omitempty"` + ZeroRTTEarlyData string `json:"zerorttearlydata,omitempty"` +} diff --git a/nitrogo/models/stream.go b/nitrogo/models/stream.go new file mode 100644 index 0000000..7960c50 --- /dev/null +++ b/nitrogo/models/stream.go @@ -0,0 +1,51 @@ +package models + +// stream configuration structs +type StreamSession struct { + Name string `json:"name,omitempty"` +} + +type StreamIdentifier struct { + AcceptanceThreshold string `json:"acceptancethreshold,omitempty"` + AppFlowLog string `json:"appflowlog,omitempty"` + BreachThreshold int `json:"breachthreshold,omitempty"` + Count float64 `json:"__count,omitempty"` + Interval int `json:"interval,omitempty"` + Log string `json:"log,omitempty"` + LogInterval int `json:"loginterval,omitempty"` + LogLimit int `json:"loglimit,omitempty"` + MaxTransactionThreshold int `json:"maxtransactionthreshold,omitempty"` + MinTransactionThreshold int `json:"mintransactionthreshold,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule []string `json:"rule,omitempty"` + SampleCount int `json:"samplecount,omitempty"` + SelectorName string `json:"selectorname,omitempty"` + SNMPTrap string `json:"snmptrap,omitempty"` + Sort string `json:"sort,omitempty"` + TrackAckOnlyPackets string `json:"trackackonlypackets,omitempty"` + TrackTransactions string `json:"tracktransactions,omitempty"` +} + +type StreamIdentifierBinding struct { + Name string `json:"name,omitempty"` + StreamIdentifierAnalyticsProfileBinding []any `json:"streamidentifier_analyticsprofile_binding,omitempty"` + StreamIdentifierStreamSessionBinding []any `json:"streamidentifier_streamsession_binding,omitempty"` +} + +type StreamIdentifierAnalyticsProfileBinding struct { + AnalyticsProfile string `json:"analyticsprofile,omitempty"` + Name string `json:"name,omitempty"` +} + +type StreamSelector struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule []string `json:"rule,omitempty"` +} + +type StreamIdentifierStreamSessionBinding struct { + AnalyticsProfile string `json:"analyticsprofile,omitempty"` + Name string `json:"name,omitempty"` +} diff --git a/nitrogo/models/subscriber.go b/nitrogo/models/subscriber.go new file mode 100644 index 0000000..15aa8b8 --- /dev/null +++ b/nitrogo/models/subscriber.go @@ -0,0 +1,91 @@ +package models + +// subscriber configuration structs +type SubscriberSessions struct { + AVPDisplayBuffer string `json:"avpdisplaybuffer,omitempty"` + Count float64 `json:"__count,omitempty"` + Flags int `json:"flags,omitempty"` + IdleTTL int `json:"idlettl,omitempty"` + IP string `json:"ip,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + ServicePath string `json:"servicepath,omitempty"` + SubscriberRules []string `json:"subscriberrules,omitempty"` + SubscriptionIDType string `json:"subscriptionidtype,omitempty"` + SubscriptionIDValue string `json:"subscriptionidvalue,omitempty"` + TTL int `json:"ttl,omitempty"` + VLAN int `json:"vlan,omitempty"` +} + +type SubscriberGxInterface struct { + CerRequestTimeout int `json:"cerrequesttimeout,omitempty"` + GxReportingAVP1 []any `json:"gxreportingavp1,omitempty"` + GxReportingAVP1Type string `json:"gxreportingavp1type,omitempty"` + GxReportingAVP1VendorID int `json:"gxreportingavp1vendorid,omitempty"` + GxReportingAVP2 []any `json:"gxreportingavp2,omitempty"` + GxReportingAVP2Type string `json:"gxreportingavp2type,omitempty"` + GxReportingAVP2VendorID int `json:"gxreportingavp2vendorid,omitempty"` + GxReportingAVP3 []any `json:"gxreportingavp3,omitempty"` + GxReportingAVP3Type string `json:"gxreportingavp3type,omitempty"` + GxReportingAVP3VendorID int `json:"gxreportingavp3vendorid,omitempty"` + GxReportingAVP4 []any `json:"gxreportingavp4,omitempty"` + GxReportingAVP4Type string `json:"gxreportingavp4type,omitempty"` + GxReportingAVP4VendorID int `json:"gxreportingavp4vendorid,omitempty"` + GxReportingAVP5 []any `json:"gxreportingavp5,omitempty"` + GxReportingAVP5Type string `json:"gxreportingavp5type,omitempty"` + GxReportingAVP5VendorID int `json:"gxreportingavp5vendorid,omitempty"` + HealthCheck string `json:"healthcheck,omitempty"` + HealthCheckTTL int `json:"healthcheckttl,omitempty"` + HoldOnSubscriberAbsence string `json:"holdonsubscriberabsence,omitempty"` + Identity string `json:"identity,omitempty"` + IdleTTL int `json:"idlettl,omitempty"` + NegativeTTL int `json:"negativettl,omitempty"` + NegativeTTLLimitedSuccess string `json:"negativettllimitedsuccess,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + PCRFRealm string `json:"pcrfrealm,omitempty"` + PurgeSDBOnGxFailure string `json:"purgesdbongxfailure,omitempty"` + Realm string `json:"realm,omitempty"` + RequestRetryAttempts int `json:"requestretryattempts,omitempty"` + RequestTimeout int `json:"requesttimeout,omitempty"` + RevalidationTimeout int `json:"revalidationtimeout,omitempty"` + Service string `json:"service,omitempty"` + ServicePathAVP []any `json:"servicepathavp,omitempty"` + ServicePathInfoMode string `json:"servicepathinfomode,omitempty"` + ServicePathVendorID int `json:"servicepathvendorid,omitempty"` + Status string `json:"status,omitempty"` + SvrState string `json:"svrstate,omitempty"` + VServer string `json:"vserver,omitempty"` +} + +type SubscriberProfile struct { + AVPDisplayBuffer string `json:"avpdisplaybuffer,omitempty"` + Count float64 `json:"__count,omitempty"` + Flags int `json:"flags,omitempty"` + IP string `json:"ip,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ServicePath string `json:"servicepath,omitempty"` + SubscriberRules []string `json:"subscriberrules,omitempty"` + SubscriptionIDType string `json:"subscriptionidtype,omitempty"` + SubscriptionIDValue string `json:"subscriptionidvalue,omitempty"` + TTL int `json:"ttl,omitempty"` + VLAN int `json:"vlan,omitempty"` +} + +type SubscriberParam struct { + Builtin []string `json:"builtin,omitempty"` + Feature string `json:"feature,omitempty"` + IdleAction string `json:"idleaction,omitempty"` + IdleTTL int `json:"idlettl,omitempty"` + InterfaceType string `json:"interfacetype,omitempty"` + IPv6PrefixLookupList []any `json:"ipv6prefixlookuplist,omitempty"` + KeyType string `json:"keytype,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type SubscriberRadiusInterface struct { + ListeningService string `json:"listeningservice,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + RadiusInterimAsStart string `json:"radiusinterimasstart,omitempty"` + SvrState string `json:"svrstate,omitempty"` +} diff --git a/nitrogo/models/system.go b/nitrogo/models/system.go index 12b99b8..4465361 100644 --- a/nitrogo/models/system.go +++ b/nitrogo/models/system.go @@ -1,9 +1,313 @@ -// Derived from Citrix ADC Nitro Go SDK (https://github.com/netscaler/adc-nitro-go) -// Originally licensed under the Apache License, Version 2.0 -// Modifications by Adam Crawford, 2025 - package models +// system configuration structs +type SystemGlobalAuthenticationLDAPPolicyBinding struct { + Builtin []string `json:"builtin,omitempty"` + Feature string `json:"feature,omitempty"` + GlobalBindType string `json:"globalbindtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type SystemUserSystemCmdPolicyBinding struct { + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + Username string `json:"username,omitempty"` +} + +type SystemGlobalAuditSyslogPolicyBinding struct { + Builtin []string `json:"builtin,omitempty"` + Feature string `json:"feature,omitempty"` + GlobalBindType string `json:"globalbindtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type SystemHWError struct { + DiskCheck bool `json:"diskcheck,omitempty"` + HWErrorCount int `json:"hwerrorcount,omitempty"` + Response string `json:"response,omitempty"` +} + +type SystemParameter struct { + AllowDefaultPartition string `json:"allowdefaultpartition,omitempty"` + BasicAuth string `json:"basicauth,omitempty"` + CLILogLevel string `json:"cliloglevel,omitempty"` + DaysToExpire int `json:"daystoexpire,omitempty"` + Doppler string `json:"doppler,omitempty"` + FIPSUserMode string `json:"fipsusermode,omitempty"` + ForcePasswordChange string `json:"forcepasswordchange,omitempty"` + GoogleAnalytics string `json:"googleanalytics,omitempty"` + LocalAuth string `json:"localauth,omitempty"` + MaxClient int `json:"maxclient,omitempty"` + MaxSessionPerUser int `json:"maxsessionperuser,omitempty"` + MinPasswordLen int `json:"minpasswordlen,omitempty"` + NATPCBForceFlushLimit int `json:"natpcbforceflushlimit,omitempty"` + NATPCBRstOnTimeout string `json:"natpcbrstontimeout,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PasswordHistoryControl string `json:"passwordhistorycontrol,omitempty"` + PromptString string `json:"promptstring,omitempty"` + PwdHistoryCount int `json:"pwdhistorycount,omitempty"` + RBAOnResponse string `json:"rbaonresponse,omitempty"` + ReAuthOnAuthParamChange string `json:"reauthonauthparamchange,omitempty"` + RemoveSensitiveFiles string `json:"removesensitivefiles,omitempty"` + RestrictedTimeout string `json:"restrictedtimeout,omitempty"` + StrongPassword string `json:"strongpassword,omitempty"` + Timeout int `json:"timeout,omitempty"` + TotalAuthTimeout int `json:"totalauthtimeout,omitempty"` + WAFProtection []string `json:"wafprotection,omitempty"` + WarnPriorNDays int `json:"warnpriorndays,omitempty"` +} + +type SystemGroupSystemCmdPolicyBinding struct { + GroupName string `json:"groupname,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type SystemGlobalAuthenticationLocalPolicyBinding struct { + Builtin []string `json:"builtin,omitempty"` + Feature string `json:"feature,omitempty"` + GlobalBindType string `json:"globalbindtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type SystemADMUserInfo struct { + Username string `json:"username,omitempty"` +} + +type SystemSession struct { + All bool `json:"all,omitempty"` + ClientIPAddress string `json:"clientipaddress,omitempty"` + ClientType string `json:"clienttype,omitempty"` + Count float64 `json:"__count,omitempty"` + CurrentConn bool `json:"currentconn,omitempty"` + ExpiryTime int `json:"expirytime,omitempty"` + LastActivityTime string `json:"lastactivitytime,omitempty"` + LastActivityTimeLocal string `json:"lastactivitytimelocal,omitempty"` + LoginTime string `json:"logintime,omitempty"` + LoginTimeLocal string `json:"logintimelocal,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NumOfConnections int `json:"numofconnections,omitempty"` + PartitionName string `json:"partitionname,omitempty"` + SID int `json:"sid,omitempty"` + Username string `json:"username,omitempty"` +} + +type SystemAutoRestoreFeature struct { +} + +type SystemGlobalBinding struct { + SystemGlobalAuditNSLogPolicyBinding []any `json:"systemglobal_auditnslogpolicy_binding,omitempty"` + SystemGlobalAuditSyslogPolicyBinding []any `json:"systemglobal_auditsyslogpolicy_binding,omitempty"` + SystemGlobalAuthenticationLDAPPolicyBinding []any `json:"systemglobal_authenticationldappolicy_binding,omitempty"` + SystemGlobalAuthenticationLocalPolicyBinding []any `json:"systemglobal_authenticationlocalpolicy_binding,omitempty"` + SystemGlobalAuthenticationPolicyBinding []any `json:"systemglobal_authenticationpolicy_binding,omitempty"` + SystemGlobalAuthenticationRADIUSPolicyBinding []any `json:"systemglobal_authenticationradiuspolicy_binding,omitempty"` + SystemGlobalAuthenticationTACACSPolicyBinding []any `json:"systemglobal_authenticationtacacspolicy_binding,omitempty"` +} + +type SystemKEK struct { + Level string `json:"level,omitempty"` +} + +type SystemCPUParam struct { + Count float64 `json:"__count,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PEMode string `json:"pemode,omitempty"` +} + +type SystemRestorePoint struct { + BackupFileName string `json:"backupfilename,omitempty"` + Count float64 `json:"__count,omitempty"` + CreatedBy string `json:"createdby,omitempty"` + CreationTime string `json:"creationtime,omitempty"` + FileName string `json:"filename,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + TechSuprtName string `json:"techsuprtname,omitempty"` + Version string `json:"version,omitempty"` +} + +type SystemGlobalAuditNSLogPolicyBinding struct { + Builtin []string `json:"builtin,omitempty"` + Feature string `json:"feature,omitempty"` + GlobalBindType string `json:"globalbindtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type SystemGroup struct { + AllowedManagementInterface []string `json:"allowedmanagementinterface,omitempty"` + Count float64 `json:"__count,omitempty"` + DaysToExpire int `json:"daystoexpire,omitempty"` + GroupName string `json:"groupname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PromptString string `json:"promptstring,omitempty"` + Timeout int `json:"timeout,omitempty"` + WarnPriorNDays int `json:"warnpriorndays,omitempty"` +} + +type SystemGlobalAuthenticationRADIUSPolicyBinding struct { + Builtin []string `json:"builtin,omitempty"` + Feature string `json:"feature,omitempty"` + GlobalBindType string `json:"globalbindtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type SystemGroupSystemUserBinding struct { + GroupName string `json:"groupname,omitempty"` + Username string `json:"username,omitempty"` +} + +type SystemGlobalAuthenticationTACACSPolicyBinding struct { + Builtin []string `json:"builtin,omitempty"` + Feature string `json:"feature,omitempty"` + GlobalBindType string `json:"globalbindtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type SystemUserSystemGroupBinding struct { + GroupName string `json:"groupname,omitempty"` + Username string `json:"username,omitempty"` +} + +type SystemFIPSStatus struct { + FIPSStatus string `json:"fipsstatus,omitempty"` + IntelHWCryptographicAcceleratorVersion string `json:"intelhwcryptographicacceleratorversion,omitempty"` + NetScalerControlPlaneCryptographicLibraryVersion string `json:"netscalercontrolplanecryptographiclibraryversion,omitempty"` + NetScalerCrytographicModuleVersion string `json:"netscalercrytographicmoduleversion,omitempty"` + NetScalerDataPlaneCryptographicLibraryVersion string `json:"netscalerdataplanecryptographiclibraryversion,omitempty"` + NetScalerJitterEntropySourceVersion string `json:"netscalerjitterentropysourceversion,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type SystemSignedExeReport struct { + Message string `json:"message,omitempty"` +} + +type SystemNSBTracing struct { + ConfiguredState string `json:"configuredstate,omitempty"` + EffectiveState string `json:"effectivestate,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` +} + +type SystemCmdPolicy struct { + Action string `json:"action,omitempty"` + Builtin []string `json:"builtin,omitempty"` + CmdSpec string `json:"cmdspec,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PolicyName string `json:"policyname,omitempty"` +} + +type SystemGroupNSPartitionBinding struct { + GroupName string `json:"groupname,omitempty"` + PartitionName string `json:"partitionname,omitempty"` +} + +type SystemGlobalAuthenticationPolicyBinding struct { + Builtin []string `json:"builtin,omitempty"` + Feature string `json:"feature,omitempty"` + GlobalBindType string `json:"globalbindtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + NextFactor string `json:"nextfactor,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type SystemGroupBinding struct { + GroupName string `json:"groupname,omitempty"` + SystemGroupNSPartitionBinding []any `json:"systemgroup_nspartition_binding,omitempty"` + SystemGroupSystemCmdPolicyBinding []any `json:"systemgroup_systemcmdpolicy_binding,omitempty"` + SystemGroupSystemUserBinding []any `json:"systemgroup_systemuser_binding,omitempty"` +} + +type SystemBackup struct { + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + CreatedBy string `json:"createdby,omitempty"` + CreationTime string `json:"creationtime,omitempty"` + FileName string `json:"filename,omitempty"` + IncludeKernel string `json:"includekernel,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + Level string `json:"level,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Size int `json:"size,omitempty"` + SkipBackup bool `json:"skipbackup,omitempty"` + UseLocalTimezone bool `json:"uselocaltimezone,omitempty"` + Version string `json:"version,omitempty"` +} + +type SystemSSHKey struct { + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Src string `json:"src,omitempty"` + SSHKeyType string `json:"sshkeytype,omitempty"` +} + +type SystemUser struct { + AllowedManagementInterface []string `json:"allowedmanagementinterface,omitempty"` + AllowedManagementInterfaceKind string `json:"allowedmanagementinterfacekind,omitempty"` + Count float64 `json:"__count,omitempty"` + DaysToExpireKind string `json:"daystoexpirekind,omitempty"` + Encrypted bool `json:"encrypted,omitempty"` + ExternalAuth string `json:"externalauth,omitempty"` + HashMethod string `json:"hashmethod,omitempty"` + LastPwdChangeTimestamp int `json:"lastpwdchangetimestamp,omitempty"` + Logging string `json:"logging,omitempty"` + MaxSession int `json:"maxsession,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Password string `json:"password,omitempty"` + PromptInheritedFrom string `json:"promptinheritedfrom,omitempty"` + PromptString string `json:"promptstring,omitempty"` + Timeout int `json:"timeout,omitempty"` + TimeoutKind string `json:"timeoutkind,omitempty"` + Username string `json:"username,omitempty"` +} + +type SystemUserBinding struct { + SystemUserNSPartitionBinding []any `json:"systemuser_nspartition_binding,omitempty"` + SystemUserSystemCmdPolicyBinding []any `json:"systemuser_systemcmdpolicy_binding,omitempty"` + SystemUserSystemGroupBinding []any `json:"systemuser_systemgroup_binding,omitempty"` + Username string `json:"username,omitempty"` +} + +type SystemFile struct { + Count float64 `json:"__count,omitempty"` + FileAccessTime string `json:"fileaccesstime,omitempty"` + FileContent string `json:"filecontent,omitempty"` + FileEncoding string `json:"fileencoding,omitempty"` + FileLocation string `json:"filelocation,omitempty"` + FileMode []string `json:"filemode,omitempty"` + FileModifiedTime string `json:"filemodifiedtime,omitempty"` + FileName string `json:"filename,omitempty"` + FileSize int `json:"filesize,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type SystemUserNSPartitionBinding struct { + PartitionName string `json:"partitionname,omitempty"` + Username string `json:"username,omitempty"` +} + type SystemStatus struct { AddiMgmtCPUUsagePcnt float64 `json:"addimgmtcpuusagepcnt,omitempty"` AuxTemp0 int `json:"auxtemp0,omitempty"` @@ -19,10 +323,10 @@ type SystemStatus struct { AuxVolt6 float64 `json:"auxvolt6,omitempty"` AuxVolt7 float64 `json:"auxvolt7,omitempty"` ClearStats string `json:"clearstats,omitempty"` - Cpu0Temp int `json:"cpu0temp,omitempty"` - Cpu1Temp int `json:"cpu1temp,omitempty"` - CpuFan0Apeed int `json:"cpufan0speed,omitempty"` - CpuFan1Apeed int `json:"cpufan1speed,omitempty"` + CPU0Temp int `json:"cpu0temp,omitempty"` + CPU1Temp int `json:"cpu1temp,omitempty"` + CPUFan0Speed int `json:"cpufan0speed,omitempty"` + CPUFan1Speed int `json:"cpufan1speed,omitempty"` CPUUsage string `json:"cpuusage,omitempty"` CPUUsagePcnt float64 `json:"cpuusagepcnt,omitempty"` Disk0Avail int `json:"disk0avail,omitempty"` @@ -30,7 +334,7 @@ type SystemStatus struct { Disk0Size int `json:"disk0size,omitempty"` Disk0Used int `json:"disk0used,omitempty"` Disk1Avail int `json:"disk1avail,omitempty"` - Disk1perUsage int `json:"disk1perusage,omitempty"` + Disk1PerUsage int `json:"disk1perusage,omitempty"` Disk1Size int `json:"disk1size,omitempty"` Disk1Used int `json:"disk1used,omitempty"` Fan0Speed int `json:"fan0speed,omitempty"` @@ -45,7 +349,7 @@ type SystemStatus struct { MemUsagePcnt float64 `json:"memusagepcnt,omitempty"` MemUseInMB string `json:"memuseinmb,omitempty"` MgmtCPU0UsagePcnt float64 `json:"mgmtcpu0usagepcnt,omitempty"` - MgmtCPUUsageCcnt float64 `json:"mgmtcpuusagepcnt,omitempty"` + MgmtCPUUsagePcnt float64 `json:"mgmtcpuusagepcnt,omitempty"` NumCPUs string `json:"numcpus,omitempty"` PktCPUUsagePcnt float64 `json:"pktcpuusagepcnt,omitempty"` PowerSupply1Status string `json:"powersupply1status,omitempty"` @@ -59,13 +363,13 @@ type SystemStatus struct { StartTimeLocal string `json:"starttimelocal,omitempty"` SystemFanSpeed int `json:"systemfanspeed,omitempty"` TimeSinceStart string `json:"timesincestart,omitempty"` - VoltageV12n float64 `json:"voltagev12n,omitempty"` - VoltageV12p float64 `json:"voltagev12p,omitempty"` + VoltageV12N float64 `json:"voltagev12n,omitempty"` + VoltageV12P float64 `json:"voltagev12p,omitempty"` VoltageV33Main float64 `json:"voltagev33main,omitempty"` VoltageV33Stby float64 `json:"voltagev33stby,omitempty"` - VoltageV5n float64 `json:"voltagev5n,omitempty"` - VoltageV5p float64 `json:"voltagev5p,omitempty"` - VoltageV5sb float64 `json:"voltagev5sb,omitempty"` + VoltageV5N float64 `json:"voltagev5n,omitempty"` + VoltageV5P float64 `json:"voltagev5p,omitempty"` + VoltageV5SB float64 `json:"voltagev5sb,omitempty"` VoltageVBat float64 `json:"voltagevbat,omitempty"` VoltageVCC0 float64 `json:"voltagevcc0,omitempty"` VoltageVCC1 float64 `json:"voltagevcc1,omitempty"` @@ -74,8 +378,87 @@ type SystemStatus struct { } type SystemExtraMgmtCPU struct { - Nodeid int `json:"nodeid,omitempty"` + NodeID int `json:"nodeid,omitempty"` ConfiguredState string `json:"configuredstate,omitempty"` EffectiveState string `json:"effectivestate,omitempty"` NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` } + +type SystemCollectionParam struct { + CommunityName string `json:"communityname,omitempty"` + LogLevel string `json:"loglevel,omitempty"` + DataPath string `json:"datapath,omitempty"` +} + +type SystemCore struct { + Datasource string `json:"datasource,omitempty"` + Response string `json:"response,omitempty"` +} + +type SystemCounterGroup struct { + Datasource string `json:"datasource,omitempty"` + Response string `json:"response,omitempty"` +} + +type SystemCounters struct { + CounterGroup string `json:"countergroup,omitempty"` + Datasource string `json:"datasource,omitempty"` + Response string `json:"response,omitempty"` +} + +type SystemDataSource struct { + Datasource string `json:"datasource,omitempty"` + Response string `json:"response,omitempty"` +} + +type SystemEntity struct { + Type string `json:"type,omitempty"` + Datasource string `json:"datasource,omitempty"` + Core int `json:"core,omitempty"` + Response string `json:"response,omitempty"` +} + +type SystemEntityData struct { + Type string `json:"type,omitempty"` + Name string `json:"name,omitempty"` + AllDeleted string `json:"alldeleted,omitempty"` + AllInactive string `json:"allinactive,omitempty"` + Datasource string `json:"datasource,omitempty"` + Core int `json:"core,omitempty"` + Counters string `json:"counters,omitempty"` + StartTime string `json:"starttime,omitempty"` + EndTime string `json:"endtime,omitempty"` + Last int `json:"last,omitempty"` + Unit string `json:"unit,omitempty"` + Response string `json:"response,omitempty"` + StartUpdate string `json:"startupdate,omitempty"` + LastUpdate string `json:"lastupdate,omitempty"` +} + +type SystemEntityType struct { + Datasource string `json:"datasource,omitempty"` + Response string `json:"response,omitempty"` +} + +type SystemEventHistory struct { + StartTime string `json:"starttime,omitempty"` + EndTime string `json:"endtime,omitempty"` + Last int `json:"last,omitempty"` + Unit string `json:"unit,omitempty"` + Datasource string `json:"datasource,omitempty"` + Response string `json:"response,omitempty"` +} + +type SystemGlobalData struct { + Counters string `json:"counters,omitempty"` + CounterGroup string `json:"countergroup,omitempty"` + StartTime string `json:"starttime,omitempty"` + EndTime string `json:"endtime,omitempty"` + Last int `json:"last,omitempty"` + Unit string `json:"unit,omitempty"` + Datasource string `json:"datasource,omitempty"` + Core int `json:"core,omitempty"` + Response string `json:"response,omitempty"` + StartUpdate float64 `json:"startupdate,omitempty"` + LastUpdate float64 `json:"lastupdate,omitempty"` +} diff --git a/nitrogo/models/tm.go b/nitrogo/models/tm.go new file mode 100644 index 0000000..92397e7 --- /dev/null +++ b/nitrogo/models/tm.go @@ -0,0 +1,278 @@ +package models + +// tm configuration structs +type TMFormSSOAction struct { + ActionURL string `json:"actionurl,omitempty"` + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NameValuePair string `json:"namevaluepair,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NVType string `json:"nvtype,omitempty"` + PasswdField string `json:"passwdfield,omitempty"` + ResponseSize int `json:"responsesize,omitempty"` + SSOSuccessRule string `json:"ssosuccessrule,omitempty"` + SubmitMethod string `json:"submitmethod,omitempty"` + UserField string `json:"userfield,omitempty"` +} + +type TMTrafficPolicyLBVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type TMTrafficPolicy struct { + Action string `json:"action,omitempty"` + Count float64 `json:"__count,omitempty"` + Hits int `json:"hits,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule string `json:"rule,omitempty"` +} + +type TMGlobalTMTrafficPolicyBinding struct { + BindPolicyType int `json:"bindpolicytype,omitempty"` + GlobalBindType string `json:"globalbindtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type TMGlobalBinding struct { + TMGlobalAuditNSLogPolicyBinding []any `json:"tmglobal_auditnslogpolicy_binding,omitempty"` + TMGlobalAuditSyslogPolicyBinding []any `json:"tmglobal_auditsyslogpolicy_binding,omitempty"` + TMGlobalTMSessionPolicyBinding []any `json:"tmglobal_tmsessionpolicy_binding,omitempty"` + TMGlobalTMTrafficPolicyBinding []any `json:"tmglobal_tmtrafficpolicy_binding,omitempty"` +} + +type TMTrafficPolicyBinding struct { + Name string `json:"name,omitempty"` + TMTrafficPolicyCSVServerBinding []any `json:"tmtrafficpolicy_csvserver_binding,omitempty"` + TMTrafficPolicyLBVServerBinding []any `json:"tmtrafficpolicy_lbvserver_binding,omitempty"` + TMTrafficPolicyTMGlobalBinding []any `json:"tmtrafficpolicy_tmglobal_binding,omitempty"` +} + +type TMSessionPolicy struct { + Action string `json:"action,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + ExpressionType string `json:"expressiontype,omitempty"` + Feature string `json:"feature,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Hits int `json:"hits,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule string `json:"rule,omitempty"` +} + +type TMTrafficPolicyCSVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type TMSessionPolicyTMGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type TMSessionParameter struct { + DefaultAuthorizationAction string `json:"defaultauthorizationaction,omitempty"` + Homepage string `json:"homepage,omitempty"` + HTTPOnlyCookie string `json:"httponlycookie,omitempty"` + KCDAccount string `json:"kcdaccount,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PersistentCookie string `json:"persistentcookie,omitempty"` + PersistentCookieValidity int `json:"persistentcookievalidity,omitempty"` + SessTimeout int `json:"sesstimeout,omitempty"` + SSO string `json:"sso,omitempty"` + SSOCredential string `json:"ssocredential,omitempty"` + SSODomain string `json:"ssodomain,omitempty"` + TMSessionPolicyBindType string `json:"tmsessionpolicybindtype,omitempty"` + TMSessionPolicyCount int `json:"tmsessionpolicycount,omitempty"` +} + +type TMGlobalAuditNSLogPolicyBinding struct { + BindPolicyType int `json:"bindpolicytype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type TMTrafficAction struct { + AppTimeout int `json:"apptimeout,omitempty"` + Count float64 `json:"__count,omitempty"` + ForcedTimeout string `json:"forcedtimeout,omitempty"` + ForcedTimeoutVal int `json:"forcedtimeoutval,omitempty"` + FormSSOAction string `json:"formssoaction,omitempty"` + InitiateLogout string `json:"initiatelogout,omitempty"` + KCDAccount string `json:"kcdaccount,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PasswdExpression string `json:"passwdexpression,omitempty"` + PersistentCookie string `json:"persistentcookie,omitempty"` + SAMLSSOProfile string `json:"samlssoprofile,omitempty"` + SSO string `json:"sso,omitempty"` + UserExpression string `json:"userexpression,omitempty"` +} + +type TMSessionPolicyBinding struct { + Name string `json:"name,omitempty"` + TMSessionPolicyAAAGroupBinding []any `json:"tmsessionpolicy_aaagroup_binding,omitempty"` + TMSessionPolicyAAAUserBinding []any `json:"tmsessionpolicy_aaauser_binding,omitempty"` + TMSessionPolicyAuthenticationVServerBinding []any `json:"tmsessionpolicy_authenticationvserver_binding,omitempty"` + TMSessionPolicyTMGlobalBinding []any `json:"tmsessionpolicy_tmglobal_binding,omitempty"` +} + +type TMSessionPolicyAAAGroupBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type TMTrafficPolicyTMGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type TMGlobalTMSessionPolicyBinding struct { + BindPolicyType int `json:"bindpolicytype,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Feature string `json:"feature,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type TMGlobalAuditSyslogPolicyBinding struct { + BindPolicyType int `json:"bindpolicytype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type TMSAMLSSOProfile struct { + AssertionConsumerServiceURL string `json:"assertionconsumerserviceurl,omitempty"` + Attribute1 string `json:"attribute1,omitempty"` + Attribute10 string `json:"attribute10,omitempty"` + Attribute10Expr string `json:"attribute10expr,omitempty"` + Attribute10Format string `json:"attribute10format,omitempty"` + Attribute10FriendlyName string `json:"attribute10friendlyname,omitempty"` + Attribute11 string `json:"attribute11,omitempty"` + Attribute11Expr string `json:"attribute11expr,omitempty"` + Attribute11Format string `json:"attribute11format,omitempty"` + Attribute11FriendlyName string `json:"attribute11friendlyname,omitempty"` + Attribute12 string `json:"attribute12,omitempty"` + Attribute12Expr string `json:"attribute12expr,omitempty"` + Attribute12Format string `json:"attribute12format,omitempty"` + Attribute12FriendlyName string `json:"attribute12friendlyname,omitempty"` + Attribute13 string `json:"attribute13,omitempty"` + Attribute13Expr string `json:"attribute13expr,omitempty"` + Attribute13Format string `json:"attribute13format,omitempty"` + Attribute13FriendlyName string `json:"attribute13friendlyname,omitempty"` + Attribute14 string `json:"attribute14,omitempty"` + Attribute14Expr string `json:"attribute14expr,omitempty"` + Attribute14Format string `json:"attribute14format,omitempty"` + Attribute14FriendlyName string `json:"attribute14friendlyname,omitempty"` + Attribute15 string `json:"attribute15,omitempty"` + Attribute15Expr string `json:"attribute15expr,omitempty"` + Attribute15Format string `json:"attribute15format,omitempty"` + Attribute15FriendlyName string `json:"attribute15friendlyname,omitempty"` + Attribute16 string `json:"attribute16,omitempty"` + Attribute16Expr string `json:"attribute16expr,omitempty"` + Attribute16Format string `json:"attribute16format,omitempty"` + Attribute16FriendlyName string `json:"attribute16friendlyname,omitempty"` + Attribute1Expr string `json:"attribute1expr,omitempty"` + Attribute1Format string `json:"attribute1format,omitempty"` + Attribute1FriendlyName string `json:"attribute1friendlyname,omitempty"` + Attribute2 string `json:"attribute2,omitempty"` + Attribute2Expr string `json:"attribute2expr,omitempty"` + Attribute2Format string `json:"attribute2format,omitempty"` + Attribute2FriendlyName string `json:"attribute2friendlyname,omitempty"` + Attribute3 string `json:"attribute3,omitempty"` + Attribute3Expr string `json:"attribute3expr,omitempty"` + Attribute3Format string `json:"attribute3format,omitempty"` + Attribute3FriendlyName string `json:"attribute3friendlyname,omitempty"` + Attribute4 string `json:"attribute4,omitempty"` + Attribute4Expr string `json:"attribute4expr,omitempty"` + Attribute4Format string `json:"attribute4format,omitempty"` + Attribute4FriendlyName string `json:"attribute4friendlyname,omitempty"` + Attribute5 string `json:"attribute5,omitempty"` + Attribute5Expr string `json:"attribute5expr,omitempty"` + Attribute5Format string `json:"attribute5format,omitempty"` + Attribute5FriendlyName string `json:"attribute5friendlyname,omitempty"` + Attribute6 string `json:"attribute6,omitempty"` + Attribute6Expr string `json:"attribute6expr,omitempty"` + Attribute6Format string `json:"attribute6format,omitempty"` + Attribute6FriendlyName string `json:"attribute6friendlyname,omitempty"` + Attribute7 string `json:"attribute7,omitempty"` + Attribute7Expr string `json:"attribute7expr,omitempty"` + Attribute7Format string `json:"attribute7format,omitempty"` + Attribute7FriendlyName string `json:"attribute7friendlyname,omitempty"` + Attribute8 string `json:"attribute8,omitempty"` + Attribute8Expr string `json:"attribute8expr,omitempty"` + Attribute8Format string `json:"attribute8format,omitempty"` + Attribute8FriendlyName string `json:"attribute8friendlyname,omitempty"` + Attribute9 string `json:"attribute9,omitempty"` + Attribute9Expr string `json:"attribute9expr,omitempty"` + Attribute9Format string `json:"attribute9format,omitempty"` + Attribute9FriendlyName string `json:"attribute9friendlyname,omitempty"` + Audience string `json:"audience,omitempty"` + Count float64 `json:"__count,omitempty"` + DigestMethod string `json:"digestmethod,omitempty"` + EncryptAssertion string `json:"encryptassertion,omitempty"` + EncryptionAlgorithm string `json:"encryptionalgorithm,omitempty"` + Name string `json:"name,omitempty"` + NameIDExpr string `json:"nameidexpr,omitempty"` + NameIDFormat string `json:"nameidformat,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + RelayStateRule string `json:"relaystaterule,omitempty"` + SAMLIssuerName string `json:"samlissuername,omitempty"` + SAMLSigningCertName string `json:"samlsigningcertname,omitempty"` + SAMLSPCertName string `json:"samlspcertname,omitempty"` + SendPassword string `json:"sendpassword,omitempty"` + SignAssertion string `json:"signassertion,omitempty"` + SignatureAlg string `json:"signaturealg,omitempty"` + SkewTime int `json:"skewtime,omitempty"` +} + +type TMSessionAction struct { + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + DefaultAuthorizationAction string `json:"defaultauthorizationaction,omitempty"` + Feature string `json:"feature,omitempty"` + Homepage string `json:"homepage,omitempty"` + HTTPOnlyCookie string `json:"httponlycookie,omitempty"` + KCDAccount string `json:"kcdaccount,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PersistentCookie string `json:"persistentcookie,omitempty"` + PersistentCookieValidity int `json:"persistentcookievalidity,omitempty"` + SessTimeout int `json:"sesstimeout,omitempty"` + SSO string `json:"sso,omitempty"` + SSOCredential string `json:"ssocredential,omitempty"` + SSODomain string `json:"ssodomain,omitempty"` +} + +type TMSessionPolicyAuthenticationVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type TMSessionPolicyAAAUserBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} diff --git a/nitrogo/models/transform.go b/nitrogo/models/transform.go new file mode 100644 index 0000000..f1ebcaa --- /dev/null +++ b/nitrogo/models/transform.go @@ -0,0 +1,175 @@ +package models + +// transform configuration structs +type TransformPolicyCSVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type TransformProfileBinding struct { + Name string `json:"name,omitempty"` + TransformProfileTransformActionBinding []any `json:"transformprofile_transformaction_binding,omitempty"` +} + +type TransformPolicyBinding struct { + Name string `json:"name,omitempty"` + TransformPolicyCSVServerBinding []any `json:"transformpolicy_csvserver_binding,omitempty"` + TransformPolicyLBVServerBinding []any `json:"transformpolicy_lbvserver_binding,omitempty"` + TransformPolicyTransformGlobalBinding []any `json:"transformpolicy_transformglobal_binding,omitempty"` + TransformPolicyTransformPolicyLabelBinding []any `json:"transformpolicy_transformpolicylabel_binding,omitempty"` +} + +type TransformPolicyLabel struct { + Count float64 `json:"__count,omitempty"` + Description string `json:"description,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Hits int `json:"hits,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyLabelType string `json:"policylabeltype,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type TransformPolicyTransformPolicyLabelBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type TransformPolicyLabelTransformPolicyBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type TransformPolicy struct { + Builtin []string `json:"builtin,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + IsDefault bool `json:"isdefault,omitempty"` + LogAction string `json:"logaction,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ProfileName string `json:"profilename,omitempty"` + Rule string `json:"rule,omitempty"` +} + +type TransformProfile struct { + AdditionalReqHeadersList string `json:"additionalreqheaderslist,omitempty"` + AdditionalRespHeadersList string `json:"additionalrespheaderslist,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + OnlyTransformAbsURLInBody string `json:"onlytransformabsurlinbody,omitempty"` + RegexForFindingURLInCSS string `json:"regexforfindingurlincss,omitempty"` + RegexForFindingURLInJavascript string `json:"regexforfindingurlinjavascript,omitempty"` + RegexForFindingURLInXComponent string `json:"regexforfindingurlinxcomponent,omitempty"` + RegexForFindingURLInXML string `json:"regexforfindingurlinxml,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type TransformGlobalTransformPolicyBinding struct { + FlowType int `json:"flowtype,omitempty"` + GlobalBindType string `json:"globalbindtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type TransformPolicyLBVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type TransformAction struct { + Comment string `json:"comment,omitempty"` + ContinueMatching string `json:"continuematching,omitempty"` + CookieDomainFrom string `json:"cookiedomainfrom,omitempty"` + CookieDomainInto string `json:"cookiedomaininto,omitempty"` + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Priority int `json:"priority,omitempty"` + ProfileName string `json:"profilename,omitempty"` + ReqURLFrom string `json:"requrlfrom,omitempty"` + ReqURLInto string `json:"requrlinto,omitempty"` + ResURLFrom string `json:"resurlfrom,omitempty"` + ResURLInto string `json:"resurlinto,omitempty"` + State string `json:"state,omitempty"` +} + +type TransformPolicyLabelBinding struct { + LabelName string `json:"labelname,omitempty"` + TransformPolicyLabelPolicyBindingBinding []any `json:"transformpolicylabel_policybinding_binding,omitempty"` + TransformPolicyLabelTransformPolicyBinding []any `json:"transformpolicylabel_transformpolicy_binding,omitempty"` +} + +type TransformGlobalBinding struct { + TransformGlobalTransformPolicyBinding []any `json:"transformglobal_transformpolicy_binding,omitempty"` +} + +type TransformProfileTransformActionBinding struct { + ActionComment string `json:"actioncomment,omitempty"` + ActionName string `json:"actionname,omitempty"` + CookieDomainFrom string `json:"cookiedomainfrom,omitempty"` + CookieDomainInto string `json:"cookiedomaininto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` + ProfileName string `json:"profilename,omitempty"` + ReqURLFrom string `json:"requrlfrom,omitempty"` + ReqURLInto string `json:"requrlinto,omitempty"` + ResURLFrom string `json:"resurlfrom,omitempty"` + ResURLInto string `json:"resurlinto,omitempty"` + State string `json:"state,omitempty"` +} + +type TransformPolicyLabelPolicyBindingBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type TransformPolicyTransformGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} diff --git a/nitrogo/models/tunnel.go b/nitrogo/models/tunnel.go new file mode 100644 index 0000000..d38ed84 --- /dev/null +++ b/nitrogo/models/tunnel.go @@ -0,0 +1,55 @@ +package models + +// tunnel configuration structs +type TunnelTrafficPolicy struct { + Action string `json:"action,omitempty"` + Builtin []string `json:"builtin,omitempty"` + ClientTransactions int `json:"clienttransactions,omitempty"` + ClientTTLB int `json:"clientttlb,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + ExpressionType string `json:"expressiontype,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + IsDefault bool `json:"isdefault,omitempty"` + LogAction string `json:"logaction,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule string `json:"rule,omitempty"` + RxBytes int `json:"rxbytes,omitempty"` + ServerTransactions int `json:"servertransactions,omitempty"` + ServerTTLB int `json:"serverttlb,omitempty"` + TxBytes int `json:"txbytes,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type TunnelGlobalBinding struct { + TunnelGlobalTunnelTrafficPolicyBinding []any `json:"tunnelglobal_tunneltrafficpolicy_binding,omitempty"` +} + +type TunnelTrafficPolicyBinding struct { + Name string `json:"name,omitempty"` + TunnelTrafficPolicyTunnelGlobalBinding []any `json:"tunneltrafficpolicy_tunnelglobal_binding,omitempty"` +} + +type TunnelTrafficPolicyTunnelGlobalBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type TunnelGlobalTunnelTrafficPolicyBinding struct { + Builtin []string `json:"builtin,omitempty"` + Feature string `json:"feature,omitempty"` + GlobalBindType string `json:"globalbindtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyName string `json:"policyname,omitempty"` + PolicyType string `json:"policytype,omitempty"` + Priority int `json:"priority,omitempty"` + State string `json:"state,omitempty"` + TypeField string `json:"type,omitempty"` +} diff --git a/nitrogo/models/ulfd.go b/nitrogo/models/ulfd.go new file mode 100644 index 0000000..1bc1cc5 --- /dev/null +++ b/nitrogo/models/ulfd.go @@ -0,0 +1,9 @@ +package models + +// ulfd configuration structs +type ULFDServer struct { + Count float64 `json:"__count,omitempty"` + LoggerIP string `json:"loggerip,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + State string `json:"state,omitempty"` +} diff --git a/nitrogo/models/urlfiltering.go b/nitrogo/models/urlfiltering.go new file mode 100644 index 0000000..784c68b --- /dev/null +++ b/nitrogo/models/urlfiltering.go @@ -0,0 +1,36 @@ +// Derived from Citrix ADC Nitro Go SDK (https://github.com/netscaler/adc-nitro-go) +// Originally licensed under the Apache License, Version 2.0 +// Modifications by Adam Crawford, 2026 + +package models + +type URLFilteringParameter struct { + HoursBetweenDBUpdates int `json:"hoursbetweendbupdates,omitempty"` + TimeOfDayToUpdateDB string `json:"timeofdaytoupdatedb,omitempty"` + LocalDatabaseThreads int `json:"localdatabasethreads,omitempty"` + CloudHost string `json:"cloudhost,omitempty"` + SeedDBPath string `json:"seeddbpath,omitempty"` + MaxNumberOfCloudThreads string `json:"maxnumberofcloudthreads,omitempty"` + CloudKeepAliveTimeout string `json:"cloudkeepalivetimeout,omitempty"` + CloudServerConnectTimeout string `json:"cloudserverconnecttimeout,omitempty"` + CloudDBLookupTimeout string `json:"clouddblookuptimeout,omitempty"` + ProxyHostIP string `json:"proxyhostip,omitempty"` + ProxyPort string `json:"proxyport,omitempty"` + ProxyUsername string `json:"proxyusername,omitempty"` + ProxyPassword string `json:"proxypassword,omitempty"` + SeedDBSizeLevel string `json:"seeddbsizelevel,omitempty"` +} + +type URLFilteringCategories struct { + Group string `json:"group,omitempty"` + Categories string `json:"categories,omitempty"` +} + +type URLFilteringCategorization struct { + URL string `json:"url,omitempty"` + Categorization string `json:"categorization,omitempty"` +} + +type URLFilteringCategoryGroups struct { + CategoryGroups string `json:"categorygroups,omitempty"` +} diff --git a/nitrogo/models/user.go b/nitrogo/models/user.go new file mode 100644 index 0000000..71b7170 --- /dev/null +++ b/nitrogo/models/user.go @@ -0,0 +1,30 @@ +package models + +// user configuration structs +type UserVServer struct { + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + CurState string `json:"curstate,omitempty"` + DefaultLB string `json:"defaultlb,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NoDefaultBindings string `json:"nodefaultbindings,omitempty"` + Params string `json:"Params,omitempty"` + Port int `json:"port,omitempty"` + State string `json:"state,omitempty"` + StateChangeTimeMsec int `json:"statechangetimemsec,omitempty"` + StateChangeTimeSec string `json:"statechangetimesec,omitempty"` + TicksSinceLastStateChange int `json:"tickssincelaststatechange,omitempty"` + UserProtocol string `json:"userprotocol,omitempty"` + Value string `json:"value,omitempty"` +} + +type UserProtocol struct { + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Extension string `json:"extension,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Transport string `json:"transport,omitempty"` +} diff --git a/nitrogo/models/utility.go b/nitrogo/models/utility.go new file mode 100644 index 0000000..89924e4 --- /dev/null +++ b/nitrogo/models/utility.go @@ -0,0 +1,139 @@ +package models + +// utility configuration structs +type Raid struct { + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type Install struct { + A bool `json:"a,omitempty"` + Async bool `json:"Async,omitempty"` + EnhancedUpgrade bool `json:"enhancedupgrade,omitempty"` + ID int `json:"id,omitempty"` + L bool `json:"l,omitempty"` + ResizeSwapVar bool `json:"resizeswapvar,omitempty"` + URL string `json:"url,omitempty"` + Y bool `json:"y,omitempty"` +} + +type Traceroute6 struct { + Host string `json:"host,omitempty"` + I bool `json:"I,omitempty"` + M int `json:"m,omitempty"` + N bool `json:"n,omitempty"` + P int `json:"p,omitempty"` + PacketLen int `json:"packetlen,omitempty"` + Q int `json:"q,omitempty"` + R bool `json:"r,omitempty"` + Response string `json:"response,omitempty"` + S string `json:"s,omitempty"` + T int `json:"T,omitempty"` + V bool `json:"v,omitempty"` + W int `json:"w,omitempty"` +} + +type Ping struct { + C int `json:"c,omitempty"` + HostName string `json:"hostName,omitempty"` + I string `json:"I,omitempty"` + I1 int `json:"i,omitempty"` + N bool `json:"n,omitempty"` + P string `json:"p,omitempty"` + Q bool `json:"q,omitempty"` + Response string `json:"response,omitempty"` + S string `json:"S,omitempty"` + S1 int `json:"s,omitempty"` + T int `json:"T,omitempty"` + T1 int `json:"t,omitempty"` +} + +type TechSupport struct { + ADSS bool `json:"adss,omitempty"` + AuthToken string `json:"authtoken,omitempty"` + CaseNumber string `json:"casenumber,omitempty"` + Description string `json:"description,omitempty"` + File string `json:"file,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Nodes []any `json:"nodes,omitempty"` + PartitionName string `json:"partitionname,omitempty"` + Proxy string `json:"proxy,omitempty"` + Response string `json:"response,omitempty"` + Scope string `json:"scope,omitempty"` + ServerName string `json:"servername,omitempty"` + Time string `json:"time,omitempty"` + Upload bool `json:"upload,omitempty"` +} + +type Traceroute struct { + Host string `json:"host,omitempty"` + M int `json:"M,omitempty"` + M1 int `json:"m,omitempty"` + N bool `json:"n,omitempty"` + P string `json:"P,omitempty"` + P1 int `json:"p,omitempty"` + PacketLen int `json:"packetlen,omitempty"` + Q int `json:"q,omitempty"` + R bool `json:"r,omitempty"` + Response string `json:"response,omitempty"` + S bool `json:"S,omitempty"` + S1 string `json:"s,omitempty"` + T int `json:"T,omitempty"` + T1 int `json:"t,omitempty"` + V bool `json:"v,omitempty"` + W int `json:"w,omitempty"` +} + +type CallHome struct { + AnomalyDetection string `json:"anomalydetection,omitempty"` + CallHomeStatus []string `json:"callhomestatus,omitempty"` + EmailAddress string `json:"emailaddress,omitempty"` + FlashFirstFail string `json:"flashfirstfail,omitempty"` + FlashLatestFailure string `json:"flashlatestfailure,omitempty"` + HBCustomInterval int `json:"hbcustominterval,omitempty"` + HDDFirstFail string `json:"hddfirstfail,omitempty"` + HDDLatestFailure string `json:"hddlatestfailure,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + MemThreFirstAnomaly string `json:"memthrefirstanomaly,omitempty"` + MemThreLatestAnomaly string `json:"memthrelatestanomaly,omitempty"` + Mode string `json:"mode,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + Port int `json:"port,omitempty"` + PowFirstFail string `json:"powfirstfail,omitempty"` + PowLatestFailure string `json:"powlatestfailure,omitempty"` + ProxyAuthService string `json:"proxyauthservice,omitempty"` + ProxyMode string `json:"proxymode,omitempty"` + RestartLatestFail string `json:"restartlatestfail,omitempty"` + RLFirstHighDrop string `json:"rlfirsthighdrop,omitempty"` + RLLatestHighDrop string `json:"rllatesthighdrop,omitempty"` + SSLCardFirstFailure string `json:"sslcardfirstfailure,omitempty"` + SSLCardLatestFailure string `json:"sslcardlatestfailure,omitempty"` +} + +type FileSystemEncryption struct { + EffectiveState string `json:"effectivestate,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + NTimes0Flash int `json:"ntimes0flash,omitempty"` + NTimes0Var int `json:"ntimes0var,omitempty"` + Passphrase string `json:"passphrase,omitempty"` + SupportedState string `json:"supportedstate,omitempty"` +} + +type Ping6 struct { + B int `json:"b,omitempty"` + C int `json:"c,omitempty"` + HostName string `json:"hostName,omitempty"` + I string `json:"I,omitempty"` + I1 int `json:"i,omitempty"` + M bool `json:"m,omitempty"` + N bool `json:"n,omitempty"` + P string `json:"p,omitempty"` + Q bool `json:"q,omitempty"` + Response string `json:"response,omitempty"` + S string `json:"S,omitempty"` + S1 int `json:"s,omitempty"` + T int `json:"T,omitempty"` + T1 int `json:"t,omitempty"` + V int `json:"V,omitempty"` +} diff --git a/nitrogo/models/videooptimization.go b/nitrogo/models/videooptimization.go new file mode 100644 index 0000000..8fddd9a --- /dev/null +++ b/nitrogo/models/videooptimization.go @@ -0,0 +1,234 @@ +package models + +// videooptimization configuration structs +type VideoOptimizationGlobalPacingBinding struct { + VideoOptimizationGlobalPacingVideoOptimizationPacingPolicyBinding []any `json:"videooptimizationglobalpacing_videooptimizationpacingpolicy_binding,omitempty"` +} + +type VideoOptimizationParameter struct { + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + QUICPacingRate int `json:"quicpacingrate,omitempty"` + RandomSamplingPercentage float64 `json:"randomsamplingpercentage,omitempty"` +} + +type VideoOptimizationPacingPolicyLabelBinding struct { + LabelName string `json:"labelname,omitempty"` + VideoOptimizationPacingPolicyLabelPolicyBindingBinding []any `json:"videooptimizationpacingpolicylabel_policybinding_binding,omitempty"` + VideoOptimizationPacingPolicyLabelVideoOptimizationPacingPolicyBinding []any `json:"videooptimizationpacingpolicylabel_videooptimizationpacingpolicy_binding,omitempty"` +} + +type VideoOptimizationPacingAction struct { + Builtin []string `json:"builtin,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rate int `json:"rate,omitempty"` + ReferenceCount int `json:"referencecount,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type VideoOptimizationDetectionPolicyLabel struct { + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Hits int `json:"hits,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyLabelType string `json:"policylabeltype,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type VideoOptimizationGlobalDetectionVideoOptimizationDetectionPolicyBinding struct { + GlobalBindType string `json:"globalbindtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type VideoOptimizationDetectionPolicyLBVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type VideoOptimizationPacingPolicyLBVServerBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type VideoOptimizationPacingPolicy struct { + Action string `json:"action,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + LogAction string `json:"logaction,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule string `json:"rule,omitempty"` + UndefAction string `json:"undefaction,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type VideoOptimizationDetectionPolicyLabelPolicyBindingBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type VideoOptimizationDetectionPolicyBinding struct { + Name string `json:"name,omitempty"` + VideoOptimizationDetectionPolicyLBVServerBinding []any `json:"videooptimizationdetectionpolicy_lbvserver_binding,omitempty"` + VideoOptimizationDetectionPolicyVideoOptimizationGlobalDetectionBinding []any `json:"videooptimizationdetectionpolicy_videooptimizationglobaldetection_binding,omitempty"` +} + +type VideoOptimizationGlobalPacingVideoOptimizationPacingPolicyBinding struct { + GlobalBindType string `json:"globalbindtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type VideoOptimizationPacingPolicyBinding struct { + Name string `json:"name,omitempty"` + VideoOptimizationPacingPolicyLBVServerBinding []any `json:"videooptimizationpacingpolicy_lbvserver_binding,omitempty"` + VideoOptimizationPacingPolicyVideoOptimizationGlobalPacingBinding []any `json:"videooptimizationpacingpolicy_videooptimizationglobalpacing_binding,omitempty"` +} + +type VideoOptimizationDetectionPolicyLabelBinding struct { + LabelName string `json:"labelname,omitempty"` + VideoOptimizationDetectionPolicyLabelPolicyBindingBinding []any `json:"videooptimizationdetectionpolicylabel_policybinding_binding,omitempty"` + VideoOptimizationDetectionPolicyLabelVideoOptimizationDetectionPolicyBinding []any `json:"videooptimizationdetectionpolicylabel_videooptimizationdetectionpolicy_binding,omitempty"` +} + +type VideoOptimizationGlobalDetectionBinding struct { + VideoOptimizationGlobalDetectionVideoOptimizationDetectionPolicyBinding []any `json:"videooptimizationglobaldetection_videooptimizationdetectionpolicy_binding,omitempty"` +} + +type VideoOptimizationPacingPolicyLabelPolicyBindingBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type VideoOptimizationDetectionPolicyLabelVideoOptimizationDetectionPolicyBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type VideoOptimizationDetectionAction struct { + Builtin []string `json:"builtin,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ReferenceCount int `json:"referencecount,omitempty"` + TypeField string `json:"type,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type VideoOptimizationPacingPolicyVideoOptimizationGlobalPacingBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type VideoOptimizationPacingPolicyLabelVideoOptimizationPacingPolicyBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Invoke bool `json:"invoke,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type VideoOptimizationDetectionPolicy struct { + Action string `json:"action,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + LogAction string `json:"logaction,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule string `json:"rule,omitempty"` + UndefAction string `json:"undefaction,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type VideoOptimizationPacingPolicyLabel struct { + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + Hits int `json:"hits,omitempty"` + InvokeLabelName string `json:"invoke_labelname,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NumPol int `json:"numpol,omitempty"` + PolicyLabelType string `json:"policylabeltype,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type VideoOptimizationDetectionPolicyVideoOptimizationGlobalDetectionBinding struct { + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + LabelName string `json:"labelname,omitempty"` + LabelType string `json:"labeltype,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} diff --git a/nitrogo/models/vpn.go b/nitrogo/models/vpn.go new file mode 100644 index 0000000..67f1ad2 --- /dev/null +++ b/nitrogo/models/vpn.go @@ -0,0 +1,1520 @@ +package models + +// vpn configuration structs +type VPNClientlessAccessPolicyVPNVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type VPNGlobalAuditNSLogPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNICADTLSConnection struct { + ChannelNumber int `json:"channelnumber,omitempty"` + Count float64 `json:"__count,omitempty"` + DestIP string `json:"destip,omitempty"` + DestPort int `json:"destport,omitempty"` + Domain string `json:"domain,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + PeID int `json:"peid,omitempty"` + SrcIP string `json:"srcip,omitempty"` + SrcPort int `json:"srcport,omitempty"` + Username string `json:"username,omitempty"` +} + +type VPNStoreInfo struct { + Count float64 `json:"__count,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + StoreAPISupport string `json:"storeapisupport,omitempty"` + StoreList string `json:"storelist,omitempty"` + StoreServerIsSF string `json:"storeserverissf,omitempty"` + StoreServerStatus string `json:"storeserverstatus,omitempty"` + StoreStatus string `json:"storestatus,omitempty"` + URL string `json:"url,omitempty"` +} + +type VPNGlobalIntranetIPBinding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + IntranetIP string `json:"intranetip,omitempty"` + Netmask string `json:"netmask,omitempty"` +} + +type VPNURLPolicyVPNVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type VPNURLPolicyAAAUserBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type VPNEULA struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type VPNSessionPolicyVPNVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type VPNSessionPolicyBinding struct { + Name string `json:"name,omitempty"` + VPNSessionPolicyAAAGroupBinding []any `json:"vpnsessionpolicy_aaagroup_binding,omitempty"` + VPNSessionPolicyAAAUserBinding []any `json:"vpnsessionpolicy_aaauser_binding,omitempty"` + VPNSessionPolicyVPNGlobalBinding []any `json:"vpnsessionpolicy_vpnglobal_binding,omitempty"` + VPNSessionPolicyVPNVServerBinding []any `json:"vpnsessionpolicy_vpnvserver_binding,omitempty"` +} + +type VPNVServerCSPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNVServerAuditSyslogPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNGlobalVPNClientlessAccessPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Feature string `json:"feature,omitempty"` + GlobalBindType string `json:"globalbindtype,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` + TypeField string `json:"type,omitempty"` +} + +type VPNGlobalSecurePrivateAccessURLBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + SecurePrivateAccessURL string `json:"secureprivateaccessurl,omitempty"` +} + +type VPNVServerAppControllerBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + AppController string `json:"appcontroller,omitempty"` + Name string `json:"name,omitempty"` +} + +type VPNGlobalVPNSecurePrivateAccessProfileBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + SecurePrivateAccessProfile string `json:"secureprivateaccessprofile,omitempty"` +} + +type VPNURLPolicyAAAGroupBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type VPNGlobalAuthenticationCertPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNVServerAnalyticsProfileBinding struct { + Count float64 `json:"__count,omitempty"` + AnalyticsProfile string `json:"analyticsprofile,omitempty"` + Name string `json:"name,omitempty"` +} + +type VPNIntranetApplication struct { + ClientApplication []string `json:"clientapplication,omitempty"` + Count float64 `json:"__count,omitempty"` + DestIP string `json:"destip,omitempty"` + DestPort string `json:"destport,omitempty"` + Hostname string `json:"hostname,omitempty"` + Interception string `json:"interception,omitempty"` + IntranetApplication string `json:"intranetapplication,omitempty"` + IPAddress string `json:"ipaddress,omitempty"` + IPRange string `json:"iprange,omitempty"` + Netmask string `json:"netmask,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Protocol string `json:"protocol,omitempty"` + SpoofIIP string `json:"spoofiip,omitempty"` + SrcIP string `json:"srcip,omitempty"` + SrcPort int `json:"srcport,omitempty"` +} + +type VPNGlobalVPNTrafficPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNURLAction struct { + ActualURL string `json:"actualurl,omitempty"` + ApplicationType string `json:"applicationtype,omitempty"` + ClientlessAccess string `json:"clientlessaccess,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + IconURL string `json:"iconurl,omitempty"` + LinkName string `json:"linkname,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + SAMLSSOProfile string `json:"samlssoprofile,omitempty"` + SSOType string `json:"ssotype,omitempty"` + VServerName string `json:"vservername,omitempty"` +} + +type VPNPCoIPConnection struct { + All bool `json:"all,omitempty"` + Count float64 `json:"__count,omitempty"` + DestIP string `json:"destip,omitempty"` + DestPort int `json:"destport,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + PeID int `json:"peid,omitempty"` + SrcIP string `json:"srcip,omitempty"` + SrcPort int `json:"srcport,omitempty"` + Username string `json:"username,omitempty"` +} + +type VPNVServerVPNEULABinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + EULA string `json:"eula,omitempty"` + Name string `json:"name,omitempty"` +} + +type VPNVServerAuthenticationNegotiatePolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNSFConfig struct { + Count float64 `json:"__count,omitempty"` + Filename string `json:"filename,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Vserver []string `json:"vserver,omitempty"` +} + +type VPNPortalTheme struct { + BaseTheme string `json:"basetheme,omitempty"` + Count float64 `json:"__count,omitempty"` + Feature string `json:"feature,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type VPNTrafficPolicyVPNVServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type VPNGlobalAuthenticationLDAPPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNGlobalVPNEULABinding struct { + Count float64 `json:"__count,omitempty"` + EULA string `json:"eula,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` +} + +type VPNParameter struct { + AccessRestrictedPageRedirect string `json:"accessrestrictedpageredirect,omitempty"` + AdvancedClientlessVPNMode string `json:"advancedclientlessvpnmode,omitempty"` + AllowedLoginGroups string `json:"allowedlogingroups,omitempty"` + AllProtocolProxy string `json:"allprotocolproxy,omitempty"` + AlwaysOnProfileName string `json:"alwaysonprofilename,omitempty"` + AppTokenTimeout int `json:"apptokentimeout,omitempty"` + AuthorizationGroup string `json:"authorizationgroup,omitempty"` + AutoProxyURL string `json:"autoproxyurl,omitempty"` + BackendCertValidation string `json:"backendcertvalidation,omitempty"` + BackendDTLS12 string `json:"backenddtls12,omitempty"` + BackendServerSNI string `json:"backendserversni,omitempty"` + CitrixReceiverHome string `json:"citrixreceiverhome,omitempty"` + ClientChoices string `json:"clientchoices,omitempty"` + ClientCleanupPrompt string `json:"clientcleanupprompt,omitempty"` + ClientConfiguration []string `json:"clientconfiguration,omitempty"` + ClientDebug string `json:"clientdebug,omitempty"` + ClientIDleTimeout int `json:"clientidletimeout,omitempty"` + ClientIDleTimeoutWarning int `json:"clientidletimeoutwarning,omitempty"` + ClientlessModeURLEncoding string `json:"clientlessmodeurlencoding,omitempty"` + ClientlessPersistentCookie string `json:"clientlesspersistentcookie,omitempty"` + ClientlessVPNMode string `json:"clientlessvpnmode,omitempty"` + ClientOptions []string `json:"clientoptions,omitempty"` + ClientSecurity string `json:"clientsecurity,omitempty"` + ClientSecurityGroup string `json:"clientsecuritygroup,omitempty"` + ClientSecurityLog string `json:"clientsecuritylog,omitempty"` + ClientSecurityMessage string `json:"clientsecuritymessage,omitempty"` + ClientVersions string `json:"clientversions,omitempty"` + DefaultAuthorizationAction string `json:"defaultauthorizationaction,omitempty"` + DevicePosture string `json:"deviceposture,omitempty"` + DNSVServerName string `json:"dnsvservername,omitempty"` + EmailHome string `json:"emailhome,omitempty"` + EncryptCSECExp string `json:"encryptcsecexp,omitempty"` + EPAClientType string `json:"epaclienttype,omitempty"` + ForceCleanup []string `json:"forcecleanup,omitempty"` + ForcedTimeout int `json:"forcedtimeout,omitempty"` + ForcedTimeoutWarning int `json:"forcedtimeoutwarning,omitempty"` + FQDNSpoofedIP string `json:"fqdnspoofedip,omitempty"` + FTPProxy string `json:"ftpproxy,omitempty"` + GopherProxy string `json:"gopherproxy,omitempty"` + HomePage string `json:"homepage,omitempty"` + HTTPPort []any `json:"httpport,omitempty"` + HTTPProxy string `json:"httpproxy,omitempty"` + HTTPTrackConnProxy string `json:"httptrackconnproxy,omitempty"` + ICAProxy string `json:"icaproxy,omitempty"` + ICASessionTimeout string `json:"icasessiontimeout,omitempty"` + ICAUserAccounting string `json:"icauseraccounting,omitempty"` + IconWithReceiver string `json:"iconwithreceiver,omitempty"` + IIPDNSSuffix string `json:"iipdnssuffix,omitempty"` + KCDAccount string `json:"kcdaccount,omitempty"` + KillConnections string `json:"killconnections,omitempty"` + LinuxPluginUpgrade string `json:"linuxpluginupgrade,omitempty"` + LocalLANAccess string `json:"locallanaccess,omitempty"` + LoginScript string `json:"loginscript,omitempty"` + LogoutScript string `json:"logoutscript,omitempty"` + MacPluginUpgrade string `json:"macpluginupgrade,omitempty"` + MaxIIPPerUser int `json:"maxiipperuser,omitempty"` + MDXTokenTimeout int `json:"mdxtokentimeout,omitempty"` + Name string `json:"name,omitempty"` + Netmask string `json:"netmask,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NTDomain string `json:"ntdomain,omitempty"` + PCoIPProfileName string `json:"pcoipprofilename,omitempty"` + Proxy string `json:"proxy,omitempty"` + ProxyException string `json:"proxyexception,omitempty"` + ProxyLocalBypass string `json:"proxylocalbypass,omitempty"` + RDPClientProfileName string `json:"rdpclientprofilename,omitempty"` + RFC1918 string `json:"rfc1918,omitempty"` + SameSite string `json:"samesite,omitempty"` + SecureBrowse string `json:"securebrowse,omitempty"` + SecurePrivateAccess string `json:"secureprivateaccess,omitempty"` + SecurePrivateAccessProfile string `json:"secureprivateaccessprofile,omitempty"` + SessTimeout int `json:"sesstimeout,omitempty"` + SmartGroup string `json:"smartgroup,omitempty"` + SocksProxy string `json:"socksproxy,omitempty"` + SplitDNS string `json:"splitdns,omitempty"` + SplitTunnel string `json:"splittunnel,omitempty"` + SpoofIIP string `json:"spoofiip,omitempty"` + SSLProxy string `json:"sslproxy,omitempty"` + SSO string `json:"sso,omitempty"` + SSOCredential string `json:"ssocredential,omitempty"` + StoreFrontURL string `json:"storefronturl,omitempty"` + TransparentInterception string `json:"transparentinterception,omitempty"` + UITheme string `json:"uitheme,omitempty"` + UseIIP string `json:"useiip,omitempty"` + UseMIP string `json:"usemip,omitempty"` + UserDomains string `json:"userdomains,omitempty"` + VPNSessionPolicyBindType string `json:"vpnsessionpolicybindtype,omitempty"` + VPNSessionPolicyCount int `json:"vpnsessionpolicycount,omitempty"` + WIHome string `json:"wihome,omitempty"` + WIHomeAddressType string `json:"wihomeaddresstype,omitempty"` + WindowsAutoLogon string `json:"windowsautologon,omitempty"` + WindowsClientType string `json:"windowsclienttype,omitempty"` + WindowsPluginUpgrade string `json:"windowspluginupgrade,omitempty"` + Winsip string `json:"winsip,omitempty"` + WIPortalMode string `json:"wiportalmode,omitempty"` +} + +type VPNClientlessAccessProfile struct { + Builtin []string `json:"builtin,omitempty"` + ClientConsumedCookies string `json:"clientconsumedcookies,omitempty"` + Count float64 `json:"__count,omitempty"` + CSSRewritePolicyLabel string `json:"cssrewritepolicylabel,omitempty"` + Description string `json:"description,omitempty"` + Feature string `json:"feature,omitempty"` + IsDefault bool `json:"isdefault,omitempty"` + JavascriptRewritePolicyLabel string `json:"javascriptrewritepolicylabel,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ProfileName string `json:"profilename,omitempty"` + RegexForFindingCustomURLs string `json:"regexforfindingcustomurls,omitempty"` + RegexForFindingURLInCSS string `json:"regexforfindingurlincss,omitempty"` + RegexForFindingURLInJavascript string `json:"regexforfindingurlinjavascript,omitempty"` + RegexForFindingURLInXComponent string `json:"regexforfindingurlinxcomponent,omitempty"` + RegexForFindingURLInXML string `json:"regexforfindingurlinxml,omitempty"` + ReqHdrRewritePolicyLabel string `json:"reqhdrrewritepolicylabel,omitempty"` + RequirePersistentCookie string `json:"requirepersistentcookie,omitempty"` + ResHdrRewritePolicyLabel string `json:"reshdrrewritepolicylabel,omitempty"` + URLRewritePolicyLabel string `json:"urlrewritepolicylabel,omitempty"` + XComponentRewritePolicyLabel string `json:"xcomponentrewritepolicylabel,omitempty"` + XMLRewritePolicyLabel string `json:"xmlrewritepolicylabel,omitempty"` +} + +type VPNSAMLSSOProfile struct { + AssertionConsumerServiceURL string `json:"assertionconsumerserviceurl,omitempty"` + Attribute1 string `json:"attribute1,omitempty"` + Attribute10 string `json:"attribute10,omitempty"` + Attribute10Expr string `json:"attribute10expr,omitempty"` + Attribute10Format string `json:"attribute10format,omitempty"` + Attribute10FriendlyName string `json:"attribute10friendlyname,omitempty"` + Attribute11 string `json:"attribute11,omitempty"` + Attribute11Expr string `json:"attribute11expr,omitempty"` + Attribute11Format string `json:"attribute11format,omitempty"` + Attribute11FriendlyName string `json:"attribute11friendlyname,omitempty"` + Attribute12 string `json:"attribute12,omitempty"` + Attribute12Expr string `json:"attribute12expr,omitempty"` + Attribute12Format string `json:"attribute12format,omitempty"` + Attribute12FriendlyName string `json:"attribute12friendlyname,omitempty"` + Attribute13 string `json:"attribute13,omitempty"` + Attribute13Expr string `json:"attribute13expr,omitempty"` + Attribute13Format string `json:"attribute13format,omitempty"` + Attribute13FriendlyName string `json:"attribute13friendlyname,omitempty"` + Attribute14 string `json:"attribute14,omitempty"` + Attribute14Expr string `json:"attribute14expr,omitempty"` + Attribute14Format string `json:"attribute14format,omitempty"` + Attribute14FriendlyName string `json:"attribute14friendlyname,omitempty"` + Attribute15 string `json:"attribute15,omitempty"` + Attribute15Expr string `json:"attribute15expr,omitempty"` + Attribute15Format string `json:"attribute15format,omitempty"` + Attribute15FriendlyName string `json:"attribute15friendlyname,omitempty"` + Attribute16 string `json:"attribute16,omitempty"` + Attribute16Expr string `json:"attribute16expr,omitempty"` + Attribute16Format string `json:"attribute16format,omitempty"` + Attribute16FriendlyName string `json:"attribute16friendlyname,omitempty"` + Attribute1Expr string `json:"attribute1expr,omitempty"` + Attribute1Format string `json:"attribute1format,omitempty"` + Attribute1FriendlyName string `json:"attribute1friendlyname,omitempty"` + Attribute2 string `json:"attribute2,omitempty"` + Attribute2Expr string `json:"attribute2expr,omitempty"` + Attribute2Format string `json:"attribute2format,omitempty"` + Attribute2FriendlyName string `json:"attribute2friendlyname,omitempty"` + Attribute3 string `json:"attribute3,omitempty"` + Attribute3Expr string `json:"attribute3expr,omitempty"` + Attribute3Format string `json:"attribute3format,omitempty"` + Attribute3FriendlyName string `json:"attribute3friendlyname,omitempty"` + Attribute4 string `json:"attribute4,omitempty"` + Attribute4Expr string `json:"attribute4expr,omitempty"` + Attribute4Format string `json:"attribute4format,omitempty"` + Attribute4FriendlyName string `json:"attribute4friendlyname,omitempty"` + Attribute5 string `json:"attribute5,omitempty"` + Attribute5Expr string `json:"attribute5expr,omitempty"` + Attribute5Format string `json:"attribute5format,omitempty"` + Attribute5FriendlyName string `json:"attribute5friendlyname,omitempty"` + Attribute6 string `json:"attribute6,omitempty"` + Attribute6Expr string `json:"attribute6expr,omitempty"` + Attribute6Format string `json:"attribute6format,omitempty"` + Attribute6FriendlyName string `json:"attribute6friendlyname,omitempty"` + Attribute7 string `json:"attribute7,omitempty"` + Attribute7Expr string `json:"attribute7expr,omitempty"` + Attribute7Format string `json:"attribute7format,omitempty"` + Attribute7FriendlyName string `json:"attribute7friendlyname,omitempty"` + Attribute8 string `json:"attribute8,omitempty"` + Attribute8Expr string `json:"attribute8expr,omitempty"` + Attribute8Format string `json:"attribute8format,omitempty"` + Attribute8FriendlyName string `json:"attribute8friendlyname,omitempty"` + Attribute9 string `json:"attribute9,omitempty"` + Attribute9Expr string `json:"attribute9expr,omitempty"` + Attribute9Format string `json:"attribute9format,omitempty"` + Attribute9FriendlyName string `json:"attribute9friendlyname,omitempty"` + Audience string `json:"audience,omitempty"` + Count float64 `json:"__count,omitempty"` + DigestMethod string `json:"digestmethod,omitempty"` + EncryptAssertion string `json:"encryptassertion,omitempty"` + EncryptionAlgorithm string `json:"encryptionalgorithm,omitempty"` + Name string `json:"name,omitempty"` + NameIDExpr string `json:"nameidexpr,omitempty"` + NameIDFormat string `json:"nameidformat,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + RelayStateRule string `json:"relaystaterule,omitempty"` + SAMLIssuerName string `json:"samlissuername,omitempty"` + SAMLSigningCertName string `json:"samlsigningcertname,omitempty"` + SAMLSPCertName string `json:"samlspcertname,omitempty"` + SendPassword string `json:"sendpassword,omitempty"` + SignAssertion string `json:"signassertion,omitempty"` + SignatureAlg string `json:"signaturealg,omitempty"` + SignatureService string `json:"signatureservice,omitempty"` + SkewTime int `json:"skewtime,omitempty"` +} + +type VPNVServerAuditNSLogPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNGlobalVPNSessionPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Feature string `json:"feature,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNPCoIPVServerProfile struct { + Count float64 `json:"__count,omitempty"` + LoginDomain string `json:"logindomain,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + UDPPort int `json:"udpport,omitempty"` +} + +type VPNSessionPolicyVPNGlobalBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type VPNVServerIntranetIP6Binding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + IntranetIP6 string `json:"intranetip6,omitempty"` + Name string `json:"name,omitempty"` + NumAddr int `json:"numaddr,omitempty"` +} + +type VPNVServerFEOPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNGlobalAuditSyslogPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNVServerVPNSessionPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNVServerVPNURLBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + Name string `json:"name,omitempty"` + URLName string `json:"urlname,omitempty"` +} + +type VPNVServerVPNURLPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNVServerAuthenticationWebAuthPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNClientlessAccessPolicy struct { + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + Description string `json:"description,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + IsDefault bool `json:"isdefault,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + ProfileName string `json:"profilename,omitempty"` + Rule string `json:"rule,omitempty"` + UndefAction string `json:"undefaction,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type VPNVServerAAAPreauthenticationPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNTrafficPolicyBinding struct { + Name string `json:"name,omitempty"` + VPNTrafficPolicyAAAGroupBinding []any `json:"vpntrafficpolicy_aaagroup_binding,omitempty"` + VPNTrafficPolicyAAAUserBinding []any `json:"vpntrafficpolicy_aaauser_binding,omitempty"` + VPNTrafficPolicyVPNGlobalBinding []any `json:"vpntrafficpolicy_vpnglobal_binding,omitempty"` + VPNTrafficPolicyVPNVServerBinding []any `json:"vpntrafficpolicy_vpnvserver_binding,omitempty"` +} + +type VPNVServerAuthenticationSAMLIDPPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNNextHopServer struct { + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NextHopFQDN string `json:"nexthopfqdn,omitempty"` + NextHopIP string `json:"nexthopip,omitempty"` + NextHopPort int `json:"nexthopport,omitempty"` + ResAddressType string `json:"resaddresstype,omitempty"` + Secure string `json:"secure,omitempty"` +} + +type VPNURLPolicy struct { + Action string `json:"action,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + LogAction string `json:"logaction,omitempty"` + Name string `json:"name,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule string `json:"rule,omitempty"` + UndefHits int `json:"undefhits,omitempty"` +} + +type VPNGlobalVPNURLPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + Builtin []string `json:"builtin,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNSessionPolicy struct { + Action string `json:"action,omitempty"` + Builtin []string `json:"builtin,omitempty"` + Count float64 `json:"__count,omitempty"` + ExpressionType string `json:"expressiontype,omitempty"` + Feature string `json:"feature,omitempty"` + Hits int `json:"hits,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule string `json:"rule,omitempty"` +} + +type VPNURL struct { + ActualURL string `json:"actualurl,omitempty"` + AppJSON string `json:"appjson,omitempty"` + ApplicationType string `json:"applicationtype,omitempty"` + ClientlessAccess string `json:"clientlessaccess,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + IconURL string `json:"iconurl,omitempty"` + LinkName string `json:"linkname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + SAMLSSOProfile string `json:"samlssoprofile,omitempty"` + SSOType string `json:"ssotype,omitempty"` + URLName string `json:"urlname,omitempty"` + VServerName string `json:"vservername,omitempty"` +} + +type VPNGlobalAuthenticationPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNVServerAuthenticationTACACSPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNGlobalVPNNextHopServerBinding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + NextHopServer string `json:"nexthopserver,omitempty"` +} + +type VPNVServerICAPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNVServerAuthenticationCertPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNVServerAuthenticationSAMLPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNURLPolicyVPNGlobalBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type VPNTrafficPolicyAAAGroupBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type VPNVServerCachePolicyBinding struct { + Count float64 `json:"__count,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNGlobalVPNPortalThemeBinding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + PortalTheme string `json:"portaltheme,omitempty"` +} + +type VPNVServerShareFileServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + Name string `json:"name,omitempty"` + ShareFile string `json:"sharefile,omitempty"` +} + +type VPNGlobalAuthenticationSAMLPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNTrafficPolicy struct { + Action string `json:"action,omitempty"` + Count float64 `json:"__count,omitempty"` + ExpressionType string `json:"expressiontype,omitempty"` + Hits int `json:"hits,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + Rule string `json:"rule,omitempty"` +} + +type VPNVServerAuthenticationLoginSchemaPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNVServerVPNTrafficPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNSessionPolicyAAAUserBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type VPNVServerVPNIntranetApplicationBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + IntranetApplication string `json:"intranetapplication,omitempty"` + Name string `json:"name,omitempty"` +} + +type VPNVServerAppFlowPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNGlobalAuthenticationRADIUSPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNClientlessAccessPolicyVPNGlobalBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type VPNGlobalAuthenticationLocalPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNGlobalVPNURLBinding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + URLName string `json:"urlname,omitempty"` +} + +type VPNSessionPolicyAAAGroupBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type VPNVServerBinding struct { + Name string `json:"name,omitempty"` + VPNVServerAAAPreauthenticationPolicyBinding []any `json:"vpnvserver_aaapreauthenticationpolicy_binding,omitempty"` + VPNVServerAnalyticsProfileBinding []any `json:"vpnvserver_analyticsprofile_binding,omitempty"` + VPNVServerAppControllerBinding []any `json:"vpnvserver_appcontroller_binding,omitempty"` + VPNVServerAppFlowPolicyBinding []any `json:"vpnvserver_appflowpolicy_binding,omitempty"` + VPNVServerAppFWPolicyBinding []any `json:"vpnvserver_appfwpolicy_binding,omitempty"` + VPNVServerAuditNSLogPolicyBinding []any `json:"vpnvserver_auditnslogpolicy_binding,omitempty"` + VPNVServerAuditSyslogPolicyBinding []any `json:"vpnvserver_auditsyslogpolicy_binding,omitempty"` + VPNVServerAuthenticationCertPolicyBinding []any `json:"vpnvserver_authenticationcertpolicy_binding,omitempty"` + VPNVServerAuthenticationDFAPolicyBinding []any `json:"vpnvserver_authenticationdfapolicy_binding,omitempty"` + VPNVServerAuthenticationLDAPPolicyBinding []any `json:"vpnvserver_authenticationldappolicy_binding,omitempty"` + VPNVServerAuthenticationLocalPolicyBinding []any `json:"vpnvserver_authenticationlocalpolicy_binding,omitempty"` + VPNVServerAuthenticationLoginSchemaPolicyBinding []any `json:"vpnvserver_authenticationloginschemapolicy_binding,omitempty"` + VPNVServerAuthenticationNegotiatePolicyBinding []any `json:"vpnvserver_authenticationnegotiatepolicy_binding,omitempty"` + VPNVServerAuthenticationOAuthIDPPolicyBinding []any `json:"vpnvserver_authenticationoauthidppolicy_binding,omitempty"` + VPNVServerAuthenticationPolicyBinding []any `json:"vpnvserver_authenticationpolicy_binding,omitempty"` + VPNVServerAuthenticationRADIUSPolicyBinding []any `json:"vpnvserver_authenticationradiuspolicy_binding,omitempty"` + VPNVServerAuthenticationSAMLIDPPolicyBinding []any `json:"vpnvserver_authenticationsamlidppolicy_binding,omitempty"` + VPNVServerAuthenticationSAMLPolicyBinding []any `json:"vpnvserver_authenticationsamlpolicy_binding,omitempty"` + VPNVServerAuthenticationTACACSPolicyBinding []any `json:"vpnvserver_authenticationtacacspolicy_binding,omitempty"` + VPNVServerAuthenticationWebAuthPolicyBinding []any `json:"vpnvserver_authenticationwebauthpolicy_binding,omitempty"` + VPNVServerCachePolicyBinding []any `json:"vpnvserver_cachepolicy_binding,omitempty"` + VPNVServerCSPolicyBinding []any `json:"vpnvserver_cspolicy_binding,omitempty"` + VPNVServerFEOPolicyBinding []any `json:"vpnvserver_feopolicy_binding,omitempty"` + VPNVServerICAPolicyBinding []any `json:"vpnvserver_icapolicy_binding,omitempty"` + VPNVServerIntranetIP6Binding []any `json:"vpnvserver_intranetip6_binding,omitempty"` + VPNVServerIntranetIPBinding []any `json:"vpnvserver_intranetip_binding,omitempty"` + VPNVServerResponderPolicyBinding []any `json:"vpnvserver_responderpolicy_binding,omitempty"` + VPNVServerRewritePolicyBinding []any `json:"vpnvserver_rewritepolicy_binding,omitempty"` + VPNVServerSecurePrivateAccessURLBinding []any `json:"vpnvserver_secureprivateaccessurl_binding,omitempty"` + VPNVServerShareFileServerBinding []any `json:"vpnvserver_sharefileserver_binding,omitempty"` + VPNVServerSTAServerBinding []any `json:"vpnvserver_staserver_binding,omitempty"` + VPNVServerVPNClientlessAccessPolicyBinding []any `json:"vpnvserver_vpnclientlessaccesspolicy_binding,omitempty"` + VPNVServerVPNEPAProfileBinding []any `json:"vpnvserver_vpnepaprofile_binding,omitempty"` + VPNVServerVPNEULABinding []any `json:"vpnvserver_vpneula_binding,omitempty"` + VPNVServerVPNIntranetApplicationBinding []any `json:"vpnvserver_vpnintranetapplication_binding,omitempty"` + VPNVServerVPNNextHopServerBinding []any `json:"vpnvserver_vpnnexthopserver_binding,omitempty"` + VPNVServerVPNPortalThemeBinding []any `json:"vpnvserver_vpnportaltheme_binding,omitempty"` + VPNVServerVPNSecurePrivateAccessProfileBinding []any `json:"vpnvserver_vpnsecureprivateaccessprofile_binding,omitempty"` + VPNVServerVPNSessionPolicyBinding []any `json:"vpnvserver_vpnsessionpolicy_binding,omitempty"` + VPNVServerVPNTrafficPolicyBinding []any `json:"vpnvserver_vpntrafficpolicy_binding,omitempty"` + VPNVServerVPNURLBinding []any `json:"vpnvserver_vpnurl_binding,omitempty"` + VPNVServerVPNURLPolicyBinding []any `json:"vpnvserver_vpnurlpolicy_binding,omitempty"` +} + +type VPNSessionAction struct { + AdvancedClientlessVPNMode string `json:"advancedclientlessvpnmode,omitempty"` + AllowedLoginGroups string `json:"allowedlogingroups,omitempty"` + AllProtocolProxy string `json:"allprotocolproxy,omitempty"` + AlwaysOnProfileName string `json:"alwaysonprofilename,omitempty"` + AuthorizationGroup string `json:"authorizationgroup,omitempty"` + AutoProxyURL string `json:"autoproxyurl,omitempty"` + Builtin []string `json:"builtin,omitempty"` + CitrixReceiverHome string `json:"citrixreceiverhome,omitempty"` + ClientChoices string `json:"clientchoices,omitempty"` + ClientCleanupPrompt string `json:"clientcleanupprompt,omitempty"` + ClientConfiguration []string `json:"clientconfiguration,omitempty"` + ClientDebug string `json:"clientdebug,omitempty"` + ClientIDleTimeout int `json:"clientidletimeout,omitempty"` + ClientIDleTimeoutWarning int `json:"clientidletimeoutwarning,omitempty"` + ClientlessModeURLEncoding string `json:"clientlessmodeurlencoding,omitempty"` + ClientlessPersistentCookie string `json:"clientlesspersistentcookie,omitempty"` + ClientlessVPNMode string `json:"clientlessvpnmode,omitempty"` + ClientOptions string `json:"clientoptions,omitempty"` + ClientSecurity string `json:"clientsecurity,omitempty"` + ClientSecurityGroup string `json:"clientsecuritygroup,omitempty"` + ClientSecurityLog string `json:"clientsecuritylog,omitempty"` + ClientSecurityMessage string `json:"clientsecuritymessage,omitempty"` + Count float64 `json:"__count,omitempty"` + DefaultAuthorizationAction string `json:"defaultauthorizationaction,omitempty"` + DNSVServerName string `json:"dnsvservername,omitempty"` + EmailHome string `json:"emailhome,omitempty"` + EPAClientType string `json:"epaclienttype,omitempty"` + Feature string `json:"feature,omitempty"` + ForceCleanup []string `json:"forcecleanup,omitempty"` + ForcedTimeout int `json:"forcedtimeout,omitempty"` + ForcedTimeoutWarning int `json:"forcedtimeoutwarning,omitempty"` + FQDNSpoofedIP string `json:"fqdnspoofedip,omitempty"` + FTPProxy string `json:"ftpproxy,omitempty"` + GopherProxy string `json:"gopherproxy,omitempty"` + HomePage string `json:"homepage,omitempty"` + HTTPPort []any `json:"httpport,omitempty"` + HTTPProxy string `json:"httpproxy,omitempty"` + ICAProxy string `json:"icaproxy,omitempty"` + IconWithReceiver string `json:"iconwithreceiver,omitempty"` + IIPDNSSuffix string `json:"iipdnssuffix,omitempty"` + KCDAccount string `json:"kcdaccount,omitempty"` + KillConnections string `json:"killconnections,omitempty"` + LinuxPluginUpgrade string `json:"linuxpluginupgrade,omitempty"` + LocalLANAccess string `json:"locallanaccess,omitempty"` + LoginScript string `json:"loginscript,omitempty"` + LogoutScript string `json:"logoutscript,omitempty"` + MacPluginUpgrade string `json:"macpluginupgrade,omitempty"` + Name string `json:"name,omitempty"` + Netmask string `json:"netmask,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NTDomain string `json:"ntdomain,omitempty"` + PCoIPProfileName string `json:"pcoipprofilename,omitempty"` + Proxy string `json:"proxy,omitempty"` + ProxyException string `json:"proxyexception,omitempty"` + ProxyLocalBypass string `json:"proxylocalbypass,omitempty"` + RDPClientProfileName string `json:"rdpclientprofilename,omitempty"` + RFC1918 string `json:"rfc1918,omitempty"` + SecureBrowse string `json:"securebrowse,omitempty"` + SessTimeout int `json:"sesstimeout,omitempty"` + SFGatewayAuthType string `json:"sfgatewayauthtype,omitempty"` + SmartGroup string `json:"smartgroup,omitempty"` + SocksProxy string `json:"socksproxy,omitempty"` + SplitDNS string `json:"splitdns,omitempty"` + SplitTunnel string `json:"splittunnel,omitempty"` + SpoofIIP string `json:"spoofiip,omitempty"` + SSLProxy string `json:"sslproxy,omitempty"` + SSO string `json:"sso,omitempty"` + SSOCredential string `json:"ssocredential,omitempty"` + StoreFrontURL string `json:"storefronturl,omitempty"` + TransparentInterception string `json:"transparentinterception,omitempty"` + UseIIP string `json:"useiip,omitempty"` + UseMIP string `json:"usemip,omitempty"` + UserAccounting string `json:"useraccounting,omitempty"` + WIHome string `json:"wihome,omitempty"` + WIHomeAddressType string `json:"wihomeaddresstype,omitempty"` + WindowsAutoLogon string `json:"windowsautologon,omitempty"` + WindowsClientType string `json:"windowsclienttype,omitempty"` + WindowsPluginUpgrade string `json:"windowspluginupgrade,omitempty"` + Winsip string `json:"winsip,omitempty"` + WIPortalMode string `json:"wiportalmode,omitempty"` +} + +type VPNVServerAuthenticationLDAPPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNTrafficAction struct { + AppTimeout int `json:"apptimeout,omitempty"` + Count float64 `json:"__count,omitempty"` + FormSSOAction string `json:"formssoaction,omitempty"` + Fta string `json:"fta,omitempty"` + Hdx string `json:"hdx,omitempty"` + KCDAccount string `json:"kcdaccount,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + PasswdExpression string `json:"passwdexpression,omitempty"` + Proxy string `json:"proxy,omitempty"` + Qual string `json:"qual,omitempty"` + SAMLSSOProfile string `json:"samlssoprofile,omitempty"` + SSO string `json:"sso,omitempty"` + UserExpression string `json:"userexpression,omitempty"` + Wanscaler string `json:"wanscaler,omitempty"` +} + +type VPNVServerVPNSecurePrivateAccessProfileBinding struct { + ActType int `json:"acttype,omitempty"` + Name string `json:"name,omitempty"` + SecurePrivateAccessProfile string `json:"secureprivateaccessprofile,omitempty"` +} + +type VPNVServerVPNEPAProfileBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + EPAProfile string `json:"epaprofile,omitempty"` + EPAProfileOptional bool `json:"epaprofileoptional,omitempty"` + Name string `json:"name,omitempty"` +} + +type VPNFormSSOAction struct { + ActionURL string `json:"actionurl,omitempty"` + Count float64 `json:"__count,omitempty"` + Name string `json:"name,omitempty"` + NameValuePair string `json:"namevaluepair,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NvType string `json:"nvtype,omitempty"` + PasswdField string `json:"passwdfield,omitempty"` + ResponseSize int `json:"responsesize,omitempty"` + SSOSuccessRule string `json:"ssosuccessrule,omitempty"` + SubmitMethod string `json:"submitmethod,omitempty"` + UserField string `json:"userfield,omitempty"` +} + +type VPNVServerAuthenticationRADIUSPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNVServerAuthenticationLocalPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNTrafficPolicyVPNGlobalBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type VPNURLPolicyBinding struct { + Name string `json:"name,omitempty"` + VPNURLPolicyAAAGroupBinding []any `json:"vpnurlpolicy_aaagroup_binding,omitempty"` + VPNURLPolicyAAAUserBinding []any `json:"vpnurlpolicy_aaauser_binding,omitempty"` + VPNURLPolicyVPNGlobalBinding []any `json:"vpnurlpolicy_vpnglobal_binding,omitempty"` + VPNURLPolicyVPNVServerBinding []any `json:"vpnurlpolicy_vpnvserver_binding,omitempty"` +} + +type VPNVServerResponderPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNVServerSecurePrivateAccessURLBinding struct { + ActType int `json:"acttype,omitempty"` + Name string `json:"name,omitempty"` + SecurePrivateAccessURL string `json:"secureprivateaccessurl,omitempty"` +} + +type VPNVServerAuthenticationPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNGlobalBinding struct { + VPNGlobalAppControllerBinding []any `json:"vpnglobal_appcontroller_binding,omitempty"` + VPNGlobalAppFWPolicyBinding []any `json:"vpnglobal_appfwpolicy_binding,omitempty"` + VPNGlobalAuditNSLogPolicyBinding []any `json:"vpnglobal_auditnslogpolicy_binding,omitempty"` + VPNGlobalAuditSyslogPolicyBinding []any `json:"vpnglobal_auditsyslogpolicy_binding,omitempty"` + VPNGlobalAuthenticationCertPolicyBinding []any `json:"vpnglobal_authenticationcertpolicy_binding,omitempty"` + VPNGlobalAuthenticationLDAPPolicyBinding []any `json:"vpnglobal_authenticationldappolicy_binding,omitempty"` + VPNGlobalAuthenticationLocalPolicyBinding []any `json:"vpnglobal_authenticationlocalpolicy_binding,omitempty"` + VPNGlobalAuthenticationNegotiatePolicyBinding []any `json:"vpnglobal_authenticationnegotiatepolicy_binding,omitempty"` + VPNGlobalAuthenticationPolicyBinding []any `json:"vpnglobal_authenticationpolicy_binding,omitempty"` + VPNGlobalAuthenticationRADIUSPolicyBinding []any `json:"vpnglobal_authenticationradiuspolicy_binding,omitempty"` + VPNGlobalAuthenticationSAMLPolicyBinding []any `json:"vpnglobal_authenticationsamlpolicy_binding,omitempty"` + VPNGlobalAuthenticationTACACSPolicyBinding []any `json:"vpnglobal_authenticationtacacspolicy_binding,omitempty"` + VPNGlobalGSLBDomainBinding []any `json:"vpnglobal_gslbdomain_binding,omitempty"` + VPNGlobalIntranetIP6Binding []any `json:"vpnglobal_intranetip6_binding,omitempty"` + VPNGlobalIntranetIPBinding []any `json:"vpnglobal_intranetip_binding,omitempty"` + VPNGlobalSecurePrivateAccessURLBinding []any `json:"vpnglobal_secureprivateaccessurl_binding,omitempty"` + VPNGlobalShareFileServerBinding []any `json:"vpnglobal_sharefileserver_binding,omitempty"` + VPNGlobalSSLCertKeyBinding []any `json:"vpnglobal_sslcertkey_binding,omitempty"` + VPNGlobalSTAServerBinding []any `json:"vpnglobal_staserver_binding,omitempty"` + VPNGlobalVPNClientlessAccessPolicyBinding []any `json:"vpnglobal_vpnclientlessaccesspolicy_binding,omitempty"` + VPNGlobalVPNEULABinding []any `json:"vpnglobal_vpneula_binding,omitempty"` + VPNGlobalVPNIntranetApplicationBinding []any `json:"vpnglobal_vpnintranetapplication_binding,omitempty"` + VPNGlobalVPNNextHopServerBinding []any `json:"vpnglobal_vpnnexthopserver_binding,omitempty"` + VPNGlobalVPNPortalThemeBinding []any `json:"vpnglobal_vpnportaltheme_binding,omitempty"` + VPNGlobalVPNSecurePrivateAccessProfileBinding []any `json:"vpnglobal_vpnsecureprivateaccessprofile_binding,omitempty"` + VPNGlobalVPNSessionPolicyBinding []any `json:"vpnglobal_vpnsessionpolicy_binding,omitempty"` + VPNGlobalVPNTrafficPolicyBinding []any `json:"vpnglobal_vpntrafficpolicy_binding,omitempty"` + VPNGlobalVPNURLBinding []any `json:"vpnglobal_vpnurl_binding,omitempty"` + VPNGlobalVPNURLPolicyBinding []any `json:"vpnglobal_vpnurlpolicy_binding,omitempty"` +} + +type VPNGlobalAppControllerBinding struct { + Count float64 `json:"__count,omitempty"` + AppController string `json:"appcontroller,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` +} + +type VPNVServerAuthenticationDFAPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNPCoIPProfile struct { + ConServerURL string `json:"conserverurl,omitempty"` + Count float64 `json:"__count,omitempty"` + IcvVerification string `json:"icvverification,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + SessionIdleTimeout int `json:"sessionidletimeout,omitempty"` +} + +type VPNGlobalShareFileServerBinding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + ShareFile string `json:"sharefile,omitempty"` +} + +type VPNTrafficPolicyAAAUserBinding struct { + Count float64 `json:"__count,omitempty"` + ActivePolicy int `json:"activepolicy,omitempty"` + BoundTo string `json:"boundto,omitempty"` + Name string `json:"name,omitempty"` + Priority int `json:"priority,omitempty"` +} + +type VPNAlwaysOnProfile struct { + ClientControl string `json:"clientcontrol,omitempty"` + Count float64 `json:"__count,omitempty"` + LocationBasedVPN string `json:"locationbasedvpn,omitempty"` + Name string `json:"name,omitempty"` + NetworkAccessOnVPNFailure string `json:"networkaccessonvpnfailure,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type VPNVServerVPNNextHopServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + Name string `json:"name,omitempty"` + NextHopServer string `json:"nexthopserver,omitempty"` +} + +type VPNGlobalAppFWPolicyBinding struct { + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNVServerSTAServerBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + Name string `json:"name,omitempty"` + STAAddressType string `json:"staaddresstype,omitempty"` + STAAuthID string `json:"staauthid,omitempty"` + STAServer string `json:"staserver,omitempty"` + STAState string `json:"stastate,omitempty"` +} + +type VPNGlobalVPNIntranetApplicationBinding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + IntranetApplication string `json:"intranetapplication,omitempty"` +} + +type VPNVServerIntranetIPBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + IntranetIP string `json:"intranetip,omitempty"` + MapField string `json:"map,omitempty"` + Name string `json:"name,omitempty"` + Netmask string `json:"netmask,omitempty"` +} + +type VPNClientlessAccessPolicyBinding struct { + Name string `json:"name,omitempty"` + VPNClientlessAccessPolicyVPNGlobalBinding []any `json:"vpnclientlessaccesspolicy_vpnglobal_binding,omitempty"` + VPNClientlessAccessPolicyVPNVServerBinding []any `json:"vpnclientlessaccesspolicy_vpnvserver_binding,omitempty"` +} + +type VPNGlobalAuthenticationNegotiatePolicyBinding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNGlobalAuthenticationTACACSPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + PolicyName string `json:"policyname,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNGlobalIntranetIP6Binding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + IntranetIP6 string `json:"intranetip6,omitempty"` + NumAddr int `json:"numaddr,omitempty"` +} + +type VPNVServer struct { + AccessRestrictedPageRedirect string `json:"accessrestrictedpageredirect,omitempty"` + AdvancedEPA string `json:"advancedepa,omitempty"` + AppFlowLog string `json:"appflowlog,omitempty"` + Authentication string `json:"authentication,omitempty"` + AuthnProfile string `json:"authnprofile,omitempty"` + BackupVServer string `json:"backupvserver,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + CacheType string `json:"cachetype,omitempty"` + CacheVServer string `json:"cachevserver,omitempty"` + CertKeyNames string `json:"certkeynames,omitempty"` + CGInfraHomePageRedirect string `json:"cginfrahomepageredirect,omitempty"` + CltTimeout int `json:"clttimeout,omitempty"` + Comment string `json:"comment,omitempty"` + Count float64 `json:"__count,omitempty"` + CSVServer string `json:"csvserver,omitempty"` + CurAAAUsers int `json:"curaaausers,omitempty"` + CurState string `json:"curstate,omitempty"` + CurTotalUsers int `json:"curtotalusers,omitempty"` + DeploymentType string `json:"deploymenttype,omitempty"` + DeviceCert string `json:"devicecert,omitempty"` + DevicePosture string `json:"deviceposture,omitempty"` + DisablePrimaryOnDown string `json:"disableprimaryondown,omitempty"` + Domain string `json:"domain,omitempty"` + DoubleHop string `json:"doublehop,omitempty"` + DownStateFlush string `json:"downstateflush,omitempty"` + DTLS string `json:"dtls,omitempty"` + EPAProfileOptional bool `json:"epaprofileoptional,omitempty"` + FailedLoginTimeout int `json:"failedlogintimeout,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + HTTPProfileName string `json:"httpprofilename,omitempty"` + ICAOnly string `json:"icaonly,omitempty"` + ICAProxySessionMigration string `json:"icaproxysessionmigration,omitempty"` + ICMPVSRResponse string `json:"icmpvsrresponse,omitempty"` + IP string `json:"ip,omitempty"` + IPSet string `json:"ipset,omitempty"` + IPv46 string `json:"ipv46,omitempty"` + L2Conn string `json:"l2conn,omitempty"` + LinuxEPAPluginUpgrade string `json:"linuxepapluginupgrade,omitempty"` + ListenPolicy string `json:"listenpolicy,omitempty"` + ListenPriority int `json:"listenpriority,omitempty"` + LoginOnce string `json:"loginonce,omitempty"` + LogoutOnSmartcardRemoval string `json:"logoutonsmartcardremoval,omitempty"` + MacEPAPluginUpgrade string `json:"macepapluginupgrade,omitempty"` + MapField string `json:"map,omitempty"` + MaxAAAUsers int `json:"maxaaausers,omitempty"` + MaxLoginAttempts int `json:"maxloginattempts,omitempty"` + Name string `json:"name,omitempty"` + NetProfile string `json:"netprofile,omitempty"` + NewName string `json:"newname,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NGName string `json:"ngname,omitempty"` + NoDefaultBindings string `json:"nodefaultbindings,omitempty"` + PCoIPVServerProfileName string `json:"pcoipvserverprofilename,omitempty"` + Port int `json:"port,omitempty"` + Precedence string `json:"precedence,omitempty"` + QUICProfileName string `json:"quicprofilename,omitempty"` + Range int `json:"range,omitempty"` + RDPServerProfileName string `json:"rdpserverprofilename,omitempty"` + Redirect string `json:"redirect,omitempty"` + RedirectURL string `json:"redirecturl,omitempty"` + Response string `json:"response,omitempty"` + RHIState string `json:"rhistate,omitempty"` + Rule string `json:"rule,omitempty"` + SameSite string `json:"samesite,omitempty"` + Secondary bool `json:"secondary,omitempty"` + SecurePrivateAccess string `json:"secureprivateaccess,omitempty"` + ServiceName string `json:"servicename,omitempty"` + ServiceType string `json:"servicetype,omitempty"` + SOMethod string `json:"somethod,omitempty"` + SOPersistence string `json:"sopersistence,omitempty"` + SOPersistenceTimeout int `json:"sopersistencetimeout,omitempty"` + SOThreshold int `json:"sothreshold,omitempty"` + State string `json:"state,omitempty"` + Status int `json:"status,omitempty"` + TCPProfileName string `json:"tcpprofilename,omitempty"` + TypeField string `json:"type,omitempty"` + UseMIP string `json:"usemip,omitempty"` + UserDomains string `json:"userdomains,omitempty"` + Value string `json:"value,omitempty"` + VServerFQDN string `json:"vserverfqdn,omitempty"` + Weight int `json:"weight,omitempty"` + WindowsEPAPluginUpgrade string `json:"windowsepapluginupgrade,omitempty"` +} + +type VPNGlobalSSLCertKeyBinding struct { + Count float64 `json:"__count,omitempty"` + CACert string `json:"cacert,omitempty"` + CertKeyName string `json:"certkeyname,omitempty"` + CRLCheck string `json:"crlcheck,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + OCSPCheck string `json:"ocspcheck,omitempty"` + UserDataEncryptionKey string `json:"userdataencryptionkey,omitempty"` +} + +type VPNVServerAppFWPolicyBinding struct { + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNICAConnection struct { + All bool `json:"all,omitempty"` + Count float64 `json:"__count,omitempty"` + DestIP string `json:"destip,omitempty"` + DestPort int `json:"destport,omitempty"` + Domain string `json:"domain,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + NodeID int `json:"nodeid,omitempty"` + PeID int `json:"peid,omitempty"` + ProductName string `json:"productname,omitempty"` + SrcIP string `json:"srcip,omitempty"` + SrcPort int `json:"srcport,omitempty"` + TenantName string `json:"tenantname,omitempty"` + TransProto string `json:"transproto,omitempty"` + Username string `json:"username,omitempty"` +} + +type VPNVServerRewritePolicyBinding struct { + Count float64 `json:"__count,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNVServerAuthenticationOAuthIDPPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} + +type VPNGlobalSTAServerBinding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + STAAddressType string `json:"staaddresstype,omitempty"` + STAAuthID string `json:"staauthid,omitempty"` + STAServer string `json:"staserver,omitempty"` + STAState string `json:"stastate,omitempty"` +} + +type VPNSecurePrivateAccessProfile struct { + AccessRestrictedPageRedirect string `json:"accessrestrictedpageredirect,omitempty"` + ChromeEnterprisePremiumMode string `json:"chromeenterprisepremiummode,omitempty"` + CloudDeployment string `json:"clouddeployment,omitempty"` + Count float64 `json:"__count,omitempty"` + CustomerID string `json:"customerid,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + URL string `json:"url,omitempty"` +} + +type VPNEPAProfile struct { + Count float64 `json:"__count,omitempty"` + Data string `json:"data,omitempty"` + Filename string `json:"filename,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` +} + +type VPNVServerVPNPortalThemeBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + Name string `json:"name,omitempty"` + PortalTheme string `json:"portaltheme,omitempty"` +} + +type VPNGlobalDomainBinding struct { + Count float64 `json:"__count,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + IntranetDomain string `json:"intranetdomain,omitempty"` +} + +type VPNVServerVPNClientlessAccessPolicyBinding struct { + Count float64 `json:"__count,omitempty"` + ActType int `json:"acttype,omitempty"` + BindPoint string `json:"bindpoint,omitempty"` + GotoPriorityExpression string `json:"gotopriorityexpression,omitempty"` + GroupExtraction bool `json:"groupextraction,omitempty"` + Name string `json:"name,omitempty"` + Policy string `json:"policy,omitempty"` + Priority int `json:"priority,omitempty"` + Secondary bool `json:"secondary,omitempty"` +} diff --git a/nitrogo/models/wasm.go b/nitrogo/models/wasm.go new file mode 100644 index 0000000..b614a0d --- /dev/null +++ b/nitrogo/models/wasm.go @@ -0,0 +1,10 @@ +package models + +// wasm configuration structs +type WasmModule struct { + Count float64 `json:"__count,omitempty"` + ModuleFile string `json:"modulefile,omitempty"` + Name string `json:"name,omitempty"` + NextGenAPIResource string `json:"_nextgenapiresource,omitempty"` + SignatureFile string `json:"signaturefile,omitempty"` +} diff --git a/nitrogo/network.go b/nitrogo/network.go index 1dc9248..c03d829 100644 --- a/nitrogo/network.go +++ b/nitrogo/network.go @@ -1,707 +1,10070 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + appAlgParamURL = "/nitro/v1/config/appalgparam" + arpURL = "/nitro/v1/config/arp" + arpParamURL = "/nitro/v1/config/arpparam" + bridgeGroupURL = "/nitro/v1/config/bridgegroup" + bridgeGroupBindingURL = "/nitro/v1/config/bridgegroup_binding" + bridgeGroupNSIP6BindingURL = "/nitro/v1/config/bridgegroup_nsip6_binding" + bridgeGroupNSIPBindingURL = "/nitro/v1/config/bridgegroup_nsip_binding" + bridgeGroupVLANBindingURL = "/nitro/v1/config/bridgegroup_vlan_binding" + bridgeGroupVXLANBindingURL = "/nitro/v1/config/bridgegroup_vxlan_binding" + bridgeTableURL = "/nitro/v1/config/bridgetable" + channelURL = "/nitro/v1/config/channel" + channelBindingURL = "/nitro/v1/config/channel_binding" + channelInterfaceBindingURL = "/nitro/v1/config/channel_interface_binding" + ciURL = "/nitro/v1/config/ci" + fisURL = "/nitro/v1/config/fis" + fisBindingURL = "/nitro/v1/config/fis_binding" + fisChannelBindingURL = "/nitro/v1/config/fis_channel_binding" + fisInterfaceBindingURL = "/nitro/v1/config/fis_interface_binding" + forwardingSessionURL = "/nitro/v1/config/forwardingsession" + inatURL = "/nitro/v1/config/inat" + inatParamURL = "/nitro/v1/config/inatparam" + interfaceURL = "/nitro/v1/config/interface" + interfaceBindingURL = "/nitro/v1/config/interface_binding" + interfacePairURL = "/nitro/v1/config/interfacepair" + ip6TunnelURL = "/nitro/v1/config/ip6tunnel" + ip6TunnelParamURL = "/nitro/v1/config/ip6tunnelparam" + ipSetURL = "/nitro/v1/config/ipset" + ipSetBindingURL = "/nitro/v1/config/ipset_binding" + ipSetNSIP6BindingURL = "/nitro/v1/config/ipset_nsip6_binding" + ipSetNSIPBindingURL = "/nitro/v1/config/ipset_nsip_binding" + ipTunnelURL = "/nitro/v1/config/iptunnel" + ipTunnelParamURL = "/nitro/v1/config/iptunnelparam" + ipv6URL = "/nitro/v1/config/ipv6" + l2ParamURL = "/nitro/v1/config/l2param" + l3ParamURL = "/nitro/v1/config/l3param" + l4ParamURL = "/nitro/v1/config/l4param" + lacpURL = "/nitro/v1/config/lacp" + linkSetURL = "/nitro/v1/config/linkset" + linkSetBindingURL = "/nitro/v1/config/linkset_binding" + linkSetChannelBindingURL = "/nitro/v1/config/linkset_channel_binding" + linkSetInterfaceBindingURL = "/nitro/v1/config/linkset_interface_binding" + mapBMRURL = "/nitro/v1/config/mapbmr" + mapBMRBindingURL = "/nitro/v1/config/mapbmr_binding" + mapBMRBMRV4NetworkBindingURL = "/nitro/v1/config/mapbmr_bmrv4network_binding" + mapDMRURL = "/nitro/v1/config/mapdmr" + mapDomainURL = "/nitro/v1/config/mapdomain" + mapDomainBindingURL = "/nitro/v1/config/mapdomain_binding" + mapDomainMapBMRBindingURL = "/nitro/v1/config/mapdomain_mapbmr_binding" + nat64URL = "/nitro/v1/config/nat64" + nat64ParamURL = "/nitro/v1/config/nat64param" + nd6URL = "/nitro/v1/config/nd6" + nd6RAVariablesURL = "/nitro/v1/config/nd6ravariables" + nd6RAVariablesBindingURL = "/nitro/v1/config/nd6ravariables_binding" + nd6RAVariablesOnLinkIPV6PrefixBindingURL = "/nitro/v1/config/nd6ravariables_onlinkipv6prefix_binding" + netBridgeURL = "/nitro/v1/config/netbridge" + netBridgeBindingURL = "/nitro/v1/config/netbridge_binding" + netBridgeIPTunnelBindingURL = "/nitro/v1/config/netbridge_iptunnel_binding" + netBridgeNSIP6BindingURL = "/nitro/v1/config/netbridge_nsip6_binding" + netBridgeNSIPBindingURL = "/nitro/v1/config/netbridge_nsip_binding" + netBridgeVLANBindingURL = "/nitro/v1/config/netbridge_vlan_binding" + netProfileURL = "/nitro/v1/config/netprofile" + netProfileBindingURL = "/nitro/v1/config/netprofile_binding" + netProfileNATRuleBindingURL = "/nitro/v1/config/netprofile_natrule_binding" + netProfileSrcPortSetBindingURL = "/nitro/v1/config/netprofile_srcportset_binding" + onLinkIPV6PrefixURL = "/nitro/v1/config/onlinkipv6prefix" + ptpURL = "/nitro/v1/config/ptp" + rnatURL = "/nitro/v1/config/rnat" + rnatBindingURL = "/nitro/v1/config/rnat_binding" + rnatNSIPBindingURL = "/nitro/v1/config/rnat_nsip_binding" + rnatRetainSourcePortSetBindingURL = "/nitro/v1/config/rnat_retainsourceportset_binding" + rnat6URL = "/nitro/v1/config/rnat6" + rnat6BindingURL = "/nitro/v1/config/rnat6_binding" + rnat6NSIP6BindingURL = "/nitro/v1/config/rnat6_nsip6_binding" + rnatGlobalBindingURL = "/nitro/v1/config/rnatglobal_binding" + rnatGlobalAuditSyslogPolicyBindingURL = "/nitro/v1/config/rnatglobal_auditsyslogpolicy_binding" + rnatParamURL = "/nitro/v1/config/rnatparam" + rnatSessionURL = "/nitro/v1/config/rnatsession" + routeURL = "/nitro/v1/config/route" + route6URL = "/nitro/v1/config/route6" + rssKeyTypeURL = "/nitro/v1/config/rsskeytype" + vlanURL = "/nitro/v1/config/vlan" + vlanBindingURL = "/nitro/v1/config/vlan_binding" + vlanChannelBindingURL = "/nitro/v1/config/vlan_channel_binding" + vlanInterfaceBindingURL = "/nitro/v1/config/vlan_interface_binding" + vlanLinkSetBindingURL = "/nitro/v1/config/vlan_linkset_binding" + vlanNSIP6BindingURL = "/nitro/v1/config/vlan_nsip6_binding" + vlanNSIPBindingURL = "/nitro/v1/config/vlan_nsip_binding" + vridURL = "/nitro/v1/config/vrid" + vridBindingURL = "/nitro/v1/config/vrid_binding" + vridChannelBindingURL = "/nitro/v1/config/vrid_channel_binding" + vridInterfaceBindingURL = "/nitro/v1/config/vrid_interface_binding" + vridNSIP6BindingURL = "/nitro/v1/config/vrid_nsip6_binding" + vridNSIPBindingURL = "/nitro/v1/config/vrid_nsip_binding" + vridTrackInterfaceBindingURL = "/nitro/v1/config/vrid_trackinterface_binding" + vrid6URL = "/nitro/v1/config/vrid6" + vrid6BindingURL = "/nitro/v1/config/vrid6_binding" + vrid6ChannelBindingURL = "/nitro/v1/config/vrid6_channel_binding" + vrid6InterfaceBindingURL = "/nitro/v1/config/vrid6_interface_binding" + vrid6NSIP6BindingURL = "/nitro/v1/config/vrid6_nsip6_binding" + vrid6NSIPBindingURL = "/nitro/v1/config/vrid6_nsip_binding" + vrid6TrackInterfaceBindingURL = "/nitro/v1/config/vrid6_trackinterface_binding" + vridParamURL = "/nitro/v1/config/vridparam" + vxlanURL = "/nitro/v1/config/vxlan" + vxlanBindingURL = "/nitro/v1/config/vxlan_binding" + vxlanIPTunnelBindingURL = "/nitro/v1/config/vxlan_iptunnel_binding" + vxlanNSIP6BindingURL = "/nitro/v1/config/vxlan_nsip6_binding" + vxlanNSIPBindingURL = "/nitro/v1/config/vxlan_nsip_binding" + vxlanSrcIPBindingURL = "/nitro/v1/config/vxlan_srcip_binding" + vxlanVLANMapURL = "/nitro/v1/config/vxlanvlanmap" + vxlanVLANMapBindingURL = "/nitro/v1/config/vxlanvlanmap_binding" + vxlanVLANMapVXLANBindingURL = "/nitro/v1/config/vxlanvlanmap_vxlan_binding" +) + type NetworkService struct { client *Client } // appalgparam -func (s *NetworkService) UpdateAppAlgParam() {} -func (s *NetworkService) UnsetAppAlgParam() {} -func (s *NetworkService) GetAllAppAlgParam() {} +func (s *NetworkService) UpdateAppAlgParam(resource models.AppALGParam) error { + payload := map[string]any{"appalgparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, appAlgParamURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetAppAlgParam(resource models.AppALGParam) error { + payload := map[string]any{"appalgparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", appAlgParamURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllAppAlgParam() ([]models.AppALGParam, error) { + req, err := s.client.NewRequest(http.MethodGet, appAlgParamURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.AppALGParam `json:"appalgparam"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} // arp -func (s *NetworkService) AddARP() {} -func (s *NetworkService) DeleteARP() {} -func (s *NetworkService) SendARP() {} -func (s *NetworkService) GetAllARP() {} -func (s *NetworkService) CountARP() {} +func (s *NetworkService) AddARP(resource models.ARP) error { + payload := map[string]any{"arp": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, arpURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteARP(ipaddress string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", arpURL, ipaddress), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) SendARP(resource models.ARP) error { + payload := map[string]any{"arp": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=send", arpURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllARP() ([]models.ARP, error) { + req, err := s.client.NewRequest(http.MethodGet, arpURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.ARP `json:"arp"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) CountARP() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", arpURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.ARP `json:"arp"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} // arpparam -func (s *NetworkService) UpdateARPParam() {} -func (s *NetworkService) UnsetARPParam() {} -func (s *NetworkService) GetAllARPParam() {} +func (s *NetworkService) UpdateARPParam(resource models.ARPParam) error { + payload := map[string]any{"arpparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, arpParamURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetARPParam(resource models.ARPParam) error { + payload := map[string]any{"arpparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", arpParamURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllARPParam() ([]models.ARPParam, error) { + req, err := s.client.NewRequest(http.MethodGet, arpParamURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.ARPParam `json:"arpparam"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} // bridgegroup -func (s *NetworkService) AddBridgeGroup() {} -func (s *NetworkService) DeleteBridgeGroup() {} -func (s *NetworkService) UpdateBridgeGroup() {} -func (s *NetworkService) UnsetBridgeGroup() {} -func (s *NetworkService) GetAllBridgeGroup() {} -func (s *NetworkService) GetBridgeGroup() {} -func (s *NetworkService) CountBridgeGroup() {} +func (s *NetworkService) AddBridgeGroup(resource models.BridgeGroup) error { + payload := map[string]any{"bridgegroup": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, bridgeGroupURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteBridgeGroup(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", bridgeGroupURL, id), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UpdateBridgeGroup(resource models.BridgeGroup) error { + payload := map[string]any{"bridgegroup": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, bridgeGroupURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetBridgeGroup(resource models.BridgeGroup) error { + payload := map[string]any{"bridgegroup": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", bridgeGroupURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllBridgeGroup() ([]models.BridgeGroup, error) { + req, err := s.client.NewRequest(http.MethodGet, bridgeGroupURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.BridgeGroup `json:"bridgegroup"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetBridgeGroup(id string) (*models.BridgeGroup, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", bridgeGroupURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.BridgeGroup `json:"bridgegroup"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountBridgeGroup() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", bridgeGroupURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.BridgeGroup `json:"bridgegroup"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} // bridgegroup_binding -func (s *NetworkService) GetAllBridgeGroupBinding() {} -func (s *NetworkService) GetBridgeGroupBinding() {} +func (s *NetworkService) GetAllBridgeGroupBinding() ([]models.BridgeGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, bridgeGroupBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.BridgeGroupBinding `json:"bridgegroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetBridgeGroupBinding(id string) (*models.BridgeGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", bridgeGroupBindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.BridgeGroupBinding `json:"bridgegroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} // bridgegroup_nsip6_binding -func (s *NetworkService) AddBridgeGroupNSIP6Binding() {} -func (s *NetworkService) DeleteBridgeGroupNSIP6Binding() {} -func (s *NetworkService) GetAllBridgeGroupNSIP6Binding() {} -func (s *NetworkService) GetBridgeGroupNSIP6Binding() {} -func (s *NetworkService) CountBridgeGroupNSIP6Binding() {} +func (s *NetworkService) AddBridgeGroupNSIP6Binding(resource models.BridgeGroupNSIP6Binding) error { + payload := map[string]any{"bridgegroup_nsip6_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, bridgeGroupNSIP6BindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteBridgeGroupNSIP6Binding(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", bridgeGroupNSIP6BindingURL, id), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllBridgeGroupNSIP6Binding() ([]models.BridgeGroupNSIP6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, bridgeGroupNSIP6BindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.BridgeGroupNSIP6Binding `json:"bridgegroup_nsip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetBridgeGroupNSIP6Binding(id string) (*models.BridgeGroupNSIP6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", bridgeGroupNSIP6BindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.BridgeGroupNSIP6Binding `json:"bridgegroup_nsip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountBridgeGroupNSIP6Binding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", bridgeGroupNSIP6BindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.BridgeGroupNSIP6Binding `json:"bridgegroup_nsip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} // bridgegroup_nsip_binding -func (s *NetworkService) AddBrigeGroupNSIPBinding() {} -func (s *NetworkService) DeleteBrigeGroupNSIPBinding() {} -func (s *NetworkService) GetAllBrigeGroupNSIPBinding() {} -func (s *NetworkService) GetBrigeGroupNSIPBinding() {} -func (s *NetworkService) CountBrigeGroupNSIPBinding() {} +func (s *NetworkService) AddBrigeGroupNSIPBinding(resource models.BridgeGroupNSIPBinding) error { + payload := map[string]any{"bridgegroup_nsip_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// bridgegroup_vlan_binding -func (s *NetworkService) AddBridgeGroupVLANBinding() {} -func (s *NetworkService) DeleteBridgeGroupVLANBinding() {} -func (s *NetworkService) GetAllBridgeGroupVLANBinding() {} -func (s *NetworkService) GetBridgeGroupVLANBinding() {} -func (s *NetworkService) CountBridgeGroupVLANBinding() {} + req, err := s.client.NewRequest(http.MethodPost, bridgeGroupNSIPBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } -// bridgetable -func (s *NetworkService) AddBridgeTable() {} -func (s *NetworkService) DeleteBridgeTable() {} -func (s *NetworkService) UpdateBridgeTable() {} -func (s *NetworkService) UnsetBridgeTable() {} -func (s *NetworkService) GetAllBridgeTable() {} -func (s *NetworkService) CountBridgeTable() {} + _, err = s.client.Do(req) + return err +} -// channel -func (s *NetworkService) AddChannel() {} -func (s *NetworkService) DeleteChannel() {} -func (s *NetworkService) UpdateChannel() {} -func (s *NetworkService) UnsetChannel() {} -func (s *NetworkService) GetAllChannel() {} -func (s *NetworkService) GetChannel() {} -func (s *NetworkService) CountChannel() {} +func (s *NetworkService) DeleteBrigeGroupNSIPBinding(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", bridgeGroupNSIPBindingURL, id), nil) + if err != nil { + return err + } -// channel_binding -func (s *NetworkService) GetAllChannelBinding() {} -func (s *NetworkService) GetChannelBinding() {} + _, err = s.client.Do(req) + return err +} -// channel_interface_binding -func (s *NetworkService) AddChannelInterfaceBinding() {} -func (s *NetworkService) DeleteChannelInterfaceBinding() {} -func (s *NetworkService) GetAllChannelInterfaceBinding() {} -func (s *NetworkService) GetChannelInterfaceBinding() {} -func (s *NetworkService) CountChannelInterfaceBinding() {} +func (s *NetworkService) GetAllBrigeGroupNSIPBinding() ([]models.BridgeGroupNSIPBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, bridgeGroupNSIPBindingURL, nil) + if err != nil { + return nil, err + } -// ci -func (s *NetworkService) GetAllCI() {} -func (s *NetworkService) CountCI() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// fis -func (s *NetworkService) AddFIS() {} -func (s *NetworkService) DeleteFIS() {} -func (s *NetworkService) GetAllFIS() {} -func (s *NetworkService) GetFIS() {} -func (s *NetworkService) CountFIS() {} + var result struct { + Data []models.BridgeGroupNSIPBinding `json:"bridgegroup_nsip_binding"` + } -// fis_binding -func (s *NetworkService) GetAllFISBinding() {} -func (s *NetworkService) GetFISBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// fis_channel_binding -func (s *NetworkService) AddFISChannelBinding() {} -func (s *NetworkService) DeleteFISChannelBinding() {} -func (s *NetworkService) GetAllFISChannelBinding() {} -func (s *NetworkService) GetFISChannelBinding() {} -func (s *NetworkService) CountFISChannelBinding() {} + return result.Data, nil +} -// fis_interface_binding -func (s *NetworkService) AddFISInterfaceBinding() {} -func (s *NetworkService) DeleteFISInterfaceBinding() {} +func (s *NetworkService) GetBrigeGroupNSIPBinding(id string) (*models.BridgeGroupNSIPBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", bridgeGroupNSIPBindingURL, id), nil) + if err != nil { + return nil, err + } -// forwardingsession -func (s *NetworkService) AddFowardingSession() {} -func (s *NetworkService) DeleteFowardingSession() {} -func (s *NetworkService) UpdateFowardingSession() {} -func (s *NetworkService) GetAllFowardingSession() {} -func (s *NetworkService) GetFowardingSession() {} -func (s *NetworkService) CountFowardingSession() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// inat -func (s *NetworkService) AddINAT() {} -func (s *NetworkService) DeleteINAT() {} -func (s *NetworkService) UpdateINAT() {} -func (s *NetworkService) UnsetINAT() {} -func (s *NetworkService) GetAllINAT() {} -func (s *NetworkService) GetINAT() {} -func (s *NetworkService) CountINAT() {} + var result struct { + Data []models.BridgeGroupNSIPBinding `json:"bridgegroup_nsip_binding"` + } -// inatparam -func (s *NetworkService) UpdateINATParam() {} -func (s *NetworkService) UnsetINATParam() {} -func (s *NetworkService) GetAllINATParam() {} -func (s *NetworkService) GetINATParam() {} -func (s *NetworkService) CountINATParam() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// interface -func (s *NetworkService) ClearInterface() {} -func (s *NetworkService) UpdateInterface() {} -func (s *NetworkService) UnsetInterface() {} -func (s *NetworkService) EnableInterface() {} -func (s *NetworkService) DisableInterface() {} -func (s *NetworkService) ResetInterface() {} -func (s *NetworkService) GetAllInterface() {} -func (s *NetworkService) GetInterface() {} -func (s *NetworkService) CountInterface() {} + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } -// interfacepair -func (s *NetworkService) AddInterfacePair() {} -func (s *NetworkService) DeleteInterfacePair() {} -func (s *NetworkService) GetAllInterfacePair() {} -func (s *NetworkService) GetInterfacePair() {} -func (s *NetworkService) CountInterfacePair() {} + return &result.Data[0], nil +} -// ip6tunnel -func (s *NetworkService) AddIP6Tunnel() {} -func (s *NetworkService) DeleteIP6Tunnel() {} -func (s *NetworkService) GetAllIP6Tunnel() {} -func (s *NetworkService) GetIP6Tunnel() {} -func (s *NetworkService) CountIP6Tunnel() {} +func (s *NetworkService) CountBrigeGroupNSIPBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", bridgeGroupNSIPBindingURL), nil) + if err != nil { + return 0, err + } -// ip6tunnelparam -func (s *NetworkService) UpdateIP6TunnelParam() {} -func (s *NetworkService) UnsetIP6TunnelParam() {} -func (s *NetworkService) GetAllIP6TunnelParam() {} + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } -// ipset -func (s *NetworkService) AddIPSet() {} -func (s *NetworkService) DeleteIPSet() {} -func (s *NetworkService) GetAllIPSet() {} -func (s *NetworkService) GetIPSet() {} -func (s *NetworkService) CountIPSet() {} + var result struct { + Data []models.BridgeGroupNSIPBinding `json:"bridgegroup_nsip_binding"` + } -// ipset_binding -func (s *NetworkService) GetAllIPSetBinding() {} -func (s *NetworkService) GetIPSetBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } -// ipset_nsip6_binding -func (s *NetworkService) AddIPSetNSIP6Binding() {} -func (s *NetworkService) DeleteIPSetNSIP6Binding() {} -func (s *NetworkService) GetAllIPSetNSIP6Binding() {} -func (s *NetworkService) GetIPSetNSIP6Binding() {} -func (s *NetworkService) CountIPSetNSIP6Binding() {} + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} -// ipset_nsip_binding -func (s *NetworkService) AddIPSetNSIPBinding() {} -func (s *NetworkService) DeleteIPSetNSIPBinding() {} -func (s *NetworkService) GetAllIPSetNSIPBinding() {} -func (s *NetworkService) GetIPSetNSIPBinding() {} -func (s *NetworkService) CountIPSetNSIPBinding() {} +// bridgegroup_vlan_binding +func (s *NetworkService) AddBridgeGroupVLANBinding(resource models.BridgeGroupVLANBinding) error { + payload := map[string]any{"bridgegroup_vlan_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// iptunnel -func (s *NetworkService) AddIPTunnel() {} -func (s *NetworkService) DeleteIPTunnel() {} -func (s *NetworkService) UpdateIPTunnel() {} -func (s *NetworkService) UnsetIPTunnel() {} -func (s *NetworkService) GetAllIPTunnel() {} -func (s *NetworkService) GetIPTunnel() {} -func (s *NetworkService) CountIPTunnel() {} + req, err := s.client.NewRequest(http.MethodPost, bridgeGroupVLANBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } -// iptunnelparam -func (s *NetworkService) UpdateIPTunnelParam() {} -func (s *NetworkService) UnsetIPTunnelParam() {} -func (s *NetworkService) GetAllIPTunnelParam() {} + _, err = s.client.Do(req) + return err +} -// ipv6 -func (s *NetworkService) UpdateIPV6() {} -func (s *NetworkService) UnsetIPV6() {} -func (s *NetworkService) GetAllIPV6() {} -func (s *NetworkService) GetIPV6() {} -func (s *NetworkService) CountIPV6() {} +func (s *NetworkService) DeleteBridgeGroupVLANBinding(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", bridgeGroupVLANBindingURL, id), nil) + if err != nil { + return err + } -// l2param -func (s *NetworkService) UpdateL2Param() {} -func (s *NetworkService) UnsetL2Param() {} -func (s *NetworkService) GetAllL2Param() {} + _, err = s.client.Do(req) + return err +} -// l3param -func (s *NetworkService) UpdateL3Param() {} -func (s *NetworkService) UnsetL3Param() {} -func (s *NetworkService) GetAllL3Param() {} +func (s *NetworkService) GetAllBridgeGroupVLANBinding() ([]models.BridgeGroupVLANBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, bridgeGroupVLANBindingURL, nil) + if err != nil { + return nil, err + } -// l4param -func (s *NetworkService) UpdateL4Param() {} -func (s *NetworkService) UnsetL4Param() {} -func (s *NetworkService) GetAllL4Param() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// lacp -func (s *NetworkService) UpdateLACP() {} -func (s *NetworkService) GetAllLACP() {} -func (s *NetworkService) GetLACP() {} -func (s *NetworkService) CountLACP() {} + var result struct { + Data []models.BridgeGroupVLANBinding `json:"bridgegroup_vlan_binding"` + } -// linkset -func (s *NetworkService) AddLinkSet() {} -func (s *NetworkService) DeleteLinkSet() {} -func (s *NetworkService) GetAllLinkSet() {} -func (s *NetworkService) GetLinkSet() {} -func (s *NetworkService) CountLinkSet() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// linkset_binding -func (s *NetworkService) GetAllLinkSetBinding() {} -func (s *NetworkService) GetLinkSetBinding() {} + return result.Data, nil +} -// linkset_channel_binding -func (s *NetworkService) AddLinkSetChannelBinding() {} -func (s *NetworkService) DeleteLinkSetChannelBinding() {} -func (s *NetworkService) GetAllLinkSetChannelBinding() {} -func (s *NetworkService) GetLinkSetChannelBinding() {} -func (s *NetworkService) CountLinkSetChannelBinding() {} +func (s *NetworkService) GetBridgeGroupVLANBinding(id string) (*models.BridgeGroupVLANBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", bridgeGroupVLANBindingURL, id), nil) + if err != nil { + return nil, err + } -// linkset_interface_binding -func (s *NetworkService) AddLinkSetInterfaceBinding() {} -func (s *NetworkService) DeleteLinkSetInterfaceBinding() {} -func (s *NetworkService) GetAllLinkSetInterfaceBinding() {} -func (s *NetworkService) GetLinkSetInterfaceBinding() {} -func (s *NetworkService) CountLinkSetInterfaceBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// mapbmr -func (s *NetworkService) AddMAPBMR() {} -func (s *NetworkService) DeleteMAPBMR() {} -func (s *NetworkService) GetAllMAPBMR() {} -func (s *NetworkService) GetMAPBMR() {} -func (s *NetworkService) CountMAPBMR() {} + var result struct { + Data []models.BridgeGroupVLANBinding `json:"bridgegroup_vlan_binding"` + } -// mapbr_binding -func (s *NetworkService) GetAllMAPBMRBinding() {} -func (s *NetworkService) GetMAPBMRBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// mapbmr_bmrv4network_binding -func (s *NetworkService) AddMAPBMRBMRV4NetworkBinding() {} -func (s *NetworkService) DeleteMAPBMRBMRV4NetworkBinding() {} -func (s *NetworkService) GetAllMAPBMRBMRV4NetworkBinding() {} -func (s *NetworkService) GetMAPBMRBMRV4NetworkBinding() {} -func (s *NetworkService) CountMAPBMRBMRV4NetworkBinding() {} + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } -// mapdmr -func (s *NetworkService) AddMAPDMR() {} -func (s *NetworkService) DeleteMAPDMR() {} -func (s *NetworkService) GetAllMAPDMR() {} -func (s *NetworkService) GetMAPDMR() {} -func (s *NetworkService) CountMAPDMR() {} + return &result.Data[0], nil +} -// mapdomain -func (s *NetworkService) AddMAPDomain() {} -func (s *NetworkService) DeleteMAPDomain() {} -func (s *NetworkService) GetAllMAPDomain() {} -func (s *NetworkService) GetMAPDomain() {} -func (s *NetworkService) CountMAPDomain() {} +func (s *NetworkService) CountBridgeGroupVLANBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", bridgeGroupVLANBindingURL), nil) + if err != nil { + return 0, err + } -// mapdomain_binding -func (s *NetworkService) GetAllMAPDomainBinding() {} -func (s *NetworkService) GetMAPDomainBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } -// mapdomain_mapbmr_binding -func (s *NetworkService) AddMAPDomainMAPBMRBinding() {} -func (s *NetworkService) DeleteMAPDomainMAPBMRBinding() {} -func (s *NetworkService) GetAllMAPDomainMAPBMRBinding() {} -func (s *NetworkService) GetMAPDomainMAPBMRBinding() {} -func (s *NetworkService) CountMAPDomainMAPBMRBinding() {} + var result struct { + Data []models.BridgeGroupVLANBinding `json:"bridgegroup_vlan_binding"` + } -// nat64 -func (s *NetworkService) AddNAT64() {} -func (s *NetworkService) DeleteNAT64() {} -func (s *NetworkService) UpdateNAT64() {} -func (s *NetworkService) UnsetNAT64() {} -func (s *NetworkService) GetAllNAT64() {} -func (s *NetworkService) GetNAT64() {} -func (s *NetworkService) CountNAT64() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } -// nat64param -func (s *NetworkService) UpdateNAT64Param() {} -func (s *NetworkService) UnsetNAT64Param() {} -func (s *NetworkService) GetAllNAT64Param() {} -func (s *NetworkService) GetNAT64Param() {} -func (s *NetworkService) CountNAT64Param() {} + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} -// nd6 -func (s *NetworkService) AddND6() {} -func (s *NetworkService) DeleteND6() {} -func (s *NetworkService) ClearND6() {} -func (s *NetworkService) GetAllND6() {} -func (s *NetworkService) CountND6() {} +// bridgetable +func (s *NetworkService) AddBridgeTable(resource models.BridgeTable) error { + payload := map[string]any{"bridgetable": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// nd6ravariables -func (s *NetworkService) UpdateND6RAVariables() {} -func (s *NetworkService) UnsetND6RAVariables() {} -func (s *NetworkService) GetAllND6RAVariables() {} -func (s *NetworkService) GetND6RAVariables() {} -func (s *NetworkService) CountND6RAVariables() {} + req, err := s.client.NewRequest(http.MethodPost, bridgeTableURL, bytes.NewReader(data)) + if err != nil { + return err + } -// nd6ravariables_binding -func (s *NetworkService) GetAllND6RAVariablesBinding() {} -func (s *NetworkService) GetND6RAVariablesBinding() {} + _, err = s.client.Do(req) + return err +} -// nd6ravariables_onlinkipv6prefix_binding -func (s *NetworkService) AddND6RAVariablesOnlinkIPV6PrefixBinding() {} -func (s *NetworkService) DeleteND6RAVariablesOnlinkIPV6PrefixBinding() {} -func (s *NetworkService) GetAllND6RAVariablesOnlinkIPV6PrefixBinding() {} -func (s *NetworkService) GetND6RAVariablesOnlinkIPV6PrefixBinding() {} -func (s *NetworkService) CountND6RAVariablesOnlinkIPV6PrefixBinding() {} +func (s *NetworkService) DeleteBridgeTable(mac string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", bridgeTableURL, mac), nil) + if err != nil { + return err + } -// netbridge -func (s *NetworkService) AddNetBridge() {} -func (s *NetworkService) DeleteNetBridge() {} -func (s *NetworkService) UpdateNetBridge() {} -func (s *NetworkService) UnsetNetBridge() {} -func (s *NetworkService) GetAllNetBridge() {} -func (s *NetworkService) GetNetBridge() {} -func (s *NetworkService) CountNetBridge() {} + _, err = s.client.Do(req) + return err +} -// netbridge_binding -func (s *NetworkService) GetAllNetBridgeBinding() {} -func (s *NetworkService) GetNetBridgeBinding() {} +func (s *NetworkService) UpdateBridgeTable(resource models.BridgeTable) error { + payload := map[string]any{"bridgetable": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// netbridge_iptunnel_binding -func (s *NetworkService) AddNetBridgeIPTunnelBinding() {} -func (s *NetworkService) DeleteNetBridgeIPTunnelBinding() {} -func (s *NetworkService) GetAllNetBridgeIPTunnelBinding() {} -func (s *NetworkService) GetNetBridgeIPTunnelBinding() {} -func (s *NetworkService) CountNetBridgeIPTunnelBinding() {} + req, err := s.client.NewRequest(http.MethodPut, bridgeTableURL, bytes.NewReader(data)) + if err != nil { + return err + } -// netbridge_nsip6_binding -func (s *NetworkService) AddNetBridgeNSIP6Binding() {} -func (s *NetworkService) DeleteNetBridgeNSIP6Binding() {} -func (s *NetworkService) GetAllNetBridgeNSIP6Binding() {} -func (s *NetworkService) GetNetBridgeNSIP6Binding() {} -func (s *NetworkService) CountNetBridgeNSIP6Binding() {} + _, err = s.client.Do(req) + return err +} -// netbridge_nsip_binding -func (s *NetworkService) AddNetBridgeNSIPBinding() {} -func (s *NetworkService) DeleteNetBridgeNSIPBinding() {} -func (s *NetworkService) GetAllNetBridgeNSIPBinding() {} -func (s *NetworkService) GetNetBridgeNSIPBinding() {} -func (s *NetworkService) CountNetBridgeNSIPBinding() {} +func (s *NetworkService) UnsetBridgeTable(resource models.BridgeTable) error { + payload := map[string]any{"bridgetable": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// netbridge_vlan_binding -func (s *NetworkService) AddNetBridgeVLANBinding() {} -func (s *NetworkService) DeleteNetBridgeVLANBinding() {} -func (s *NetworkService) GetAllNetBridgeVLANBinding() {} -func (s *NetworkService) GetNetBridgeVLANBinding() {} -func (s *NetworkService) CountNetBridgeVLANBinding() {} + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", bridgeTableURL), bytes.NewReader(data)) + if err != nil { + return err + } -// netprofile -func (s *NetworkService) AddNetProfile() {} -func (s *NetworkService) DeleteNetProfile() {} -func (s *NetworkService) UpdateNetProfile() {} -func (s *NetworkService) UnsetNetProfile() {} -func (s *NetworkService) GetAllNetProfile() {} -func (s *NetworkService) GetNetProfile() {} -func (s *NetworkService) CountNetProfile() {} + _, err = s.client.Do(req) + return err +} -// netprofile_binding -func (s *NetworkService) GetAllNetProfileBinding() {} -func (s *NetworkService) GetNetProfileBinding() {} +func (s *NetworkService) GetAllBridgeTable() ([]models.BridgeTable, error) { + req, err := s.client.NewRequest(http.MethodGet, bridgeTableURL, nil) + if err != nil { + return nil, err + } -// netprofile_natrule_binding -func (s *NetworkService) AddNetProfileNATRuleBinding() {} -func (s *NetworkService) DeleteNetProfileNATRuleBinding() {} -func (s *NetworkService) GetAllNetProfileNATRuleBinding() {} -func (s *NetworkService) GetNetProfileNATRuleBinding() {} -func (s *NetworkService) CountNetProfileNATRuleBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// netprofile_srcportset_binding -func (s *NetworkService) AddNetProfileSrcPortSetBinding() {} -func (s *NetworkService) DeleteNetProfileSrcPortSetBinding() {} -func (s *NetworkService) GetAllNetProfileSrcPortSetBinding() {} -func (s *NetworkService) GetNetProfileSrcPortSetBinding() {} -func (s *NetworkService) CountNetProfileSrcPortSetBinding() {} + var result struct { + Data []models.BridgeTable `json:"bridgetable"` + } -// onlinkipv6prefix -func (s *NetworkService) AddOnlinkIPV6Prefix() {} -func (s *NetworkService) DeleteOnlinkIPV6Prefix() {} -func (s *NetworkService) UpdateOnlinkIPV6Prefix() {} -func (s *NetworkService) UnsetOnlinkIPV6Prefix() {} -func (s *NetworkService) GetAllOnlinkIPV6Prefix() {} -func (s *NetworkService) GetOnlinkIPV6Prefix() {} -func (s *NetworkService) CountOnlinkIPV6Prefix() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// ptp -func (s *NetworkService) UpdatePTP() {} -func (s *NetworkService) GetAllPTP() {} + return result.Data, nil +} -// rnat -func (s *NetworkService) AddRNAT() {} -func (s *NetworkService) DeleteRNAT() {} -func (s *NetworkService) UpdateRNAT() {} -func (s *NetworkService) UnsetRNAT() {} -func (s *NetworkService) ClearRNAT() {} -func (s *NetworkService) RenameRNAT() {} -func (s *NetworkService) GetAllRNAT() {} -func (s *NetworkService) GetRNAT() {} -func (s *NetworkService) CountRNAT() {} +func (s *NetworkService) CountBridgeTable() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", bridgeTableURL), nil) + if err != nil { + return 0, err + } -// rnat6 -func (s *NetworkService) AddRNAT6() {} -func (s *NetworkService) DeleteRNAT6() {} -func (s *NetworkService) UpdateRNAT6() {} -func (s *NetworkService) UnsetRNAT6() {} -func (s *NetworkService) GetAllRNAT6() {} -func (s *NetworkService) GetRNAT6() {} -func (s *NetworkService) CountRNAT6() {} + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } -// rnat6_binding -func (s *NetworkService) GetAllRNAT6Binding() {} -func (s *NetworkService) GetRNAT6Binding() {} + var result struct { + Data []models.BridgeTable `json:"bridgetable"` + } -// rnat6_nsip6_binding -func (s *NetworkService) AddRNAT6NSIP6Binding() {} -func (s *NetworkService) DeleteRNAT6NSIP6Binding() {} -func (s *NetworkService) GetAllRNAT6NSIP6Binding() {} -func (s *NetworkService) GetRNAT6NSIP6Binding() {} -func (s *NetworkService) CountRNAT6NSIP6Binding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } -// rnatglobal_auditsyslogpolicy_binding -func (s *NetworkService) AddRNATGlobalAuditSyslogPolicyBinding() {} -func (s *NetworkService) DeleteRNATGlobalAuditSyslogPolicyBinding() {} -func (s *NetworkService) GetRNATGlobalAuditSyslogPolicyBinding() {} -func (s *NetworkService) CountRNATGlobalAuditSyslogPolicyBinding() {} + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} -// rnatglobal_binding -func (s *NetworkService) GetRBATGlobalBinding() {} +// channel +func (s *NetworkService) AddChannel(resource models.Channel) error { + payload := map[string]any{"channel": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// rnatparam -func (s *NetworkService) UpdateRNATParam() {} -func (s *NetworkService) UnsetRNATParam() {} -func (s *NetworkService) GetAllRNATParam() {} + req, err := s.client.NewRequest(http.MethodPost, channelURL, bytes.NewReader(data)) + if err != nil { + return err + } -// rnatsession -func (s *NetworkService) FlushRNATSession() {} + _, err = s.client.Do(req) + return err +} -// rnat_binding -func (s *NetworkService) GetAllRNATBinding() {} -func (s *NetworkService) GetRNATBinding() {} +func (s *NetworkService) DeleteChannel(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", channelURL, id), nil) + if err != nil { + return err + } -// rnat_nsip_binding -func (s *NetworkService) AddRNATNSIPBinding() {} -func (s *NetworkService) DeleteRNATNSIPBinding() {} -func (s *NetworkService) GetAllRNATNSIPBinding() {} -func (s *NetworkService) GetRNATNSIPBinding() {} -func (s *NetworkService) CountRNATNSIPBinding() {} + _, err = s.client.Do(req) + return err +} -// rnat_retainsourceportset_binding -func (s *NetworkService) AddRNATRetainSourcePortSetBinding() {} -func (s *NetworkService) DeleteRNATRetainSourcePortSetBinding() {} -func (s *NetworkService) GetAllRNATRetainSourcePortSetBinding() {} -func (s *NetworkService) GetRNATRetainSourcePortSetBinding() {} -func (s *NetworkService) CountRNATRetainSourcePortSetBinding() {} +func (s *NetworkService) UpdateChannel(resource models.Channel) error { + payload := map[string]any{"channel": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// route -func (s *NetworkService) AddRoute() {} -func (s *NetworkService) DeleteRoute() {} -func (s *NetworkService) UpdateRoute() {} -func (s *NetworkService) UnsetRoute() {} -func (s *NetworkService) ClearRoute() {} -func (s *NetworkService) GetAllRoute() {} -func (s *NetworkService) CountRoute() {} + req, err := s.client.NewRequest(http.MethodPut, channelURL, bytes.NewReader(data)) + if err != nil { + return err + } -// route6 -func (s *NetworkService) AddRoute6() {} -func (s *NetworkService) DeleteRoute6() {} -func (s *NetworkService) UpdateRoute6() {} -func (s *NetworkService) UnsetRoute6() {} -func (s *NetworkService) ClearRoute6() {} -func (s *NetworkService) GetAllRoute6() {} -func (s *NetworkService) CountRoute6() {} + _, err = s.client.Do(req) + return err +} -// rsskeytype -func (s *NetworkService) UpdateRSSKeyType() {} -func (s *NetworkService) GetAllRSSKeyType() {} +func (s *NetworkService) UnsetChannel(resource models.Channel) error { + payload := map[string]any{"channel": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// vlan -func (s *NetworkService) AddVLAN() {} -func (s *NetworkService) DeleteVLAN() {} -func (s *NetworkService) UpdateVLAN() {} -func (s *NetworkService) UnsetVLAN() {} -func (s *NetworkService) GetAllVLAN() {} -func (s *NetworkService) GetVLAN() {} -func (s *NetworkService) CountVLAN() {} + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", channelURL), bytes.NewReader(data)) + if err != nil { + return err + } -// vlan_binding -func (s *NetworkService) GetAllVLANBinding() {} -func (s *NetworkService) GetVLANBinding() {} + _, err = s.client.Do(req) + return err +} -// vlan_channel_binding -func (s *NetworkService) AddVLANChannelBinding() {} -func (s *NetworkService) DeleteVLANChannelBinding() {} -func (s *NetworkService) GetAllVLANChannelBinding() {} -func (s *NetworkService) GetVLANChannelBinding() {} -func (s *NetworkService) CountVLANChannelBinding() {} +func (s *NetworkService) GetAllChannel() ([]models.Channel, error) { + req, err := s.client.NewRequest(http.MethodGet, channelURL, nil) + if err != nil { + return nil, err + } -// vlan_interface_binding -func (s *NetworkService) AddVLANInterfaceBinding() {} -func (s *NetworkService) DeleteVLANInterfaceBinding() {} -func (s *NetworkService) GetAllVLANInterfaceBinding() {} -func (s *NetworkService) GetVLANInterfaceBinding() {} -func (s *NetworkService) CountVLANInterfaceBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// vlan_linkset_binding -func (s *NetworkService) AddVLANLinkSetBinding() {} -func (s *NetworkService) DeleteVLANLinkSetBinding() {} -func (s *NetworkService) GetAllVLANLinkSetBinding() {} -func (s *NetworkService) GetVLANLinkSetBinding() {} -func (s *NetworkService) CountVLANLinkSetBinding() {} + var result struct { + Data []models.Channel `json:"channel"` + } -// vlan_nsip6_binding -func (s *NetworkService) AddVLANNSIP6Binding() {} -func (s *NetworkService) DeleteVLANNSIP6Binding() {} -func (s *NetworkService) GetAllVLANNSIP6Binding() {} -func (s *NetworkService) GetVLANNSIP6Binding() {} -func (s *NetworkService) CountVLANNSIP6Binding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// vlan_nsip_binding -func (s *NetworkService) AddVLANNSIPBinding() {} -func (s *NetworkService) DeleteVLANNSIPBinding() {} -func (s *NetworkService) GetAllVLANNSIPBinding() {} -func (s *NetworkService) GetVLANNSIPBinding() {} -func (s *NetworkService) CountVLANNSIPBinding() {} + return result.Data, nil +} -// vrid -func (s *NetworkService) AddVRID() {} -func (s *NetworkService) DeleteVRID() {} -func (s *NetworkService) UpdateVRID() {} -func (s *NetworkService) UnsetVRID() {} -func (s *NetworkService) GetAllVRID() {} -func (s *NetworkService) GetVRID() {} -func (s *NetworkService) CountVRID() {} +func (s *NetworkService) GetChannel(id string) (*models.Channel, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", channelURL, id), nil) + if err != nil { + return nil, err + } -// vrid6 -func (s *NetworkService) AddVRID6() {} -func (s *NetworkService) DeleteVRID6() {} -func (s *NetworkService) UpdateVRID6() {} -func (s *NetworkService) UnsetVRID6() {} -func (s *NetworkService) GetAllVRID6() {} -func (s *NetworkService) GetVRID6() {} -func (s *NetworkService) CountVRID6() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// vrid6_binding -func (s *NetworkService) GetAllVRID6Biding() {} -func (s *NetworkService) GetVRID6Biding() {} + var result struct { + Data []models.Channel `json:"channel"` + } -// vrid6_channel_binding -func (s *NetworkService) AddVRID6ChannelBinding() {} -func (s *NetworkService) DeleteVRID6ChannelBinding() {} -func (s *NetworkService) GetAllVRID6ChannelBinding() {} -func (s *NetworkService) GetVRID6ChannelBinding() {} -func (s *NetworkService) CountVRID6ChannelBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// vrid6_interface_binding -func (s *NetworkService) AddVRID6InterfaceBinding() {} -func (s *NetworkService) DeleteVRID6InterfaceBinding() {} -func (s *NetworkService) GetAllVRID6InterfaceBinding() {} -func (s *NetworkService) GetVRID6InterfaceBinding() {} -func (s *NetworkService) CountVRID6InterfaceBinding() {} + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } -// vrid6_nsip6_binding -func (s *NetworkService) GetAllVRID6NSIP6Binding() {} -func (s *NetworkService) GetVRID6NSIP6Binding() {} -func (s *NetworkService) CountVRID6NSIP6Binding() {} + return &result.Data[0], nil +} -// vrid6_nsip_binding -func (s *NetworkService) GetAllVRID6NSIPBinding() {} -func (s *NetworkService) GetVRID6NSIPBinding() {} -func (s *NetworkService) CountVRID6NSIPBinding() {} +func (s *NetworkService) CountChannel() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", channelURL), nil) + if err != nil { + return 0, err + } -// vrid6_trackinterface_binding -func (s *NetworkService) AddVRID6TrackInterfaceBinding() {} -func (s *NetworkService) DeleteVRID6TrackInterfaceBinding() {} -func (s *NetworkService) GetAllVRID6TrackInterfaceBinding() {} -func (s *NetworkService) GetVRID6TrackInterfaceBinding() {} -func (s *NetworkService) CountVRID6TrackInterfaceBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } -// vridparam -func (s *NetworkService) UpdateVRIDParam() {} -func (s *NetworkService) UnsetVRIDParam() {} -func (s *NetworkService) GetAllVRIDParam() {} + var result struct { + Data []models.Channel `json:"channel"` + } -// vrid_binding -func (s *NetworkService) GetAllVRIDBinding() {} -func (s *NetworkService) GetVRIDBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } -// vrid_channel_binding -func (s *NetworkService) AddVRIDChannelBinding() {} -func (s *NetworkService) DeleteVRIDChannelBinding() {} -func (s *NetworkService) GetAllVRIDChannelBinding() {} -func (s *NetworkService) GetVRIDChannelBinding() {} -func (s *NetworkService) CountVRIDChannelBinding() {} + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} -// vrid_interface_binding -func (s *NetworkService) AddVRIDInterfaceBinding() {} -func (s *NetworkService) DeleteVRIDInterfaceBinding() {} -func (s *NetworkService) GetAllVRIDInterfaceBinding() {} -func (s *NetworkService) GetVRIDInterfaceBinding() {} -func (s *NetworkService) CountVRIDInterfaceBinding() {} +// channel_binding +func (s *NetworkService) GetAllChannelBinding() ([]models.ChannelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, channelBindingURL, nil) + if err != nil { + return nil, err + } -// vrid_nsip6_binding -func (s *NetworkService) GetAllVRIDNSIP6Binding() {} -func (s *NetworkService) GetVRIDNSIP6Binding() {} -func (s *NetworkService) CountVRIDNSIP6Binding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// vrid_nsip_binding -func (s *NetworkService) GetAllVRIDNSIPBinding() {} -func (s *NetworkService) GetVRIDNSIPBinding() {} -func (s *NetworkService) CountVRIDNSIPBinding() {} + var result struct { + Data []models.ChannelBinding `json:"channel_binding"` + } -// vrid_trackinterface_binding -func (s *NetworkService) AddVRIDTrackInterfaceBinding() {} -func (s *NetworkService) DeleteVRIDTrackInterfaceBinding() {} -func (s *NetworkService) GetAllVRIDTrackInterfaceBinding() {} -func (s *NetworkService) GetVRIDTrackInterfaceBinding() {} -func (s *NetworkService) CountVRIDTrackInterfaceBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// vxlan -func (s *NetworkService) AddVXLAN() {} -func (s *NetworkService) DeleteVXLAN() {} -func (s *NetworkService) UpdateVXLAN() {} -func (s *NetworkService) UnsetVXLAN() {} -func (s *NetworkService) GetAllVXLAN() {} -func (s *NetworkService) GetVXLAN() {} -func (s *NetworkService) CountVXLAN() {} + return result.Data, nil +} -// vxlanvlanmap -func (s *NetworkService) AddVXLANVLANMap() {} -func (s *NetworkService) DeleteVXLANVLANMap() {} -func (s *NetworkService) GetAllVXLANVLANMap() {} -func (s *NetworkService) GetVXLANVLANMap() {} -func (s *NetworkService) CountVXLANVLANMap() {} +func (s *NetworkService) GetChannelBinding(id string) (*models.ChannelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", channelBindingURL, id), nil) + if err != nil { + return nil, err + } -// vxlanvlanmap_binding -func (s *NetworkService) GetAllVXLANVLANMapBinding() {} -func (s *NetworkService) GetVXLANVLANMapBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// vxlanvlanmap_vxlan_binding -func (s *NetworkService) AddVXLANVLANMapVXLANBinding() {} -func (s *NetworkService) DeleteVXLANVLANMapVXLANBinding() {} -func (s *NetworkService) GetAllVXLANVLANMapVXLANBinding() {} -func (s *NetworkService) GetVXLANVLANMapVXLANBinding() {} -func (s *NetworkService) CountVXLANVLANMapVXLANBinding() {} + var result struct { + Data []models.ChannelBinding `json:"channel_binding"` + } -// vxlan_binding -func (s *NetworkService) GetAllVXLANBinding() {} -func (s *NetworkService) GetVXLANBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// vxlan_iptunnel_binding -func (s *NetworkService) GetAllVXLANIPTunnelBinding() {} -func (s *NetworkService) GetVXLANIPTunnelBinding() {} -func (s *NetworkService) CountVXLANIPTunnelBinding() {} + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } -// vxlan_nsip6_binding -func (s *NetworkService) AddVXLANNSIP6Binding() {} -func (s *NetworkService) DeleteVXLANNSIP6Binding() {} -func (s *NetworkService) GetAllVXLANNSIP6Binding() {} -func (s *NetworkService) GetVXLANNSIP6Binding() {} -func (s *NetworkService) CountVXLANNSIP6Binding() {} + return &result.Data[0], nil +} -// vxlan_nsip_binding -func (s *NetworkService) AddVXLANNSIPBinding() {} -func (s *NetworkService) DeleteVXLANNSIPBinding() {} -func (s *NetworkService) GetAllVXLANNSIPBinding() {} -func (s *NetworkService) GetVXLANNSIPBinding() {} -func (s *NetworkService) CountVXLANNSIPBinding() {} +// channel_interface_binding +func (s *NetworkService) AddChannelInterfaceBinding(resource models.ChannelInterfaceBinding) error { + payload := map[string]any{"channel_interface_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// vxlan_srcip_binding -func (s *NetworkService) AddVXLANSrcIPBinding() {} -func (s *NetworkService) DeleteVXLANSrcIPBinding() {} -func (s *NetworkService) GetAllVXLANSrcIPBinding() {} -func (s *NetworkService) GetVXLANSrcIPBinding() {} -func (s *NetworkService) CountVXLANSrcIPBinding() {} + req, err := s.client.NewRequest(http.MethodPost, channelInterfaceBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteChannelInterfaceBinding(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", channelInterfaceBindingURL, id), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllChannelInterfaceBinding() ([]models.ChannelInterfaceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, channelInterfaceBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.ChannelInterfaceBinding `json:"channel_interface_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetChannelInterfaceBinding(id string) (*models.ChannelInterfaceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", channelInterfaceBindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.ChannelInterfaceBinding `json:"channel_interface_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountChannelInterfaceBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", channelInterfaceBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.ChannelInterfaceBinding `json:"channel_interface_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// ci +func (s *NetworkService) GetAllCI() ([]models.CI, error) { + req, err := s.client.NewRequest(http.MethodGet, ciURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.CI `json:"ci"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) CountCI() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", ciURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.CI `json:"ci"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// fis +func (s *NetworkService) AddFIS(resource models.FIS) error { + payload := map[string]any{"fis": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fisURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteFIS(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", fisURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllFIS() ([]models.FIS, error) { + req, err := s.client.NewRequest(http.MethodGet, fisURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.FIS `json:"fis"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetFIS(name string) (*models.FIS, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", fisURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.FIS `json:"fis"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountFIS() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", fisURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.FIS `json:"fis"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// fis_binding +func (s *NetworkService) GetAllFISBinding() ([]models.FISBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fisBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.FISBinding `json:"fis_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetFISBinding(name string) (*models.FISBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", fisBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.FISBinding `json:"fis_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +// fis_channel_binding +func (s *NetworkService) AddFISChannelBinding(resource models.FISChannelBinding) error { + payload := map[string]any{"fis_channel_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fisChannelBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteFISChannelBinding(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", fisChannelBindingURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllFISChannelBinding() ([]models.FISChannelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fisChannelBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.FISChannelBinding `json:"fis_channel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetFISChannelBinding(name string) (*models.FISChannelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", fisChannelBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.FISChannelBinding `json:"fis_channel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountFISChannelBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", fisChannelBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.FISChannelBinding `json:"fis_channel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// fis_interface_binding +func (s *NetworkService) AddFISInterfaceBinding(resource models.FISInterfaceBinding) error { + payload := map[string]any{"fis_interface_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fisInterfaceBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteFISInterfaceBinding(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", fisInterfaceBindingURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// forwardingsession +func (s *NetworkService) AddFowardingSession(resource models.ForwardingSession) error { + payload := map[string]any{"forwardingsession": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, forwardingSessionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteFowardingSession(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", forwardingSessionURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UpdateFowardingSession(resource models.ForwardingSession) error { + payload := map[string]any{"forwardingsession": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, forwardingSessionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllFowardingSession() ([]models.ForwardingSession, error) { + req, err := s.client.NewRequest(http.MethodGet, forwardingSessionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.ForwardingSession `json:"forwardingsession"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetFowardingSession(name string) (*models.ForwardingSession, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", forwardingSessionURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.ForwardingSession `json:"forwardingsession"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountFowardingSession() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", forwardingSessionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.ForwardingSession `json:"forwardingsession"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// inat +func (s *NetworkService) AddINAT(resource models.INAT) error { + payload := map[string]any{"inat": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, inatURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteINAT(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", inatURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UpdateINAT(resource models.INAT) error { + payload := map[string]any{"inat": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, inatURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetINAT(resource models.INAT) error { + payload := map[string]any{"inat": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", inatURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllINAT() ([]models.INAT, error) { + req, err := s.client.NewRequest(http.MethodGet, inatURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.INAT `json:"inat"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetINAT(name string) (*models.INAT, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", inatURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.INAT `json:"inat"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountINAT() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", inatURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.INAT `json:"inat"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// inatparam +func (s *NetworkService) UpdateINATParam(resource models.INATParam) error { + payload := map[string]any{"inatparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, inatParamURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetINATParam(resource models.INATParam) error { + payload := map[string]any{"inatparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", inatParamURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllINATParam() ([]models.INATParam, error) { + req, err := s.client.NewRequest(http.MethodGet, inatParamURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.INATParam `json:"inatparam"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetINATParam(name string) (*models.INATParam, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", inatParamURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.INATParam `json:"inatparam"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountINATParam() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", inatParamURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.INATParam `json:"inatparam"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// interface +func (s *NetworkService) ClearInterface(id string) error { + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=clear", interfaceURL), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UpdateInterface(resource models.Interface) error { + payload := map[string]any{"interface": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, interfaceURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetInterface(resource models.Interface) error { + payload := map[string]any{"interface": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", interfaceURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) EnableInterface(resource models.Interface) error { + payload := map[string]any{"interface": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=enable", interfaceURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DisableInterface(resource models.Interface) error { + payload := map[string]any{"interface": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=disable", interfaceURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) ResetInterface(resource models.Interface) error { + payload := map[string]any{"interface": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=reset", interfaceURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllInterface() ([]models.Interface, error) { + req, err := s.client.NewRequest(http.MethodGet, interfaceURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.Interface `json:"interface"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetInterface(id string) (*models.Interface, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", interfaceURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.Interface `json:"interface"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountInterface() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", interfaceURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.Interface `json:"interface"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// interfacepair +func (s *NetworkService) AddInterfacePair(resource models.InterfacePair) error { + payload := map[string]any{"interfacepair": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, interfacePairURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteInterfacePair(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", interfacePairURL, id), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllInterfacePair() ([]models.InterfacePair, error) { + req, err := s.client.NewRequest(http.MethodGet, interfacePairURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.InterfacePair `json:"interfacepair"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetInterfacePair(id string) (*models.InterfacePair, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", interfacePairURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.InterfacePair `json:"interfacepair"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountInterfacePair() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", interfacePairURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.InterfacePair `json:"interfacepair"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// ip6tunnel +func (s *NetworkService) AddIP6Tunnel(resource models.IP6Tunnel) error { + payload := map[string]any{"ip6tunnel": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, ip6TunnelURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteIP6Tunnel(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", ip6TunnelURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllIP6Tunnel() ([]models.IP6Tunnel, error) { + req, err := s.client.NewRequest(http.MethodGet, ip6TunnelURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.IP6Tunnel `json:"ip6tunnel"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetIP6Tunnel(name string) (*models.IP6Tunnel, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", ip6TunnelURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.IP6Tunnel `json:"ip6tunnel"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountIP6Tunnel() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", ip6TunnelURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.IP6Tunnel `json:"ip6tunnel"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// ip6tunnelparam +func (s *NetworkService) UpdateIP6TunnelParam(resource models.IP6TunnelParam) error { + payload := map[string]any{"ip6tunnelparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, ip6TunnelParamURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetIP6TunnelParam(resource models.IP6TunnelParam) error { + payload := map[string]any{"ip6tunnelparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", ip6TunnelParamURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllIP6TunnelParam() ([]models.IP6TunnelParam, error) { + req, err := s.client.NewRequest(http.MethodGet, ip6TunnelParamURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.IP6TunnelParam `json:"ip6tunnelparam"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// ipset +func (s *NetworkService) AddIPSet(resource models.IPSet) error { + payload := map[string]any{"ipset": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, ipSetURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteIPSet(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", ipSetURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllIPSet() ([]models.IPSet, error) { + req, err := s.client.NewRequest(http.MethodGet, ipSetURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.IPSet `json:"ipset"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetIPSet(name string) (*models.IPSet, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", ipSetURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.IPSet `json:"ipset"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountIPSet() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", ipSetURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.IPSet `json:"ipset"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// ipset_binding +func (s *NetworkService) GetAllIPSetBinding() ([]models.IPSetBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, ipSetBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.IPSetBinding `json:"ipset_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetIPSetBinding(name string) (*models.IPSetBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", ipSetBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.IPSetBinding `json:"ipset_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +// ipset_nsip6_binding +func (s *NetworkService) AddIPSetNSIP6Binding(resource models.IPSetNSIP6Binding) error { + payload := map[string]any{"ipset_nsip6_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, ipSetNSIP6BindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteIPSetNSIP6Binding(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", ipSetNSIP6BindingURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllIPSetNSIP6Binding() ([]models.IPSetNSIP6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, ipSetNSIP6BindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.IPSetNSIP6Binding `json:"ipset_nsip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetIPSetNSIP6Binding(name string) (*models.IPSetNSIP6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", ipSetNSIP6BindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.IPSetNSIP6Binding `json:"ipset_nsip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountIPSetNSIP6Binding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", ipSetNSIP6BindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.IPSetNSIP6Binding `json:"ipset_nsip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// ipset_nsip_binding +func (s *NetworkService) AddIPSetNSIPBinding(resource models.IPSetNSIPBinding) error { + payload := map[string]any{"ipset_nsip_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, ipSetNSIPBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteIPSetNSIPBinding(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", ipSetNSIPBindingURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllIPSetNSIPBinding() ([]models.IPSetNSIPBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, ipSetNSIPBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.IPSetNSIPBinding `json:"ipset_nsip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetIPSetNSIPBinding(name string) (*models.IPSetNSIPBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", ipSetNSIPBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.IPSetNSIPBinding `json:"ipset_nsip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountIPSetNSIPBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", ipSetNSIPBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.IPSetNSIPBinding `json:"ipset_nsip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// iptunnel +func (s *NetworkService) AddIPTunnel(resource models.IPTunnel) error { + payload := map[string]any{"iptunnel": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, ipTunnelURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteIPTunnel(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", ipTunnelURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UpdateIPTunnel(resource models.IPTunnel) error { + payload := map[string]any{"iptunnel": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, ipTunnelURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetIPTunnel(resource models.IPTunnel) error { + payload := map[string]any{"iptunnel": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", ipTunnelURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllIPTunnel() ([]models.IPTunnel, error) { + req, err := s.client.NewRequest(http.MethodGet, ipTunnelURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.IPTunnel `json:"iptunnel"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetIPTunnel(name string) (*models.IPTunnel, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", ipTunnelURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.IPTunnel `json:"iptunnel"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountIPTunnel() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", ipTunnelURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.IPTunnel `json:"iptunnel"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// iptunnelparam +func (s *NetworkService) UpdateIPTunnelParam(resource models.IPTunnelParam) error { + payload := map[string]any{"iptunnelparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, ipTunnelParamURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetIPTunnelParam(resource models.IPTunnelParam) error { + payload := map[string]any{"iptunnelparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", ipTunnelParamURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllIPTunnelParam() ([]models.IPTunnelParam, error) { + req, err := s.client.NewRequest(http.MethodGet, ipTunnelParamURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.IPTunnelParam `json:"iptunnelparam"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// ipv6 +func (s *NetworkService) UpdateIPV6(resource models.IPv6) error { + payload := map[string]any{"ipv6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, ipv6URL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetIPV6(resource models.IPv6) error { + payload := map[string]any{"ipv6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", ipv6URL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllIPV6() ([]models.IPv6, error) { + req, err := s.client.NewRequest(http.MethodGet, ipv6URL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.IPv6 `json:"ipv6"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetIPV6(dodad string) (*models.IPv6, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", ipv6URL, dodad), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.IPv6 `json:"ipv6"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountIPV6() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", ipv6URL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.IPv6 `json:"ipv6"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// l2param +func (s *NetworkService) UpdateL2Param(resource models.L2Param) error { + payload := map[string]any{"l2param": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, l2ParamURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetL2Param(resource models.L2Param) error { + payload := map[string]any{"l2param": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", l2ParamURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllL2Param() ([]models.L2Param, error) { + req, err := s.client.NewRequest(http.MethodGet, l2ParamURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.L2Param `json:"l2param"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// l3param +func (s *NetworkService) UpdateL3Param(resource models.L3Param) error { + payload := map[string]any{"l3param": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, l3ParamURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetL3Param(resource models.L3Param) error { + payload := map[string]any{"l3param": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", l3ParamURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllL3Param() ([]models.L3Param, error) { + req, err := s.client.NewRequest(http.MethodGet, l3ParamURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.L3Param `json:"l3param"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// l4param +func (s *NetworkService) UpdateL4Param(resource models.L4Param) error { + payload := map[string]any{"l4param": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, l4ParamURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetL4Param(resource models.L4Param) error { + payload := map[string]any{"l4param": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", l4ParamURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllL4Param() ([]models.L4Param, error) { + req, err := s.client.NewRequest(http.MethodGet, l4ParamURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.L4Param `json:"l4param"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// lacp +func (s *NetworkService) UpdateLACP(resource models.LACP) error { + payload := map[string]any{"lacp": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, lacpURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllLACP() ([]models.LACP, error) { + req, err := s.client.NewRequest(http.MethodGet, lacpURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LACP `json:"lacp"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetLACP(syspriority string) (*models.LACP, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", lacpURL, syspriority), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LACP `json:"lacp"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountLACP() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", lacpURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LACP `json:"lacp"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// linkset +func (s *NetworkService) AddLinkSet(resource models.LinkSet) error { + payload := map[string]any{"linkset": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, linkSetURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteLinkSet(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", linkSetURL, id), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllLinkSet() ([]models.LinkSet, error) { + req, err := s.client.NewRequest(http.MethodGet, linkSetURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LinkSet `json:"linkset"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetLinkSet(id string) (*models.LinkSet, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", linkSetURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LinkSet `json:"linkset"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountLinkSet() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", linkSetURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LinkSet `json:"linkset"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// linkset_binding +func (s *NetworkService) GetAllLinkSetBinding() ([]models.LinkSetBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, linkSetBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LinkSetBinding `json:"linkset_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetLinkSetBinding(id string) (*models.LinkSetBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", linkSetBindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LinkSetBinding `json:"linkset_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +// linkset_channel_binding +func (s *NetworkService) AddLinkSetChannelBinding(resource models.LinkSetChannelBinding) error { + payload := map[string]any{"linkset_channel_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, linkSetChannelBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteLinkSetChannelBinding(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", linkSetChannelBindingURL, id), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllLinkSetChannelBinding() ([]models.LinkSetChannelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, linkSetChannelBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LinkSetChannelBinding `json:"linkset_channel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetLinkSetChannelBinding(id string) (*models.LinkSetChannelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", linkSetChannelBindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LinkSetChannelBinding `json:"linkset_channel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountLinkSetChannelBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", linkSetChannelBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LinkSetChannelBinding `json:"linkset_channel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// linkset_interface_binding +func (s *NetworkService) AddLinkSetInterfaceBinding(resource models.LinkSetInterfaceBinding) error { + payload := map[string]any{"linkset_interface_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, linkSetInterfaceBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteLinkSetInterfaceBinding(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", linkSetInterfaceBindingURL, id), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllLinkSetInterfaceBinding() ([]models.LinkSetInterfaceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, linkSetInterfaceBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LinkSetInterfaceBinding `json:"linkset_interface_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetLinkSetInterfaceBinding(id string) (*models.LinkSetInterfaceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", linkSetInterfaceBindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.LinkSetInterfaceBinding `json:"linkset_interface_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountLinkSetInterfaceBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", linkSetInterfaceBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.LinkSetInterfaceBinding `json:"linkset_interface_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// mapbmr +func (s *NetworkService) AddMAPBMR(resource models.MapBMR) error { + payload := map[string]any{"mapbmr": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, mapBMRURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteMAPBMR(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", mapBMRURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllMAPBMR() ([]models.MapBMR, error) { + req, err := s.client.NewRequest(http.MethodGet, mapBMRURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.MapBMR `json:"mapbmr"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetMAPBMR(name string) (*models.MapBMR, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", mapBMRURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.MapBMR `json:"mapbmr"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountMAPBMR() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", mapBMRURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.MapBMR `json:"mapbmr"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// mapbmr_binding +func (s *NetworkService) GetAllMAPBMRBinding() ([]models.MapBMRBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, mapBMRBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.MapBMRBinding `json:"mapbmr_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetMAPBMRBinding(name string) (*models.MapBMRBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", mapBMRBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.MapBMRBinding `json:"mapbmr_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +// mapbmr_bmrv4network_binding +func (s *NetworkService) AddMAPBMRBMRV4NetworkBinding(resource models.MapBMRBMRV4NetworkBinding) error { + payload := map[string]any{"mapbmr_bmrv4network_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, mapBMRBMRV4NetworkBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteMAPBMRBMRV4NetworkBinding(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", mapBMRBMRV4NetworkBindingURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllMAPBMRBMRV4NetworkBinding() ([]models.MapBMRBMRV4NetworkBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, mapBMRBMRV4NetworkBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.MapBMRBMRV4NetworkBinding `json:"mapbmr_bmrv4network_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetMAPBMRBMRV4NetworkBinding(name string) (*models.MapBMRBMRV4NetworkBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", mapBMRBMRV4NetworkBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.MapBMRBMRV4NetworkBinding `json:"mapbmr_bmrv4network_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountMAPBMRBMRV4NetworkBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", mapBMRBMRV4NetworkBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.MapBMRBMRV4NetworkBinding `json:"mapbmr_bmrv4network_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// mapdmr +func (s *NetworkService) AddMAPDMR(resource models.MapDMR) error { + payload := map[string]any{"mapdmr": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, mapDMRURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteMAPDMR(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", mapDMRURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllMAPDMR() ([]models.MapDMR, error) { + req, err := s.client.NewRequest(http.MethodGet, mapDMRURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.MapDMR `json:"mapdmr"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetMAPDMR(name string) (*models.MapDMR, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", mapDMRURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.MapDMR `json:"mapdmr"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} +func (s *NetworkService) CountMAPDMR() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", mapDMRURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.MapDMR `json:"mapdmr"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// mapdomain +func (s *NetworkService) AddMAPDomain(resource models.MapDomain) error { + payload := map[string]any{"mapdomain": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, mapDomainURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteMAPDomain(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", mapDomainURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllMAPDomain() ([]models.MapDomain, error) { + req, err := s.client.NewRequest(http.MethodGet, mapDomainURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.MapDomain `json:"mapdomain"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetMAPDomain(name string) (*models.MapDomain, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", mapDomainURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.MapDomain `json:"mapdomain"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountMAPDomain() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", mapDomainURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.MapDomain `json:"mapdomain"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// mapdomain_binding +func (s *NetworkService) GetAllMAPDomainBinding() ([]models.MapDomainBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, mapDomainBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.MapDomainBinding `json:"mapdomain_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetMAPDomainBinding(name string) (*models.MapDomainBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", mapDomainBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.MapDomainBinding `json:"mapdomain_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +// mapdomain_mapbmr_binding +func (s *NetworkService) AddMAPDomainMAPBMRBinding(resource models.MapDomainMapBMRBinding) error { + payload := map[string]any{"mapdomain_mapbmr_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, mapDomainMapBMRBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteMAPDomainMAPBMRBinding(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", mapDomainMapBMRBindingURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllMAPDomainMAPBMRBinding() ([]models.MapDomainMapBMRBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, mapDomainMapBMRBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.MapDomainMapBMRBinding `json:"mapdomain_mapbmr_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetMAPDomainMAPBMRBinding(name string) (*models.MapDomainMapBMRBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", mapDomainMapBMRBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.MapDomainMapBMRBinding `json:"mapdomain_mapbmr_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountMAPDomainMAPBMRBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", mapDomainMapBMRBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.MapDomainMapBMRBinding `json:"mapdomain_mapbmr_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nat64 +func (s *NetworkService) AddNAT64(resource models.NAT64) error { + payload := map[string]any{"nat64": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nat64URL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteNAT64(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nat64URL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UpdateNAT64(resource models.NAT64) error { + payload := map[string]any{"nat64": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nat64URL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetNAT64(resource models.NAT64) error { + payload := map[string]any{"nat64": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nat64URL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllNAT64() ([]models.NAT64, error) { + req, err := s.client.NewRequest(http.MethodGet, nat64URL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NAT64 `json:"nat64"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetNAT64(name string) (*models.NAT64, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nat64URL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NAT64 `json:"nat64"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountNAT64() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nat64URL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NAT64 `json:"nat64"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nat64param +func (s *NetworkService) UpdateNAT64Param(resource models.NAT64Param) error { + payload := map[string]any{"nat64param": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nat64ParamURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetNAT64Param(resource models.NAT64Param) error { + payload := map[string]any{"nat64param": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nat64ParamURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllNAT64Param() ([]models.NAT64Param, error) { + req, err := s.client.NewRequest(http.MethodGet, nat64ParamURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NAT64Param `json:"nat64param"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetNAT64Param() (*models.NAT64Param, error) { + req, err := s.client.NewRequest(http.MethodGet, nat64ParamURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NAT64Param `json:"nat64param"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountNAT64Param() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nat64ParamURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NAT64Param `json:"nat64param"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nd6 +func (s *NetworkService) AddND6(resource models.ND6) error { + payload := map[string]any{"nd6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nd6URL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteND6(neighbor string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nd6URL, neighbor), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) ClearND6(neighbor string) error { + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=clear", nd6URL), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllND6() ([]models.ND6, error) { + req, err := s.client.NewRequest(http.MethodGet, nd6URL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.ND6 `json:"nd6"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} +func (s *NetworkService) CountND6() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nd6URL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.ND6 `json:"nd6"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nd6ravariables +func (s *NetworkService) UpdateND6RAVariables(resource models.ND6RAVariables) error { + payload := map[string]any{"nd6ravariables": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nd6RAVariablesURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetND6RAVariables(resource models.ND6RAVariables) error { + payload := map[string]any{"nd6ravariables": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nd6RAVariablesURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllND6RAVariables() ([]models.ND6RAVariables, error) { + req, err := s.client.NewRequest(http.MethodGet, nd6RAVariablesURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.ND6RAVariables `json:"nd6ravariables"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetND6RAVariables(vlan string) (*models.ND6RAVariables, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nd6RAVariablesURL, vlan), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.ND6RAVariables `json:"nd6ravariables"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountND6RAVariables() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nd6RAVariablesURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.ND6RAVariables `json:"nd6ravariables"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nd6ravariables_binding +func (s *NetworkService) GetAllND6RAVariablesBinding() ([]models.ND6RAVariablesBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, nd6RAVariablesBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.ND6RAVariablesBinding `json:"nd6ravariables_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetND6RAVariablesBinding(vlan string) (*models.ND6RAVariablesBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nd6RAVariablesBindingURL, vlan), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.ND6RAVariablesBinding `json:"nd6ravariables_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +// nd6ravariables_onlinkipv6prefix_binding +func (s *NetworkService) AddND6RAVariablesOnlinkIPV6PrefixBinding(resource models.ND6RAVariablesOnLinkIPv6PrefixBinding) error { + payload := map[string]any{"nd6ravariables_onlinkipv6prefix_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nd6RAVariablesOnLinkIPV6PrefixBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteND6RAVariablesOnlinkIPV6PrefixBinding(vlan string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nd6RAVariablesOnLinkIPV6PrefixBindingURL, vlan), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllND6RAVariablesOnlinkIPV6PrefixBinding() ([]models.ND6RAVariablesOnLinkIPv6PrefixBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, nd6RAVariablesOnLinkIPV6PrefixBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.ND6RAVariablesOnLinkIPv6PrefixBinding `json:"nd6ravariables_onlinkipv6prefix_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetND6RAVariablesOnlinkIPV6PrefixBinding(vlan string) (*models.ND6RAVariablesOnLinkIPv6PrefixBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nd6RAVariablesOnLinkIPV6PrefixBindingURL, vlan), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.ND6RAVariablesOnLinkIPv6PrefixBinding `json:"nd6ravariables_onlinkipv6prefix_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountND6RAVariablesOnlinkIPV6PrefixBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nd6RAVariablesOnLinkIPV6PrefixBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.ND6RAVariablesOnLinkIPv6PrefixBinding `json:"nd6ravariables_onlinkipv6prefix_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// netbridge +func (s *NetworkService) AddNetBridge(resource models.NetBridge) error { + payload := map[string]any{"netbridge": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, netBridgeURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteNetBridge(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", netBridgeURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UpdateNetBridge(resource models.NetBridge) error { + payload := map[string]any{"netbridge": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, netBridgeURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetNetBridge(resource models.NetBridge) error { + payload := map[string]any{"netbridge": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", netBridgeURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllNetBridge() ([]models.NetBridge, error) { + req, err := s.client.NewRequest(http.MethodGet, netBridgeURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NetBridge `json:"netbridge"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetNetBridge(name string) (*models.NetBridge, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", netBridgeURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NetBridge `json:"netbridge"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountNetBridge() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", netBridgeURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NetBridge `json:"netbridge"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// netbridge_binding +func (s *NetworkService) GetAllNetBridgeBinding() ([]models.NetBridgeBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, netBridgeBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NetBridgeBinding `json:"netbridge_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetNetBridgeBinding(name string) (*models.NetBridgeBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", netBridgeBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NetBridgeBinding `json:"netbridge_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +// netbridge_iptunnel_binding +func (s *NetworkService) AddNetBridgeIPTunnelBinding(resource models.NetBridgeIPTunnelBinding) error { + payload := map[string]any{"netbridge_iptunnel_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, netBridgeIPTunnelBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteNetBridgeIPTunnelBinding(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", netBridgeIPTunnelBindingURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllNetBridgeIPTunnelBinding() ([]models.NetBridgeIPTunnelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, netBridgeIPTunnelBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NetBridgeIPTunnelBinding `json:"netbridge_iptunnel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetNetBridgeIPTunnelBinding(name string) (*models.NetBridgeIPTunnelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", netBridgeIPTunnelBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NetBridgeIPTunnelBinding `json:"netbridge_iptunnel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountNetBridgeIPTunnelBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", netBridgeIPTunnelBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NetBridgeIPTunnelBinding `json:"netbridge_iptunnel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// netbridge_nsip6_binding +func (s *NetworkService) AddNetBridgeNSIP6Binding(resource models.NetBridgeNSIP6Binding) error { + payload := map[string]any{"netbridge_nsip6_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, netBridgeNSIP6BindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteNetBridgeNSIP6Binding(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", netBridgeNSIP6BindingURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllNetBridgeNSIP6Binding() ([]models.NetBridgeNSIP6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, netBridgeNSIP6BindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NetBridgeNSIP6Binding `json:"netbridge_nsip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetNetBridgeNSIP6Binding(name string) (*models.NetBridgeNSIP6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", netBridgeNSIP6BindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NetBridgeNSIP6Binding `json:"netbridge_nsip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountNetBridgeNSIP6Binding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", netBridgeNSIP6BindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NetBridgeNSIP6Binding `json:"netbridge_nsip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// netbridge_nsip_binding +func (s *NetworkService) AddNetBridgeNSIPBinding(resource models.NetBridgeNSIPBinding) error { + payload := map[string]any{"netbridge_nsip_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, netBridgeNSIPBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteNetBridgeNSIPBinding(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", netBridgeNSIPBindingURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllNetBridgeNSIPBinding() ([]models.NetBridgeNSIPBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, netBridgeNSIPBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NetBridgeNSIPBinding `json:"netbridge_nsip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetNetBridgeNSIPBinding(name string) (*models.NetBridgeNSIPBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", netBridgeNSIPBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NetBridgeNSIPBinding `json:"netbridge_nsip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountNetBridgeNSIPBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", netBridgeNSIPBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NetBridgeNSIPBinding `json:"netbridge_nsip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// netbridge_vlan_binding +func (s *NetworkService) AddNetBridgeVLANBinding(resource models.NetBridgeVLANBinding) error { + payload := map[string]any{"netbridge_vlan_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, netBridgeVLANBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteNetBridgeVLANBinding(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", netBridgeVLANBindingURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllNetBridgeVLANBinding() ([]models.NetBridgeVLANBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, netBridgeVLANBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NetBridgeVLANBinding `json:"netbridge_vlan_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetNetBridgeVLANBinding(name string) (*models.NetBridgeVLANBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", netBridgeVLANBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NetBridgeVLANBinding `json:"netbridge_vlan_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountNetBridgeVLANBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", netBridgeVLANBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NetBridgeVLANBinding `json:"netbridge_vlan_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// netprofile +func (s *NetworkService) AddNetProfile(resource models.NetProfile) error { + payload := map[string]any{"netprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, netProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteNetProfile(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", netProfileURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UpdateNetProfile(resource models.NetProfile) error { + payload := map[string]any{"netprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, netProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetNetProfile(resource models.NetProfile) error { + payload := map[string]any{"netprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", netProfileURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllNetProfile() ([]models.NetProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, netProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NetProfile `json:"netprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetNetProfile(name string) (*models.NetProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", netProfileURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NetProfile `json:"netprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountNetProfile() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", netProfileURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NetProfile `json:"netprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// netprofile_binding +func (s *NetworkService) GetAllNetProfileBinding() ([]models.NetProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, netProfileBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NetProfileBinding `json:"netprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetNetProfileBinding(name string) (*models.NetProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", netProfileBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NetProfileBinding `json:"netprofile_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +// netprofile_natrule_binding +func (s *NetworkService) AddNetProfileNATRuleBinding(resource models.NetProfileNATRuleBinding) error { + payload := map[string]any{"netprofile_natrule_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, netProfileNATRuleBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteNetProfileNATRuleBinding(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", netProfileNATRuleBindingURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllNetProfileNATRuleBinding() ([]models.NetProfileNATRuleBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, netProfileNATRuleBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NetProfileNATRuleBinding `json:"netprofile_natrule_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetNetProfileNATRuleBinding(name string) (*models.NetProfileNATRuleBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", netProfileNATRuleBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NetProfileNATRuleBinding `json:"netprofile_natrule_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountNetProfileNATRuleBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", netProfileNATRuleBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NetProfileNATRuleBinding `json:"netprofile_natrule_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// netprofile_srcportset_binding +func (s *NetworkService) AddNetProfileSrcPortSetBinding(resource models.NetProfileSrcPortSetBinding) error { + payload := map[string]any{"netprofile_srcportset_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, netProfileSrcPortSetBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteNetProfileSrcPortSetBinding(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", netProfileSrcPortSetBindingURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllNetProfileSrcPortSetBinding() ([]models.NetProfileSrcPortSetBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, netProfileSrcPortSetBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NetProfileSrcPortSetBinding `json:"netprofile_srcportset_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetNetProfileSrcPortSetBinding(name string) (*models.NetProfileSrcPortSetBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", netProfileSrcPortSetBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NetProfileSrcPortSetBinding `json:"netprofile_srcportset_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountNetProfileSrcPortSetBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", netProfileSrcPortSetBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NetProfileSrcPortSetBinding `json:"netprofile_srcportset_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// onlinkipv6prefix +func (s *NetworkService) AddOnlinkIPV6Prefix(resource models.OnLinkIPv6Prefix) error { + payload := map[string]any{"onlinkipv6prefix": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, onLinkIPV6PrefixURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteOnlinkIPV6Prefix(ipv6prefix string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", onLinkIPV6PrefixURL, ipv6prefix), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UpdateOnlinkIPV6Prefix(resource models.OnLinkIPv6Prefix) error { + payload := map[string]any{"onlinkipv6prefix": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, onLinkIPV6PrefixURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetOnlinkIPV6Prefix(resource models.OnLinkIPv6Prefix) error { + payload := map[string]any{"onlinkipv6prefix": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", onLinkIPV6PrefixURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllOnlinkIPV6Prefix() ([]models.OnLinkIPv6Prefix, error) { + req, err := s.client.NewRequest(http.MethodGet, onLinkIPV6PrefixURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.OnLinkIPv6Prefix `json:"onlinkipv6prefix"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetOnlinkIPV6Prefix(ipv6prefix string) (*models.OnLinkIPv6Prefix, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", onLinkIPV6PrefixURL, ipv6prefix), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.OnLinkIPv6Prefix `json:"onlinkipv6prefix"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountOnlinkIPV6Prefix() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", onLinkIPV6PrefixURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.OnLinkIPv6Prefix `json:"onlinkipv6prefix"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// ptp +func (s *NetworkService) UpdatePTP(resource models.PTP) error { + payload := map[string]any{"ptp": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, ptpURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllPTP() ([]models.PTP, error) { + req, err := s.client.NewRequest(http.MethodGet, ptpURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.PTP `json:"ptp"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// rnat +func (s *NetworkService) AddRNAT(resource models.RNAT) error { + payload := map[string]any{"rnat": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, rnatURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteRNAT(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", rnatURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UpdateRNAT(resource models.RNAT) error { + payload := map[string]any{"rnat": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, rnatURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetRNAT(resource models.RNAT) error { + payload := map[string]any{"rnat": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", rnatURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) ClearRNAT() error { + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=clear", rnatURL), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) RenameRNAT(resource models.RNAT) error { + payload := map[string]any{"rnat": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=rename", rnatURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllRNAT() ([]models.RNAT, error) { + req, err := s.client.NewRequest(http.MethodGet, rnatURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.RNAT `json:"rnat"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetRNAT(name string) (*models.RNAT, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", rnatURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.RNAT `json:"rnat"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountRNAT() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", rnatURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.RNAT `json:"rnat"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// rnat6 +func (s *NetworkService) AddRNAT6(resource models.RNAT6) error { + payload := map[string]any{"rnat6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, rnat6URL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteRNAT6(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", rnat6URL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UpdateRNAT6(resource models.RNAT6) error { + payload := map[string]any{"rnat6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, rnat6URL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetRNAT6(resource models.RNAT6) error { + payload := map[string]any{"rnat6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", rnat6URL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllRNAT6() ([]models.RNAT6, error) { + req, err := s.client.NewRequest(http.MethodGet, rnat6URL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.RNAT6 `json:"rnat6"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetRNAT6(name string) (*models.RNAT6, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", rnat6URL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.RNAT6 `json:"rnat6"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountRNAT6() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", rnat6URL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.RNAT6 `json:"rnat6"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// rnat6_binding +func (s *NetworkService) GetAllRNAT6Binding() ([]models.RNAT6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, rnat6BindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.RNAT6Binding `json:"rnat6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetRNAT6Binding(name string) (*models.RNAT6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", rnat6BindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.RNAT6Binding `json:"rnat6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +// rnat6_nsip6_binding +func (s *NetworkService) AddRNAT6NSIP6Binding(resource models.RNAT6NSIP6Binding) error { + payload := map[string]any{"rnat6_nsip6_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, rnat6NSIP6BindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteRNAT6NSIP6Binding(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", rnat6NSIP6BindingURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllRNAT6NSIP6Binding() ([]models.RNAT6NSIP6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, rnat6NSIP6BindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.RNAT6NSIP6Binding `json:"rnat6_nsip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetRNAT6NSIP6Binding(name string) (*models.RNAT6NSIP6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", rnat6NSIP6BindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.RNAT6NSIP6Binding `json:"rnat6_nsip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountRNAT6NSIP6Binding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", rnat6NSIP6BindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.RNAT6NSIP6Binding `json:"rnat6_nsip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// rnatglobal_auditsyslogpolicy_binding +func (s *NetworkService) AddRNATGlobalAuditSyslogPolicyBinding(resource models.RNATGlobalAuditSyslogPolicyBinding) error { + payload := map[string]any{"rnatglobal_auditsyslogpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, rnatGlobalAuditSyslogPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteRNATGlobalAuditSyslogPolicyBinding(policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", rnatGlobalAuditSyslogPolicyBindingURL, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetRNATGlobalAuditSyslogPolicyBinding() ([]models.RNATGlobalAuditSyslogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, rnatGlobalAuditSyslogPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.RNATGlobalAuditSyslogPolicyBinding `json:"rnatglobal_auditsyslogpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) CountRNATGlobalAuditSyslogPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", rnatGlobalAuditSyslogPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.RNATGlobalAuditSyslogPolicyBinding `json:"rnatglobal_auditsyslogpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// rnatglobal_binding +func (s *NetworkService) GetRBATGlobalBinding() ([]models.RNATGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, rnatGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.RNATGlobalBinding `json:"rnatglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// rnatparam +func (s *NetworkService) UpdateRNATParam(resource models.RNATParam) error { + payload := map[string]any{"rnatparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, rnatParamURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetRNATParam(resource models.RNATParam) error { + payload := map[string]any{"rnatparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", rnatParamURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllRNATParam() ([]models.RNATParam, error) { + req, err := s.client.NewRequest(http.MethodGet, rnatParamURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.RNATParam `json:"rnatparam"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// rnatsession +func (s *NetworkService) FlushRNATSession(resource models.RNATSession) error { + payload := map[string]any{"rnatsession": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=flush", rnatSessionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// rnat_binding +func (s *NetworkService) GetAllRNATBinding() ([]models.RNATBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, rnatBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.RNATBinding `json:"rnat_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetRNATBinding(name string) (*models.RNATBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", rnatBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.RNATBinding `json:"rnat_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +// rnat_nsip_binding +func (s *NetworkService) AddRNATNSIPBinding(resource models.RNATNSIPBinding) error { + payload := map[string]any{"rnat_nsip_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, rnatNSIPBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteRNATNSIPBinding(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", rnatNSIPBindingURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllRNATNSIPBinding() ([]models.RNATNSIPBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, rnatNSIPBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.RNATNSIPBinding `json:"rnat_nsip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetRNATNSIPBinding(name string) (*models.RNATNSIPBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", rnatNSIPBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.RNATNSIPBinding `json:"rnat_nsip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountRNATNSIPBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", rnatNSIPBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.RNATNSIPBinding `json:"rnat_nsip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// rnat_retainsourceportset_binding +func (s *NetworkService) AddRNATRetainSourcePortSetBinding(resource models.RNATRetainSourcePortSetBinding) error { + payload := map[string]any{"rnat_retainsourceportset_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, rnatRetainSourcePortSetBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteRNATRetainSourcePortSetBinding(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", rnatRetainSourcePortSetBindingURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllRNATRetainSourcePortSetBinding() ([]models.RNATRetainSourcePortSetBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, rnatRetainSourcePortSetBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.RNATRetainSourcePortSetBinding `json:"rnat_retainsourceportset_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetRNATRetainSourcePortSetBinding(name string) (*models.RNATRetainSourcePortSetBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", rnatRetainSourcePortSetBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.RNATRetainSourcePortSetBinding `json:"rnat_retainsourceportset_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountRNATRetainSourcePortSetBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", rnatRetainSourcePortSetBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.RNATRetainSourcePortSetBinding `json:"rnat_retainsourceportset_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// route +func (s *NetworkService) AddRoute(resource models.Route) error { + payload := map[string]any{"route": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, routeURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteRoute(network string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", routeURL, network), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UpdateRoute(resource models.Route) error { + payload := map[string]any{"route": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, routeURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetRoute(resource models.Route) error { + payload := map[string]any{"route": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", routeURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) ClearRoute() error { + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=clear", routeURL), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllRoute() ([]models.Route, error) { + req, err := s.client.NewRequest(http.MethodGet, routeURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.Route `json:"route"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) CountRoute() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", routeURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.Route `json:"route"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// route6 +func (s *NetworkService) AddRoute6(resource models.Route6) error { + payload := map[string]any{"route6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, route6URL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteRoute6(network string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", route6URL, network), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UpdateRoute6(resource models.Route6) error { + payload := map[string]any{"route6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, route6URL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetRoute6(resource models.Route6) error { + payload := map[string]any{"route6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", route6URL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) ClearRoute6() error { + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=clear", route6URL), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllRoute6() ([]models.Route6, error) { + req, err := s.client.NewRequest(http.MethodGet, route6URL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.Route6 `json:"route6"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) CountRoute6() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", route6URL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.Route6 `json:"route6"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// rsskeytype +func (s *NetworkService) UpdateRSSKeyType(resource models.RSSKeyType) error { + payload := map[string]any{"rsskeytype": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, rssKeyTypeURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllRSSKeyType() ([]models.RSSKeyType, error) { + req, err := s.client.NewRequest(http.MethodGet, rssKeyTypeURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.RSSKeyType `json:"rsskeytype"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// vlan +func (s *NetworkService) AddVLAN(resource models.VLAN) error { + payload := map[string]any{"vlan": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vlanURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteVLAN(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vlanURL, id), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UpdateVLAN(resource models.VLAN) error { + payload := map[string]any{"vlan": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, vlanURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetVLAN(resource models.VLAN) error { + payload := map[string]any{"vlan": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", vlanURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllVLAN() ([]models.VLAN, error) { + req, err := s.client.NewRequest(http.MethodGet, vlanURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VLAN `json:"vlan"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVLAN(id string) (*models.VLAN, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vlanURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VLAN `json:"vlan"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountVLAN() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vlanURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VLAN `json:"vlan"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// vlan_binding +func (s *NetworkService) GetAllVLANBinding() ([]models.VLANBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vlanBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VLANBinding `json:"vlan_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVLANBinding(id string) (*models.VLANBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vlanBindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VLANBinding `json:"vlan_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +// vlan_channel_binding +func (s *NetworkService) AddVLANChannelBinding(resource models.VLANChannelBinding) error { + payload := map[string]any{"vlan_channel_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vlanChannelBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteVLANChannelBinding(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vlanChannelBindingURL, id), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllVLANChannelBinding() ([]models.VLANChannelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vlanChannelBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VLANChannelBinding `json:"vlan_channel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVLANChannelBinding(id string) (*models.VLANChannelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vlanChannelBindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VLANChannelBinding `json:"vlan_channel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountVLANChannelBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vlanChannelBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VLANChannelBinding `json:"vlan_channel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// vlan_interface_binding +func (s *NetworkService) AddVLANInterfaceBinding(resource models.VLANInterfaceBinding) error { + payload := map[string]any{"vlan_interface_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vlanInterfaceBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteVLANInterfaceBinding(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vlanInterfaceBindingURL, id), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllVLANInterfaceBinding() ([]models.VLANInterfaceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vlanInterfaceBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VLANInterfaceBinding `json:"vlan_interface_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVLANInterfaceBinding(id string) (*models.VLANInterfaceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vlanInterfaceBindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VLANInterfaceBinding `json:"vlan_interface_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountVLANInterfaceBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vlanInterfaceBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VLANInterfaceBinding `json:"vlan_interface_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// vlan_linkset_binding +func (s *NetworkService) AddVLANLinkSetBinding(resource models.VLANLinkSetBinding) error { + payload := map[string]any{"vlan_linkset_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vlanLinkSetBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteVLANLinkSetBinding(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vlanLinkSetBindingURL, id), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllVLANLinkSetBinding() ([]models.VLANLinkSetBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vlanLinkSetBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VLANLinkSetBinding `json:"vlan_linkset_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVLANLinkSetBinding(id string) (*models.VLANLinkSetBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vlanLinkSetBindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VLANLinkSetBinding `json:"vlan_linkset_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountVLANLinkSetBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vlanLinkSetBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VLANLinkSetBinding `json:"vlan_linkset_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// vlan_nsip6_binding +func (s *NetworkService) AddVLANNSIP6Binding(resource models.VLANNSIP6Binding) error { + payload := map[string]any{"vlan_nsip6_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vlanNSIP6BindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteVLANNSIP6Binding(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vlanNSIP6BindingURL, id), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllVLANNSIP6Binding() ([]models.VLANNSIP6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, vlanNSIP6BindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VLANNSIP6Binding `json:"vlan_nsip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVLANNSIP6Binding(id string) (*models.VLANNSIP6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vlanNSIP6BindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VLANNSIP6Binding `json:"vlan_nsip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountVLANNSIP6Binding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vlanNSIP6BindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VLANNSIP6Binding `json:"vlan_nsip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// vlan_nsip_binding +func (s *NetworkService) AddVLANNSIPBinding(resource models.VLANNSIPBinding) error { + payload := map[string]any{"vlan_nsip_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vlanNSIPBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteVLANNSIPBinding(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vlanNSIPBindingURL, id), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllVLANNSIPBinding() ([]models.VLANNSIPBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vlanNSIPBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VLANNSIPBinding `json:"vlan_nsip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVLANNSIPBinding(id string) (*models.VLANNSIPBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vlanNSIPBindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VLANNSIPBinding `json:"vlan_nsip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountVLANNSIPBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vlanNSIPBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VLANNSIPBinding `json:"vlan_nsip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// vrid +func (s *NetworkService) AddVRID(resource models.VRID) error { + payload := map[string]any{"vrid": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vridURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteVRID(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vridURL, id), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UpdateVRID(resource models.VRID) error { + payload := map[string]any{"vrid": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, vridURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetVRID(resource models.VRID) error { + payload := map[string]any{"vrid": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", vridURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllVRID() ([]models.VRID, error) { + req, err := s.client.NewRequest(http.MethodGet, vridURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRID `json:"vrid"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVRID(id string) (*models.VRID, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vridURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRID `json:"vrid"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountVRID() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vridURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VRID `json:"vrid"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// vrid6 +func (s *NetworkService) AddVRID6(resource models.VRID6) error { + payload := map[string]any{"vrid6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vrid6URL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteVRID6(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vrid6URL, id), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UpdateVRID6(resource models.VRID6) error { + payload := map[string]any{"vrid6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, vrid6URL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetVRID6(resource models.VRID6) error { + payload := map[string]any{"vrid6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", vrid6URL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllVRID6() ([]models.VRID6, error) { + req, err := s.client.NewRequest(http.MethodGet, vrid6URL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRID6 `json:"vrid6"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVRID6(id string) (*models.VRID6, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vrid6URL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRID6 `json:"vrid6"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountVRID6() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vrid6URL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VRID6 `json:"vrid6"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// vrid6_binding +func (s *NetworkService) GetAllVRID6Biding() ([]models.VRID6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, vrid6BindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRID6Binding `json:"vrid6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVRID6Biding(id string) (*models.VRID6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vrid6BindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRID6Binding `json:"vrid6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +// vrid6_channel_binding +func (s *NetworkService) AddVRID6ChannelBinding(resource models.VRID6ChannelBinding) error { + payload := map[string]any{"vrid6_channel_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vrid6ChannelBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteVRID6ChannelBinding(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vrid6ChannelBindingURL, id), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllVRID6ChannelBinding() ([]models.VRID6ChannelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vrid6ChannelBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRID6ChannelBinding `json:"vrid6_channel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVRID6ChannelBinding(id string) (*models.VRID6ChannelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vrid6ChannelBindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRID6ChannelBinding `json:"vrid6_channel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountVRID6ChannelBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vrid6ChannelBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VRID6ChannelBinding `json:"vrid6_channel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// vrid6_interface_binding +func (s *NetworkService) AddVRID6InterfaceBinding(resource models.VRID6InterfaceBinding) error { + payload := map[string]any{"vrid6_interface_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vrid6InterfaceBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteVRID6InterfaceBinding(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vrid6InterfaceBindingURL, id), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllVRID6InterfaceBinding() ([]models.VRID6InterfaceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vrid6InterfaceBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRID6InterfaceBinding `json:"vrid6_interface_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVRID6InterfaceBinding(id string) (*models.VRID6InterfaceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vrid6InterfaceBindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRID6InterfaceBinding `json:"vrid6_interface_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountVRID6InterfaceBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vrid6InterfaceBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VRID6InterfaceBinding `json:"vrid6_interface_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// vrid6_nsip6_binding +func (s *NetworkService) GetAllVRID6NSIP6Binding() ([]models.VRID6NSIP6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, vrid6NSIP6BindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRID6NSIP6Binding `json:"vrid6_nsip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVRID6NSIP6Binding(id string) (*models.VRID6NSIP6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vrid6NSIP6BindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRID6NSIP6Binding `json:"vrid6_nsip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountVRID6NSIP6Binding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vrid6NSIP6BindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VRID6NSIP6Binding `json:"vrid6_nsip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// vrid6_nsip_binding +func (s *NetworkService) GetAllVRID6NSIPBinding() ([]models.VRID6NSIPBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vrid6NSIPBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRID6NSIPBinding `json:"vrid6_nsip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVRID6NSIPBinding(id string) (*models.VRID6NSIPBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vrid6NSIPBindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRID6NSIPBinding `json:"vrid6_nsip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountVRID6NSIPBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vrid6NSIPBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VRID6NSIPBinding `json:"vrid6_nsip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// vrid6_trackinterface_binding +func (s *NetworkService) AddVRID6TrackInterfaceBinding(resource models.VRID6TrackInterfaceBinding) error { + payload := map[string]any{"vrid6_trackinterface_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vrid6TrackInterfaceBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteVRID6TrackInterfaceBinding(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vrid6TrackInterfaceBindingURL, id), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllVRID6TrackInterfaceBinding() ([]models.VRID6TrackInterfaceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vrid6TrackInterfaceBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRID6TrackInterfaceBinding `json:"vrid6_trackinterface_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVRID6TrackInterfaceBinding(id string) (*models.VRID6TrackInterfaceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vrid6TrackInterfaceBindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRID6TrackInterfaceBinding `json:"vrid6_trackinterface_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountVRID6TrackInterfaceBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vrid6TrackInterfaceBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VRID6TrackInterfaceBinding `json:"vrid6_trackinterface_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// vridparam +func (s *NetworkService) UpdateVRIDParam(resource models.VRIDParam) error { + payload := map[string]any{"vridparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, vridParamURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetVRIDParam(resource models.VRIDParam) error { + payload := map[string]any{"vridparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", vridParamURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllVRIDParam() ([]models.VRIDParam, error) { + req, err := s.client.NewRequest(http.MethodGet, vridParamURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRIDParam `json:"vridparam"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// vrid_binding +func (s *NetworkService) GetAllVRIDBinding() ([]models.VRIDBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vridBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRIDBinding `json:"vrid_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVRIDBinding(id string) (*models.VRIDBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vridBindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRIDBinding `json:"vrid_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +// vrid_channel_binding +func (s *NetworkService) AddVRIDChannelBinding(resource models.VRIDChannelBinding) error { + payload := map[string]any{"vrid_channel_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vridChannelBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteVRIDChannelBinding(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vridChannelBindingURL, id), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllVRIDChannelBinding() ([]models.VRIDChannelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vridChannelBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRIDChannelBinding `json:"vrid_channel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVRIDChannelBinding(id string) (*models.VRIDChannelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vridChannelBindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRIDChannelBinding `json:"vrid_channel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountVRIDChannelBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vridChannelBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VRIDChannelBinding `json:"vrid_channel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// vrid_interface_binding +func (s *NetworkService) AddVRIDInterfaceBinding(resource models.VRIDInterfaceBinding) error { + payload := map[string]any{"vrid_interface_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vridInterfaceBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteVRIDInterfaceBinding(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vridInterfaceBindingURL, id), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllVRIDInterfaceBinding() ([]models.VRIDInterfaceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vridInterfaceBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRIDInterfaceBinding `json:"vrid_interface_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVRIDInterfaceBinding(id string) (*models.VRIDInterfaceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vridInterfaceBindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRIDInterfaceBinding `json:"vrid_interface_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountVRIDInterfaceBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vridInterfaceBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VRIDInterfaceBinding `json:"vrid_interface_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// vrid_nsip6_binding +func (s *NetworkService) GetAllVRIDNSIP6Binding() ([]models.VRIDNSIP6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, vridNSIP6BindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRIDNSIP6Binding `json:"vrid_nsip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVRIDNSIP6Binding(id string) (*models.VRIDNSIP6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vridNSIP6BindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRIDNSIP6Binding `json:"vrid_nsip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountVRIDNSIP6Binding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vridNSIP6BindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VRIDNSIP6Binding `json:"vrid_nsip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// vrid_nsip_binding +func (s *NetworkService) GetAllVRIDNSIPBinding() ([]models.VRIDNSIPBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vridNSIPBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRIDNSIPBinding `json:"vrid_nsip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVRIDNSIPBinding(id string) (*models.VRIDNSIPBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vridNSIPBindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRIDNSIPBinding `json:"vrid_nsip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountVRIDNSIPBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vridNSIPBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VRIDNSIPBinding `json:"vrid_nsip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// vrid_trackinterface_binding +func (s *NetworkService) AddVRIDTrackInterfaceBinding(resource models.VRIDTrackInterfaceBinding) error { + payload := map[string]any{"vrid_trackinterface_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vridTrackInterfaceBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteVRIDTrackInterfaceBinding(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vridTrackInterfaceBindingURL, id), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllVRIDTrackInterfaceBinding() ([]models.VRIDTrackInterfaceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vridTrackInterfaceBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRIDTrackInterfaceBinding `json:"vrid_trackinterface_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVRIDTrackInterfaceBinding(id string) (*models.VRIDTrackInterfaceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vridTrackInterfaceBindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VRIDTrackInterfaceBinding `json:"vrid_trackinterface_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountVRIDTrackInterfaceBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vridTrackInterfaceBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VRIDTrackInterfaceBinding `json:"vrid_trackinterface_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// vxlan +func (s *NetworkService) AddVXLAN(resource models.VXLAN) error { + payload := map[string]any{"vxlan": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vxlanURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteVXLAN(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vxlanURL, id), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UpdateVXLAN(resource models.VXLAN) error { + payload := map[string]any{"vxlan": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, vxlanURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) UnsetVXLAN(resource models.VXLAN) error { + payload := map[string]any{"vxlan": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", vxlanURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllVXLAN() ([]models.VXLAN, error) { + req, err := s.client.NewRequest(http.MethodGet, vxlanURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VXLAN `json:"vxlan"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVXLAN(id string) (*models.VXLAN, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vxlanURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VXLAN `json:"vxlan"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountVXLAN() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vxlanURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VXLAN `json:"vxlan"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// vxlanvlanmap +func (s *NetworkService) AddVXLANVLANMap(resource models.VXLANVLANMap) error { + payload := map[string]any{"vxlanvlanmap": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vxlanVLANMapURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteVXLANVLANMap(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vxlanVLANMapURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllVXLANVLANMap() ([]models.VXLANVLANMap, error) { + req, err := s.client.NewRequest(http.MethodGet, vxlanVLANMapURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VXLANVLANMap `json:"vxlanvlanmap"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVXLANVLANMap(name string) (*models.VXLANVLANMap, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vxlanVLANMapURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VXLANVLANMap `json:"vxlanvlanmap"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountVXLANVLANMap() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vxlanVLANMapURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VXLANVLANMap `json:"vxlanvlanmap"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// vxlanvlanmap_binding +func (s *NetworkService) GetAllVXLANVLANMapBinding() ([]models.VXLANVLANMapBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vxlanVLANMapBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VXLANVLANMapBinding `json:"vxlanvlanmap_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVXLANVLANMapBinding(name string) (*models.VXLANVLANMapBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vxlanVLANMapBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VXLANVLANMapBinding `json:"vxlanvlanmap_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +// vxlanvlanmap_vxlan_binding +func (s *NetworkService) AddVXLANVLANMapVXLANBinding(resource models.VXLANVLANMapVXLANBinding) error { + payload := map[string]any{"vxlanvlanmap_vxlan_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vxlanVLANMapVXLANBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteVXLANVLANMapVXLANBinding(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vxlanVLANMapVXLANBindingURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllVXLANVLANMapVXLANBinding() ([]models.VXLANVLANMapVXLANBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vxlanVLANMapVXLANBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VXLANVLANMapVXLANBinding `json:"vxlanvlanmap_vxlan_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVXLANVLANMapVXLANBinding(name string) (*models.VXLANVLANMapVXLANBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vxlanVLANMapVXLANBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VXLANVLANMapVXLANBinding `json:"vxlanvlanmap_vxlan_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountVXLANVLANMapVXLANBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vxlanVLANMapVXLANBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VXLANVLANMapVXLANBinding `json:"vxlanvlanmap_vxlan_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// vxlan_binding +func (s *NetworkService) GetAllVXLANBinding() ([]models.VxlanBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vxlanBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VxlanBinding `json:"vxlan_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVXLANBinding(id string) (*models.VxlanBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vxlanBindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VxlanBinding `json:"vxlan_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +// vxlan_iptunnel_binding +func (s *NetworkService) AddVXLANIPTunnelBinding(resource models.VXLANIPTunnelBinding) error { + payload := map[string]any{"vxlan_iptunnel_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vxlanIPTunnelBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteVXLANIPTunnelBinding(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vxlanIPTunnelBindingURL, id), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllVXLANIPTunnelBinding() ([]models.VXLANIPTunnelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vxlanIPTunnelBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VXLANIPTunnelBinding `json:"vxlan_iptunnel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVXLANIPTunnelBinding(id string) (*models.VXLANIPTunnelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vxlanIPTunnelBindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VXLANIPTunnelBinding `json:"vxlan_iptunnel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountVXLANIPTunnelBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vxlanIPTunnelBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VXLANIPTunnelBinding `json:"vxlan_iptunnel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// vxlan_nsip6_binding +func (s *NetworkService) AddVXLANNSIP6Binding(resource models.VXLANNSIP6Binding) error { + payload := map[string]any{"vxlan_nsip6_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vxlanNSIP6BindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteVXLANNSIP6Binding(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vxlanNSIP6BindingURL, id), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllVXLANNSIP6Binding() ([]models.VXLANNSIP6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, vxlanNSIP6BindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VXLANNSIP6Binding `json:"vxlan_nsip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVXLANNSIP6Binding(id string) (*models.VXLANNSIP6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vxlanNSIP6BindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VXLANNSIP6Binding `json:"vxlan_nsip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountVXLANNSIP6Binding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vxlanNSIP6BindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VXLANNSIP6Binding `json:"vxlan_nsip6_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// vxlan_nsip_binding +func (s *NetworkService) AddVXLANNSIPBinding(resource models.VXLANNSIPBinding) error { + payload := map[string]any{"vxlan_nsip_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vxlanNSIPBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteVXLANNSIPBinding(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vxlanNSIPBindingURL, id), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllVXLANNSIPBinding() ([]models.VXLANNSIPBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vxlanNSIPBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VXLANNSIPBinding `json:"vxlan_nsip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVXLANNSIPBinding(id string) (*models.VXLANNSIPBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vxlanNSIPBindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VXLANNSIPBinding `json:"vxlan_nsip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountVXLANNSIPBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vxlanNSIPBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VXLANNSIPBinding `json:"vxlan_nsip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// vxlan_srcip_binding +func (s *NetworkService) AddVXLANSrcIPBinding(resource models.VXLANSrcIPBinding) error { + payload := map[string]any{"vxlan_srcip_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vxlanSrcIPBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) DeleteVXLANSrcIPBinding(id string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vxlanSrcIPBindingURL, id), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NetworkService) GetAllVXLANSrcIPBinding() ([]models.VXLANSrcIPBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vxlanSrcIPBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VXLANSrcIPBinding `json:"vxlan_srcip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NetworkService) GetVXLANSrcIPBinding(id string) (*models.VXLANSrcIPBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vxlanSrcIPBindingURL, id), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VXLANSrcIPBinding `json:"vxlan_srcip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *NetworkService) CountVXLANSrcIPBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vxlanSrcIPBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VXLANSrcIPBinding `json:"vxlan_srcip_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} diff --git a/nitrogo/ns.go b/nitrogo/ns.go index f4fe6d2..a38ab9b 100644 --- a/nitrogo/ns.go +++ b/nitrogo/ns.go @@ -1,5 +1,118 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "strings" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + nsACLURL = "/nitro/v1/config/nsacl" + nsACL6URL = "/nitro/v1/config/nsacl6" + nsACLSURL = "/nitro/v1/config/nsacls" + nsACLS6URL = "/nitro/v1/config/nsacls6" + nsAppFlowCollectorURL = "/nitro/v1/config/nsappflowcollector" + nsAppFlowParamURL = "/nitro/v1/config/nsappflowparam" + nsCapacityURL = "/nitro/v1/config/nscapacity" + nsConfigURL = "/nitro/v1/config/nsconfig" + nsConnectionTableURL = "/nitro/v1/config/nsconnectiontable" + nsConsoleLoginPromptURL = "/nitro/v1/config/nsconsoleloginprompt" + nsDHCPParamsURL = "/nitro/v1/config/nsdhcpparams" + nsDialogURL = "/nitro/v1/config/nsdialog" + nsEncryptionParamsURL = "/nitro/v1/config/nsencryptionparams" + nsEventsURL = "/nitro/v1/config/nsevents" + nsExtensionURL = "/nitro/v1/config/nsextension" + nsExtensionBindingURL = "/nitro/v1/config/nsextension_binding" + nsExtensionExtensionFunctionBindingURL = "/nitro/v1/config/nsextension_extensionfunction_binding" + nsFeatureURL = "/nitro/v1/config/nsfeature" + nsHardwareURL = "/nitro/v1/config/nshardware" + nsHostNameURL = "/nitro/v1/config/nshostname" + nsHTTPParamURL = "/nitro/v1/config/nshttpparam" + nsHTTPProfileURL = "/nitro/v1/config/nshttpprofile" + nsICAPProfileURL = "/nitro/v1/config/nsicapprofile" + nsIPURL = "/nitro/v1/config/nsip" + nsIP6URL = "/nitro/v1/config/nsip6" + nsLicenseURL = "/nitro/v1/config/nslicense" + nsLicenseParametersURL = "/nitro/v1/config/nslicenseparameters" + nsLicenseServerURL = "/nitro/v1/config/nslicenseserver" + nsLimitIdentifierURL = "/nitro/v1/config/nslimitidentifier" + nsLimitSelectorURL = "/nitro/v1/config/nslimitselector" + nsLimitSessionsURL = "/nitro/v1/config/nslimitsessions" + nsLogActionURL = "/nitro/v1/config/nslogaction" + nsLogGlobalBindingURL = "/nitro/v1/config/nslogglobal_binding" + nsLogGlobalAuditNSLogPolicyBindingURL = "/nitro/v1/config/nslogglobal_auditnslogpolicy_binding" + nsLogParamsURL = "/nitro/v1/config/nslogparams" + nsLogPolicyURL = "/nitro/v1/config/nslogpolicy" + nsLogPolicyBindingURL = "/nitro/v1/config/nslogpolicy_binding" + nsModeURL = "/nitro/v1/config/nsmode" + nsParamURL = "/nitro/v1/config/nsparam" + nsPartitionURL = "/nitro/v1/config/nspartition" + nsPartitionBindingURL = "/nitro/v1/config/nspartition_binding" + nsPartitionBridgeGroupBindingURL = "/nitro/v1/config/nspartition_bridgegroup_binding" + nsPartitionVLANBindingURL = "/nitro/v1/config/nspartition_vlan_binding" + nsPartitionVXLANBindingURL = "/nitro/v1/config/nspartition_vxlan_binding" + nsRateControlURL = "/nitro/v1/config/nsratecontrol" + nsRPCNodeURL = "/nitro/v1/config/nsrpcnode" + nsRunningConfigURL = "/nitro/v1/config/nsrunningconfig" + nsSavedConfigURL = "/nitro/v1/config/nssavedconfig" + nsServicePathURL = "/nitro/v1/config/nsservicepath" + nsSimpleACLURL = "/nitro/v1/config/nssimpleacl" + nsSimpleACL6URL = "/nitro/v1/config/nssimpleacl6" + nsSPParamsURL = "/nitro/v1/config/nsspparams" + nsSurgeProtectionURL = "/nitro/v1/config/nssurgeprotection" + nsTCPBufParamURL = "/nitro/v1/config/nstcpbufparam" + nsTCPParamURL = "/nitro/v1/config/nstcpparam" + nsTCPProfileURL = "/nitro/v1/config/nstcpprofile" + nsTimeoutURL = "/nitro/v1/config/nstimeout" + nsTimerURL = "/nitro/v1/config/nstimer" + nsTrafficDomainURL = "/nitro/v1/config/nstrafficdomain" + nsTrafficDomainBindingURL = "/nitro/v1/config/nstrafficdomain_binding" + nsTrafficDomainBridgeGroupBindingURL = "/nitro/v1/config/nstrafficdomain_bridgegroup_binding" + nsTrafficDomainVLANBindingURL = "/nitro/v1/config/nstrafficdomain_vlan_binding" + nsTrafficDomainVXLANBindingURL = "/nitro/v1/config/nstrafficdomain_vxlan_binding" + nsVariableURL = "/nitro/v1/config/nsvariable" + nsVersionURL = "/nitro/v1/config/nsversion" + nsWeblogParamURL = "/nitro/v1/config/nsweblogparam" + nsXMLNamespaceURL = "/nitro/v1/config/nsxmlnamespace" + nsXMLSchemaURL = "/nitro/v1/config/nsxmlschema" + nsAptLicenseURL = "/nitro/v1/config/nsaptlicense" + nsAssignmentURL = "/nitro/v1/config/nsassignment" + nsCQAParamURL = "/nitro/v1/config/nscqaparam" + nsDHCPIPURL = "/nitro/v1/config/nsdhcpip" + nsDiameterURL = "/nitro/v1/config/nsdiameter" + nsEncryptionKeyURL = "/nitro/v1/config/nsencryptionkey" + nsHostnameURL = "/nitro/v1/config/nshostname" + nsLicenseProxyServerURL = "/nitro/v1/config/nslicenseproxyserver" + nsLicenseServerPoolURL = "/nitro/v1/config/nslicenseserverpool" + nsMigrationURL = "/nitro/v1/config/nsmigration" + nsPartitionMACURL = "/nitro/v1/config/nspartitionmac" + nsPBRURL = "/nitro/v1/config/nspbr" + nsPBR6URL = "/nitro/v1/config/nspbr6" + nsPBRsURL = "/nitro/v1/config/nspbrs" + nsRollBackCMDURL = "/nitro/v1/config/nsrollbackcmd" + nsServiceFunctionURL = "/nitro/v1/config/nsservicefunction" + nsServicePathBindingURL = "/nitro/v1/config/nsservicepath_binding" + nsServicePathNSServiceFunctionBindingURL = "/nitro/v1/config/nsservicepath_nsservicefunction_binding" + nsSourceRouteCacheTableURL = "/nitro/v1/config/nssourceroutecachetable" + nsStatsURL = "/nitro/v1/config/nsstats" + nsSurgeQURL = "/nitro/v1/config/nssurgeq" + nsTimerAutoScalePolicyBindingURL = "/nitro/v1/config/nstimer_autoscalepolicy_binding" + nsTimerBindingURL = "/nitro/v1/config/nstimer_binding" + nsTimeZoneURL = "/nitro/v1/config/nstimezone" + nsVPXParamURL = "/nitro/v1/config/nsvpxparam" + nsCentralManagementServerURL = "/nitro/v1/config/nscentralmanagementserver" + nsHMACKeyURL = "/nitro/v1/config/nshmackey" + nsLimitIdentifierBindingURL = "/nitro/v1/config/nslimitidentifier_binding" + nsLimitIdentifierNSLimitSessionsBindingURL = "/nitro/v1/config/nslimitidentifier_nslimitsessions_binding" + nsPartitionVlanBindingURL = "/nitro/v1/config/nspartition_vlan_binding" + rebootURL = "/nitro/v1/config/reboot" + shutdownURL = "/nitro/v1/config/shutdown" +) + // ns // System/Global level configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/ns/ns @@ -8,549 +121,7363 @@ type NSService struct { } // nsacl -func (s *NSService) AddNSACL() {} -func (s *NSService) DeleteNSACL() {} -func (s *NSService) UpdateNSACL() {} -func (s *NSService) UnsetNSACL() {} -func (s *NSService) EnableNSACL() {} -func (s *NSService) DisableNSACL() {} -func (s *NSService) RenameNSACL() {} -func (s *NSService) GetAllNSACL() {} -func (s *NSService) GetNSACL() {} -func (s *NSService) CountNSACL() {} +func (s *NSService) AddNSACL(resource models.NSACL) error { + payload := map[string]any{"nsacl": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsACLURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSACL(aclname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsACLURL, aclname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UpdateNSACL(resource models.NSACL) error { + payload := map[string]any{"nsacl": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsACLURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSACL(resource models.NSACL) error { + payload := map[string]any{"nsacl": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsACLURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) EnableNSACL(resource models.NSACL) error { + payload := map[string]any{"nsacl": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=enable", nsACLURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DisableNSACL(resource models.NSACL) error { + payload := map[string]any{"nsacl": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=disable", nsACLURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) RenameNSACL(resource models.NSACL) error { + payload := map[string]any{"nsacl": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=rename", nsACLURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSACL() ([]models.NSACL, error) { + req, err := s.client.NewRequest(http.MethodGet, nsACLURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSACL `json:"nsacl"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSACL(aclname string) (*models.NSACL, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsACLURL, aclname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSACL `json:"nsacl"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nsacl %s not found", aclname) + } + + return &result.Data[0], nil +} + +func (s *NSService) CountNSACL() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsACLURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSACL `json:"nsacl"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} // nsacl6 -func (s *NSService) AddNSACL6() {} -func (s *NSService) DeleteNSACL6() {} -func (s *NSService) UpdateNSACL6() {} -func (s *NSService) UnsetNSACL6() {} -func (s *NSService) EnableNSACL6() {} -func (s *NSService) DisableNSACL6() {} -func (s *NSService) RenameNSACL6() {} -func (s *NSService) GetAllNSACL6() {} -func (s *NSService) GetNSACL6() {} -func (s *NSService) CountNSACL6() {} +func (s *NSService) AddNSACL6(resource models.NSACL6) error { + payload := map[string]any{"nsacl6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsACL6URL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSACL6(acl6name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsACL6URL, acl6name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UpdateNSACL6(resource models.NSACL6) error { + payload := map[string]any{"nsacl6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsACL6URL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSACL6(resource models.NSACL6) error { + payload := map[string]any{"nsacl6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsACL6URL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) EnableNSACL6(resource models.NSACL6) error { + payload := map[string]any{"nsacl6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=enable", nsACL6URL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DisableNSACL6(resource models.NSACL6) error { + payload := map[string]any{"nsacl6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=disable", nsACL6URL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) RenameNSACL6(resource models.NSACL6) error { + payload := map[string]any{"nsacl6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=rename", nsACL6URL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSACL6() ([]models.NSACL6, error) { + req, err := s.client.NewRequest(http.MethodGet, nsACL6URL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSACL6 `json:"nsacl6"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSACL6(acl6name string) (*models.NSACL6, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsACL6URL, acl6name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSACL6 `json:"nsacl6"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nsacl6 %s not found", acl6name) + } + + return &result.Data[0], nil +} + +func (s *NSService) CountNSACL6() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsACL6URL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSACL6 `json:"nsacl6"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} // nsacls -func (s *NSService) RenumberNSACLS() {} -func (s *NSService) ClearNSACLS() {} -func (s *NSService) ApplyNSACLS() {} +func (s *NSService) RenumberNSACLS() error { + payload := map[string]any{"nsacls": map[string]any{}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=renumber", nsACLSURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) ClearNSACLS() error { + payload := map[string]any{"nsacls": map[string]any{}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=clear", nsACLSURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) ApplyNSACLS() error { + payload := map[string]any{"nsacls": map[string]any{}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=apply", nsACLSURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} // nsacls6 -func (s *NSService) RenumberNSACLS6() {} -func (s *NSService) ClearNSACLS6() {} -func (s *NSService) ApplyNSACLS6() {} +func (s *NSService) RenumberNSACLS6() error { + payload := map[string]any{"nsacls6": map[string]any{}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=renumber", nsACLS6URL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) ClearNSACLS6() error { + payload := map[string]any{"nsacls6": map[string]any{}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=clear", nsACLS6URL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) ApplyNSACLS6() error { + payload := map[string]any{"nsacls6": map[string]any{}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=apply", nsACLS6URL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} // nsappflowcollector -func (s *NSService) AddNSAppFlowCollector() {} -func (s *NSService) DeleteNSAppFlowCollector() {} -func (s *NSService) GetAllNSAppFlowCollector() {} -func (s *NSService) GetNSAppFlowCollector() {} -func (s *NSService) CountNSAppFlowCollector() {} +func (s *NSService) AddNSAppFlowCollector(resource models.NSAppFlowCollector) error { + payload := map[string]any{"nsappflowcollector": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsAppFlowCollectorURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSAppFlowCollector(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsAppFlowCollectorURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSAppFlowCollector() ([]models.NSAppFlowCollector, error) { + req, err := s.client.NewRequest(http.MethodGet, nsAppFlowCollectorURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSAppFlowCollector `json:"nsappflowcollector"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSAppFlowCollector(name string) (*models.NSAppFlowCollector, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsAppFlowCollectorURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSAppFlowCollector `json:"nsappflowcollector"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nsappflowcollector %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *NSService) CountNSAppFlowCollector() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsAppFlowCollectorURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSAppFlowCollector `json:"nsappflowcollector"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} // nsappflowparam -func (s *NSService) UpdateNSAppFlowParam() {} -func (s *NSService) UnsetNSAppFlowParam() {} -func (s *NSService) GetAllNSAppFlowParam() {} +func (s *NSService) UpdateNSAppFlowParam(resource models.NSAppFlowParam) error { + payload := map[string]any{"nsappflowparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// nsaptlicense -func (s *NSService) GetAllNSAptLicense() {} -func (s *NSService) CountNSAptLicense() {} -func (s *NSService) ChangeNSAptLicense() {} + req, err := s.client.NewRequest(http.MethodPut, nsAppFlowParamURL, bytes.NewReader(data)) + if err != nil { + return err + } -// nsassignment -func (s *NSService) AddNSAssignment() {} -func (s *NSService) DeleteNSAssignment() {} -func (s *NSService) UpdateNSAssignment() {} -func (s *NSService) UnsetNSAssignment() {} -func (s *NSService) GetAllNSAssignment() {} -func (s *NSService) GetNSAssignment() {} -func (s *NSService) CountNSAssignment() {} -func (s *NSService) RenameNSAssignment() {} + _, err = s.client.Do(req) + return err +} -// nscapacity -func (s *NSService) UpdateNSCapacity() {} -func (s *NSService) UnsetNSCapacity() {} -func (s *NSService) GetAllNSCapacity() {} +func (s *NSService) UnsetNSAppFlowParam(resource models.NSAppFlowParam) error { + payload := map[string]any{"nsappflowparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// nscentralmanagementserver -func (s *NSService) AddNSCentralManagementServer() {} -func (s *NSService) DeleteNSCentralManagementServer() {} -func (s *NSService) GetAllNSCentralManagementServer() {} -func (s *NSService) GetNSCentralManagementServer() {} -func (s *NSService) CountNSCentralManagementServer() {} + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsAppFlowParamURL), bytes.NewReader(data)) + if err != nil { + return err + } -// nsconfig -func (s *NSService) ClearNSConfig() {} -func (s *NSService) SaveNSConfig() {} -func (s *NSService) DiffNSConfig() {} -func (s *NSService) UpdateNSConfig() {} -func (s *NSService) UnsetNSConfig() {} -func (s *NSService) GetAllNSConfig() {} + _, err = s.client.Do(req) + return err +} -// nsconnectiontable -func (s *NSService) GetAllNSconnectionTable() {} -func (s *NSService) CountNSconnectionTable() {} +func (s *NSService) GetAllNSAppFlowParam() ([]models.NSAppFlowParam, error) { + req, err := s.client.NewRequest(http.MethodGet, nsAppFlowParamURL, nil) + if err != nil { + return nil, err + } -// nsconsoleloginprompt -func (s *NSService) UpdateNSConsoleLoginPrompt() {} -func (s *NSService) UnsetNSConsoleLoginPrompt() {} -func (s *NSService) GetAllNSConsoleLoginPrompt() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// nscqaparam -func (s *NSService) UpdateNSCQAParam() {} -func (s *NSService) UnsetNSCQAParam() {} -func (s *NSService) GetAllNSCQAParam() {} + var result struct { + Data []models.NSAppFlowParam `json:"nsappflowparam"` + } -// nsdhcpip -func (s *NSService) ReleaseNSDHCPIP() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// nsdhcpparams -func (s *NSService) UpdateNSDHCPParams() {} -func (s *NSService) UnsetNSDHCPParams() {} -func (s *NSService) GetAllNSDHCPParams() {} + return result.Data, nil +} -// nsdiamter -func (s *NSService) UpdateNSDiameter() {} -func (s *NSService) UnsetNSDiameter() {} -func (s *NSService) GetAllNSDiameter() {} -func (s *NSService) GetNSDiameter() {} -func (s *NSService) CountNSDiameter() {} +// nsaptlicense +func (s *NSService) GetAllNSAptLicense() ([]models.NSAPTLicense, error) { + req, err := s.client.NewRequest(http.MethodGet, nsAptLicenseURL, nil) + if err != nil { + return nil, err + } -// nsencyrptionkey -func (s *NSService) AddNSEncryptionKey() {} -func (s *NSService) DeleteNSEncryptionKey() {} -func (s *NSService) UpdateNSEncryptionKey() {} -func (s *NSService) UnsetNSEncryptionKey() {} -func (s *NSService) GetAllNSEncryptionKey() {} -func (s *NSService) GetNSEncryptionKey() {} -func (s *NSService) CountNSEncryptionKey() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// nsencryptionparams -func (s *NSService) UpdateNSEncryptionParams() {} -func (s *NSService) GetAllNSEncryptionParams() {} + var result struct { + Data []models.NSAPTLicense `json:"nsaptlicense"` + } -// nsevents -func (s *NSService) GetAllNSEvents() {} -func (s *NSService) CountNSEvents() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// nsextension -func (s *NSService) ImportNSExtension() {} -func (s *NSService) AddNSExtension() {} -func (s *NSService) DeleteNSExtension() {} -func (s *NSService) UpdateNSExtension() {} -func (s *NSService) UnsetNSExtension() {} -func (s *NSService) GetAllNSExtension() {} -func (s *NSService) GetNSExtension() {} -func (s *NSService) CountNSExtension() {} -func (s *NSService) ChangeNSExtension() {} + return result.Data, nil +} -// nsextension_binding -func (s *NSService) GetAllNSExtenionBinding() {} -func (s *NSService) GetNSExtenionBinding() {} +func (s *NSService) CountNSAptLicense() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsAptLicenseURL), nil) + if err != nil { + return 0, err + } -// nsextension_extensionfunction_binding -func (s *NSService) GetAllNSExtensionExtensionFunctionBinding() {} -func (s *NSService) GetNSExtensionExtensionFunctionBinding() {} -func (s *NSService) CountNSExtensionExtensionFunctionBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } -// nsfeature -func (s *NSService) EnableNSFeature() {} -func (s *NSService) DisableNSFeature() {} -func (s *NSService) GetAllNSFeature() {} + var result struct { + Data []models.NSAPTLicense `json:"nsaptlicense"` + } -// nshardware -func (s *NSService) GetAllNSHardware() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } -// nshmackey -func (s *NSService) AddNSHMACKey() {} -func (s *NSService) DeleteNSHMACKey() {} -func (s *NSService) UpdateNSHMACKey() {} -func (s *NSService) UnsetNSHMACKey() {} -func (s *NSService) GetAllNSHMACKey() {} -func (s *NSService) GetNSHMACKey() {} -func (s *NSService) CountNSHMACKey() {} + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} -// nshostname -func (s *NSService) UpdateNSHostname() {} -func (s *NSService) GetAllNSHostname() {} -func (s *NSService) CountNSHostname() {} +func (s *NSService) ChangeNSAptLicense(resource models.NSAPTLicense) error { + payload := map[string]any{"nsaptlicense": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// nshttpparam -func (s *NSService) UpdateNSHTTPParam() {} -func (s *NSService) GetAllNSHTTPParam() {} -func (s *NSService) CountNSHTTPParam() {} + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=change", nsAptLicenseURL), bytes.NewReader(data)) + if err != nil { + return err + } -// nshttpprofile -func (s *NSService) AddNSHTTPProfile() {} -func (s *NSService) DeleteNSHTTPProfile() {} -func (s *NSService) UpdateNSHTTPProfile() {} -func (s *NSService) UnsetNSHTTPProfile() {} -func (s *NSService) GetAllNSHTTPProfile() {} -func (s *NSService) GetNSHTTPProfile() {} -func (s *NSService) CountNSHTTPProfile() {} + _, err = s.client.Do(req) + return err +} -// nsicapprofile -func (s *NSService) AddNSICAPProfile() {} -func (s *NSService) DeleteNSICAPProfile() {} -func (s *NSService) UpdateNSICAPProfile() {} -func (s *NSService) UnsetNSICAPProfile() {} -func (s *NSService) GetAllNSICAPProfile() {} -func (s *NSService) GetNSICAPProfile() {} -func (s *NSService) CountNSICAPProfile() {} +// nsassignment +func (s *NSService) AddNSAssignment(resource models.NSAssignment) error { + payload := map[string]any{"nsassignment": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// nsip -func (s *NSService) AddNSIP() {} -func (s *NSService) DeleteNSIP() {} -func (s *NSService) UpdateNSIP() {} -func (s *NSService) UnsetNSIP() {} -func (s *NSService) EnableNSIP() {} -func (s *NSService) DisableNSIP() {} -func (s *NSService) GetAllNSIP() {} -func (s *NSService) CountNSIP() {} + req, err := s.client.NewRequest(http.MethodPost, nsAssignmentURL, bytes.NewReader(data)) + if err != nil { + return err + } -// nsip6 -func (s *NSService) AddNSIP6() {} -func (s *NSService) DeleteNSIP6() {} -func (s *NSService) UpdateNSIP6() {} -func (s *NSService) UnsetNSIP6() {} -func (s *NSService) GetAllNSIP6() {} -func (s *NSService) CountNSIP6() {} + _, err = s.client.Do(req) + return err +} -// nslicense -func (s *NSService) GetAllNSLicense() {} +func (s *NSService) DeleteNSAssignment(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsAssignmentURL, name), nil) + if err != nil { + return err + } -// nslicenseproxyserver -func (s *NSService) AddNSLicenseProxyServer() {} -func (s *NSService) DeleteNSLicenseProxyServer() {} -func (s *NSService) UpdateNSLicenseProxyServer() {} -func (s *NSService) GetAllNSLicenseProxyServer() {} -func (s *NSService) CountNSLicenseProxyServer() {} + _, err = s.client.Do(req) + return err +} -// nslicenseserver -func (s *NSService) AddNSLicenseServer() {} -func (s *NSService) DeleteNSLicenseServer() {} -func (s *NSService) UpdateNSLicenseServer() {} -func (s *NSService) GetAllNSLicenseServer() {} -func (s *NSService) CountNSLicenseServer() {} +func (s *NSService) UpdateNSAssignment(resource models.NSAssignment) error { + payload := map[string]any{"nsassignment": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// nslicenseserverpool -func (s *NSService) GetAllNSLicenseServerPool() {} + req, err := s.client.NewRequest(http.MethodPut, nsAssignmentURL, bytes.NewReader(data)) + if err != nil { + return err + } -// nslimitidentifier -func (s *NSService) AddNSLimitIdentifier() {} -func (s *NSService) DeleteNSLimitIdentifier() {} -func (s *NSService) UpdateNSLimitIdentifier() {} -func (s *NSService) UnsetNSLimitIdentifier() {} -func (s *NSService) GetAllNSLimitIdentifier() {} -func (s *NSService) GetNSLimitIdentifier() {} -func (s *NSService) CountNSLimitIdentifier() {} + _, err = s.client.Do(req) + return err +} -// nslimitidentifier_binding -func (s *NSService) GetAllNSLimitIdentifierBinding() {} -func (s *NSService) GetNSLimitIdentifierBinding() {} +func (s *NSService) UnsetNSAssignment(resource models.NSAssignment) error { + payload := map[string]any{"nsassignment": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// nslimitidentifier_nslimitsessions_binding -func (s *NSService) GetAllNSLimitIdentifierNSLimitSessionsBinding() {} -func (s *NSService) GetNSLimitIdentifierNSLimitSessionsBinding() {} -func (s *NSService) CountNSLimitIdentifierNSLimitSessionsBinding() {} + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsAssignmentURL), bytes.NewReader(data)) + if err != nil { + return err + } -// nslimitselector -func (s *NSService) AddNSLimitSelector() {} -func (s *NSService) DeleteNSLimitSelector() {} -func (s *NSService) UpdateNSLimitSelector() {} -func (s *NSService) UnsetNSLimitSelector() {} -func (s *NSService) GetAllNSLimitSelector() {} -func (s *NSService) GetNSLimitSelector() {} -func (s *NSService) CountNSLimitSelector() {} + _, err = s.client.Do(req) + return err +} -// nslimitsessions -func (s *NSService) GetAllNSLimitSessions() {} -func (s *NSService) CountNSLimitSessions() {} -func (s *NSService) ClearNSLimitSessions() {} +func (s *NSService) GetAllNSAssignment() ([]models.NSAssignment, error) { + req, err := s.client.NewRequest(http.MethodGet, nsAssignmentURL, nil) + if err != nil { + return nil, err + } -// nsmigration -func (s *NSService) GetAllNSMigration() {} -func (s *NSService) CountNSMigration() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// nsmode -func (s *NSService) EnableNSMode() {} -func (s *NSService) DisableNSMode() {} -func (s *NSService) GetAllNSMode() {} + var result struct { + Data []models.NSAssignment `json:"nsassignment"` + } -// nsparam -func (s *NSService) UpdateNSParam() {} -func (s *NSService) UnsetNSParam() {} -func (s *NSService) GetAllNSParam() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// nspartition -func (s *NSService) AddNSPartition() {} -func (s *NSService) DeleteNSPartition() {} -func (s *NSService) UpdateNSPartition() {} -func (s *NSService) UnsetNSPartition() {} -func (s *NSService) SwitchNSPartition() {} -func (s *NSService) GetAllNSPartition() {} -func (s *NSService) GetNSPartition() {} -func (s *NSService) CountNSPartition() {} + return result.Data, nil +} -// nspartitionmac -func (s *NSService) GetAllNSPartitionMAC() {} -func (s *NSService) CountNSPartitionMAC() {} +func (s *NSService) GetNSAssignment(name string) (*models.NSAssignment, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsAssignmentURL, name), nil) + if err != nil { + return nil, err + } -// nspartition_binding -func (s *NSService) GetAllNSPartitionBinding() {} -func (s *NSService) GetNSPartitionBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// nspartition_bridgegroup_binding -func (s *NSService) AddNSPartitionBridgeGroupBinding() {} -func (s *NSService) DeleteNSPartitionBridgeGroupBinding() {} -func (s *NSService) GetAllNSPartitionBridgeGroupBinding() {} -func (s *NSService) GetNSPartitionBridgeGroupBinding() {} -func (s *NSService) CountNSPartitionBridgeGroupBinding() {} + var result struct { + Data []models.NSAssignment `json:"nsassignment"` + } -// nspartition_vlan_binding -func (s *NSService) AddNSPartitionVLANBinding() {} -func (s *NSService) DeleteNSPartitionVLANBinding() {} -func (s *NSService) GetAllNSPartitionVLANBinding() {} -func (s *NSService) GetNSPartitionVLANBinding() {} -func (s *NSService) CountNSPartitionVLANBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// nspartition_vxlan_binding -func (s *NSService) AddNSPartitionVXLANBinding() {} -func (s *NSService) DeleteNSPartitionVXLANBinding() {} -func (s *NSService) GetAllNSPartitionVXLANBinding() {} -func (s *NSService) GetNSPartitionVXLANBinding() {} -func (s *NSService) CountNSPartitionVXLANBinding() {} + if len(result.Data) == 0 { + return nil, fmt.Errorf("nsassignment %s not found", name) + } -// nspbr -func (s *NSService) AddNSPBR() {} -func (s *NSService) DeleteNSPBR() {} -func (s *NSService) UpdateNSPBR() {} -func (s *NSService) UnsetNSPBR() {} -func (s *NSService) EnableNSPBR() {} -func (s *NSService) DisableNSPBR() {} -func (s *NSService) GetAllNSPBR() {} -func (s *NSService) GetNSPBR() {} -func (s *NSService) CountNSPBR() {} + return &result.Data[0], nil +} -// nspbr6 -func (s *NSService) AddNSPBR6() {} -func (s *NSService) DeleteNSPBR6() {} -func (s *NSService) UpdateNSPBR6() {} -func (s *NSService) UnsetNSPBR6() {} -func (s *NSService) RenumberNSPBR6() {} -func (s *NSService) EnableNSPBR6() {} -func (s *NSService) DisableNSPBR6() {} -func (s *NSService) GetAllNSPBR6() {} -func (s *NSService) GetNSPBR6() {} -func (s *NSService) CountNSPBR6() {} -func (s *NSService) ClearNSPBR6() {} -func (s *NSService) ApplyNSPBR6() {} +func (s *NSService) CountNSAssignment() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsAssignmentURL), nil) + if err != nil { + return 0, err + } -// nspbrs -func (s *NSService) RenumberNSPBRs() {} -func (s *NSService) ClearNSPBRs() {} -func (s *NSService) ApplyNSPBRs() {} + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } -// nsratecontrol -func (s *NSService) UpdateNSrateControl() {} -func (s *NSService) UnsetNSrateControl() {} -func (s *NSService) GetAllNSrateControl() {} + var result struct { + Data []models.NSAssignment `json:"nsassignment"` + } -// nsrollbackcmd -func (s *NSService) GetAllNSRollBackCMD() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } -// nsrpcnode -func (s *NSService) UpdateNSRPCNode() {} -func (s *NSService) UnsetNSRPCNode() {} -func (s *NSService) GetAllNSRPCNode() {} -func (s *NSService) GetNSRPCNode() {} -func (s *NSService) CountNSRPCNode() {} + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} -// nsrunningconfig -func (s *NSService) GetAllNSRunningConfig() {} +func (s *NSService) RenameNSAssignment(resource models.NSAssignment) error { + payload := map[string]any{"nsassignment": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// nssavedconfig -func (s *NSService) GetAllNSSavedConfig() {} + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=rename", nsAssignmentURL), bytes.NewReader(data)) + if err != nil { + return err + } -// nsservicefunction -func (s *NSService) AddNSServiceFunction() {} -func (s *NSService) DeleteNSServiceFunction() {} -func (s *NSService) GetAllNSServiceFunction() {} -func (s *NSService) GetNSServiceFunction() {} -func (s *NSService) CountNSServiceFunction() {} + _, err = s.client.Do(req) + return err +} -// nsservicepath -func (s *NSService) AddNSServicePath() {} -func (s *NSService) DeleteNSServicePath() {} -func (s *NSService) GetAllNSServicePath() {} -func (s *NSService) GetNSServicePath() {} -func (s *NSService) CountNSServicePath() {} +// nscapacity +func (s *NSService) UpdateNSCapacity(resource models.NSCapacity) error { + payload := map[string]any{"nscapacity": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// nsservicepath_binding -func (s *NSService) GetAllNSServicePathBinding() {} -func (s *NSService) GetNSServicePathBinding() {} + req, err := s.client.NewRequest(http.MethodPut, nsCapacityURL, bytes.NewReader(data)) + if err != nil { + return err + } -// nsservicepath_nsservicefunction_binding -func (s *NSService) AddNSServicePathNSServiceFunctionBinding() {} -func (s *NSService) DeleteNSServicePathNSServiceFunctionBinding() {} -func (s *NSService) GetAllNSServicePathNSServiceFunctionBinding() {} -func (s *NSService) GetNSServicePathNSServiceFunctionBinding() {} -func (s *NSService) CountNSServicePathNSServiceFunctionBinding() {} + _, err = s.client.Do(req) + return err +} -// nssimpleacl -func (s *NSService) AddNSSimpleACL() {} -func (s *NSService) DeleteNSSimpleACL() {} -func (s *NSService) FlushNSSimpleACL() {} -func (s *NSService) GetAllNSSimpleACL() {} -func (s *NSService) GetNSSimpleACL() {} -func (s *NSService) CountNSSimpleACL() {} -func (s *NSService) ClearNSSimpleACL() {} +func (s *NSService) UnsetNSCapacity(resource models.NSCapacity) error { + payload := map[string]any{"nscapacity": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// nssimpleacl6 -func (s *NSService) AddNSSimpleACL6() {} -func (s *NSService) DeleteNSSimpleACL6() {} -func (s *NSService) FlushNSSimpleACL6() {} -func (s *NSService) GetAllNSSimpleACL6() {} -func (s *NSService) GetNSSimpleACL6() {} -func (s *NSService) CountNSSimpleACL6() {} -func (s *NSService) ClearNSSimpleACL6() {} + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsCapacityURL), bytes.NewReader(data)) + if err != nil { + return err + } -// nssourceroutecachetable -func (s *NSService) FlushNSSourceRouteCacheTable() {} -func (s *NSService) GetAllNSSourceRouteCacheTable() {} -func (s *NSService) CountNSSourceRouteCacheTable() {} + _, err = s.client.Do(req) + return err +} -// nsspparams -func (s *NSService) UpdateNSSPParams() {} -func (s *NSService) UnsetNSSPParams() {} -func (s *NSService) GetAllNSSPParams() {} +func (s *NSService) GetAllNSCapacity() ([]models.NSCapacity, error) { + req, err := s.client.NewRequest(http.MethodGet, nsCapacityURL, nil) + if err != nil { + return nil, err + } -// nsstats -func (s *NSService) ClearNSStats() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// nssurgeq -func (s *NSService) FlushNSSurgeQ() {} + var result struct { + Data []models.NSCapacity `json:"nscapacity"` + } -// nstcpbufparam -func (s *NSService) UpdateNSTCPBufParam() {} -func (s *NSService) UnsetNSTCPBufParam() {} -func (s *NSService) GetAllNSTCPBufParam() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// nstcpparam -func (s *NSService) UpdateNSTCPParam() {} -func (s *NSService) UnsetNSTCPParam() {} -func (s *NSService) GetAllNSTCPParam() {} + return result.Data, nil +} -// nstcpprofile -func (s *NSService) AddNSTCPProfile() {} -func (s *NSService) DeleteNSTCPProfile() {} -func (s *NSService) UpdateNSTCPProfile() {} -func (s *NSService) UnsetNSTCPProfile() {} -func (s *NSService) GetAllNSTCPProfile() {} -func (s *NSService) GetNSTCPProfile() {} -func (s *NSService) CountNSTCPProfile() {} +// nscentralmanagementserver +func (s *NSService) AddNSCentralManagementServer(resource models.NSCentralManagementServer) error { + payload := map[string]any{"nscentralmanagementserver": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// nstimeout -func (s *NSService) UpdateNSTimeout() {} -func (s *NSService) UnsetNSTimeout() {} -func (s *NSService) GetAllNSTimeout() {} + req, err := s.client.NewRequest(http.MethodPost, nsCentralManagementServerURL, bytes.NewReader(data)) + if err != nil { + return err + } -// nstimer -func (s *NSService) AddNSTimer() {} -func (s *NSService) DeleteNSTimer() {} -func (s *NSService) UpdateNSTimer() {} -func (s *NSService) UnsetNSTimer() {} -func (s *NSService) GetAllNSTimer() {} -func (s *NSService) GetNSTimer() {} -func (s *NSService) CountNSTimer() {} -func (s *NSService) RenameNSTimer() {} + _, err = s.client.Do(req) + return err +} -// nstimer_autoscalepolicy_binding -func (s *NSService) AddNSTimerAutoScalePolicyBinding() {} -func (s *NSService) DeleteNSTimerAutoScalePolicyBinding() {} -func (s *NSService) GetAllNSTimerAutoScalePolicyBinding() {} -func (s *NSService) GetNSTimerAutoScalePolicyBinding() {} -func (s *NSService) CountNSTimerAutoScalePolicyBinding() {} +func (s *NSService) DeleteNSCentralManagementServer(servername string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsCentralManagementServerURL, servername), nil) + if err != nil { + return err + } -// nstimer_binding -func (s *NSService) GetAllNSTimerBinding() {} -func (s *NSService) GetNSTimerBinding() {} + _, err = s.client.Do(req) + return err +} -// nstimezone -func (s *NSService) GetAllNSTimeZone() {} -func (s *NSService) GetNSTimeZone() {} -func (s *NSService) CountNSTimeZone() {} +func (s *NSService) GetAllNSCentralManagementServer() ([]models.NSCentralManagementServer, error) { + req, err := s.client.NewRequest(http.MethodGet, nsCentralManagementServerURL, nil) + if err != nil { + return nil, err + } -// nstrafficdomain -func (s *NSService) AddNSTrafficDomain() {} -func (s *NSService) DeleteNSTrafficDomain() {} -func (s *NSService) EnableNSTrafficDomain() {} -func (s *NSService) DisableNSTrafficDomain() {} -func (s *NSService) GetAllNSTrafficDomain() {} -func (s *NSService) GetNSTrafficDomain() {} -func (s *NSService) CountNSTrafficDomain() {} -func (s *NSService) ClearNSTrafficDomain() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// nstrafficdomain_binding -func (s *NSService) GetAllNSTrafficDomainBinding() {} -func (s *NSService) GetNSTrafficDomainBinding() {} + var result struct { + Data []models.NSCentralManagementServer `json:"nscentralmanagementserver"` + } -// nstrafficdomain_bridgegroup_binding -func (s *NSService) AddBSTrafficDomainBridgeGroupBinding() {} -func (s *NSService) DeleteBSTrafficDomainBridgeGroupBinding() {} -func (s *NSService) GetAllBSTrafficDomainBridgeGroupBinding() {} -func (s *NSService) GetBSTrafficDomainBridgeGroupBinding() {} -func (s *NSService) CountBSTrafficDomainBridgeGroupBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// nstrafficdomain_vlan_binding -func (s *NSService) AddNSTrafficDomainVLANBinding() {} -func (s *NSService) DeleteNSTrafficDomainVLANBinding() {} -func (s *NSService) GetAllNSTrafficDomainVLANBinding() {} -func (s *NSService) GetNSTrafficDomainVLANBinding() {} -func (s *NSService) CountNSTrafficDomainVLANBinding() {} + return result.Data, nil +} -// nstrafficdomain_vxlan_binding -func (s *NSService) AddNSTrafficDomainVXLANBinding() {} -func (s *NSService) DeleteNSTrafficDomainVXLANBinding() {} -func (s *NSService) GetAllNSTrafficDomainVXLANBinding() {} -func (s *NSService) GetNSTrafficDomainVXLANBinding() {} -func (s *NSService) CountNSTrafficDomainVXLANBinding() {} +func (s *NSService) GetNSCentralManagementServer(servername string) (*models.NSCentralManagementServer, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsCentralManagementServerURL, servername), nil) + if err != nil { + return nil, err + } -// nsvariable -func (s *NSService) AddNSVariable() {} -func (s *NSService) DeleteNSVariable() {} -func (s *NSService) UpdateNSVariable() {} -func (s *NSService) UnsetNSVariable() {} -func (s *NSService) GetAllNSVariable() {} -func (s *NSService) GetNSVariable() {} -func (s *NSService) CountNSVariable() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// nsversion -func (s *NSService) GetAllNSVersion() {} + var result struct { + Data []models.NSCentralManagementServer `json:"nscentralmanagementserver"` + } -// nsvpxparam -func (s *NSService) UpdateNSVPXParam() {} -func (s *NSService) UnsetNSVPXParam() {} -func (s *NSService) GetAllNSVPXParam() {} -func (s *NSService) CountNSVPXParam() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// nsweblogparam -func (s *NSService) UpdateNSWebLogParam() {} -func (s *NSService) UnsetNSWebLogParam() {} -func (s *NSService) GetAllNSWebLogParam() {} + if len(result.Data) == 0 { + return nil, fmt.Errorf("nscentralmanagementserver %s not found", servername) + } -// nsxmlnamespace -func (s *NSService) AddNSXMLNamespace() {} -func (s *NSService) DeleteNSXMLNamespace() {} -func (s *NSService) UpdateNSXMLNamespace() {} -func (s *NSService) UnsetNSXMLNamespace() {} -func (s *NSService) GetAllNSXMLNamespace() {} -func (s *NSService) GetNSXMLNamespace() {} -func (s *NSService) CountNSXMLNamespace() {} + return &result.Data[0], nil +} -// reboot -func (s *NSService) Reboot() {} +func (s *NSService) CountNSCentralManagementServer() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsCentralManagementServerURL), nil) + if err != nil { + return 0, err + } -// shutdown -func (s *NSService) Shutdown() {} + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSCentralManagementServer `json:"nscentralmanagementserver"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nsconfig +func (s *NSService) ClearNSConfig(resource models.NSConfig) error { + payload := map[string]any{"nsconfig": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=clear", nsConfigURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) SaveNSConfig(resource models.NSConfig) error { + payload := map[string]any{"nsconfig": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=save", nsConfigURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DiffNSConfig(resource models.NSConfig) error { + payload := map[string]any{"nsconfig": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=diff", nsConfigURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UpdateNSConfig(resource models.NSConfig) error { + payload := map[string]any{"nsconfig": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsConfigURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSConfig(resource models.NSConfig) error { + payload := map[string]any{"nsconfig": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsConfigURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSConfig() ([]models.NSConfig, error) { + req, err := s.client.NewRequest(http.MethodGet, nsConfigURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSConfig `json:"nsconfig"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// nsconnectiontable +func (s *NSService) GetAllNSconnectionTable(args map[string]string) ([]models.NSConnectionTable, error) { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s%s", nsConnectionTableURL, argsStr), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSConnectionTable `json:"nsconnectiontable"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) CountNSconnectionTable(args map[string]string) (int, error) { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + "&count=yes" + } else { + argsStr = "?count=yes" + } + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s%s", nsConnectionTableURL, argsStr), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSConnectionTable `json:"nsconnectiontable"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nsconsoleloginprompt +func (s *NSService) UpdateNSConsoleLoginPrompt(resource models.NSConsoleLoginPrompt) error { + payload := map[string]any{"nsconsoleloginprompt": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsConsoleLoginPromptURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSConsoleLoginPrompt(resource models.NSConsoleLoginPrompt) error { + payload := map[string]any{"nsconsoleloginprompt": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsConsoleLoginPromptURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSConsoleLoginPrompt() ([]models.NSConsoleLoginPrompt, error) { + req, err := s.client.NewRequest(http.MethodGet, nsConsoleLoginPromptURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSConsoleLoginPrompt `json:"nsconsoleloginprompt"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// nscqaparam +func (s *NSService) UpdateNSCQAParam(resource models.NSCQAParam) error { + payload := map[string]any{"nscqaparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsCQAParamURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSCQAParam(resource models.NSCQAParam) error { + payload := map[string]any{"nscqaparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsCQAParamURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSCQAParam() ([]models.NSCQAParam, error) { + req, err := s.client.NewRequest(http.MethodGet, nsCQAParamURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSCQAParam `json:"nscqaparam"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// nsdhcpip +func (s *NSService) ReleaseNSDHCPIP() error { + payload := map[string]any{"nsdhcpip": map[string]any{}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=release", nsDHCPIPURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// nsdhcpparams +func (s *NSService) UpdateNSDHCPParams(resource models.NSDHCPParams) error { + payload := map[string]any{"nsdhcpparams": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsDHCPParamsURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSDHCPParams(resource models.NSDHCPParams) error { + payload := map[string]any{"nsdhcpparams": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsDHCPParamsURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSDHCPParams() ([]models.NSDHCPParams, error) { + req, err := s.client.NewRequest(http.MethodGet, nsDHCPParamsURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSDHCPParams `json:"nsdhcpparams"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// nsdiamter +func (s *NSService) UpdateNSDiameter(resource models.NSDiameter) error { + payload := map[string]any{"nsdiameter": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsDiameterURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSDiameter(resource models.NSDiameter) error { + payload := map[string]any{"nsdiameter": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsDiameterURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSDiameter() ([]models.NSDiameter, error) { + req, err := s.client.NewRequest(http.MethodGet, nsDiameterURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSDiameter `json:"nsdiameter"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSDiameter() (*models.NSDiameter, error) { + req, err := s.client.NewRequest(http.MethodGet, nsDiameterURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSDiameter `json:"nsdiameter"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nsdiameter not found") + } + + return &result.Data[0], nil +} + +func (s *NSService) CountNSDiameter() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsDiameterURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSDiameter `json:"nsdiameter"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nsencyrptionkey +func (s *NSService) AddNSEncryptionKey(resource models.NSEncryptionKey) error { + payload := map[string]any{"nsencryptionkey": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsEncryptionKeyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSEncryptionKey(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsEncryptionKeyURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UpdateNSEncryptionKey(resource models.NSEncryptionKey) error { + payload := map[string]any{"nsencryptionkey": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsEncryptionKeyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSEncryptionKey(resource models.NSEncryptionKey) error { + payload := map[string]any{"nsencryptionkey": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsEncryptionKeyURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSEncryptionKey() ([]models.NSEncryptionKey, error) { + req, err := s.client.NewRequest(http.MethodGet, nsEncryptionKeyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSEncryptionKey `json:"nsencryptionkey"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSEncryptionKey(name string) (*models.NSEncryptionKey, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsEncryptionKeyURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSEncryptionKey `json:"nsencryptionkey"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nsencryptionkey %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *NSService) CountNSEncryptionKey() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsEncryptionKeyURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSEncryptionKey `json:"nsencryptionkey"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nsencryptionparams +func (s *NSService) UpdateNSEncryptionParams(resource models.NSEncryptionParams) error { + payload := map[string]any{"nsencryptionparams": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsEncryptionParamsURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSEncryptionParams() ([]models.NSEncryptionParams, error) { + req, err := s.client.NewRequest(http.MethodGet, nsEncryptionParamsURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSEncryptionParams `json:"nsencryptionparams"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// nsevents +func (s *NSService) GetAllNSEvents() ([]models.NSEvents, error) { + req, err := s.client.NewRequest(http.MethodGet, nsEventsURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSEvents `json:"nsevents"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) CountNSEvents() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsEventsURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSEvents `json:"nsevents"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nsextension +func (s *NSService) ImportNSExtension(resource models.NSExtension) error { + payload := map[string]any{"nsextension": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=import", nsExtensionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) AddNSExtension(resource models.NSExtension) error { + payload := map[string]any{"nsextension": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsExtensionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSExtension(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsExtensionURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UpdateNSExtension(resource models.NSExtension) error { + payload := map[string]any{"nsextension": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsExtensionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSExtension(resource models.NSExtension) error { + payload := map[string]any{"nsextension": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsExtensionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSExtension() ([]models.NSExtension, error) { + req, err := s.client.NewRequest(http.MethodGet, nsExtensionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSExtension `json:"nsextension"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSExtension(name string) (*models.NSExtension, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsExtensionURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSExtension `json:"nsextension"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nsextension %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *NSService) CountNSExtension() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsExtensionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSExtension `json:"nsextension"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +func (s *NSService) ChangeNSExtension(resource models.NSExtension) error { + payload := map[string]any{"nsextension": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=change", nsExtensionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// nsextension_binding +func (s *NSService) GetAllNSExtenionBinding() ([]models.NSExtensionBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, nsExtensionBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSExtensionBinding `json:"nsextension_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSExtenionBinding(name string) (*models.NSExtensionBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsExtensionBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSExtensionBinding `json:"nsextension_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nsextension_binding %s not found", name) + } + + return &result.Data[0], nil +} + +// nsextension_extensionfunction_binding +func (s *NSService) GetAllNSExtensionExtensionFunctionBinding() ([]models.NSExtensionExtensionFunctionBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, nsExtensionExtensionFunctionBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSExtensionExtensionFunctionBinding `json:"nsextension_extensionfunction_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSExtensionExtensionFunctionBinding(name string) ([]models.NSExtensionExtensionFunctionBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsExtensionExtensionFunctionBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSExtensionExtensionFunctionBinding `json:"nsextension_extensionfunction_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) CountNSExtensionExtensionFunctionBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", nsExtensionExtensionFunctionBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSExtensionExtensionFunctionBinding `json:"nsextension_extensionfunction_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nsfeature +func (s *NSService) EnableNSFeature(resource models.NSFeature) error { + payload := map[string]any{"nsfeature": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=enable", nsFeatureURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DisableNSFeature(resource models.NSFeature) error { + payload := map[string]any{"nsfeature": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=disable", nsFeatureURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSFeature() ([]models.NSFeature, error) { + req, err := s.client.NewRequest(http.MethodGet, nsFeatureURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSFeature `json:"nsfeature"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// nshardware +func (s *NSService) GetAllNSHardware() ([]models.NSHardware, error) { + req, err := s.client.NewRequest(http.MethodGet, nsHardwareURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSHardware `json:"nshardware"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// nshmackey +func (s *NSService) AddNSHMACKey(resource models.NSHMACKey) error { + payload := map[string]any{"nshmackey": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsHMACKeyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSHMACKey(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsHMACKeyURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UpdateNSHMACKey(resource models.NSHMACKey) error { + payload := map[string]any{"nshmackey": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsHMACKeyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSHMACKey(resource models.NSHMACKey) error { + payload := map[string]any{"nshmackey": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsHMACKeyURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSHMACKey() ([]models.NSHMACKey, error) { + req, err := s.client.NewRequest(http.MethodGet, nsHMACKeyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSHMACKey `json:"nshmackey"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSHMACKey(name string) (*models.NSHMACKey, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsHMACKeyURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSHMACKey `json:"nshmackey"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nshmackey %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *NSService) CountNSHMACKey() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsHMACKeyURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSHMACKey `json:"nshmackey"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nshostname +func (s *NSService) UpdateNSHostname(resource models.NSHostname) error { + payload := map[string]any{"nshostname": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsHostnameURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSHostname() ([]models.NSHostname, error) { + req, err := s.client.NewRequest(http.MethodGet, nsHostnameURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSHostname `json:"nshostname"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) CountNSHostname() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsHostnameURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSHostname `json:"nshostname"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nshttpparam +func (s *NSService) UpdateNSHTTPParam(resource models.NSHTTPParam) error { + payload := map[string]any{"nshttpparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsHTTPParamURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSHTTPParam() ([]models.NSHTTPParam, error) { + req, err := s.client.NewRequest(http.MethodGet, nsHTTPParamURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSHTTPParam `json:"nshttpparam"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) CountNSHTTPParam() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsHTTPParamURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSHTTPParam `json:"nshttpparam"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nshttpprofile +func (s *NSService) AddNSHTTPProfile(resource models.NSHTTPProfile) error { + payload := map[string]any{"nshttpprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsHTTPProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSHTTPProfile(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsHTTPProfileURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UpdateNSHTTPProfile(resource models.NSHTTPProfile) error { + payload := map[string]any{"nshttpprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsHTTPProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSHTTPProfile(resource models.NSHTTPProfile) error { + payload := map[string]any{"nshttpprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsHTTPProfileURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSHTTPProfile() ([]models.NSHTTPProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, nsHTTPProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSHTTPProfile `json:"nshttpprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSHTTPProfile(name string) (*models.NSHTTPProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsHTTPProfileURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSHTTPProfile `json:"nshttpprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nshttpprofile %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *NSService) CountNSHTTPProfile() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsHTTPProfileURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSHTTPProfile `json:"nshttpprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nsicapprofile +func (s *NSService) AddNSICAPProfile(resource models.NSICAPProfile) error { + payload := map[string]any{"nsicapprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsICAPProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSICAPProfile(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsICAPProfileURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UpdateNSICAPProfile(resource models.NSICAPProfile) error { + payload := map[string]any{"nsicapprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsICAPProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSICAPProfile(resource models.NSICAPProfile) error { + payload := map[string]any{"nsicapprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsICAPProfileURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSICAPProfile() ([]models.NSICAPProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, nsICAPProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSICAPProfile `json:"nsicapprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSICAPProfile(name string) (*models.NSICAPProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsICAPProfileURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSICAPProfile `json:"nsicapprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nsicapprofile %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *NSService) CountNSICAPProfile() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsICAPProfileURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSICAPProfile `json:"nsicapprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nsip +func (s *NSService) AddNSIP(resource models.NSIP) error { + payload := map[string]any{"nsip": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsIPURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSIP(ipaddress string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsIPURL, ipaddress), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UpdateNSIP(resource models.NSIP) error { + payload := map[string]any{"nsip": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsIPURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSIP(resource models.NSIP) error { + payload := map[string]any{"nsip": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsIPURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) EnableNSIP(resource models.NSIP) error { + payload := map[string]any{"nsip": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=enable", nsIPURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DisableNSIP(resource models.NSIP) error { + payload := map[string]any{"nsip": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=disable", nsIPURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSIP() ([]models.NSIP, error) { + req, err := s.client.NewRequest(http.MethodGet, nsIPURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSIP `json:"nsip"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) CountNSIP() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsIPURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSIP `json:"nsip"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nsip6 +func (s *NSService) AddNSIP6(resource models.NSIP6) error { + payload := map[string]any{"nsip6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsIP6URL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSIP6(ipv6address string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsIP6URL, ipv6address), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UpdateNSIP6(resource models.NSIP6) error { + payload := map[string]any{"nsip6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsIP6URL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSIP6(resource models.NSIP6) error { + payload := map[string]any{"nsip6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsIP6URL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSIP6() ([]models.NSIP6, error) { + req, err := s.client.NewRequest(http.MethodGet, nsIP6URL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSIP6 `json:"nsip6"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) CountNSIP6() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsIP6URL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSIP6 `json:"nsip6"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nslicense +func (s *NSService) GetAllNSLicense() ([]models.NSLicense, error) { + req, err := s.client.NewRequest(http.MethodGet, nsLicenseURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSLicense `json:"nslicense"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// nslicenseproxyserver +func (s *NSService) AddNSLicenseProxyServer(resource models.NSLicenseProxyServer) error { + payload := map[string]any{"nslicenseproxyserver": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsLicenseProxyServerURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSLicenseProxyServer(serverip string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsLicenseProxyServerURL, serverip), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UpdateNSLicenseProxyServer(resource models.NSLicenseProxyServer) error { + payload := map[string]any{"nslicenseproxyserver": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsLicenseProxyServerURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSLicenseProxyServer() ([]models.NSLicenseProxyServer, error) { + req, err := s.client.NewRequest(http.MethodGet, nsLicenseProxyServerURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSLicenseProxyServer `json:"nslicenseproxyserver"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) CountNSLicenseProxyServer() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsLicenseProxyServerURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSLicenseProxyServer `json:"nslicenseproxyserver"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nslicenseserver +func (s *NSService) AddNSLicenseServer(resource models.NSLicenseServer) error { + payload := map[string]any{"nslicenseserver": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsLicenseServerURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSLicenseServer(servername string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsLicenseServerURL, servername), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UpdateNSLicenseServer(resource models.NSLicenseServer) error { + payload := map[string]any{"nslicenseserver": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsLicenseServerURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSLicenseServer() ([]models.NSLicenseServer, error) { + req, err := s.client.NewRequest(http.MethodGet, nsLicenseServerURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSLicenseServer `json:"nslicenseserver"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) CountNSLicenseServer() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsLicenseServerURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSLicenseServer `json:"nslicenseserver"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nslicenseserverpool +func (s *NSService) GetAllNSLicenseServerPool() ([]models.NSLicenseServerPool, error) { + req, err := s.client.NewRequest(http.MethodGet, nsLicenseServerPoolURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSLicenseServerPool `json:"nslicenseserverpool"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// nslimitidentifier +func (s *NSService) AddNSLimitIdentifier(resource models.NSLimitIdentifier) error { + payload := map[string]any{"nslimitidentifier": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsLimitIdentifierURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSLimitIdentifier(limitidentifier string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsLimitIdentifierURL, limitidentifier), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UpdateNSLimitIdentifier(resource models.NSLimitIdentifier) error { + payload := map[string]any{"nslimitidentifier": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsLimitIdentifierURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSLimitIdentifier(resource models.NSLimitIdentifier) error { + payload := map[string]any{"nslimitidentifier": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsLimitIdentifierURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSLimitIdentifier() ([]models.NSLimitIdentifier, error) { + req, err := s.client.NewRequest(http.MethodGet, nsLimitIdentifierURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSLimitIdentifier `json:"nslimitidentifier"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSLimitIdentifier(limitidentifier string) (*models.NSLimitIdentifier, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsLimitIdentifierURL, limitidentifier), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSLimitIdentifier `json:"nslimitidentifier"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nslimitidentifier %s not found", limitidentifier) + } + + return &result.Data[0], nil +} + +func (s *NSService) CountNSLimitIdentifier() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsLimitIdentifierURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSLimitIdentifier `json:"nslimitidentifier"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nslimitidentifier_binding +func (s *NSService) GetAllNSLimitIdentifierBinding() ([]models.NSLimitIdentifierBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, nsLimitIdentifierBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSLimitIdentifierBinding `json:"nslimitidentifier_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSLimitIdentifierBinding(limitidentifier string) (*models.NSLimitIdentifierBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsLimitIdentifierBindingURL, limitidentifier), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSLimitIdentifierBinding `json:"nslimitidentifier_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nslimitidentifier_binding %s not found", limitidentifier) + } + + return &result.Data[0], nil +} + +// nslimitidentifier_nslimitsessions_binding +func (s *NSService) GetAllNSLimitIdentifierNSLimitSessionsBinding() ([]models.NSLimitIdentifierNSLimitSessionsBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, nsLimitIdentifierNSLimitSessionsBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSLimitIdentifierNSLimitSessionsBinding `json:"nslimitidentifier_nslimitsessions_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSLimitIdentifierNSLimitSessionsBinding(limitidentifier string) ([]models.NSLimitIdentifierNSLimitSessionsBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsLimitIdentifierNSLimitSessionsBindingURL, limitidentifier), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSLimitIdentifierNSLimitSessionsBinding `json:"nslimitidentifier_nslimitsessions_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) CountNSLimitIdentifierNSLimitSessionsBinding(limitidentifier string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", nsLimitIdentifierNSLimitSessionsBindingURL, limitidentifier), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSLimitIdentifierNSLimitSessionsBinding `json:"nslimitidentifier_nslimitsessions_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nslimitselector +func (s *NSService) AddNSLimitSelector(resource models.NSLimitSelector) error { + payload := map[string]any{"nslimitselector": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsLimitSelectorURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSLimitSelector(selectorname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsLimitSelectorURL, selectorname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UpdateNSLimitSelector(resource models.NSLimitSelector) error { + payload := map[string]any{"nslimitselector": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsLimitSelectorURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSLimitSelector(resource models.NSLimitSelector) error { + payload := map[string]any{"nslimitselector": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsLimitSelectorURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSLimitSelector() ([]models.NSLimitSelector, error) { + req, err := s.client.NewRequest(http.MethodGet, nsLimitSelectorURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSLimitSelector `json:"nslimitselector"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSLimitSelector(selectorname string) (*models.NSLimitSelector, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsLimitSelectorURL, selectorname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSLimitSelector `json:"nslimitselector"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nslimitselector %s not found", selectorname) + } + + return &result.Data[0], nil +} + +func (s *NSService) CountNSLimitSelector() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsLimitSelectorURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSLimitSelector `json:"nslimitselector"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nslimitsessions +func (s *NSService) GetAllNSLimitSessions(args map[string]string) ([]models.NSLimitSessions, error) { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s%s", nsLimitSessionsURL, argsStr), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSLimitSessions `json:"nslimitsessions"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) CountNSLimitSessions(args map[string]string) (int, error) { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + "&count=yes" + } else { + argsStr = "?count=yes" + } + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s%s", nsLimitSessionsURL, argsStr), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSLimitSessions `json:"nslimitsessions"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +func (s *NSService) ClearNSLimitSessions(resource models.NSLimitSessions) error { + payload := map[string]any{"nslimitsessions": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=clear", nsLimitSessionsURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// nsmigration +func (s *NSService) GetAllNSMigration() ([]models.NSMigration, error) { + req, err := s.client.NewRequest(http.MethodGet, nsMigrationURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSMigration `json:"nsmigration"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) CountNSMigration() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsMigrationURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSMigration `json:"nsmigration"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nsmode +func (s *NSService) EnableNSMode(resource models.NSMode) error { + payload := map[string]any{"nsmode": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=enable", nsModeURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DisableNSMode(resource models.NSMode) error { + payload := map[string]any{"nsmode": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=disable", nsModeURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSMode() ([]models.NSMode, error) { + req, err := s.client.NewRequest(http.MethodGet, nsModeURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSMode `json:"nsmode"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// nsparam +func (s *NSService) UpdateNSParam(resource models.NSParam) error { + payload := map[string]any{"nsparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsParamURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSParam(resource models.NSParam) error { + payload := map[string]any{"nsparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsParamURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSParam() ([]models.NSParam, error) { + req, err := s.client.NewRequest(http.MethodGet, nsParamURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSParam `json:"nsparam"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// nspartition +func (s *NSService) AddNSPartition(resource models.NSPartition) error { + payload := map[string]any{"nspartition": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsPartitionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSPartition(partitionname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsPartitionURL, partitionname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UpdateNSPartition(resource models.NSPartition) error { + payload := map[string]any{"nspartition": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsPartitionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSPartition(resource models.NSPartition) error { + payload := map[string]any{"nspartition": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsPartitionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) SwitchNSPartition(resource models.NSPartition) error { + payload := map[string]any{"nspartition": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=switch", nsPartitionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSPartition() ([]models.NSPartition, error) { + req, err := s.client.NewRequest(http.MethodGet, nsPartitionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSPartition `json:"nspartition"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSPartition(partitionname string) (*models.NSPartition, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsPartitionURL, partitionname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSPartition `json:"nspartition"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nspartition %s not found", partitionname) + } + + return &result.Data[0], nil +} + +func (s *NSService) CountNSPartition() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsPartitionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSPartition `json:"nspartition"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nspartitionmac +func (s *NSService) GetAllNSPartitionMAC() ([]models.NSPartitionMac, error) { + req, err := s.client.NewRequest(http.MethodGet, nsPartitionMACURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSPartitionMac `json:"nspartitionmac"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) CountNSPartitionMAC() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsPartitionMACURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSPartitionMac `json:"nspartitionmac"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nspartition_binding +func (s *NSService) GetAllNSPartitionBinding() ([]models.NSPartitionBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, nsPartitionBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSPartitionBinding `json:"nspartition_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSPartitionBinding(partitionname string) (*models.NSPartitionBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsPartitionBindingURL, partitionname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSPartitionBinding `json:"nspartition_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nspartition_binding %s not found", partitionname) + } + + return &result.Data[0], nil +} + +// nspartition_bridgegroup_binding +func (s *NSService) AddNSPartitionBridgeGroupBinding(resource models.NSPartitionBridgeGroupBinding) error { + payload := map[string]any{"nspartition_bridgegroup_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsPartitionBridgeGroupBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSPartitionBridgeGroupBinding(partitionname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsPartitionBridgeGroupBindingURL, partitionname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSPartitionBridgeGroupBinding() ([]models.NSPartitionBridgeGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, nsPartitionBridgeGroupBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSPartitionBridgeGroupBinding `json:"nspartition_bridgegroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSPartitionBridgeGroupBinding(partitionname string) ([]models.NSPartitionBridgeGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsPartitionBridgeGroupBindingURL, partitionname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSPartitionBridgeGroupBinding `json:"nspartition_bridgegroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) CountNSPartitionBridgeGroupBinding(partitionname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", nsPartitionBridgeGroupBindingURL, partitionname), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSPartitionBridgeGroupBinding `json:"nspartition_bridgegroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nspartition_vlan_binding +func (s *NSService) AddNSPartitionVLANBinding(resource models.NSPartitionVlanBinding) error { + payload := map[string]any{"nspartition_vlan_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsPartitionVlanBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSPartitionVLANBinding(partitionname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsPartitionVlanBindingURL, partitionname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSPartitionVLANBinding() ([]models.NSPartitionVlanBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, nsPartitionVlanBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSPartitionVlanBinding `json:"nspartition_vlan_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSPartitionVLANBinding(partitionname string) ([]models.NSPartitionVlanBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsPartitionVlanBindingURL, partitionname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSPartitionVlanBinding `json:"nspartition_vlan_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) CountNSPartitionVLANBinding(partitionname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", nsPartitionVlanBindingURL, partitionname), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSPartitionVlanBinding `json:"nspartition_vlan_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nspartition_vxlan_binding +func (s *NSService) AddNSPartitionVXLANBinding(resource models.NSPartitionVXLANBinding) error { + payload := map[string]any{"nspartition_vxlan_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsPartitionVXLANBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSPartitionVXLANBinding(partitionname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsPartitionVXLANBindingURL, partitionname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSPartitionVXLANBinding() ([]models.NSPartitionVXLANBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, nsPartitionVXLANBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSPartitionVXLANBinding `json:"nspartition_vxlan_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSPartitionVXLANBinding(partitionname string) ([]models.NSPartitionVXLANBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsPartitionVXLANBindingURL, partitionname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSPartitionVXLANBinding `json:"nspartition_vxlan_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) CountNSPartitionVXLANBinding(partitionname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", nsPartitionVXLANBindingURL, partitionname), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSPartitionVXLANBinding `json:"nspartition_vxlan_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nspbr +func (s *NSService) AddNSPBR(resource models.NSPBR) error { + payload := map[string]any{"nspbr": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsPBRURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSPBR(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsPBRURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UpdateNSPBR(resource models.NSPBR) error { + payload := map[string]any{"nspbr": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsPBRURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSPBR(resource models.NSPBR) error { + payload := map[string]any{"nspbr": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsPBRURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) EnableNSPBR(resource models.NSPBR) error { + payload := map[string]any{"nspbr": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=enable", nsPBRURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DisableNSPBR(resource models.NSPBR) error { + payload := map[string]any{"nspbr": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=disable", nsPBRURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSPBR() ([]models.NSPBR, error) { + req, err := s.client.NewRequest(http.MethodGet, nsPBRURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSPBR `json:"nspbr"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSPBR(name string) (*models.NSPBR, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsPBRURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSPBR `json:"nspbr"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nspbr %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *NSService) CountNSPBR() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsPBRURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSPBR `json:"nspbr"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nspbr6 +func (s *NSService) AddNSPBR6(resource models.NSPBR6) error { + payload := map[string]any{"nspbr6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsPBR6URL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSPBR6(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsPBR6URL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UpdateNSPBR6(resource models.NSPBR6) error { + payload := map[string]any{"nspbr6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsPBR6URL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSPBR6(resource models.NSPBR6) error { + payload := map[string]any{"nspbr6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsPBR6URL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) RenumberNSPBR6(resource models.NSPBR6) error { + payload := map[string]any{"nspbr6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=renumber", nsPBR6URL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) EnableNSPBR6(resource models.NSPBR6) error { + payload := map[string]any{"nspbr6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=enable", nsPBR6URL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DisableNSPBR6(resource models.NSPBR6) error { + payload := map[string]any{"nspbr6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=disable", nsPBR6URL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSPBR6() ([]models.NSPBR6, error) { + req, err := s.client.NewRequest(http.MethodGet, nsPBR6URL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSPBR6 `json:"nspbr6"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSPBR6(name string) (*models.NSPBR6, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsPBR6URL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSPBR6 `json:"nspbr6"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nspbr6 %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *NSService) CountNSPBR6() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsPBR6URL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSPBR6 `json:"nspbr6"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +func (s *NSService) ClearNSPBR6(resource models.NSPBR6) error { + payload := map[string]any{"nspbr6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=clear", nsPBR6URL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) ApplyNSPBR6(resource models.NSPBR6) error { + payload := map[string]any{"nspbr6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=apply", nsPBR6URL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// nspbrs +func (s *NSService) RenumberNSPBRs() error { + payload := map[string]any{"nspbrs": map[string]any{}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=renumber", nsPBRsURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) ClearNSPBRs() error { + payload := map[string]any{"nspbrs": map[string]any{}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=clear", nsPBRsURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) ApplyNSPBRs() error { + payload := map[string]any{"nspbrs": map[string]any{}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=apply", nsPBRsURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// nsratecontrol +func (s *NSService) UpdateNSrateControl(resource models.NSRateControl) error { + payload := map[string]any{"nsratecontrol": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsRateControlURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSrateControl(resource models.NSRateControl) error { + payload := map[string]any{"nsratecontrol": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsRateControlURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSrateControl() ([]models.NSRateControl, error) { + req, err := s.client.NewRequest(http.MethodGet, nsRateControlURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSRateControl `json:"nsratecontrol"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// nsrollbackcmd +func (s *NSService) GetAllNSRollBackCMD() ([]models.NSRollbackCmd, error) { + req, err := s.client.NewRequest(http.MethodGet, nsRollBackCMDURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSRollbackCmd `json:"nsrollbackcmd"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// nsrpcnode +func (s *NSService) UpdateNSRPCNode(resource models.NSRPCNode) error { + payload := map[string]any{"nsrpcnode": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsRPCNodeURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSRPCNode(resource models.NSRPCNode) error { + payload := map[string]any{"nsrpcnode": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsRPCNodeURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSRPCNode() ([]models.NSRPCNode, error) { + req, err := s.client.NewRequest(http.MethodGet, nsRPCNodeURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSRPCNode `json:"nsrpcnode"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSRPCNode(ipaddress string) (*models.NSRPCNode, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsRPCNodeURL, ipaddress), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSRPCNode `json:"nsrpcnode"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nsrpcnode %s not found", ipaddress) + } + + return &result.Data[0], nil +} + +func (s *NSService) CountNSRPCNode() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsRPCNodeURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSRPCNode `json:"nsrpcnode"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nsrunningconfig +func (s *NSService) GetAllNSRunningConfig() ([]models.NSRunningConfig, error) { + req, err := s.client.NewRequest(http.MethodGet, nsRunningConfigURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSRunningConfig `json:"nsrunningconfig"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// nssavedconfig +func (s *NSService) GetAllNSSavedConfig() ([]models.NSSavedConfig, error) { + req, err := s.client.NewRequest(http.MethodGet, nsSavedConfigURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSSavedConfig `json:"nssavedconfig"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// nsservicefunction +func (s *NSService) AddNSServiceFunction(resource models.NSServiceFunction) error { + payload := map[string]any{"nsservicefunction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsServiceFunctionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSServiceFunction(servicefunctionname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsServiceFunctionURL, servicefunctionname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSServiceFunction() ([]models.NSServiceFunction, error) { + req, err := s.client.NewRequest(http.MethodGet, nsServiceFunctionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSServiceFunction `json:"nsservicefunction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSServiceFunction(servicefunctionname string) (*models.NSServiceFunction, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsServiceFunctionURL, servicefunctionname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSServiceFunction `json:"nsservicefunction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nsservicefunction %s not found", servicefunctionname) + } + + return &result.Data[0], nil +} + +func (s *NSService) CountNSServiceFunction() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsServiceFunctionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSServiceFunction `json:"nsservicefunction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nsservicepath +func (s *NSService) AddNSServicePath(resource models.NSServicePath) error { + payload := map[string]any{"nsservicepath": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsServicePathURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSServicePath(servicepathname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsServicePathURL, servicepathname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSServicePath() ([]models.NSServicePath, error) { + req, err := s.client.NewRequest(http.MethodGet, nsServicePathURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSServicePath `json:"nsservicepath"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSServicePath(servicepathname string) (*models.NSServicePath, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsServicePathURL, servicepathname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSServicePath `json:"nsservicepath"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nsservicepath %s not found", servicepathname) + } + + return &result.Data[0], nil +} + +func (s *NSService) CountNSServicePath() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsServicePathURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSServicePath `json:"nsservicepath"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nsservicepath_binding +func (s *NSService) GetAllNSServicePathBinding() ([]models.NSServicePathBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, nsServicePathBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSServicePathBinding `json:"nsservicepath_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSServicePathBinding(servicepathname string) (*models.NSServicePathBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsServicePathBindingURL, servicepathname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSServicePathBinding `json:"nsservicepath_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nsservicepath_binding %s not found", servicepathname) + } + + return &result.Data[0], nil +} + +// nsservicepath_nsservicefunction_binding +func (s *NSService) AddNSServicePathNSServiceFunctionBinding(resource models.NSServicePathNSServiceFunctionBinding) error { + payload := map[string]any{"nsservicepath_nsservicefunction_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsServicePathNSServiceFunctionBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSServicePathNSServiceFunctionBinding(servicepathname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsServicePathNSServiceFunctionBindingURL, servicepathname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSServicePathNSServiceFunctionBinding() ([]models.NSServicePathNSServiceFunctionBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, nsServicePathNSServiceFunctionBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSServicePathNSServiceFunctionBinding `json:"nsservicepath_nsservicefunction_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSServicePathNSServiceFunctionBinding(servicepathname string) ([]models.NSServicePathNSServiceFunctionBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsServicePathNSServiceFunctionBindingURL, servicepathname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSServicePathNSServiceFunctionBinding `json:"nsservicepath_nsservicefunction_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) CountNSServicePathNSServiceFunctionBinding(servicepathname string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", nsServicePathNSServiceFunctionBindingURL, servicepathname), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSServicePathNSServiceFunctionBinding `json:"nsservicepath_nsservicefunction_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nssimpleacl +func (s *NSService) AddNSSimpleACL(resource models.NSSimpleACL) error { + payload := map[string]any{"nssimpleacl": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsSimpleACLURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSSimpleACL(aclname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsSimpleACLURL, aclname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) FlushNSSimpleACL() error { + payload := map[string]any{"nssimpleacl": map[string]any{}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=flush", nsSimpleACLURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSSimpleACL() ([]models.NSSimpleACL, error) { + req, err := s.client.NewRequest(http.MethodGet, nsSimpleACLURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSSimpleACL `json:"nssimpleacl"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSSimpleACL(aclname string) (*models.NSSimpleACL, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsSimpleACLURL, aclname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSSimpleACL `json:"nssimpleacl"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nssimpleacl %s not found", aclname) + } + + return &result.Data[0], nil +} + +func (s *NSService) CountNSSimpleACL() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsSimpleACLURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSSimpleACL `json:"nssimpleacl"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +func (s *NSService) ClearNSSimpleACL(resource models.NSSimpleACL) error { + payload := map[string]any{"nssimpleacl": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=clear", nsSimpleACLURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// nssimpleacl6 +func (s *NSService) AddNSSimpleACL6(resource models.NSSimpleACL6) error { + payload := map[string]any{"nssimpleacl6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsSimpleACL6URL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSSimpleACL6(aclname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsSimpleACL6URL, aclname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) FlushNSSimpleACL6() error { + payload := map[string]any{"nssimpleacl6": map[string]any{}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=flush", nsSimpleACL6URL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSSimpleACL6() ([]models.NSSimpleACL6, error) { + req, err := s.client.NewRequest(http.MethodGet, nsSimpleACL6URL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSSimpleACL6 `json:"nssimpleacl6"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSSimpleACL6(aclname string) (*models.NSSimpleACL6, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsSimpleACL6URL, aclname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSSimpleACL6 `json:"nssimpleacl6"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nssimpleacl6 %s not found", aclname) + } + + return &result.Data[0], nil +} + +func (s *NSService) CountNSSimpleACL6() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsSimpleACL6URL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSSimpleACL6 `json:"nssimpleacl6"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +func (s *NSService) ClearNSSimpleACL6(resource models.NSSimpleACL6) error { + payload := map[string]any{"nssimpleacl6": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=clear", nsSimpleACL6URL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// nssourceroutecachetable +func (s *NSService) FlushNSSourceRouteCacheTable() error { + payload := map[string]any{"nssourceroutecachetable": map[string]any{}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=flush", nsSourceRouteCacheTableURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSSourceRouteCacheTable() ([]models.NSSourceRouteCacheTable, error) { + req, err := s.client.NewRequest(http.MethodGet, nsSourceRouteCacheTableURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSSourceRouteCacheTable `json:"nssourceroutecachetable"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) CountNSSourceRouteCacheTable() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsSourceRouteCacheTableURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSSourceRouteCacheTable `json:"nssourceroutecachetable"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nsspparams +func (s *NSService) UpdateNSSPParams(resource models.NSSPParams) error { + payload := map[string]any{"nsspparams": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsSPParamsURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} +func (s *NSService) UnsetNSSPParams(resource models.NSSPParams) error { + payload := map[string]any{"nsspparams": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsSPParamsURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSSPParams() ([]models.NSSPParams, error) { + req, err := s.client.NewRequest(http.MethodGet, nsSPParamsURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSSPParams `json:"nsspparams"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// nsstats +func (s *NSService) ClearNSStats(resource models.NSStats) error { + payload := map[string]any{"nsstats": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=clear", nsStatsURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// nssurgeq +func (s *NSService) FlushNSSurgeQ() error { + payload := map[string]any{"nssurgeq": map[string]any{}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=flush", nsSurgeQURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// nstcpbufparam +func (s *NSService) UpdateNSTCPBufParam(resource models.NSTCPBufParam) error { + payload := map[string]any{"nstcpbufparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsTCPBufParamURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSTCPBufParam(resource models.NSTCPBufParam) error { + payload := map[string]any{"nstcpbufparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsTCPBufParamURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSTCPBufParam() ([]models.NSTCPBufParam, error) { + req, err := s.client.NewRequest(http.MethodGet, nsTCPBufParamURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSTCPBufParam `json:"nstcpbufparam"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// nstcpparam +func (s *NSService) UpdateNSTCPParam(resource models.NSTCPParam) error { + payload := map[string]any{"nstcpparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsTCPParamURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSTCPParam(resource models.NSTCPParam) error { + payload := map[string]any{"nstcpparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsTCPParamURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSTCPParam() ([]models.NSTCPParam, error) { + req, err := s.client.NewRequest(http.MethodGet, nsTCPParamURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSTCPParam `json:"nstcpparam"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// nstcpprofile +func (s *NSService) AddNSTCPProfile(resource models.NSTCPProfile) error { + payload := map[string]any{"nstcpprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsTCPProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSTCPProfile(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsTCPProfileURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UpdateNSTCPProfile(resource models.NSTCPProfile) error { + payload := map[string]any{"nstcpprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsTCPProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSTCPProfile(resource models.NSTCPProfile) error { + payload := map[string]any{"nstcpprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsTCPProfileURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSTCPProfile() ([]models.NSTCPProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, nsTCPProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSTCPProfile `json:"nstcpprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSTCPProfile(name string) (*models.NSTCPProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsTCPProfileURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSTCPProfile `json:"nstcpprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nstcpprofile %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *NSService) CountNSTCPProfile() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsTCPProfileURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSTCPProfile `json:"nstcpprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nstimeout +func (s *NSService) UpdateNSTimeout(resource models.NSTimeout) error { + payload := map[string]any{"nstimeout": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsTimeoutURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSTimeout(resource models.NSTimeout) error { + payload := map[string]any{"nstimeout": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsTimeoutURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSTimeout() ([]models.NSTimeout, error) { + req, err := s.client.NewRequest(http.MethodGet, nsTimeoutURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSTimeout `json:"nstimeout"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// nstimer +func (s *NSService) AddNSTimer(resource models.NSTimer) error { + payload := map[string]any{"nstimer": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsTimerURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSTimer(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsTimerURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UpdateNSTimer(resource models.NSTimer) error { + payload := map[string]any{"nstimer": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsTimerURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSTimer(resource models.NSTimer) error { + payload := map[string]any{"nstimer": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsTimerURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSTimer() ([]models.NSTimer, error) { + req, err := s.client.NewRequest(http.MethodGet, nsTimerURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSTimer `json:"nstimer"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSTimer(name string) (*models.NSTimer, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsTimerURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSTimer `json:"nstimer"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nstimer %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *NSService) CountNSTimer() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsTimerURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSTimer `json:"nstimer"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +func (s *NSService) RenameNSTimer(resource models.NSTimer) error { + payload := map[string]any{"nstimer": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=rename", nsTimerURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// nstimer_autoscalepolicy_binding +func (s *NSService) AddNSTimerAutoScalePolicyBinding(resource models.NSTimerAutoScalePolicyBinding) error { + payload := map[string]any{"nstimer_autoscalepolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsTimerAutoScalePolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSTimerAutoScalePolicyBinding(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsTimerAutoScalePolicyBindingURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSTimerAutoScalePolicyBinding() ([]models.NSTimerAutoScalePolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, nsTimerAutoScalePolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSTimerAutoScalePolicyBinding `json:"nstimer_autoscalepolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSTimerAutoScalePolicyBinding(name string) ([]models.NSTimerAutoScalePolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsTimerAutoScalePolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSTimerAutoScalePolicyBinding `json:"nstimer_autoscalepolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) CountNSTimerAutoScalePolicyBinding(name string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", nsTimerAutoScalePolicyBindingURL, name), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSTimerAutoScalePolicyBinding `json:"nstimer_autoscalepolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nstimer_binding +func (s *NSService) GetAllNSTimerBinding() ([]models.NSTimerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, nsTimerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSTimerBinding `json:"nstimer_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSTimerBinding(name string) (*models.NSTimerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsTimerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSTimerBinding `json:"nstimer_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nstimer_binding %s not found", name) + } + + return &result.Data[0], nil +} + +// nstimezone +func (s *NSService) GetAllNSTimeZone() ([]models.NSTimeZone, error) { + req, err := s.client.NewRequest(http.MethodGet, nsTimeZoneURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSTimeZone `json:"nstimezone"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSTimeZone() (*models.NSTimeZone, error) { + req, err := s.client.NewRequest(http.MethodGet, nsTimeZoneURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSTimeZone `json:"nstimezone"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nstimezone not found") + } + + return &result.Data[0], nil +} + +func (s *NSService) CountNSTimeZone() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsTimeZoneURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSTimeZone `json:"nstimezone"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nstrafficdomain +func (s *NSService) AddNSTrafficDomain(resource models.NSTrafficDomain) error { + payload := map[string]any{"nstrafficdomain": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsTrafficDomainURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSTrafficDomain(td string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsTrafficDomainURL, td), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) EnableNSTrafficDomain(resource models.NSTrafficDomain) error { + payload := map[string]any{"nstrafficdomain": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=enable", nsTrafficDomainURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DisableNSTrafficDomain(resource models.NSTrafficDomain) error { + payload := map[string]any{"nstrafficdomain": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=disable", nsTrafficDomainURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSTrafficDomain() ([]models.NSTrafficDomain, error) { + req, err := s.client.NewRequest(http.MethodGet, nsTrafficDomainURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSTrafficDomain `json:"nstrafficdomain"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSTrafficDomain(td string) (*models.NSTrafficDomain, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsTrafficDomainURL, td), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSTrafficDomain `json:"nstrafficdomain"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nstrafficdomain %s not found", td) + } + + return &result.Data[0], nil +} + +func (s *NSService) CountNSTrafficDomain() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsTrafficDomainURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSTrafficDomain `json:"nstrafficdomain"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +func (s *NSService) ClearNSTrafficDomain(resource models.NSTrafficDomain) error { + payload := map[string]any{"nstrafficdomain": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=clear", nsTrafficDomainURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// nstrafficdomain_binding +func (s *NSService) GetAllNSTrafficDomainBinding() ([]models.NSTrafficDomainBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, nsTrafficDomainBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSTrafficDomainBinding `json:"nstrafficdomain_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSTrafficDomainBinding(td string) (*models.NSTrafficDomainBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsTrafficDomainBindingURL, td), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSTrafficDomainBinding `json:"nstrafficdomain_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nstrafficdomain_binding %s not found", td) + } + + return &result.Data[0], nil +} + +// nstrafficdomain_bridgegroup_binding +func (s *NSService) AddNSTrafficDomainBridgeGroupBinding(resource models.NSTrafficDomainBridgeGroupBinding) error { + payload := map[string]any{"nstrafficdomain_bridgegroup_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsTrafficDomainBridgeGroupBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSTrafficDomainBridgeGroupBinding(td string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsTrafficDomainBridgeGroupBindingURL, td), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSTrafficDomainBridgeGroupBinding() ([]models.NSTrafficDomainBridgeGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, nsTrafficDomainBridgeGroupBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSTrafficDomainBridgeGroupBinding `json:"nstrafficdomain_bridgegroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSTrafficDomainBridgeGroupBinding(td string) ([]models.NSTrafficDomainBridgeGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsTrafficDomainBridgeGroupBindingURL, td), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSTrafficDomainBridgeGroupBinding `json:"nstrafficdomain_bridgegroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) CountNSTrafficDomainBridgeGroupBinding(td string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", nsTrafficDomainBridgeGroupBindingURL, td), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSTrafficDomainBridgeGroupBinding `json:"nstrafficdomain_bridgegroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nstrafficdomain_vlan_binding +func (s *NSService) AddNSTrafficDomainVLANBinding(resource models.NSTrafficDomainVLANBinding) error { + payload := map[string]any{"nstrafficdomain_vlan_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsTrafficDomainVLANBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSTrafficDomainVLANBinding(td string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsTrafficDomainVLANBindingURL, td), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSTrafficDomainVLANBinding() ([]models.NSTrafficDomainVLANBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, nsTrafficDomainVLANBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSTrafficDomainVLANBinding `json:"nstrafficdomain_vlan_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSTrafficDomainVLANBinding(td string) ([]models.NSTrafficDomainVLANBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsTrafficDomainVLANBindingURL, td), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSTrafficDomainVLANBinding `json:"nstrafficdomain_vlan_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) CountNSTrafficDomainVLANBinding(td string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", nsTrafficDomainVLANBindingURL, td), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSTrafficDomainVLANBinding `json:"nstrafficdomain_vlan_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nstrafficdomain_vxlan_binding +func (s *NSService) AddNSTrafficDomainVXLANBinding(resource models.NSTrafficDomainVXLANBinding) error { + payload := map[string]any{"nstrafficdomain_vxlan_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsTrafficDomainVXLANBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSTrafficDomainVXLANBinding(td string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsTrafficDomainVXLANBindingURL, td), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSTrafficDomainVXLANBinding() ([]models.NSTrafficDomainVXLANBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, nsTrafficDomainVXLANBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSTrafficDomainVXLANBinding `json:"nstrafficdomain_vxlan_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSTrafficDomainVXLANBinding(td string) ([]models.NSTrafficDomainVXLANBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsTrafficDomainVXLANBindingURL, td), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSTrafficDomainVXLANBinding `json:"nstrafficdomain_vxlan_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) CountNSTrafficDomainVXLANBinding(td string) (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s?count=yes", nsTrafficDomainVXLANBindingURL, td), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSTrafficDomainVXLANBinding `json:"nstrafficdomain_vxlan_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nsvariable +func (s *NSService) AddNSVariable(resource models.NSVariable) error { + payload := map[string]any{"nsvariable": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsVariableURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSVariable(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsVariableURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UpdateNSVariable(resource models.NSVariable) error { + payload := map[string]any{"nsvariable": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsVariableURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSVariable(resource models.NSVariable) error { + payload := map[string]any{"nsvariable": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsVariableURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSVariable() ([]models.NSVariable, error) { + req, err := s.client.NewRequest(http.MethodGet, nsVariableURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSVariable `json:"nsvariable"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSVariable(name string) (*models.NSVariable, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsVariableURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSVariable `json:"nsvariable"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nsvariable %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *NSService) CountNSVariable() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsVariableURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSVariable `json:"nsvariable"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nsversion +func (s *NSService) GetAllNSVersion() ([]models.NSVersion, error) { + req, err := s.client.NewRequest(http.MethodGet, nsVersionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSVersion `json:"nsversion"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// nsvpxparam +func (s *NSService) UpdateNSVPXParam(resource models.NSVPXParam) error { + payload := map[string]any{"nsvpxparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsVPXParamURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSVPXParam(resource models.NSVPXParam) error { + payload := map[string]any{"nsvpxparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsVPXParamURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSVPXParam() ([]models.NSVPXParam, error) { + req, err := s.client.NewRequest(http.MethodGet, nsVPXParamURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSVPXParam `json:"nsvpxparam"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) CountNSVPXParam() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsVPXParamURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSVPXParam `json:"nsvpxparam"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// nsweblogparam +func (s *NSService) UpdateNSWebLogParam(resource models.NSWebLogParam) error { + payload := map[string]any{"nsweblogparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsWeblogParamURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSWebLogParam(resource models.NSWebLogParam) error { + payload := map[string]any{"nsweblogparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsWeblogParamURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSWebLogParam() ([]models.NSWebLogParam, error) { + req, err := s.client.NewRequest(http.MethodGet, nsWeblogParamURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSWebLogParam `json:"nsweblogparam"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// nsxmlnamespace +func (s *NSService) AddNSXMLNamespace(resource models.NSXMLNamespace) error { + payload := map[string]any{"nsxmlnamespace": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, nsXMLNamespaceURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) DeleteNSXMLNamespace(prefix string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", nsXMLNamespaceURL, prefix), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UpdateNSXMLNamespace(resource models.NSXMLNamespace) error { + payload := map[string]any{"nsxmlnamespace": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, nsXMLNamespaceURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) UnsetNSXMLNamespace(resource models.NSXMLNamespace) error { + payload := map[string]any{"nsxmlnamespace": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", nsXMLNamespaceURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NSService) GetAllNSXMLNamespace() ([]models.NSXMLNamespace, error) { + req, err := s.client.NewRequest(http.MethodGet, nsXMLNamespaceURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSXMLNamespace `json:"nsxmlnamespace"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *NSService) GetNSXMLNamespace(prefix string) (*models.NSXMLNamespace, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", nsXMLNamespaceURL, prefix), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.NSXMLNamespace `json:"nsxmlnamespace"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("nsxmlnamespace %s not found", prefix) + } + + return &result.Data[0], nil +} + +func (s *NSService) CountNSXMLNamespace() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", nsXMLNamespaceURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.NSXMLNamespace `json:"nsxmlnamespace"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// reboot +func (s *NSService) Reboot() error { + payload := map[string]any{"reboot": map[string]any{}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, rebootURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// shutdown +func (s *NSService) Shutdown() error { + payload := map[string]any{"shutdown": map[string]any{}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, shutdownURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} diff --git a/nitrogo/ntp.go b/nitrogo/ntp.go index a552e8b..c90c409 100644 --- a/nitrogo/ntp.go +++ b/nitrogo/ntp.go @@ -1,5 +1,22 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + ntpParamURL = "/nitro/v1/config/ntpparam" + ntpServerURL = "/nitro/v1/config/ntpserver" + ntpStatusURL = "/nitro/v1/config/ntpstatus" + ntpSyncURL = "/nitro/v1/config/ntpsync" +) + // NTP configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/ntp/ntp type NTPService struct { @@ -9,28 +26,290 @@ type NTPService struct { // ntpparam // Configuration for NTP parameter resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/ntp/ntpparam -func (s *NTPService) UpdateNTPParam() {} -func (s *NTPService) UnsetNTPParam() {} -func (s *NTPService) GetAllNTPParam() {} + +func (s *NTPService) UpdateNTPParam(param models.NTPParam) error { + payload := map[string]any{ + "ntpparam": param, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, ntpParamURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NTPService) UnsetNTPParam(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "ntpparam": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, ntpParamURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NTPService) GetAllNTPParam() (models.NTPParam, error) { + req, err := s.client.NewRequest(http.MethodGet, ntpParamURL, nil) + if err != nil { + return models.NTPParam{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.NTPParam{}, err + } + + var result struct { + NTPParams []models.NTPParam `json:"ntpparam"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.NTPParam{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.NTPParams) > 0 { + return result.NTPParams[0], nil + } + + return models.NTPParam{}, nil +} // ntpserver // Configuration for NTP server resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/ntp/ntpserver -func (s *NTPService) AddNTPServer() {} -func (s *NTPService) DeleteNTPServer() {} -func (s *NTPService) UpdateNTPServer() {} -func (s *NTPService) UnsetNTPServer() {} -func (s *NTPService) GetAllNTPServer() {} -func (s *NTPService) CountNTPServer() {} + +func (s *NTPService) AddNTPServer(server models.NTPServer) error { + payload := map[string]any{ + "ntpserver": server, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, ntpServerURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NTPService) DeleteNTPServer(serverip string, servername string) error { + reqURL := fmt.Sprintf("%s/%s", ntpServerURL, serverip) + if servername != "" { + reqURL += "?args=servername:" + url.QueryEscape(servername) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NTPService) UpdateNTPServer(server models.NTPServer) error { + payload := map[string]any{ + "ntpserver": server, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, ntpServerURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NTPService) UnsetNTPServer(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "ntpserver": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, ntpServerURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NTPService) GetAllNTPServer() ([]models.NTPServer, error) { + req, err := s.client.NewRequest(http.MethodGet, ntpServerURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + NTPServers []models.NTPServer `json:"ntpserver"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.NTPServers, nil +} + +func (s *NTPService) CountNTPServer() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, ntpServerURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + NTPServers []struct { + Count float64 `json:"__count"` + } `json:"ntpserver"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.NTPServers) > 0 { + return result.NTPServers[0].Count, nil + } + + return 0, nil +} // ntpstatus // Configuration for ntp status resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/ntp/ntpstatus -func (s *NTPService) GetAllNTPStatus() {} + +func (s *NTPService) GetAllNTPStatus() ([]models.NTPStatus, error) { + req, err := s.client.NewRequest(http.MethodGet, ntpStatusURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + NTPStatus []models.NTPStatus `json:"ntpstatus"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.NTPStatus, nil +} // ntpsync // Configuration for NTP sync resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/ntp/ntpsync -func (s *NTPService) EnableNTPSync() {} -func (s *NTPService) DisableNTPSync() {} -func (s *NTPService) GetAllNTPSync() {} + +func (s *NTPService) EnableNTPSync() error { + payload := map[string]any{ + "ntpsync": map[string]any{}, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, ntpSyncURL+"?action=enable", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NTPService) DisableNTPSync() error { + payload := map[string]any{ + "ntpsync": map[string]any{}, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, ntpSyncURL+"?action=disable", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *NTPService) GetAllNTPSync() ([]models.NTPSync, error) { + req, err := s.client.NewRequest(http.MethodGet, ntpSyncURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + NTPSync []models.NTPSync `json:"ntpsync"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.NTPSync, nil +} diff --git a/nitrogo/pcp.go b/nitrogo/pcp.go index f29d3aa..413cf29 100644 --- a/nitrogo/pcp.go +++ b/nitrogo/pcp.go @@ -1,5 +1,20 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + pcpMapURL = "/nitro/v1/config/pcpmap" + pcpProfileURL = "/nitro/v1/config/pcpprofile" + pcpServerURL = "/nitro/v1/config/pcpserver" +) + // Port Control Protocol Configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/pcp/pcp type PCPService struct { @@ -9,27 +24,355 @@ type PCPService struct { // pcpmap // Configuration for server resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/pcp/pcpmap -func (s *PCPService) GetAllPCPMap() {} -func (s *PCPService) CountPCPMap() {} + +func (s *PCPService) GetAllPCPMap() ([]models.PCPMap, error) { + req, err := s.client.NewRequest(http.MethodGet, pcpMapURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + PCPMaps []models.PCPMap `json:"pcpmap"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.PCPMaps, nil +} + +func (s *PCPService) CountPCPMap() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, pcpMapURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + PCPMaps []struct { + Count float64 `json:"__count"` + } `json:"pcpmap"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.PCPMaps) > 0 { + return result.PCPMaps[0].Count, nil + } + + return 0, nil +} // pcpprofile // Configuration for PCP Profile resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/pcp/pcpprofile -func (s *PCPService) AddPCPProfile() {} -func (s *PCPService) DeletePCPProfile() {} -func (s *PCPService) UpdatePCPProfile() {} -func (s *PCPService) UnsetPCPProfile() {} -func (s *PCPService) GetAllPCPProfile() {} -func (s *PCPService) GetPCPProfile() {} -func (s *PCPService) CountPCPProfile() {} + +func (s *PCPService) AddPCPProfile(profile models.PCPProfile) error { + payload := map[string]any{ + "pcpprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, pcpProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *PCPService) DeletePCPProfile(name string) error { + url := fmt.Sprintf("%s/%s", pcpProfileURL, name) + req, err := s.client.NewRequest(http.MethodDelete, url, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *PCPService) UpdatePCPProfile(profile models.PCPProfile) error { + payload := map[string]any{ + "pcpprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, pcpProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *PCPService) UnsetPCPProfile(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "pcpprofile": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, pcpProfileURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *PCPService) GetAllPCPProfile() ([]models.PCPProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, pcpProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + PCPProfiles []models.PCPProfile `json:"pcpprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.PCPProfiles, nil +} + +func (s *PCPService) GetPCPProfile(name string) ([]models.PCPProfile, error) { + url := fmt.Sprintf("%s/%s", pcpProfileURL, name) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + PCPProfiles []models.PCPProfile `json:"pcpprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.PCPProfiles, nil +} + +func (s *PCPService) CountPCPProfile() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, pcpProfileURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + PCPProfiles []struct { + Count float64 `json:"__count"` + } `json:"pcpprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.PCPProfiles) > 0 { + return result.PCPProfiles[0].Count, nil + } + + return 0, nil +} // pcpserver // Configuration for server resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/pcp/pcpserver -func (s *PCPService) AddPCPServer() {} -func (s *PCPService) DeletePCPServer() {} -func (s *PCPService) UpdatePCPServer() {} -func (s *PCPService) UnsetPCPServer() {} -func (s *PCPService) GetAllPCPServer() {} -func (s *PCPService) GetPCPServer() {} -func (s *PCPService) CountPCPServer() {} + +func (s *PCPService) AddPCPServer(server models.PCPServer) error { + payload := map[string]any{ + "pcpserver": server, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, pcpServerURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *PCPService) DeletePCPServer(name string) error { + url := fmt.Sprintf("%s/%s", pcpServerURL, name) + req, err := s.client.NewRequest(http.MethodDelete, url, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *PCPService) UpdatePCPServer(server models.PCPServer) error { + payload := map[string]any{ + "pcpserver": server, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, pcpServerURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *PCPService) UnsetPCPServer(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "pcpserver": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, pcpServerURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *PCPService) GetAllPCPServer() ([]models.PCPServer, error) { + req, err := s.client.NewRequest(http.MethodGet, pcpServerURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + PCPServers []models.PCPServer `json:"pcpserver"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.PCPServers, nil +} + +func (s *PCPService) GetPCPServer(name string) ([]models.PCPServer, error) { + url := fmt.Sprintf("%s/%s", pcpServerURL, name) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + PCPServers []models.PCPServer `json:"pcpserver"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.PCPServers, nil +} + +func (s *PCPService) CountPCPServer() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, pcpServerURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + PCPServers []struct { + Count float64 `json:"__count"` + } `json:"pcpserver"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.PCPServers) > 0 { + return result.PCPServers[0].Count, nil + } + + return 0, nil +} diff --git a/nitrogo/policy.go b/nitrogo/policy.go index 680cad0..4d6ad05 100644 --- a/nitrogo/policy.go +++ b/nitrogo/policy.go @@ -1,5 +1,33 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + policyDatasetURL = "/nitro/v1/config/policydataset" + policyDatasetBindingURL = "/nitro/v1/config/policydataset_binding" + policyDatasetValueBindingURL = "/nitro/v1/config/policydataset_value_binding" + policyEvaluationURL = "/nitro/v1/config/policyevaluation" + policyExpressionURL = "/nitro/v1/config/policyexpression" + policyHTTPCalloutURL = "/nitro/v1/config/policyhttpcallout" + policyMapURL = "/nitro/v1/config/policymap" + policyParamURL = "/nitro/v1/config/policyparam" + policyPATSetURL = "/nitro/v1/config/policypatset" + policyPATSetBindingURL = "/nitro/v1/config/policypatset_binding" + policyPATSetPatternBindingURL = "/nitro/v1/config/policypatset_pattern_binding" + policyStringMapURL = "/nitro/v1/config/policystringmap" + policyStringMapBindingURL = "/nitro/v1/config/policystringmap_binding" + policyStringMapPatternBindingURL = "/nitro/v1/config/policystringmap_pattern_binding" + policyURLSetURL = "/nitro/v1/config/policyurlset" +) + // Policy configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/policy/policy type PolicyService struct { @@ -7,105 +35,1370 @@ type PolicyService struct { } // policydataset -func (s *PolicyService) AddPolicyDataset() {} -func (s *PolicyService) DeletePolicyDataset() {} -func (s *PolicyService) UpdatePolicyDataset() {} -func (s *PolicyService) UnsetPolicyDataset() {} -func (s *PolicyService) GetAllPolicyDataset() {} -func (s *PolicyService) GetPolicyDataset() {} -func (s *PolicyService) CountPolicyDataset() {} + +func (s *PolicyService) AddPolicyDataset(dataset models.PolicyDataset) error { + payload := map[string]any{ + "policydataset": dataset, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, policyDatasetURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) DeletePolicyDataset(name string) error { + reqURL := fmt.Sprintf("%s/%s", policyDatasetURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) UpdatePolicyDataset(dataset models.PolicyDataset) error { + payload := map[string]any{ + "policydataset": dataset, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, policyDatasetURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) UnsetPolicyDataset(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{ + "policydataset": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, policyDatasetURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) GetAllPolicyDataset() ([]models.PolicyDataset, error) { + req, err := s.client.NewRequest(http.MethodGet, policyDatasetURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Datasets []models.PolicyDataset `json:"policydataset"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Datasets, nil +} + +func (s *PolicyService) GetPolicyDataset(name string) ([]models.PolicyDataset, error) { + reqURL := fmt.Sprintf("%s/%s", policyDatasetURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Datasets []models.PolicyDataset `json:"policydataset"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Datasets, nil +} + +func (s *PolicyService) CountPolicyDataset() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, policyDatasetURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Datasets []struct { + Count float64 `json:"__count"` + } `json:"policydataset"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Datasets) > 0 { + return result.Datasets[0].Count, nil + } + return 0, nil +} // policydataset_binding -func (s *PolicyService) GetAllPolicyDatasetBinding() {} -func (s *PolicyService) GetPolicyDatasetBinding() {} + +func (s *PolicyService) GetAllPolicyDatasetBinding() ([]models.PolicyDatasetBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, policyDatasetBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.PolicyDatasetBinding `json:"policydataset_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *PolicyService) GetPolicyDatasetBinding(name string) ([]models.PolicyDatasetBinding, error) { + reqURL := fmt.Sprintf("%s/%s", policyDatasetBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.PolicyDatasetBinding `json:"policydataset_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // policydataset_value_binding -func (s *PolicyService) AddPolicyDatasetValueBinding() {} -func (s *PolicyService) DeletePolicyDatasetValueBinding() {} -func (s *PolicyService) GetAllPolicyDatasetValueBinding() {} -func (s *PolicyService) GetPolicyDatasetValueBinding() {} -func (s *PolicyService) CountPolicyDatasetValueBinding() {} + +func (s *PolicyService) AddPolicyDatasetValueBinding(binding models.PolicyDatasetValueBinding) error { + payload := map[string]any{ + "policydataset_value_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, policyDatasetValueBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) DeletePolicyDatasetValueBinding(name, value string) error { + reqURL := fmt.Sprintf("%s/%s?args=value:%s", policyDatasetValueBindingURL, url.QueryEscape(name), url.QueryEscape(value)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) GetAllPolicyDatasetValueBinding() ([]models.PolicyDatasetValueBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, policyDatasetValueBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.PolicyDatasetValueBinding `json:"policydataset_value_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *PolicyService) GetPolicyDatasetValueBinding(name string) ([]models.PolicyDatasetValueBinding, error) { + reqURL := fmt.Sprintf("%s/%s", policyDatasetValueBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.PolicyDatasetValueBinding `json:"policydataset_value_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *PolicyService) CountPolicyDatasetValueBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", policyDatasetValueBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"policydataset_value_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // policyevaluation -func (s *PolicyService) GetAllPolicyEvaluation() {} -func (s *PolicyService) CountPolicyEvaluation() {} + +func (s *PolicyService) GetAllPolicyEvaluation() ([]models.PolicyEvaluation, error) { + req, err := s.client.NewRequest(http.MethodGet, policyEvaluationURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Evals []models.PolicyEvaluation `json:"policyevaluation"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Evals, nil +} + +func (s *PolicyService) CountPolicyEvaluation() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, policyEvaluationURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Evals []struct { + Count float64 `json:"__count"` + } `json:"policyevaluation"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Evals) > 0 { + return result.Evals[0].Count, nil + } + return 0, nil +} // policyexpression -func (s *PolicyService) AddPolicyExpression() {} -func (s *PolicyService) DeletePolicyExpression() {} -func (s *PolicyService) UpdatePolicyExpression() {} -func (s *PolicyService) UnsetPolicyExpression() {} -func (s *PolicyService) GetAllPolicyExpression() {} -func (s *PolicyService) GetPolicyExpression() {} -func (s *PolicyService) CountPolicyExpression() {} + +func (s *PolicyService) AddPolicyExpression(expression models.PolicyExpression) error { + payload := map[string]any{ + "policyexpression": expression, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, policyExpressionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) DeletePolicyExpression(name string) error { + reqURL := fmt.Sprintf("%s/%s", policyExpressionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) UpdatePolicyExpression(expression models.PolicyExpression) error { + payload := map[string]any{ + "policyexpression": expression, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, policyExpressionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) UnsetPolicyExpression(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{ + "policyexpression": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, policyExpressionURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) GetAllPolicyExpression() ([]models.PolicyExpression, error) { + req, err := s.client.NewRequest(http.MethodGet, policyExpressionURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Exprs []models.PolicyExpression `json:"policyexpression"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Exprs, nil +} + +func (s *PolicyService) GetPolicyExpression(name string) ([]models.PolicyExpression, error) { + reqURL := fmt.Sprintf("%s/%s", policyExpressionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Exprs []models.PolicyExpression `json:"policyexpression"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Exprs, nil +} + +func (s *PolicyService) CountPolicyExpression() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, policyExpressionURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Exprs []struct { + Count float64 `json:"__count"` + } `json:"policyexpression"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Exprs) > 0 { + return result.Exprs[0].Count, nil + } + return 0, nil +} // policyhttpcallout -func (s *PolicyService) AddPolicyHTTPCallout() {} -func (s *PolicyService) DeletePolicyHTTPCallout() {} -func (s *PolicyService) UpdatePolicyHTTPCallout() {} -func (s *PolicyService) UnsetPolicyHTTPCallout() {} -func (s *PolicyService) GetAllPolicyHTTPCallout() {} -func (s *PolicyService) GetPolicyHTTPCallout() {} -func (s *PolicyService) CountPolicyHTTPCallout() {} + +func (s *PolicyService) AddPolicyHTTPCallout(callout models.PolicyHTTPCallout) error { + payload := map[string]any{ + "policyhttpcallout": callout, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, policyHTTPCalloutURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) DeletePolicyHTTPCallout(name string) error { + reqURL := fmt.Sprintf("%s/%s", policyHTTPCalloutURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) UpdatePolicyHTTPCallout(callout models.PolicyHTTPCallout) error { + payload := map[string]any{ + "policyhttpcallout": callout, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, policyHTTPCalloutURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) UnsetPolicyHTTPCallout(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{ + "policyhttpcallout": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, policyHTTPCalloutURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) GetAllPolicyHTTPCallout() ([]models.PolicyHTTPCallout, error) { + req, err := s.client.NewRequest(http.MethodGet, policyHTTPCalloutURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Callouts []models.PolicyHTTPCallout `json:"policyhttpcallout"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Callouts, nil +} + +func (s *PolicyService) GetPolicyHTTPCallout(name string) ([]models.PolicyHTTPCallout, error) { + reqURL := fmt.Sprintf("%s/%s", policyHTTPCalloutURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Callouts []models.PolicyHTTPCallout `json:"policyhttpcallout"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Callouts, nil +} + +func (s *PolicyService) CountPolicyHTTPCallout() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, policyHTTPCalloutURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Callouts []struct { + Count float64 `json:"__count"` + } `json:"policyhttpcallout"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Callouts) > 0 { + return result.Callouts[0].Count, nil + } + return 0, nil +} // policymap -func (s *PolicyService) AddPolicyMap() {} -func (s *PolicyService) DeletePolicyMap() {} -func (s *PolicyService) GetAllPolicyMap() {} -func (s *PolicyService) GetPolicyMap() {} -func (s *PolicyService) CountPolicyMap() {} + +func (s *PolicyService) AddPolicyMap(policymap models.PolicyMap) error { + payload := map[string]any{ + "policymap": policymap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, policyMapURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) DeletePolicyMap(mappolicyname string) error { + reqURL := fmt.Sprintf("%s/%s", policyMapURL, url.QueryEscape(mappolicyname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) GetAllPolicyMap() ([]models.PolicyMap, error) { + req, err := s.client.NewRequest(http.MethodGet, policyMapURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Maps []models.PolicyMap `json:"policymap"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Maps, nil +} + +func (s *PolicyService) GetPolicyMap(mappolicyname string) ([]models.PolicyMap, error) { + reqURL := fmt.Sprintf("%s/%s", policyMapURL, url.QueryEscape(mappolicyname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Maps []models.PolicyMap `json:"policymap"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Maps, nil +} + +func (s *PolicyService) CountPolicyMap() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, policyMapURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Maps []struct { + Count float64 `json:"__count"` + } `json:"policymap"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Maps) > 0 { + return result.Maps[0].Count, nil + } + return 0, nil +} // policyparam -func (s *PolicyService) UpdatePolicyParam() {} -func (s *PolicyService) UnsetPolicyParam() {} -func (s *PolicyService) GetAllPolicyParam() {} + +func (s *PolicyService) UpdatePolicyParam(param models.PolicyParam) error { + payload := map[string]any{ + "policyparam": param, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, policyParamURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) UnsetPolicyParam(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{ + "policyparam": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, policyParamURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) GetAllPolicyParam() (models.PolicyParam, error) { + req, err := s.client.NewRequest(http.MethodGet, policyParamURL, nil) + if err != nil { + return models.PolicyParam{}, err + } + resp, err := s.client.Do(req) + if err != nil { + return models.PolicyParam{}, err + } + var result struct { + Params []models.PolicyParam `json:"policyparam"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return models.PolicyParam{}, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Params) > 0 { + return result.Params[0], nil + } + return models.PolicyParam{}, nil +} // policypatset -func (s *PolicyService) AddPolicyPATSet() {} -func (s *PolicyService) DeletePolicyPATSet() {} -func (s *PolicyService) UpdatePolicyPATSet() {} -func (s *PolicyService) UnsetPolicyPATSet() {} -func (s *PolicyService) GetAllPolicyPATSet() {} -func (s *PolicyService) GetPolicyPATSet() {} -func (s *PolicyService) CountPolicyPATSet() {} + +func (s *PolicyService) AddPolicyPATSet(patset models.PolicyPatset) error { + payload := map[string]any{ + "policypatset": patset, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, policyPATSetURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) DeletePolicyPATSet(name string) error { + reqURL := fmt.Sprintf("%s/%s", policyPATSetURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) UpdatePolicyPATSet(patset models.PolicyPatset) error { + payload := map[string]any{ + "policypatset": patset, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, policyPATSetURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) UnsetPolicyPATSet(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{ + "policypatset": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, policyPATSetURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) GetAllPolicyPATSet() ([]models.PolicyPatset, error) { + req, err := s.client.NewRequest(http.MethodGet, policyPATSetURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Pats []models.PolicyPatset `json:"policypatset"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Pats, nil +} + +func (s *PolicyService) GetPolicyPATSet(name string) ([]models.PolicyPatset, error) { + reqURL := fmt.Sprintf("%s/%s", policyPATSetURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Pats []models.PolicyPatset `json:"policypatset"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Pats, nil +} + +func (s *PolicyService) CountPolicyPATSet() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, policyPATSetURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Pats []struct { + Count float64 `json:"__count"` + } `json:"policypatset"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Pats) > 0 { + return result.Pats[0].Count, nil + } + return 0, nil +} // policypatset_binding -func (s *PolicyService) GetAllPolicyPATSetBinding() {} -func (s *PolicyService) GetPolicyPATSetBinding() {} + +func (s *PolicyService) GetAllPolicyPATSetBinding() ([]models.PolicyPatsetBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, policyPATSetBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.PolicyPatsetBinding `json:"policypatset_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *PolicyService) GetPolicyPATSetBinding(name string) ([]models.PolicyPatsetBinding, error) { + reqURL := fmt.Sprintf("%s/%s", policyPATSetBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.PolicyPatsetBinding `json:"policypatset_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // policypatset_pattern_binding -func (s *PolicyService) AddPolicyPATSetPatternBinding() {} -func (s *PolicyService) DeletePolicyPATSetPatternBinding() {} -func (s *PolicyService) GetAllPolicyPATSetPatternBinding() {} -func (s *PolicyService) GetPolicyPATSetPatternBinding() {} -func (s *PolicyService) CountPolicyPATSetPatternBinding() {} + +func (s *PolicyService) AddPolicyPATSetPatternBinding(binding models.PolicyPatsetPatternBinding) error { + payload := map[string]any{ + "policypatset_pattern_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, policyPATSetPatternBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) DeletePolicyPATSetPatternBinding(name, pattern string) error { + reqURL := fmt.Sprintf("%s/%s?args=String:%s", policyPATSetPatternBindingURL, url.QueryEscape(name), url.QueryEscape(pattern)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) GetAllPolicyPATSetPatternBinding() ([]models.PolicyPatsetPatternBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, policyPATSetPatternBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.PolicyPatsetPatternBinding `json:"policypatset_pattern_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *PolicyService) GetPolicyPATSetPatternBinding(name string) ([]models.PolicyPatsetPatternBinding, error) { + reqURL := fmt.Sprintf("%s/%s", policyPATSetPatternBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.PolicyPatsetPatternBinding `json:"policypatset_pattern_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *PolicyService) CountPolicyPATSetPatternBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", policyPATSetPatternBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"policypatset_pattern_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // policystringmap -func (s *PolicyService) AddPolicyStringMap() {} -func (s *PolicyService) DeletePolicyStringMap() {} -func (s *PolicyService) UpdatePolicyStringMap() {} -func (s *PolicyService) UnsetPolicyStringMap() {} -func (s *PolicyService) GetAllPolicyStringMap() {} -func (s *PolicyService) GetPolicyStringMap() {} -func (s *PolicyService) CountPolicyStringMap() {} + +func (s *PolicyService) AddPolicyStringMap(stringmap models.PolicyStringMap) error { + payload := map[string]any{ + "policystringmap": stringmap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, policyStringMapURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) DeletePolicyStringMap(name string) error { + reqURL := fmt.Sprintf("%s/%s", policyStringMapURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) UpdatePolicyStringMap(stringmap models.PolicyStringMap) error { + payload := map[string]any{ + "policystringmap": stringmap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, policyStringMapURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) UnsetPolicyStringMap(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{ + "policystringmap": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, policyStringMapURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) GetAllPolicyStringMap() ([]models.PolicyStringMap, error) { + req, err := s.client.NewRequest(http.MethodGet, policyStringMapURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Maps []models.PolicyStringMap `json:"policystringmap"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Maps, nil +} + +func (s *PolicyService) GetPolicyStringMap(name string) ([]models.PolicyStringMap, error) { + reqURL := fmt.Sprintf("%s/%s", policyStringMapURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Maps []models.PolicyStringMap `json:"policystringmap"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Maps, nil +} + +func (s *PolicyService) CountPolicyStringMap() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, policyStringMapURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Maps []struct { + Count float64 `json:"__count"` + } `json:"policystringmap"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Maps) > 0 { + return result.Maps[0].Count, nil + } + return 0, nil +} // policystringmap_binding -func (s *PolicyService) GetAllPolicyStringMapBinding() {} -func (s *PolicyService) GetPolicyStringMapBinding() {} + +func (s *PolicyService) GetAllPolicyStringMapBinding() ([]models.PolicyStringMapBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, policyStringMapBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.PolicyStringMapBinding `json:"policystringmap_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *PolicyService) GetPolicyStringMapBinding(name string) ([]models.PolicyStringMapBinding, error) { + reqURL := fmt.Sprintf("%s/%s", policyStringMapBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.PolicyStringMapBinding `json:"policystringmap_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // policystringmap_pattern_binding -func (s *PolicyService) AddPolicyStringMapPatternBinding() {} -func (s *PolicyService) DeletePolicyStringMapPatternBinding() {} -func (s *PolicyService) GetAllPolicyStringMapPatternBinding() {} -func (s *PolicyService) GetPolicyStringMapPatternBinding() {} -func (s *PolicyService) CountPolicyStringMapPatternBinding() {} + +func (s *PolicyService) AddPolicyStringMapPatternBinding(binding models.PolicyStringMapPatternBinding) error { + payload := map[string]any{ + "policystringmap_pattern_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, policyStringMapPatternBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) DeletePolicyStringMapPatternBinding(name, key string) error { + reqURL := fmt.Sprintf("%s/%s?args=key:%s", policyStringMapPatternBindingURL, url.QueryEscape(name), url.QueryEscape(key)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) GetAllPolicyStringMapPatternBinding() ([]models.PolicyStringMapPatternBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, policyStringMapPatternBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.PolicyStringMapPatternBinding `json:"policystringmap_pattern_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *PolicyService) GetPolicyStringMapPatternBinding(name string) ([]models.PolicyStringMapPatternBinding, error) { + reqURL := fmt.Sprintf("%s/%s", policyStringMapPatternBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.PolicyStringMapPatternBinding `json:"policystringmap_pattern_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *PolicyService) CountPolicyStringMapPatternBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", policyStringMapPatternBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"policystringmap_pattern_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // policyurlset -func (s *PolicyService) AddPolicyURLSet() {} -func (s *PolicyService) DeletePolicyURLSet() {} -func (s *PolicyService) GetAllPolicyURLSet() {} -func (s *PolicyService) GetPolicyURLSet() {} -func (s *PolicyService) CountPolicyURLSet() {} -func (s *PolicyService) ImportPolicyURLSet() {} -func (s *PolicyService) ExportPolicyURLSet() {} -func (s *PolicyService) ChangePolicyURLSet() {} + +func (s *PolicyService) AddPolicyURLSet(urlset models.PolicyURLSet) error { + payload := map[string]any{ + "policyurlset": urlset, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, policyURLSetURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) DeletePolicyURLSet(name string) error { + reqURL := fmt.Sprintf("%s/%s", policyURLSetURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) GetAllPolicyURLSet() ([]models.PolicyURLSet, error) { + req, err := s.client.NewRequest(http.MethodGet, policyURLSetURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Sets []models.PolicyURLSet `json:"policyurlset"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Sets, nil +} + +func (s *PolicyService) GetPolicyURLSet(name string) ([]models.PolicyURLSet, error) { + reqURL := fmt.Sprintf("%s/%s", policyURLSetURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Sets []models.PolicyURLSet `json:"policyurlset"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Sets, nil +} + +func (s *PolicyService) CountPolicyURLSet() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, policyURLSetURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Sets []struct { + Count float64 `json:"__count"` + } `json:"policyurlset"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Sets) > 0 { + return result.Sets[0].Count, nil + } + return 0, nil +} + +func (s *PolicyService) ImportPolicyURLSet(urlset models.PolicyURLSet) error { + payload := map[string]any{ + "policyurlset": urlset, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, policyURLSetURL+"?action=Import", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) ExportPolicyURLSet(urlset models.PolicyURLSet) error { + payload := map[string]any{ + "policyurlset": urlset, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, policyURLSetURL+"?action=export", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *PolicyService) ChangePolicyURLSet(urlset models.PolicyURLSet) error { + payload := map[string]any{ + "policyurlset": urlset, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, policyURLSetURL+"?action=change", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} diff --git a/nitrogo/protocol.go b/nitrogo/protocol.go index f0e26da..607c228 100644 --- a/nitrogo/protocol.go +++ b/nitrogo/protocol.go @@ -1,5 +1,18 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + protocolHTTPBandURL = "/nitro/v1/config/protocolhttpband" +) + // Protocol Configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/protocol/protocol type ProtocolService struct { @@ -9,7 +22,86 @@ type ProtocolService struct { // protocolhttpband // Configuration for HTTP request/response band resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/protocol/protocolhttpband -func (s *ProtocolService) UpdateProtocolHTTPBand() {} -func (s *ProtocolService) UnsetProtocolHTTPBand() {} -func (s *ProtocolService) GetAllProtocolHTTPBand() {} -func (s *ProtocolService) ClearProtocolHTTPBand() {} + +func (s *ProtocolService) UpdateProtocolHTTPBand(band models.ProtocolHTTPBand) error { + payload := map[string]any{ + "protocolhttpband": band, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, protocolHTTPBandURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ProtocolService) UnsetProtocolHTTPBand(args []string) error { + unsetMap := make(map[string]bool) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "protocolhttpband": unsetMap, + } + + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, protocolHTTPBandURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ProtocolService) GetAllProtocolHTTPBand() ([]models.ProtocolHTTPBand, error) { + req, err := s.client.NewRequest(http.MethodGet, protocolHTTPBandURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bands []models.ProtocolHTTPBand `json:"protocolhttpband"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bands, nil +} + +func (s *ProtocolService) ClearProtocolHTTPBand(band models.ProtocolHTTPBand) error { + payload := map[string]any{ + "protocolhttpband": band, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, protocolHTTPBandURL+"?action=clear", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} diff --git a/nitrogo/rdp.go b/nitrogo/rdp.go index 7e07af1..6c55b19 100644 --- a/nitrogo/rdp.go +++ b/nitrogo/rdp.go @@ -1,5 +1,20 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + rdpClientProfileURL = "/nitro/v1/config/rdpclientprofile" + rdpConnectionsURL = "/nitro/v1/config/rdpconnections" + rdpServerProfileURL = "/nitro/v1/config/rdpserverprofile" +) + // RDP configuration // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/rdp/rdp type RDPService struct { @@ -9,28 +24,373 @@ type RDPService struct { // rdpclientprofile // Configuration for RDP clientprofile resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/rdp/rdpclientprofile -func (s *RDPService) AddRDPClientProfile() {} -func (s *RDPService) DeleteRDPClientProfile() {} -func (s *RDPService) UpdateRDPClientProfile() {} -func (s *RDPService) UnsetRDPClientProfile() {} -func (s *RDPService) GetAllRDPClientProfile() {} -func (s *RDPService) GetRDPClientProfile() {} -func (s *RDPService) CountRDPClientProfile() {} + +func (s *RDPService) AddRDPClientProfile(profile models.RDPClientProfile) error { + payload := map[string]any{ + "rdpclientprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, rdpClientProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *RDPService) DeleteRDPClientProfile(name string) error { + url := fmt.Sprintf("%s/%s", rdpClientProfileURL, name) + req, err := s.client.NewRequest(http.MethodDelete, url, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *RDPService) UpdateRDPClientProfile(profile models.RDPClientProfile) error { + payload := map[string]any{ + "rdpclientprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, rdpClientProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *RDPService) UnsetRDPClientProfile(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "rdpclientprofile": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, rdpClientProfileURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *RDPService) GetAllRDPClientProfile() ([]models.RDPClientProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, rdpClientProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + RDPClientProfiles []models.RDPClientProfile `json:"rdpclientprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.RDPClientProfiles, nil +} + +func (s *RDPService) GetRDPClientProfile(name string) ([]models.RDPClientProfile, error) { + url := fmt.Sprintf("%s/%s", rdpClientProfileURL, name) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + RDPClientProfiles []models.RDPClientProfile `json:"rdpclientprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.RDPClientProfiles, nil +} + +func (s *RDPService) CountRDPClientProfile() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, rdpClientProfileURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + RDPClientProfiles []struct { + Count float64 `json:"__count"` + } `json:"rdpclientprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.RDPClientProfiles) > 0 { + return result.RDPClientProfiles[0].Count, nil + } + + return 0, nil +} // rdpconnections // Configuration for active rdp connections resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/rdp/rdpconnections -func (s *RDPService) GetAllRDPConnections() {} -func (s *RDPService) CountRDPConnections() {} -func (s *RDPService) KillRDPConnections() {} + +func (s *RDPService) GetAllRDPConnections() ([]models.RDPConnections, error) { + req, err := s.client.NewRequest(http.MethodGet, rdpConnectionsURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + RDPConnections []models.RDPConnections `json:"rdpconnections"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.RDPConnections, nil +} + +func (s *RDPService) CountRDPConnections() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, rdpConnectionsURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + RDPConnections []struct { + Count float64 `json:"__count"` + } `json:"rdpconnections"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.RDPConnections) > 0 { + return result.RDPConnections[0].Count, nil + } + + return 0, nil +} + +func (s *RDPService) KillRDPConnections(connections models.RDPConnections) error { + payload := map[string]any{ + "rdpconnections": connections, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, rdpConnectionsURL+"?action=kill", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} // rspserverprofile // Configuration for RDP serverprofile resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/rdp/rdpserverprofile -func (s *RDPService) AddRDPServerProfile() {} -func (s *RDPService) DeleteRDPServerProfile() {} -func (s *RDPService) UpdateRDPServerProfile() {} -func (s *RDPService) UnsetRDPServerProfile() {} -func (s *RDPService) GetAllRDPServerProfile() {} -func (s *RDPService) GetRDPServerProfile() {} -func (s *RDPService) CountRDPServerProfile() {} + +func (s *RDPService) AddRDPServerProfile(profile models.RDPServerProfile) error { + payload := map[string]any{ + "rdpserverprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, rdpServerProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *RDPService) DeleteRDPServerProfile(name string) error { + url := fmt.Sprintf("%s/%s", rdpServerProfileURL, name) + req, err := s.client.NewRequest(http.MethodDelete, url, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *RDPService) UpdateRDPServerProfile(profile models.RDPServerProfile) error { + payload := map[string]any{ + "rdpserverprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, rdpServerProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *RDPService) UnsetRDPServerProfile(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "rdpserverprofile": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, rdpServerProfileURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *RDPService) GetAllRDPServerProfile() ([]models.RDPServerProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, rdpServerProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + RDPServerProfiles []models.RDPServerProfile `json:"rdpserverprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.RDPServerProfiles, nil +} + +func (s *RDPService) GetRDPServerProfile(name string) ([]models.RDPServerProfile, error) { + url := fmt.Sprintf("%s/%s", rdpServerProfileURL, name) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + RDPServerProfiles []models.RDPServerProfile `json:"rdpserverprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.RDPServerProfiles, nil +} + +func (s *RDPService) CountRDPServerProfile() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, rdpServerProfileURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + RDPServerProfiles []struct { + Count float64 `json:"__count"` + } `json:"rdpserverprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.RDPServerProfiles) > 0 { + return result.RDPServerProfiles[0].Count, nil + } + + return 0, nil +} diff --git a/nitrogo/reputation.go b/nitrogo/reputation.go index 6aa58c8..6703402 100644 --- a/nitrogo/reputation.go +++ b/nitrogo/reputation.go @@ -1,5 +1,18 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + reputationSettingsURL = "/nitro/v1/config/reputationsettings" +) + // Reputation services configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/reputation/reputation type ReputationService struct { @@ -9,6 +22,72 @@ type ReputationService struct { // reputationsettings // Configuration for Reputation service settings resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/reputation/reputationsettings -func (s *ReputationService) UpdateReputationSettings() {} -func (s *ReputationService) UnsetReputationSettings() {} -func (s *ReputationService) GetAllReputationSettings() {} + +func (s *ReputationService) UpdateReputationSettings(settings models.ReputationSettings) error { + payload := map[string]any{ + "reputationsettings": settings, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, reputationSettingsURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ReputationService) UnsetReputationSettings(args []string) error { + unsetMap := make(map[string]bool) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "reputationsettings": unsetMap, + } + + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, reputationSettingsURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ReputationService) GetAllReputationSettings() (models.ReputationSettings, error) { + req, err := s.client.NewRequest(http.MethodGet, reputationSettingsURL, nil) + if err != nil { + return models.ReputationSettings{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.ReputationSettings{}, err + } + + var result struct { + Settings []models.ReputationSettings `json:"reputationsettings"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.ReputationSettings{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Settings) > 0 { + return result.Settings[0], nil + } + + return models.ReputationSettings{}, nil +} diff --git a/nitrogo/responder.go b/nitrogo/responder.go index f8a63e6..81ebc4c 100644 --- a/nitrogo/responder.go +++ b/nitrogo/responder.go @@ -1,5 +1,35 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + responderActionURL = "/nitro/v1/config/responderaction" + responderGlobalBindingURL = "/nitro/v1/config/responderglobal_binding" + responderGlobalResponderPolicyBindingURL = "/nitro/v1/config/responderglobal_responderpolicy_binding" + responderHTMLPageURL = "/nitro/v1/config/responderhtmlpage" + responderParamURL = "/nitro/v1/config/responderparam" + responderPolicyURL = "/nitro/v1/config/responderpolicy" + responderPolicyLabelURL = "/nitro/v1/config/responderpolicylabel" + responderPolicyLabelBindingURL = "/nitro/v1/config/responderpolicylabel_binding" + responderPolicyLabelPolicyBindingBindingURL = "/nitro/v1/config/responderpolicylabel_policybinding_binding" + responderPolicyLabelResponderPolicyBindingURL = "/nitro/v1/config/responderpolicylabel_responderpolicy_binding" + responderPolicyBindingURL = "/nitro/v1/config/responderpolicy_binding" + responderPolicyCRVServerBindingURL = "/nitro/v1/config/responderpolicy_crvserver_binding" + responderPolicyCSVServerBindingURL = "/nitro/v1/config/responderpolicy_csvserver_binding" + responderPolicyLBVServerBindingURL = "/nitro/v1/config/responderpolicy_lbvserver_binding" + responderPolicyResponderGlobalBindingURL = "/nitro/v1/config/responderpolicy_responderglobal_binding" + responderPolicyResponderPolicyLabelBindingURL = "/nitro/v1/config/responderpolicy_responderpolicylabel_binding" + responderPolicyVPNVServerBindingURL = "/nitro/v1/config/responderpolicy_vpnvserver_binding" +) + // Responder configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/responder/responder type ResponderService struct { @@ -7,100 +37,1274 @@ type ResponderService struct { } // responderaction -func (s *ResponderService) AddResponderAction() {} -func (s *ResponderService) DeleteResponderAction() {} -func (s *ResponderService) UpdateResponderAction() {} -func (s *ResponderService) UnsetResponderAction() {} -func (s *ResponderService) GetAllResponderAction() {} -func (s *ResponderService) GetResponderAction() {} -func (s *ResponderService) CountResponderAction() {} -func (s *ResponderService) RenameResponderAction() {} + +func (s *ResponderService) AddResponderAction(action models.ResponderAction) error { + payload := map[string]any{ + "responderaction": action, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, responderActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ResponderService) DeleteResponderAction(name string) error { + reqURL := fmt.Sprintf("%s/%s", responderActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ResponderService) UpdateResponderAction(action models.ResponderAction) error { + payload := map[string]any{ + "responderaction": action, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, responderActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ResponderService) UnsetResponderAction(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{ + "responderaction": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, responderActionURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ResponderService) GetAllResponderAction() ([]models.ResponderAction, error) { + req, err := s.client.NewRequest(http.MethodGet, responderActionURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Actions []models.ResponderAction `json:"responderaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Actions, nil +} + +func (s *ResponderService) GetResponderAction(name string) ([]models.ResponderAction, error) { + reqURL := fmt.Sprintf("%s/%s", responderActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Actions []models.ResponderAction `json:"responderaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Actions, nil +} + +func (s *ResponderService) CountResponderAction() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, responderActionURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Actions []struct { + Count float64 `json:"__count"` + } `json:"responderaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Actions) > 0 { + return result.Actions[0].Count, nil + } + return 0, nil +} + +func (s *ResponderService) RenameResponderAction(name, newname string) error { + payload := map[string]any{ + "responderaction": map[string]string{ + "name": name, + "newname": newname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, responderActionURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} // responderglobal_binding -func (s *ResponderService) GetResponderGlobalBinding() {} + +func (s *ResponderService) GetResponderGlobalBinding() ([]models.ResponderGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, responderGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ResponderGlobalBinding `json:"responderglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // responderglobal_responderpolicy_binding -func (s *ResponderService) AddResponderGlobalResponderPolicyBinding() {} -func (s *ResponderService) DeleteResponderGlobalResponderPolicyBinding() {} -func (s *ResponderService) GetResponderGlobalResponderPolicyBinding() {} -func (s *ResponderService) CountResponderGlobalResponderPolicyBinding() {} + +func (s *ResponderService) AddResponderGlobalResponderPolicyBinding(binding models.ResponderGlobalResponderPolicyBinding) error { + payload := map[string]any{ + "responderglobal_responderpolicy_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, responderGlobalResponderPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ResponderService) DeleteResponderGlobalResponderPolicyBinding(policyname, typeField string, priority int) error { + reqURL := fmt.Sprintf("%s?args=policyname:%s,type:%s,priority:%d", responderGlobalResponderPolicyBindingURL, url.QueryEscape(policyname), url.QueryEscape(typeField), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ResponderService) GetResponderGlobalResponderPolicyBinding() ([]models.ResponderGlobalResponderPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, responderGlobalResponderPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ResponderGlobalResponderPolicyBinding `json:"responderglobal_responderpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ResponderService) CountResponderGlobalResponderPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, responderGlobalResponderPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"responderglobal_responderpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // responderhtmlpage -func (s *ResponderService) ImportResponderHTMLPage() {} -func (s *ResponderService) DeleteResponderHTMLPage() {} -func (s *ResponderService) GetAllResponderHTMLPage() {} -func (s *ResponderService) GetResponderHTMLPage() {} -func (s *ResponderService) ChangeResponderHTMLPage() {} + +func (s *ResponderService) ImportResponderHTMLPage(page models.ResponderHTMLPage) error { + payload := map[string]any{ + "responderhtmlpage": page, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, responderHTMLPageURL+"?action=Import", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ResponderService) DeleteResponderHTMLPage(name string) error { + reqURL := fmt.Sprintf("%s/%s", responderHTMLPageURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ResponderService) GetAllResponderHTMLPage() ([]models.ResponderHTMLPage, error) { + req, err := s.client.NewRequest(http.MethodGet, responderHTMLPageURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Pages []models.ResponderHTMLPage `json:"responderhtmlpage"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Pages, nil +} + +func (s *ResponderService) GetResponderHTMLPage(name string) ([]models.ResponderHTMLPage, error) { + reqURL := fmt.Sprintf("%s/%s", responderHTMLPageURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Pages []models.ResponderHTMLPage `json:"responderhtmlpage"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Pages, nil +} + +func (s *ResponderService) ChangeResponderHTMLPage(page models.ResponderHTMLPage) error { + payload := map[string]any{ + "responderhtmlpage": page, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, responderHTMLPageURL+"?action=update", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} // responderparam -func (s *ResponderService) UpdateResponderParam() {} -func (s *ResponderService) UnsetResponderParam() {} -func (s *ResponderService) GetAllResponderParam() {} + +func (s *ResponderService) UpdateResponderParam(param models.ResponderParam) error { + payload := map[string]any{ + "responderparam": param, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, responderParamURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ResponderService) UnsetResponderParam(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{ + "responderparam": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, responderParamURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ResponderService) GetAllResponderParam() (models.ResponderParam, error) { + req, err := s.client.NewRequest(http.MethodGet, responderParamURL, nil) + if err != nil { + return models.ResponderParam{}, err + } + resp, err := s.client.Do(req) + if err != nil { + return models.ResponderParam{}, err + } + var result struct { + Params []models.ResponderParam `json:"responderparam"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return models.ResponderParam{}, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Params) > 0 { + return result.Params[0], nil + } + return models.ResponderParam{}, nil +} // responderpolicy -func (s *ResponderService) AddResponderPolicy() {} -func (s *ResponderService) DeleteResponderPolicy() {} -func (s *ResponderService) UpdateResponderPolicy() {} -func (s *ResponderService) UnsetResponderPolicy() {} -func (s *ResponderService) GetAllResponderPolicy() {} -func (s *ResponderService) GetResponderPolicy() {} -func (s *ResponderService) CountResponderPolicy() {} -func (s *ResponderService) RenameResponderPolicy() {} + +func (s *ResponderService) AddResponderPolicy(policy models.ResponderPolicy) error { + payload := map[string]any{ + "responderpolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, responderPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ResponderService) DeleteResponderPolicy(name string) error { + reqURL := fmt.Sprintf("%s/%s", responderPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ResponderService) UpdateResponderPolicy(policy models.ResponderPolicy) error { + payload := map[string]any{ + "responderpolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, responderPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ResponderService) UnsetResponderPolicy(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{ + "responderpolicy": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, responderPolicyURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ResponderService) GetAllResponderPolicy() ([]models.ResponderPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, responderPolicyURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Policies []models.ResponderPolicy `json:"responderpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Policies, nil +} + +func (s *ResponderService) GetResponderPolicy(name string) ([]models.ResponderPolicy, error) { + reqURL := fmt.Sprintf("%s/%s", responderPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Policies []models.ResponderPolicy `json:"responderpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Policies, nil +} + +func (s *ResponderService) CountResponderPolicy() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, responderPolicyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Policies []struct { + Count float64 `json:"__count"` + } `json:"responderpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Policies) > 0 { + return result.Policies[0].Count, nil + } + return 0, nil +} + +func (s *ResponderService) RenameResponderPolicy(name, newname string) error { + payload := map[string]any{ + "responderpolicy": map[string]string{ + "name": name, + "newname": newname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, responderPolicyURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} // responderpolicylabel -func (s *ResponderService) AddResponderPolicyLabel() {} -func (s *ResponderService) DeleteResponderPolicyLabel() {} -func (s *ResponderService) GetAllResponderPolicyLabel() {} -func (s *ResponderService) GetResponderPolicyLabel() {} -func (s *ResponderService) CountResponderPolicyLabel() {} -func (s *ResponderService) RenameResponderPolicyLabel() {} + +func (s *ResponderService) AddResponderPolicyLabel(label models.ResponderPolicyLabel) error { + payload := map[string]any{ + "responderpolicylabel": label, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, responderPolicyLabelURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ResponderService) DeleteResponderPolicyLabel(labelname string) error { + reqURL := fmt.Sprintf("%s/%s", responderPolicyLabelURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ResponderService) GetAllResponderPolicyLabel() ([]models.ResponderPolicyLabel, error) { + req, err := s.client.NewRequest(http.MethodGet, responderPolicyLabelURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Labels []models.ResponderPolicyLabel `json:"responderpolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Labels, nil +} + +func (s *ResponderService) GetResponderPolicyLabel(labelname string) ([]models.ResponderPolicyLabel, error) { + reqURL := fmt.Sprintf("%s/%s", responderPolicyLabelURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Labels []models.ResponderPolicyLabel `json:"responderpolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Labels, nil +} + +func (s *ResponderService) CountResponderPolicyLabel() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, responderPolicyLabelURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Labels []struct { + Count float64 `json:"__count"` + } `json:"responderpolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Labels) > 0 { + return result.Labels[0].Count, nil + } + return 0, nil +} + +func (s *ResponderService) RenameResponderPolicyLabel(labelname, newname string) error { + payload := map[string]any{ + "responderpolicylabel": map[string]string{ + "labelname": labelname, + "newname": newname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, responderPolicyLabelURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} // responderpolicylabel_binding -func (s *ResponderService) GetAllResponderPolicyLabelBinding() {} -func (s *ResponderService) GetResponderPolicyLabelBinding() {} + +func (s *ResponderService) GetAllResponderPolicyLabelBinding() ([]models.ResponderPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, responderPolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ResponderPolicyLabelBinding `json:"responderpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ResponderService) GetResponderPolicyLabelBinding(labelname string) ([]models.ResponderPolicyLabelBinding, error) { + reqURL := fmt.Sprintf("%s/%s", responderPolicyLabelBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ResponderPolicyLabelBinding `json:"responderpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // respondrepolicylabel_policybinding_binding -func (s *ResponderService) GetAllResponderPolicyLabelPolicyBindingBinding() {} -func (s *ResponderService) GetResponderPolicyLabelPolicyBindingBinding() {} -func (s *ResponderService) CountResponderPolicyLabelPolicyBindingBinding() {} + +func (s *ResponderService) GetAllResponderPolicyLabelPolicyBindingBinding() ([]models.ResponderPolicyLabelPolicyBindingBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, responderPolicyLabelPolicyBindingBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ResponderPolicyLabelPolicyBindingBinding `json:"responderpolicylabel_policybinding_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ResponderService) GetResponderPolicyLabelPolicyBindingBinding(labelname string) ([]models.ResponderPolicyLabelPolicyBindingBinding, error) { + reqURL := fmt.Sprintf("%s/%s", responderPolicyLabelPolicyBindingBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ResponderPolicyLabelPolicyBindingBinding `json:"responderpolicylabel_policybinding_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ResponderService) CountResponderPolicyLabelPolicyBindingBinding(labelname string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", responderPolicyLabelPolicyBindingBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"responderpolicylabel_policybinding_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // responderpolicylabel_responderpolicy_binding -func (s *ResponderService) AddResponderPolicyLabelResponderPolicyBinding() {} -func (s *ResponderService) DeleteResponderPolicyLabelResponderPolicyBinding() {} -func (s *ResponderService) GetAllResponderPolicyLabelResponderPolicyBinding() {} -func (s *ResponderService) GetResponderPolicyLabelResponderPolicyBinding() {} -func (s *ResponderService) CountResponderPolicyLabelResponderPolicyBinding() {} + +func (s *ResponderService) AddResponderPolicyLabelResponderPolicyBinding(binding models.ResponderPolicyLabelResponderPolicyBinding) error { + payload := map[string]any{ + "responderpolicylabel_responderpolicy_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, responderPolicyLabelResponderPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ResponderService) DeleteResponderPolicyLabelResponderPolicyBinding(labelname, policyname string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,priority:%d", responderPolicyLabelResponderPolicyBindingURL, url.QueryEscape(labelname), url.QueryEscape(policyname), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *ResponderService) GetAllResponderPolicyLabelResponderPolicyBinding() ([]models.ResponderPolicyLabelResponderPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, responderPolicyLabelResponderPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ResponderPolicyLabelResponderPolicyBinding `json:"responderpolicylabel_responderpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ResponderService) GetResponderPolicyLabelResponderPolicyBinding(labelname string) ([]models.ResponderPolicyLabelResponderPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", responderPolicyLabelResponderPolicyBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ResponderPolicyLabelResponderPolicyBinding `json:"responderpolicylabel_responderpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ResponderService) CountResponderPolicyLabelResponderPolicyBinding(labelname string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", responderPolicyLabelResponderPolicyBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"responderpolicylabel_responderpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // responderpolicy_binding -func (s *ResponderService) GetAllResponderPolicyBinding() {} -func (s *ResponderService) GetResponderPolicyBinding() {} + +func (s *ResponderService) GetAllResponderPolicyBinding() ([]models.ResponderPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, responderPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ResponderPolicyBinding `json:"responderpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ResponderService) GetResponderPolicyBinding(name string) ([]models.ResponderPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", responderPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ResponderPolicyBinding `json:"responderpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // responderpolicy_crvserver_binding -func (s *ResponderService) GetAllResponderPolicyCRVServerBinding() {} -func (s *ResponderService) GetResponderPolicyCRVServerBinding() {} -func (s *ResponderService) CountResponderPolicyCRVServerBinding() {} + +func (s *ResponderService) GetAllResponderPolicyCRVServerBinding() ([]models.ResponderPolicyCRVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, responderPolicyCRVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ResponderPolicyCRVServerBinding `json:"responderpolicy_crvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ResponderService) GetResponderPolicyCRVServerBinding(name string) ([]models.ResponderPolicyCRVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", responderPolicyCRVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ResponderPolicyCRVServerBinding `json:"responderpolicy_crvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ResponderService) CountResponderPolicyCRVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", responderPolicyCRVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"responderpolicy_crvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // responderpolicy_csvserver_binding -func (s *ResponderService) GetAllResponderPolicyCSVServerBinding() {} -func (s *ResponderService) GetResponderPolicyCSVServerBinding() {} -func (s *ResponderService) CountResponderPolicyCSVServerBinding() {} + +func (s *ResponderService) GetAllResponderPolicyCSVServerBinding() ([]models.ResponderPolicyCSVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, responderPolicyCSVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ResponderPolicyCSVServerBinding `json:"responderpolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ResponderService) GetResponderPolicyCSVServerBinding(name string) ([]models.ResponderPolicyCSVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", responderPolicyCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ResponderPolicyCSVServerBinding `json:"responderpolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ResponderService) CountResponderPolicyCSVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", responderPolicyCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"responderpolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // responderpolicy_lbvserver_binding -func (s *ResponderService) GetAllResponderPolicyLBVServerBinding() {} -func (s *ResponderService) GetResponderPolicyLBVServerBinding() {} -func (s *ResponderService) CountResponderPolicyLBVServerBinding() {} + +func (s *ResponderService) GetAllResponderPolicyLBVServerBinding() ([]models.ResponderPolicyLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, responderPolicyLBVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ResponderPolicyLBVServerBinding `json:"responderpolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ResponderService) GetResponderPolicyLBVServerBinding(name string) ([]models.ResponderPolicyLBVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", responderPolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ResponderPolicyLBVServerBinding `json:"responderpolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ResponderService) CountResponderPolicyLBVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", responderPolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"responderpolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // responderpolicy_responderglobal_binding -func (s *ResponderService) GetAllResponderPolicyResponderGlobalBinding() {} -func (s *ResponderService) GetResponderPolicyResponderGlobalBinding() {} -func (s *ResponderService) CountResponderPolicyResponderGlobalBinding() {} + +func (s *ResponderService) GetAllResponderPolicyResponderGlobalBinding() ([]models.ResponderPolicyResponderGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, responderPolicyResponderGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ResponderPolicyResponderGlobalBinding `json:"responderpolicy_responderglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ResponderService) GetResponderPolicyResponderGlobalBinding(name string) ([]models.ResponderPolicyResponderGlobalBinding, error) { + reqURL := fmt.Sprintf("%s/%s", responderPolicyResponderGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ResponderPolicyResponderGlobalBinding `json:"responderpolicy_responderglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ResponderService) CountResponderPolicyResponderGlobalBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", responderPolicyResponderGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"responderpolicy_responderglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // responderpolicy_responderpolicylabel_binding -func (s *ResponderService) GetAllResponderPolicyResponderPolicyLabelBinding() {} -func (s *ResponderService) GetResponderPolicyResponderPolicyLabelBinding() {} -func (s *ResponderService) CountResponderPolicyResponderPolicyLabelBinding() {} + +func (s *ResponderService) GetAllResponderPolicyResponderPolicyLabelBinding() ([]models.ResponderPolicyResponderPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, responderPolicyResponderPolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ResponderPolicyResponderPolicyLabelBinding `json:"responderpolicy_responderpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ResponderService) GetResponderPolicyResponderPolicyLabelBinding(name string) ([]models.ResponderPolicyResponderPolicyLabelBinding, error) { + reqURL := fmt.Sprintf("%s/%s", responderPolicyResponderPolicyLabelBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ResponderPolicyResponderPolicyLabelBinding `json:"responderpolicy_responderpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ResponderService) CountResponderPolicyResponderPolicyLabelBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", responderPolicyResponderPolicyLabelBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"responderpolicy_responderpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // responderpolicy_vpnvserver_binding -func (s *ResponderService) GetAllResponderPolicyVPNVServerBinding() {} -func (s *ResponderService) GetResponderPolicyVPNVServerBinding() {} -func (s *ResponderService) CountResponderPolicyVPNVServerBinding() {} + +func (s *ResponderService) GetAllResponderPolicyVPNVServerBinding() ([]models.ResponderPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, responderPolicyVPNVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ResponderPolicyVPNVServerBinding `json:"responderpolicy_vpnvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ResponderService) GetResponderPolicyVPNVServerBinding(name string) ([]models.ResponderPolicyVPNVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", responderPolicyVPNVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.ResponderPolicyVPNVServerBinding `json:"responderpolicy_vpnvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *ResponderService) CountResponderPolicyVPNVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", responderPolicyVPNVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"responderpolicy_vpnvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} diff --git a/nitrogo/rewrite.go b/nitrogo/rewrite.go index a43d4be..97b8339 100644 --- a/nitrogo/rewrite.go +++ b/nitrogo/rewrite.go @@ -1,5 +1,33 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + rewriteActionURL = "/nitro/v1/config/rewriteaction" + rewriteGlobalBindingURL = "/nitro/v1/config/rewriteglobal_binding" + rewriteGlobalRewritePolicyBindingURL = "/nitro/v1/config/rewriteglobal_rewritepolicy_binding" + rewriteParamURL = "/nitro/v1/config/rewriteparam" + rewritePolicyURL = "/nitro/v1/config/rewritepolicy" + rewritePolicyLabelURL = "/nitro/v1/config/rewritepolicylabel" + rewritePolicyLabelBindingURL = "/nitro/v1/config/rewritepolicylabel_binding" + rewritePolicyLabelPolicyBindingBindingURL = "/nitro/v1/config/rewritepolicylabel_policybinding_binding" + rewritePolicyLabelRewritePolicyBindingURL = "/nitro/v1/config/rewritepolicylabel_rewritepolicy_binding" + rewritePolicyBindingURL = "/nitro/v1/config/rewritepolicy_binding" + rewritePolicyCSVServerBindingURL = "/nitro/v1/config/rewritepolicy_csvserver_binding" + rewritePolicyLBVServerBindingURL = "/nitro/v1/config/rewritepolicy_lbvserver_binding" + rewritePolicyRewriteGlobalBindingURL = "/nitro/v1/config/rewritepolicy_rewriteglobal_binding" + rewritePolicyRewritePolicyLabelBindingURL = "/nitro/v1/config/rewritepolicy_rewritepolicylabel_binding" + rewritePolicyVPNVServerBindingURL = "/nitro/v1/config/rewritepolicy_vpnvserver_binding" +) + // Rewrite configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/rewrite/rewrite type RewriteService struct { @@ -7,88 +35,1125 @@ type RewriteService struct { } // rewriteaction -func (s *RewriteService) AddRewriteAction() {} -func (s *RewriteService) DeleteRewriteAction() {} -func (s *RewriteService) UpdateRewriteAction() {} -func (s *RewriteService) UnsetRewriteAction() {} -func (s *RewriteService) GetAllRewriteAction() {} -func (s *RewriteService) GetRewriteAction() {} -func (s *RewriteService) CountRewriteAction() {} -func (s *RewriteService) RenameRewriteAction() {} + +func (s *RewriteService) AddRewriteAction(action models.RewriteAction) error { + payload := map[string]any{ + "rewriteaction": action, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, rewriteActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *RewriteService) DeleteRewriteAction(name string) error { + reqURL := fmt.Sprintf("%s/%s", rewriteActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *RewriteService) UpdateRewriteAction(action models.RewriteAction) error { + payload := map[string]any{ + "rewriteaction": action, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, rewriteActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *RewriteService) UnsetRewriteAction(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{ + "rewriteaction": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, rewriteActionURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *RewriteService) GetAllRewriteAction() ([]models.RewriteAction, error) { + req, err := s.client.NewRequest(http.MethodGet, rewriteActionURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Actions []models.RewriteAction `json:"rewriteaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Actions, nil +} + +func (s *RewriteService) GetRewriteAction(name string) ([]models.RewriteAction, error) { + reqURL := fmt.Sprintf("%s/%s", rewriteActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Actions []models.RewriteAction `json:"rewriteaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Actions, nil +} + +func (s *RewriteService) CountRewriteAction() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, rewriteActionURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Actions []struct { + Count float64 `json:"__count"` + } `json:"rewriteaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Actions) > 0 { + return result.Actions[0].Count, nil + } + return 0, nil +} + +func (s *RewriteService) RenameRewriteAction(name, newname string) error { + payload := map[string]any{ + "rewriteaction": map[string]string{ + "name": name, + "newname": newname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, rewriteActionURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} // rewriteglobal_binding -func (s *RewriteService) GetRewriteGlobalBinding() {} + +func (s *RewriteService) GetRewriteGlobalBinding() ([]models.RewriteGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, rewriteGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.RewriteGlobalBinding `json:"rewriteglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // rewriteglobal_rewritepolicy_binding -func (s *RewriteService) AddRewriteGlobalRewritePolicyBinding() {} -func (s *RewriteService) DeleteRewriteGlobalRewritePolicyBinding() {} -func (s *RewriteService) GetRewriteGlobalRewritePolicyBinding() {} -func (s *RewriteService) CountRewriteGlobalRewritePolicyBinding() {} + +func (s *RewriteService) AddRewriteGlobalRewritePolicyBinding(binding models.RewriteGlobalRewritePolicyBinding) error { + payload := map[string]any{ + "rewriteglobal_rewritepolicy_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, rewriteGlobalRewritePolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *RewriteService) DeleteRewriteGlobalRewritePolicyBinding(policyname string) error { + reqURL := fmt.Sprintf("%s?args=policyname:%s", rewriteGlobalRewritePolicyBindingURL, url.QueryEscape(policyname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *RewriteService) GetRewriteGlobalRewritePolicyBinding() ([]models.RewriteGlobalRewritePolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, rewriteGlobalRewritePolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.RewriteGlobalRewritePolicyBinding `json:"rewriteglobal_rewritepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *RewriteService) CountRewriteGlobalRewritePolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, rewriteGlobalRewritePolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"rewriteglobal_rewritepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // rewriteparam -func (s *RewriteService) UpdateRewriteParam() {} -func (s *RewriteService) UnsetRewriteParam() {} -func (s *RewriteService) GetAllRewriteParam() {} + +func (s *RewriteService) UpdateRewriteParam(param models.RewriteParam) error { + payload := map[string]any{ + "rewriteparam": param, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, rewriteParamURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *RewriteService) UnsetRewriteParam(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{ + "rewriteparam": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, rewriteParamURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *RewriteService) GetAllRewriteParam() (models.RewriteParam, error) { + req, err := s.client.NewRequest(http.MethodGet, rewriteParamURL, nil) + if err != nil { + return models.RewriteParam{}, err + } + resp, err := s.client.Do(req) + if err != nil { + return models.RewriteParam{}, err + } + var result struct { + Params []models.RewriteParam `json:"rewriteparam"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return models.RewriteParam{}, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Params) > 0 { + return result.Params[0], nil + } + return models.RewriteParam{}, nil +} // rewritepolicy -func (s *RewriteService) AddRewritePolicy() {} -func (s *RewriteService) DeleteRewritePolicy() {} -func (s *RewriteService) UpdateRewritePolicy() {} -func (s *RewriteService) UnsetRewritePolicy() {} -func (s *RewriteService) GetAllRewritePolicy() {} -func (s *RewriteService) GetRewritePolicy() {} -func (s *RewriteService) CountRewritePolicy() {} -func (s *RewriteService) RenameRewritePolicy() {} + +func (s *RewriteService) AddRewritePolicy(policy models.RewritePolicy) error { + payload := map[string]any{ + "rewritepolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, rewritePolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *RewriteService) DeleteRewritePolicy(name string) error { + reqURL := fmt.Sprintf("%s/%s", rewritePolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *RewriteService) UpdateRewritePolicy(policy models.RewritePolicy) error { + payload := map[string]any{ + "rewritepolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, rewritePolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *RewriteService) UnsetRewritePolicy(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{ + "rewritepolicy": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, rewritePolicyURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *RewriteService) GetAllRewritePolicy() ([]models.RewritePolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, rewritePolicyURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Policies []models.RewritePolicy `json:"rewritepolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Policies, nil +} + +func (s *RewriteService) GetRewritePolicy(name string) ([]models.RewritePolicy, error) { + reqURL := fmt.Sprintf("%s/%s", rewritePolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Policies []models.RewritePolicy `json:"rewritepolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Policies, nil +} + +func (s *RewriteService) CountRewritePolicy() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, rewritePolicyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Policies []struct { + Count float64 `json:"__count"` + } `json:"rewritepolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Policies) > 0 { + return result.Policies[0].Count, nil + } + return 0, nil +} + +func (s *RewriteService) RenameRewritePolicy(name, newname string) error { + payload := map[string]any{ + "rewritepolicy": map[string]string{ + "name": name, + "newname": newname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, rewritePolicyURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} // rewritepolicylabel -func (s *RewriteService) AddRewritePolicyLabel() {} -func (s *RewriteService) DeleteRewritePolicyLabel() {} -func (s *RewriteService) GetAllRewritePolicyLabel() {} -func (s *RewriteService) GetRewritePolicyLabel() {} -func (s *RewriteService) CountRewritePolicyLabel() {} -func (s *RewriteService) RenameRewritePolicyLabel() {} + +func (s *RewriteService) AddRewritePolicyLabel(label models.RewritePolicyLabel) error { + payload := map[string]any{ + "rewritepolicylabel": label, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, rewritePolicyLabelURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *RewriteService) DeleteRewritePolicyLabel(labelname string) error { + reqURL := fmt.Sprintf("%s/%s", rewritePolicyLabelURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *RewriteService) GetAllRewritePolicyLabel() ([]models.RewritePolicyLabel, error) { + req, err := s.client.NewRequest(http.MethodGet, rewritePolicyLabelURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Labels []models.RewritePolicyLabel `json:"rewritepolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Labels, nil +} + +func (s *RewriteService) GetRewritePolicyLabel(labelname string) ([]models.RewritePolicyLabel, error) { + reqURL := fmt.Sprintf("%s/%s", rewritePolicyLabelURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Labels []models.RewritePolicyLabel `json:"rewritepolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Labels, nil +} + +func (s *RewriteService) CountRewritePolicyLabel() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, rewritePolicyLabelURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Labels []struct { + Count float64 `json:"__count"` + } `json:"rewritepolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Labels) > 0 { + return result.Labels[0].Count, nil + } + return 0, nil +} + +func (s *RewriteService) RenameRewritePolicyLabel(labelname, newname string) error { + payload := map[string]any{ + "rewritepolicylabel": map[string]string{ + "labelname": labelname, + "newname": newname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, rewritePolicyLabelURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} // rewritepolicylabel_binding -func (s *RewriteService) GetAllRewritePolicyLabelBinding() {} -func (s *RewriteService) GetRewritePolicyLabelBinding() {} + +func (s *RewriteService) GetAllRewritePolicyLabelBinding() ([]models.RewritePolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, rewritePolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.RewritePolicyLabelBinding `json:"rewritepolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *RewriteService) GetRewritePolicyLabelBinding(labelname string) ([]models.RewritePolicyLabelBinding, error) { + reqURL := fmt.Sprintf("%s/%s", rewritePolicyLabelBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.RewritePolicyLabelBinding `json:"rewritepolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // rewritepolicylabel_policybinding_binding -func (s *RewriteService) GetAllRewritePolicyLabelPolicyBindingBinding() {} -func (s *RewriteService) GetRewritePolicyLabelPolicyBindingBinding() {} -func (s *RewriteService) CountRewritePolicyLabelPolicyBindingBinding() {} -// rewritepolicylabel-rewritepolicy_binding -func (s *RewriteService) AddRewritePolicyLabelRewritePolicyBinding() {} -func (s *RewriteService) DeleteRewritePolicyLabelRewritePolicyBinding() {} -func (s *RewriteService) GetAllRewritePolicyLabelRewritePolicyBinding() {} -func (s *RewriteService) GetRewritePolicyLabelRewritePolicyBinding() {} -func (s *RewriteService) CountRewritePolicyLabelRewritePolicyBinding() {} +func (s *RewriteService) GetAllRewritePolicyLabelPolicyBindingBinding() ([]models.RewritePolicyLabelPolicyBindingBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, rewritePolicyLabelPolicyBindingBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.RewritePolicyLabelPolicyBindingBinding `json:"rewritepolicylabel_policybinding_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *RewriteService) GetRewritePolicyLabelPolicyBindingBinding(labelname string) ([]models.RewritePolicyLabelPolicyBindingBinding, error) { + reqURL := fmt.Sprintf("%s/%s", rewritePolicyLabelPolicyBindingBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.RewritePolicyLabelPolicyBindingBinding `json:"rewritepolicylabel_policybinding_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *RewriteService) CountRewritePolicyLabelPolicyBindingBinding(labelname string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", rewritePolicyLabelPolicyBindingBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"rewritepolicylabel_policybinding_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} + +// rewritepolicylabel_rewritepolicy_binding + +func (s *RewriteService) AddRewritePolicyLabelRewritePolicyBinding(binding models.RewritePolicyLabelRewritePolicyBinding) error { + payload := map[string]any{ + "rewritepolicylabel_rewritepolicy_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, rewritePolicyLabelRewritePolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *RewriteService) DeleteRewritePolicyLabelRewritePolicyBinding(labelname, policyname string) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s", rewritePolicyLabelRewritePolicyBindingURL, url.QueryEscape(labelname), url.QueryEscape(policyname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *RewriteService) GetAllRewritePolicyLabelRewritePolicyBinding() ([]models.RewritePolicyLabelRewritePolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, rewritePolicyLabelRewritePolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.RewritePolicyLabelRewritePolicyBinding `json:"rewritepolicylabel_rewritepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *RewriteService) GetRewritePolicyLabelRewritePolicyBinding(labelname string) ([]models.RewritePolicyLabelRewritePolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", rewritePolicyLabelRewritePolicyBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.RewritePolicyLabelRewritePolicyBinding `json:"rewritepolicylabel_rewritepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *RewriteService) CountRewritePolicyLabelRewritePolicyBinding(labelname string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", rewritePolicyLabelRewritePolicyBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"rewritepolicylabel_rewritepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // rewritepolicy_binding -func (s *RewriteService) GetAllRewritePolicyBinding() {} -func (s *RewriteService) GetRewritePolicyBinding() {} + +func (s *RewriteService) GetAllRewritePolicyBinding() ([]models.RewritePolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, rewritePolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.RewritePolicyBinding `json:"rewritepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *RewriteService) GetRewritePolicyBinding(name string) ([]models.RewritePolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", rewritePolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.RewritePolicyBinding `json:"rewritepolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // rewritepolicy_csvserver_binding -func (s *RewriteService) GetAllRewritePolicyCSVServerBinding() {} -func (s *RewriteService) GetRewritePolicyCSVServerBinding() {} -func (s *RewriteService) CountRewritePolicyCSVServerBinding() {} + +func (s *RewriteService) GetAllRewritePolicyCSVServerBinding() ([]models.RewritePolicyCSVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, rewritePolicyCSVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.RewritePolicyCSVServerBinding `json:"rewritepolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *RewriteService) GetRewritePolicyCSVServerBinding(name string) ([]models.RewritePolicyCSVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", rewritePolicyCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.RewritePolicyCSVServerBinding `json:"rewritepolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *RewriteService) CountRewritePolicyCSVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", rewritePolicyCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"rewritepolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // rewritepolicy_lbvserver_binding -func (s *RewriteService) GetAllRewritePolicyLBVServerBinding() {} -func (s *RewriteService) GetRewritePolicyLBVServerBinding() {} -func (s *RewriteService) CountRewritePolicyLBVServerBinding() {} + +func (s *RewriteService) GetAllRewritePolicyLBVServerBinding() ([]models.RewritePolicyLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, rewritePolicyLBVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.RewritePolicyLBVServerBinding `json:"rewritepolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *RewriteService) GetRewritePolicyLBVServerBinding(name string) ([]models.RewritePolicyLBVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", rewritePolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.RewritePolicyLBVServerBinding `json:"rewritepolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *RewriteService) CountRewritePolicyLBVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", rewritePolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"rewritepolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // rewritepolicy_rewriteglobal_binding -func (s *RewriteService) GetAllRewritePolicyRewriteGlobalBinding() {} -func (s *RewriteService) GetRewritePolicyRewriteGlobalBinding() {} -func (s *RewriteService) CountRewritePolicyRewriteGlobalBinding() {} + +func (s *RewriteService) GetAllRewritePolicyRewriteGlobalBinding() ([]models.RewritePolicyRewriteGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, rewritePolicyRewriteGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.RewritePolicyRewriteGlobalBinding `json:"rewritepolicy_rewriteglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *RewriteService) GetRewritePolicyRewriteGlobalBinding(name string) ([]models.RewritePolicyRewriteGlobalBinding, error) { + reqURL := fmt.Sprintf("%s/%s", rewritePolicyRewriteGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.RewritePolicyRewriteGlobalBinding `json:"rewritepolicy_rewriteglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *RewriteService) CountRewritePolicyRewriteGlobalBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", rewritePolicyRewriteGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"rewritepolicy_rewriteglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // rewritepolicy_rewritepolicylabel_binding -func (s *RewriteService) GetAllRewritePolicyRewritePolicyLabelBinding() {} -func (s *RewriteService) GetRewritePolicyRewritePolicyLabelBinding() {} -func (s *RewriteService) CountRewritePolicyRewritePolicyLabelBinding() {} + +func (s *RewriteService) GetAllRewritePolicyRewritePolicyLabelBinding() ([]models.RewritePolicyRewritePolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, rewritePolicyRewritePolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.RewritePolicyRewritePolicyLabelBinding `json:"rewritepolicy_rewritepolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *RewriteService) GetRewritePolicyRewritePolicyLabelBinding(name string) ([]models.RewritePolicyRewritePolicyLabelBinding, error) { + reqURL := fmt.Sprintf("%s/%s", rewritePolicyRewritePolicyLabelBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.RewritePolicyRewritePolicyLabelBinding `json:"rewritepolicy_rewritepolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *RewriteService) CountRewritePolicyRewritePolicyLabelBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", rewritePolicyRewritePolicyLabelBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"rewritepolicy_rewritepolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // rewritepolicy_vpnvserver_binding -func (s *RewriteService) GetAllRewritePolicyVPNVServerBinding() {} -func (s *RewriteService) GetRewritePolicyVPNVServerBinding() {} -func (s *RewriteService) CountRewritePolicyVPNVServerBinding() {} + +func (s *RewriteService) GetAllRewritePolicyVPNVServerBinding() ([]models.RewritePolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, rewritePolicyVPNVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.RewritePolicyVPNVServerBinding `json:"rewritepolicy_vpnvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *RewriteService) GetRewritePolicyVPNVServerBinding(name string) ([]models.RewritePolicyVPNVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", rewritePolicyVPNVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.RewritePolicyVPNVServerBinding `json:"rewritepolicy_vpnvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *RewriteService) CountRewritePolicyVPNVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", rewritePolicyVPNVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"rewritepolicy_vpnvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} diff --git a/nitrogo/router.go b/nitrogo/router.go index 087dcdb..e5dd3ac 100644 --- a/nitrogo/router.go +++ b/nitrogo/router.go @@ -1,5 +1,19 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + routerDynamicRoutingURL = "/nitro/v1/config/routerdynamicrouting" +) + // Router configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/router/router type RouterService struct { @@ -9,10 +23,145 @@ type RouterService struct { // routerdynamicrouting // Configuration for dynamic routing config resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/router/routerdynamicrouting -func (s *RouterService) AddRouterDynamicRouting() {} -func (s *RouterService) DeleteRouterDynamicRouting() {} -func (s *RouterService) UpdateRouterDynamicRouting() {} -func (s *RouterService) UnsetRouterDynamicRouting() {} -func (s *RouterService) GetAllRouterDynamicRouting() {} -func (s *RouterService) CountRouterDynamicRouting() {} -func (s *RouterService) ApplyRouterDynamicRouting() {} + +func (s *RouterService) AddRouterDynamicRouting(routing models.RouterDynamicRouting) error { + payload := map[string]any{ + "routerdynamicrouting": routing, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, routerDynamicRoutingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *RouterService) DeleteRouterDynamicRouting(commandString string) error { + // The DELETE for routerdynamicrouting has URL parameters args=commandstring: + reqURL := fmt.Sprintf("%s?args=commandstring:%s", routerDynamicRoutingURL, url.QueryEscape(commandString)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *RouterService) UpdateRouterDynamicRouting(routing models.RouterDynamicRouting) error { + payload := map[string]any{ + "routerdynamicrouting": routing, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, routerDynamicRoutingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *RouterService) UnsetRouterDynamicRouting(args []string) error { + unsetMap := make(map[string]bool) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "routerdynamicrouting": unsetMap, + } + + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, routerDynamicRoutingURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *RouterService) GetAllRouterDynamicRouting() ([]models.RouterDynamicRouting, error) { + req, err := s.client.NewRequest(http.MethodGet, routerDynamicRoutingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + RouterDynamicRoutings []models.RouterDynamicRouting `json:"routerdynamicrouting"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.RouterDynamicRoutings, nil +} + +func (s *RouterService) CountRouterDynamicRouting() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, routerDynamicRoutingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + RouterDynamicRoutings []struct { + Count float64 `json:"__count"` + } `json:"routerdynamicrouting"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.RouterDynamicRoutings) > 0 { + return result.RouterDynamicRoutings[0].Count, nil + } + + return 0, nil +} + +func (s *RouterService) ApplyRouterDynamicRouting(routing models.RouterDynamicRouting) error { + payload := map[string]any{ + "routerdynamicrouting": routing, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, routerDynamicRoutingURL+"?action=apply", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} diff --git a/nitrogo/smpp.go b/nitrogo/smpp.go index ea3eb5f..b380d28 100644 --- a/nitrogo/smpp.go +++ b/nitrogo/smpp.go @@ -1,5 +1,19 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + smppParamURL = "/nitro/v1/config/smppparam" + smppUserURL = "/nitro/v1/config/smppuser" +) + // All the commands associated with SMPP. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/smpp/smpp type SMPPService struct { @@ -9,16 +23,199 @@ type SMPPService struct { // smppparam // Configuration for SMPP configuration parameters resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/smpp/smppparam -func (s *SMPPService) UpdateSMPPParam() {} -func (s *SMPPService) UnsetSMPPParam() {} -func (s *SMPPService) GetAllSMPPParam() {} + +func (s *SMPPService) UpdateSMPPParam(param models.SMPPParam) error { + payload := map[string]any{ + "smppparam": param, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, smppParamURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SMPPService) UnsetSMPPParam(args []string) error { + unsetMap := make(map[string]bool) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "smppparam": unsetMap, + } + + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, smppParamURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SMPPService) GetAllSMPPParam() (models.SMPPParam, error) { + req, err := s.client.NewRequest(http.MethodGet, smppParamURL, nil) + if err != nil { + return models.SMPPParam{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.SMPPParam{}, err + } + + var result struct { + SMPPParams []models.SMPPParam `json:"smppparam"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.SMPPParam{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.SMPPParams) > 0 { + return result.SMPPParams[0], nil + } + + return models.SMPPParam{}, nil +} // smppuser // Configuration for SMPP user resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/smpp/smppuser -func (s *SMPPService) AddSMPPUser() {} -func (s *SMPPService) DeleteSMPPUser() {} -func (s *SMPPService) UpdateSMPPUser() {} -func (s *SMPPService) GetAllSMPPUser() {} -func (s *SMPPService) GetSMPPUser() {} -func (s *SMPPService) CountSMPPUser() {} + +func (s *SMPPService) AddSMPPUser(user models.SMPPUser) error { + payload := map[string]any{ + "smppuser": user, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, smppUserURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SMPPService) DeleteSMPPUser(username string) error { + url := fmt.Sprintf("%s/%s", smppUserURL, username) + req, err := s.client.NewRequest(http.MethodDelete, url, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SMPPService) UpdateSMPPUser(user models.SMPPUser) error { + payload := map[string]any{ + "smppuser": user, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, smppUserURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SMPPService) GetAllSMPPUser() ([]models.SMPPUser, error) { + req, err := s.client.NewRequest(http.MethodGet, smppUserURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SMPPUsers []models.SMPPUser `json:"smppuser"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SMPPUsers, nil +} + +func (s *SMPPService) GetSMPPUser(username string) ([]models.SMPPUser, error) { + url := fmt.Sprintf("%s/%s", smppUserURL, username) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SMPPUsers []models.SMPPUser `json:"smppuser"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SMPPUsers, nil +} + +func (s *SMPPService) CountSMPPUser() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, smppUserURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + SMPPUsers []struct { + Count float64 `json:"__count"` + } `json:"smppuser"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.SMPPUsers) > 0 { + return result.SMPPUsers[0].Count, nil + } + + return 0, nil +} diff --git a/nitrogo/snmp.go b/nitrogo/snmp.go index 35e31d0..0f7d83d 100644 --- a/nitrogo/snmp.go +++ b/nitrogo/snmp.go @@ -1,5 +1,31 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + snmpAlarmURL = "/nitro/v1/config/snmpalarm" + snmpCommunityURL = "/nitro/v1/config/snmpcommunity" + snmpEngineIdURL = "/nitro/v1/config/snmpengineid" + snmpGroupURL = "/nitro/v1/config/snmpgroup" + snmpManagerURL = "/nitro/v1/config/snmpmanager" + snmpMIBURL = "/nitro/v1/config/snmpmib" + snmpOIDURL = "/nitro/v1/config/snmpoid" + snmpOptionURL = "/nitro/v1/config/snmpoption" + snmpTrapURL = "/nitro/v1/config/snmptrap" + snmpTrapBindingURL = "/nitro/v1/config/snmptrap_binding" + snmpTrapSNMPUserBindingURL = "/nitro/v1/config/snmptrap_snmpuser_binding" + snmpUserURL = "/nitro/v1/config/snmpuser" + snmpViewURL = "/nitro/v1/config/snmpview" +) + // SNMP(Simple Network Management Protocol) configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/snmp/snmp type SNMPService struct { @@ -7,90 +33,1390 @@ type SNMPService struct { } // snmpalarm -func (s *SNMPService) UpdateSNMPAlarm() {} -func (s *SNMPService) UnsetSNMPAlarm() {} -func (s *SNMPService) EnableSNMPAlarm() {} -func (s *SNMPService) DisableSNMPAlarm() {} -func (s *SNMPService) GetAllSNMPAlarm() {} -func (s *SNMPService) GetSNMPAlarm() {} -func (s *SNMPService) CountSNMPAlarm() {} + +func (s *SNMPService) UpdateSNMPAlarm(alarm models.SNMPAlarm) error { + payload := map[string]any{ + "snmpalarm": alarm, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, snmpAlarmURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) UnsetSNMPAlarm(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "snmpalarm": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, snmpAlarmURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) EnableSNMPAlarm(trapname string) error { + payload := map[string]any{ + "snmpalarm": map[string]string{ + "trapname": trapname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, snmpAlarmURL+"?action=enable", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) DisableSNMPAlarm(trapname string) error { + payload := map[string]any{ + "snmpalarm": map[string]string{ + "trapname": trapname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, snmpAlarmURL+"?action=disable", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) GetAllSNMPAlarm() ([]models.SNMPAlarm, error) { + req, err := s.client.NewRequest(http.MethodGet, snmpAlarmURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Alarms []models.SNMPAlarm `json:"snmpalarm"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Alarms, nil +} + +func (s *SNMPService) GetSNMPAlarm(trapname string) ([]models.SNMPAlarm, error) { + urlReq := fmt.Sprintf("%s/%s", snmpAlarmURL, url.QueryEscape(trapname)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Alarms []models.SNMPAlarm `json:"snmpalarm"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Alarms, nil +} + +func (s *SNMPService) CountSNMPAlarm() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, snmpAlarmURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Alarms []struct { + Count float64 `json:"__count"` + } `json:"snmpalarm"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Alarms) > 0 { + return result.Alarms[0].Count, nil + } + + return 0, nil +} // snmpcommunity -func (s *SNMPService) AddSNMPCommunity() {} -func (s *SNMPService) DeleteSNMPCommunity() {} -func (s *SNMPService) GetAllSNMPCommunity() {} -func (s *SNMPService) GetSNMPCommunity() {} -func (s *SNMPService) CountSNMPCommunity() {} + +func (s *SNMPService) AddSNMPCommunity(community models.SNMPCommunity) error { + payload := map[string]any{ + "snmpcommunity": community, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, snmpCommunityURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) DeleteSNMPCommunity(communityname string) error { + urlReq := fmt.Sprintf("%s/%s", snmpCommunityURL, url.QueryEscape(communityname)) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) GetAllSNMPCommunity() ([]models.SNMPCommunity, error) { + req, err := s.client.NewRequest(http.MethodGet, snmpCommunityURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Communities []models.SNMPCommunity `json:"snmpcommunity"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Communities, nil +} + +func (s *SNMPService) GetSNMPCommunity(communityname string) ([]models.SNMPCommunity, error) { + urlReq := fmt.Sprintf("%s/%s", snmpCommunityURL, url.QueryEscape(communityname)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Communities []models.SNMPCommunity `json:"snmpcommunity"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Communities, nil +} + +func (s *SNMPService) CountSNMPCommunity() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, snmpCommunityURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Communities []struct { + Count float64 `json:"__count"` + } `json:"snmpcommunity"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Communities) > 0 { + return result.Communities[0].Count, nil + } + + return 0, nil +} // snmpengineid -func (s *SNMPService) UpdateSNMPEngineId() {} -func (s *SNMPService) UnsetSNMPEngineId() {} -func (s *SNMPService) GetAllSNMPEngineId() {} -func (s *SNMPService) GetSNMPEngineId() {} -func (s *SNMPService) CountSNMPEngineId() {} + +func (s *SNMPService) UpdateSNMPEngineId(engineid models.SNMPEngineID) error { + payload := map[string]any{ + "snmpengineid": engineid, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, snmpEngineIdURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) UnsetSNMPEngineId(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "snmpengineid": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, snmpEngineIdURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) GetAllSNMPEngineId() ([]models.SNMPEngineID, error) { + req, err := s.client.NewRequest(http.MethodGet, snmpEngineIdURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + EngineIDs []models.SNMPEngineID `json:"snmpengineid"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.EngineIDs, nil +} + +func (s *SNMPService) GetSNMPEngineId(ownernode string) ([]models.SNMPEngineID, error) { + urlReq := fmt.Sprintf("%s/%s", snmpEngineIdURL, url.QueryEscape(ownernode)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + EngineIDs []models.SNMPEngineID `json:"snmpengineid"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.EngineIDs, nil +} + +func (s *SNMPService) CountSNMPEngineId() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, snmpEngineIdURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + EngineIDs []struct { + Count float64 `json:"__count"` + } `json:"snmpengineid"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.EngineIDs) > 0 { + return result.EngineIDs[0].Count, nil + } + + return 0, nil +} // snmpgroup -func (s *SNMPService) AddSNMPGroup() {} -func (s *SNMPService) DeleteSNMPGroup() {} -func (s *SNMPService) GetAllSNMPGroup() {} -func (s *SNMPService) GetSNMPGroup() {} -func (s *SNMPService) CountSNMPGroup() {} + +func (s *SNMPService) AddSNMPGroup(group models.SNMPGroup) error { + payload := map[string]any{ + "snmpgroup": group, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, snmpGroupURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) DeleteSNMPGroup(name string, securitylevel string) error { + urlReq := fmt.Sprintf("%s/%s?args=securitylevel:%s", snmpGroupURL, url.QueryEscape(name), url.QueryEscape(securitylevel)) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) GetAllSNMPGroup() ([]models.SNMPGroup, error) { + req, err := s.client.NewRequest(http.MethodGet, snmpGroupURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Groups []models.SNMPGroup `json:"snmpgroup"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Groups, nil +} + +func (s *SNMPService) GetSNMPGroup(name string) ([]models.SNMPGroup, error) { + urlReq := fmt.Sprintf("%s/%s", snmpGroupURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Groups []models.SNMPGroup `json:"snmpgroup"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Groups, nil +} + +func (s *SNMPService) CountSNMPGroup() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, snmpGroupURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Groups []struct { + Count float64 `json:"__count"` + } `json:"snmpgroup"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Groups) > 0 { + return result.Groups[0].Count, nil + } + + return 0, nil +} // snmpmanager -func (s *SNMPService) AddSNMPManager() {} -func (s *SNMPService) DeleteSNMPManager() {} -func (s *SNMPService) UpdateSNMPManager() {} -func (s *SNMPService) UnsetSNMPManager() {} -func (s *SNMPService) GetAllSNMPManager() {} -func (s *SNMPService) CountSNMPManager() {} + +func (s *SNMPService) AddSNMPManager(manager models.SNMPManager) error { + payload := map[string]any{ + "snmpmanager": manager, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, snmpManagerURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) DeleteSNMPManager(ip string) error { + urlReq := fmt.Sprintf("%s/%s", snmpManagerURL, url.QueryEscape(ip)) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) UpdateSNMPManager(manager models.SNMPManager) error { + payload := map[string]any{ + "snmpmanager": manager, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, snmpManagerURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) UnsetSNMPManager(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "snmpmanager": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, snmpManagerURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) GetAllSNMPManager() ([]models.SNMPManager, error) { + req, err := s.client.NewRequest(http.MethodGet, snmpManagerURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Managers []models.SNMPManager `json:"snmpmanager"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Managers, nil +} + +func (s *SNMPService) CountSNMPManager() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, snmpManagerURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Managers []struct { + Count float64 `json:"__count"` + } `json:"snmpmanager"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Managers) > 0 { + return result.Managers[0].Count, nil + } + + return 0, nil +} // snmpmib -func (s *SNMPService) UpdateSNMPMIB() {} -func (s *SNMPService) UnsetSNMPMIB() {} -func (s *SNMPService) GetAllSNMPMIB() {} -func (s *SNMPService) GetSNMPMIB() {} -func (s *SNMPService) CountSNMPMIB() {} + +func (s *SNMPService) UpdateSNMPMIB(mib models.SNMPMIB) error { + payload := map[string]any{ + "snmpmib": mib, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, snmpMIBURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) UnsetSNMPMIB(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "snmpmib": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, snmpMIBURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) GetAllSNMPMIB() ([]models.SNMPMIB, error) { + req, err := s.client.NewRequest(http.MethodGet, snmpMIBURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + MIBs []models.SNMPMIB `json:"snmpmib"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.MIBs, nil +} + +func (s *SNMPService) GetSNMPMIB(ownernode string) ([]models.SNMPMIB, error) { + urlReq := fmt.Sprintf("%s/%s", snmpMIBURL, url.QueryEscape(ownernode)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + MIBs []models.SNMPMIB `json:"snmpmib"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.MIBs, nil +} + +func (s *SNMPService) CountSNMPMIB() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, snmpMIBURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + MIBs []struct { + Count float64 `json:"__count"` + } `json:"snmpmib"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.MIBs) > 0 { + return result.MIBs[0].Count, nil + } + + return 0, nil +} // snmpoid -func (s *SNMPService) GetAllSNMPOId() {} -func (s *SNMPService) CountSNMPOId() {} + +func (s *SNMPService) GetAllSNMPOId() ([]models.SNMPOID, error) { + req, err := s.client.NewRequest(http.MethodGet, snmpOIDURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + OIDs []models.SNMPOID `json:"snmpoid"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.OIDs, nil +} + +func (s *SNMPService) CountSNMPOId() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, snmpOIDURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + OIDs []struct { + Count float64 `json:"__count"` + } `json:"snmpoid"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.OIDs) > 0 { + return result.OIDs[0].Count, nil + } + + return 0, nil +} // snmpoption -func (s *SNMPService) UpdateSNMPOption() {} -func (s *SNMPService) UnsetSNMPOption() {} -func (s *SNMPService) GetAllSNMPOption() {} + +func (s *SNMPService) UpdateSNMPOption(option models.SNMPOption) error { + payload := map[string]any{ + "snmpoption": option, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, snmpOptionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) UnsetSNMPOption(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "snmpoption": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, snmpOptionURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) GetAllSNMPOption() (models.SNMPOption, error) { + req, err := s.client.NewRequest(http.MethodGet, snmpOptionURL, nil) + if err != nil { + return models.SNMPOption{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.SNMPOption{}, err + } + + var result struct { + Options []models.SNMPOption `json:"snmpoption"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.SNMPOption{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Options) > 0 { + return result.Options[0], nil + } + + return models.SNMPOption{}, nil +} // snmptrap -func (s *SNMPService) AddSNMPTrap() {} -func (s *SNMPService) DeleteSNMPTrap() {} -func (s *SNMPService) UpdateSNMPTrap() {} -func (s *SNMPService) UnsetSNMPTrap() {} -func (s *SNMPService) GetAllSNMPTrap() {} -func (s *SNMPService) CountSNMPTrap() {} + +func (s *SNMPService) AddSNMPTrap(trap models.SNMPTrap) error { + payload := map[string]any{ + "snmptrap": trap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, snmpTrapURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) DeleteSNMPTrap(trapclass string, trapdestination string) error { + urlReq := fmt.Sprintf("%s/%s?args=trapdestination:%s", snmpTrapURL, url.QueryEscape(trapclass), url.QueryEscape(trapdestination)) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) UpdateSNMPTrap(trap models.SNMPTrap) error { + payload := map[string]any{ + "snmptrap": trap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, snmpTrapURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) UnsetSNMPTrap(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "snmptrap": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, snmpTrapURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) GetAllSNMPTrap() ([]models.SNMPTrap, error) { + req, err := s.client.NewRequest(http.MethodGet, snmpTrapURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Traps []models.SNMPTrap `json:"snmptrap"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Traps, nil +} + +func (s *SNMPService) CountSNMPTrap() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, snmpTrapURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Traps []struct { + Count float64 `json:"__count"` + } `json:"snmptrap"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Traps) > 0 { + return result.Traps[0].Count, nil + } + + return 0, nil +} // snmptrap_binding -func (s *SNMPService) GetAllSNMPTrapBinding() {} -func (s *SNMPService) GetSNMPTrapBinding() {} + +func (s *SNMPService) GetAllSNMPTrapBinding() ([]models.SNMPTrapBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, snmpTrapBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.SNMPTrapBinding `json:"snmptrap_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *SNMPService) GetSNMPTrapBinding(trapclass string) ([]models.SNMPTrapBinding, error) { + urlReq := fmt.Sprintf("%s/%s", snmpTrapBindingURL, url.QueryEscape(trapclass)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.SNMPTrapBinding `json:"snmptrap_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} // snmptrap_snmpuser_binding -func (s *SNMPService) AddSNMPTrapSNMPUserBinding() {} -func (s *SNMPService) DeleteSNMPTrapSNMPUserBinding() {} -func (s *SNMPService) GetAllSNMPTrapSNMPUserBinding() {} -func (s *SNMPService) GetSNMPTrapSNMPUserBinding() {} -func (s *SNMPService) CountSNMPTrapSNMPUserBinding() {} + +func (s *SNMPService) AddSNMPTrapSNMPUserBinding(binding models.SNMPTrapSNMPUserBinding) error { + payload := map[string]any{ + "snmptrap_snmpuser_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, snmpTrapSNMPUserBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) DeleteSNMPTrapSNMPUserBinding(trapclass string, trapdestination string) error { + urlReq := fmt.Sprintf("%s/%s?args=trapdestination:%s", snmpTrapSNMPUserBindingURL, url.QueryEscape(trapclass), url.QueryEscape(trapdestination)) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) GetAllSNMPTrapSNMPUserBinding() ([]models.SNMPTrapSNMPUserBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, snmpTrapSNMPUserBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.SNMPTrapSNMPUserBinding `json:"snmptrap_snmpuser_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *SNMPService) GetSNMPTrapSNMPUserBinding(trapclass string) ([]models.SNMPTrapSNMPUserBinding, error) { + urlReq := fmt.Sprintf("%s/%s", snmpTrapSNMPUserBindingURL, url.QueryEscape(trapclass)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.SNMPTrapSNMPUserBinding `json:"snmptrap_snmpuser_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *SNMPService) CountSNMPTrapSNMPUserBinding(trapclass string) (float64, error) { + urlReq := fmt.Sprintf("%s/%s?count=yes", snmpTrapSNMPUserBindingURL, url.QueryEscape(trapclass)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"snmptrap_snmpuser_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} // snmpuser -func (s *SNMPService) AddSNMPUser() {} -func (s *SNMPService) DeleteSNMPUser() {} -func (s *SNMPService) UpdateSNMPUser() {} -func (s *SNMPService) UnsetSNMPUser() {} -func (s *SNMPService) GetAllSNMPUser() {} -func (s *SNMPService) GetSNMPUser() {} -func (s *SNMPService) CountSNMPUser() {} + +func (s *SNMPService) AddSNMPUser(user models.SNMPUser) error { + payload := map[string]any{ + "snmpuser": user, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, snmpUserURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) DeleteSNMPUser(name string) error { + urlReq := fmt.Sprintf("%s/%s", snmpUserURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) UpdateSNMPUser(user models.SNMPUser) error { + payload := map[string]any{ + "snmpuser": user, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, snmpUserURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) UnsetSNMPUser(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "snmpuser": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, snmpUserURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) GetAllSNMPUser() ([]models.SNMPUser, error) { + req, err := s.client.NewRequest(http.MethodGet, snmpUserURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Users []models.SNMPUser `json:"snmpuser"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Users, nil +} + +func (s *SNMPService) GetSNMPUser(name string) ([]models.SNMPUser, error) { + urlReq := fmt.Sprintf("%s/%s", snmpUserURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Users []models.SNMPUser `json:"snmpuser"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Users, nil +} + +func (s *SNMPService) CountSNMPUser() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, snmpUserURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Users []struct { + Count float64 `json:"__count"` + } `json:"snmpuser"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Users) > 0 { + return result.Users[0].Count, nil + } + + return 0, nil +} // snmpview -func (s *SNMPService) AddSNMPView() {} -func (s *SNMPService) DeleteSNMPView() {} -func (s *SNMPService) UpdateSNMPView() {} -func (s *SNMPService) GetAllSNMPView() {} -func (s *SNMPService) CountSNMPView() {} + +func (s *SNMPService) AddSNMPView(view models.SNMPView) error { + payload := map[string]any{ + "snmpview": view, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, snmpViewURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) DeleteSNMPView(name string, subtree string) error { + urlReq := fmt.Sprintf("%s/%s?args=subtree:%s", snmpViewURL, url.QueryEscape(name), url.QueryEscape(subtree)) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) UpdateSNMPView(view models.SNMPView) error { + payload := map[string]any{ + "snmpview": view, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, snmpViewURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SNMPService) GetAllSNMPView() ([]models.SNMPView, error) { + req, err := s.client.NewRequest(http.MethodGet, snmpViewURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Views []models.SNMPView `json:"snmpview"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Views, nil +} + +func (s *SNMPService) CountSNMPView() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, snmpViewURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Views []struct { + Count float64 `json:"__count"` + } `json:"snmpview"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Views) > 0 { + return result.Views[0].Count, nil + } + + return 0, nil +} diff --git a/nitrogo/spillover.go b/nitrogo/spillover.go index acf7e95..97fa57f 100644 --- a/nitrogo/spillover.go +++ b/nitrogo/spillover.go @@ -1,5 +1,24 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + spilloverActionURL = "/nitro/v1/config/spilloveraction" + spilloverPolicyURL = "/nitro/v1/config/spilloverpolicy" + spilloverPolicyBindingURL = "/nitro/v1/config/spilloverpolicy_binding" + spilloverPolicyCSVServerBindingURL = "/nitro/v1/config/spilloverpolicy_csvserver_binding" + spilloverPolicyGSLBVServerBindingURL = "/nitro/v1/config/spilloverpolicy_gslbvserver_binding" + spilloverPolicyLBVServerBindingURL = "/nitro/v1/config/spilloverpolicy_lbvserver_binding" +) + // Spillover policies and actions. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/spillover/spillover type SpilloverService struct { @@ -9,48 +28,594 @@ type SpilloverService struct { // spilloveraction // Configuration for Spillover action resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/spillover/spilloveraction -func (s *SpilloverService) AddSpilloverAction() {} -func (s *SpilloverService) DeleteSpilloverAction() {} -func (s *SpilloverService) GetAllSpilloverAction() {} -func (s *SpilloverService) GetSpilloverAction() {} -func (s *SpilloverService) CountSpilloverAction() {} -func (s *SpilloverService) RenameSpilloverAction() {} + +func (s *SpilloverService) AddSpilloverAction(action models.SpilloverAction) error { + payload := map[string]any{ + "spilloveraction": action, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, spilloverActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SpilloverService) DeleteSpilloverAction(name string) error { + urlReq := fmt.Sprintf("%s/%s", spilloverActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SpilloverService) GetAllSpilloverAction() ([]models.SpilloverAction, error) { + req, err := s.client.NewRequest(http.MethodGet, spilloverActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Actions []models.SpilloverAction `json:"spilloveraction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Actions, nil +} + +func (s *SpilloverService) GetSpilloverAction(name string) ([]models.SpilloverAction, error) { + urlReq := fmt.Sprintf("%s/%s", spilloverActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Actions []models.SpilloverAction `json:"spilloveraction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Actions, nil +} + +func (s *SpilloverService) CountSpilloverAction() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, spilloverActionURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Actions []struct { + Count float64 `json:"__count"` + } `json:"spilloveraction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Actions) > 0 { + return result.Actions[0].Count, nil + } + + return 0, nil +} + +func (s *SpilloverService) RenameSpilloverAction(name string, newname string) error { + payload := map[string]any{ + "spilloveraction": map[string]string{ + "name": name, + "newname": newname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, spilloverActionURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} // spilloverpolicy // Configuration for Spillover policy resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/spillover/spilloverpolicy -func (s *SpilloverService) AddSpilloverPolicy() {} -func (s *SpilloverService) DeleteSpilloverPolicy() {} -func (s *SpilloverService) UpdateSpilloverPolicy() {} -func (s *SpilloverService) UnsetSpilloverPolicy() {} -func (s *SpilloverService) GetAllSpilloverPolicy() {} -func (s *SpilloverService) GetSpilloverPolicy() {} -func (s *SpilloverService) CountSpilloverPolicy() {} -func (s *SpilloverService) RenameSpilloverPolicy() {} + +func (s *SpilloverService) AddSpilloverPolicy(policy models.SpilloverPolicy) error { + payload := map[string]any{ + "spilloverpolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, spilloverPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SpilloverService) DeleteSpilloverPolicy(name string) error { + urlReq := fmt.Sprintf("%s/%s", spilloverPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SpilloverService) UpdateSpilloverPolicy(policy models.SpilloverPolicy) error { + payload := map[string]any{ + "spilloverpolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, spilloverPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SpilloverService) UnsetSpilloverPolicy(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "spilloverpolicy": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, spilloverPolicyURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SpilloverService) GetAllSpilloverPolicy() ([]models.SpilloverPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, spilloverPolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Policies []models.SpilloverPolicy `json:"spilloverpolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Policies, nil +} + +func (s *SpilloverService) GetSpilloverPolicy(name string) ([]models.SpilloverPolicy, error) { + urlReq := fmt.Sprintf("%s/%s", spilloverPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Policies []models.SpilloverPolicy `json:"spilloverpolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Policies, nil +} + +func (s *SpilloverService) CountSpilloverPolicy() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, spilloverPolicyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Policies []struct { + Count float64 `json:"__count"` + } `json:"spilloverpolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Policies) > 0 { + return result.Policies[0].Count, nil + } + + return 0, nil +} + +func (s *SpilloverService) RenameSpilloverPolicy(name string, newname string) error { + payload := map[string]any{ + "spilloverpolicy": map[string]string{ + "name": name, + "newname": newname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, spilloverPolicyURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} // spilloverpolicy_binding // Binding object which returns the resources bound to spilloverpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/spillover/spilloverpolicy_binding -func (s *SpilloverService) GetAllSpilloverPolicyBinding() {} -func (s *SpilloverService) GetSpilloverPolicyBinding() {} + +func (s *SpilloverService) GetAllSpilloverPolicyBinding() ([]models.SpilloverPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, spilloverPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.SpilloverPolicyBinding `json:"spilloverpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *SpilloverService) GetSpilloverPolicyBinding(name string) ([]models.SpilloverPolicyBinding, error) { + urlReq := fmt.Sprintf("%s/%s", spilloverPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.SpilloverPolicyBinding `json:"spilloverpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} // spilloverpolicy_csvserver_binding // Binding object showing the csvserver that can be bound to spilloverpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/spillover/spilloverpolicy_csvserver_binding -func (s *SpilloverService) GetAllSpilloverPolicyCSVServerBinding() {} -func (s *SpilloverService) GetSpilloverPolicyCSVServerBinding() {} -func (s *SpilloverService) CountSpilloverPolicyCSVServerBinding() {} + +func (s *SpilloverService) GetAllSpilloverPolicyCSVServerBinding() ([]models.SpilloverPolicyCSVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, spilloverPolicyCSVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.SpilloverPolicyCSVServerBinding `json:"spilloverpolicy_csvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *SpilloverService) GetSpilloverPolicyCSVServerBinding(name string) ([]models.SpilloverPolicyCSVServerBinding, error) { + urlReq := fmt.Sprintf("%s/%s", spilloverPolicyCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.SpilloverPolicyCSVServerBinding `json:"spilloverpolicy_csvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *SpilloverService) CountSpilloverPolicyCSVServerBinding(name string) (float64, error) { + urlReq := fmt.Sprintf("%s/%s?count=yes", spilloverPolicyCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"spilloverpolicy_csvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} // spilloverpolicy_gslbvserver_binding // Binding object showing the gslbvserver that can be bound to spilloverpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/spillover/spilloverpolicy_gslbvserver_binding -func (s *SpilloverService) GetAllSpilloverPolicyGSLBVServerBinding() {} -func (s *SpilloverService) GetSpilloverPolicyGSLBVServerBinding() {} -func (s *SpilloverService) CountSpilloverPolicyGSLBVServerBinding() {} + +func (s *SpilloverService) GetAllSpilloverPolicyGSLBVServerBinding() ([]models.SpilloverPolicyGSLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, spilloverPolicyGSLBVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.SpilloverPolicyGSLBVServerBinding `json:"spilloverpolicy_gslbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *SpilloverService) GetSpilloverPolicyGSLBVServerBinding(name string) ([]models.SpilloverPolicyGSLBVServerBinding, error) { + urlReq := fmt.Sprintf("%s/%s", spilloverPolicyGSLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.SpilloverPolicyGSLBVServerBinding `json:"spilloverpolicy_gslbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *SpilloverService) CountSpilloverPolicyGSLBVServerBinding(name string) (float64, error) { + urlReq := fmt.Sprintf("%s/%s?count=yes", spilloverPolicyGSLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"spilloverpolicy_gslbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} // spilloverpolicy_lbvserver_binding // Binding object showing the lbvserver that can be bound to spilloverpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/spillover/spilloverpolicy_lbvserver_binding -func (s *SpilloverService) GetAllSpilloverPolicyLBVServerBinding() {} -func (s *SpilloverService) GetSpilloverPolicyLBVServerBinding() {} -func (s *SpilloverService) CountSpilloverPolicyLBVServerBinding() {} + +func (s *SpilloverService) GetAllSpilloverPolicyLBVServerBinding() ([]models.SpilloverPolicyLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, spilloverPolicyLBVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.SpilloverPolicyLBVServerBinding `json:"spilloverpolicy_lbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *SpilloverService) GetSpilloverPolicyLBVServerBinding(name string) ([]models.SpilloverPolicyLBVServerBinding, error) { + urlReq := fmt.Sprintf("%s/%s", spilloverPolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.SpilloverPolicyLBVServerBinding `json:"spilloverpolicy_lbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *SpilloverService) CountSpilloverPolicyLBVServerBinding(name string) (float64, error) { + urlReq := fmt.Sprintf("%s/%s?count=yes", spilloverPolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"spilloverpolicy_lbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} diff --git a/nitrogo/ssl.go b/nitrogo/ssl.go index aab6180..92b7edc 100644 --- a/nitrogo/ssl.go +++ b/nitrogo/ssl.go @@ -1,5 +1,108 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + sslActionURL = "/nitro/v1/config/sslaction" + sslCACertGroupURL = "/nitro/v1/config/sslcacertgroup" + sslCACertGroupBindingURL = "/nitro/v1/config/sslcacertgroup_binding" + sslCACertGroupSSLCertKeyBindingURL = "/nitro/v1/config/sslcacertgroup_sslcertkey_binding" + sslCertURL = "/nitro/v1/config/sslcert" + sslCertBundleURL = "/nitro/v1/config/sslcertbundle" + sslCertChainURL = "/nitro/v1/config/sslcertchain" + sslCertChainBindingURL = "/nitro/v1/config/sslcertchain_binding" + sslCertChainSSLCertKeyBindingURL = "/nitro/v1/config/sslcertchain_sslcertkey_binding" + sslCertFileURL = "/nitro/v1/config/sslcertfile" + sslCertificateChainURL = "/nitro/v1/config/sslcertificatechain" + sslCertKeyURL = "/nitro/v1/config/sslcertkey" + sslCertKeyBindingURL = "/nitro/v1/config/sslcertkey_binding" + sslCertKeyCRLDistributionBindingURL = "/nitro/v1/config/sslcertkey_crldistribution_binding" + sslCertKeyServiceBindingURL = "/nitro/v1/config/sslcertkey_service_binding" + sslCertKeySSLOCSPResponderBindingURL = "/nitro/v1/config/sslcertkey_sslocspresponder_binding" + sslCertKeySSLProfileBindingURL = "/nitro/v1/config/sslcertkey_sslprofile_binding" + sslCertKeySSLVServerBindingURL = "/nitro/v1/config/sslcertkey_sslvserver_binding" + sslCertLinkURL = "/nitro/v1/config/sslcertlink" + sslCertReqURL = "/nitro/v1/config/sslcertreq" + sslCipherURL = "/nitro/v1/config/sslcipher" + sslCipherSuiteURL = "/nitro/v1/config/sslciphersuite" + sslCipherBindingURL = "/nitro/v1/config/sslcipher_binding" + sslCipherIndividualCipherBindingURL = "/nitro/v1/config/sslcipher_individualcipher_binding" + sslCipherServiceGroupBindingURL = "/nitro/v1/config/sslcipher_servicegroup_binding" + sslCipherServiceBindingURL = "/nitro/v1/config/sslcipher_service_binding" + sslCipherSSLCipherSuiteBindingURL = "/nitro/v1/config/sslcipher_sslciphersuite_binding" + sslCipherSSLProfileBindingURL = "/nitro/v1/config/sslcipher_sslprofile_binding" + sslCipherSSLVServerBindingURL = "/nitro/v1/config/sslcipher_sslvserver_binding" + sslCRLURL = "/nitro/v1/config/sslcrl" + sslCRLFileURL = "/nitro/v1/config/sslcrlfile" + sslCRLBindingURL = "/nitro/v1/config/sslcrl_binding" + sslCRLSerialNumberBindingURL = "/nitro/v1/config/sslcrl_serialnumber_binding" + sslDHFileURL = "/nitro/v1/config/ssldhfile" + sslDHParamURL = "/nitro/v1/config/ssldhparam" + sslDTLSProfileURL = "/nitro/v1/config/ssldtlsprofile" + sslECDSAKeyURL = "/nitro/v1/config/sslecdsakey" + sslFIPSURL = "/nitro/v1/config/sslfips" + sslFIPSKeyURL = "/nitro/v1/config/sslfipskey" + sslFIPSSIMSourceURL = "/nitro/v1/config/sslfipssimsource" + sslFIPSSIMTargetURL = "/nitro/v1/config/sslfipssimtarget" + sslGlobalBindingURL = "/nitro/v1/config/sslglobal_binding" + sslGlobalSSLPolicyBindingURL = "/nitro/v1/config/sslglobal_sslpolicy_binding" + sslHSMKeyURL = "/nitro/v1/config/sslhsmkey" + sslKeyFileURL = "/nitro/v1/config/sslkeyfile" + sslLogProfileURL = "/nitro/v1/config/ssllogprofile" + sslOCSPResponderURL = "/nitro/v1/config/sslocspresponder" + sslParameterURL = "/nitro/v1/config/sslparameter" + sslPKCS12URL = "/nitro/v1/config/sslpkcs12" + sslPKCS8URL = "/nitro/v1/config/sslpkcs8" + sslPolicyURL = "/nitro/v1/config/sslpolicy" + sslPolicyLabelURL = "/nitro/v1/config/sslpolicylabel" + sslPolicyLabelBindingURL = "/nitro/v1/config/sslpolicylabel_binding" + sslPolicyLabelSSLPolicyBindingURL = "/nitro/v1/config/sslpolicylabel_sslpolicy_binding" + sslPolicyBindingURL = "/nitro/v1/config/sslpolicy_binding" + sslPolicyCSVServerBindingURL = "/nitro/v1/config/sslpolicy_csvserver_binding" + sslPolicyLBVServerBindingURL = "/nitro/v1/config/sslpolicy_lbvserver_binding" + sslPolicySSLGlobalBindingURL = "/nitro/v1/config/sslpolicy_sslglobal_binding" + sslPolicySSLPolicyLabelBindingURL = "/nitro/v1/config/sslpolicy_sslpolicylabel_binding" + sslPolicySSLServiceBindingURL = "/nitro/v1/config/sslpolicy_sslservice_binding" + sslPolicySSLVServerBindingURL = "/nitro/v1/config/sslpolicy_sslvserver_binding" + sslProfileURL = "/nitro/v1/config/sslprofile" + sslProfileBindingURL = "/nitro/v1/config/sslprofile_binding" + sslProfileECCCurveBindingURL = "/nitro/v1/config/sslprofile_ecccurve_binding" + sslProfileSSLCertKeyBindingURL = "/nitro/v1/config/sslprofile_sslcertkey_binding" + sslProfileSSLCipherSuiteBindingURL = "/nitro/v1/config/sslprofile_sslciphersuite_binding" + sslProfileSSLCipherBindingURL = "/nitro/v1/config/sslprofile_sslcipher_binding" + sslProfileSSLVServerBindingURL = "/nitro/v1/config/sslprofile_sslvserver_binding" + sslRSAKeyURL = "/nitro/v1/config/sslrsakey" + sslServiceURL = "/nitro/v1/config/sslservice" + sslServiceGroupURL = "/nitro/v1/config/sslservicegroup" + sslServiceGroupBindingURL = "/nitro/v1/config/sslservicegroup_binding" + sslServiceGroupECCCurveBindingURL = "/nitro/v1/config/sslservicegroup_ecccurve_binding" + sslServiceGroupSSLCertKeyBindingURL = "/nitro/v1/config/sslservicegroup_sslcertkey_binding" + sslServiceGroupSSLCipherSuiteBindingURL = "/nitro/v1/config/sslservicegroup_sslciphersuite_binding" + sslServiceGroupSSLCipherBindingURL = "/nitro/v1/config/sslservicegroup_sslcipher_binding" + sslServiceBindingURL = "/nitro/v1/config/sslservice_binding" + sslServiceECCCurveBindingURL = "/nitro/v1/config/sslservice_ecccurve_binding" + sslServiceSSLCertKeyBindingURL = "/nitro/v1/config/sslservice_sslcertkey_binding" + sslServiceSSLCipherSuiteBindingURL = "/nitro/v1/config/sslservice_sslciphersuite_binding" + sslServiceSSLCipherBindingURL = "/nitro/v1/config/sslservice_sslcipher_binding" + sslServiceSSLPolicyBindingURL = "/nitro/v1/config/sslservice_sslpolicy_binding" + sslVServerURL = "/nitro/v1/config/sslvserver" + sslVServerBindingURL = "/nitro/v1/config/sslvserver_binding" + sslVServerECCCurveBindingURL = "/nitro/v1/config/sslvserver_ecccurve_binding" + sslVServerSSLCertKeyBindingURL = "/nitro/v1/config/sslvserver_sslcertkey_binding" + sslVServerSSLCipherSuiteBindingURL = "/nitro/v1/config/sslvserver_sslciphersuite_binding" + sslVServerSSLCipherBindingURL = "/nitro/v1/config/sslvserver_sslcipher_binding" + sslVServerSSLPolicyBindingURL = "/nitro/v1/config/sslvserver_sslpolicy_binding" + sslWrapKeyURL = "/nitro/v1/config/sslwrapkey" +) + // SSL // SSL Configuration // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/ssl/ssl @@ -8,138 +111,1605 @@ type SSLService struct { } // sslaction -func (s *SSLService) AddSSLAction() {} -func (s *SSLService) DeleteSSLAction() {} -func (s *SSLService) GetAllSSLAction() {} -func (s *SSLService) GetSSLAction() {} -func (s *SSLService) CountSSLAction() {} +func (s *SSLService) AddSSLAction(action models.SSLAction) error { + payload := map[string]any{"sslaction": action} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLAction(name string) error { + reqURL := fmt.Sprintf("%s/%s", sslActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLAction() ([]models.SSLAction, error) { + req, err := s.client.NewRequest(http.MethodGet, sslActionURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLAction `json:"sslaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLAction(name string) ([]models.SSLAction, error) { + reqURL := fmt.Sprintf("%s/%s", sslActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLAction `json:"sslaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLAction() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, sslActionURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslcacertgroup -func (s *SSLService) AddSSLCACertGroup() {} -func (s *SSLService) DeleteSSLCACertGroup() {} -func (s *SSLService) GetAllSSLCACertGroup() {} -func (s *SSLService) GetSSLCACertGroup() {} -func (s *SSLService) CountSSLCACertGroup() {} +func (s *SSLService) AddSSLCACertGroup(group models.SSLCACertGroup) error { + payload := map[string]any{"sslcacertgroup": group} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslCACertGroupURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLCACertGroup(cacertgroupname string) error { + reqURL := fmt.Sprintf("%s/%s", sslCACertGroupURL, url.QueryEscape(cacertgroupname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLCACertGroup() ([]models.SSLCACertGroup, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCACertGroupURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCACertGroup `json:"sslcacertgroup"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLCACertGroup(cacertgroupname string) ([]models.SSLCACertGroup, error) { + reqURL := fmt.Sprintf("%s/%s", sslCACertGroupURL, url.QueryEscape(cacertgroupname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCACertGroup `json:"sslcacertgroup"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLCACertGroup() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCACertGroupURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslcacertgroup"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslcacertgroup_binding -func (s *SSLService) GetAllSSLCACertGroupBinding() {} -func (s *SSLService) GetSSLCACertGroupBinding() {} +func (s *SSLService) GetAllSSLCACertGroupBinding() ([]models.SSLCACertGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCACertGroupBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCACertGroupBinding `json:"sslcacertgroup_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLCACertGroupBinding(cacertgroupname string) ([]models.SSLCACertGroupBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslCACertGroupBindingURL, url.QueryEscape(cacertgroupname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCACertGroupBinding `json:"sslcacertgroup_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} // sslcacertgroup_sslcertkey_binding -func (s *SSLService) AddSSLCACertGroupSSLCertKeyBinding() {} -func (s *SSLService) DeleteSSLCACertGroupSSLCertKeyBinding() {} -func (s *SSLService) GetAllSSLCACertGroupSSLCertKeyBinding() {} -func (s *SSLService) GetSSLCACertGroupSSLCertKeyBinding() {} -func (s *SSLService) CountSSLCACertGroupSSLCertKeyBinding() {} +func (s *SSLService) AddSSLCACertGroupSSLCertKeyBinding(binding models.SSLCACertGroupSSLCertKeyBinding) error { + payload := map[string]any{"sslcacertgroup_sslcertkey_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslCACertGroupSSLCertKeyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLCACertGroupSSLCertKeyBinding(cacertgroupname string, certkeyname string) error { + reqURL := fmt.Sprintf("%s/%s?args=certkeyname:%s", sslCACertGroupSSLCertKeyBindingURL, url.QueryEscape(cacertgroupname), url.QueryEscape(certkeyname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLCACertGroupSSLCertKeyBinding() ([]models.SSLCACertGroupSSLCertKeyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCACertGroupSSLCertKeyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCACertGroupSSLCertKeyBinding `json:"sslcacertgroup_sslcertkey_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLCACertGroupSSLCertKeyBinding(cacertgroupname string) ([]models.SSLCACertGroupSSLCertKeyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslCACertGroupSSLCertKeyBindingURL, url.QueryEscape(cacertgroupname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCACertGroupSSLCertKeyBinding `json:"sslcacertgroup_sslcertkey_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLCACertGroupSSLCertKeyBinding(cacertgroupname string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslCACertGroupSSLCertKeyBindingURL, url.QueryEscape(cacertgroupname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslcacertgroup_sslcertkey_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslcert -func (s *SSLService) CreateSSLCert() {} +func (s *SSLService) CreateSSLCert(cert models.SSLCert) error { + payload := map[string]any{"sslcert": cert} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslCertURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} // sslcertbundle -func (s *SSLService) ImportSSLCertBundle() {} -func (s *SSLService) DeleteSSLCertBundle() {} -func (s *SSLService) ApplySSLCertBundle() {} -func (s *SSLService) ExportSSLCertBundle() {} -func (s *SSLService) GetAllSSLCertBundle() {} -func (s *SSLService) CountSSLCertBundle() {} +func (s *SSLService) ImportSSLCertBundle(bundle models.SSLCertBundle) error { + payload := map[string]any{"sslcertbundle": bundle} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslCertBundleURL+"?action=import", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLCertBundle(name string) error { + reqURL := fmt.Sprintf("%s/%s", sslCertBundleURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) ApplySSLCertBundle() error { + req, err := s.client.NewRequest(http.MethodPost, sslCertBundleURL+"?action=apply", nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) ExportSSLCertBundle(bundle models.SSLCertBundle) error { + payload := map[string]any{"sslcertbundle": bundle} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslCertBundleURL+"?action=export", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLCertBundle() ([]models.SSLCertBundle, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCertBundleURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCertBundle `json:"sslcertbundle"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLCertBundle() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCertBundleURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslcertbundle"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslcertchain -func (s *SSLService) GetAllSSLCertChain() {} -func (s *SSLService) GetSSLCertChain() {} -func (s *SSLService) CountSSLCertChain() {} +func (s *SSLService) GetAllSSLCertChain() ([]models.SSLCertChain, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCertChainURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCertChain `json:"sslcertchain"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLCertChain(certkeyname string) ([]models.SSLCertChain, error) { + reqURL := fmt.Sprintf("%s/%s", sslCertChainURL, url.QueryEscape(certkeyname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCertChain `json:"sslcertchain"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLCertChain() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCertChainURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslcertchain"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslcertchain_binding -func (s *SSLService) GetSSLCertChainBinding() {} +func (s *SSLService) GetSSLCertChainBinding(certkeyname string) ([]models.SSLCertChainBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslCertChainBindingURL, url.QueryEscape(certkeyname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCertChainBinding `json:"sslcertchain_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} // sslcertchain_sslcertkey_binding -func (s *SSLService) GetSSLCertChainSSLCertKeyBinding() {} -func (s *SSLService) CountSSLCertChainSSLCertKeyBinding() {} +func (s *SSLService) GetSSLCertChainSSLCertKeyBinding(certkeyname string) ([]models.SSLCertChainSSLCertKeyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslCertChainSSLCertKeyBindingURL, url.QueryEscape(certkeyname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCertChainSSLCertKeyBinding `json:"sslcertchain_sslcertkey_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLCertChainSSLCertKeyBinding(certkeyname string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslCertChainSSLCertKeyBindingURL, url.QueryEscape(certkeyname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslcertchain_sslcertkey_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslcertfile -func (s *SSLService) ImportSSLCertFile() {} -func (s *SSLService) DeleteSSLCertFile() {} -func (s *SSLService) GetAllSSLCertFile() {} -func (s *SSLService) CountSSLCertFile() {} +func (s *SSLService) ImportSSLCertFile(file models.SSLCertFile) error { + payload := map[string]any{"sslcertfile": file} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslCertFileURL+"?action=import", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLCertFile(name string) error { + reqURL := fmt.Sprintf("%s/%s", sslCertFileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLCertFile() ([]models.SSLCertFile, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCertFileURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCertFile `json:"sslcertfile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLCertFile() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCertFileURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslcertfile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslcertificatechain -func (s *SSLService) AddSSLCertificateChain() {} -func (s *SSLService) GetAllSSLCertificateChain() {} -func (s *SSLService) GetSSLCertificateChain() {} -func (s *SSLService) CountSSLCertificateChain() {} +func (s *SSLService) AddSSLCertificateChain(chain models.SSLCertificateChain) error { + payload := map[string]any{"sslcertificatechain": chain} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslCertificateChainURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLCertificateChain() ([]models.SSLCertificateChain, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCertificateChainURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCertificateChain `json:"sslcertificatechain"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLCertificateChain(certkeyname string) ([]models.SSLCertificateChain, error) { + reqURL := fmt.Sprintf("%s/%s", sslCertificateChainURL, url.QueryEscape(certkeyname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCertificateChain `json:"sslcertificatechain"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLCertificateChain() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCertificateChainURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslcertificatechain"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslcertkey -func (s *SSLService) AddSSLCertKey() {} -func (s *SSLService) DeleteSSLCertKey() {} -func (s *SSLService) UpdateSSLCertKey() {} -func (s *SSLService) UnsetSSLCertKey() {} -func (s *SSLService) LinkSSLCertKey() {} -func (s *SSLService) UnlinkSSLCertKey() {} -func (s *SSLService) ChangeSSLCertKey() {} -func (s *SSLService) ClearSSLCertKey() {} -func (s *SSLService) GetAllSSLCertKey() {} -func (s *SSLService) GetSSLCertKey() {} -func (s *SSLService) CountSSLCertKey() {} +func (s *SSLService) AddSSLCertKey(certkey models.SSLCertKey) error { + payload := map[string]any{"sslcertkey": certkey} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslCertKeyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLCertKey(certkey string) error { + reqURL := fmt.Sprintf("%s/%s", sslCertKeyURL, url.QueryEscape(certkey)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) UpdateSSLCertKey(certkey models.SSLCertKey) error { + payload := map[string]any{"sslcertkey": certkey} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslCertKeyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) UnsetSSLCertKey(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"sslcertkey": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslCertKeyURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) LinkSSLCertKey(certkey models.SSLCertKey) error { + payload := map[string]any{"sslcertkey": certkey} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslCertKeyURL+"?action=link", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) UnlinkSSLCertKey(certkey models.SSLCertKey) error { + payload := map[string]any{"sslcertkey": certkey} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslCertKeyURL+"?action=unlink", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) ChangeSSLCertKey(certkey models.SSLCertKey) error { + payload := map[string]any{"sslcertkey": certkey} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslCertKeyURL+"?action=change", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) ClearSSLCertKey(certkey models.SSLCertKey) error { + payload := map[string]any{"sslcertkey": certkey} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslCertKeyURL+"?action=clear", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLCertKey() ([]models.SSLCertKey, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCertKeyURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCertKey `json:"sslcertkey"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLCertKey(certkey string) ([]models.SSLCertKey, error) { + reqURL := fmt.Sprintf("%s/%s", sslCertKeyURL, url.QueryEscape(certkey)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCertKey `json:"sslcertkey"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLCertKey() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCertKeyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslcertkey"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslcertkey_binding -func (s *SSLService) GetAllSSLCertKeyBinding() {} -func (s *SSLService) GetSSLCertKeyBinding() {} +func (s *SSLService) GetAllSSLCertKeyBinding() ([]models.SSLCertKeyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCertKeyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCertKeyBinding `json:"sslcertkey_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLCertKeyBinding(certkey string) ([]models.SSLCertKeyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslCertKeyBindingURL, url.QueryEscape(certkey)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCertKeyBinding `json:"sslcertkey_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} // sslcertkey_crldistribution_binding -func (s *SSLService) GetAllSSLCertKeyCRLDistributionBinding() {} -func (s *SSLService) GetSSLCertKeyCRLDistributionBinding() {} -func (s *SSLService) CountSSLCertKeyCRLDistributionBinding() {} +func (s *SSLService) GetAllSSLCertKeyCRLDistributionBinding() ([]models.SSLCertKeyCRLDistributionBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCertKeyCRLDistributionBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCertKeyCRLDistributionBinding `json:"sslcertkey_crldistribution_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLCertKeyCRLDistributionBinding(certkey string) ([]models.SSLCertKeyCRLDistributionBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslCertKeyCRLDistributionBindingURL, url.QueryEscape(certkey)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCertKeyCRLDistributionBinding `json:"sslcertkey_crldistribution_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLCertKeyCRLDistributionBinding(certkey string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslCertKeyCRLDistributionBindingURL, url.QueryEscape(certkey)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslcertkey_crldistribution_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslcertkey_service_binding -func (s *SSLService) GetAllSSLCertKeyServiceBinding() {} -func (s *SSLService) GetSSLCertKeyServiceBinding() {} -func (s *SSLService) CountSSLCertKeyServiceBinding() {} +func (s *SSLService) GetAllSSLCertKeyServiceBinding() ([]models.SSLCertKeyServiceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCertKeyServiceBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCertKeyServiceBinding `json:"sslcertkey_service_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLCertKeyServiceBinding(certkey string) ([]models.SSLCertKeyServiceBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslCertKeyServiceBindingURL, url.QueryEscape(certkey)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCertKeyServiceBinding `json:"sslcertkey_service_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLCertKeyServiceBinding(certkey string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslCertKeyServiceBindingURL, url.QueryEscape(certkey)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslcertkey_service_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslcertkey_sslocspresponder_binding -func (s *SSLService) AddSSLCertKeySSLOCSPResponderBinding() {} -func (s *SSLService) DeleteSSLCertKeySSLOCSPResponderBinding() {} -func (s *SSLService) GetAllSSLCertKeySSLOCSPResponderBinding() {} -func (s *SSLService) GetSSLCertKeySSLOCSPResponderBinding() {} -func (s *SSLService) CountSSLCertKeySSLOCSPResponderBinding() {} +func (s *SSLService) AddSSLCertKeySSLOCSPResponderBinding(binding models.SSLCertKeySSLOCSPResponderBinding) error { + payload := map[string]any{"sslcertkey_sslocspresponder_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslCertKeySSLOCSPResponderBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLCertKeySSLOCSPResponderBinding(certkey string, ocspresponder string) error { + reqURL := fmt.Sprintf("%s/%s?args=ocspresponder:%s", sslCertKeySSLOCSPResponderBindingURL, url.QueryEscape(certkey), url.QueryEscape(ocspresponder)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLCertKeySSLOCSPResponderBinding() ([]models.SSLCertKeySSLOCSPResponderBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCertKeySSLOCSPResponderBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCertKeySSLOCSPResponderBinding `json:"sslcertkey_sslocspresponder_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLCertKeySSLOCSPResponderBinding(certkey string) ([]models.SSLCertKeySSLOCSPResponderBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslCertKeySSLOCSPResponderBindingURL, url.QueryEscape(certkey)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCertKeySSLOCSPResponderBinding `json:"sslcertkey_sslocspresponder_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLCertKeySSLOCSPResponderBinding(certkey string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslCertKeySSLOCSPResponderBindingURL, url.QueryEscape(certkey)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslcertkey_sslocspresponder_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslcertkey_sslprofile_binding -func (s *SSLService) GetAllSSLCertKeySSLProfileBinding() {} -func (s *SSLService) GetSSLCertKeySSLProfileBinding() {} -func (s *SSLService) CountSSLCertKeySSLProfileBinding() {} +func (s *SSLService) GetAllSSLCertKeySSLProfileBinding() ([]models.SSLCertKeySSLProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCertKeySSLProfileBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCertKeySSLProfileBinding `json:"sslcertkey_sslprofile_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLCertKeySSLProfileBinding(certkey string) ([]models.SSLCertKeySSLProfileBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslCertKeySSLProfileBindingURL, url.QueryEscape(certkey)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCertKeySSLProfileBinding `json:"sslcertkey_sslprofile_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLCertKeySSLProfileBinding(certkey string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslCertKeySSLProfileBindingURL, url.QueryEscape(certkey)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslcertkey_sslprofile_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslcertkey_sslvserver_binding -func (s *SSLService) GetAllSSLCertKeySSLVServerBinding() {} -func (s *SSLService) GetSSLCertKeySSLVServerBinding() {} -func (s *SSLService) CountSSLCertKeySSLVServerBinding() {} +func (s *SSLService) GetAllSSLCertKeySSLVServerBinding() ([]models.SSLCertKeySSLVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCertKeySSLVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCertKeySSLVServerBinding `json:"sslcertkey_sslvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLCertKeySSLVServerBinding(certkey string) ([]models.SSLCertKeySSLVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslCertKeySSLVServerBindingURL, url.QueryEscape(certkey)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCertKeySSLVServerBinding `json:"sslcertkey_sslvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLCertKeySSLVServerBinding(certkey string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslCertKeySSLVServerBindingURL, url.QueryEscape(certkey)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslcertkey_sslvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslcertlink -func (s *SSLService) GetAllSSLCertLink() {} -func (s *SSLService) CountSSLCertLink() {} +func (s *SSLService) GetAllSSLCertLink() ([]models.SSLCertLink, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCertLinkURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCertLink `json:"sslcertlink"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLCertLink() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCertLinkURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslcertlink"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslcertreq -func (s *SSLService) CreateSSLCertReq() {} +func (s *SSLService) CreateSSLCertReq(certreq models.SSLCertReq) error { + payload := map[string]any{"sslcertreq": certreq} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslCertReqURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} // sslcipher -func (s *SSLService) AddSSLCipher() {} -func (s *SSLService) DeleteSSLCipher() {} -func (s *SSLService) UpdateSSLCipher() {} -func (s *SSLService) UnsetSSLCipher() {} -func (s *SSLService) GetAllSSLCipher() {} -func (s *SSLService) GetSSLCipher() {} -func (s *SSLService) CountSSLCipher() {} +func (s *SSLService) AddSSLCipher(cipher models.SSLCipher) error { + payload := map[string]any{"sslcipher": cipher} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslCipherURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLCipher(ciphergroupname string) error { + reqURL := fmt.Sprintf("%s/%s", sslCipherURL, url.QueryEscape(ciphergroupname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) UpdateSSLCipher(cipher models.SSLCipher) error { + payload := map[string]any{"sslcipher": cipher} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslCipherURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) UnsetSSLCipher(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"sslcipher": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslCipherURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLCipher() ([]models.SSLCipher, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCipherURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCipher `json:"sslcipher"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLCipher(ciphergroupname string) ([]models.SSLCipher, error) { + reqURL := fmt.Sprintf("%s/%s", sslCipherURL, url.QueryEscape(ciphergroupname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCipher `json:"sslcipher"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLCipher() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCipherURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslcipher"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslciphersuite -func (s *SSLService) GetAllSSLCipherSuite() {} -func (s *SSLService) GetSSLCipherSuite() {} -func (s *SSLService) CountSSLCipherSuite() {} +func (s *SSLService) GetAllSSLCipherSuite() ([]models.SSLCipherSuite, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCipherSuiteURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCipherSuite `json:"sslciphersuite"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLCipherSuite(ciphername string) ([]models.SSLCipherSuite, error) { + reqURL := fmt.Sprintf("%s/%s", sslCipherSuiteURL, url.QueryEscape(ciphername)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCipherSuite `json:"sslciphersuite"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLCipherSuite() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCipherSuiteURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslciphersuite"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslcipher_binding -func (s *SSLService) GetAllSSLCipherBinding() {} -func (s *SSLService) GetSSLCipherBinding() {} +func (s *SSLService) GetAllSSLCipherBinding() ([]models.SSLCipherBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCipherBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCipherBinding `json:"sslcipher_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLCipherBinding(ciphergroupname string) ([]models.SSLCipherBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslCipherBindingURL, url.QueryEscape(ciphergroupname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCipherBinding `json:"sslcipher_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} // sslcipher_individualcipher_binding -func (s *SSLService) GetAllSSLCipherIndividualCipherBinding() {} -func (s *SSLService) GetSSLCipherIndividualCipherBinding() {} -func (s *SSLService) CountSSLCipherIndividualCipherBinding() {} +func (s *SSLService) GetAllSSLCipherIndividualCipherBinding() ([]models.SSLCipherIndividualCipherBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCipherIndividualCipherBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCipherIndividualCipherBinding `json:"sslcipher_individualcipher_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLCipherIndividualCipherBinding(ciphergroupname string) ([]models.SSLCipherIndividualCipherBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslCipherIndividualCipherBindingURL, url.QueryEscape(ciphergroupname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCipherIndividualCipherBinding `json:"sslcipher_individualcipher_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLCipherIndividualCipherBinding(ciphergroupname string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslCipherIndividualCipherBindingURL, url.QueryEscape(ciphergroupname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslcipher_individualcipher_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslcipher_servicegroup_binding // This object has no operations documented. These are guesses and need to be tested before they will be uncommented. @@ -154,16 +1724,158 @@ func (s *SSLService) CountSSLCipherIndividualCipherBinding() {} // func (s *SSLService) CountSSLCipherServiceBinding() {} // sslcipher_sslciphersuite_binding -func (s *SSLService) AddSSLCipherSSLCipherSuiteBinding() {} -func (s *SSLService) DeleteSSLCipherSSLCipherSuiteBinding() {} -func (s *SSLService) GetAllSSLCipherSSLCipherSuiteBinding() {} -func (s *SSLService) GetSSLCipherSSLCipherSuiteBinding() {} -func (s *SSLService) CountSSLCipherSSLCipherSuiteBinding() {} +func (s *SSLService) AddSSLCipherSSLCipherSuiteBinding(binding models.SSLCipherSSLCipherSuiteBinding) error { + payload := map[string]any{"sslcipher_sslciphersuite_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslCipherSSLCipherSuiteBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLCipherSSLCipherSuiteBinding(ciphergroupname string, ciphername string) error { + reqURL := fmt.Sprintf("%s/%s?args=ciphername:%s", sslCipherSSLCipherSuiteBindingURL, url.QueryEscape(ciphergroupname), url.QueryEscape(ciphername)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLCipherSSLCipherSuiteBinding() ([]models.SSLCipherSSLCipherSuiteBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCipherSSLCipherSuiteBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCipherSSLCipherSuiteBinding `json:"sslcipher_sslciphersuite_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLCipherSSLCipherSuiteBinding(ciphergroupname string) ([]models.SSLCipherSSLCipherSuiteBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslCipherSSLCipherSuiteBindingURL, url.QueryEscape(ciphergroupname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCipherSSLCipherSuiteBinding `json:"sslcipher_sslciphersuite_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLCipherSSLCipherSuiteBinding(ciphergroupname string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslCipherSSLCipherSuiteBindingURL, url.QueryEscape(ciphergroupname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslcipher_sslciphersuite_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslcipher_sslprofile_binding -func (s *SSLService) GetAllSSLCipherSSLProfileBinding() {} -func (s *SSLService) GetSSLCipherSSLProfileBinding() {} -func (s *SSLService) CountSSLCipherSSLProfileBinding() {} +func (s *SSLService) GetAllSSLCipherSSLProfileBinding() ([]models.SSLCipherSSLProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCipherSSLProfileBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCipherSSLProfileBinding `json:"sslcipher_sslprofile_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLCipherSSLProfileBinding(ciphergroupname string) ([]models.SSLCipherSSLProfileBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslCipherSSLProfileBindingURL, url.QueryEscape(ciphergroupname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCipherSSLProfileBinding `json:"sslcipher_sslprofile_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLCipherSSLProfileBinding(ciphergroupname string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslCipherSSLProfileBindingURL, url.QueryEscape(ciphergroupname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslcipher_sslprofile_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslcipher_sslvserver_binding // This object has no operations documented. These are guesses and need to be tested before they will be uncommented. @@ -172,369 +1884,4437 @@ func (s *SSLService) CountSSLCipherSSLProfileBinding() {} // func (s *SSLService) CountSSLCipherSSLVServerBinding() {} // sslcrl -func (s *SSLService) AddSSLCRL() {} -func (s *SSLService) DeleteSSLCRL() {} -func (s *SSLService) UpdateSSLCRL() {} -func (s *SSLService) UnsetSSLCRL() {} -func (s *SSLService) CreateSSLCRL() {} -func (s *SSLService) GetAllSSLCRL() {} -func (s *SSLService) GetSSLCRL() {} -func (s *SSLService) CountSSLCRL() {} +func (s *SSLService) AddSSLCRL(crl models.SSLCRL) error { + payload := map[string]any{"sslcrl": crl} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslCRLURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} -// sslcrlfile -func (s *SSLService) ImportSSLCRLFile() {} -func (s *SSLService) DeleteSSLCRLFile() {} -func (s *SSLService) GetAllSSLCRLFile() {} -func (s *SSLService) CountSSLCRLFile() {} +func (s *SSLService) DeleteSSLCRL(crlname string) error { + reqURL := fmt.Sprintf("%s/%s", sslCRLURL, url.QueryEscape(crlname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} -// sslcrl_binding -func (s *SSLService) GetAllSSLCRLBinding() {} -func (s *SSLService) GetSSLCRLBinding() {} +func (s *SSLService) UpdateSSLCRL(crl models.SSLCRL) error { + payload := map[string]any{"sslcrl": crl} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslCRLURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} -// sslcrl_serialnumber_binding -func (s *SSLService) GetAllSSLCRLSerialNumberBinding() {} -func (s *SSLService) GetSSLCRLSerialNumberBinding() {} -func (s *SSLService) CountSSLCRLSerialNumberBinding() {} +func (s *SSLService) UnsetSSLCRL(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"sslcrl": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslCRLURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} -// ssldhfile -func (s *SSLService) ImportSSLDHFile() {} -func (s *SSLService) DeleteSSLDHFile() {} -func (s *SSLService) GetAllSSLDHFile() {} -func (s *SSLService) CountSSLDHFile() {} +func (s *SSLService) CreateSSLCRL(crl models.SSLCRL) error { + payload := map[string]any{"sslcrl": crl} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslCRLURL+"?action=create", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} -// ssldhparam -func (s *SSLService) ParamSSLDHParam() {} +func (s *SSLService) GetAllSSLCRL() ([]models.SSLCRL, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCRLURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCRL `json:"sslcrl"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} -// ssldtlsprofile -func (s *SSLService) AddSSLDTLSProfile() {} -func (s *SSLService) DeleteSSLDTLSProfile() {} -func (s *SSLService) UpdateSSLDTLSProfile() {} -func (s *SSLService) UnsetSSLDTLSProfile() {} -func (s *SSLService) GetAllSSLDTLSProfile() {} -func (s *SSLService) GetSSLDTLSProfile() {} -func (s *SSLService) CountSSLDTLSProfile() {} +func (s *SSLService) GetSSLCRL(crlname string) ([]models.SSLCRL, error) { + reqURL := fmt.Sprintf("%s/%s", sslCRLURL, url.QueryEscape(crlname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCRL `json:"sslcrl"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} -// sslecdsakey -func (s *SSLService) CreateSSLECDSAKey() {} +func (s *SSLService) CountSSLCRL() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCRLURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslcrl"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} -// sslfips -func (s *SSLService) UpdateSSLFIPs() {} -func (s *SSLService) UnsetSSLFIPs() {} -func (s *SSLService) ChangeSSLFIPs() {} -func (s *SSLService) ResetSSLFIPs() {} -func (s *SSLService) GetAllSSLFIPs() {} +// sslcrlfile +func (s *SSLService) ImportSSLCRLFile(file models.SSLCRLFile) error { + payload := map[string]any{"sslcrlfile": file} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslCRLFileURL+"?action=import", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} -// sslfipskey -func (s *SSLService) CreateSSLFIPsKey() {} -func (s *SSLService) DeleteSSLFIPsKey() {} -func (s *SSLService) ImportSSLFIPsKey() {} -func (s *SSLService) ExportSSLFIPsKey() {} -func (s *SSLService) GetAllSSLFIPsKey() {} -func (s *SSLService) GetSSLFIPsKey() {} -func (s *SSLService) CountSSLFIPsKey() {} +func (s *SSLService) DeleteSSLCRLFile(name string) error { + reqURL := fmt.Sprintf("%s/%s", sslCRLFileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} -// sslfipssimsource -func (s *SSLService) EnableSSLFIPsSIMSource() {} -func (s *SSLService) InitSSLFIPsSIMSource() {} +func (s *SSLService) GetAllSSLCRLFile() ([]models.SSLCRLFile, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCRLFileURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCRLFile `json:"sslcrlfile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} -// sslfipssimtarget -func (s *SSLService) EnableSSLFIPsSIMTarget() {} -func (s *SSLService) InitSSLFIPsSIMTarget() {} +func (s *SSLService) CountSSLCRLFile() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCRLFileURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslcrlfile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} -// sslglobal_binding -func (s *SSLService) GetSSLGLobalBinding() {} +// sslcrl_binding +func (s *SSLService) GetAllSSLCRLBinding() ([]models.SSLCRLBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCRLBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCRLBinding `json:"sslcrl_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} -// sslglobal_sslpolicy_binding -func (s *SSLService) AddSSLGlobalSSLPolicyBinding() {} -func (s *SSLService) DeleteSSLGlobalSSLPolicyBinding() {} -func (s *SSLService) GetSSLGlobalSSLPolicyBinding() {} -func (s *SSLService) CountSSLGlobalSSLPolicyBinding() {} +func (s *SSLService) GetSSLCRLBinding(crlname string) ([]models.SSLCRLBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslCRLBindingURL, url.QueryEscape(crlname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCRLBinding `json:"sslcrl_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} -// sslhsmkey -func (s *SSLService) AddSSLHSMKey() {} -func (s *SSLService) DeleteSSLHSMKey() {} -func (s *SSLService) GetAllSSLHSMKey() {} -func (s *SSLService) GetSSLHSMKey() {} -func (s *SSLService) CountSSLHSMKey() {} +// sslcrl_serialnumber_binding +func (s *SSLService) GetAllSSLCRLSerialNumberBinding() ([]models.SSLCRLSerialNumberBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslCRLSerialNumberBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCRLSerialNumberBinding `json:"sslcrl_serialnumber_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} -// sslkeyfile -func (s *SSLService) ImportSSLKeyFile() {} -func (s *SSLService) DeleteSSLKeyFile() {} -func (s *SSLService) GetAllSSLKeyFile() {} -func (s *SSLService) CountSSLKeyFile() {} +func (s *SSLService) GetSSLCRLSerialNumberBinding(crlname string) ([]models.SSLCRLSerialNumberBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslCRLSerialNumberBindingURL, url.QueryEscape(crlname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLCRLSerialNumberBinding `json:"sslcrl_serialnumber_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} -// ssllogprofile -func (s *SSLService) AddSSLLogProfile() {} -func (s *SSLService) DeleteSSLLogProfile() {} -func (s *SSLService) UpdateSSLLogProfile() {} -func (s *SSLService) UnsetSSLLogProfile() {} -func (s *SSLService) GetAllSSLLogProfile() {} -func (s *SSLService) GetSSLLogProfile() {} -func (s *SSLService) CountSSLLogProfile() {} +func (s *SSLService) CountSSLCRLSerialNumberBinding(crlname string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslCRLSerialNumberBindingURL, url.QueryEscape(crlname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslcrl_serialnumber_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} -// sslocspresponder -func (s *SSLService) AddSSLOCSPResponder() {} -func (s *SSLService) DeleteSSLOCSPResponder() {} -func (s *SSLService) UpdateSSLOCSPResponder() {} -func (s *SSLService) UnsetSSLOCSPResponder() {} -func (s *SSLService) GetAllSSLOCSPResponder() {} -func (s *SSLService) GetSSLOCSPResponder() {} -func (s *SSLService) CountSSLOCSPResponder() {} +// ssldhfile +func (s *SSLService) ImportSSLDHFile(file models.SSLDHFile) error { + payload := map[string]any{"ssldhfile": file} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslDHFileURL+"?action=import", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} -// sslparameter -func (s *SSLService) UpdateSSLParameter() {} -func (s *SSLService) UnsetSSLParameter() {} -func (s *SSLService) GetAllSSLParameter() {} +func (s *SSLService) DeleteSSLDHFile(name string) error { + reqURL := fmt.Sprintf("%s/%s", sslDHFileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} -// sslpkcs12 -func (s *SSLService) ConvertSSLPKCS12() {} +func (s *SSLService) GetAllSSLDHFile() ([]models.SSLDHFile, error) { + req, err := s.client.NewRequest(http.MethodGet, sslDHFileURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLDHFile `json:"ssldhfile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} -// sslpkcs8 -func (s *SSLService) ConvertSSLPKCS8() {} +func (s *SSLService) CountSSLDHFile() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, sslDHFileURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"ssldhfile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} -// sslpolicy -func (s *SSLService) AddSSLPolicy() {} -func (s *SSLService) DeleteSSLPolicy() {} -func (s *SSLService) UpdateSSLPolicy() {} -func (s *SSLService) UnsetSSLPolicy() {} -func (s *SSLService) GetAllSSLPolicy() {} -func (s *SSLService) GetSSLPolicy() {} -func (s *SSLService) CountSSLPolicy() {} +// ssldhparam +func (s *SSLService) ParamSSLDHParam(param models.SSLDHParam) error { + payload := map[string]any{"ssldhparam": param} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslDHParamURL+"?action=param", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} -// sslpolicylabel -func (s *SSLService) AddSSLPolicyLabel() {} -func (s *SSLService) DeleteSSLPolicyLabel() {} -func (s *SSLService) GetAllSSLPolicyLabel() {} -func (s *SSLService) GetSSLPolicyLabel() {} -func (s *SSLService) CountSSLPolicyLabel() {} +// ssldtlsprofile +func (s *SSLService) AddSSLDTLSProfile(profile models.SSLDTLSProfile) error { + payload := map[string]any{"ssldtlsprofile": profile} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslDTLSProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} -// sslpolicylabel_binding -func (s *SSLService) GetAllSSLPolicyLabelBinding() {} -func (s *SSLService) GetSSLPolicyLabelBinding() {} +func (s *SSLService) DeleteSSLDTLSProfile(name string) error { + reqURL := fmt.Sprintf("%s/%s", sslDTLSProfileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} -// sslpolicylabel_sslpolicy_binding -func (s *SSLService) AddSSLpolicyLabelSSLPolicyBinding() {} -func (s *SSLService) DeleteSSLpolicyLabelSSLPolicyBinding() {} -func (s *SSLService) GetAllSSLpolicyLabelSSLPolicyBinding() {} -func (s *SSLService) GetSSLpolicyLabelSSLPolicyBinding() {} -func (s *SSLService) CountSSLpolicyLabelSSLPolicyBinding() {} +func (s *SSLService) UpdateSSLDTLSProfile(profile models.SSLDTLSProfile) error { + payload := map[string]any{"ssldtlsprofile": profile} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslDTLSProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} -// sslpolicy_binding -func (s *SSLService) GetAllSSLPolicyBinding() {} -func (s *SSLService) GetSSLPolicyBinding() {} +func (s *SSLService) UnsetSSLDTLSProfile(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"ssldtlsprofile": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslDTLSProfileURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} -// sslpolicy_csvserver_binding -func (s *SSLService) GetAllSSLPolicyCSVServerBinding() {} -func (s *SSLService) GetSSLPolicyCSVServerBinding() {} -func (s *SSLService) CountSSLPolicyCSVServerBinding() {} +func (s *SSLService) GetAllSSLDTLSProfile() ([]models.SSLDTLSProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, sslDTLSProfileURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLDTLSProfile `json:"ssldtlsprofile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} -// sslpolicy_lbvserver_binding -func (s *SSLService) GetAllSSLPolicyLBVServerBinding() {} -func (s *SSLService) GetSSLPolicyLBVServerBinding() {} -func (s *SSLService) CountSSLPolicyLBVServerBinding() {} +func (s *SSLService) GetSSLDTLSProfile(name string) ([]models.SSLDTLSProfile, error) { + reqURL := fmt.Sprintf("%s/%s", sslDTLSProfileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLDTLSProfile `json:"ssldtlsprofile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} -// sslpolicy_sslglobal_binding -func (s *SSLService) GetAllSSLPolicySSLGlobalBinding() {} -func (s *SSLService) GetSSLPolicySSLGlobalBinding() {} -func (s *SSLService) CountSSLPolicySSLGlobalBinding() {} +func (s *SSLService) CountSSLDTLSProfile() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, sslDTLSProfileURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"ssldtlsprofile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} -// sslpolicy_sslpolicylabel_binding -func (s *SSLService) GetAllSSLPolicySSLPolicyLabelBinding() {} -func (s *SSLService) GetSSLPolicySSLPolicyLabelBinding() {} -func (s *SSLService) CountSSLPolicySSLPolicyLabelBinding() {} +// sslecdsakey +func (s *SSLService) CreateSSLECDSAKey(key models.SSLECDSAKey) error { + payload := map[string]any{"sslecdsakey": key} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslECDSAKeyURL+"?action=create", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} -// sslpolicy_sslservice_binding -func (s *SSLService) GetAllSSLPolicySSLServiceBinding() {} -func (s *SSLService) GetSSLPolicySSLServiceBinding() {} -func (s *SSLService) CountSSLPolicySSLServiceBinding() {} +// sslfips +func (s *SSLService) UpdateSSLFIPS(fips models.SSLFIPS) error { + payload := map[string]any{"sslfips": fips} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslFIPSURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} -// sslpolicy_sslvserver_binding -func (s *SSLService) GetAllSSLPolicySSLVServerBinding() {} -func (s *SSLService) GetSSLPolicySSLVServerBinding() {} -func (s *SSLService) CountSSLPolicySSLVServerBinding() {} +func (s *SSLService) UnsetSSLFIPS(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"sslfips": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslFIPSURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} -// sslprofile -func (s *SSLService) AddSSLProfile() {} -func (s *SSLService) DeleteSSLProfile() {} -func (s *SSLService) UpdateSSLProfile() {} -func (s *SSLService) UnsetSSLProfile() {} -func (s *SSLService) GetAllSSLProfile() {} -func (s *SSLService) GetSSLProfile() {} -func (s *SSLService) CountSSLProfile() {} +func (s *SSLService) ChangeSSLFIPS(fips models.SSLFIPS) error { + payload := map[string]any{"sslfips": fips} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslFIPSURL+"?action=change", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} -// sslprofile_binding -func (s *SSLService) GetAllSSLProfileBinding() {} -func (s *SSLService) GetSSLProfileBinding() {} +func (s *SSLService) ResetSSLFIPS(fips models.SSLFIPS) error { + payload := map[string]any{"sslfips": fips} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslFIPSURL+"?action=reset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} -// sslprofile_eccurve_binding -func (s *SSLService) AddSSLProfileECCCurveBinding() {} -func (s *SSLService) DeleteSSLProfileECCCurveBinding() {} -func (s *SSLService) GetAllSSLProfileECCCurveBinding() {} -func (s *SSLService) GetSSLProfileECCCurveBinding() {} -func (s *SSLService) CountSSLProfileECCCurveBinding() {} +func (s *SSLService) GetAllSSLFIPS() (models.SSLFIPS, error) { + req, err := s.client.NewRequest(http.MethodGet, sslFIPSURL, nil) + if err != nil { + return models.SSLFIPS{}, err + } + resp, err := s.client.Do(req) + if err != nil { + return models.SSLFIPS{}, err + } + var result struct { + Items []models.SSLFIPS `json:"sslfips"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return models.SSLFIPS{}, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0], nil + } + return models.SSLFIPS{}, nil +} -// sslprofile_sslcertkey_binding -func (s *SSLService) AddSSLProfileSSLCertKeyBinding() {} -func (s *SSLService) DeleteSSLProfileSSLCertKeyBinding() {} -func (s *SSLService) GetAllSSLProfileSSLCertKeyBinding() {} -func (s *SSLService) GetSSLProfileSSLCertKeyBinding() {} -func (s *SSLService) CountSSLProfileSSLCertKeyBinding() {} +// sslfipskey +func (s *SSLService) CreateSSLFIPSKey(key models.SSLFIPSKey) error { + payload := map[string]any{"sslfipskey": key} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslFIPSKeyURL+"?action=create", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} -// sslprofile_sslciphersuite_binding -func (s *SSLService) AddSSLProfileSSLCipherSuiteBinding() {} -func (s *SSLService) DeleteSSLProfileSSLCipherSuiteBinding() {} -func (s *SSLService) GetAllSSLProfileSSLCipherSuiteBinding() {} -func (s *SSLService) GetSSLProfileSSLCipherSuiteBinding() {} -func (s *SSLService) CountSSLProfileSSLCipherSuiteBinding() {} +func (s *SSLService) DeleteSSLFIPSKey(name string) error { + reqURL := fmt.Sprintf("%s/%s", sslFIPSKeyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} -// sslprofile_sslcipher_binding -func (s *SSLService) AddSSLProfileSSLCipherBinding() {} -func (s *SSLService) DeleteSSLProfileSSLCipherBinding() {} -func (s *SSLService) GetAllSSLProfileSSLCipherBinding() {} -func (s *SSLService) GetSSLProfileSSLCipherBinding() {} -func (s *SSLService) CountSSLProfileSSLCipherBinding() {} +func (s *SSLService) ImportSSLFIPSKey(key models.SSLFIPSKey) error { + payload := map[string]any{"sslfipskey": key} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslFIPSKeyURL+"?action=import", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} -// sslprofile_sslvserver_binding -func (s *SSLService) GetAllSSLProfileSSLVServerBinding() {} -func (s *SSLService) GetSSLProfileSSLVServerBinding() {} -func (s *SSLService) CountSSLProfileSSLVServerBinding() {} +func (s *SSLService) ExportSSLFIPSKey(key models.SSLFIPSKey) error { + payload := map[string]any{"sslfipskey": key} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslFIPSKeyURL+"?action=export", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} -// sslrsakey -func (s *SSLService) CreateSSLRSAKey() {} +func (s *SSLService) GetAllSSLFIPSKey() ([]models.SSLFIPSKey, error) { + req, err := s.client.NewRequest(http.MethodGet, sslFIPSKeyURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLFIPSKey `json:"sslfipskey"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} -// sslservice -func (s *SSLService) UpdateSSLService() {} -func (s *SSLService) UnsetSSLService() {} -func (s *SSLService) GetAllSSLService() {} -func (s *SSLService) GetSSLService() {} -func (s *SSLService) CountSSLService() {} +func (s *SSLService) GetSSLFIPSKey(name string) ([]models.SSLFIPSKey, error) { + reqURL := fmt.Sprintf("%s/%s", sslFIPSKeyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLFIPSKey `json:"sslfipskey"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} -// sslservicegroup -func (s *SSLService) UpdateSSLServiceGroup() {} -func (s *SSLService) UnsetSSLServiceGroup() {} -func (s *SSLService) GetAllSSLServiceGroup() {} -func (s *SSLService) GetSSLServiceGroup() {} -func (s *SSLService) CountSSLServiceGroup() {} +func (s *SSLService) CountSSLFIPSKey() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, sslFIPSKeyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslfipskey"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} + +// sslfipssimsource +func (s *SSLService) EnableSSLFIPSSimSource(source models.SSLFIPSSimSource) error { + payload := map[string]any{"sslfipssimsource": source} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslFIPSSIMSourceURL+"?action=enable", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) InitSSLFIPSSimSource(source models.SSLFIPSSimSource) error { + payload := map[string]any{"sslfipssimsource": source} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslFIPSSIMSourceURL+"?action=init", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +// sslfipssimtarget +func (s *SSLService) EnableSSLFIPSSimTarget(target models.SSLFIPSSimTarget) error { + payload := map[string]any{"sslfipssimtarget": target} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslFIPSSIMTargetURL+"?action=enable", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) InitSSLFIPSSimTarget(target models.SSLFIPSSimTarget) error { + payload := map[string]any{"sslfipssimtarget": target} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslFIPSSIMTargetURL+"?action=init", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +// sslglobal_binding +func (s *SSLService) GetSSLGlobalBinding() ([]models.SSLGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLGlobalBinding `json:"sslglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +// sslglobal_sslpolicy_binding +func (s *SSLService) AddSSLGlobalSSLPolicyBinding(binding models.SSLGlobalSSLPolicyBinding) error { + payload := map[string]any{"sslglobal_sslpolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslGlobalSSLPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLGlobalSSLPolicyBinding(policyname string, typefield string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=type:%s,priority:%d", sslGlobalSSLPolicyBindingURL, url.QueryEscape(policyname), url.QueryEscape(typefield), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetSSLGlobalSSLPolicyBinding() ([]models.SSLGlobalSSLPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslGlobalSSLPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLGlobalSSLPolicyBinding `json:"sslglobal_sslpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLGlobalSSLPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, sslGlobalSSLPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslglobal_sslpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} + +// sslhsmkey +func (s *SSLService) AddSSLHSMKey(key models.SSLHSMKey) error { + payload := map[string]any{"sslhsmkey": key} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslHSMKeyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLHSMKey(name string) error { + reqURL := fmt.Sprintf("%s/%s", sslHSMKeyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLHSMKey() ([]models.SSLHSMKey, error) { + req, err := s.client.NewRequest(http.MethodGet, sslHSMKeyURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLHSMKey `json:"sslhsmkey"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLHSMKey(name string) ([]models.SSLHSMKey, error) { + reqURL := fmt.Sprintf("%s/%s", sslHSMKeyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLHSMKey `json:"sslhsmkey"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLHSMKey() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, sslHSMKeyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslhsmkey"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} + +// sslkeyfile +func (s *SSLService) ImportSSLKeyFile(file models.SSLKeyFile) error { + payload := map[string]any{"sslkeyfile": file} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslKeyFileURL+"?action=import", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLKeyFile(name string) error { + reqURL := fmt.Sprintf("%s/%s", sslKeyFileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLKeyFile() ([]models.SSLKeyFile, error) { + req, err := s.client.NewRequest(http.MethodGet, sslKeyFileURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLKeyFile `json:"sslkeyfile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLKeyFile() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, sslKeyFileURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslkeyfile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} + +// ssllogprofile +func (s *SSLService) AddSSLLogProfile(profile models.SSLLogProfile) error { + payload := map[string]any{"ssllogprofile": profile} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslLogProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLLogProfile(name string) error { + reqURL := fmt.Sprintf("%s/%s", sslLogProfileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) UpdateSSLLogProfile(profile models.SSLLogProfile) error { + payload := map[string]any{"ssllogprofile": profile} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslLogProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) UnsetSSLLogProfile(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"ssllogprofile": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslLogProfileURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLLogProfile() ([]models.SSLLogProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, sslLogProfileURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLLogProfile `json:"ssllogprofile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLLogProfile(name string) ([]models.SSLLogProfile, error) { + reqURL := fmt.Sprintf("%s/%s", sslLogProfileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLLogProfile `json:"ssllogprofile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLLogProfile() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, sslLogProfileURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"ssllogprofile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} + +// sslocspresponder +func (s *SSLService) AddSSLOCSPResponder(responder models.SSLOCSPResponder) error { + payload := map[string]any{"sslocspresponder": responder} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslOCSPResponderURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLOCSPResponder(name string) error { + reqURL := fmt.Sprintf("%s/%s", sslOCSPResponderURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) UpdateSSLOCSPResponder(responder models.SSLOCSPResponder) error { + payload := map[string]any{"sslocspresponder": responder} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslOCSPResponderURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) UnsetSSLOCSPResponder(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"sslocspresponder": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslOCSPResponderURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLOCSPResponder() ([]models.SSLOCSPResponder, error) { + req, err := s.client.NewRequest(http.MethodGet, sslOCSPResponderURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLOCSPResponder `json:"sslocspresponder"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLOCSPResponder(name string) ([]models.SSLOCSPResponder, error) { + reqURL := fmt.Sprintf("%s/%s", sslOCSPResponderURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLOCSPResponder `json:"sslocspresponder"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLOCSPResponder() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, sslOCSPResponderURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslocspresponder"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} + +// sslparameter +func (s *SSLService) UpdateSSLParameter(param models.SSLParameter) error { + payload := map[string]any{"sslparameter": param} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslParameterURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) UnsetSSLParameter(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"sslparameter": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslParameterURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLParameter() (models.SSLParameter, error) { + req, err := s.client.NewRequest(http.MethodGet, sslParameterURL, nil) + if err != nil { + return models.SSLParameter{}, err + } + resp, err := s.client.Do(req) + if err != nil { + return models.SSLParameter{}, err + } + var result struct { + Items []models.SSLParameter `json:"sslparameter"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return models.SSLParameter{}, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0], nil + } + return models.SSLParameter{}, nil +} + +// sslpkcs12 +func (s *SSLService) ConvertSSLPKCS12(pkcs12 models.SSLPKCS12) error { + payload := map[string]any{"sslpkcs12": pkcs12} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslPKCS12URL+"?action=convert", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +// sslpkcs8 +func (s *SSLService) ConvertSSLPKCS8(pkcs8 models.SSLPKCS8) error { + payload := map[string]any{"sslpkcs8": pkcs8} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslPKCS8URL+"?action=convert", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +// sslpolicy +func (s *SSLService) AddSSLPolicy(policy models.SSLPolicy) error { + payload := map[string]any{"sslpolicy": policy} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLPolicy(name string) error { + reqURL := fmt.Sprintf("%s/%s", sslPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) UpdateSSLPolicy(policy models.SSLPolicy) error { + payload := map[string]any{"sslpolicy": policy} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) UnsetSSLPolicy(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"sslpolicy": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslPolicyURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLPolicy() ([]models.SSLPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, sslPolicyURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLPolicy `json:"sslpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLPolicy(name string) ([]models.SSLPolicy, error) { + reqURL := fmt.Sprintf("%s/%s", sslPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLPolicy `json:"sslpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLPolicy() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, sslPolicyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} + +// sslpolicylabel +func (s *SSLService) AddSSLPolicyLabel(label models.SSLPolicyLabel) error { + payload := map[string]any{"sslpolicylabel": label} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslPolicyLabelURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLPolicyLabel(name string) error { + reqURL := fmt.Sprintf("%s/%s", sslPolicyLabelURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLPolicyLabel() ([]models.SSLPolicyLabel, error) { + req, err := s.client.NewRequest(http.MethodGet, sslPolicyLabelURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLPolicyLabel `json:"sslpolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLPolicyLabel(name string) ([]models.SSLPolicyLabel, error) { + reqURL := fmt.Sprintf("%s/%s", sslPolicyLabelURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLPolicyLabel `json:"sslpolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLPolicyLabel() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, sslPolicyLabelURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslpolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} + +// sslpolicylabel_binding +func (s *SSLService) GetAllSSLPolicyLabelBinding() ([]models.SSLPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslPolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLPolicyLabelBinding `json:"sslpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLPolicyLabelBinding(name string) ([]models.SSLPolicyLabelBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslPolicyLabelBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLPolicyLabelBinding `json:"sslpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +// sslpolicylabel_sslpolicy_binding +func (s *SSLService) AddSSLpolicyLabelSSLPolicyBinding(binding models.SSLPolicyLabelSSLPolicyBinding) error { + payload := map[string]any{"sslpolicylabel_sslpolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslPolicyLabelSSLPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLpolicyLabelSSLPolicyBinding(labelname string, policyname string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,priority:%d", sslPolicyLabelSSLPolicyBindingURL, url.QueryEscape(labelname), url.QueryEscape(policyname), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLpolicyLabelSSLPolicyBinding() ([]models.SSLPolicyLabelSSLPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslPolicyLabelSSLPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLPolicyLabelSSLPolicyBinding `json:"sslpolicylabel_sslpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLpolicyLabelSSLPolicyBinding(labelname string) ([]models.SSLPolicyLabelSSLPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslPolicyLabelSSLPolicyBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLPolicyLabelSSLPolicyBinding `json:"sslpolicylabel_sslpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLpolicyLabelSSLPolicyBinding(labelname string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslPolicyLabelSSLPolicyBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslpolicylabel_sslpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} + +// sslpolicy_binding +func (s *SSLService) GetAllSSLPolicyBinding() ([]models.SSLPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLPolicyBinding `json:"sslpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLPolicyBinding(name string) ([]models.SSLPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLPolicyBinding `json:"sslpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +// sslpolicy_csvserver_binding +func (s *SSLService) GetAllSSLPolicyCSVServerBinding() ([]models.SSLPolicyCSVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslPolicyCSVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLPolicyCSVServerBinding `json:"sslpolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLPolicyCSVServerBinding(name string) ([]models.SSLPolicyCSVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslPolicyCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLPolicyCSVServerBinding `json:"sslpolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLPolicyCSVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslPolicyCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslpolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} + +// sslpolicy_lbvserver_binding +func (s *SSLService) GetAllSSLPolicyLBVServerBinding() ([]models.SSLPolicyLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslPolicyLBVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLPolicyLBVServerBinding `json:"sslpolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLPolicyLBVServerBinding(name string) ([]models.SSLPolicyLBVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslPolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLPolicyLBVServerBinding `json:"sslpolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLPolicyLBVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslPolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslpolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} + +// sslpolicy_sslglobal_binding +func (s *SSLService) GetAllSSLPolicySSLGlobalBinding() ([]models.SSLPolicySSLGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslPolicySSLGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLPolicySSLGlobalBinding `json:"sslpolicy_sslglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLPolicySSLGlobalBinding(name string) ([]models.SSLPolicySSLGlobalBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslPolicySSLGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLPolicySSLGlobalBinding `json:"sslpolicy_sslglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLPolicySSLGlobalBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslPolicySSLGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslpolicy_sslglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} + +// sslpolicy_sslpolicylabel_binding +func (s *SSLService) GetAllSSLPolicySSLPolicyLabelBinding() ([]models.SSLPolicySSLPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslPolicySSLPolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLPolicySSLPolicyLabelBinding `json:"sslpolicy_sslpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLPolicySSLPolicyLabelBinding(name string) ([]models.SSLPolicySSLPolicyLabelBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslPolicySSLPolicyLabelBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLPolicySSLPolicyLabelBinding `json:"sslpolicy_sslpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLPolicySSLPolicyLabelBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslPolicySSLPolicyLabelBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslpolicy_sslpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} + +// sslpolicy_sslservice_binding +func (s *SSLService) GetAllSSLPolicySSLServiceBinding() ([]models.SSLPolicySSLServiceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslPolicySSLServiceBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLPolicySSLServiceBinding `json:"sslpolicy_sslservice_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLPolicySSLServiceBinding(name string) ([]models.SSLPolicySSLServiceBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslPolicySSLServiceBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLPolicySSLServiceBinding `json:"sslpolicy_sslservice_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLPolicySSLServiceBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslPolicySSLServiceBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslpolicy_sslservice_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} + +// sslpolicy_sslvserver_binding +func (s *SSLService) GetAllSSLPolicySSLVServerBinding() ([]models.SSLPolicySSLVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslPolicySSLVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLPolicySSLVServerBinding `json:"sslpolicy_sslvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLPolicySSLVServerBinding(name string) ([]models.SSLPolicySSLVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslPolicySSLVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLPolicySSLVServerBinding `json:"sslpolicy_sslvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLPolicySSLVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslPolicySSLVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslpolicy_sslvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} + +// sslprofile +func (s *SSLService) AddSSLProfile(profile models.SSLProfile) error { + payload := map[string]any{"sslprofile": profile} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLProfile(name string) error { + reqURL := fmt.Sprintf("%s/%s", sslProfileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) UpdateSSLProfile(profile models.SSLProfile) error { + payload := map[string]any{"sslprofile": profile} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) UnsetSSLProfile(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"sslprofile": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslProfileURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLProfile() ([]models.SSLProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, sslProfileURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLProfile `json:"sslprofile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLProfile(name string) ([]models.SSLProfile, error) { + reqURL := fmt.Sprintf("%s/%s", sslProfileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLProfile `json:"sslprofile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLProfile() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, sslProfileURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslprofile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} + +// sslprofile_binding +func (s *SSLService) GetAllSSLProfileBinding() ([]models.SSLProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslProfileBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLProfileBinding `json:"sslprofile_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLProfileBinding(name string) ([]models.SSLProfileBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslProfileBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLProfileBinding `json:"sslprofile_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +// sslprofile_eccurve_binding +func (s *SSLService) AddSSLProfileECCCurveBinding(binding models.SSLProfileECCCurveBinding) error { + payload := map[string]any{"sslprofile_ecccurve_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslProfileECCCurveBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLProfileECCCurveBinding(name string, ecccurvename string) error { + reqURL := fmt.Sprintf("%s/%s?args=ecccurvename:%s", sslProfileECCCurveBindingURL, url.QueryEscape(name), url.QueryEscape(ecccurvename)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLProfileECCCurveBinding() ([]models.SSLProfileECCCurveBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslProfileECCCurveBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLProfileECCCurveBinding `json:"sslprofile_ecccurve_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLProfileECCCurveBinding(name string) ([]models.SSLProfileECCCurveBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslProfileECCCurveBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLProfileECCCurveBinding `json:"sslprofile_ecccurve_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLProfileECCCurveBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslProfileECCCurveBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslprofile_ecccurve_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} + +// sslprofile_sslcertkey_binding +func (s *SSLService) AddSSLProfileSSLCertKeyBinding(binding models.SSLProfileSSLCertKeyBinding) error { + payload := map[string]any{"sslprofile_sslcertkey_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslProfileSSLCertKeyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLProfileSSLCertKeyBinding(name string, certkeyname string) error { + reqURL := fmt.Sprintf("%s/%s?args=certkeyname:%s", sslProfileSSLCertKeyBindingURL, url.QueryEscape(name), url.QueryEscape(certkeyname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLProfileSSLCertKeyBinding() ([]models.SSLProfileSSLCertKeyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslProfileSSLCertKeyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLProfileSSLCertKeyBinding `json:"sslprofile_sslcertkey_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLProfileSSLCertKeyBinding(name string) ([]models.SSLProfileSSLCertKeyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslProfileSSLCertKeyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLProfileSSLCertKeyBinding `json:"sslprofile_sslcertkey_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLProfileSSLCertKeyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslProfileSSLCertKeyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslprofile_sslcertkey_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} + +// sslprofile_sslciphersuite_binding +func (s *SSLService) AddSSLProfileSSLCipherSuiteBinding(binding models.SSLProfileSSLCipherSuiteBinding) error { + payload := map[string]any{"sslprofile_sslciphersuite_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslProfileSSLCipherSuiteBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLProfileSSLCipherSuiteBinding(name string, ciphername string) error { + reqURL := fmt.Sprintf("%s/%s?args=ciphername:%s", sslProfileSSLCipherSuiteBindingURL, url.QueryEscape(name), url.QueryEscape(ciphername)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLProfileSSLCipherSuiteBinding() ([]models.SSLProfileSSLCipherSuiteBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslProfileSSLCipherSuiteBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLProfileSSLCipherSuiteBinding `json:"sslprofile_sslciphersuite_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLProfileSSLCipherSuiteBinding(name string) ([]models.SSLProfileSSLCipherSuiteBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslProfileSSLCipherSuiteBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLProfileSSLCipherSuiteBinding `json:"sslprofile_sslciphersuite_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLProfileSSLCipherSuiteBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslProfileSSLCipherSuiteBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslprofile_sslciphersuite_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} + +// sslprofile_sslcipher_binding +func (s *SSLService) AddSSLProfileSSLCipherBinding(binding models.SSLProfileSSLCipherBinding) error { + payload := map[string]any{"sslprofile_sslcipher_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslProfileSSLCipherBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLProfileSSLCipherBinding(name string, ciphername string) error { + reqURL := fmt.Sprintf("%s/%s?args=ciphername:%s", sslProfileSSLCipherBindingURL, url.QueryEscape(name), url.QueryEscape(ciphername)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLProfileSSLCipherBinding() ([]models.SSLProfileSSLCipherBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslProfileSSLCipherBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLProfileSSLCipherBinding `json:"sslprofile_sslcipher_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLProfileSSLCipherBinding(name string) ([]models.SSLProfileSSLCipherBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslProfileSSLCipherBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLProfileSSLCipherBinding `json:"sslprofile_sslcipher_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLProfileSSLCipherBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslProfileSSLCipherBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslprofile_sslcipher_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} + +// sslprofile_sslvserver_binding +func (s *SSLService) GetAllSSLProfileSSLVServerBinding() ([]models.SSLProfileSSLVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslProfileSSLVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLProfileSSLVServerBinding `json:"sslprofile_sslvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLProfileSSLVServerBinding(name string) ([]models.SSLProfileSSLVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslProfileSSLVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLProfileSSLVServerBinding `json:"sslprofile_sslvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLProfileSSLVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslProfileSSLVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslprofile_sslvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} + +// sslrsakey +func (s *SSLService) CreateSSLRSAKey(key models.SSLRSAKey) error { + payload := map[string]any{"sslrsakey": key} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslRSAKeyURL+"?action=create", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +// sslservice +func (s *SSLService) UpdateSSLService(service models.SSLService) error { + payload := map[string]any{"sslservice": service} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslServiceURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) UnsetSSLService(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"sslservice": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslServiceURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLService() ([]models.SSLService, error) { + req, err := s.client.NewRequest(http.MethodGet, sslServiceURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLService `json:"sslservice"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLService(servicename string) ([]models.SSLService, error) { + reqURL := fmt.Sprintf("%s/%s", sslServiceURL, url.QueryEscape(servicename)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLService `json:"sslservice"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLService() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, sslServiceURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslservice"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} + +// sslservicegroup +func (s *SSLService) UpdateSSLServiceGroup(group models.SSLServiceGroup) error { + payload := map[string]any{"sslservicegroup": group} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslServiceGroupURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) UnsetSSLServiceGroup(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"sslservicegroup": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslServiceGroupURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLServiceGroup() ([]models.SSLServiceGroup, error) { + req, err := s.client.NewRequest(http.MethodGet, sslServiceGroupURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLServiceGroup `json:"sslservicegroup"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLServiceGroup(servicegroupname string) ([]models.SSLServiceGroup, error) { + reqURL := fmt.Sprintf("%s/%s", sslServiceGroupURL, url.QueryEscape(servicegroupname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLServiceGroup `json:"sslservicegroup"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLServiceGroup() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, sslServiceGroupURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslservicegroup"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslservicegroup_binding -func (s *SSLService) GetAllSSLServiceGroupBinding() {} -func (s *SSLService) GetSSLServiceGroupBinding() {} +func (s *SSLService) GetAllSSLServiceGroupBinding() ([]models.SSLServiceGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslServiceGroupBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLServiceGroupBinding `json:"sslservicegroup_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLServiceGroupBinding(servicegroupname string) ([]models.SSLServiceGroupBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslServiceGroupBindingURL, url.QueryEscape(servicegroupname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLServiceGroupBinding `json:"sslservicegroup_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} // sslservicegroup_ecccurve_binding -func (s *SSLService) AddSSLServiceGroupECCCurveBinding() {} -func (s *SSLService) DeleteSSLServiceGroupECCCurveBinding() {} -func (s *SSLService) GetAllSSLServiceGroupECCCurveBinding() {} -func (s *SSLService) GetSSLServiceGroupECCCurveBinding() {} -func (s *SSLService) CountSSLServiceGroupECCCurveBinding() {} +func (s *SSLService) AddSSLServiceGroupECCCurveBinding(binding models.SSLServiceGroupECCCurveBinding) error { + payload := map[string]any{"sslservicegroup_ecccurve_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslServiceGroupECCCurveBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLServiceGroupECCCurveBinding(servicegroupname string, ecccurvename string) error { + reqURL := fmt.Sprintf("%s/%s?args=ecccurvename:%s", sslServiceGroupECCCurveBindingURL, url.QueryEscape(servicegroupname), url.QueryEscape(ecccurvename)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLServiceGroupECCCurveBinding() ([]models.SSLServiceGroupECCCurveBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslServiceGroupECCCurveBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLServiceGroupECCCurveBinding `json:"sslservicegroup_ecccurve_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLServiceGroupECCCurveBinding(servicegroupname string) ([]models.SSLServiceGroupECCCurveBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslServiceGroupECCCurveBindingURL, url.QueryEscape(servicegroupname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLServiceGroupECCCurveBinding `json:"sslservicegroup_ecccurve_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLServiceGroupECCCurveBinding(servicegroupname string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslServiceGroupECCCurveBindingURL, url.QueryEscape(servicegroupname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslservicegroup_ecccurve_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslservicegroup_sslcertkey_binding -func (s *SSLService) AddSSLServiceGroupSSLCertKeyBinding() {} -func (s *SSLService) DeleteSSLServiceGroupSSLCertKeyBinding() {} -func (s *SSLService) GetAllSSLServiceGroupSSLCertKeyBinding() {} -func (s *SSLService) GetSSLServiceGroupSSLCertKeyBinding() {} -func (s *SSLService) CountSSLServiceGroupSSLCertKeyBinding() {} +func (s *SSLService) AddSSLServiceGroupSSLCertKeyBinding(binding models.SSLServiceGroupSSLCertKeyBinding) error { + payload := map[string]any{"sslservicegroup_sslcertkey_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslServiceGroupSSLCertKeyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLServiceGroupSSLCertKeyBinding(servicegroupname string, certkeyname string) error { + reqURL := fmt.Sprintf("%s/%s?args=certkeyname:%s", sslServiceGroupSSLCertKeyBindingURL, url.QueryEscape(servicegroupname), url.QueryEscape(certkeyname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLServiceGroupSSLCertKeyBinding() ([]models.SSLServiceGroupSSLCertKeyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslServiceGroupSSLCertKeyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLServiceGroupSSLCertKeyBinding `json:"sslservicegroup_sslcertkey_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLServiceGroupSSLCertKeyBinding(servicegroupname string) ([]models.SSLServiceGroupSSLCertKeyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslServiceGroupSSLCertKeyBindingURL, url.QueryEscape(servicegroupname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLServiceGroupSSLCertKeyBinding `json:"sslservicegroup_sslcertkey_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLServiceGroupSSLCertKeyBinding(servicegroupname string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslServiceGroupSSLCertKeyBindingURL, url.QueryEscape(servicegroupname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslservicegroup_sslcertkey_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslservicegroup_sslciphersuite_binding -func (s *SSLService) AddSSLServiceGroupSSLCipherSuiteBinding() {} -func (s *SSLService) DeleteSSLServiceGroupSSLCipherSuiteBinding() {} -func (s *SSLService) GetAllSSLServiceGroupSSLCipherSuiteBinding() {} -func (s *SSLService) GetSSLServiceGroupSSLCipherSuiteBinding() {} -func (s *SSLService) CountSSLServiceGroupSSLCipherSuiteBinding() {} +func (s *SSLService) AddSSLServiceGroupSSLCipherSuiteBinding(binding models.SSLServiceGroupSSLCipherSuiteBinding) error { + payload := map[string]any{"sslservicegroup_sslciphersuite_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslServiceGroupSSLCipherSuiteBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLServiceGroupSSLCipherSuiteBinding(servicegroupname string, ciphername string) error { + reqURL := fmt.Sprintf("%s/%s?args=ciphername:%s", sslServiceGroupSSLCipherSuiteBindingURL, url.QueryEscape(servicegroupname), url.QueryEscape(ciphername)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLServiceGroupSSLCipherSuiteBinding() ([]models.SSLServiceGroupSSLCipherSuiteBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslServiceGroupSSLCipherSuiteBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLServiceGroupSSLCipherSuiteBinding `json:"sslservicegroup_sslciphersuite_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLServiceGroupSSLCipherSuiteBinding(servicegroupname string) ([]models.SSLServiceGroupSSLCipherSuiteBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslServiceGroupSSLCipherSuiteBindingURL, url.QueryEscape(servicegroupname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLServiceGroupSSLCipherSuiteBinding `json:"sslservicegroup_sslciphersuite_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLServiceGroupSSLCipherSuiteBinding(servicegroupname string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslServiceGroupSSLCipherSuiteBindingURL, url.QueryEscape(servicegroupname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslservicegroup_sslciphersuite_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslservicegroup_sslcipher_binding -func (s *SSLService) AddSSLServiceGroupSSLCipherBinding() {} -func (s *SSLService) DeleteSSLServiceGroupSSLCipherBinding() {} -func (s *SSLService) GetAllSSLServiceGroupSSLCipherBinding() {} -func (s *SSLService) GetSSLServiceGroupSSLCipherBinding() {} -func (s *SSLService) CountSSLServiceGroupSSLCipherBinding() {} +func (s *SSLService) AddSSLServiceGroupSSLCipherBinding(binding models.SSLServiceGroupSSLCipherBinding) error { + payload := map[string]any{"sslservicegroup_sslcipher_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslServiceGroupSSLCipherBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLServiceGroupSSLCipherBinding(servicegroupname string, ciphername string) error { + reqURL := fmt.Sprintf("%s/%s?args=ciphername:%s", sslServiceGroupSSLCipherBindingURL, url.QueryEscape(servicegroupname), url.QueryEscape(ciphername)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLServiceGroupSSLCipherBinding() ([]models.SSLServiceGroupSSLCipherBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslServiceGroupSSLCipherBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLServiceGroupSSLCipherBinding `json:"sslservicegroup_sslcipher_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLServiceGroupSSLCipherBinding(servicegroupname string) ([]models.SSLServiceGroupSSLCipherBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslServiceGroupSSLCipherBindingURL, url.QueryEscape(servicegroupname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLServiceGroupSSLCipherBinding `json:"sslservicegroup_sslcipher_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLServiceGroupSSLCipherBinding(servicegroupname string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslServiceGroupSSLCipherBindingURL, url.QueryEscape(servicegroupname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslservicegroup_sslcipher_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslservice_binding -func (s *SSLService) GetAllSSLServiceBinding() {} -func (s *SSLService) GetSSLServiceBinding() {} +func (s *SSLService) GetAllSSLServiceBinding() ([]models.SSLServiceBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslServiceBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLServiceBinding `json:"sslservice_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLServiceBinding(servicename string) ([]models.SSLServiceBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslServiceBindingURL, url.QueryEscape(servicename)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLServiceBinding `json:"sslservice_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} // sslservice_ecccurve_binding -func (s *SSLService) SSLServiceECCCurveBinding() {} -func (s *SSLService) DeleteSSLServiceECCCurveBinding() {} -func (s *SSLService) GetAllSSLServiceECCCurveBinding() {} -func (s *SSLService) GetSSLServiceECCCurveBinding() {} -func (s *SSLService) CountSSLServiceECCCurveBinding() {} +func (s *SSLService) AddSSLServiceECCCurveBinding(binding models.SSLServiceECCCurveBinding) error { + payload := map[string]any{"sslservice_ecccurve_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslServiceECCCurveBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLServiceECCCurveBinding(servicename string, ecccurvename string) error { + reqURL := fmt.Sprintf("%s/%s?args=ecccurvename:%s", sslServiceECCCurveBindingURL, url.QueryEscape(servicename), url.QueryEscape(ecccurvename)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLServiceECCCurveBinding() ([]models.SSLServiceECCCurveBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslServiceECCCurveBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLServiceECCCurveBinding `json:"sslservice_ecccurve_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLServiceECCCurveBinding(servicename string) ([]models.SSLServiceECCCurveBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslServiceECCCurveBindingURL, url.QueryEscape(servicename)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLServiceECCCurveBinding `json:"sslservice_ecccurve_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLServiceECCCurveBinding(servicename string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslServiceECCCurveBindingURL, url.QueryEscape(servicename)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslservice_ecccurve_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslservice_sslcertkey_binding -func (s *SSLService) AddSSLServiceSSLCertKeyBinding() {} -func (s *SSLService) DeleteSSLServiceSSLCertKeyBinding() {} -func (s *SSLService) GetAllSSLServiceSSLCertKeyBinding() {} -func (s *SSLService) GetSSLServiceSSLCertKeyBinding() {} -func (s *SSLService) CountSSLServiceSSLCertKeyBinding() {} +func (s *SSLService) AddSSLServiceSSLCertKeyBinding(binding models.SSLServiceSSLCertKeyBinding) error { + payload := map[string]any{"sslservice_sslcertkey_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslServiceSSLCertKeyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLServiceSSLCertKeyBinding(servicename string, certkeyname string) error { + reqURL := fmt.Sprintf("%s/%s?args=certkeyname:%s", sslServiceSSLCertKeyBindingURL, url.QueryEscape(servicename), url.QueryEscape(certkeyname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLServiceSSLCertKeyBinding() ([]models.SSLServiceSSLCertKeyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslServiceSSLCertKeyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLServiceSSLCertKeyBinding `json:"sslservice_sslcertkey_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLServiceSSLCertKeyBinding(servicename string) ([]models.SSLServiceSSLCertKeyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslServiceSSLCertKeyBindingURL, url.QueryEscape(servicename)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLServiceSSLCertKeyBinding `json:"sslservice_sslcertkey_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLServiceSSLCertKeyBinding(servicename string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslServiceSSLCertKeyBindingURL, url.QueryEscape(servicename)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslservice_sslcertkey_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslservice_sslciphersuite_binding -func (s *SSLService) AddSSLServiceSSLCipherSuiteBinding() {} -func (s *SSLService) DeleteSSLServiceSSLCipherSuiteBinding() {} -func (s *SSLService) GetAllSSLServiceSSLCipherSuiteBinding() {} -func (s *SSLService) GetSSLServiceSSLCipherSuiteBinding() {} -func (s *SSLService) CountSSLServiceSSLCipherSuiteBinding() {} +func (s *SSLService) AddSSLServiceSSLCipherSuiteBinding(binding models.SSLServiceSSLCipherSuiteBinding) error { + payload := map[string]any{"sslservice_sslciphersuite_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslServiceSSLCipherSuiteBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLServiceSSLCipherSuiteBinding(servicename string, ciphername string) error { + reqURL := fmt.Sprintf("%s/%s?args=ciphername:%s", sslServiceSSLCipherSuiteBindingURL, url.QueryEscape(servicename), url.QueryEscape(ciphername)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLServiceSSLCipherSuiteBinding() ([]models.SSLServiceSSLCipherSuiteBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslServiceSSLCipherSuiteBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLServiceSSLCipherSuiteBinding `json:"sslservice_sslciphersuite_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLServiceSSLCipherSuiteBinding(servicename string) ([]models.SSLServiceSSLCipherSuiteBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslServiceSSLCipherSuiteBindingURL, url.QueryEscape(servicename)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLServiceSSLCipherSuiteBinding `json:"sslservice_sslciphersuite_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLServiceSSLCipherSuiteBinding(servicename string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslServiceSSLCipherSuiteBindingURL, url.QueryEscape(servicename)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslservice_sslciphersuite_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslservice_sslcipher_binding -func (s *SSLService) AddSSLServiceSSLCipherBinding() {} -func (s *SSLService) DeleteSSLServiceSSLCipherBinding() {} -func (s *SSLService) GetAllSSLServiceSSLCipherBinding() {} -func (s *SSLService) GetSSLServiceSSLCipherBinding() {} -func (s *SSLService) CountSSLServiceSSLCipherBinding() {} +func (s *SSLService) AddSSLServiceSSLCipherBinding(binding models.SSLServiceSSLCipherBinding) error { + payload := map[string]any{"sslservice_sslcipher_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslServiceSSLCipherBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLServiceSSLCipherBinding(servicename string, ciphername string) error { + reqURL := fmt.Sprintf("%s/%s?args=ciphername:%s", sslServiceSSLCipherBindingURL, url.QueryEscape(servicename), url.QueryEscape(ciphername)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLServiceSSLCipherBinding() ([]models.SSLServiceSSLCipherBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslServiceSSLCipherBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLServiceSSLCipherBinding `json:"sslservice_sslcipher_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLServiceSSLCipherBinding(servicename string) ([]models.SSLServiceSSLCipherBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslServiceSSLCipherBindingURL, url.QueryEscape(servicename)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLServiceSSLCipherBinding `json:"sslservice_sslcipher_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLServiceSSLCipherBinding(servicename string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslServiceSSLCipherBindingURL, url.QueryEscape(servicename)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslservice_sslcipher_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslservice_sslpolicy_binding -func (s *SSLService) AddSSLServiceSSLPolicyBinding() {} -func (s *SSLService) DeleteSSLServiceSSLPolicyBinding() {} -func (s *SSLService) GetAllSSLServiceSSLPolicyBinding() {} -func (s *SSLService) GetSSLServiceSSLPolicyBinding() {} -func (s *SSLService) CountSSLServiceSSLPolicyBinding() {} +func (s *SSLService) AddSSLServiceSSLPolicyBinding(binding models.SSLServiceSSLPolicyBinding) error { + payload := map[string]any{"sslservice_sslpolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslServiceSSLPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLServiceSSLPolicyBinding(servicename string, policyname string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,priority:%d", sslServiceSSLPolicyBindingURL, url.QueryEscape(servicename), url.QueryEscape(policyname), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLServiceSSLPolicyBinding() ([]models.SSLServiceSSLPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslServiceSSLPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLServiceSSLPolicyBinding `json:"sslservice_sslpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLServiceSSLPolicyBinding(servicename string) ([]models.SSLServiceSSLPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslServiceSSLPolicyBindingURL, url.QueryEscape(servicename)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLServiceSSLPolicyBinding `json:"sslservice_sslpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLServiceSSLPolicyBinding(servicename string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslServiceSSLPolicyBindingURL, url.QueryEscape(servicename)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslservice_sslpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslvserver -func (s *SSLService) UpdateSSLVServer() {} -func (s *SSLService) UnsetSSLVServer() {} -func (s *SSLService) GetAllSSLVServer() {} -func (s *SSLService) GetSSLVServer() {} -func (s *SSLService) CountSSLVServer() {} +func (s *SSLService) UpdateSSLVServer(vserver models.SSLVServer) error { + payload := map[string]any{"sslvserver": vserver} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslVServerURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) UnsetSSLVServer(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"sslvserver": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslVServerURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLVServer() ([]models.SSLVServer, error) { + req, err := s.client.NewRequest(http.MethodGet, sslVServerURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLVServer `json:"sslvserver"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLVServer(vservername string) ([]models.SSLVServer, error) { + reqURL := fmt.Sprintf("%s/%s", sslVServerURL, url.QueryEscape(vservername)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLVServer `json:"sslvserver"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLVServer() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, sslVServerURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslvserver"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslvserver_binding -func (s *SSLService) GetAllSSLVServerBinding() {} -func (s *SSLService) GetSSLVServerBinding() {} +func (s *SSLService) GetAllSSLVServerBinding() ([]models.SSLVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLVServerBinding `json:"sslvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLVServerBinding(vservername string) ([]models.SSLVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslVServerBindingURL, url.QueryEscape(vservername)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLVServerBinding `json:"sslvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} // sslvserver_ecccurve_binding -func (s *SSLService) AddSSLVServerECCCurveBinding() {} -func (s *SSLService) DeleteSSLVServerECCCurveBinding() {} -func (s *SSLService) GetAllSSLVServerECCCurveBinding() {} -func (s *SSLService) GetSSLVServerECCCurveBinding() {} -func (s *SSLService) CountSSLVServerECCCurveBinding() {} +func (s *SSLService) AddSSLVServerECCCurveBinding(binding models.SSLVServerECCCurveBinding) error { + payload := map[string]any{"sslvserver_ecccurve_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslVServerECCCurveBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLVServerECCCurveBinding(vservername string, ecccurvename string) error { + reqURL := fmt.Sprintf("%s/%s?args=ecccurvename:%s", sslVServerECCCurveBindingURL, url.QueryEscape(vservername), url.QueryEscape(ecccurvename)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLVServerECCCurveBinding() ([]models.SSLVServerECCCurveBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslVServerECCCurveBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLVServerECCCurveBinding `json:"sslvserver_ecccurve_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLVServerECCCurveBinding(vservername string) ([]models.SSLVServerECCCurveBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslVServerECCCurveBindingURL, url.QueryEscape(vservername)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLVServerECCCurveBinding `json:"sslvserver_ecccurve_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLVServerECCCurveBinding(vservername string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslVServerECCCurveBindingURL, url.QueryEscape(vservername)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslvserver_ecccurve_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslvserver_sslcertkey_binding -func (s *SSLService) AddSSLVServerSSLCertKeyBinding() {} -func (s *SSLService) DeleteSSLVServerSSLCertKeyBinding() {} -func (s *SSLService) GetAllSSLVServerSSLCertKeyBinding() {} -func (s *SSLService) GetSSLVServerSSLCertKeyBinding() {} -func (s *SSLService) CountSSLVServerSSLCertKeyBinding() {} +func (s *SSLService) AddSSLVServerSSLCertKeyBinding(binding models.SSLVServerSSLCertKeyBinding) error { + payload := map[string]any{"sslvserver_sslcertkey_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslVServerSSLCertKeyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLVServerSSLCertKeyBinding(vservername string, certkeyname string) error { + reqURL := fmt.Sprintf("%s/%s?args=certkeyname:%s", sslVServerSSLCertKeyBindingURL, url.QueryEscape(vservername), url.QueryEscape(certkeyname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLVServerSSLCertKeyBinding() ([]models.SSLVServerSSLCertKeyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslVServerSSLCertKeyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLVServerSSLCertKeyBinding `json:"sslvserver_sslcertkey_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLVServerSSLCertKeyBinding(vservername string) ([]models.SSLVServerSSLCertKeyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslVServerSSLCertKeyBindingURL, url.QueryEscape(vservername)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLVServerSSLCertKeyBinding `json:"sslvserver_sslcertkey_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLVServerSSLCertKeyBinding(vservername string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslVServerSSLCertKeyBindingURL, url.QueryEscape(vservername)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslvserver_sslcertkey_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslvserver_sslciphersuite_binding -func (s *SSLService) AddSSLVServerSSLCipherSuiteBinding() {} -func (s *SSLService) DeleteSSLVServerSSLCipherSuiteBinding() {} -func (s *SSLService) GetAllSSLVServerSSLCipherSuiteBinding() {} -func (s *SSLService) GetSSLVServerSSLCipherSuiteBinding() {} -func (s *SSLService) CountSSLVServerSSLCipherSuiteBinding() {} +func (s *SSLService) AddSSLVServerSSLCipherSuiteBinding(binding models.SSLVServerSSLCipherSuiteBinding) error { + payload := map[string]any{"sslvserver_sslciphersuite_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslVServerSSLCipherSuiteBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLVServerSSLCipherSuiteBinding(vservername string, ciphername string) error { + reqURL := fmt.Sprintf("%s/%s?args=ciphername:%s", sslVServerSSLCipherSuiteBindingURL, url.QueryEscape(vservername), url.QueryEscape(ciphername)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLVServerSSLCipherSuiteBinding() ([]models.SSLVServerSSLCipherSuiteBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslVServerSSLCipherSuiteBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLVServerSSLCipherSuiteBinding `json:"sslvserver_sslciphersuite_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLVServerSSLCipherSuiteBinding(vservername string) ([]models.SSLVServerSSLCipherSuiteBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslVServerSSLCipherSuiteBindingURL, url.QueryEscape(vservername)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLVServerSSLCipherSuiteBinding `json:"sslvserver_sslciphersuite_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLVServerSSLCipherSuiteBinding(vservername string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslVServerSSLCipherSuiteBindingURL, url.QueryEscape(vservername)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslvserver_sslciphersuite_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslvserver_sslcipher_binding -func (s *SSLService) AddSSLVServerSSLCipherBInding() {} -func (s *SSLService) DeleteSSLVServerSSLCipherBInding() {} -func (s *SSLService) GetAllSSLVServerSSLCipherBInding() {} -func (s *SSLService) GetSSLVServerSSLCipherBInding() {} -func (s *SSLService) CountSSLVServerSSLCipherBInding() {} +func (s *SSLService) AddSSLVServerSSLCipherBinding(binding models.SSLVServerSSLCipherBinding) error { + payload := map[string]any{"sslvserver_sslcipher_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslVServerSSLCipherBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLVServerSSLCipherBinding(vservername string, ciphername string) error { + reqURL := fmt.Sprintf("%s/%s?args=ciphername:%s", sslVServerSSLCipherBindingURL, url.QueryEscape(vservername), url.QueryEscape(ciphername)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLVServerSSLCipherBinding() ([]models.SSLVServerSSLCipherBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslVServerSSLCipherBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLVServerSSLCipherBinding `json:"sslvserver_sslcipher_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLVServerSSLCipherBinding(vservername string) ([]models.SSLVServerSSLCipherBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslVServerSSLCipherBindingURL, url.QueryEscape(vservername)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLVServerSSLCipherBinding `json:"sslvserver_sslcipher_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLVServerSSLCipherBinding(vservername string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslVServerSSLCipherBindingURL, url.QueryEscape(vservername)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslvserver_sslcipher_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslvserver_sslpolicy_binding -func (s *SSLService) AddSSLVServerSSLPolicyBinding() {} -func (s *SSLService) DeleteSSLVServerSSLPolicyBinding() {} -func (s *SSLService) GetAllSSLVServerSSLPolicyBinding() {} -func (s *SSLService) GetSSLVServerSSLPolicyBinding() {} -func (s *SSLService) CountSSLVServerSSLPolicyBinding() {} +func (s *SSLService) AddSSLVServerSSLPolicyBinding(binding models.SSLVServerSSLPolicyBinding) error { + payload := map[string]any{"sslvserver_sslpolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, sslVServerSSLPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLVServerSSLPolicyBinding(vservername string, policyname string, typefield string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,type:%s,priority:%d", sslVServerSSLPolicyBindingURL, url.QueryEscape(vservername), url.QueryEscape(policyname), url.QueryEscape(typefield), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLVServerSSLPolicyBinding() ([]models.SSLVServerSSLPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, sslVServerSSLPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLVServerSSLPolicyBinding `json:"sslvserver_sslpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) GetSSLVServerSSLPolicyBinding(vservername string) ([]models.SSLVServerSSLPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", sslVServerSSLPolicyBindingURL, url.QueryEscape(vservername)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLVServerSSLPolicyBinding `json:"sslvserver_sslpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLVServerSSLPolicyBinding(vservername string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", sslVServerSSLPolicyBindingURL, url.QueryEscape(vservername)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslvserver_sslpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} // sslwrapkey -func (s *SSLService) CreateSSLWrapKey() {} -func (s *SSLService) DeleteSSLWrapKey() {} -func (s *SSLService) GetAllSSLWrapKey() {} -func (s *SSLService) CountSSLWrapKey() {} +func (s *SSLService) CreateSSLWrapKey(key models.SSLWrapKey) error { + payload := map[string]any{"sslwrapkey": key} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, sslWrapKeyURL+"?action=create", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) DeleteSSLWrapKey(name string) error { + reqURL := fmt.Sprintf("%s/%s", sslWrapKeyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *SSLService) GetAllSSLWrapKey() ([]models.SSLWrapKey, error) { + req, err := s.client.NewRequest(http.MethodGet, sslWrapKeyURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Items []models.SSLWrapKey `json:"sslwrapkey"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Items, nil +} + +func (s *SSLService) CountSSLWrapKey() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, sslWrapKeyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Items []struct { + Count float64 `json:"__count"` + } `json:"sslwrapkey"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Items) > 0 { + return result.Items[0].Count, nil + } + return 0, nil +} diff --git a/nitrogo/stream.go b/nitrogo/stream.go index dd9cf39..05bd205 100644 --- a/nitrogo/stream.go +++ b/nitrogo/stream.go @@ -1,5 +1,23 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + streamIdentifierURL = "/nitro/v1/config/streamidentifier" + streamIdentifierBindingURL = "/nitro/v1/config/streamidentifier_binding" + streamIdentifierStreamSessionBindingURL = "/nitro/v1/config/streamidentifier_streamsession_binding" + streamSelectorURL = "/nitro/v1/config/streamselector" + streamSessionURL = "/nitro/v1/config/streamsession" +) + // Stream configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/stream/stream type StreamService struct { @@ -9,38 +27,430 @@ type StreamService struct { // streamidentifier // Configuration for identifier resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/stream/streamidentifier -func (s *StreamService) AddStreamIdentifier() {} -func (s *StreamService) DeleteStreamIdentifier() {} -func (s *StreamService) UpdateStreamIdentifier() {} -func (s *StreamService) UnsetStreamIdentifier() {} -func (s *StreamService) GetAllStreamIdentifier() {} -func (s *StreamService) GetStreamIdentifier() {} -func (s *StreamService) CountStreamIdentifier() {} + +func (s *StreamService) AddStreamIdentifier(identifier models.StreamIdentifier) error { + payload := map[string]any{ + "streamidentifier": identifier, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, streamIdentifierURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *StreamService) DeleteStreamIdentifier(name string) error { + url := fmt.Sprintf("%s/%s", streamIdentifierURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, url, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *StreamService) UpdateStreamIdentifier(identifier models.StreamIdentifier) error { + payload := map[string]any{ + "streamidentifier": identifier, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, streamIdentifierURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *StreamService) UnsetStreamIdentifier(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "streamidentifier": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, streamIdentifierURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *StreamService) GetAllStreamIdentifier() ([]models.StreamIdentifier, error) { + req, err := s.client.NewRequest(http.MethodGet, streamIdentifierURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + StreamIdentifiers []models.StreamIdentifier `json:"streamidentifier"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.StreamIdentifiers, nil +} + +func (s *StreamService) GetStreamIdentifier(name string) ([]models.StreamIdentifier, error) { + url := fmt.Sprintf("%s/%s", streamIdentifierURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + StreamIdentifiers []models.StreamIdentifier `json:"streamidentifier"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.StreamIdentifiers, nil +} + +func (s *StreamService) CountStreamIdentifier() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, streamIdentifierURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + StreamIdentifiers []struct { + Count float64 `json:"__count"` + } `json:"streamidentifier"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.StreamIdentifiers) > 0 { + return result.StreamIdentifiers[0].Count, nil + } + + return 0, nil +} // streamidentifier_binding // Binding object which returns the resources bound to streamidentifier. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/stream/streamidentifier_binding -func (s *StreamService) GetAllStreamIdentifierBinding() {} -func (s *StreamService) GetStreamIdentifierBinding() {} + +func (s *StreamService) GetAllStreamIdentifierBinding() ([]models.StreamIdentifierBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, streamIdentifierBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.StreamIdentifierBinding `json:"streamidentifier_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *StreamService) GetStreamIdentifierBinding(name string) ([]models.StreamIdentifierBinding, error) { + url := fmt.Sprintf("%s/%s", streamIdentifierBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.StreamIdentifierBinding `json:"streamidentifier_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} // streamidentifier_streamsession_binding // Binding object showing the streamsession that can be bound to streamidentifier. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/stream/streamidentifier_streamsession_binding -func (s *StreamService) GetAllStreamIdentifierStreamSessionBinding() {} -func (s *StreamService) GetStreamIdentifierStreamSessionBinding() {} -func (s *StreamService) CountStreamIdentifierStreamSessionBinding() {} + +func (s *StreamService) GetAllStreamIdentifierStreamSessionBinding() ([]models.StreamIdentifierStreamSessionBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, streamIdentifierStreamSessionBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.StreamIdentifierStreamSessionBinding `json:"streamidentifier_streamsession_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *StreamService) GetStreamIdentifierStreamSessionBinding(name string) ([]models.StreamIdentifierStreamSessionBinding, error) { + url := fmt.Sprintf("%s/%s", streamIdentifierStreamSessionBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.StreamIdentifierStreamSessionBinding `json:"streamidentifier_streamsession_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *StreamService) CountStreamIdentifierStreamSessionBinding(name string) (float64, error) { + url := fmt.Sprintf("%s/%s?count=yes", streamIdentifierStreamSessionBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"streamidentifier_streamsession_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} // streamselector // Configuration for selector resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/stream/streamselector -func (s *StreamService) AddStreamSelector() {} -func (s *StreamService) DeleteStreamSelector() {} -func (s *StreamService) UpdateStreamSelector() {} -func (s *StreamService) GetAllStreamSelector() {} -func (s *StreamService) GetStreamSelector() {} -func (s *StreamService) CountStreamSelector() {} + +func (s *StreamService) AddStreamSelector(selector models.StreamSelector) error { + payload := map[string]any{ + "streamselector": selector, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, streamSelectorURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *StreamService) DeleteStreamSelector(name string) error { + url := fmt.Sprintf("%s/%s", streamSelectorURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, url, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *StreamService) UpdateStreamSelector(selector models.StreamSelector) error { + payload := map[string]any{ + "streamselector": selector, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, streamSelectorURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *StreamService) GetAllStreamSelector() ([]models.StreamSelector, error) { + req, err := s.client.NewRequest(http.MethodGet, streamSelectorURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + StreamSelectors []models.StreamSelector `json:"streamselector"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.StreamSelectors, nil +} + +func (s *StreamService) GetStreamSelector(name string) ([]models.StreamSelector, error) { + url := fmt.Sprintf("%s/%s", streamSelectorURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + StreamSelectors []models.StreamSelector `json:"streamselector"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.StreamSelectors, nil +} + +func (s *StreamService) CountStreamSelector() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, streamSelectorURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + StreamSelectors []struct { + Count float64 `json:"__count"` + } `json:"streamselector"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.StreamSelectors) > 0 { + return result.StreamSelectors[0].Count, nil + } + + return 0, nil +} // streamsession // Configuration for active connection resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/stream/streamsession -func (s *StreamService) ClearStreamSession() {} + +func (s *StreamService) ClearStreamSession(session models.StreamSession) error { + payload := map[string]any{ + "streamsession": session, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, streamSessionURL+"?action=clear", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} diff --git a/nitrogo/subscriber.go b/nitrogo/subscriber.go index 54e563a..3604dc3 100644 --- a/nitrogo/subscriber.go +++ b/nitrogo/subscriber.go @@ -1,5 +1,22 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + subscriberGxInterfaceURL = "/nitro/v1/config/subscribergxinterface" + subscriberParamURL = "/nitro/v1/config/subscriberparam" + subscriberProfileURL = "/nitro/v1/config/subscriberprofile" + subscriberRADIUSInterfaceURL = "/nitro/v1/config/subscriberradiusinterface" + subscriberSessionsURL = "/nitro/v1/config/subscribersessions" +) + // Subscriber configuration // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/subscriber/subscriber type SubscriberService struct { @@ -9,37 +26,415 @@ type SubscriberService struct { // subscribergxinterface // Configuration for Gx interface Parameters resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/subscriber/subscribergxinterface -func (s *SubscriberService) UpdateSubscriberGxInterface() {} -func (s *SubscriberService) UnsetSubscriberGxInterface() {} -func (s *SubscriberService) GetAllSubscriberGxInterface() {} + +func (s *SubscriberService) UpdateSubscriberGxInterface(param models.SubscriberGxInterface) error { + payload := map[string]any{ + "subscribergxinterface": param, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, subscriberGxInterfaceURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SubscriberService) UnsetSubscriberGxInterface(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "subscribergxinterface": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, subscriberGxInterfaceURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SubscriberService) GetAllSubscriberGxInterface() (models.SubscriberGxInterface, error) { + req, err := s.client.NewRequest(http.MethodGet, subscriberGxInterfaceURL, nil) + if err != nil { + return models.SubscriberGxInterface{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.SubscriberGxInterface{}, err + } + + var result struct { + SubscriberGxInterfaces []models.SubscriberGxInterface `json:"subscribergxinterface"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.SubscriberGxInterface{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.SubscriberGxInterfaces) > 0 { + return result.SubscriberGxInterfaces[0], nil + } + + return models.SubscriberGxInterface{}, nil +} // subscriberparam // Configuration for Subscriber Params resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/subscriber/subscriberparam -func (s *SubscriberService) UpdateSubscriberParam() {} -func (s *SubscriberService) UnsetSubscriberParam() {} -func (s *SubscriberService) GetAllSubscriberParam() {} + +func (s *SubscriberService) UpdateSubscriberParam(param models.SubscriberParam) error { + payload := map[string]any{ + "subscriberparam": param, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, subscriberParamURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SubscriberService) UnsetSubscriberParam(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "subscriberparam": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, subscriberParamURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SubscriberService) GetAllSubscriberParam() (models.SubscriberParam, error) { + req, err := s.client.NewRequest(http.MethodGet, subscriberParamURL, nil) + if err != nil { + return models.SubscriberParam{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.SubscriberParam{}, err + } + + var result struct { + SubscriberParams []models.SubscriberParam `json:"subscriberparam"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.SubscriberParam{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.SubscriberParams) > 0 { + return result.SubscriberParams[0], nil + } + + return models.SubscriberParam{}, nil +} // subscriberprofile // Configuration for Subscriber Profile resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/subscriber/subscriberprofile -func (s *SubscriberService) AddSubscriberProfile() {} -func (s *SubscriberService) DeleteSubscriberProfile() {} -func (s *SubscriberService) UpdateSubscriberProfile() {} -func (s *SubscriberService) UnsetSubscriberProfile() {} -func (s *SubscriberService) GetAllSubscriberProfile() {} -func (s *SubscriberService) CountSubscriberProfile() {} - -// subscriverradiusinterface + +func (s *SubscriberService) AddSubscriberProfile(profile models.SubscriberProfile) error { + payload := map[string]any{ + "subscriberprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, subscriberProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SubscriberService) DeleteSubscriberProfile(ip string) error { + url := fmt.Sprintf("%s/%s", subscriberProfileURL, ip) + req, err := s.client.NewRequest(http.MethodDelete, url, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SubscriberService) UpdateSubscriberProfile(profile models.SubscriberProfile) error { + payload := map[string]any{ + "subscriberprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, subscriberProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SubscriberService) UnsetSubscriberProfile(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "subscriberprofile": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, subscriberProfileURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SubscriberService) GetAllSubscriberProfile() ([]models.SubscriberProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, subscriberProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SubscriberProfiles []models.SubscriberProfile `json:"subscriberprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SubscriberProfiles, nil +} + +func (s *SubscriberService) CountSubscriberProfile() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, subscriberProfileURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + SubscriberProfiles []struct { + Count float64 `json:"__count"` + } `json:"subscriberprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.SubscriberProfiles) > 0 { + return result.SubscriberProfiles[0].Count, nil + } + + return 0, nil +} + +// subscriberradiusinterface // Configuration for RADIUS interface Parameters resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/subscriber/subscriberradiusinterface -func (s *SubscriberService) UpdateSubscriberRADIUSInterface() {} -func (s *SubscriberService) UnsetSubscriberRADIUSInterface() {} -func (s *SubscriberService) GetAllSubscriberRADIUSInterface() {} + +func (s *SubscriberService) UpdateSubscriberRADIUSInterface(param models.SubscriberRadiusInterface) error { + payload := map[string]any{ + "subscriberradiusinterface": param, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, subscriberRADIUSInterfaceURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SubscriberService) UnsetSubscriberRADIUSInterface(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "subscriberradiusinterface": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, subscriberRADIUSInterfaceURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SubscriberService) GetAllSubscriberRADIUSInterface() (models.SubscriberRadiusInterface, error) { + req, err := s.client.NewRequest(http.MethodGet, subscriberRADIUSInterfaceURL, nil) + if err != nil { + return models.SubscriberRadiusInterface{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.SubscriberRadiusInterface{}, err + } + + var result struct { + SubscriberRADIUSInterfaces []models.SubscriberRadiusInterface `json:"subscriberradiusinterface"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.SubscriberRadiusInterface{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.SubscriberRADIUSInterfaces) > 0 { + return result.SubscriberRADIUSInterfaces[0], nil + } + + return models.SubscriberRadiusInterface{}, nil +} // subscribersessions // Configuration for subscriber sesions resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/subscriber/subscribersessions -func (s *SubscriberService) ClearSubscriberSessions() {} -func (s *SubscriberService) GetAllSubscriberSessions() {} -func (s *SubscriberService) CountSubscriberSessions() {} + +func (s *SubscriberService) ClearSubscriberSessions(session models.SubscriberSessions) error { + payload := map[string]any{ + "subscribersessions": session, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, subscriberSessionsURL+"?action=clear", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SubscriberService) GetAllSubscriberSessions() ([]models.SubscriberSessions, error) { + req, err := s.client.NewRequest(http.MethodGet, subscriberSessionsURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SubscriberSessions []models.SubscriberSessions `json:"subscribersessions"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SubscriberSessions, nil +} + +func (s *SubscriberService) CountSubscriberSessions() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, subscriberSessionsURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + SubscriberSessions []struct { + Count float64 `json:"__count"` + } `json:"subscribersessions"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.SubscriberSessions) > 0 { + return result.SubscriberSessions[0].Count, nil + } + + return 0, nil +} diff --git a/nitrogo/system.go b/nitrogo/system.go index 009226f..b594965 100644 --- a/nitrogo/system.go +++ b/nitrogo/system.go @@ -1,13 +1,58 @@ package nitrogo import ( + "bytes" "encoding/json" "fmt" "net/http" + "strings" "github.com/AdamJCrawford/NitroGo/nitrogo/models" ) +const ( + systemAutoRestoreFeatureURL = "/nitro/v1/config/systemautorestorefeature" + systemBackupURL = "/nitro/v1/config/systembackup" + systemCmdPolicyURL = "/nitro/v1/config/systemcmdpolicy" + systemCollectionParamURL = "/nitro/v1/config/systemcollectionparam" + systemCoreURL = "/nitro/v1/config/systemcore" + systemCounterGroupURL = "/nitro/v1/config/systemcountergroup" + systemCountersURL = "/nitro/v1/config/systemcounters" + systemDataSourceURL = "/nitro/v1/config/systemdatasource" + systemEntityURL = "/nitro/v1/config/systementity" + systemEntityDataURL = "/nitro/v1/config/systementitydata" + systemEntityTypeURL = "/nitro/v1/config/systementitytype" + systemEventHistoryURL = "/nitro/v1/config/systemeventhistory" + systemExtraMgmtCPUURL = "/nitro/v1/config/systemextramgmtcpu" + systemFileURL = "/nitro/v1/config/systemfile" + systemGlobalDataURL = "/nitro/v1/config/systemglobaldata" + systemGlobalAuditNSLogPolicyBindingURL = "/nitro/v1/config/systemglobal_auditnslogpolicy_binding" + systemGlobalAuditSyslogPolicyBindingURL = "/nitro/v1/config/systemglobal_auditsyslogpolicy_binding" + systemGlobalAuthenticationLDAPPolicyBindingURL = "/nitro/v1/config/systemglobal_authenticationldappolicy_binding" + systemGlobalAuthenticationLocalPolicyBindingURL = "/nitro/v1/config/systemglobal_authenticationlocalpolicy_binding" + systemGlobalAuthenticationPolicyBindingURL = "/nitro/v1/config/systemglobal_authenticationpolicy_binding" + systemGlobalAuthenticationRADIUSPolicyBindingURL = "/nitro/v1/config/systemglobal_authenticationradiuspolicy_binding" + systemGlobalAuthenticationTACACSPolicyBindingURL = "/nitro/v1/config/systemglobal_authenticationtacacspolicy_binding" + systemGlobalBindingURL = "/nitro/v1/config/systemglobal_binding" + systemGroupURL = "/nitro/v1/config/systemgroup" + systemGroupBindingURL = "/nitro/v1/config/systemgroup_binding" + systemGroupNSPartitionBindingURL = "/nitro/v1/config/systemgroup_nspartition_binding" + systemGroupSystemCmdPolicyBindingURL = "/nitro/v1/config/systemgroup_systemcmdpolicy_binding" + systemGroupSystemUserBindingURL = "/nitro/v1/config/systemgroup_systemuser_binding" + systemHWErrorURL = "/nitro/v1/config/systemhwerror" + systemKEKURL = "/nitro/v1/config/systemkek" + systemParameterURL = "/nitro/v1/config/systemparameter" + systemRestorePointURL = "/nitro/v1/config/systemrestorepoint" + systemSessionURL = "/nitro/v1/config/systemsession" + systemSSHKeyURL = "/nitro/v1/config/systemsshkey" + systemUserURL = "/nitro/v1/config/systemuser" + systemUserBindingURL = "/nitro/v1/config/systemuser_binding" + systemUserNSPartitionBindingURL = "/nitro/v1/config/systemuser_nspartition_binding" + systemUserSystemCmdPolicyBindingURL = "/nitro/v1/config/systemuser_systemcmdpolicy_binding" + systemUserSystemGroupBindingURL = "/nitro/v1/config/systemuser_systemgroup_binding" + systemStatsURL = "/nitro/v1/stat/system" +) + // System // System configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/system/system @@ -16,261 +61,2772 @@ type SystemService struct { } // systemautorestorefeature -func (s *SystemService) EnableSystemAutoRestoreFeature() {} -func (s *SystemService) DisableSystemAutoRestoreFeature() {} +func (s *SystemService) EnableSystemAutoRestoreFeature() error { + payload := map[string]any{"systemautorestorefeature": map[string]any{}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=enable", systemAutoRestoreFeatureURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) DisableSystemAutoRestoreFeature() error { + payload := map[string]any{"systemautorestorefeature": map[string]any{}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=disable", systemAutoRestoreFeatureURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} // systembackup -func (s *SystemService) AddSystemBackup() {} -func (s *SystemService) DeleteSystemBackup() {} -func (s *SystemService) CreateSystemBackup() {} -func (s *SystemService) RestoreSystemBackup() {} -func (s *SystemService) GetAllSystemBackup() {} -func (s *SystemService) GetSystemBackup() {} -func (s *SystemService) CountSystemBackup() {} +func (s *SystemService) AddSystemBackup(resource models.SystemBackup) error { + payload := map[string]any{"systembackup": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, systemBackupURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) DeleteSystemBackup(filename string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", systemBackupURL, filename), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) CreateSystemBackup(resource models.SystemBackup) error { + payload := map[string]any{"systembackup": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=create", systemBackupURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) RestoreSystemBackup(resource models.SystemBackup) error { + payload := map[string]any{"systembackup": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=restore", systemBackupURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) GetAllSystemBackup() ([]models.SystemBackup, error) { + req, err := s.client.NewRequest(http.MethodGet, systemBackupURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemBackup []models.SystemBackup `json:"systembackup"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemBackup, nil +} + +func (s *SystemService) GetSystemBackup(filename string) (models.SystemBackup, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", systemBackupURL, filename), nil) + if err != nil { + return models.SystemBackup{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.SystemBackup{}, err + } + + var result struct { + SystemBackup []models.SystemBackup `json:"systembackup"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.SystemBackup{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.SystemBackup) == 0 { + return models.SystemBackup{}, fmt.Errorf("systembackup %s not found", filename) + } + + return result.SystemBackup[0], nil +} + +func (s *SystemService) CountSystemBackup() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", systemBackupURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + SystemBackup []models.SystemBackup `json:"systembackup"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.SystemBackup) > 0 { + return int(result.SystemBackup[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} // systemcmdpolicy -func (s *SystemService) AddSystemCmdPolicy() {} -func (s *SystemService) DeleteSystemCmdPolicy() {} -func (s *SystemService) UpdateSystemCmdPolicy() {} -func (s *SystemService) GetAllSystemCmdPolicy() {} -func (s *SystemService) GetSystemCmdPolicy() {} -func (s *SystemService) CountSystemCmdPolicy() {} +func (s *SystemService) AddSystemCmdPolicy(resource models.SystemCmdPolicy) error { + payload := map[string]any{"systemcmdpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// systemcollectionparam -func (s *SystemService) UpdateSystemCollectionParam() {} -func (s *SystemService) UnsetSystemCollectionParam() {} -func (s *SystemService) GetAllSystemCollectionParam() {} + req, err := s.client.NewRequest(http.MethodPost, systemCmdPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } -// systemcore -func (s *SystemService) GetAllSystemCore() {} + _, err = s.client.Do(req) + return err +} -// systemcountergroup -func (s *SystemService) GetAllSystemCounterGroup() {} +func (s *SystemService) DeleteSystemCmdPolicy(policyname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", systemCmdPolicyURL, policyname), nil) + if err != nil { + return err + } -// systemcounters -func (s *SystemService) GetAllSystemCounters() {} + _, err = s.client.Do(req) + return err +} -// systemdatasource -func (s *SystemService) GetAllSystemDataSource() {} +func (s *SystemService) UpdateSystemCmdPolicy(resource models.SystemCmdPolicy) error { + payload := map[string]any{"systemcmdpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// systementity -func (s *SystemService) GetAllSystemEntity() {} + req, err := s.client.NewRequest(http.MethodPut, systemCmdPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } -// systementitydata -func (s *SystemService) DeleteSystemEntityData() {} -func (s *SystemService) GetAllSystemEntityData() {} + _, err = s.client.Do(req) + return err +} -// systementitytype -func (s *SystemService) GetAllSystemEntityType() {} +func (s *SystemService) GetAllSystemCmdPolicy() ([]models.SystemCmdPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, systemCmdPolicyURL, nil) + if err != nil { + return nil, err + } -// systemeventhistory -func (s *SystemService) GetAllSystemEventHistory() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// systemextramgmtcpu -func (s *SystemService) EnableSystemExtraMgmtCPU() {} -func (s *SystemService) DisableSystemExtraMgmtCPU() {} -func (s *SystemService) GetAllSystemExtraMgmtCPU() (models.SystemExtraMgmtCPU, error) { - u := "nitro/v1/config/systemextramgmtcpu" - v := models.SystemExtraMgmtCPU{} + var result struct { + SystemCmdPolicy []models.SystemCmdPolicy `json:"systemcmdpolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemCmdPolicy, nil +} + +func (s *SystemService) GetSystemCmdPolicy(policyname string) (models.SystemCmdPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", systemCmdPolicyURL, policyname), nil) + if err != nil { + return models.SystemCmdPolicy{}, err + } - req, err := s.client.NewRequest(http.MethodGet, u, nil) + resp, err := s.client.Do(req) + if err != nil { + return models.SystemCmdPolicy{}, err + } + + var result struct { + SystemCmdPolicy []models.SystemCmdPolicy `json:"systemcmdpolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.SystemCmdPolicy{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.SystemCmdPolicy) == 0 { + return models.SystemCmdPolicy{}, fmt.Errorf("systemcmdpolicy %s not found", policyname) + } + + return result.SystemCmdPolicy[0], nil +} + +func (s *SystemService) CountSystemCmdPolicy() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", systemCmdPolicyURL), nil) if err != nil { - return v, err + return 0, err } resp, err := s.client.Do(req) if err != nil { - return v, err + return 0, err + } + + var result struct { + SystemCmdPolicy []models.SystemCmdPolicy `json:"systemcmdpolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.SystemCmdPolicy) > 0 { + return int(result.SystemCmdPolicy[0].Count), nil } + return 0, fmt.Errorf("failed to parse count") +} - data, err := json.Marshal(resp["systemextramgmtcpu"]) +// systemcollectionparam +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/system/systemcollectionparam +func (s *SystemService) UpdateSystemCollectionParam(resource models.SystemCollectionParam) error { + payload := map[string]any{"systemcollectionparam": resource} + data, err := json.Marshal(payload) if err != nil { - return v, err + return err } - err = json.Unmarshal(data, &v) + req, err := s.client.NewRequest(http.MethodPut, systemCollectionParamURL, bytes.NewReader(data)) if err != nil { - return v, fmt.Errorf("failed to unmarshal: %w", err) + return err } - return v, nil + _, err = s.client.Do(req) + return err } -// systemfile -func (s *SystemService) AddSystemFile() {} -func (s *SystemService) DeleteSystemFile() {} -func (s *SystemService) GetAllSystemFile() {} -func (s *SystemService) CountSystemFile() {} +func (s *SystemService) UnsetSystemCollectionParam(resource models.SystemCollectionParam) error { + payload := map[string]any{"systemcollectionparam": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// systemglobaldata -func (s *SystemService) GetAllSystemGlobalData() {} + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", systemCollectionParamURL), bytes.NewReader(data)) + if err != nil { + return err + } -// systemglobal_auditglobal_auditnslogpolicy_binding -func (s *SystemService) AddSystemGlobalAuditNSLogPolicyBinding() {} -func (s *SystemService) DeleteSystemGlobalAuditNSLogPolicyBinding() {} -func (s *SystemService) GetSystemGlobalAuditNSLogPolicyBinding() {} -func (s *SystemService) CountSystemGlobalAuditNSLogPolicyBinding() {} + _, err = s.client.Do(req) + return err +} -// systemglobal_auditsyslogpolicy_binding -func (s *SystemService) AddSystemGlobalAuditSyslogPolicyBinding() {} -func (s *SystemService) DeleteSystemGlobalAuditSyslogPolicyBinding() {} -func (s *SystemService) GetSystemGlobalAuditSyslogPolicyBinding() {} -func (s *SystemService) CountSystemGlobalAuditSyslogPolicyBinding() {} +func (s *SystemService) GetAllSystemCollectionParam() (models.SystemCollectionParam, error) { + req, err := s.client.NewRequest(http.MethodGet, systemCollectionParamURL, nil) + if err != nil { + return models.SystemCollectionParam{}, err + } -// systemglobal_authenticationldappolicy_binding -func (s *SystemService) AddSystemGlobalAuthenticationLDAPPolicyBinding() {} -func (s *SystemService) DeleteSystemGlobalAuthenticationLDAPPolicyBinding() {} -func (s *SystemService) GetSystemGlobalAuthenticationLDAPPolicyBinding() {} -func (s *SystemService) CountSystemGlobalAuthenticationLDAPPolicyBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return models.SystemCollectionParam{}, err + } -// systemglobal_authenticationlocalpolicy_binding -func (s *SystemService) AddSystemGlobalAuthenticationLocalPolicyBinding() {} -func (s *SystemService) DeleteSystemGlobalAuthenticationLocalPolicyBinding() {} -func (s *SystemService) GetSystemGlobalAuthenticationLocalPolicyBinding() {} -func (s *SystemService) CountSystemGlobalAuthenticationLocalPolicyBinding() {} + var result struct { + Data models.SystemCollectionParam `json:"systemcollectionparam"` + } -// systemglobal_authenticationpolicy_binding -func (s *SystemService) AddSystemGlobalAuthenticationPolicyBinding() {} -func (s *SystemService) DeleteSystemGlobalAuthenticationPolicyBinding() {} -func (s *SystemService) GetSystemGlobalAuthenticationPolicyBinding() {} -func (s *SystemService) CountSystemGlobalAuthenticationPolicyBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return models.SystemCollectionParam{}, fmt.Errorf("failed to unmarshal: %w", err) + } -// systemglobal_authenticationradiuspolicy_binding -func (s *SystemService) AddSystemGlobalAuthenticationRADIUSPolicyBinding() {} -func (s *SystemService) DeleteSystemGlobalAuthenticationRADIUSPolicyBinding() {} -func (s *SystemService) GetSystemGlobalAuthenticationRADIUSPolicyBinding() {} -func (s *SystemService) CountSystemGlobalAuthenticationRADIUSPolicyBinding() {} + return result.Data, nil +} -// systemglobal_authenticationtacacspolicy_binding -func (s *SystemService) AddSystemGlobalAuthenticationTACACSPolicyBinding() {} -func (s *SystemService) DeleteSystemGlobalAuthenticationTACACSPolicyBinding() {} -func (s *SystemService) GetSystemGlobalAuthenticationTACACSPolicyBinding() {} -func (s *SystemService) CountSystemGlobalAuthenticationTACACSPolicyBinding() {} +// systemcore +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/system/systemcore +func (s *SystemService) GetAllSystemCore(args map[string]string) ([]models.SystemCore, error) { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s%s", systemCoreURL, argsStr), nil) + if err != nil { + return nil, err + } -// systemglobal_binding -func (s *SystemService) GetSystemGlobalBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// systemgroup -func (s *SystemService) AddSystemGroup() {} -func (s *SystemService) DeleteSystemGroup() {} -func (s *SystemService) UpdateSystemGroup() {} -func (s *SystemService) UnsetSystemGroup() {} -func (s *SystemService) GetAllSystemGroup() {} -func (s *SystemService) GetSystemGroup() {} -func (s *SystemService) CountSystemGroup() {} + var result struct { + Data []models.SystemCore `json:"systemcore"` + } -// systemgroup_binding -func (s *SystemService) GetAllSystemGroupBinding() {} -func (s *SystemService) GetSystemGroupBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// systemgroup_nspartition_binding -func (s *SystemService) AddSystemGroupNSPartitionBinding() {} -func (s *SystemService) DeleteSystemGroupNSPartitionBinding() {} -func (s *SystemService) GetAllSystemGroupNSPartitionBinding() {} -func (s *SystemService) GetSystemGroupNSPartitionBinding() {} -func (s *SystemService) CountSystemGroupNSPartitionBinding() {} + return result.Data, nil +} -// systemgroup_systemcmdpolicy_binding -func (s *SystemService) AddSystemGroupSystemCmdPolicyBinding() {} -func (s *SystemService) DeleteSystemGroupSystemCmdPolicyBinding() {} -func (s *SystemService) GetAllSystemGroupSystemCmdPolicyBinding() {} -func (s *SystemService) GetSystemGroupSystemCmdPolicyBinding() {} -func (s *SystemService) CountSystemGroupSystemCmdPolicyBinding() {} +// systemcountergroup +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/system/systemcountergroup +func (s *SystemService) GetAllSystemCounterGroup(args map[string]string) ([]models.SystemCounterGroup, error) { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s%s", systemCounterGroupURL, argsStr), nil) + if err != nil { + return nil, err + } -// systemgroup_systemuser_binding -func (s *SystemService) AddSystemGroupSystemUserBinding() {} -func (s *SystemService) DeleteSystemGroupSystemUserBinding() {} -func (s *SystemService) GetAllSystemGroupSystemUserBinding() {} -func (s *SystemService) GetSystemGroupSystemUserBinding() {} -func (s *SystemService) CountSystemGroupSystemUserBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// systemhwerror -func (s *SystemService) CheckSystemHWError() {} + var result struct { + Data []models.SystemCounterGroup `json:"systemcountergroup"` + } -// systemkek -func (s *SystemService) ChangeSystemKEK() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// systemparameter -func (s *SystemService) UpdateSystemParameter() {} -func (s *SystemService) UnsetSystemParameter() {} -func (s *SystemService) GetAllSystemParameter() {} + return result.Data, nil +} -// systemrestorepoint -func (s *SystemService) CreateSystemRestorePoint() {} -func (s *SystemService) DeleteSystemRestorePoint() {} -func (s *SystemService) GetAllSystemRestorePoint() {} -func (s *SystemService) GetSystemRestorePoint() {} -func (s *SystemService) CountSystemRestorePoint() {} +// systemcounters +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/system/systemcounters +func (s *SystemService) GetAllSystemCounters(args map[string]string) ([]models.SystemCounters, error) { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s%s", systemCountersURL, argsStr), nil) + if err != nil { + return nil, err + } -// systemsession -func (s *SystemService) KillSystemSession() {} -func (s *SystemService) GetAllSystemSession() {} -func (s *SystemService) GetSystemSession() {} -func (s *SystemService) CountSystemSession() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// systemsshkey -func (s *SystemService) ImportSystemSSHKey() {} -func (s *SystemService) DeleteSystemSSHKey() {} -func (s *SystemService) GetAllSystemSSHKey() {} + var result struct { + Data []models.SystemCounters `json:"systemcounters"` + } -// systemuser -func (s *SystemService) AddSystemUser() {} -func (s *SystemService) DeleteSystemUser() {} -func (s *SystemService) UpdateSystemUser() {} -func (s *SystemService) UnsetSystemUser() {} -func (s *SystemService) GetAllSystemUser() {} -func (s *SystemService) GetSystemUser() {} -func (s *SystemService) CountSystemUser() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// systemuser_binding -func (s *SystemService) GetAllSystemUserBinding() {} -func (s *SystemService) GetSystemUserBinding() {} + return result.Data, nil +} -// systemuser_nspartition_binding -func (s *SystemService) AddSystemUserNSPartitionBinding() {} -func (s *SystemService) DeleteSystemUserNSPartitionBinding() {} -func (s *SystemService) GetAllSystemUserNSPartitionBinding() {} -func (s *SystemService) GetSystemUserNSPartitionBinding() {} -func (s *SystemService) CountSystemUserNSPartitionBinding() {} +// systemdatasource +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/system/systemdatasource +func (s *SystemService) GetAllSystemDataSource(args map[string]string) ([]models.SystemDataSource, error) { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s%s", systemDataSourceURL, argsStr), nil) + if err != nil { + return nil, err + } -// systemuser_systemcmdpolicy_binding -func (s *SystemService) AddSystemUserSystemCmdPolicyBinding() {} -func (s *SystemService) DeleteSystemUserSystemCmdPolicyBinding() {} -func (s *SystemService) GetAllSystemUserSystemCmdPolicyBinding() {} -func (s *SystemService) GetSystemUserSystemCmdPolicyBinding() {} -func (s *SystemService) CountSystemUserSystemCmdPolicyBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// systemuser_systemgroup_binding -func (s *SystemService) GetAllSystemUserSystemGroupBinding() {} -func (s *SystemService) GetSystemUserSystemGroupBinding() {} -func (s *SystemService) CountSystemUserSystemGroupBinding() {} + var result struct { + Data []models.SystemDataSource `json:"systemdatasource"` + } -// statistics + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// system -func (s *SystemService) GetAllSystemStats() (models.SystemStatus, error) { - u := "nitro/v1/stat/system" - v := models.SystemStatus{} + return result.Data, nil +} - req, err := s.client.NewRequest(http.MethodGet, u, nil) +// systementity +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/system/systementity +func (s *SystemService) GetAllSystemEntity(args map[string]string) ([]models.SystemEntity, error) { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s%s", systemEntityURL, argsStr), nil) if err != nil { - return v, err + return nil, err } resp, err := s.client.Do(req) if err != nil { - return v, err + return nil, err + } + + var result struct { + Data []models.SystemEntity `json:"systementity"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// systementitydata +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/system/systementitydata +func (s *SystemService) DeleteSystemEntityData(args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s%s", systemEntityDataURL, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) GetAllSystemEntityData(args map[string]string) ([]models.SystemEntityData, error) { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s%s", systemEntityDataURL, argsStr), nil) + if err != nil { + return nil, err } - data, err := json.Marshal(resp["system"]) + resp, err := s.client.Do(req) if err != nil { - return v, err + return nil, err + } + + var result struct { + Data []models.SystemEntityData `json:"systementitydata"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// systementitytype +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/system/systementitytype +func (s *SystemService) GetAllSystemEntityType(args map[string]string) ([]models.SystemEntityType, error) { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s%s", systemEntityTypeURL, argsStr), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.SystemEntityType `json:"systementitytype"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// systemeventhistory +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/system/systemeventhistory +func (s *SystemService) GetAllSystemEventHistory(args map[string]string) ([]models.SystemEventHistory, error) { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s%s", systemEventHistoryURL, argsStr), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.SystemEventHistory `json:"systemeventhistory"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// systemextramgmtcpu +func (s *SystemService) EnableSystemExtraMgmtCPU() error { + payload := map[string]any{"systemextramgmtcpu": map[string]any{}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=enable", systemExtraMgmtCPUURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) DisableSystemExtraMgmtCPU() error { + payload := map[string]any{"systemextramgmtcpu": map[string]any{}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=disable", systemExtraMgmtCPUURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) GetAllSystemExtraMgmtCPU() (models.SystemExtraMgmtCPU, error) { + req, err := s.client.NewRequest(http.MethodGet, systemExtraMgmtCPUURL, nil) + if err != nil { + return models.SystemExtraMgmtCPU{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.SystemExtraMgmtCPU{}, err + } + + var result struct { + ExtraMgmtCPU models.SystemExtraMgmtCPU `json:"systemextramgmtcpu"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.SystemExtraMgmtCPU{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.ExtraMgmtCPU, nil +} + +// systemfile +func (s *SystemService) AddSystemFile(resource models.SystemFile) error { + payload := map[string]any{"systemfile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, systemFileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) DeleteSystemFile(filename string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", systemFileURL, filename, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) GetAllSystemFile() ([]models.SystemFile, error) { + req, err := s.client.NewRequest(http.MethodGet, systemFileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemFile []models.SystemFile `json:"systemfile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemFile, nil +} + +func (s *SystemService) CountSystemFile() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", systemFileURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + SystemFile []models.SystemFile `json:"systemfile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.SystemFile) > 0 { + return int(result.SystemFile[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// systemglobaldata +// https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/system/systemglobaldata +func (s *SystemService) GetAllSystemGlobalData(args map[string]string) ([]models.SystemGlobalData, error) { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s%s", systemGlobalDataURL, argsStr), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.SystemGlobalData `json:"systemglobaldata"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +// systemglobal_auditnslogpolicy_binding +func (s *SystemService) AddSystemGlobalAuditNSLogPolicyBinding(resource models.SystemGlobalAuditNSLogPolicyBinding) error { + payload := map[string]any{"systemglobal_auditnslogpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, systemGlobalAuditNSLogPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) DeleteSystemGlobalAuditNSLogPolicyBinding(policyname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", systemGlobalAuditNSLogPolicyBindingURL, policyname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) GetSystemGlobalAuditNSLogPolicyBinding() ([]models.SystemGlobalAuditNSLogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, systemGlobalAuditNSLogPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemGlobalAuditNSLogPolicyBinding []models.SystemGlobalAuditNSLogPolicyBinding `json:"systemglobal_auditnslogpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemGlobalAuditNSLogPolicyBinding, nil +} + +func (s *SystemService) CountSystemGlobalAuditNSLogPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, systemGlobalAuditNSLogPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"systemglobal_auditnslogpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// systemglobal_auditsyslogpolicy_binding +func (s *SystemService) AddSystemGlobalAuditSyslogPolicyBinding(resource models.SystemGlobalAuditSyslogPolicyBinding) error { + payload := map[string]any{"systemglobal_auditsyslogpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, systemGlobalAuditSyslogPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) DeleteSystemGlobalAuditSyslogPolicyBinding(policyname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", systemGlobalAuditSyslogPolicyBindingURL, policyname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) GetSystemGlobalAuditSyslogPolicyBinding() ([]models.SystemGlobalAuditSyslogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, systemGlobalAuditSyslogPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemGlobalAuditSyslogPolicyBinding []models.SystemGlobalAuditSyslogPolicyBinding `json:"systemglobal_auditsyslogpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemGlobalAuditSyslogPolicyBinding, nil +} + +// Struct lacks Count field, leaving for later +func (s *SystemService) CountSystemGlobalAuditSyslogPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, systemGlobalAuditSyslogPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"systemglobal_auditsyslogpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// systemglobal_authenticationldappolicy_binding +func (s *SystemService) AddSystemGlobalAuthenticationLDAPPolicyBinding(resource models.SystemGlobalAuthenticationLDAPPolicyBinding) error { + payload := map[string]any{"systemglobal_authenticationldappolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, systemGlobalAuthenticationLDAPPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) DeleteSystemGlobalAuthenticationLDAPPolicyBinding(policyname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", systemGlobalAuthenticationLDAPPolicyBindingURL, policyname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) GetSystemGlobalAuthenticationLDAPPolicyBinding() ([]models.SystemGlobalAuthenticationLDAPPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, systemGlobalAuthenticationLDAPPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemGlobalAuthenticationLDAPPolicyBinding []models.SystemGlobalAuthenticationLDAPPolicyBinding `json:"systemglobal_authenticationldappolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemGlobalAuthenticationLDAPPolicyBinding, nil +} + +// Struct lacks Count field, leaving for later +func (s *SystemService) CountSystemGlobalAuthenticationLDAPPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, systemGlobalAuthenticationLDAPPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"systemglobal_authenticationldappolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// systemglobal_authenticationlocalpolicy_binding +func (s *SystemService) AddSystemGlobalAuthenticationLocalPolicyBinding(resource models.SystemGlobalAuthenticationLocalPolicyBinding) error { + payload := map[string]any{"systemglobal_authenticationlocalpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, systemGlobalAuthenticationLocalPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) DeleteSystemGlobalAuthenticationLocalPolicyBinding(policyname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", systemGlobalAuthenticationLocalPolicyBindingURL, policyname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) GetSystemGlobalAuthenticationLocalPolicyBinding() ([]models.SystemGlobalAuthenticationLocalPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, systemGlobalAuthenticationLocalPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemGlobalAuthenticationLocalPolicyBinding []models.SystemGlobalAuthenticationLocalPolicyBinding `json:"systemglobal_authenticationlocalpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemGlobalAuthenticationLocalPolicyBinding, nil +} + +// Struct lacks Count field, leaving for later +func (s *SystemService) CountSystemGlobalAuthenticationLocalPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, systemGlobalAuthenticationLocalPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"systemglobal_authenticationlocalpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// systemglobal_authenticationpolicy_binding +func (s *SystemService) AddSystemGlobalAuthenticationPolicyBinding(resource models.SystemGlobalAuthenticationPolicyBinding) error { + payload := map[string]any{"systemglobal_authenticationpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, systemGlobalAuthenticationPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) DeleteSystemGlobalAuthenticationPolicyBinding(policyname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", systemGlobalAuthenticationPolicyBindingURL, policyname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) GetSystemGlobalAuthenticationPolicyBinding() ([]models.SystemGlobalAuthenticationPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, systemGlobalAuthenticationPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemGlobalAuthenticationPolicyBinding []models.SystemGlobalAuthenticationPolicyBinding `json:"systemglobal_authenticationpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemGlobalAuthenticationPolicyBinding, nil +} + +// Struct lacks Count field, leaving for later +func (s *SystemService) CountSystemGlobalAuthenticationPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, systemGlobalAuthenticationPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"systemglobal_authenticationpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// systemglobal_authenticationradiuspolicy_binding +func (s *SystemService) AddSystemGlobalAuthenticationRADIUSPolicyBinding(resource models.SystemGlobalAuthenticationRADIUSPolicyBinding) error { + payload := map[string]any{"systemglobal_authenticationradiuspolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, systemGlobalAuthenticationRADIUSPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) DeleteSystemGlobalAuthenticationRADIUSPolicyBinding(policyname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", systemGlobalAuthenticationRADIUSPolicyBindingURL, policyname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) GetSystemGlobalAuthenticationRADIUSPolicyBinding() ([]models.SystemGlobalAuthenticationRADIUSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, systemGlobalAuthenticationRADIUSPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemGlobalAuthenticationRADIUSPolicyBinding []models.SystemGlobalAuthenticationRADIUSPolicyBinding `json:"systemglobal_authenticationradiuspolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemGlobalAuthenticationRADIUSPolicyBinding, nil +} + +// Struct lacks Count field, leaving for later +func (s *SystemService) CountSystemGlobalAuthenticationRADIUSPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, systemGlobalAuthenticationRADIUSPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"systemglobal_authenticationradiuspolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// systemglobal_authenticationtacacspolicy_binding +func (s *SystemService) AddSystemGlobalAuthenticationTACACSPolicyBinding(resource models.SystemGlobalAuthenticationTACACSPolicyBinding) error { + payload := map[string]any{"systemglobal_authenticationtacacspolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, systemGlobalAuthenticationTACACSPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) DeleteSystemGlobalAuthenticationTACACSPolicyBinding(policyname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", systemGlobalAuthenticationTACACSPolicyBindingURL, policyname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) GetSystemGlobalAuthenticationTACACSPolicyBinding() ([]models.SystemGlobalAuthenticationTACACSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, systemGlobalAuthenticationTACACSPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemGlobalAuthenticationTACACSPolicyBinding []models.SystemGlobalAuthenticationTACACSPolicyBinding `json:"systemglobal_authenticationtacacspolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemGlobalAuthenticationTACACSPolicyBinding, nil +} + +// Struct lacks Count field, leaving for later +func (s *SystemService) CountSystemGlobalAuthenticationTACACSPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, systemGlobalAuthenticationTACACSPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"systemglobal_authenticationtacacspolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// systemglobal_binding +func (s *SystemService) GetSystemGlobalBinding() (models.SystemGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, systemGlobalBindingURL, nil) + if err != nil { + return models.SystemGlobalBinding{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.SystemGlobalBinding{}, err + } + + var result struct { + SystemGlobalBinding []models.SystemGlobalBinding `json:"systemglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.SystemGlobalBinding{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.SystemGlobalBinding) == 0 { + return models.SystemGlobalBinding{}, fmt.Errorf("systemglobal_binding not found") + } + + return result.SystemGlobalBinding[0], nil +} + +// systemgroup +func (s *SystemService) AddSystemGroup(resource models.SystemGroup) error { + payload := map[string]any{"systemgroup": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, systemGroupURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) DeleteSystemGroup(groupname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", systemGroupURL, groupname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) UpdateSystemGroup(resource models.SystemGroup) error { + payload := map[string]any{"systemgroup": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, systemGroupURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) UnsetSystemGroup(resource models.SystemGroup) error { + payload := map[string]any{"systemgroup": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", systemGroupURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) GetAllSystemGroup() ([]models.SystemGroup, error) { + req, err := s.client.NewRequest(http.MethodGet, systemGroupURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemGroup []models.SystemGroup `json:"systemgroup"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemGroup, nil +} + +func (s *SystemService) GetSystemGroup(groupname string) (models.SystemGroup, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", systemGroupURL, groupname), nil) + if err != nil { + return models.SystemGroup{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.SystemGroup{}, err + } + + var result struct { + SystemGroup []models.SystemGroup `json:"systemgroup"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.SystemGroup{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.SystemGroup) == 0 { + return models.SystemGroup{}, fmt.Errorf("systemgroup %s not found", groupname) + } + + return result.SystemGroup[0], nil +} + +func (s *SystemService) CountSystemGroup() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", systemGroupURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + SystemGroup []models.SystemGroup `json:"systemgroup"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.SystemGroup) > 0 { + return int(result.SystemGroup[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// systemgroup_binding +func (s *SystemService) GetAllSystemGroupBinding() ([]models.SystemGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, systemGroupBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemGroupBinding []models.SystemGroupBinding `json:"systemgroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemGroupBinding, nil +} + +func (s *SystemService) GetSystemGroupBinding(groupname string) (models.SystemGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", systemGroupBindingURL, groupname), nil) + if err != nil { + return models.SystemGroupBinding{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.SystemGroupBinding{}, err + } + + var result struct { + SystemGroupBinding []models.SystemGroupBinding `json:"systemgroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.SystemGroupBinding{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.SystemGroupBinding) == 0 { + return models.SystemGroupBinding{}, fmt.Errorf("systemgroup_binding %s not found", groupname) + } + + return result.SystemGroupBinding[0], nil +} + +// systemgroup_nspartition_binding +func (s *SystemService) AddSystemGroupNSPartitionBinding(resource models.SystemGroupNSPartitionBinding) error { + payload := map[string]any{"systemgroup_nspartition_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, systemGroupNSPartitionBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) DeleteSystemGroupNSPartitionBinding(groupname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", systemGroupNSPartitionBindingURL, groupname, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) GetAllSystemGroupNSPartitionBinding() ([]models.SystemGroupNSPartitionBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, systemGroupNSPartitionBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemGroupNSPartitionBinding []models.SystemGroupNSPartitionBinding `json:"systemgroup_nspartition_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemGroupNSPartitionBinding, nil +} + +func (s *SystemService) GetSystemGroupNSPartitionBinding(groupname string) ([]models.SystemGroupNSPartitionBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", systemGroupNSPartitionBindingURL, groupname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemGroupNSPartitionBinding []models.SystemGroupNSPartitionBinding `json:"systemgroup_nspartition_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemGroupNSPartitionBinding, nil +} + +// Struct lacks Count field, leaving for later +func (s *SystemService) CountSystemGroupNSPartitionBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, systemGroupNSPartitionBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"systemgroup_nspartition_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// systemgroup_systemcmdpolicy_binding +func (s *SystemService) AddSystemGroupSystemCmdPolicyBinding(resource models.SystemGroupSystemCmdPolicyBinding) error { + payload := map[string]any{"systemgroup_systemcmdpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, systemGroupSystemCmdPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) DeleteSystemGroupSystemCmdPolicyBinding(groupname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", systemGroupSystemCmdPolicyBindingURL, groupname, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) GetAllSystemGroupSystemCmdPolicyBinding() ([]models.SystemGroupSystemCmdPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, systemGroupSystemCmdPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemGroupSystemCmdPolicyBinding []models.SystemGroupSystemCmdPolicyBinding `json:"systemgroup_systemcmdpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemGroupSystemCmdPolicyBinding, nil +} + +func (s *SystemService) GetSystemGroupSystemCmdPolicyBinding(groupname string) ([]models.SystemGroupSystemCmdPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", systemGroupSystemCmdPolicyBindingURL, groupname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemGroupSystemCmdPolicyBinding []models.SystemGroupSystemCmdPolicyBinding `json:"systemgroup_systemcmdpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemGroupSystemCmdPolicyBinding, nil +} + +// Struct lacks Count field, leaving for later +func (s *SystemService) CountSystemGroupSystemCmdPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, systemGroupSystemCmdPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"systemgroup_systemcmdpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// systemgroup_systemuser_binding +func (s *SystemService) AddSystemGroupSystemUserBinding(resource models.SystemGroupSystemUserBinding) error { + payload := map[string]any{"systemgroup_systemuser_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, systemGroupSystemUserBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) DeleteSystemGroupSystemUserBinding(groupname string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", systemGroupSystemUserBindingURL, groupname, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) GetAllSystemGroupSystemUserBinding() ([]models.SystemGroupSystemUserBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, systemGroupSystemUserBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemGroupSystemUserBinding []models.SystemGroupSystemUserBinding `json:"systemgroup_systemuser_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemGroupSystemUserBinding, nil +} + +func (s *SystemService) GetSystemGroupSystemUserBinding(groupname string) ([]models.SystemGroupSystemUserBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", systemGroupSystemUserBindingURL, groupname), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemGroupSystemUserBinding []models.SystemGroupSystemUserBinding `json:"systemgroup_systemuser_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemGroupSystemUserBinding, nil +} + +// Struct lacks Count field, leaving for later +func (s *SystemService) CountSystemGroupSystemUserBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, systemGroupSystemUserBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"systemgroup_systemuser_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// systemhwerror +func (s *SystemService) CheckSystemHWError() (models.SystemHWError, error) { + req, err := s.client.NewRequest(http.MethodGet, systemHWErrorURL, nil) + if err != nil { + return models.SystemHWError{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.SystemHWError{}, err + } + + var result struct { + SystemHWError []models.SystemHWError `json:"systemhwerror"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.SystemHWError{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.SystemHWError) == 0 { + return models.SystemHWError{}, fmt.Errorf("systemhwerror not found") + } + + return result.SystemHWError[0], nil +} + +// systemkek +func (s *SystemService) ChangeSystemKEK(resource models.SystemKEK) error { + payload := map[string]any{"systemkek": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, systemKEKURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +// systemparameter +func (s *SystemService) UpdateSystemParameter(resource models.SystemParameter) error { + payload := map[string]any{"systemparameter": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, systemParameterURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) UnsetSystemParameter(resource models.SystemParameter) error { + payload := map[string]any{"systemparameter": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", systemParameterURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) GetAllSystemParameter() (models.SystemParameter, error) { + req, err := s.client.NewRequest(http.MethodGet, systemParameterURL, nil) + if err != nil { + return models.SystemParameter{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.SystemParameter{}, err + } + + var result struct { + SystemParameter models.SystemParameter `json:"systemparameter"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.SystemParameter{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemParameter, nil +} + +// systemrestorepoint +func (s *SystemService) CreateSystemRestorePoint(resource models.SystemRestorePoint) error { + payload := map[string]any{"systemrestorepoint": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=create", systemRestorePointURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) DeleteSystemRestorePoint(filename string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", systemRestorePointURL, filename), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) GetAllSystemRestorePoint() ([]models.SystemRestorePoint, error) { + req, err := s.client.NewRequest(http.MethodGet, systemRestorePointURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemRestorePoint []models.SystemRestorePoint `json:"systemrestorepoint"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemRestorePoint, nil +} + +func (s *SystemService) GetSystemRestorePoint(filename string) (models.SystemRestorePoint, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", systemRestorePointURL, filename), nil) + if err != nil { + return models.SystemRestorePoint{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.SystemRestorePoint{}, err + } + + var result struct { + SystemRestorePoint []models.SystemRestorePoint `json:"systemrestorepoint"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.SystemRestorePoint{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.SystemRestorePoint) == 0 { + return models.SystemRestorePoint{}, fmt.Errorf("systemrestorepoint %s not found", filename) + } + + return result.SystemRestorePoint[0], nil +} + +func (s *SystemService) CountSystemRestorePoint() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", systemRestorePointURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + SystemRestorePoint []models.SystemRestorePoint `json:"systemrestorepoint"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.SystemRestorePoint) > 0 { + return int(result.SystemRestorePoint[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// systemsession +func (s *SystemService) KillSystemSession(resource models.SystemSession) error { + payload := map[string]any{"systemsession": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=kill", systemSessionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) GetAllSystemSession() ([]models.SystemSession, error) { + req, err := s.client.NewRequest(http.MethodGet, systemSessionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemSession []models.SystemSession `json:"systemsession"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemSession, nil +} + +func (s *SystemService) GetSystemSession(sid string) (models.SystemSession, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", systemSessionURL, sid), nil) + if err != nil { + return models.SystemSession{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.SystemSession{}, err + } + + var result struct { + SystemSession []models.SystemSession `json:"systemsession"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.SystemSession{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.SystemSession) == 0 { + return models.SystemSession{}, fmt.Errorf("systemsession %s not found", sid) + } + + return result.SystemSession[0], nil +} + +func (s *SystemService) CountSystemSession() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", systemSessionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + SystemSession []models.SystemSession `json:"systemsession"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.SystemSession) > 0 { + return int(result.SystemSession[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// systemsshkey +func (s *SystemService) ImportSystemSSHKey(resource models.SystemSSHKey) error { + payload := map[string]any{"systemsshkey": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=import", systemSSHKeyURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) DeleteSystemSSHKey(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", systemSSHKeyURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) GetAllSystemSSHKey() ([]models.SystemSSHKey, error) { + req, err := s.client.NewRequest(http.MethodGet, systemSSHKeyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemSSHKey []models.SystemSSHKey `json:"systemsshkey"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemSSHKey, nil +} + +// systemuser +func (s *SystemService) AddSystemUser(resource models.SystemUser) error { + payload := map[string]any{"systemuser": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, systemUserURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) DeleteSystemUser(username string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", systemUserURL, username), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) UpdateSystemUser(resource models.SystemUser) error { + payload := map[string]any{"systemuser": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, systemUserURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) UnsetSystemUser(resource models.SystemUser) error { + payload := map[string]any{"systemuser": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", systemUserURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) GetAllSystemUser() ([]models.SystemUser, error) { + req, err := s.client.NewRequest(http.MethodGet, systemUserURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemUser []models.SystemUser `json:"systemuser"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemUser, nil +} + +func (s *SystemService) GetSystemUser(username string) (models.SystemUser, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", systemUserURL, username), nil) + if err != nil { + return models.SystemUser{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.SystemUser{}, err + } + + var result struct { + SystemUser []models.SystemUser `json:"systemuser"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.SystemUser{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.SystemUser) == 0 { + return models.SystemUser{}, fmt.Errorf("systemuser %s not found", username) + } + + return result.SystemUser[0], nil +} + +func (s *SystemService) CountSystemUser() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", systemUserURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + SystemUser []models.SystemUser `json:"systemuser"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.SystemUser) > 0 { + return int(result.SystemUser[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// systemuser_binding +func (s *SystemService) GetAllSystemUserBinding() ([]models.SystemUserBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, systemUserBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemUserBinding []models.SystemUserBinding `json:"systemuser_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemUserBinding, nil +} + +func (s *SystemService) GetSystemUserBinding(username string) (models.SystemUserBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", systemUserBindingURL, username), nil) + if err != nil { + return models.SystemUserBinding{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.SystemUserBinding{}, err + } + + var result struct { + SystemUserBinding []models.SystemUserBinding `json:"systemuser_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.SystemUserBinding{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.SystemUserBinding) == 0 { + return models.SystemUserBinding{}, fmt.Errorf("systemuser_binding %s not found", username) + } + + return result.SystemUserBinding[0], nil +} + +// systemuser_nspartition_binding +func (s *SystemService) AddSystemUserNSPartitionBinding(resource models.SystemUserNSPartitionBinding) error { + payload := map[string]any{"systemuser_nspartition_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, systemUserNSPartitionBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) DeleteSystemUserNSPartitionBinding(username string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", systemUserNSPartitionBindingURL, username, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) GetAllSystemUserNSPartitionBinding() ([]models.SystemUserNSPartitionBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, systemUserNSPartitionBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemUserNSPartitionBinding []models.SystemUserNSPartitionBinding `json:"systemuser_nspartition_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemUserNSPartitionBinding, nil +} + +func (s *SystemService) GetSystemUserNSPartitionBinding(username string) ([]models.SystemUserNSPartitionBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", systemUserNSPartitionBindingURL, username), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemUserNSPartitionBinding []models.SystemUserNSPartitionBinding `json:"systemuser_nspartition_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemUserNSPartitionBinding, nil +} + +// Struct lacks Count field, leaving for later +func (s *SystemService) CountSystemUserNSPartitionBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, systemUserNSPartitionBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"systemuser_nspartition_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// systemuser_systemcmdpolicy_binding +func (s *SystemService) AddSystemUserSystemCmdPolicyBinding(resource models.SystemUserSystemCmdPolicyBinding) error { + payload := map[string]any{"systemuser_systemcmdpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, systemUserSystemCmdPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) DeleteSystemUserSystemCmdPolicyBinding(username string, args map[string]string) error { + var argsStr string + if len(args) > 0 { + var parts []string + for k, v := range args { + parts = append(parts, fmt.Sprintf("%s:%s", k, v)) + } + argsStr = "?args=" + strings.Join(parts, ",") + } + + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s%s", systemUserSystemCmdPolicyBindingURL, username, argsStr), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *SystemService) GetAllSystemUserSystemCmdPolicyBinding() ([]models.SystemUserSystemCmdPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, systemUserSystemCmdPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemUserSystemCmdPolicyBinding []models.SystemUserSystemCmdPolicyBinding `json:"systemuser_systemcmdpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemUserSystemCmdPolicyBinding, nil +} + +func (s *SystemService) GetSystemUserSystemCmdPolicyBinding(username string) ([]models.SystemUserSystemCmdPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", systemUserSystemCmdPolicyBindingURL, username), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemUserSystemCmdPolicyBinding []models.SystemUserSystemCmdPolicyBinding `json:"systemuser_systemcmdpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemUserSystemCmdPolicyBinding, nil +} + +// Struct lacks Count field, leaving for later +func (s *SystemService) CountSystemUserSystemCmdPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, systemUserSystemCmdPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"systemuser_systemcmdpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +// systemuser_systemgroup_binding +func (s *SystemService) GetAllSystemUserSystemGroupBinding() ([]models.SystemUserSystemGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, systemUserSystemGroupBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemUserSystemGroupBinding []models.SystemUserSystemGroupBinding `json:"systemuser_systemgroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemUserSystemGroupBinding, nil +} + +func (s *SystemService) GetSystemUserSystemGroupBinding(username string) ([]models.SystemUserSystemGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", systemUserSystemGroupBindingURL, username), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + SystemUserSystemGroupBinding []models.SystemUserSystemGroupBinding `json:"systemuser_systemgroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.SystemUserSystemGroupBinding, nil +} + +// Struct lacks Count field, leaving for later +func (s *SystemService) CountSystemUserSystemGroupBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, systemUserSystemGroupBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"systemuser_systemgroup_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} + +//////////////// +// statistics // +//////////////// + +// system +func (s *SystemService) GetAllSystemStats() (models.SystemStatus, error) { + req, err := s.client.NewRequest(http.MethodGet, systemStatsURL, nil) + if err != nil { + return models.SystemStatus{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.SystemStatus{}, err + } + + var result struct { + SystemStatus models.SystemStatus `json:"system"` } - err = json.Unmarshal(data, &v) + err = json.Unmarshal(resp, &result) if err != nil { - return v, fmt.Errorf("failed to unmarshal: %w", err) + return models.SystemStatus{}, fmt.Errorf("failed to unmarshal: %w", err) } - return v, nil + return result.SystemStatus, nil } diff --git a/nitrogo/tm.go b/nitrogo/tm.go index 42214f6..7504938 100644 --- a/nitrogo/tm.go +++ b/nitrogo/tm.go @@ -1,5 +1,39 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + tmFormSSOActionURL = "/nitro/v1/config/tmformssoaction" + tmGlobalAuditNSLogPolicyBindingURL = "/nitro/v1/config/tmglobal_auditnslogpolicy_binding" + tmGlobalAuditSyslogPolicyBindingURL = "/nitro/v1/config/tmglobal_auditsyslogpolicy_binding" + tmGlobalBindingURL = "/nitro/v1/config/tmglobal_binding" + tmGlobalTMSessionPolicyBindingURL = "/nitro/v1/config/tmglobal_tmsessionpolicy_binding" + tmGlobalTMTrafficPolicyBindingURL = "/nitro/v1/config/tmglobal_tmtrafficpolicy_binding" + tmSAMLSSOProfileURL = "/nitro/v1/config/tmsamlssoprofile" + tmSessionActionURL = "/nitro/v1/config/tmsessionaction" + tmSessionParameterURL = "/nitro/v1/config/tmsessionparameter" + tmSessionPolicyURL = "/nitro/v1/config/tmsessionpolicy" + tmSessionPolicyAAAGroupBindingURL = "/nitro/v1/config/tmsessionpolicy_aaagroup_binding" + tmSessionPolicyAAAUserBindingURL = "/nitro/v1/config/tmsessionpolicy_aaauser_binding" + tmSessionPolicyAuthenticationVServerBindingURL = "/nitro/v1/config/tmsessionpolicy_authenticationvserver_binding" + tmSessionPolicyBindingURL = "/nitro/v1/config/tmsessionpolicy_binding" + tmSessionPolicyTMGlobalBindingURL = "/nitro/v1/config/tmsessionpolicy_tmglobal_binding" + tmTrafficActionURL = "/nitro/v1/config/tmtrafficaction" + tmTrafficPolicyURL = "/nitro/v1/config/tmtrafficpolicy" + tmTrafficPolicyBindingURL = "/nitro/v1/config/tmtrafficpolicy_binding" + tmTrafficPolicyCSVServerBindingURL = "/nitro/v1/config/tmtrafficpolicy_csvserver_binding" + tmTrafficPolicyLBVServerBindingURL = "/nitro/v1/config/tmtrafficpolicy_lbvserver_binding" + tmTrafficPolicyTMGlobalBindingURL = "/nitro/v1/config/tmtrafficpolicy_tmglobal_binding" +) + // Traffic Management // TM session/policy configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/tm/tm @@ -8,130 +42,1603 @@ type TMService struct { } // tmformssoaction -func (s *TMService) AddTMFormSSOAction() {} -func (s *TMService) DeleteTMFormSSOAction() {} -func (s *TMService) UpdateTMFormSSOAction() {} -func (s *TMService) UnsetTMFormSSOAction() {} -func (s *TMService) GetAllTMFormSSOAction() {} -func (s *TMService) GetTMFormSSOAction() {} -func (s *TMService) CountTMFormSSOAction() {} +func (s *TMService) AddTMFormSSOAction(action models.TMFormSSOAction) error { + payload := map[string]any{"tmformssoaction": action} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, tmFormSSOActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) DeleteTMFormSSOAction(name string) error { + reqURL := fmt.Sprintf("%s/%s", tmFormSSOActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) UpdateTMFormSSOAction(action models.TMFormSSOAction) error { + payload := map[string]any{"tmformssoaction": action} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, tmFormSSOActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) UnsetTMFormSSOAction(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"tmformssoaction": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, tmFormSSOActionURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) GetAllTMFormSSOAction() ([]models.TMFormSSOAction, error) { + req, err := s.client.NewRequest(http.MethodGet, tmFormSSOActionURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Actions []models.TMFormSSOAction `json:"tmformssoaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Actions, nil +} + +func (s *TMService) GetTMFormSSOAction(name string) ([]models.TMFormSSOAction, error) { + reqURL := fmt.Sprintf("%s/%s", tmFormSSOActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Actions []models.TMFormSSOAction `json:"tmformssoaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Actions, nil +} + +func (s *TMService) CountTMFormSSOAction() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, tmFormSSOActionURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Actions []struct { + Count float64 `json:"__count"` + } `json:"tmformssoaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Actions) > 0 { + return result.Actions[0].Count, nil + } + return 0, nil +} // tmglobal_auditnslogpolicy_binding -func (s *TMService) AddTMGlobalAuditNSLogPolicyBinding() {} -func (s *TMService) DeleteTMGlobalAuditNSLogPolicyBinding() {} -func (s *TMService) GetTMGlobalAuditNSLogPolicyBinding() {} -func (s *TMService) CountTMGlobalAuditNSLogPolicyBinding() {} +func (s *TMService) AddTMGlobalAuditNSLogPolicyBinding(binding models.TMGlobalAuditNSLogPolicyBinding) error { + payload := map[string]any{"tmglobal_auditnslogpolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, tmGlobalAuditNSLogPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} -// tmglobal_auditsyslogpolcy_binding -func (s *TMService) AddTMGlobalAuditSyslogPolicyBinding() {} -func (s *TMService) DeleteTMGlobalAuditSyslogPolicyBinding() {} -func (s *TMService) GetTMGlobalAuditSyslogPolicyBinding() {} -func (s *TMService) CountTMGlobalAuditSyslogPolicyBinding() {} +func (s *TMService) DeleteTMGlobalAuditNSLogPolicyBinding(policyName string) error { + reqURL := fmt.Sprintf("%s?args=policyname:%s", tmGlobalAuditNSLogPolicyBindingURL, url.QueryEscape(policyName)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) GetTMGlobalAuditNSLogPolicyBinding() ([]models.TMGlobalAuditNSLogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, tmGlobalAuditNSLogPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TMGlobalAuditNSLogPolicyBinding `json:"tmglobal_auditnslogpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TMService) CountTMGlobalAuditNSLogPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, tmGlobalAuditNSLogPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"tmglobal_auditnslogpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} + +// tmglobal_auditsyslogpolicy_binding +func (s *TMService) AddTMGlobalAuditSyslogPolicyBinding(binding models.TMGlobalAuditSyslogPolicyBinding) error { + payload := map[string]any{"tmglobal_auditsyslogpolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, tmGlobalAuditSyslogPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) DeleteTMGlobalAuditSyslogPolicyBinding(policyName string) error { + reqURL := fmt.Sprintf("%s?args=policyname:%s", tmGlobalAuditSyslogPolicyBindingURL, url.QueryEscape(policyName)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) GetTMGlobalAuditSyslogPolicyBinding() ([]models.TMGlobalAuditSyslogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, tmGlobalAuditSyslogPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TMGlobalAuditSyslogPolicyBinding `json:"tmglobal_auditsyslogpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TMService) CountTMGlobalAuditSyslogPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, tmGlobalAuditSyslogPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"tmglobal_auditsyslogpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // tmglobal_binding -func (s *TMService) GetTMGlobalBinding() {} +func (s *TMService) GetTMGlobalBinding() ([]models.TMGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, tmGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TMGlobalBinding `json:"tmglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // tmglobal_tmsessionpolicy_binding -func (s *TMService) AddTMGlobalTMSessionPolicyBinding() {} -func (s *TMService) DeleteTMGlobalTMSessionPolicyBinding() {} -func (s *TMService) GetTMGlobalTMSessionPolicyBinding() {} -func (s *TMService) CountTMGlobalTMSessionPolicyBinding() {} +func (s *TMService) AddTMGlobalTMSessionPolicyBinding(binding models.TMGlobalTMSessionPolicyBinding) error { + payload := map[string]any{"tmglobal_tmsessionpolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, tmGlobalTMSessionPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) DeleteTMGlobalTMSessionPolicyBinding(policyName string) error { + reqURL := fmt.Sprintf("%s?args=policyname:%s", tmGlobalTMSessionPolicyBindingURL, url.QueryEscape(policyName)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) GetTMGlobalTMSessionPolicyBinding() ([]models.TMGlobalTMSessionPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, tmGlobalTMSessionPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TMGlobalTMSessionPolicyBinding `json:"tmglobal_tmsessionpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TMService) CountTMGlobalTMSessionPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, tmGlobalTMSessionPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"tmglobal_tmsessionpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // tmglobal_tmtrafficpolicy_binding -func (s *TMService) AddTMGlobalTMTrafficPolicyBinding() {} -func (s *TMService) DeleteTMGlobalTMTrafficPolicyBinding() {} -func (s *TMService) GetTMGlobalTMTrafficPolicyBinding() {} -func (s *TMService) CountTMGlobalTMTrafficPolicyBinding() {} +func (s *TMService) AddTMGlobalTMTrafficPolicyBinding(binding models.TMGlobalTMTrafficPolicyBinding) error { + payload := map[string]any{"tmglobal_tmtrafficpolicy_binding": binding} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, tmGlobalTMTrafficPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) DeleteTMGlobalTMTrafficPolicyBinding(policyName string) error { + reqURL := fmt.Sprintf("%s?args=policyname:%s", tmGlobalTMTrafficPolicyBindingURL, url.QueryEscape(policyName)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) GetTMGlobalTMTrafficPolicyBinding() ([]models.TMGlobalTMTrafficPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, tmGlobalTMTrafficPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TMGlobalTMTrafficPolicyBinding `json:"tmglobal_tmtrafficpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TMService) CountTMGlobalTMTrafficPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, tmGlobalTMTrafficPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"tmglobal_tmtrafficpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // tmsamlssoprofile -func (s *TMService) AddTMSAMLSSOProfile() {} -func (s *TMService) DeleteTMSAMLSSOProfile() {} -func (s *TMService) UpdateTMSAMLSSOProfile() {} -func (s *TMService) UnsetTMSAMLSSOProfile() {} -func (s *TMService) GetAllTMSAMLSSOProfile() {} -func (s *TMService) GetTMSAMLSSOProfile() {} -func (s *TMService) CountTMSAMLSSOProfile() {} +func (s *TMService) AddTMSAMLSSOProfile(profile models.TMSAMLSSOProfile) error { + payload := map[string]any{"tmsamlssoprofile": profile} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, tmSAMLSSOProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) DeleteTMSAMLSSOProfile(name string) error { + reqURL := fmt.Sprintf("%s/%s", tmSAMLSSOProfileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) UpdateTMSAMLSSOProfile(profile models.TMSAMLSSOProfile) error { + payload := map[string]any{"tmsamlssoprofile": profile} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, tmSAMLSSOProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) UnsetTMSAMLSSOProfile(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"tmsamlssoprofile": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, tmSAMLSSOProfileURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) GetAllTMSAMLSSOProfile() ([]models.TMSAMLSSOProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, tmSAMLSSOProfileURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Profiles []models.TMSAMLSSOProfile `json:"tmsamlssoprofile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Profiles, nil +} + +func (s *TMService) GetTMSAMLSSOProfile(name string) ([]models.TMSAMLSSOProfile, error) { + reqURL := fmt.Sprintf("%s/%s", tmSAMLSSOProfileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Profiles []models.TMSAMLSSOProfile `json:"tmsamlssoprofile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Profiles, nil +} + +func (s *TMService) CountTMSAMLSSOProfile() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, tmSAMLSSOProfileURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Profiles []struct { + Count float64 `json:"__count"` + } `json:"tmsamlssoprofile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Profiles) > 0 { + return result.Profiles[0].Count, nil + } + return 0, nil +} // tmsessionaction -func (s *TMService) AddTMSessionAction() {} -func (s *TMService) DeleteTMSessionAction() {} -func (s *TMService) UpdateTMSessionAction() {} -func (s *TMService) UnsetTMSessionAction() {} -func (s *TMService) GetAllTMSessionAction() {} -func (s *TMService) GetTMSessionAction() {} -func (s *TMService) CountTMSessionAction() {} +func (s *TMService) AddTMSessionAction(action models.TMSessionAction) error { + payload := map[string]any{"tmsessionaction": action} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, tmSessionActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) DeleteTMSessionAction(name string) error { + reqURL := fmt.Sprintf("%s/%s", tmSessionActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) UpdateTMSessionAction(action models.TMSessionAction) error { + payload := map[string]any{"tmsessionaction": action} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, tmSessionActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) UnsetTMSessionAction(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"tmsessionaction": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, tmSessionActionURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) GetAllTMSessionAction() ([]models.TMSessionAction, error) { + req, err := s.client.NewRequest(http.MethodGet, tmSessionActionURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Actions []models.TMSessionAction `json:"tmsessionaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Actions, nil +} + +func (s *TMService) GetTMSessionAction(name string) ([]models.TMSessionAction, error) { + reqURL := fmt.Sprintf("%s/%s", tmSessionActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Actions []models.TMSessionAction `json:"tmsessionaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Actions, nil +} + +func (s *TMService) CountTMSessionAction() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, tmSessionActionURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Actions []struct { + Count float64 `json:"__count"` + } `json:"tmsessionaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Actions) > 0 { + return result.Actions[0].Count, nil + } + return 0, nil +} // tmsessionparameter -func (s *TMService) UpdateTMSessonParameter() {} -func (s *TMService) UnsetTMSessonParameter() {} -func (s *TMService) GetAllTMSessonParameter() {} +func (s *TMService) UpdateTMSessionParameter(param models.TMSessionParameter) error { + payload := map[string]any{"tmsessionparameter": param} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, tmSessionParameterURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) UnsetTMSessionParameter(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"tmsessionparameter": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, tmSessionParameterURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) GetAllTMSessionParameter() (models.TMSessionParameter, error) { + req, err := s.client.NewRequest(http.MethodGet, tmSessionParameterURL, nil) + if err != nil { + return models.TMSessionParameter{}, err + } + resp, err := s.client.Do(req) + if err != nil { + return models.TMSessionParameter{}, err + } + var result struct { + Params []models.TMSessionParameter `json:"tmsessionparameter"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return models.TMSessionParameter{}, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Params) > 0 { + return result.Params[0], nil + } + return models.TMSessionParameter{}, nil +} // tmsessionpolicy -func (s *TMService) AddTMSessionPolicy() {} -func (s *TMService) DeleteTMSessionPolicy() {} -func (s *TMService) UpdateTMSessionPolicy() {} -func (s *TMService) UnsetTMSessionPolicy() {} -func (s *TMService) GetAllTMSessionPolicy() {} -func (s *TMService) GetTMSessionPolicy() {} -func (s *TMService) CountTMSessionPolicy() {} +func (s *TMService) AddTMSessionPolicy(policy models.TMSessionPolicy) error { + payload := map[string]any{"tmsessionpolicy": policy} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, tmSessionPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) DeleteTMSessionPolicy(name string) error { + reqURL := fmt.Sprintf("%s/%s", tmSessionPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) UpdateTMSessionPolicy(policy models.TMSessionPolicy) error { + payload := map[string]any{"tmsessionpolicy": policy} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, tmSessionPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) UnsetTMSessionPolicy(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"tmsessionpolicy": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, tmSessionPolicyURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) GetAllTMSessionPolicy() ([]models.TMSessionPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, tmSessionPolicyURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Policies []models.TMSessionPolicy `json:"tmsessionpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Policies, nil +} + +func (s *TMService) GetTMSessionPolicy(name string) ([]models.TMSessionPolicy, error) { + reqURL := fmt.Sprintf("%s/%s", tmSessionPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Policies []models.TMSessionPolicy `json:"tmsessionpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Policies, nil +} + +func (s *TMService) CountTMSessionPolicy() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, tmSessionPolicyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Policies []struct { + Count float64 `json:"__count"` + } `json:"tmsessionpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Policies) > 0 { + return result.Policies[0].Count, nil + } + return 0, nil +} // tmsessionpolicy_aaagroup_binding -func (s *TMService) GetAllTMSessionPolicyAAAGroupBinding() {} -func (s *TMService) GetTMSessionPolicyAAAGroupBinding() {} -func (s *TMService) CountTMSessionPolicyAAAGroupBinding() {} +func (s *TMService) GetAllTMSessionPolicyAAAGroupBinding() ([]models.TMSessionPolicyAAAGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, tmSessionPolicyAAAGroupBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TMSessionPolicyAAAGroupBinding `json:"tmsessionpolicy_aaagroup_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TMService) GetTMSessionPolicyAAAGroupBinding(name string) ([]models.TMSessionPolicyAAAGroupBinding, error) { + reqURL := fmt.Sprintf("%s/%s", tmSessionPolicyAAAGroupBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TMSessionPolicyAAAGroupBinding `json:"tmsessionpolicy_aaagroup_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TMService) CountTMSessionPolicyAAAGroupBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", tmSessionPolicyAAAGroupBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"tmsessionpolicy_aaagroup_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // tmsessionpolicy_aaauser_binding -func (s *TMService) GetAllTMSessionPolicyAAAUserBinding() {} -func (s *TMService) GetTMSessionPolicyAAAUserBinding() {} -func (s *TMService) CountTMSessionPolicyAAAUserBinding() {} +func (s *TMService) GetAllTMSessionPolicyAAAUserBinding() ([]models.TMSessionPolicyAAAUserBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, tmSessionPolicyAAAUserBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TMSessionPolicyAAAUserBinding `json:"tmsessionpolicy_aaauser_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} -// tmsesisonpolicy_authenticationvserver_binding -func (s *TMService) GetAllTMSessionPolicyAuthenticationVServerBinding() {} -func (s *TMService) GetTMSessionPolicyAuthenticationVServerBinding() {} -func (s *TMService) CountTMSessionPolicyAuthenticationVServerBinding() {} +func (s *TMService) GetTMSessionPolicyAAAUserBinding(name string) ([]models.TMSessionPolicyAAAUserBinding, error) { + reqURL := fmt.Sprintf("%s/%s", tmSessionPolicyAAAUserBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TMSessionPolicyAAAUserBinding `json:"tmsessionpolicy_aaauser_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TMService) CountTMSessionPolicyAAAUserBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", tmSessionPolicyAAAUserBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"tmsessionpolicy_aaauser_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} + +// tmsessionpolicy_authenticationvserver_binding +func (s *TMService) GetAllTMSessionPolicyAuthenticationVServerBinding() ([]models.TMSessionPolicyAuthenticationVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, tmSessionPolicyAuthenticationVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TMSessionPolicyAuthenticationVServerBinding `json:"tmsessionpolicy_authenticationvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TMService) GetTMSessionPolicyAuthenticationVServerBinding(name string) ([]models.TMSessionPolicyAuthenticationVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", tmSessionPolicyAuthenticationVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TMSessionPolicyAuthenticationVServerBinding `json:"tmsessionpolicy_authenticationvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TMService) CountTMSessionPolicyAuthenticationVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", tmSessionPolicyAuthenticationVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"tmsessionpolicy_authenticationvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // tmsessionpolicy_binding -func (s *TMService) GetAllTMSessionPolicyBinding() {} -func (s *TMService) GetTMSessionPolicyBinding() {} +func (s *TMService) GetAllTMSessionPolicyBinding() ([]models.TMSessionPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, tmSessionPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TMSessionPolicyBinding `json:"tmsessionpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TMService) GetTMSessionPolicyBinding(name string) ([]models.TMSessionPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", tmSessionPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TMSessionPolicyBinding `json:"tmsessionpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // tmsessionpolicy_tmglobal_binding -func (s *TMService) GetAllTMSessionPolicyTMGlobalBinding() {} -func (s *TMService) GetTMSessionPolicyTMGlobalBinding() {} -func (s *TMService) CountTMSessionPolicyTMGlobalBinding() {} +func (s *TMService) GetAllTMSessionPolicyTMGlobalBinding() ([]models.TMSessionPolicyTMGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, tmSessionPolicyTMGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TMSessionPolicyTMGlobalBinding `json:"tmsessionpolicy_tmglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TMService) GetTMSessionPolicyTMGlobalBinding(name string) ([]models.TMSessionPolicyTMGlobalBinding, error) { + reqURL := fmt.Sprintf("%s/%s", tmSessionPolicyTMGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TMSessionPolicyTMGlobalBinding `json:"tmsessionpolicy_tmglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TMService) CountTMSessionPolicyTMGlobalBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", tmSessionPolicyTMGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"tmsessionpolicy_tmglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // tmtrafficaction -func (s *TMService) AddTMTrafficAction() {} -func (s *TMService) DeleteTMTrafficAction() {} -func (s *TMService) UpdateTMTrafficAction() {} -func (s *TMService) UnsetTMTrafficAction() {} -func (s *TMService) GetAllTMTrafficAction() {} -func (s *TMService) GetTMTrafficAction() {} -func (s *TMService) CountTMTrafficAction() {} +func (s *TMService) AddTMTrafficAction(action models.TMTrafficAction) error { + payload := map[string]any{"tmtrafficaction": action} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, tmTrafficActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) DeleteTMTrafficAction(name string) error { + reqURL := fmt.Sprintf("%s/%s", tmTrafficActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) UpdateTMTrafficAction(action models.TMTrafficAction) error { + payload := map[string]any{"tmtrafficaction": action} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, tmTrafficActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) UnsetTMTrafficAction(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"tmtrafficaction": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, tmTrafficActionURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) GetAllTMTrafficAction() ([]models.TMTrafficAction, error) { + req, err := s.client.NewRequest(http.MethodGet, tmTrafficActionURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Actions []models.TMTrafficAction `json:"tmtrafficaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Actions, nil +} + +func (s *TMService) GetTMTrafficAction(name string) ([]models.TMTrafficAction, error) { + reqURL := fmt.Sprintf("%s/%s", tmTrafficActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Actions []models.TMTrafficAction `json:"tmtrafficaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Actions, nil +} + +func (s *TMService) CountTMTrafficAction() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, tmTrafficActionURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Actions []struct { + Count float64 `json:"__count"` + } `json:"tmtrafficaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Actions) > 0 { + return result.Actions[0].Count, nil + } + return 0, nil +} // tmtrafficpolicy -func (s *TMService) AddTMTrafficPolicy() {} -func (s *TMService) DeleteTMTrafficPolicy() {} -func (s *TMService) UpdateTMTrafficPolicy() {} -func (s *TMService) UnsetTMTrafficPolicy() {} -func (s *TMService) GetAllTMTrafficPolicy() {} -func (s *TMService) GetTMTrafficPolicy() {} -func (s *TMService) CountTMTrafficPolicy() {} +func (s *TMService) AddTMTrafficPolicy(policy models.TMTrafficPolicy) error { + payload := map[string]any{"tmtrafficpolicy": policy} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, tmTrafficPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) DeleteTMTrafficPolicy(name string) error { + reqURL := fmt.Sprintf("%s/%s", tmTrafficPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) UpdateTMTrafficPolicy(policy models.TMTrafficPolicy) error { + payload := map[string]any{"tmtrafficpolicy": policy} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, tmTrafficPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) UnsetTMTrafficPolicy(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{"tmtrafficpolicy": unsetMap} + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, tmTrafficPolicyURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TMService) GetAllTMTrafficPolicy() ([]models.TMTrafficPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, tmTrafficPolicyURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Policies []models.TMTrafficPolicy `json:"tmtrafficpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Policies, nil +} + +func (s *TMService) GetTMTrafficPolicy(name string) ([]models.TMTrafficPolicy, error) { + reqURL := fmt.Sprintf("%s/%s", tmTrafficPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Policies []models.TMTrafficPolicy `json:"tmtrafficpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Policies, nil +} + +func (s *TMService) CountTMTrafficPolicy() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, tmTrafficPolicyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Policies []struct { + Count float64 `json:"__count"` + } `json:"tmtrafficpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Policies) > 0 { + return result.Policies[0].Count, nil + } + return 0, nil +} // tmtrafficpolicy_binding -func (s *TMService) GetAllTMTrafficPolicyBinding() {} -func (s *TMService) GetTMTrafficPolicyBinding() {} +func (s *TMService) GetAllTMTrafficPolicyBinding() ([]models.TMTrafficPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, tmTrafficPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TMTrafficPolicyBinding `json:"tmtrafficpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TMService) GetTMTrafficPolicyBinding(name string) ([]models.TMTrafficPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", tmTrafficPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TMTrafficPolicyBinding `json:"tmtrafficpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // tmtrafficpolicy_csvserver_binding -func (s *TMService) GetAllTMTrafficPolicyCSVServerBinding() {} -func (s *TMService) GetTMTrafficPolicyCSVServerBinding() {} -func (s *TMService) CountTMTrafficPolicyCSVServerBinding() {} +func (s *TMService) GetAllTMTrafficPolicyCSVServerBinding() ([]models.TMTrafficPolicyCSVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, tmTrafficPolicyCSVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TMTrafficPolicyCSVServerBinding `json:"tmtrafficpolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TMService) GetTMTrafficPolicyCSVServerBinding(name string) ([]models.TMTrafficPolicyCSVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", tmTrafficPolicyCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TMTrafficPolicyCSVServerBinding `json:"tmtrafficpolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TMService) CountTMTrafficPolicyCSVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", tmTrafficPolicyCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"tmtrafficpolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // tmtrafficpolicy_lbvserver_binding -func (s *TMService) GetAllTMTrafficPolicyLBVServerBinding() {} -func (s *TMService) GetTMTrafficPolicyLBVServerBinding() {} -func (s *TMService) CountTMTrafficPolicyLBVServerBinding() {} +func (s *TMService) GetAllTMTrafficPolicyLBVServerBinding() ([]models.TMTrafficPolicyLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, tmTrafficPolicyLBVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TMTrafficPolicyLBVServerBinding `json:"tmtrafficpolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TMService) GetTMTrafficPolicyLBVServerBinding(name string) ([]models.TMTrafficPolicyLBVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", tmTrafficPolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TMTrafficPolicyLBVServerBinding `json:"tmtrafficpolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TMService) CountTMTrafficPolicyLBVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", tmTrafficPolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"tmtrafficpolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // tmtrafficpolicy_tmglobal_binding -func (s *TMService) GetAllTMTrafficPolicyTMGlobalBinding() {} -func (s *TMService) GetTMTrafficPolicyTMGlobalBinding() {} -func (s *TMService) CountTMTrafficPolicyTMGlobalBinding() {} +func (s *TMService) GetAllTMTrafficPolicyTMGlobalBinding() ([]models.TMTrafficPolicyTMGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, tmTrafficPolicyTMGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TMTrafficPolicyTMGlobalBinding `json:"tmtrafficpolicy_tmglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TMService) GetTMTrafficPolicyTMGlobalBinding(name string) ([]models.TMTrafficPolicyTMGlobalBinding, error) { + reqURL := fmt.Sprintf("%s/%s", tmTrafficPolicyTMGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TMTrafficPolicyTMGlobalBinding `json:"tmtrafficpolicy_tmglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TMService) CountTMTrafficPolicyTMGlobalBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", tmTrafficPolicyTMGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"tmtrafficpolicy_tmglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} diff --git a/nitrogo/transform.go b/nitrogo/transform.go index fd8a481..caad108 100644 --- a/nitrogo/transform.go +++ b/nitrogo/transform.go @@ -1,5 +1,34 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + transformActionURL = "/nitro/v1/config/transformaction" + transformGlobalBindingURL = "/nitro/v1/config/transformglobal_binding" + transformGlobalTransformPolicyBindingURL = "/nitro/v1/config/transformglobal_transformpolicy_binding" + transformPolicyURL = "/nitro/v1/config/transformpolicy" + transformPolicyLabelURL = "/nitro/v1/config/transformpolicylabel" + transformPolicyLabelBindingURL = "/nitro/v1/config/transformpolicylabel_binding" + transformPolicyLabelPolicyBindingBindingURL = "/nitro/v1/config/transformpolicylabel_policybinding_binding" + transformPolicyLabelTransformPolicyBindingURL = "/nitro/v1/config/transformpolicylabel_transformpolicy_binding" + transformPolicyBindingURL = "/nitro/v1/config/transformpolicy_binding" + transformPolicyCSVServerBindingURL = "/nitro/v1/config/transformpolicy_csvserver_binding" + transformPolicyLBVServerBindingURL = "/nitro/v1/config/transformpolicy_lbvserver_binding" + transformPolicyTransformGlobalBindingURL = "/nitro/v1/config/transformpolicy_transformglobal_binding" + transformPolicyTransformPolicyLabelBindingURL = "/nitro/v1/config/transformpolicy_transformpolicylabel_binding" + transformProfileURL = "/nitro/v1/config/transformprofile" + transformProfileBindingURL = "/nitro/v1/config/transformprofile_binding" + transformProfileTransformActionBindingURL = "/nitro/v1/config/transformprofile_transformaction_binding" +) + // Transform // URL Transformation configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/transform/transform @@ -8,95 +37,1214 @@ type TransformService struct { } // transformaction -func (s *TransformService) AddTransformAction() {} -func (s *TransformService) DeleteTransformAction() {} -func (s *TransformService) UpdateTransformAction() {} -func (s *TransformService) UnsetTransformAction() {} -func (s *TransformService) GetAllTransformAction() {} -func (s *TransformService) GetTransformAction() {} -func (s *TransformService) CountTransformAction() {} + +func (s *TransformService) AddTransformAction(action models.TransformAction) error { + payload := map[string]any{ + "transformaction": action, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, transformActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TransformService) DeleteTransformAction(name string) error { + reqURL := fmt.Sprintf("%s/%s", transformActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TransformService) UpdateTransformAction(action models.TransformAction) error { + payload := map[string]any{ + "transformaction": action, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, transformActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TransformService) UnsetTransformAction(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{ + "transformaction": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, transformActionURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TransformService) GetAllTransformAction() ([]models.TransformAction, error) { + req, err := s.client.NewRequest(http.MethodGet, transformActionURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Actions []models.TransformAction `json:"transformaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Actions, nil +} + +func (s *TransformService) GetTransformAction(name string) ([]models.TransformAction, error) { + reqURL := fmt.Sprintf("%s/%s", transformActionURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Actions []models.TransformAction `json:"transformaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Actions, nil +} + +func (s *TransformService) CountTransformAction() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, transformActionURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Actions []struct { + Count float64 `json:"__count"` + } `json:"transformaction"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Actions) > 0 { + return result.Actions[0].Count, nil + } + return 0, nil +} // transformglobal_binding -func (s *TransformService) GetTransformGlobalBinding() {} + +func (s *TransformService) GetTransformGlobalBinding() ([]models.TransformGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, transformGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TransformGlobalBinding `json:"transformglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // transformglobal_transformpolicy_binding -func (s *TransformService) AddTransformGlobalTransformPolicyBinding() {} -func (s *TransformService) DeleteTransformGlobalTransformPolicyBinding() {} -func (s *TransformService) GetTransformGlobalTransformPolicyBinding() {} -func (s *TransformService) CountTransformGlobalTransformPolicyBinding() {} + +func (s *TransformService) AddTransformGlobalTransformPolicyBinding(binding models.TransformGlobalTransformPolicyBinding) error { + payload := map[string]any{ + "transformglobal_transformpolicy_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, transformGlobalTransformPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TransformService) DeleteTransformGlobalTransformPolicyBinding(policyname string, typeField string, priority int) error { + reqURL := fmt.Sprintf("%s?args=policyname:%s,type:%s,priority:%d", transformGlobalTransformPolicyBindingURL, url.QueryEscape(policyname), url.QueryEscape(typeField), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TransformService) GetTransformGlobalTransformPolicyBinding() ([]models.TransformGlobalTransformPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, transformGlobalTransformPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TransformGlobalTransformPolicyBinding `json:"transformglobal_transformpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TransformService) CountTransformGlobalTransformPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, transformGlobalTransformPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"transformglobal_transformpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // transformpolicy -func (s *TransformService) AddTransformPolicy() {} -func (s *TransformService) DeleteTransformPolicy() {} -func (s *TransformService) UpdateTransformPolicy() {} -func (s *TransformService) UnsetTransformPolicy() {} -func (s *TransformService) RenameTransformPolicy() {} -func (s *TransformService) GetAllTransformPolicy() {} -func (s *TransformService) GetTransformPolicy() {} -func (s *TransformService) CountTransformPolicy() {} + +func (s *TransformService) AddTransformPolicy(policy models.TransformPolicy) error { + payload := map[string]any{ + "transformpolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, transformPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TransformService) DeleteTransformPolicy(name string) error { + reqURL := fmt.Sprintf("%s/%s", transformPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TransformService) UpdateTransformPolicy(policy models.TransformPolicy) error { + payload := map[string]any{ + "transformpolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, transformPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TransformService) UnsetTransformPolicy(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{ + "transformpolicy": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, transformPolicyURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TransformService) RenameTransformPolicy(name, newname string) error { + payload := map[string]any{ + "transformpolicy": map[string]string{ + "name": name, + "newname": newname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, transformPolicyURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TransformService) GetAllTransformPolicy() ([]models.TransformPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, transformPolicyURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Policies []models.TransformPolicy `json:"transformpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Policies, nil +} + +func (s *TransformService) GetTransformPolicy(name string) ([]models.TransformPolicy, error) { + reqURL := fmt.Sprintf("%s/%s", transformPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Policies []models.TransformPolicy `json:"transformpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Policies, nil +} + +func (s *TransformService) CountTransformPolicy() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, transformPolicyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Policies []struct { + Count float64 `json:"__count"` + } `json:"transformpolicy"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Policies) > 0 { + return result.Policies[0].Count, nil + } + return 0, nil +} // transformpolicylabel -func (s *TransformService) AddTransformPolicyLabel() {} -func (s *TransformService) DeleteTransformPolicyLabel() {} -func (s *TransformService) RenameTransformPolicyLabel() {} -func (s *TransformService) GetAllTransformPolicyLabel() {} -func (s *TransformService) GetTransformPolicyLabel() {} -func (s *TransformService) CountTransformPolicyLabel() {} + +func (s *TransformService) AddTransformPolicyLabel(label models.TransformPolicyLabel) error { + payload := map[string]any{ + "transformpolicylabel": label, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, transformPolicyLabelURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TransformService) DeleteTransformPolicyLabel(labelname string) error { + reqURL := fmt.Sprintf("%s/%s", transformPolicyLabelURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TransformService) RenameTransformPolicyLabel(labelname, newname string) error { + payload := map[string]any{ + "transformpolicylabel": map[string]string{ + "labelname": labelname, + "newname": newname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, transformPolicyLabelURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TransformService) GetAllTransformPolicyLabel() ([]models.TransformPolicyLabel, error) { + req, err := s.client.NewRequest(http.MethodGet, transformPolicyLabelURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Labels []models.TransformPolicyLabel `json:"transformpolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Labels, nil +} + +func (s *TransformService) GetTransformPolicyLabel(labelname string) ([]models.TransformPolicyLabel, error) { + reqURL := fmt.Sprintf("%s/%s", transformPolicyLabelURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Labels []models.TransformPolicyLabel `json:"transformpolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Labels, nil +} + +func (s *TransformService) CountTransformPolicyLabel() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, transformPolicyLabelURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Labels []struct { + Count float64 `json:"__count"` + } `json:"transformpolicylabel"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Labels) > 0 { + return result.Labels[0].Count, nil + } + return 0, nil +} // transformpolicylabel_binding -func (s *TransformService) GetAllTransformPolicyLabelBinding() {} -func (s *TransformService) GetTransformPolicyLabelBinding() {} + +func (s *TransformService) GetAllTransformPolicyLabelBinding() ([]models.TransformPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, transformPolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TransformPolicyLabelBinding `json:"transformpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TransformService) GetTransformPolicyLabelBinding(labelname string) ([]models.TransformPolicyLabelBinding, error) { + reqURL := fmt.Sprintf("%s/%s", transformPolicyLabelBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TransformPolicyLabelBinding `json:"transformpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // transformpolicylabel_policybinding_binding -func (s *TransformService) GetAllTransformPolicyLabelPolicyBindingBinding() {} -func (s *TransformService) GetTransformPolicyLabelPolicyBindingBinding() {} -func (s *TransformService) CountTransformPolicyLabelPolicyBindingBinding() {} -// transformpolicytlabel_transformpolicy_binding -func (s *TransformService) AddTransformPolicyLabelTransformPolicyBinding() {} -func (s *TransformService) DeleteTransformPolicyLabelTransformPolicyBinding() {} -func (s *TransformService) GetAllTransformPolicyLabelTransformPolicyBinding() {} -func (s *TransformService) GetTransformPolicyLabelTransformPolicyBinding() {} -func (s *TransformService) CountTransformPolicyLabelTransformPolicyBinding() {} +func (s *TransformService) GetAllTransformPolicyLabelPolicyBindingBinding() ([]models.TransformPolicyLabelPolicyBindingBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, transformPolicyLabelPolicyBindingBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TransformPolicyLabelPolicyBindingBinding `json:"transformpolicylabel_policybinding_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TransformService) GetTransformPolicyLabelPolicyBindingBinding(labelname string) ([]models.TransformPolicyLabelPolicyBindingBinding, error) { + reqURL := fmt.Sprintf("%s/%s", transformPolicyLabelPolicyBindingBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TransformPolicyLabelPolicyBindingBinding `json:"transformpolicylabel_policybinding_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TransformService) CountTransformPolicyLabelPolicyBindingBinding(labelname string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", transformPolicyLabelPolicyBindingBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"transformpolicylabel_policybinding_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} + +// transformpolicylabel_transformpolicy_binding + +func (s *TransformService) AddTransformPolicyLabelTransformPolicyBinding(binding models.TransformPolicyLabelTransformPolicyBinding) error { + payload := map[string]any{ + "transformpolicylabel_transformpolicy_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, transformPolicyLabelTransformPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TransformService) DeleteTransformPolicyLabelTransformPolicyBinding(labelname, policyname string, priority int) error { + reqURL := fmt.Sprintf("%s/%s?args=policyname:%s,priority:%d", transformPolicyLabelTransformPolicyBindingURL, url.QueryEscape(labelname), url.QueryEscape(policyname), priority) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TransformService) GetAllTransformPolicyLabelTransformPolicyBinding() ([]models.TransformPolicyLabelTransformPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, transformPolicyLabelTransformPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TransformPolicyLabelTransformPolicyBinding `json:"transformpolicylabel_transformpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TransformService) GetTransformPolicyLabelTransformPolicyBinding(labelname string) ([]models.TransformPolicyLabelTransformPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", transformPolicyLabelTransformPolicyBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TransformPolicyLabelTransformPolicyBinding `json:"transformpolicylabel_transformpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TransformService) CountTransformPolicyLabelTransformPolicyBinding(labelname string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", transformPolicyLabelTransformPolicyBindingURL, url.QueryEscape(labelname)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"transformpolicylabel_transformpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // transformpolicy_binding -func (s *TransformService) GetAllTransformPolicyBinding() {} -func (s *TransformService) GetTransformPolicyBinding() {} + +func (s *TransformService) GetAllTransformPolicyBinding() ([]models.TransformPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, transformPolicyBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TransformPolicyBinding `json:"transformpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TransformService) GetTransformPolicyBinding(name string) ([]models.TransformPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", transformPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TransformPolicyBinding `json:"transformpolicy_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // transformpolicy_csvserver_binding -func (s *TransformService) GetAllTransformPolicyCSVServerBinding() {} -func (s *TransformService) GetTransformPolicyCSVServerBinding() {} -func (s *TransformService) CountTransformPolicyCSVServerBinding() {} + +func (s *TransformService) GetAllTransformPolicyCSVServerBinding() ([]models.TransformPolicyCSVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, transformPolicyCSVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TransformPolicyCSVServerBinding `json:"transformpolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TransformService) GetTransformPolicyCSVServerBinding(name string) ([]models.TransformPolicyCSVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", transformPolicyCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TransformPolicyCSVServerBinding `json:"transformpolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TransformService) CountTransformPolicyCSVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", transformPolicyCSVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"transformpolicy_csvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // transformpolicy_lbvserver_binding -func (s *TransformService) GetAllTransformPolicyLBVServerBinding() {} -func (s *TransformService) GetTransformPolicyLBVServerBinding() {} -func (s *TransformService) CountTransformPolicyLBVServerBinding() {} + +func (s *TransformService) GetAllTransformPolicyLBVServerBinding() ([]models.TransformPolicyLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, transformPolicyLBVServerBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TransformPolicyLBVServerBinding `json:"transformpolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TransformService) GetTransformPolicyLBVServerBinding(name string) ([]models.TransformPolicyLBVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", transformPolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TransformPolicyLBVServerBinding `json:"transformpolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TransformService) CountTransformPolicyLBVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", transformPolicyLBVServerBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"transformpolicy_lbvserver_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // transformpolicy_transformglobal_binding -func (s *TransformService) GetAllTransformPolicyTransformGlobalBinding() {} -func (s *TransformService) GetTransformPolicyTransformGlobalBinding() {} -func (s *TransformService) CountTransformPolicyTransformGlobalBinding() {} + +func (s *TransformService) GetAllTransformPolicyTransformGlobalBinding() ([]models.TransformPolicyTransformGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, transformPolicyTransformGlobalBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TransformPolicyTransformGlobalBinding `json:"transformpolicy_transformglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TransformService) GetTransformPolicyTransformGlobalBinding(name string) ([]models.TransformPolicyTransformGlobalBinding, error) { + reqURL := fmt.Sprintf("%s/%s", transformPolicyTransformGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TransformPolicyTransformGlobalBinding `json:"transformpolicy_transformglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TransformService) CountTransformPolicyTransformGlobalBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", transformPolicyTransformGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"transformpolicy_transformglobal_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // transformpolicy_transformpolicylabel_binding -func (s *TransformService) GetAllTransformPolicyTransformPolicyLabelBinding() {} -func (s *TransformService) GetTransformPolicyTransformPolicyLabelBinding() {} -func (s *TransformService) CountTransformPolicyTransformPolicyLabelBinding() {} + +func (s *TransformService) GetAllTransformPolicyTransformPolicyLabelBinding() ([]models.TransformPolicyTransformPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, transformPolicyTransformPolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TransformPolicyTransformPolicyLabelBinding `json:"transformpolicy_transformpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TransformService) GetTransformPolicyTransformPolicyLabelBinding(name string) ([]models.TransformPolicyTransformPolicyLabelBinding, error) { + reqURL := fmt.Sprintf("%s/%s", transformPolicyTransformPolicyLabelBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TransformPolicyTransformPolicyLabelBinding `json:"transformpolicy_transformpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TransformService) CountTransformPolicyTransformPolicyLabelBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", transformPolicyTransformPolicyLabelBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"transformpolicy_transformpolicylabel_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} // transformprofile -func (s *TransformService) AddTransformProfile() {} -func (s *TransformService) DeleteTransformProfile() {} -func (s *TransformService) UpdateTransformProfile() {} -func (s *TransformService) UnsetTransformProfile() {} -func (s *TransformService) GetAllTransformProfile() {} -func (s *TransformService) GetTransformProfile() {} -func (s *TransformService) CountTransformProfile() {} + +func (s *TransformService) AddTransformProfile(profile models.TransformProfile) error { + payload := map[string]any{ + "transformprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, transformProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TransformService) DeleteTransformProfile(name string) error { + reqURL := fmt.Sprintf("%s/%s", transformProfileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TransformService) UpdateTransformProfile(profile models.TransformProfile) error { + payload := map[string]any{ + "transformprofile": profile, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPut, transformProfileURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TransformService) UnsetTransformProfile(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + payload := map[string]any{ + "transformprofile": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + req, err := s.client.NewRequest(http.MethodPost, transformProfileURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + _, err = s.client.Do(req) + return err +} + +func (s *TransformService) GetAllTransformProfile() ([]models.TransformProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, transformProfileURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Profiles []models.TransformProfile `json:"transformprofile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Profiles, nil +} + +func (s *TransformService) GetTransformProfile(name string) ([]models.TransformProfile, error) { + reqURL := fmt.Sprintf("%s/%s", transformProfileURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Profiles []models.TransformProfile `json:"transformprofile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Profiles, nil +} + +func (s *TransformService) CountTransformProfile() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, transformProfileURL+"?count=yes", nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Profiles []struct { + Count float64 `json:"__count"` + } `json:"transformprofile"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Profiles) > 0 { + return result.Profiles[0].Count, nil + } + return 0, nil +} // transformprofile_binding -func (s *TransformService) GetAllTransformProfileBinding() {} -func (s *TransformService) GetTransformProfileBinding() {} + +func (s *TransformService) GetAllTransformProfileBinding() ([]models.TransformProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, transformProfileBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TransformProfileBinding `json:"transformprofile_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TransformService) GetTransformProfileBinding(name string) ([]models.TransformProfileBinding, error) { + reqURL := fmt.Sprintf("%s/%s", transformProfileBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TransformProfileBinding `json:"transformprofile_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} // transformprofile_transformaction_binding -func (s *TransformService) GetAllTransformProfileTransformActionBinding() {} -func (s *TransformService) GetTransformProfileTransformActionBinding() {} -func (s *TransformService) CountTransformProfileTransformActionBinding() {} + +func (s *TransformService) GetAllTransformProfileTransformActionBinding() ([]models.TransformProfileTransformActionBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, transformProfileTransformActionBindingURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TransformProfileTransformActionBinding `json:"transformprofile_transformaction_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TransformService) GetTransformProfileTransformActionBinding(name string) ([]models.TransformProfileTransformActionBinding, error) { + reqURL := fmt.Sprintf("%s/%s", transformProfileTransformActionBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + var result struct { + Bindings []models.TransformProfileTransformActionBinding `json:"transformprofile_transformaction_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + return result.Bindings, nil +} + +func (s *TransformService) CountTransformProfileTransformActionBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", transformProfileTransformActionBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"transformprofile_transformaction_binding"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + return 0, nil +} diff --git a/nitrogo/tunnel.go b/nitrogo/tunnel.go index e530164..c7e4b35 100644 --- a/nitrogo/tunnel.go +++ b/nitrogo/tunnel.go @@ -1,5 +1,23 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + tunnelGlobalBindingURL = "/nitro/v1/config/tunnelglobal_binding" + tunnelGlobalTunnelTrafficPolicyBindingURL = "/nitro/v1/config/tunnelglobal_tunneltrafficpolicy_binding" + tunnelTrafficPolicyURL = "/nitro/v1/config/tunneltrafficpolicy" + tunnelTrafficPolicyBindingURL = "/nitro/v1/config/tunneltrafficpolicy_binding" + tunnelTrafficPolicyTunnelGlobalBindingURL = "/nitro/v1/config/tunneltrafficpolicy_tunnelglobal_binding" +) + // SSL VPN Tunnel Configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/tunnel/tunnel type TunnelService struct { @@ -9,37 +27,414 @@ type TunnelService struct { // tunnelglobal_binding // Binding object which returns the resources bound to tunnelglobal. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/tunnel/tunnelglobal_binding -func (s *TunnelService) GetTunnelGlobalBinding() {} + +func (s *TunnelService) GetTunnelGlobalBinding() ([]models.TunnelGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, tunnelGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.TunnelGlobalBinding `json:"tunnelglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} // tunnelglobal_tunneltrafficpolicy_binding // Binding object showing the tunneltrafficpolicy that can be bound to tunnelglobal. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/tunnel/tunnelglobal_tunneltrafficpolicy_binding -func (s *TunnelService) AddTunnelGlobalTunnelTrafficPolicyBinding() {} -func (s *TunnelService) DeleteTunnelGlobalTunnelTrafficPolicyBinding() {} -func (s *TunnelService) GetTunnelGlobalTunnelTrafficPolicyBinding() {} -func (s *TunnelService) CountTunnelGlobalTunnelTrafficPolicyBinding() {} + +func (s *TunnelService) AddTunnelGlobalTunnelTrafficPolicyBinding(binding models.TunnelGlobalTunnelTrafficPolicyBinding) error { + payload := map[string]any{ + "tunnelglobal_tunneltrafficpolicy_binding": binding, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, tunnelGlobalTunnelTrafficPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *TunnelService) DeleteTunnelGlobalTunnelTrafficPolicyBinding(policyname string) error { + urlReq := fmt.Sprintf("%s?args=policyname:%s", tunnelGlobalTunnelTrafficPolicyBindingURL, url.QueryEscape(policyname)) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *TunnelService) GetTunnelGlobalTunnelTrafficPolicyBinding() ([]models.TunnelGlobalTunnelTrafficPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, tunnelGlobalTunnelTrafficPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.TunnelGlobalTunnelTrafficPolicyBinding `json:"tunnelglobal_tunneltrafficpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *TunnelService) CountTunnelGlobalTunnelTrafficPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, tunnelGlobalTunnelTrafficPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"tunnelglobal_tunneltrafficpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} // tunneltrafficpolicy // Configuration for tunnel policy resource // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/tunnel/tunneltrafficpolicy -func (s *TunnelService) AddTunnelTrafficPolicy() {} -func (s *TunnelService) DeleteTunnelTrafficPolicy() {} -func (s *TunnelService) UpdateTunnelTrafficPolicy() {} -func (s *TunnelService) UnsetTunnelTrafficPolicy() {} -func (s *TunnelService) GetAllTunnelTrafficPolicy() {} -func (s *TunnelService) GetTunnelTrafficPolicy() {} -func (s *TunnelService) CountTunnelTrafficPolicy() {} -func (s *TunnelService) RenameTunnelTrafficPolicy() {} + +func (s *TunnelService) AddTunnelTrafficPolicy(policy models.TunnelTrafficPolicy) error { + payload := map[string]any{ + "tunneltrafficpolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, tunnelTrafficPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *TunnelService) DeleteTunnelTrafficPolicy(name string) error { + urlReq := fmt.Sprintf("%s/%s", tunnelTrafficPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, urlReq, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *TunnelService) UpdateTunnelTrafficPolicy(policy models.TunnelTrafficPolicy) error { + payload := map[string]any{ + "tunneltrafficpolicy": policy, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, tunnelTrafficPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *TunnelService) UnsetTunnelTrafficPolicy(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "tunneltrafficpolicy": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, tunnelTrafficPolicyURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *TunnelService) GetAllTunnelTrafficPolicy() ([]models.TunnelTrafficPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, tunnelTrafficPolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Policies []models.TunnelTrafficPolicy `json:"tunneltrafficpolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Policies, nil +} + +func (s *TunnelService) GetTunnelTrafficPolicy(name string) ([]models.TunnelTrafficPolicy, error) { + urlReq := fmt.Sprintf("%s/%s", tunnelTrafficPolicyURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Policies []models.TunnelTrafficPolicy `json:"tunneltrafficpolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Policies, nil +} + +func (s *TunnelService) CountTunnelTrafficPolicy() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, tunnelTrafficPolicyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Policies []struct { + Count float64 `json:"__count"` + } `json:"tunneltrafficpolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Policies) > 0 { + return result.Policies[0].Count, nil + } + + return 0, nil +} + +func (s *TunnelService) RenameTunnelTrafficPolicy(name string, newname string) error { + payload := map[string]any{ + "tunneltrafficpolicy": map[string]string{ + "name": name, + "newname": newname, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, tunnelTrafficPolicyURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} // tunneltrafficpolicy_binding // Binding object which returns the resources bound to tunneltrafficpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/tunnel/tunneltrafficpolicy_binding -func (s *TunnelService) GetAllTunnelTrafficPolicyBinding() {} -func (s *TunnelService) GetTunnelTrafficPolicyBinding() {} + +func (s *TunnelService) GetAllTunnelTrafficPolicyBinding() ([]models.TunnelTrafficPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, tunnelTrafficPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.TunnelTrafficPolicyBinding `json:"tunneltrafficpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *TunnelService) GetTunnelTrafficPolicyBinding(name string) ([]models.TunnelTrafficPolicyBinding, error) { + urlReq := fmt.Sprintf("%s/%s", tunnelTrafficPolicyBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.TunnelTrafficPolicyBinding `json:"tunneltrafficpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} // tunneltrafficpolicy_tunnelglobal_binding // Binding object showing the tunnelglobal that can be bound to tunneltrafficpolicy. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/tunnel/tunneltrafficpolicy_tunnelglobal_binding -func (s *TunnelService) GetAllTunnelTrafficPolicyTunnelGlobalBinding() {} -func (s *TunnelService) GetTunnelTrafficPolicyTunnelGlobalBinding() {} -func (s *TunnelService) CountTunnelTrafficPolicyTunnelGlobalBinding() {} + +func (s *TunnelService) GetAllTunnelTrafficPolicyTunnelGlobalBinding() ([]models.TunnelTrafficPolicyTunnelGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, tunnelTrafficPolicyTunnelGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.TunnelTrafficPolicyTunnelGlobalBinding `json:"tunneltrafficpolicy_tunnelglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *TunnelService) GetTunnelTrafficPolicyTunnelGlobalBinding(name string) ([]models.TunnelTrafficPolicyTunnelGlobalBinding, error) { + urlReq := fmt.Sprintf("%s/%s", tunnelTrafficPolicyTunnelGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.TunnelTrafficPolicyTunnelGlobalBinding `json:"tunneltrafficpolicy_tunnelglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *TunnelService) CountTunnelTrafficPolicyTunnelGlobalBinding(name string) (float64, error) { + urlReq := fmt.Sprintf("%s/%s?count=yes", tunnelTrafficPolicyTunnelGlobalBindingURL, url.QueryEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, urlReq, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"tunneltrafficpolicy_tunnelglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} diff --git a/nitrogo/ulfd.go b/nitrogo/ulfd.go index ccded5d..892a2bf 100644 --- a/nitrogo/ulfd.go +++ b/nitrogo/ulfd.go @@ -1,5 +1,18 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + ulfdServerURL = "/nitro/v1/config/ulfdserver" +) + // ULFD server configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/ulfd/ulfd type ULFDService struct { @@ -9,8 +22,108 @@ type ULFDService struct { // ulfdserver // Configuration for ulfd server resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/ulfd/ulfdserver -func (s *ULFDService) AddULFDServer() {} -func (s *ULFDService) DeleteULFDServer() {} -func (s *ULFDService) GetAllULFDServer() {} -func (s *ULFDService) GetULFDServer() {} -func (s *ULFDService) CountULFDServer() {} + +func (s *ULFDService) AddULFDServer(server models.ULFDServer) error { + payload := map[string]any{ + "ulfdserver": server, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, ulfdServerURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ULFDService) DeleteULFDServer(loggerip string) error { + url := fmt.Sprintf("%s/%s", ulfdServerURL, loggerip) + req, err := s.client.NewRequest(http.MethodDelete, url, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *ULFDService) GetAllULFDServer() ([]models.ULFDServer, error) { + req, err := s.client.NewRequest(http.MethodGet, ulfdServerURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + ULFDServers []models.ULFDServer `json:"ulfdserver"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.ULFDServers, nil +} + +func (s *ULFDService) GetULFDServer(loggerip string) ([]models.ULFDServer, error) { + url := fmt.Sprintf("%s/%s", ulfdServerURL, loggerip) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + ULFDServers []models.ULFDServer `json:"ulfdserver"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.ULFDServers, nil +} + +func (s *ULFDService) CountULFDServer() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, ulfdServerURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + ULFDServers []struct { + Count float64 `json:"__count"` + } `json:"ulfdserver"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.ULFDServers) > 0 { + return result.ULFDServers[0].Count, nil + } + + return 0, nil +} diff --git a/nitrogo/url_filtering.go b/nitrogo/url_filtering.go index 6276f75..9cf9eaf 100644 --- a/nitrogo/url_filtering.go +++ b/nitrogo/url_filtering.go @@ -1,5 +1,21 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + urlFilteringCategoriesURL = "/nitro/v1/config/urlfilteringcategories" + urlFilteringCategorizationURL = "/nitro/v1/config/urlfilteringcategorization" + urlFilteringCategoryGroupsURL = "/nitro/v1/config/urlfilteringcategorygroups" + urlFilteringParameterURL = "/nitro/v1/config/urlfilteringparameter" +) + // URL Filtering feature is used control access to webpages based on category. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/urlfiltering/urlfiltering type URLFilteringService struct { @@ -9,24 +25,217 @@ type URLFilteringService struct { // urlfilteringcategories // Configuration for Categories resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/urlfiltering/urlfilteringcategories -func (s *URLFilteringService) GetAllURLFilteringCategories() {} + +func (s *URLFilteringService) GetAllURLFilteringCategories() ([]models.URLFilteringCategories, error) { + req, err := s.client.NewRequest(http.MethodGet, urlFilteringCategoriesURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Categories []models.URLFilteringCategories `json:"urlfilteringcategories"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Categories, nil +} // urlfilteringcategorization // Configuration for Categorization resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/urlfiltering/urlfilteringcategorization -func (s *URLFilteringService) AddURLFilteringCategorization() {} -func (s *URLFilteringService) ClearURLFilteringCategorization() {} -func (s *URLFilteringService) GetAllURLFilteringCategorization() {} -func (s *URLFilteringService) CountURLFilteringCategorization() {} + +func (s *URLFilteringService) AddURLFilteringCategorization(categorization models.URLFilteringCategorization) error { + payload := map[string]any{ + "urlfilteringcategorization": categorization, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, urlFilteringCategorizationURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *URLFilteringService) ClearURLFilteringCategorization(categorization models.URLFilteringCategorization) error { + payload := map[string]any{ + "urlfilteringcategorization": categorization, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, urlFilteringCategorizationURL+"?action=clear", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *URLFilteringService) GetAllURLFilteringCategorization() ([]models.URLFilteringCategorization, error) { + req, err := s.client.NewRequest(http.MethodGet, urlFilteringCategorizationURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Categorization []models.URLFilteringCategorization `json:"urlfilteringcategorization"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Categorization, nil +} + +func (s *URLFilteringService) CountURLFilteringCategorization() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, urlFilteringCategorizationURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Categorization []struct { + Count float64 `json:"__count"` + } `json:"urlfilteringcategorization"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Categorization) > 0 { + return result.Categorization[0].Count, nil + } + + return 0, nil +} // urlfilteringcategorygroups // Configuration for Category Groups resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/urlfiltering/urlfilteringcategorygroups -func (s *URLFilteringService) GetAllURLFilteringCategoryGroups() {} + +func (s *URLFilteringService) GetAllURLFilteringCategoryGroups() ([]models.URLFilteringCategoryGroups, error) { + req, err := s.client.NewRequest(http.MethodGet, urlFilteringCategoryGroupsURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + CategoryGroups []models.URLFilteringCategoryGroups `json:"urlfilteringcategorygroups"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.CategoryGroups, nil +} // urlfilteringparameter // Configuration for URLFILTERING paramter resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/urlfiltering/urlfilteringparameter -func (s *URLFilteringService) UpdateURLFilteringParameter() {} -func (s *URLFilteringService) UnsetURLFilteringParameter() {} -func (s *URLFilteringService) GetAllURLFilteringParameter() {} + +func (s *URLFilteringService) UpdateURLFilteringParameter(param models.URLFilteringParameter) error { + payload := map[string]any{ + "urlfilteringparameter": param, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, urlFilteringParameterURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *URLFilteringService) UnsetURLFilteringParameter(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "urlfilteringparameter": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, urlFilteringParameterURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *URLFilteringService) GetAllURLFilteringParameter() (models.URLFilteringParameter, error) { + req, err := s.client.NewRequest(http.MethodGet, urlFilteringParameterURL, nil) + if err != nil { + return models.URLFilteringParameter{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.URLFilteringParameter{}, err + } + + var result struct { + URLFilteringParameters []models.URLFilteringParameter `json:"urlfilteringparameter"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.URLFilteringParameter{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.URLFilteringParameters) > 0 { + return result.URLFilteringParameters[0], nil + } + + return models.URLFilteringParameter{}, nil +} diff --git a/nitrogo/user.go b/nitrogo/user.go index 8abd1f5..b4d6c23 100644 --- a/nitrogo/user.go +++ b/nitrogo/user.go @@ -1,5 +1,19 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + userProtocolURL = "/nitro/v1/config/userprotocol" + userVServerURL = "/nitro/v1/config/uservserver" +) + // User protocol configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/user/user type UserService struct { @@ -9,22 +23,319 @@ type UserService struct { // userprotocol // Configuration for user protocol resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/user/userprotocol -func (s *UserService) AddUserProtocol() {} -func (s *UserService) DeleteUserProtocol() {} -func (s *UserService) UpdateUserProtocol() {} -func (s *UserService) UnsetUserProtocol() {} -func (s *UserService) GetAllUserProtocol() {} -func (s *UserService) GetUserProtocol() {} -func (s *UserService) CountUserProtocol() {} + +func (s *UserService) AddUserProtocol(protocol models.UserProtocol) error { + payload := map[string]any{ + "userprotocol": protocol, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, userProtocolURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *UserService) DeleteUserProtocol(name string) error { + url := fmt.Sprintf("%s/%s", userProtocolURL, name) + req, err := s.client.NewRequest(http.MethodDelete, url, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *UserService) UpdateUserProtocol(protocol models.UserProtocol) error { + payload := map[string]any{ + "userprotocol": protocol, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, userProtocolURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *UserService) UnsetUserProtocol(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "userprotocol": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, userProtocolURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *UserService) GetAllUserProtocol() ([]models.UserProtocol, error) { + req, err := s.client.NewRequest(http.MethodGet, userProtocolURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + UserProtocols []models.UserProtocol `json:"userprotocol"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.UserProtocols, nil +} + +func (s *UserService) GetUserProtocol(name string) ([]models.UserProtocol, error) { + url := fmt.Sprintf("%s/%s", userProtocolURL, name) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + UserProtocols []models.UserProtocol `json:"userprotocol"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.UserProtocols, nil +} + +func (s *UserService) CountUserProtocol() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, userProtocolURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + UserProtocols []struct { + Count float64 `json:"__count"` + } `json:"userprotocol"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.UserProtocols) > 0 { + return result.UserProtocols[0].Count, nil + } + + return 0, nil +} // uservserver // Configuration for virtual server resource. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/user/uservserver -func (s *UserService) AddUserVServer() {} -func (s *UserService) DeleteUserVServer() {} -func (s *UserService) UpdateUserVServer() {} -func (s *UserService) UnsetUserVServer() {} -func (s *UserService) EnableUserVServer() {} -func (s *UserService) GetAllUserVServer() {} -func (s *UserService) GetUserVServer() {} -func (s *UserService) CountUserVServer() {} + +func (s *UserService) AddUserVServer(vserver models.UserVServer) error { + payload := map[string]any{ + "uservserver": vserver, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, userVServerURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *UserService) DeleteUserVServer(name string) error { + url := fmt.Sprintf("%s/%s", userVServerURL, name) + req, err := s.client.NewRequest(http.MethodDelete, url, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *UserService) UpdateUserVServer(vserver models.UserVServer) error { + payload := map[string]any{ + "uservserver": vserver, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, userVServerURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *UserService) UnsetUserVServer(args []string) error { + unsetMap := make(map[string]any) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "uservserver": unsetMap, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, userVServerURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *UserService) EnableUserVServer(name string) error { + payload := map[string]any{ + "uservserver": map[string]any{ + "name": name, + }, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, userVServerURL+"?action=enable", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *UserService) GetAllUserVServer() ([]models.UserVServer, error) { + req, err := s.client.NewRequest(http.MethodGet, userVServerURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + UserVServers []models.UserVServer `json:"uservserver"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.UserVServers, nil +} + +func (s *UserService) GetUserVServer(name string) ([]models.UserVServer, error) { + url := fmt.Sprintf("%s/%s", userVServerURL, name) + req, err := s.client.NewRequest(http.MethodGet, url, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + UserVServers []models.UserVServer `json:"uservserver"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.UserVServers, nil +} + +func (s *UserService) CountUserVServer() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, userVServerURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + UserVServers []struct { + Count float64 `json:"__count"` + } `json:"uservserver"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.UserVServers) > 0 { + return result.UserVServers[0].Count, nil + } + + return 0, nil +} diff --git a/nitrogo/utility.go b/nitrogo/utility.go index 9083276..b58ef27 100644 --- a/nitrogo/utility.go +++ b/nitrogo/utility.go @@ -1,5 +1,25 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + callHomeURL = "/nitro/v1/config/callhome" + installURL = "/nitro/v1/config/install" + pingURL = "/nitro/v1/config/ping" + ping6URL = "/nitro/v1/config/ping6" + raidURL = "/nitro/v1/config/raid" + techSupportURL = "/nitro/v1/config/techsupport" + traceRouteURL = "/nitro/v1/config/traceroute" + traceRoute6URL = "/nitro/v1/config/traceroute6" +) + // Utilities. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/utility/utility type UtilityService struct { @@ -7,27 +27,286 @@ type UtilityService struct { } // callhome -func (s *UtilityService) UpdateCallHome() {} -func (s *UtilityService) UnsetCallHome() {} -func (s *UtilityService) GetAllCallHome() {} + +func (s *UtilityService) UpdateCallHome(callhome models.CallHome) error { + payload := map[string]any{ + "callhome": callhome, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, callHomeURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *UtilityService) UnsetCallHome(args []string) error { + unsetMap := make(map[string]bool) + for _, arg := range args { + unsetMap[arg] = true + } + + payload := map[string]any{ + "callhome": unsetMap, + } + + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, callHomeURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *UtilityService) GetAllCallHome() (models.CallHome, error) { + req, err := s.client.NewRequest(http.MethodGet, callHomeURL, nil) + if err != nil { + return models.CallHome{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.CallHome{}, err + } + + var result struct { + CallHomes []models.CallHome `json:"callhome"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return models.CallHome{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.CallHomes) > 0 { + return result.CallHomes[0], nil + } + + return models.CallHome{}, nil +} // install -func (s *UtilityService) InstallInstall() {} + +func (s *UtilityService) InstallInstall(install models.Install) error { + payload := map[string]any{ + "install": install, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, installURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} // ping -func (s *UtilityService) PingPing() {} + +func (s *UtilityService) PingPing(ping models.Ping) (models.Ping, error) { + payload := map[string]any{ + "ping": ping, + } + body, err := json.Marshal(payload) + if err != nil { + return models.Ping{}, fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, pingURL, bytes.NewBuffer(body)) + if err != nil { + return models.Ping{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.Ping{}, err + } + + var result struct { + Pings []models.Ping `json:"ping"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return models.Ping{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Pings) > 0 { + return result.Pings[0], nil + } + + return models.Ping{}, nil +} // ping6 -func (s *UtilityService) Ping6Ping6() {} + +func (s *UtilityService) Ping6Ping6(ping6 models.Ping6) (models.Ping6, error) { + payload := map[string]any{ + "ping6": ping6, + } + body, err := json.Marshal(payload) + if err != nil { + return models.Ping6{}, fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, ping6URL, bytes.NewBuffer(body)) + if err != nil { + return models.Ping6{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.Ping6{}, err + } + + var result struct { + Ping6s []models.Ping6 `json:"ping6"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return models.Ping6{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Ping6s) > 0 { + return result.Ping6s[0], nil + } + + return models.Ping6{}, nil +} // raid -func (s *UtilityService) GetAllRAID() {} + +func (s *UtilityService) GetAllRAID() ([]models.Raid, error) { + req, err := s.client.NewRequest(http.MethodGet, raidURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Raids []models.Raid `json:"raid"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Raids, nil +} // techsupport -func (s *UtilityService) GetAllTechSupport() {} + +func (s *UtilityService) GetAllTechSupport() ([]models.TechSupport, error) { + req, err := s.client.NewRequest(http.MethodGet, techSupportURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + TechSupports []models.TechSupport `json:"techsupport"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.TechSupports, nil +} // traceroute -func (s *UtilityService) TraceRouteTraceRoute() {} + +func (s *UtilityService) TraceRouteTraceRoute(traceroute models.Traceroute) (models.Traceroute, error) { + payload := map[string]any{ + "traceroute": traceroute, + } + body, err := json.Marshal(payload) + if err != nil { + return models.Traceroute{}, fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, traceRouteURL, bytes.NewBuffer(body)) + if err != nil { + return models.Traceroute{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.Traceroute{}, err + } + + var result struct { + Traceroutes []models.Traceroute `json:"traceroute"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return models.Traceroute{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Traceroutes) > 0 { + return result.Traceroutes[0], nil + } + + return models.Traceroute{}, nil +} // traceroute6 -func (s *UtilityService) TraceRoute6TraceRoute6() {} + +func (s *UtilityService) TraceRoute6TraceRoute6(traceroute6 models.Traceroute6) (models.Traceroute6, error) { + payload := map[string]any{ + "traceroute6": traceroute6, + } + body, err := json.Marshal(payload) + if err != nil { + return models.Traceroute6{}, fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, traceRoute6URL, bytes.NewBuffer(body)) + if err != nil { + return models.Traceroute6{}, err + } + + resp, err := s.client.Do(req) + if err != nil { + return models.Traceroute6{}, err + } + + var result struct { + Traceroute6s []models.Traceroute6 `json:"traceroute6"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return models.Traceroute6{}, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Traceroute6s) > 0 { + return result.Traceroute6s[0], nil + } + + return models.Traceroute6{}, nil +} diff --git a/nitrogo/video_optimization.go b/nitrogo/video_optimization.go index 01dd46b..03812da 100644 --- a/nitrogo/video_optimization.go +++ b/nitrogo/video_optimization.go @@ -1,5 +1,41 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + videoOptimizationDetectionActionURL = "/nitro/v1/config/videooptimizationdetectionaction" + videoOptimizationDetectionPolicyURL = "/nitro/v1/config/videooptimizationdetectionpolicy" + videoOptimizationDetectionPolicyLabelURL = "/nitro/v1/config/videooptimizationdetectionpolicylabel" + videoOptimizationDetectionPolicyLabelBindingURL = "/nitro/v1/config/videooptimizationdetectionpolicylabel_binding" + videoOptimizationDetectionPolicyLabelPolicyBindingBindingURL = "/nitro/v1/config/videooptimizationdetectionpolicylabel_policybinding_binding" + videoOptimizationDetectionPolicyLabelVideoOptimizationDetectionPolicyBindingURL = "/nitro/v1/config/videooptimizationdetectionpolicylabel_videooptimizationdetectionpolicy_binding" + videoOptimizationDetectionPolicyBindingURL = "/nitro/v1/config/videooptimizationdetectionpolicy_binding" + videoOptimizationDetectionPolicyLBVServerBindingURL = "/nitro/v1/config/videooptimizationdetectionpolicy_lbvserver_binding" + videoOptimizationDetectionPolicyVideoOptimizationGlobalDetectionBindingURL = "/nitro/v1/config/videooptimizationdetectionpolicy_videooptimizationglobaldetection_binding" + videoOptimizationGlobalDetectionBindingURL = "/nitro/v1/config/videooptimizationglobaldetection_binding" + videoOptimizationGlobalDetectionVideoOptimizationDetectionPolicyBindingURL = "/nitro/v1/config/videooptimizationglobaldetection_videooptimizationdetectionpolicy_binding" + videoOptimizationGlobalPacingBindingURL = "/nitro/v1/config/videooptimizationglobalpacing_binding" + videoOptimizationGlobalPacingVideoOptimizationPacingPolicyBindingURL = "/nitro/v1/config/videooptimizationglobalpacing_videooptimizationpacingpolicy_binding" + videoOptimizationPacingActionURL = "/nitro/v1/config/videooptimizationpacingaction" + videoOptimizationPacingPolicyURL = "/nitro/v1/config/videooptimizationpacingpolicy" + videoOptimizationPacingPolicyLabelURL = "/nitro/v1/config/videooptimizationpacingpolicylabel" + videoOptimizationPacingPolicyLabelBindingURL = "/nitro/v1/config/videooptimizationpacingpolicylabel_binding" + videoOptimizationPacingPolicyLabelPolicyBindingBindingURL = "/nitro/v1/config/videooptimizationpacingpolicylabel_policybinding_binding" + videoOptimizationPacingPolicyLabelVideoOptimizationPacingPolicyBindingURL = "/nitro/v1/config/videooptimizationpacingpolicylabel_videooptimizationpacingpolicy_binding" + videoOptimizationPacingPolicyBindingURL = "/nitro/v1/config/videooptimizationpacingpolicy_binding" + videoOptimizationPacingPolicyLBVServerBindingURL = "/nitro/v1/config/videooptimizationpacingpolicy_lbvserver_binding" + videoOptimizationPacingPolicyVideoOptimizationGlobalPacingBindingURL = "/nitro/v1/config/videooptimizationpacingpolicy_videooptimizationglobalpacing_binding" + videoOptimizationParameterURL = "/nitro/v1/config/videooptimizationparameter" +) + // VideoOptimization // Video optimization feature is used to show (i) the stats of different media types that are being served by the Citrix ADC and (ii) the details of optimization applied on ABR videos // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/videooptimization/videooptimization @@ -8,165 +44,2099 @@ type VideoOptimizationService struct { } // videooptimizationdetectionaction -func (s *VideoOptimizationService) AddVideoOptimizationDetectionAction() {} -func (s *VideoOptimizationService) DeleteVideoOptimizationDetectionAction() {} -func (s *VideoOptimizationService) UpdateVideoOptimizationDetectionAction() {} -func (s *VideoOptimizationService) UnsetVideoOptimizationDetectionAction() {} -func (s *VideoOptimizationService) RenameVideoOptimizationDetectionAction() {} -func (s *VideoOptimizationService) GetAllVideoOptimizationDetectionAction() {} -func (s *VideoOptimizationService) GetVideoOptimizationDetectionAction() {} -func (s *VideoOptimizationService) CountVideoOptimizationDetectionAction() {} +func (s *VideoOptimizationService) AddVideoOptimizationDetectionAction(resource models.VideoOptimizationDetectionAction) error { + payload := map[string]any{ + "videooptimizationdetectionaction": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, videoOptimizationDetectionActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) DeleteVideoOptimizationDetectionAction(name string) error { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationDetectionActionURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) UpdateVideoOptimizationDetectionAction(resource models.VideoOptimizationDetectionAction) error { + payload := map[string]any{ + "videooptimizationdetectionaction": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, videoOptimizationDetectionActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) UnsetVideoOptimizationDetectionAction(resource models.VideoOptimizationDetectionAction) error { + payload := map[string]any{ + "videooptimizationdetectionaction": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, videoOptimizationDetectionActionURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) RenameVideoOptimizationDetectionAction(resource models.VideoOptimizationDetectionAction) error { + payload := map[string]any{ + "videooptimizationdetectionaction": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, videoOptimizationDetectionActionURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) GetAllVideoOptimizationDetectionAction() ([]models.VideoOptimizationDetectionAction, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationDetectionActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Actions []models.VideoOptimizationDetectionAction `json:"videooptimizationdetectionaction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Actions, nil +} + +func (s *VideoOptimizationService) GetVideoOptimizationDetectionAction(name string) (*models.VideoOptimizationDetectionAction, error) { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationDetectionActionURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Actions []models.VideoOptimizationDetectionAction `json:"videooptimizationdetectionaction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Actions) == 0 { + return nil, fmt.Errorf("videooptimizationdetectionaction not found") + } + + return &result.Actions[0], nil +} + +func (s *VideoOptimizationService) CountVideoOptimizationDetectionAction() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationDetectionActionURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Actions []struct { + Count float64 `json:"__count"` + } `json:"videooptimizationdetectionaction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Actions) > 0 { + return result.Actions[0].Count, nil + } + + return 0, nil +} // videooptimizationdetectionpolicy -func (s *VideoOptimizationService) AddVideoOptimizationDetectionPolicy() {} -func (s *VideoOptimizationService) DeleteVideoOptimizationDetectionPolicy() {} -func (s *VideoOptimizationService) UpdateVideoOptimizationDetectionPolicy() {} -func (s *VideoOptimizationService) UnsetVideoOptimizationDetectionPolicy() {} -func (s *VideoOptimizationService) RenameVideoOptimizationDetectionPolicy() {} -func (s *VideoOptimizationService) GetAllVideoOptimizationDetectionPolicy() {} -func (s *VideoOptimizationService) GetVideoOptimizationDetectionPolicy() {} -func (s *VideoOptimizationService) CountVideoOptimizationDetectionPolicy() {} +func (s *VideoOptimizationService) AddVideoOptimizationDetectionPolicy(resource models.VideoOptimizationDetectionPolicy) error { + payload := map[string]any{ + "videooptimizationdetectionpolicy": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, videoOptimizationDetectionPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) DeleteVideoOptimizationDetectionPolicy(name string) error { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationDetectionPolicyURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) UpdateVideoOptimizationDetectionPolicy(resource models.VideoOptimizationDetectionPolicy) error { + payload := map[string]any{ + "videooptimizationdetectionpolicy": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, videoOptimizationDetectionPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) UnsetVideoOptimizationDetectionPolicy(resource models.VideoOptimizationDetectionPolicy) error { + payload := map[string]any{ + "videooptimizationdetectionpolicy": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, videoOptimizationDetectionPolicyURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) RenameVideoOptimizationDetectionPolicy(resource models.VideoOptimizationDetectionPolicy) error { + payload := map[string]any{ + "videooptimizationdetectionpolicy": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, videoOptimizationDetectionPolicyURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) GetAllVideoOptimizationDetectionPolicy() ([]models.VideoOptimizationDetectionPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationDetectionPolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Policies []models.VideoOptimizationDetectionPolicy `json:"videooptimizationdetectionpolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Policies, nil +} + +func (s *VideoOptimizationService) GetVideoOptimizationDetectionPolicy(name string) (*models.VideoOptimizationDetectionPolicy, error) { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationDetectionPolicyURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Policies []models.VideoOptimizationDetectionPolicy `json:"videooptimizationdetectionpolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Policies) == 0 { + return nil, fmt.Errorf("videooptimizationdetectionpolicy not found") + } + + return &result.Policies[0], nil +} + +func (s *VideoOptimizationService) CountVideoOptimizationDetectionPolicy() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationDetectionPolicyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Policies []struct { + Count float64 `json:"__count"` + } `json:"videooptimizationdetectionpolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Policies) > 0 { + return result.Policies[0].Count, nil + } + + return 0, nil +} // videooptimizationdetectionpolicylabel -func (s *VideoOptimizationService) AddVideoOptimizationDetectionPolicyLabel() {} -func (s *VideoOptimizationService) DeleteVideoOptimizationDetectionPolicyLabel() {} -func (s *VideoOptimizationService) RenameVideoOptimizationDetectionPolicyLabel() {} -func (s *VideoOptimizationService) GetAllVideoOptimizationDetectionPolicyLabel() {} -func (s *VideoOptimizationService) GetVideoOptimizationDetectionPolicyLabel() {} -func (s *VideoOptimizationService) CountVideoOptimizationDetectionPolicyLabel() {} +func (s *VideoOptimizationService) AddVideoOptimizationDetectionPolicyLabel(resource models.VideoOptimizationDetectionPolicyLabel) error { + payload := map[string]any{ + "videooptimizationdetectionpolicylabel": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, videoOptimizationDetectionPolicyLabelURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) DeleteVideoOptimizationDetectionPolicyLabel(name string) error { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationDetectionPolicyLabelURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) RenameVideoOptimizationDetectionPolicyLabel(resource models.VideoOptimizationDetectionPolicyLabel) error { + payload := map[string]any{ + "videooptimizationdetectionpolicylabel": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, videoOptimizationDetectionPolicyLabelURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) GetAllVideoOptimizationDetectionPolicyLabel() ([]models.VideoOptimizationDetectionPolicyLabel, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationDetectionPolicyLabelURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Labels []models.VideoOptimizationDetectionPolicyLabel `json:"videooptimizationdetectionpolicylabel"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Labels, nil +} + +func (s *VideoOptimizationService) GetVideoOptimizationDetectionPolicyLabel(name string) (*models.VideoOptimizationDetectionPolicyLabel, error) { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationDetectionPolicyLabelURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Labels []models.VideoOptimizationDetectionPolicyLabel `json:"videooptimizationdetectionpolicylabel"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Labels) == 0 { + return nil, fmt.Errorf("videooptimizationdetectionpolicylabel not found") + } + + return &result.Labels[0], nil +} + +func (s *VideoOptimizationService) CountVideoOptimizationDetectionPolicyLabel() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationDetectionPolicyLabelURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Labels []struct { + Count float64 `json:"__count"` + } `json:"videooptimizationdetectionpolicylabel"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Labels) > 0 { + return result.Labels[0].Count, nil + } + + return 0, nil +} // videooptimizationdetectionpolicylabel_binding -func (s *VideoOptimizationService) GetAllVideoOptimizationDetectionPolicyLabelBinding() {} -func (s *VideoOptimizationService) GetVideoOptimizationDetectionPolicyLabelBinding() {} +func (s *VideoOptimizationService) GetAllVideoOptimizationDetectionPolicyLabelBinding() ([]models.VideoOptimizationDetectionPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationDetectionPolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationDetectionPolicyLabelBinding `json:"videooptimizationdetectionpolicylabel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *VideoOptimizationService) GetVideoOptimizationDetectionPolicyLabelBinding(name string) (*models.VideoOptimizationDetectionPolicyLabelBinding, error) { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationDetectionPolicyLabelBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationDetectionPolicyLabelBinding `json:"videooptimizationdetectionpolicylabel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) == 0 { + return nil, fmt.Errorf("videooptimizationdetectionpolicylabel_binding not found") + } + + return &result.Bindings[0], nil +} // videooptimizationdetectionpolicylabel_policybinding_binding -func (s *VideoOptimizationService) GetAllVideoOptimizationDetectionPolicyLabelPolicyBindingBinding() { +func (s *VideoOptimizationService) GetAllVideoOptimizationDetectionPolicyLabelPolicyBindingBinding() ([]models.VideoOptimizationDetectionPolicyLabelPolicyBindingBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationDetectionPolicyLabelPolicyBindingBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationDetectionPolicyLabelPolicyBindingBinding `json:"videooptimizationdetectionpolicylabel_policybinding_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *VideoOptimizationService) GetVideoOptimizationDetectionPolicyLabelPolicyBindingBinding(name string) ([]models.VideoOptimizationDetectionPolicyLabelPolicyBindingBinding, error) { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationDetectionPolicyLabelPolicyBindingBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationDetectionPolicyLabelPolicyBindingBinding `json:"videooptimizationdetectionpolicylabel_policybinding_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *VideoOptimizationService) CountVideoOptimizationDetectionPolicyLabelPolicyBindingBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", videoOptimizationDetectionPolicyLabelPolicyBindingBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"videooptimizationdetectionpolicylabel_policybinding_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil } -func (s *VideoOptimizationService) GetVideoOptimizationDetectionPolicyLabelPolicyBindingBinding() {} -func (s *VideoOptimizationService) CountVideoOptimizationDetectionPolicyLabelPolicyBindingBinding() {} // videooptimizationdetectionpolicylabel_videooptimizationdetectionpolicy_binding -func (s *VideoOptimizationService) AddVideoOptimizationDetectionPolicyLabelVideoOptimizationDetectionPolicyBinding() { +func (s *VideoOptimizationService) AddVideoOptimizationDetectionPolicyLabelVideoOptimizationDetectionPolicyBinding(resource models.VideoOptimizationDetectionPolicyLabelVideoOptimizationDetectionPolicyBinding) error { + payload := map[string]any{ + "videooptimizationdetectionpolicylabel_videooptimizationdetectionpolicy_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, videoOptimizationDetectionPolicyLabelVideoOptimizationDetectionPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err } -func (s *VideoOptimizationService) DeleteVideoOptimizationDetectionPolicyLabelVideoOptimizationDetectionPolicyBinding() { + +func (s *VideoOptimizationService) DeleteVideoOptimizationDetectionPolicyLabelVideoOptimizationDetectionPolicyBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationDetectionPolicyLabelVideoOptimizationDetectionPolicyBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err } -func (s *VideoOptimizationService) GetAllVideoOptimizationDetectionPolicyLabelVideoOptimizationDetectionPolicyBinding() { + +func (s *VideoOptimizationService) GetAllVideoOptimizationDetectionPolicyLabelVideoOptimizationDetectionPolicyBinding() ([]models.VideoOptimizationDetectionPolicyLabelVideoOptimizationDetectionPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationDetectionPolicyLabelVideoOptimizationDetectionPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationDetectionPolicyLabelVideoOptimizationDetectionPolicyBinding `json:"videooptimizationdetectionpolicylabel_videooptimizationdetectionpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil } -func (s *VideoOptimizationService) GetVideoOptimizationDetectionPolicyLabelVideoOptimizationDetectionPolicyBinding() { + +func (s *VideoOptimizationService) GetVideoOptimizationDetectionPolicyLabelVideoOptimizationDetectionPolicyBinding(name string) ([]models.VideoOptimizationDetectionPolicyLabelVideoOptimizationDetectionPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationDetectionPolicyLabelVideoOptimizationDetectionPolicyBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationDetectionPolicyLabelVideoOptimizationDetectionPolicyBinding `json:"videooptimizationdetectionpolicylabel_videooptimizationdetectionpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil } -func (s *VideoOptimizationService) CountVideoOptimizationDetectionPolicyLabelVideoOptimizationDetectionPolicyBinding() { + +func (s *VideoOptimizationService) CountVideoOptimizationDetectionPolicyLabelVideoOptimizationDetectionPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", videoOptimizationDetectionPolicyLabelVideoOptimizationDetectionPolicyBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"videooptimizationdetectionpolicylabel_videooptimizationdetectionpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil } // videooptimizationdetectionpolicy_binding -func (s *VideoOptimizationService) GetAllVideoOptimizationDetectionPolicyBinding() {} -func (s *VideoOptimizationService) GetVideoOptimizationDetectionPolicyBinding() {} +func (s *VideoOptimizationService) GetAllVideoOptimizationDetectionPolicyBinding() ([]models.VideoOptimizationDetectionPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationDetectionPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationDetectionPolicyBinding `json:"videooptimizationdetectionpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *VideoOptimizationService) GetVideoOptimizationDetectionPolicyBinding(name string) (*models.VideoOptimizationDetectionPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationDetectionPolicyBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationDetectionPolicyBinding `json:"videooptimizationdetectionpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) == 0 { + return nil, fmt.Errorf("videooptimizationdetectionpolicy_binding not found") + } + + return &result.Bindings[0], nil +} // videooptimizationdetectionpolicy_lbvserver_binding -func (s *VideoOptimizationService) GetAllVideoOptimizationDetectionPolicyLBVServerBinding() {} -func (s *VideoOptimizationService) GetVideoOptimizationDetectionPolicyLBVServerBinding() {} -func (s *VideoOptimizationService) CountVideoOptimizationDetectionPolicyLBVServerBinding() {} +func (s *VideoOptimizationService) GetAllVideoOptimizationDetectionPolicyLBVServerBinding() ([]models.VideoOptimizationDetectionPolicyLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationDetectionPolicyLBVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationDetectionPolicyLBVServerBinding `json:"videooptimizationdetectionpolicy_lbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *VideoOptimizationService) GetVideoOptimizationDetectionPolicyLBVServerBinding(name string) ([]models.VideoOptimizationDetectionPolicyLBVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationDetectionPolicyLBVServerBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationDetectionPolicyLBVServerBinding `json:"videooptimizationdetectionpolicy_lbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *VideoOptimizationService) CountVideoOptimizationDetectionPolicyLBVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", videoOptimizationDetectionPolicyLBVServerBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"videooptimizationdetectionpolicy_lbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} // videooptimizationdetectionpolicy_videooptimizationglobaldetection_binding -func (s *VideoOptimizationService) GetAllVideoOptimizationDetectionPolicyVideoOptimizationGlobalDetectionBinding() { +func (s *VideoOptimizationService) GetAllVideoOptimizationDetectionPolicyVideoOptimizationGlobalDetectionBinding() ([]models.VideoOptimizationDetectionPolicyVideoOptimizationGlobalDetectionBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationDetectionPolicyVideoOptimizationGlobalDetectionBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationDetectionPolicyVideoOptimizationGlobalDetectionBinding `json:"videooptimizationdetectionpolicy_videooptimizationglobaldetection_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil } -func (s *VideoOptimizationService) GetVideoOptimizationDetectionPolicyVideoOptimizationGlobalDetectionBinding() { + +func (s *VideoOptimizationService) GetVideoOptimizationDetectionPolicyVideoOptimizationGlobalDetectionBinding(name string) ([]models.VideoOptimizationDetectionPolicyVideoOptimizationGlobalDetectionBinding, error) { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationDetectionPolicyVideoOptimizationGlobalDetectionBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationDetectionPolicyVideoOptimizationGlobalDetectionBinding `json:"videooptimizationdetectionpolicy_videooptimizationglobaldetection_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil } -func (s *VideoOptimizationService) CountVideoOptimizationDetectionPolicyVideoOptimizationGlobalDetectionBinding() { + +func (s *VideoOptimizationService) CountVideoOptimizationDetectionPolicyVideoOptimizationGlobalDetectionBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", videoOptimizationDetectionPolicyVideoOptimizationGlobalDetectionBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"videooptimizationdetectionpolicy_videooptimizationglobaldetection_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil } // videooptimizationglobaldetection_binding -func (s *VideoOptimizationService) GetVideoOptimizationGlobalDetectionBinding() {} +func (s *VideoOptimizationService) GetVideoOptimizationGlobalDetectionBinding() (*models.VideoOptimizationGlobalDetectionBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationGlobalDetectionBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationGlobalDetectionBinding `json:"videooptimizationglobaldetection_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) == 0 { + return nil, fmt.Errorf("videooptimizationglobaldetection_binding not found") + } + + return &result.Bindings[0], nil +} // videooptimizationglobaldetection_videooptimizationdetectionpolicy_binding -func (s *VideoOptimizationService) AddVideoOptimizationGlobalDetectionVideoOptimizationDetectionPolicyBinding() { +func (s *VideoOptimizationService) AddVideoOptimizationGlobalDetectionVideoOptimizationDetectionPolicyBinding(resource models.VideoOptimizationGlobalDetectionVideoOptimizationDetectionPolicyBinding) error { + payload := map[string]any{ + "videooptimizationglobaldetection_videooptimizationdetectionpolicy_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, videoOptimizationGlobalDetectionVideoOptimizationDetectionPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err } -func (s *VideoOptimizationService) DeleteVideoOptimizationGlobalDetectionVideoOptimizationDetectionPolicyBinding() { + +func (s *VideoOptimizationService) DeleteVideoOptimizationGlobalDetectionVideoOptimizationDetectionPolicyBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationGlobalDetectionVideoOptimizationDetectionPolicyBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err } -func (s *VideoOptimizationService) GetVideoOptimizationGlobalDetectionVideoOptimizationDetectionPolicyBinding() { + +func (s *VideoOptimizationService) GetVideoOptimizationGlobalDetectionVideoOptimizationDetectionPolicyBinding() ([]models.VideoOptimizationGlobalDetectionVideoOptimizationDetectionPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationGlobalDetectionVideoOptimizationDetectionPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationGlobalDetectionVideoOptimizationDetectionPolicyBinding `json:"videooptimizationglobaldetection_videooptimizationdetectionpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil } -func (s *VideoOptimizationService) CountVideoOptimizationGlobalDetectionVideoOptimizationDetectionPolicyBinding() { + +func (s *VideoOptimizationService) CountVideoOptimizationGlobalDetectionVideoOptimizationDetectionPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationGlobalDetectionVideoOptimizationDetectionPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"videooptimizationglobaldetection_videooptimizationdetectionpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil } // videooptimizationglobalpacing_binding -func (s *VideoOptimizationService) GetVideoOptimizationGlobalPacingBinding() {} +func (s *VideoOptimizationService) GetVideoOptimizationGlobalPacingBinding() (*models.VideoOptimizationGlobalPacingBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationGlobalPacingBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationGlobalPacingBinding `json:"videooptimizationglobalpacing_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) == 0 { + return nil, fmt.Errorf("videooptimizationglobalpacing_binding not found") + } + + return &result.Bindings[0], nil +} // videooptimizationglobalpacing_videooptimizationpacingpolicy_binding -func (s *VideoOptimizationService) AddVideoOptimizationGlobalPacingVideoOptimizationPacingPolicyBinding() { +func (s *VideoOptimizationService) AddVideoOptimizationGlobalPacingVideoOptimizationPacingPolicyBinding(resource models.VideoOptimizationGlobalPacingVideoOptimizationPacingPolicyBinding) error { + payload := map[string]any{ + "videooptimizationglobalpacing_videooptimizationpacingpolicy_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, videoOptimizationGlobalPacingVideoOptimizationPacingPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err } -func (s *VideoOptimizationService) DeleteVideoOptimizationGlobalPacingVideoOptimizationPacingPolicyBinding() { + +func (s *VideoOptimizationService) DeleteVideoOptimizationGlobalPacingVideoOptimizationPacingPolicyBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationGlobalPacingVideoOptimizationPacingPolicyBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err } -func (s *VideoOptimizationService) GetVideoOptimizationGlobalPacingVideoOptimizationPacingPolicyBinding() { + +func (s *VideoOptimizationService) GetVideoOptimizationGlobalPacingVideoOptimizationPacingPolicyBinding() ([]models.VideoOptimizationGlobalPacingVideoOptimizationPacingPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationGlobalPacingVideoOptimizationPacingPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationGlobalPacingVideoOptimizationPacingPolicyBinding `json:"videooptimizationglobalpacing_videooptimizationpacingpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil } -func (s *VideoOptimizationService) CountVideoOptimizationGlobalPacingVideoOptimizationPacingPolicyBinding() { + +func (s *VideoOptimizationService) CountVideoOptimizationGlobalPacingVideoOptimizationPacingPolicyBinding() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationGlobalPacingVideoOptimizationPacingPolicyBindingURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"videooptimizationglobalpacing_videooptimizationpacingpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil } // videooptimizationpacingaction -func (s *VideoOptimizationService) AddVideoOptimizationPacingAction() {} -func (s *VideoOptimizationService) DeleteVideoOptimizationPacingAction() {} -func (s *VideoOptimizationService) UpdateVideoOptimizationPacingAction() {} -func (s *VideoOptimizationService) UnsetVideoOptimizationPacingAction() {} -func (s *VideoOptimizationService) RenameVideoOptimizationPacingAction() {} -func (s *VideoOptimizationService) GetAllVideoOptimizationPacingAction() {} -func (s *VideoOptimizationService) GetVideoOptimizationPacingAction() {} -func (s *VideoOptimizationService) CountVideoOptimizationPacingAction() {} +func (s *VideoOptimizationService) AddVideoOptimizationPacingAction(resource models.VideoOptimizationPacingAction) error { + payload := map[string]any{ + "videooptimizationpacingaction": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, videoOptimizationPacingActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) DeleteVideoOptimizationPacingAction(name string) error { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationPacingActionURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) UpdateVideoOptimizationPacingAction(resource models.VideoOptimizationPacingAction) error { + payload := map[string]any{ + "videooptimizationpacingaction": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, videoOptimizationPacingActionURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) UnsetVideoOptimizationPacingAction(resource models.VideoOptimizationPacingAction) error { + payload := map[string]any{ + "videooptimizationpacingaction": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, videoOptimizationPacingActionURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) RenameVideoOptimizationPacingAction(resource models.VideoOptimizationPacingAction) error { + payload := map[string]any{ + "videooptimizationpacingaction": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, videoOptimizationPacingActionURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) GetAllVideoOptimizationPacingAction() ([]models.VideoOptimizationPacingAction, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationPacingActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Actions []models.VideoOptimizationPacingAction `json:"videooptimizationpacingaction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Actions, nil +} + +func (s *VideoOptimizationService) GetVideoOptimizationPacingAction(name string) (*models.VideoOptimizationPacingAction, error) { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationPacingActionURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Actions []models.VideoOptimizationPacingAction `json:"videooptimizationpacingaction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Actions) == 0 { + return nil, fmt.Errorf("videooptimizationpacingaction not found") + } + + return &result.Actions[0], nil +} + +func (s *VideoOptimizationService) CountVideoOptimizationPacingAction() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationPacingActionURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Actions []struct { + Count float64 `json:"__count"` + } `json:"videooptimizationpacingaction"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Actions) > 0 { + return result.Actions[0].Count, nil + } + + return 0, nil +} // videooptimizationpacingpolicy -func (s *VideoOptimizationService) AddVideoOptimizationPacingPolicy() {} -func (s *VideoOptimizationService) DeleteVideoOptimizationPacingPolicy() {} -func (s *VideoOptimizationService) UpdateVideoOptimizationPacingPolicy() {} -func (s *VideoOptimizationService) UnsetVideoOptimizationPacingPolicy() {} -func (s *VideoOptimizationService) RenameVideoOptimizationPacingPolicy() {} -func (s *VideoOptimizationService) GetAllVideoOptimizationPacingPolicy() {} -func (s *VideoOptimizationService) GetVideoOptimizationPacingPolicy() {} -func (s *VideoOptimizationService) CountVideoOptimizationPacingPolicy() {} +func (s *VideoOptimizationService) AddVideoOptimizationPacingPolicy(resource models.VideoOptimizationPacingPolicy) error { + payload := map[string]any{ + "videooptimizationpacingpolicy": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, videoOptimizationPacingPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) DeleteVideoOptimizationPacingPolicy(name string) error { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationPacingPolicyURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) UpdateVideoOptimizationPacingPolicy(resource models.VideoOptimizationPacingPolicy) error { + payload := map[string]any{ + "videooptimizationpacingpolicy": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, videoOptimizationPacingPolicyURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) UnsetVideoOptimizationPacingPolicy(resource models.VideoOptimizationPacingPolicy) error { + payload := map[string]any{ + "videooptimizationpacingpolicy": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, videoOptimizationPacingPolicyURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) RenameVideoOptimizationPacingPolicy(resource models.VideoOptimizationPacingPolicy) error { + payload := map[string]any{ + "videooptimizationpacingpolicy": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, videoOptimizationPacingPolicyURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) GetAllVideoOptimizationPacingPolicy() ([]models.VideoOptimizationPacingPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationPacingPolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Policies []models.VideoOptimizationPacingPolicy `json:"videooptimizationpacingpolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Policies, nil +} + +func (s *VideoOptimizationService) GetVideoOptimizationPacingPolicy(name string) (*models.VideoOptimizationPacingPolicy, error) { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationPacingPolicyURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Policies []models.VideoOptimizationPacingPolicy `json:"videooptimizationpacingpolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Policies) == 0 { + return nil, fmt.Errorf("videooptimizationpacingpolicy not found") + } + + return &result.Policies[0], nil +} + +func (s *VideoOptimizationService) CountVideoOptimizationPacingPolicy() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationPacingPolicyURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Policies []struct { + Count float64 `json:"__count"` + } `json:"videooptimizationpacingpolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Policies) > 0 { + return result.Policies[0].Count, nil + } + + return 0, nil +} // videooptimizationpacingpolicylabel -func (s *VideoOptimizationService) AddVideoOptimizationPacingPolicyLabel() {} -func (s *VideoOptimizationService) DeleteVideoOptimizationPacingPolicyLabel() {} -func (s *VideoOptimizationService) RenameVideoOptimizationPacingPolicyLabel() {} -func (s *VideoOptimizationService) GetAllVideoOptimizationPacingPolicyLabel() {} -func (s *VideoOptimizationService) GetVideoOptimizationPacingPolicyLabel() {} -func (s *VideoOptimizationService) CountVideoOptimizationPacingPolicyLabel() {} +func (s *VideoOptimizationService) AddVideoOptimizationPacingPolicyLabel(resource models.VideoOptimizationPacingPolicyLabel) error { + payload := map[string]any{ + "videooptimizationpacingpolicylabel": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, videoOptimizationPacingPolicyLabelURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) DeleteVideoOptimizationPacingPolicyLabel(name string) error { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationPacingPolicyLabelURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) RenameVideoOptimizationPacingPolicyLabel(resource models.VideoOptimizationPacingPolicyLabel) error { + payload := map[string]any{ + "videooptimizationpacingpolicylabel": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, videoOptimizationPacingPolicyLabelURL+"?action=rename", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) GetAllVideoOptimizationPacingPolicyLabel() ([]models.VideoOptimizationPacingPolicyLabel, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationPacingPolicyLabelURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Labels []models.VideoOptimizationPacingPolicyLabel `json:"videooptimizationpacingpolicylabel"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Labels, nil +} + +func (s *VideoOptimizationService) GetVideoOptimizationPacingPolicyLabel(name string) (*models.VideoOptimizationPacingPolicyLabel, error) { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationPacingPolicyLabelURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Labels []models.VideoOptimizationPacingPolicyLabel `json:"videooptimizationpacingpolicylabel"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Labels) == 0 { + return nil, fmt.Errorf("videooptimizationpacingpolicylabel not found") + } + + return &result.Labels[0], nil +} + +func (s *VideoOptimizationService) CountVideoOptimizationPacingPolicyLabel() (float64, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationPacingPolicyLabelURL+"?count=yes", nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Labels []struct { + Count float64 `json:"__count"` + } `json:"videooptimizationpacingpolicylabel"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Labels) > 0 { + return result.Labels[0].Count, nil + } + + return 0, nil +} // videooptimizationpacingpolicylabel_binding -func (s *VideoOptimizationService) GetAllVideoOptimizationPacingPolicyLabelBinding() {} -func (s *VideoOptimizationService) GetVideoOptimizationPacingPolicyLabelBinding() {} +func (s *VideoOptimizationService) GetAllVideoOptimizationPacingPolicyLabelBinding() ([]models.VideoOptimizationPacingPolicyLabelBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationPacingPolicyLabelBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationPacingPolicyLabelBinding `json:"videooptimizationpacingpolicylabel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *VideoOptimizationService) GetVideoOptimizationPacingPolicyLabelBinding(name string) (*models.VideoOptimizationPacingPolicyLabelBinding, error) { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationPacingPolicyLabelBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationPacingPolicyLabelBinding `json:"videooptimizationpacingpolicylabel_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) == 0 { + return nil, fmt.Errorf("videooptimizationpacingpolicylabel_binding not found") + } + + return &result.Bindings[0], nil +} // videooptimizationpacingpolicylabel_policybinding_binding -func (s *VideoOptimizationService) GetAllVideoOptimizationPacingPolicyLabelPolicyBindingBinding() {} -func (s *VideoOptimizationService) GetVideoOptimizationPacingPolicyLabelPolicyBindingBinding() {} -func (s *VideoOptimizationService) CountVideoOptimizationPacingPolicyLabelPolicyBindingBinding() {} +func (s *VideoOptimizationService) GetAllVideoOptimizationPacingPolicyLabelPolicyBindingBinding() ([]models.VideoOptimizationPacingPolicyLabelPolicyBindingBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationPacingPolicyLabelPolicyBindingBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationPacingPolicyLabelPolicyBindingBinding `json:"videooptimizationpacingpolicylabel_policybinding_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *VideoOptimizationService) GetVideoOptimizationPacingPolicyLabelPolicyBindingBinding(name string) ([]models.VideoOptimizationPacingPolicyLabelPolicyBindingBinding, error) { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationPacingPolicyLabelPolicyBindingBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationPacingPolicyLabelPolicyBindingBinding `json:"videooptimizationpacingpolicylabel_policybinding_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *VideoOptimizationService) CountVideoOptimizationPacingPolicyLabelPolicyBindingBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", videoOptimizationPacingPolicyLabelPolicyBindingBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"videooptimizationpacingpolicylabel_policybinding_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} // videooptimizationpacingpolicylabel_videooptimizationpacingpolicy_binding -func (s *VideoOptimizationService) AddVideoOptimizationPacingPolicyLabelVideoOptimizationPacingPolicyBinding() { +func (s *VideoOptimizationService) AddVideoOptimizationPacingPolicyLabelVideoOptimizationPacingPolicyBinding(resource models.VideoOptimizationPacingPolicyLabelVideoOptimizationPacingPolicyBinding) error { + payload := map[string]any{ + "videooptimizationpacingpolicylabel_videooptimizationpacingpolicy_binding": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, videoOptimizationPacingPolicyLabelVideoOptimizationPacingPolicyBindingURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err } -func (s *VideoOptimizationService) DeleteVideoOptimizationPacingPolicyLabelVideoOptimizationPacingPolicyBinding() { + +func (s *VideoOptimizationService) DeleteVideoOptimizationPacingPolicyLabelVideoOptimizationPacingPolicyBinding(name string, args string) error { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationPacingPolicyLabelVideoOptimizationPacingPolicyBindingURL, url.PathEscape(name)) + if args != "" { + reqURL += "?args=" + url.QueryEscape(args) + } + req, err := s.client.NewRequest(http.MethodDelete, reqURL, nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err } -func (s *VideoOptimizationService) GetAllVideoOptimizationPacingPolicyLabelVideoOptimizationPacingPolicyBinding() { + +func (s *VideoOptimizationService) GetAllVideoOptimizationPacingPolicyLabelVideoOptimizationPacingPolicyBinding() ([]models.VideoOptimizationPacingPolicyLabelVideoOptimizationPacingPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationPacingPolicyLabelVideoOptimizationPacingPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationPacingPolicyLabelVideoOptimizationPacingPolicyBinding `json:"videooptimizationpacingpolicylabel_videooptimizationpacingpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil } -func (s *VideoOptimizationService) GetVideoOptimizationPacingPolicyLabelVideoOptimizationPacingPolicyBinding() { + +func (s *VideoOptimizationService) GetVideoOptimizationPacingPolicyLabelVideoOptimizationPacingPolicyBinding(name string) ([]models.VideoOptimizationPacingPolicyLabelVideoOptimizationPacingPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationPacingPolicyLabelVideoOptimizationPacingPolicyBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationPacingPolicyLabelVideoOptimizationPacingPolicyBinding `json:"videooptimizationpacingpolicylabel_videooptimizationpacingpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil } -func (s *VideoOptimizationService) CountVideoOptimizationPacingPolicyLabelVideoOptimizationPacingPolicyBinding() { + +func (s *VideoOptimizationService) CountVideoOptimizationPacingPolicyLabelVideoOptimizationPacingPolicyBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", videoOptimizationPacingPolicyLabelVideoOptimizationPacingPolicyBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"videooptimizationpacingpolicylabel_videooptimizationpacingpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil } // videooptimizationpacingpolicy_binding -func (s *VideoOptimizationService) GetAllVideoOptimizationPacingPolicyBinding() {} -func (s *VideoOptimizationService) GetVideoOptimizationPacingPolicyBinding() {} +func (s *VideoOptimizationService) GetAllVideoOptimizationPacingPolicyBinding() ([]models.VideoOptimizationPacingPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationPacingPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationPacingPolicyBinding `json:"videooptimizationpacingpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *VideoOptimizationService) GetVideoOptimizationPacingPolicyBinding(name string) (*models.VideoOptimizationPacingPolicyBinding, error) { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationPacingPolicyBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationPacingPolicyBinding `json:"videooptimizationpacingpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) == 0 { + return nil, fmt.Errorf("videooptimizationpacingpolicy_binding not found") + } + + return &result.Bindings[0], nil +} // videooptimizationpacingpolicy_lbvserver_binding -func (s *VideoOptimizationService) GetAllVideoOptimizationPacingPolicyLBVServerBinding() {} -func (s *VideoOptimizationService) GetVideoOptimizationPacingPolicyLBVServerBinding() {} -func (s *VideoOptimizationService) CountVideoOptimizationPacingPolicyLBVServerBinding() {} +func (s *VideoOptimizationService) GetAllVideoOptimizationPacingPolicyLBVServerBinding() ([]models.VideoOptimizationPacingPolicyLBVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationPacingPolicyLBVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationPacingPolicyLBVServerBinding `json:"videooptimizationpacingpolicy_lbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *VideoOptimizationService) GetVideoOptimizationPacingPolicyLBVServerBinding(name string) ([]models.VideoOptimizationPacingPolicyLBVServerBinding, error) { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationPacingPolicyLBVServerBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationPacingPolicyLBVServerBinding `json:"videooptimizationpacingpolicy_lbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil +} + +func (s *VideoOptimizationService) CountVideoOptimizationPacingPolicyLBVServerBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", videoOptimizationPacingPolicyLBVServerBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"videooptimizationpacingpolicy_lbvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil +} // videooptimizationpacingpolicy_videooptimizationglobalpacing_binding -func (s *VideoOptimizationService) GetAllVideoOptimizationPacingPolicyVideoOptimizationGlobalPacingBinding() { +func (s *VideoOptimizationService) GetAllVideoOptimizationPacingPolicyVideoOptimizationGlobalPacingBinding() ([]models.VideoOptimizationPacingPolicyVideoOptimizationGlobalPacingBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationPacingPolicyVideoOptimizationGlobalPacingBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationPacingPolicyVideoOptimizationGlobalPacingBinding `json:"videooptimizationpacingpolicy_videooptimizationglobalpacing_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil } -func (s *VideoOptimizationService) GetVideoOptimizationPacingPolicyVideoOptimizationGlobalPacingBinding() { + +func (s *VideoOptimizationService) GetVideoOptimizationPacingPolicyVideoOptimizationGlobalPacingBinding(name string) ([]models.VideoOptimizationPacingPolicyVideoOptimizationGlobalPacingBinding, error) { + reqURL := fmt.Sprintf("%s/%s", videoOptimizationPacingPolicyVideoOptimizationGlobalPacingBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Bindings []models.VideoOptimizationPacingPolicyVideoOptimizationGlobalPacingBinding `json:"videooptimizationpacingpolicy_videooptimizationglobalpacing_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Bindings, nil } -func (s *VideoOptimizationService) CountVideoOptimizationPacingPolicyVideoOptimizationGlobalPacingBinding() { + +func (s *VideoOptimizationService) CountVideoOptimizationPacingPolicyVideoOptimizationGlobalPacingBinding(name string) (float64, error) { + reqURL := fmt.Sprintf("%s/%s?count=yes", videoOptimizationPacingPolicyVideoOptimizationGlobalPacingBindingURL, url.PathEscape(name)) + req, err := s.client.NewRequest(http.MethodGet, reqURL, nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Bindings []struct { + Count float64 `json:"__count"` + } `json:"videooptimizationpacingpolicy_videooptimizationglobalpacing_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Bindings) > 0 { + return result.Bindings[0].Count, nil + } + + return 0, nil } // videooptimizationparameter -func (s *VideoOptimizationService) UpdateVideoOptimizationParameter() {} -func (s *VideoOptimizationService) UnsetVideoOptimizationParameter() {} -func (s *VideoOptimizationService) GetAllVideoOptimizationParameter() {} +func (s *VideoOptimizationService) UpdateVideoOptimizationParameter(resource models.VideoOptimizationParameter) error { + payload := map[string]any{ + "videooptimizationparameter": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPut, videoOptimizationParameterURL, bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) UnsetVideoOptimizationParameter(resource models.VideoOptimizationParameter) error { + payload := map[string]any{ + "videooptimizationparameter": resource, + } + body, err := json.Marshal(payload) + if err != nil { + return fmt.Errorf("failed to marshal payload: %w", err) + } + + req, err := s.client.NewRequest(http.MethodPost, videoOptimizationParameterURL+"?action=unset", bytes.NewBuffer(body)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VideoOptimizationService) GetAllVideoOptimizationParameter() (*models.VideoOptimizationParameter, error) { + req, err := s.client.NewRequest(http.MethodGet, videoOptimizationParameterURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Parameters []models.VideoOptimizationParameter `json:"videooptimizationparameter"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Parameters) == 0 { + return nil, fmt.Errorf("videooptimizationparameter not found") + } + + return &result.Parameters[0], nil +} diff --git a/nitrogo/vpn.go b/nitrogo/vpn.go index 03389a9..7f5f0e6 100644 --- a/nitrogo/vpn.go +++ b/nitrogo/vpn.go @@ -1,5 +1,145 @@ package nitrogo +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + + "github.com/AdamJCrawford/NitroGo/nitrogo/models" +) + +const ( + vpnAlwaysOnProfileURL = "/nitro/v1/config/vpnalwaysonprofile" + vpnClientlessAccessPolicyURL = "/nitro/v1/config/vpnclientlessaccesspolicy" + vpnClientlessAccessPolicyBindingURL = "/nitro/v1/config/vpnclientlessaccesspolicy_binding" + vpnClientlessAccessPolicyVPNGlobalBindingURL = "/nitro/v1/config/vpnclientlessaccesspolicy_vpnglobal_binding" + vpnClientlessAccessPolicyVPNVServerBindingURL = "/nitro/v1/config/vpnclientlessaccesspolicy_vpnvserver_binding" + vpnClientlessAccessProfileURL = "/nitro/v1/config/vpnclientlessaccessprofile" + vpnEPAProfileURL = "/nitro/v1/config/vpnepaprofile" + vpnEULAURL = "/nitro/v1/config/vpneula" + vpnFormSSOActionURL = "/nitro/v1/config/vpnformssoaction" + vpnFormSSOProfileURL = "/nitro/v1/config/vpnformssoprofile" + vpnGlobalBindingURL = "/nitro/v1/config/vpnglobal_binding" + vpnGlobalAppControllerBindingURL = "/nitro/v1/config/vpnglobal_appcontroller_binding" + vpnGlobalAppFlowPolicyBindingURL = "/nitro/v1/config/vpnglobal_appflowpolicy_binding" + vpnGlobalAuditNSLogPolicyBindingURL = "/nitro/v1/config/vpnglobal_auditnslogpolicy_binding" + vpnGlobalAuditSyslogPolicyBindingURL = "/nitro/v1/config/vpnglobal_auditsyslogpolicy_binding" + vpnGlobalAuthenticationCertPolicyBindingURL = "/nitro/v1/config/vpnglobal_authenticationcertpolicy_binding" + vpnGlobalAuthenticationLDAPPolicyBindingURL = "/nitro/v1/config/vpnglobal_authenticationldappolicy_binding" + vpnGlobalAuthenticationLocalPolicyBindingURL = "/nitro/v1/config/vpnglobal_authenticationlocalpolicy_binding" + vpnGlobalAuthenticationNegotiatePolicyBindingURL = "/nitro/v1/config/vpnglobal_authenticationnegotiatepolicy_binding" + vpnGlobalAuthenticationPolicyBindingURL = "/nitro/v1/config/vpnglobal_authenticationpolicy_binding" + vpnGlobalAuthenticationRADIUSPolicyBindingURL = "/nitro/v1/config/vpnglobal_authenticationradiuspolicy_binding" + vpnGlobalAuthenticationSAMLPolicyBindingURL = "/nitro/v1/config/vpnglobal_authenticationsamlpolicy_binding" + vpnGlobalAuthenticationTACACSPolicyBindingURL = "/nitro/v1/config/vpnglobal_authenticationtacacspolicy_binding" + vpnGlobalDomainBindingURL = "/nitro/v1/config/vpnglobal_domain_binding" + vpnGlobalIntranetIP6BindingURL = "/nitro/v1/config/vpnglobal_intranetip6_binding" + vpnGlobalIntranetIPBindingURL = "/nitro/v1/config/vpnglobal_intranetip_binding" + vpnGlobalShareFileServerBindingURL = "/nitro/v1/config/vpnglobal_sharefileserver_binding" + vpnGlobalSSLCertKeyBindingURL = "/nitro/v1/config/vpnglobal_sslcertkey_binding" + vpnGlobalSTAServerBindingURL = "/nitro/v1/config/vpnglobal_staserver_binding" + vpnGlobalVPNClientlessAccessPolicyBindingURL = "/nitro/v1/config/vpnglobal_vpnclientlessaccesspolicy_binding" + vpnGlobalVPNEULABindingURL = "/nitro/v1/config/vpnglobal_vpneula_binding" + vpnGlobalVPNIntranetApplicationBindingURL = "/nitro/v1/config/vpnglobal_vpnintranetapplication_binding" + vpnGlobalVPNNextHopServerBindingURL = "/nitro/v1/config/vpnglobal_vpnnexthopserver_binding" + vpnGlobalVPNPortalThemeBindingURL = "/nitro/v1/config/vpnglobal_vpnportaltheme_binding" + vpnGlobalVPNSessionPolicyBindingURL = "/nitro/v1/config/vpnglobal_vpnsessionpolicy_binding" + vpnGlobalVPNTrafficPolicyBindingURL = "/nitro/v1/config/vpnglobal_vpntrafficpolicy_binding" + vpnGlobalVPNURLPolicyBindingURL = "/nitro/v1/config/vpnglobal_vpnurlpolicy_binding" + vpnGlobalVPNURLBindingURL = "/nitro/v1/config/vpnglobal_vpnurl_binding" + vpnICAConnectionURL = "/nitro/v1/config/vpnicaconnection" + vpnICADTLSConnectionURL = "/nitro/v1/config/vpnicadtlsconnection" + vpnIntranetApplicationURL = "/nitro/v1/config/vpnintranetapplication" + vpnIntranetApplicationBindingURL = "/nitro/v1/config/vpnintranetapplication_binding" + vpnIntranetApplicationVPNURLBindingURL = "/nitro/v1/config/vpnintranetapplication_vpnurl_binding" + vpnNextHopServerURL = "/nitro/v1/config/vpnnexthopserver" + vpnNextGenVServerURL = "/nitro/v1/config/vpnnextgenvserver" + vpnParameterURL = "/nitro/v1/config/vpnparameter" + vpnPCoIPConnectionURL = "/nitro/v1/config/vpnpcoipconnection" + vpnPCoIPProfileURL = "/nitro/v1/config/vpnpcoipprofile" + vpnPCoIPVServerProfileURL = "/nitro/v1/config/vpnpcoipvserverprofile" + vpnPortalThemeURL = "/nitro/v1/config/vpnportaltheme" + vpnSAMLSSOProfileURL = "/nitro/v1/config/vpnsamlssoprofile" + vpnSessionActionURL = "/nitro/v1/config/vpnsessionaction" + vpnSessionPolicyURL = "/nitro/v1/config/vpnsessionpolicy" + vpnSessionPolicyBindingURL = "/nitro/v1/config/vpnsessionpolicy_binding" + vpnSessionPolicyAAAGroupBindingURL = "/nitro/v1/config/vpnsessionpolicy_aaagroup_binding" + vpnSessionPolicyAAAUserBindingURL = "/nitro/v1/config/vpnsessionpolicy_aaauser_binding" + vpnSessionPolicyVPNGlobalBindingURL = "/nitro/v1/config/vpnsessionpolicy_vpnglobal_binding" + vpnSessionPolicyVPNVServerBindingURL = "/nitro/v1/config/vpnsessionpolicy_vpnvserver_binding" + vpnSFConfigURL = "/nitro/v1/config/vpnsfconfig" + vpnStoreInfoURL = "/nitro/v1/config/vpnstoreinfo" + vpnTrafficActionURL = "/nitro/v1/config/vpntrafficaction" + vpnTrafficPolicyURL = "/nitro/v1/config/vpntrafficpolicy" + vpnTrafficPolicyBindingURL = "/nitro/v1/config/vpntrafficpolicy_binding" + vpnTrafficPolicyAAAGroupBindingURL = "/nitro/v1/config/vpntrafficpolicy_aaagroup_binding" + vpnTrafficPolicyAAAUserBindingURL = "/nitro/v1/config/vpntrafficpolicy_aaauser_binding" + vpnTrafficPolicyVPNGlobalBindingURL = "/nitro/v1/config/vpntrafficpolicy_vpnglobal_binding" + vpnTrafficPolicyVPNVServerBindingURL = "/nitro/v1/config/vpntrafficpolicy_vpnvserver_binding" + vpnURLURL = "/nitro/v1/config/vpnurl" + vpnURLActionURL = "/nitro/v1/config/vpnurlaction" + vpnURLBindingURL = "/nitro/v1/config/vpnurl_binding" + vpnURLMemberBindingURL = "/nitro/v1/config/vpnurl_member_binding" + vpnURLVPNIntranetApplicationBindingURL = "/nitro/v1/config/vpnurl_vpnintranetapplication_binding" + vpnURLPolicyURL = "/nitro/v1/config/vpnurlpolicy" + vpnURLPolicyBindingURL = "/nitro/v1/config/vpnurlpolicy_binding" + vpnURLPolicyAAAGroupBindingURL = "/nitro/v1/config/vpnurlpolicy_aaagroup_binding" + vpnURLPolicyAAAUserBindingURL = "/nitro/v1/config/vpnurlpolicy_aaauser_binding" + vpnURLPolicyVPNGlobalBindingURL = "/nitro/v1/config/vpnurlpolicy_vpnglobal_binding" + vpnURLPolicyVPNVServerBindingURL = "/nitro/v1/config/vpnurlpolicy_vpnvserver_binding" + vpnVServerURL = "/nitro/v1/config/vpnvserver" + vpnVServerBindingURL = "/nitro/v1/config/vpnvserver_binding" + vpnVServerAAAGroupBindingURL = "/nitro/v1/config/vpnvserver_aaagroup_binding" + vpnVServerAAAPreauthenticationPolicyBindingURL = "/nitro/v1/config/vpnvserver_aaapreauthenticationpolicy_binding" + vpnVServerAAAUserBindingURL = "/nitro/v1/config/vpnvserver_aaauser_binding" + vpnVServerAnalyticsProfileBindingURL = "/nitro/v1/config/vpnvserver_analyticsprofile_binding" + vpnVServerAppControllerBindingURL = "/nitro/v1/config/vpnvserver_appcontroller_binding" + vpnVServerAppFlowPolicyBindingURL = "/nitro/v1/config/vpnvserver_appflowpolicy_binding" + vpnVServerAppQOEPolicyBindingURL = "/nitro/v1/config/vpnvserver_appqoepolicy_binding" + vpnVServerAuditNSLogPolicyBindingURL = "/nitro/v1/config/vpnvserver_auditnslogpolicy_binding" + vpnVServerAuditSyslogPolicyBindingURL = "/nitro/v1/config/vpnvserver_auditsyslogpolicy_binding" + vpnVServerAuthenticationCertPolicyBindingURL = "/nitro/v1/config/vpnvserver_authenticationcertpolicy_binding" + vpnVServerAuthenticationFAPolicyBindingURL = "/nitro/v1/config/vpnvserver_authenticationfapolicy_binding" + vpnVServerAuthenticationLDAPPolicyBindingURL = "/nitro/v1/config/vpnvserver_authenticationldappolicy_binding" + vpnVServerAuthenticationLocalPolicyBindingURL = "/nitro/v1/config/vpnvserver_authenticationlocalpolicy_binding" + vpnVServerAuthenticationLoginSchemaPolicyBindingURL = "/nitro/v1/config/vpnvserver_authenticationloginschemapolicy_binding" + vpnVServerAuthenticationNegotiatePolicyBindingURL = "/nitro/v1/config/vpnvserver_authenticationnegotiatepolicy_binding" + vpnVServerAuthenticationOAuthIDPPolicyBindingURL = "/nitro/v1/config/vpnvserver_authenticationoauthidppolicy_binding" + vpnVServerAuthenticationPolicyBindingURL = "/nitro/v1/config/vpnvserver_authenticationpolicy_binding" + vpnVServerAuthenticationRADIUSPolicyBindingURL = "/nitro/v1/config/vpnvserver_authenticationradiuspolicy_binding" + vpnVServerAuthenticationSAMLIDPPolicyBindingURL = "/nitro/v1/config/vpnvserver_authenticationsamlidppolicy_binding" + vpnVServerAuthenticationSAMLPolicyBindingURL = "/nitro/v1/config/vpnvserver_authenticationsamlpolicy_binding" + vpnVServerAuthenticationTACACSPolicyBindingURL = "/nitro/v1/config/vpnvserver_authenticationtacacspolicy_binding" + vpnVServerAuthenticationWebAuthPolicyBindingURL = "/nitro/v1/config/vpnvserver_authenticationwebauthpolicy_binding" + vpnVServerCachePolicyBindingURL = "/nitro/v1/config/vpnvserver_cachepolicy_binding" + vpnVServerCMPPolicyBindingURL = "/nitro/v1/config/vpnvserver_cmppolicy_binding" + vpnVServerCSPolicyBindingURL = "/nitro/v1/config/vpnvserver_cspolicy_binding" + vpnVServerFEOPolicyBindingURL = "/nitro/v1/config/vpnvserver_feopolicy_binding" + vpnVServerICAPolicyBindingURL = "/nitro/v1/config/vpnvserver_icapolicy_binding" + vpnVServerIntranetIP6BindingURL = "/nitro/v1/config/vpnvserver_intranetip6_binding" + vpnVServerIntranetIPBindingURL = "/nitro/v1/config/vpnvserver_intranetip_binding" + vpnVServerLBVServerBindingURL = "/nitro/v1/config/vpnvserver_lbvserver_binding" + vpnVServerNextHopVPNVServerBindingURL = "/nitro/v1/config/vpnvserver_nexthopvpnvserver_binding" + vpnVServerResponderPolicyBindingURL = "/nitro/v1/config/vpnvserver_responderpolicy_binding" + vpnVServerRewritePolicyBindingURL = "/nitro/v1/config/vpnvserver_rewritepolicy_binding" + vpnVServerShareFileServerBindingURL = "/nitro/v1/config/vpnvserver_sharefileserver_binding" + vpnVServerSTAServerBindingURL = "/nitro/v1/config/vpnvserver_staserver_binding" + vpnVServerTMTrafficPolicyBindingURL = "/nitro/v1/config/vpnvserver_tmtrafficpolicy_binding" + vpnVServerURLFilteringPolicyBindingURL = "/nitro/v1/config/vpnvserver_urlfilteringpolicy_binding" + vpnVServerVPNClientlessAccessPolicyBindingURL = "/nitro/v1/config/vpnvserver_vpnclientlessaccesspolicy_binding" + vpnVServerVPNEPAProfileBindingURL = "/nitro/v1/config/vpnvserver_vpnepaprofile_binding" + vpnVServerVPNEULABindingURL = "/nitro/v1/config/vpnvserver_vpneula_binding" + vpnVServerVPNIntranetApplicationBindingURL = "/nitro/v1/config/vpnvserver_vpnintranetapplication_binding" + vpnVServerVPNNextHopServerBindingURL = "/nitro/v1/config/vpnvserver_vpnnexthopserver_binding" + vpnVServerVPNNextGenVServerBindingURL = "/nitro/v1/config/vpnvserver_vpnnextgenvserver_binding" + vpnVServerVPNPortalThemeBindingURL = "/nitro/v1/config/vpnvserver_vpnportaltheme_binding" + vpnVServerVPNSessionPolicyBindingURL = "/nitro/v1/config/vpnvserver_vpnsessionpolicy_binding" + vpnVServerVPNTrafficPolicyBindingURL = "/nitro/v1/config/vpnvserver_vpntrafficpolicy_binding" + vpnVServerVPNURLBindingURL = "/nitro/v1/config/vpnvserver_vpnurl_binding" + vpnVServerVPNURLPolicyBindingURL = "/nitro/v1/config/vpnvserver_vpnurlpolicy_binding" +) + // SSL VPN // Virtual Private Network configuration. // https://developer-docs.netscaler.com/en-us/adc-nitro-api/current-release/configuration/vpn/vpn @@ -8,725 +148,9914 @@ type VPNService struct { } // vpnalwaysonprofile -func (s *VPNService) AddVPNAlwaysOnProfile() {} -func (s *VPNService) DeleteVPNAlwaysOnProfile() {} -func (s *VPNService) UpdateVPNAlwaysOnProfile() {} -func (s *VPNService) UnsetVPNAlwaysOnProfile() {} -func (s *VPNService) GetAllVPNAlwaysOnProfile() {} -func (s *VPNService) GetVPNAlwaysOnProfile() {} -func (s *VPNService) CountVPNAlwaysOnProfile() {} +func (s *VPNService) AddVPNAlwaysOnProfile(resource models.VPNAlwaysOnProfile) error { + payload := map[string]any{"vpnalwaysonprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnAlwaysOnProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNAlwaysOnProfile(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnAlwaysOnProfileURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) UpdateVPNAlwaysOnProfile(resource models.VPNAlwaysOnProfile) error { + payload := map[string]any{"vpnalwaysonprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, vpnAlwaysOnProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) UnsetVPNAlwaysOnProfile(resource models.VPNAlwaysOnProfile) error { + payload := map[string]any{"vpnalwaysonprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", vpnAlwaysOnProfileURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNAlwaysOnProfile() ([]models.VPNAlwaysOnProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnAlwaysOnProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNAlwaysOnProfile `json:"vpnalwaysonprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNAlwaysOnProfile(name string) (*models.VPNAlwaysOnProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnAlwaysOnProfileURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNAlwaysOnProfile `json:"vpnalwaysonprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNAlwaysOnProfile() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnAlwaysOnProfileURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNAlwaysOnProfile `json:"vpnalwaysonprofile"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} // vpnclientlessaccesspolicy -func (s *VPNService) AddVPNClientLessAccessPolicy() {} -func (s *VPNService) DeleteVPNClientLessAccessPolicy() {} -func (s *VPNService) UpdateVPNClientLessAccessPolicy() {} -func (s *VPNService) GetAllVPNClientLessAccessPolicy() {} -func (s *VPNService) GetVPNClientLessAccessPolicy() {} -func (s *VPNService) CountVPNClientLessAccessPolicy() {} +func (s *VPNService) AddVPNClientLessAccessPolicy(resource models.VPNClientlessAccessPolicy) error { + payload := map[string]any{"vpnclientlessaccesspolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnClientlessAccessPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNClientLessAccessPolicy(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnClientlessAccessPolicyURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) UpdateVPNClientLessAccessPolicy(resource models.VPNClientlessAccessPolicy) error { + payload := map[string]any{"vpnclientlessaccesspolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, vpnClientlessAccessPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNClientLessAccessPolicy() ([]models.VPNClientlessAccessPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnClientlessAccessPolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNClientlessAccessPolicy `json:"vpnclientlessaccesspolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNClientLessAccessPolicy(name string) (*models.VPNClientlessAccessPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnClientlessAccessPolicyURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNClientlessAccessPolicy `json:"vpnclientlessaccesspolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNClientLessAccessPolicy() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnClientlessAccessPolicyURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNClientlessAccessPolicy `json:"vpnclientlessaccesspolicy"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} // vpnclientlessaccesspolicy_binding -func (s *VPNService) GetAllVPNClientLessAccessPolicyBinding() {} -func (s *VPNService) GetVPNClientLessAccessPolicyBinding() {} +func (s *VPNService) GetAllVPNClientLessAccessPolicyBinding() ([]models.VPNClientlessAccessPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnClientlessAccessPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNClientlessAccessPolicyBinding `json:"vpnclientlessaccesspolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNClientLessAccessPolicyBinding(name string) (*models.VPNClientlessAccessPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnClientlessAccessPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNClientlessAccessPolicyBinding `json:"vpnclientlessaccesspolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} // vpnclientlessaccesspolicy_vpnglobal_binding -func (s *VPNService) GetAllVPNClientLessAccessPolicyVPNGlobalBinding() {} -func (s *VPNService) GetVPNClientLessAccessPolicyVPNGlobalBinding() {} -func (s *VPNService) CountVPNClientLessAccessPolicyVPNGlobalBinding() {} +func (s *VPNService) GetAllVPNClientLessAccessPolicyVPNGlobalBinding() ([]models.VPNClientlessAccessPolicyVPNGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnClientlessAccessPolicyVPNGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNClientlessAccessPolicyVPNGlobalBinding `json:"vpnclientlessaccesspolicy_vpnglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNClientLessAccessPolicyVPNGlobalBinding(name string) (*models.VPNClientlessAccessPolicyVPNGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnClientlessAccessPolicyVPNGlobalBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNClientlessAccessPolicyVPNGlobalBinding `json:"vpnclientlessaccesspolicy_vpnglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNClientLessAccessPolicyVPNGlobalBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnClientlessAccessPolicyVPNGlobalBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNClientlessAccessPolicyVPNGlobalBinding `json:"vpnclientlessaccesspolicy_vpnglobal_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} // vpnclientlessaccesspolicy_vpnvserver_binding -func (s *VPNService) GetAllVPNClientLessAccessPolicyVPNVServerBinding() {} -func (s *VPNService) GetVPNClientLessAccessPolicyVPNVServerBinding() {} -func (s *VPNService) CountVPNClientLessAccessPolicyVPNVServerBinding() {} +func (s *VPNService) GetAllVPNClientLessAccessPolicyVPNVServerBinding() ([]models.VPNClientlessAccessPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnClientlessAccessPolicyVPNVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNClientlessAccessPolicyVPNVServerBinding `json:"vpnclientlessaccesspolicy_vpnvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNClientLessAccessPolicyVPNVServerBinding(name string) (*models.VPNClientlessAccessPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnClientlessAccessPolicyVPNVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNClientlessAccessPolicyVPNVServerBinding `json:"vpnclientlessaccesspolicy_vpnvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNClientLessAccessPolicyVPNVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnClientlessAccessPolicyVPNVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNClientlessAccessPolicyVPNVServerBinding `json:"vpnclientlessaccesspolicy_vpnvserver_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} // vpnclientlessaccessprofile -func (s *VPNService) AddVPNClientLessAccessProfile() {} -func (s *VPNService) DeleteVPNClientLessAccessProfile() {} -func (s *VPNService) UpdateVPNClientLessAccessProfile() {} -func (s *VPNService) UnsetVPNClientLessAccessProfile() {} -func (s *VPNService) GetAllVPNClientLessAccessProfile() {} -func (s *VPNService) GetVPNClientLessAccessProfile() {} -func (s *VPNService) CountVPNClientLessAccessProfile() {} +func (s *VPNService) AddVPNClientLessAccessProfile(resource models.VPNClientlessAccessProfile) error { + payload := map[string]any{"vpnclientlessaccessprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// vpnepaprofile -func (s *VPNService) AddVPNEPAProfile() {} -func (s *VPNService) DeleteVPNEPAProfile() {} -func (s *VPNService) GetAllVPNEPAProfile() {} -func (s *VPNService) GetVPNEPAProfile() {} -func (s *VPNService) CountVPNEPAProfile() {} + req, err := s.client.NewRequest(http.MethodPost, vpnClientlessAccessProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } -// vpneula -func (s *VPNService) AddVPNEULA() {} -func (s *VPNService) DeleteVPNEULA() {} -func (s *VPNService) GetAllVPNEULA() {} -func (s *VPNService) GetVPNEULA() {} -func (s *VPNService) CountVPNEULA() {} + _, err = s.client.Do(req) + return err +} -// vpnformssoaction -func (s *VPNService) AddVPNFormSSOAction() {} -func (s *VPNService) DeleteVPNFormSSOAction() {} -func (s *VPNService) UpdateVPNFormSSOAction() {} -func (s *VPNService) UnsetVPNFormSSOAction() {} -func (s *VPNService) GetAllVPNFormSSOAction() {} -func (s *VPNService) GetVPNFormSSOAction() {} -func (s *VPNService) CountVPNFormSSOAction() {} +func (s *VPNService) DeleteVPNClientLessAccessProfile(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnClientlessAccessProfileURL, name), nil) + if err != nil { + return err + } -// vpnglobal_appcontroller_binding -func (s *VPNService) AddVPNGlobalAppControllerBinding() {} -func (s *VPNService) DeleteVPNGlobalAppControllerBinding() {} -func (s *VPNService) GetVPNGlobalAppControllerBinding() {} -func (s *VPNService) CountVPNGlobalAppControllerBinding() {} + _, err = s.client.Do(req) + return err +} -// vpnglobal_auditnslogpolicy_binding -func (s *VPNService) AddVPNGlobalAuditNSLogPolicyBinding() {} -func (s *VPNService) DeleteVPNGlobalAuditNSLogPolicyBinding() {} -func (s *VPNService) GetVPNGlobalAuditNSLogPolicyBinding() {} -func (s *VPNService) CountVPNGlobalAuditNSLogPolicyBinding() {} +func (s *VPNService) UpdateVPNClientLessAccessProfile(resource models.VPNClientlessAccessProfile) error { + payload := map[string]any{"vpnclientlessaccessprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// vpnglobal_auditsyslogpolicy_binding -func (s *VPNService) AddVPNGlobalAuditSyslogPolicyBinding() {} -func (s *VPNService) DeleteVPNGlobalAuditSyslogPolicyBinding() {} -func (s *VPNService) GetVPNGlobalAuditSyslogPolicyBinding() {} -func (s *VPNService) CountVPNGlobalAuditSyslogPolicyBinding() {} + req, err := s.client.NewRequest(http.MethodPut, vpnClientlessAccessProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } -// vpnglobal_authenticationcertpolicy_binding -func (s *VPNService) AddVPNGlobalAuthenticationCertPolicyBinding() {} -func (s *VPNService) DeleteVPNGlobalAuthenticationCertPolicyBinding() {} -func (s *VPNService) GetVPNGlobalAuthenticationCertPolicyBinding() {} -func (s *VPNService) CountVPNGlobalAuthenticationCertPolicyBinding() {} + _, err = s.client.Do(req) + return err +} -// vpnglobal_authenticationldappolicy_binding -func (s *VPNService) AddVPNGlobalAuthenticationLDAPPolicyBinding() {} -func (s *VPNService) DeleteVPNGlobalAuthenticationLDAPPolicyBinding() {} -func (s *VPNService) GetVPNGlobalAuthenticationLDAPPolicyBinding() {} -func (s *VPNService) CountVPNGlobalAuthenticationLDAPPolicyBinding() {} +func (s *VPNService) UnsetVPNClientLessAccessProfile(resource models.VPNClientlessAccessProfile) error { + payload := map[string]any{"vpnclientlessaccessprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// vpnglobal_authenticationlocalpolicy_binding -func (s *VPNService) AddVPNGlobalAuthenticationLocalPolicyBinding() {} -func (s *VPNService) DeleteVPNGlobalAuthenticationLocalPolicyBinding() {} -func (s *VPNService) GetVPNGlobalAuthenticationLocalPolicyBinding() {} -func (s *VPNService) CountVPNGlobalAuthenticationLocalPolicyBinding() {} + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", vpnClientlessAccessProfileURL), bytes.NewReader(data)) + if err != nil { + return err + } -// vpnglobal_authenticationnegotiatepolicy_binding -func (s *VPNService) AddVPNGlobalAuthenticationNegotiatePolicyBinding() {} -func (s *VPNService) DeleteVPNGlobalAuthenticationNegotiatePolicyBinding() {} -func (s *VPNService) GetVPNGlobalAuthenticationNegotiatePolicyBinding() {} -func (s *VPNService) CountVPNGlobalAuthenticationNegotiatePolicyBinding() {} + _, err = s.client.Do(req) + return err +} -// vpnglobal_authenticationpolicy_binding -func (s *VPNService) AddVPNGlobalAuthenticationPolicyBinding() {} -func (s *VPNService) DeleteVPNGlobalAuthenticationPolicyBinding() {} -func (s *VPNService) GetVPNGlobalAuthenticationPolicyBinding() {} -func (s *VPNService) CountVPNGlobalAuthenticationPolicyBinding() {} +func (s *VPNService) GetAllVPNClientLessAccessProfile() ([]models.VPNClientlessAccessProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnClientlessAccessProfileURL, nil) + if err != nil { + return nil, err + } -// vpnglobal_authenticationradiuspolicy_binding -func (s *VPNService) AddVPNGlobalAuthenticationRADIUSPolicyBinding() {} -func (s *VPNService) DeleteVPNGlobalAuthenticationRADIUSPolicyBinding() {} -func (s *VPNService) GetVPNGlobalAuthenticationRADIUSPolicyBinding() {} -func (s *VPNService) CountVPNGlobalAuthenticationRADIUSPolicyBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// vpnglobal_authenticationsamlpolicy_binding -func (s *VPNService) AddVPNGlobalAuthenticationSAMLPolicyBinding() {} -func (s *VPNService) DeleteVPNGlobalAuthenticationSAMLPolicyBinding() {} -func (s *VPNService) GetVPNGlobalAuthenticationSAMLPolicyBinding() {} -func (s *VPNService) CountVPNGlobalAuthenticationSAMLPolicyBinding() {} + var result struct { + Data []models.VPNClientlessAccessProfile `json:"vpnclientlessaccessprofile"` + } -// vpnglobal_authenticationtacacspolicy_binding -func (s *VPNService) AddVPNGlobalAuthenticationTACACSPolicy() {} -func (s *VPNService) DeleteVPNGlobalAuthenticationTACACSPolicy() {} -func (s *VPNService) GetVPNGlobalAuthenticationTACACSPolicy() {} -func (s *VPNService) CountVPNGlobalAuthenticationTACACSPolicy() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// vpnglobal_binding -func (s *VPNService) GetVPNGlobalBinding() {} + return result.Data, nil +} -// vpnglobal_domain_binding -func (s *VPNService) AddVPNGlobalDomainBinding() {} -func (s *VPNService) DeleteVPNGlobalDomainBinding() {} -func (s *VPNService) GetVPNGlobalDomainBinding() {} -func (s *VPNService) CountVPNGlobalDomainBinding() {} +func (s *VPNService) GetVPNClientLessAccessProfile(name string) (*models.VPNClientlessAccessProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnClientlessAccessProfileURL, name), nil) + if err != nil { + return nil, err + } -// vpnglobal_intranetip6_binding -func (s *VPNService) AddVPNGlobalIntranetIP6Binding() {} -func (s *VPNService) DeleteVPNGlobalIntranetIP6Binding() {} -func (s *VPNService) GetVPNGlobalIntranetIP6Binding() {} -func (s *VPNService) CountVPNGlobalIntranetIP6Binding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// vpnglobal_intranetip_binding -func (s *VPNService) AddVPNGlobalIntranetIPBinding() {} -func (s *VPNService) DeleteVPNGlobalIntranetIPBinding() {} -func (s *VPNService) GetVPNGlobalIntranetIPBinding() {} -func (s *VPNService) CountVPNGlobalIntranetIPBinding() {} + var result struct { + Data []models.VPNClientlessAccessProfile `json:"vpnclientlessaccessprofile"` + } -// vpnglobal_sharefileserver_binding -func (s *VPNService) AddVPNGlobalShareFileServerBinding() {} -func (s *VPNService) DeleteVPNGlobalShareFileServerBinding() {} -func (s *VPNService) GetVPNGlobalShareFileServerBinding() {} -func (s *VPNService) CountVPNGlobalShareFileServerBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// vpnglobal_sslcertkey_binding -func (s *VPNService) AddVPNGlobalSSLCertKeyBinding() {} -func (s *VPNService) DeleteVPNGlobalSSLCertKeyBinding() {} -func (s *VPNService) GetVPNGlobalSSLCertKeyBinding() {} -func (s *VPNService) CountVPNGlobalSSLCertKeyBinding() {} + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } -// vpnglobal_staserver_binding -func (s *VPNService) AddVPNGlobalSTAServerBinding() {} -func (s *VPNService) DeleteVPNGlobalSTAServerBinding() {} -func (s *VPNService) GetVPNGlobalSTAServerBinding() {} -func (s *VPNService) CountVPNGlobalSTAServerBinding() {} + return &result.Data[0], nil +} -// vpnglobal_vpnclientlessaccesspolicy_binding -func (s *VPNService) AddVPNGlobalVPNClientLessAccessPolicyBinding() {} -func (s *VPNService) DeleteVPNGlobalVPNClientLessAccessPolicyBinding() {} -func (s *VPNService) GetVPNGlobalVPNClientLessAccessPolicyBinding() {} -func (s *VPNService) CountVPNGlobalVPNClientLessAccessPolicyBinding() {} +func (s *VPNService) CountVPNClientLessAccessProfile() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnClientlessAccessProfileURL), nil) + if err != nil { + return 0, err + } -// vpnglobal_vpneula_binding -func (s *VPNService) AddVPNGlobalVPNEULABinding() {} -func (s *VPNService) DeleteVPNGlobalVPNEULABinding() {} -func (s *VPNService) GetVPNGlobalVPNEULABinding() {} -func (s *VPNService) CountVPNGlobalVPNEULABinding() {} + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } -// vpnglobal_vpnintranetapplication_binding -func (s *VPNService) AddVPNGlobalVPNIntranetApplicationBinding() {} -func (s *VPNService) DeleteVPNGlobalVPNIntranetApplicationBinding() {} -func (s *VPNService) GetVPNGlobalVPNIntranetApplicationBinding() {} -func (s *VPNService) CountVPNGlobalVPNIntranetApplicationBinding() {} + var result struct { + Data []models.VPNClientlessAccessProfile `json:"vpnclientlessaccessprofile"` + } -// vpnglobal_vpnnexthopserver_binding -func (s *VPNService) AddVPNGlobalVPNNextHopServerBinding() {} -func (s *VPNService) DeleteVPNGlobalVPNNextHopServerBinding() {} -func (s *VPNService) GetVPNGlobalVPNNextHopServerBinding() {} -func (s *VPNService) CountVPNGlobalVPNNextHopServerBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } -// vpnglobal_vpnportaltheme_binding -func (s *VPNService) AddVPNGlobalVPNPortalThemeBinding() {} -func (s *VPNService) DeleteVPNGlobalVPNPortalThemeBinding() {} -func (s *VPNService) GetVPNGlobalVPNPortalThemeBinding() {} -func (s *VPNService) CountVPNGlobalVPNPortalThemeBinding() {} + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} -// vpnglobal_vpnsessionpolcy_binding -func (s *VPNService) AddVPNGlobalVPNSessionPolicyBinding() {} -func (s *VPNService) DeleteVPNGlobalVPNSessionPolicyBinding() {} -func (s *VPNService) GetVPNGlobalVPNSessionPolicyBinding() {} -func (s *VPNService) CountVPNGlobalVPNSessionPolicyBinding() {} +// vpnepaprofile +func (s *VPNService) AddVPNEPAProfile(resource models.VPNEPAProfile) error { + payload := map[string]any{"vpnepaprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// vpnglobal_vpntrafficpolicy_binding -func (s *VPNService) AddVPNGlobalVPNTrafficPolicyBinding() {} -func (s *VPNService) DeleteVPNGlobalVPNTrafficPolicyBinding() {} -func (s *VPNService) GetVPNGlobalVPNTrafficPolicyBinding() {} -func (s *VPNService) CountVPNGlobalVPNTrafficPolicyBinding() {} + req, err := s.client.NewRequest(http.MethodPost, vpnEPAProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } -// vpnglobal_vpnurlpolicy_binding -func (s *VPNService) AddVPNGlobalVPNURLPolicyBinding() {} -func (s *VPNService) DeleteVPNGlobalVPNURLPolicyBinding() {} -func (s *VPNService) GetVPNGlobalVPNURLPolicyBinding() {} -func (s *VPNService) CountVPNGlobalVPNURLPolicyBinding() {} + _, err = s.client.Do(req) + return err +} -// vpnglobal_vpnurl_binding -func (s *VPNService) AddVPNGlobalVPNURLBinding() {} -func (s *VPNService) DeleteVPNGlobalVPNURLBinding() {} -func (s *VPNService) GetVPNGlobalVPNURLBinding() {} -func (s *VPNService) CountVPNGlobalVPNURLBinding() {} +func (s *VPNService) DeleteVPNEPAProfile(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnEPAProfileURL, name), nil) + if err != nil { + return err + } -// vpnicaconnection -func (s *VPNService) KillVPNICAConnection() {} -func (s *VPNService) GetAllVPNICAConnection() {} -func (s *VPNService) CountVPNICAConnection() {} + _, err = s.client.Do(req) + return err +} -// vpnicadtlsconnection -func (s *VPNService) GetAllVPNICADTLSConnection() {} -func (s *VPNService) CountVPNICADTLSConnection() {} +func (s *VPNService) GetAllVPNEPAProfile() ([]models.VPNEPAProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnEPAProfileURL, nil) + if err != nil { + return nil, err + } -// vpnintranetapplication -func (s *VPNService) AddVPNIntranetApplication() {} -func (s *VPNService) DeleteVPNIntranetApplication() {} -func (s *VPNService) GetAllVPNIntranetApplication() {} -func (s *VPNService) GetVPNIntranetApplication() {} -func (s *VPNService) CountVPNIntranetApplication() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// vpnnexthopserver -func (s *VPNService) AddVPNNextHopServer() {} -func (s *VPNService) DeleteVPNNextHopServer() {} -func (s *VPNService) GetAllVPNNextHopServer() {} -func (s *VPNService) GetVPNNextHopServer() {} -func (s *VPNService) CountVPNNextHopServer() {} + var result struct { + Data []models.VPNEPAProfile `json:"vpnepaprofile"` + } -// vpnparameter -func (s *VPNService) UpdateVPNParameter() {} -func (s *VPNService) UnsetVPNParameter() {} -func (s *VPNService) GetAllVPNParameter() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// vpnpcoipconnection -func (s *VPNService) KillVPNPCoIPConnection() {} -func (s *VPNService) GetAllVPNPCoIPConnection() {} -func (s *VPNService) CountVPNPCoIPConnection() {} + return result.Data, nil +} -// vpnpcoipprofile -func (s *VPNService) AddVPNCoIPProfile() {} -func (s *VPNService) DeleteVPNCoIPProfile() {} -func (s *VPNService) UpdateVPNCoIPProfile() {} -func (s *VPNService) UnsetVPNCoIPProfile() {} -func (s *VPNService) GetAllVPNCoIPProfile() {} -func (s *VPNService) GetVPNCoIPProfile() {} -func (s *VPNService) CountVPNCoIPProfile() {} +func (s *VPNService) GetVPNEPAProfile(name string) (*models.VPNEPAProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnEPAProfileURL, name), nil) + if err != nil { + return nil, err + } -// vpnpcoipvserverprofile -func (s *VPNService) AddVPNPCoIPVServerProfile() {} -func (s *VPNService) DeleteVPNPCoIPVServerProfile() {} -func (s *VPNService) UpdateVPNPCoIPVServerProfile() {} -func (s *VPNService) UnsetVPNPCoIPVServerProfile() {} -func (s *VPNService) GetAllVPNPCoIPVServerProfile() {} -func (s *VPNService) GetVPNPCoIPVServerProfile() {} -func (s *VPNService) CountVPNPCoIPVServerProfile() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// vpnportaltheme -func (s *VPNService) AddVPNPortalTheme() {} -func (s *VPNService) DeleteVPNPortalTheme() {} -func (s *VPNService) GetAllVPNPortalTheme() {} -func (s *VPNService) GetVPNPortalTheme() {} -func (s *VPNService) CountVPNPortalTheme() {} + var result struct { + Data []models.VPNEPAProfile `json:"vpnepaprofile"` + } -// vpnsamlssoprofile -func (s *VPNService) AddVPNSAMLSSOProfile() {} -func (s *VPNService) DeleteVPNSAMLSSOProfile() {} -func (s *VPNService) UpdateVPNSAMLSSOProfile() {} -func (s *VPNService) UnsetVPNSAMLSSOProfile() {} -func (s *VPNService) GetAllVPNSAMLSSOProfile() {} -func (s *VPNService) GetVPNSAMLSSOProfile() {} -func (s *VPNService) CountVPNSAMLSSOProfile() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// vpnsessionaction -func (s *VPNService) AddVPNSessionAction() {} -func (s *VPNService) DeleteVPNSessionAction() {} -func (s *VPNService) UpdateVPNSessionAction() {} -func (s *VPNService) UnsetVPNSessionAction() {} -func (s *VPNService) GetAllVPNSessionAction() {} -func (s *VPNService) GetVPNSessionAction() {} -func (s *VPNService) CountVPNSessionAction() {} + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } -// vpnsessionpolicy -func (s *VPNService) AddVPNSessionPolicy() {} -func (s *VPNService) DeleteVPNSessionPolicy() {} -func (s *VPNService) UpdateVPNSessionPolicy() {} -func (s *VPNService) UnsetVPNSessionPolicy() {} -func (s *VPNService) GetAllVPNSessionPolicy() {} -func (s *VPNService) GetVPNSessionPolicy() {} -func (s *VPNService) CountVPNSessionPolicy() {} + return &result.Data[0], nil +} -// vpnsesisonpolicy_aaagroup_binding -func (s *VPNService) GetAllVPNSessionPolicyAAAGroupBinding() {} -func (s *VPNService) GetVPNSessionPolicyAAAGroupBinding() {} -func (s *VPNService) CountVPNSessionPolicyAAAGroupBinding() {} +func (s *VPNService) CountVPNEPAProfile() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnEPAProfileURL), nil) + if err != nil { + return 0, err + } -// vpnsessionpolicy_aaauser_binding -func (s *VPNService) GetAllVPNSessionPolicyAAAUserBinding() {} -func (s *VPNService) GetVPNSessionPolicyAAAUserBinding() {} -func (s *VPNService) CountVPNSessionPolicyAAAUserBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } -// vpnsessionpolicy_binding -func (s *VPNService) GetAllVPNSessionPolicyBinding() {} -func (s *VPNService) GetVPNSessionPolicyBinding() {} + var result struct { + Data []models.VPNEPAProfile `json:"vpnepaprofile"` + } -// vpnsessionpolicy_vpnglobal_binding -func (s *VPNService) GetAllVPNSessionPolicyVPNGlobalBinding() {} -func (s *VPNService) GetVPNSessionPolicyVPNGlobalBinding() {} -func (s *VPNService) CountVPNSessionPolicyVPNGlobalBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } -// vpnsessionpolicy_vpnvserver_binding -func (s *VPNService) GetAllVPNSessionPolicyVPNVServerBinding() {} -func (s *VPNService) GetVPNSessionPolicyVPNVServerBinding() {} -func (s *VPNService) CountVPNSessionPolicyVPNVServerBinding() {} + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} -// vpnsfconfig -func (s *VPNService) GetAllVPNSFConfig() {} -func (s *VPNService) CountVPNSFConfig() {} +// vpneula +func (s *VPNService) AddVPNEULA(resource models.VPNEULA) error { + payload := map[string]any{"vpneula": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// vpnstoreinfo -func (s *VPNService) GetAllVPNStoreInfo() {} -func (s *VPNService) CountVPNStoreInfo() {} + req, err := s.client.NewRequest(http.MethodPost, vpnEULAURL, bytes.NewReader(data)) + if err != nil { + return err + } -// vpntrafficaction -func (s *VPNService) AddVPNTrafficAction() {} -func (s *VPNService) DeleteVPNTrafficAction() {} -func (s *VPNService) UpdateVPNTrafficAction() {} -func (s *VPNService) UnsetVPNTrafficAction() {} -func (s *VPNService) GetAllVPNTrafficAction() {} -func (s *VPNService) GetVPNTrafficAction() {} -func (s *VPNService) CountVPNTrafficAction() {} + _, err = s.client.Do(req) + return err +} -// vpntrafficpolicy -func (s *VPNService) AddVPNTrafficPolicy() {} -func (s *VPNService) DeleteVPNTrafficPolicy() {} -func (s *VPNService) UpdateVPNTrafficPolicy() {} -func (s *VPNService) UnsetVPNTrafficPolicy() {} -func (s *VPNService) GetAllVPNTrafficPolicy() {} -func (s *VPNService) GetVPNTrafficPolicy() {} -func (s *VPNService) CountVPNTrafficPolicy() {} +func (s *VPNService) DeleteVPNEULA(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnEULAURL, name), nil) + if err != nil { + return err + } -// vpntrafficpolicy_aaagroup_binding -func (s *VPNService) GetAllVPNTrafficPolicyAAAGroupBinding() {} -func (s *VPNService) GetVPNTrafficPolicyAAAGroupBinding() {} -func (s *VPNService) CountVPNTrafficPolicyAAAGroupBinding() {} + _, err = s.client.Do(req) + return err +} -// vpntrafficpolicy_aaauser_binding -func (s *VPNService) GetAllVPNTrafficPolicyAAAUserBinding() {} -func (s *VPNService) GetVPNTrafficPolicyAAAUserBinding() {} -func (s *VPNService) CountVPNTrafficPolicyAAAUserBinding() {} +func (s *VPNService) GetAllVPNEULA() ([]models.VPNEULA, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnEULAURL, nil) + if err != nil { + return nil, err + } -// vpntrafficpolicy_binding -func (s *VPNService) GetAllVPNTrafficPolicyBinding() {} -func (s *VPNService) GetVPNTrafficPolicyBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// vpntrafficpolicy_vpnglobal_binding -func (s *VPNService) GetAllVPNTrafficPolicyVPNGlobalBinding() {} -func (s *VPNService) GetVPNTrafficPolicyVPNGlobalBinding() {} -func (s *VPNService) CountVPNTrafficPolicyVPNGlobalBinding() {} + var result struct { + Data []models.VPNEULA `json:"vpneula"` + } -// vpntrafficpolicy_vpnvserver_binding -func (s *VPNService) GetAllVPNTrafficPolicyVPNVServerBinding() {} -func (s *VPNService) GetVPNTrafficPolicyVPNVServerBinding() {} -func (s *VPNService) CountVPNTrafficPolicyVPNVServerBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// vpnurl -func (s *VPNService) AddVPNURL() {} -func (s *VPNService) DeleteVPNURL() {} -func (s *VPNService) UpdateVPNURL() {} -func (s *VPNService) UnsetVPNURL() {} -func (s *VPNService) GetAllVPNURL() {} -func (s *VPNService) GetVPNURL() {} -func (s *VPNService) CountVPNURL() {} + return result.Data, nil +} -// vpnurlaction -func (s *VPNService) AddVPNURLAction() {} -func (s *VPNService) DeleteVPNURLAction() {} -func (s *VPNService) UpdateVPNURLAction() {} -func (s *VPNService) UnsetVPNURLAction() {} -func (s *VPNService) RenameVPNURLAction() {} -func (s *VPNService) GetAllVPNURLAction() {} -func (s *VPNService) GetVPNURLAction() {} -func (s *VPNService) CountVPNURLAction() {} +func (s *VPNService) GetVPNEULA(name string) (*models.VPNEULA, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnEULAURL, name), nil) + if err != nil { + return nil, err + } -// vpnurlpolicy -func (s *VPNService) AddVPNURLPolicy() {} -func (s *VPNService) DeleteVPNURLPolicy() {} -func (s *VPNService) UpdateVPNURLPolicy() {} -func (s *VPNService) UnsetVPNURLPolicy() {} -func (s *VPNService) RenameVPNURLPolicy() {} -func (s *VPNService) GetAllVPNURLPolicy() {} -func (s *VPNService) GetVPNURLPolicy() {} -func (s *VPNService) CountVPNURLPolicy() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// vpnurlpolicy_aaagroup_binding -func (s *VPNService) GetAllVPNURLPolicyAAAGroupBinding() {} -func (s *VPNService) GetVPNURLPolicyAAAGroupBinding() {} -func (s *VPNService) CountVPNURLPolicyAAAGroupBinding() {} + var result struct { + Data []models.VPNEULA `json:"vpneula"` + } -// vpnurlpolicy_aaauser_binding -func (s *VPNService) GetAllVPNURLPolicyAAAUserBinding() {} -func (s *VPNService) GetVPNURLPolicyAAAUserBinding() {} -func (s *VPNService) CountVPNURLPolicyAAAUserBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// vpnurlpolicy_binding -func (s *VPNService) GetAllVPNURLPolicyBinding() {} -func (s *VPNService) GetVPNURLPolicyBinding() {} + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } -// vpnurlpolicy_vpnglobal_binding -func (s *VPNService) GetAllVPNURLPolicyVPNGlobalBinding() {} -func (s *VPNService) GetVPNURLPolicyVPNGlobalBinding() {} -func (s *VPNService) CountVPNURLPolicyVPNGlobalBinding() {} + return &result.Data[0], nil +} -// vpnurlpolicy_vpnvserver_binding -func (s *VPNService) GetAllVPNURLPolicyVPNVServerBinding() {} -func (s *VPNService) GetVPNURLPolicyVPNVServerBinding() {} -func (s *VPNService) CountVPNURLPolicyVPNVServerBinding() {} +func (s *VPNService) CountVPNEULA() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnEULAURL), nil) + if err != nil { + return 0, err + } -// vpnvserver -func (s *VPNService) AddVPNVServer() {} -func (s *VPNService) DeleteVPNVServer() {} -func (s *VPNService) UpdateVPNVServer() {} -func (s *VPNService) UnsetVPNVServer() {} -func (s *VPNService) EnableVPNVServer() {} -func (s *VPNService) DisableVPNVServer() {} -func (s *VPNService) RenameVPNVServer() {} -func (s *VPNService) CheckVPNVServer() {} -func (s *VPNService) GetAllVPNVServer() {} -func (s *VPNService) GetVPNVServer() {} -func (s *VPNService) CountVPNVServer() {} + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } -// vpnvserver_aaapreauthenticationpolicy_binding -func (s *VPNService) AddVPNVServerAAAPreauthenticationPolicyBinding() {} -func (s *VPNService) DeleteVPNVServerAAAPreauthenticationPolicyBinding() {} -func (s *VPNService) GetAllVPNVServerAAAPreauthenticationPolicyBinding() {} -func (s *VPNService) GetVPNVServerAAAPreauthenticationPolicyBinding() {} -func (s *VPNService) CountVPNVServerAAAPreauthenticationPolicyBinding() {} + var result struct { + Data []models.VPNEULA `json:"vpneula"` + } -// vpnvserver_analyticsprofile_binding -func (s *VPNService) AddVPNVServerAnalyticsProfileBinding() {} -func (s *VPNService) DeleteVPNVServerAnalyticsProfileBinding() {} -func (s *VPNService) GetAllVPNVServerAnalyticsProfileBinding() {} -func (s *VPNService) GetVPNVServerAnalyticsProfileBinding() {} -func (s *VPNService) CountVPNVServerAnalyticsProfileBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } -// vpnvserver_appcontroller_binding -func (s *VPNService) AddVPNVServerAppControllerBinding() {} -func (s *VPNService) DeleteVPNVServerAppControllerBinding() {} -func (s *VPNService) GetAllVPNVServerAppControllerBinding() {} -func (s *VPNService) GetVPNVServerAppControllerBinding() {} -func (s *VPNService) CountVPNVServerAppControllerBinding() {} + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} -// vpnvserver_appflowpolicy_binding -func (s *VPNService) AddVPNVServerAppFlowPolicyBinding() {} -func (s *VPNService) DeleteVPNVServerAppFlowPolicyBinding() {} -func (s *VPNService) GetAllVPNVServerAppFlowPolicyBinding() {} -func (s *VPNService) GetVPNVServerAppFlowPolicyBinding() {} -func (s *VPNService) CountVPNVServerAppFlowPolicyBinding() {} +// vpnformssoaction +func (s *VPNService) AddVPNFormSSOAction(resource models.VPNFormSSOAction) error { + payload := map[string]any{"vpnformssoaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// vpnvserver_auditnslogpolicy_binding -func (s *VPNService) AddVPNVServerAuditNSLogPolicyBinding() {} -func (s *VPNService) DeleteVPNVServerAuditNSLogPolicyBinding() {} -func (s *VPNService) GetAllVPNVServerAuditNSLogPolicyBinding() {} -func (s *VPNService) VPNVServerAuditNSLogPolicyBinding() {} -func (s *VPNService) CountVPNVServerAuditNSLogPolicyBinding() {} + req, err := s.client.NewRequest(http.MethodPost, vpnFormSSOActionURL, bytes.NewReader(data)) + if err != nil { + return err + } -// vpnvserver_auditsyslogpolicy_binding -func (s *VPNService) AddVPNVServerAuditSyslogPolicyBinding() {} -func (s *VPNService) DeleteVPNVServerAuditSyslogPolicyBinding() {} -func (s *VPNService) GetAllVPNVServerAuditSyslogPolicyBinding() {} -func (s *VPNService) GetVPNVServerAuditSyslogPolicyBinding() {} -func (s *VPNService) CountVPNVServerAuditSyslogPolicyBinding() {} + _, err = s.client.Do(req) + return err +} -// vpnvserver_authenticationcertpolicy_binding -func (s *VPNService) AddVPNVServerAuthenticationCertPolicyBinding() {} -func (s *VPNService) DeleteVPNVServerAuthenticationCertPolicyBinding() {} -func (s *VPNService) GetAllVPNVServerAuthenticationCertPolicyBinding() {} -func (s *VPNService) GetVPNVServerAuthenticationCertPolicyBinding() {} -func (s *VPNService) CountVPNVServerAuthenticationCertPolicyBinding() {} +func (s *VPNService) DeleteVPNFormSSOAction(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnFormSSOActionURL, name), nil) + if err != nil { + return err + } -// vpnvserver_authenticationfapolicy_binding -func (s *VPNService) AddVPNVServerAuthenticationFAPolicyBinding() {} -func (s *VPNService) DeleteVPNVServerAuthenticationFAPolicyBinding() {} -func (s *VPNService) GetAllVPNVServerAuthenticationFAPolicyBinding() {} -func (s *VPNService) GetVPNVServerAuthenticationFAPolicyBinding() {} -func (s *VPNService) CountVPNVServerAuthenticationFAPolicyBinding() {} + _, err = s.client.Do(req) + return err +} -// vpnvserver_authenticationldappolicy_binding -func (s *VPNService) AddVPNVServerAuthenticationLDAPPolicyBinding() {} -func (s *VPNService) DeleteVPNVServerAuthenticationLDAPPolicyBinding() {} -func (s *VPNService) GetAllVPNVServerAuthenticationLDAPPolicyBinding() {} -func (s *VPNService) GetVPNVServerAuthenticationLDAPPolicyBinding() {} -func (s *VPNService) CountVPNVServerAuthenticationLDAPPolicyBinding() {} +func (s *VPNService) UpdateVPNFormSSOAction(resource models.VPNFormSSOAction) error { + payload := map[string]any{"vpnformssoaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// vpnvserver_authenticationlocalpolicy_binding -func (s *VPNService) AddVPNVServerAuthenticationLocalPolicyBinding() {} -func (s *VPNService) DeleteVPNVServerAuthenticationLocalPolicyBinding() {} -func (s *VPNService) GetAllVPNVServerAuthenticationLocalPolicyBinding() {} -func (s *VPNService) GetVPNVServerAuthenticationLocalPolicyBinding() {} -func (s *VPNService) CountVPNVServerAuthenticationLocalPolicyBinding() {} + req, err := s.client.NewRequest(http.MethodPut, vpnFormSSOActionURL, bytes.NewReader(data)) + if err != nil { + return err + } -// vpnvserver_authenticationloginschemapolicy_binding -func (s *VPNService) AddVPNVServerAuthenticationLoginSchemaPolicyBinding() {} -func (s *VPNService) DeleteVPNVServerAuthenticationLoginSchemaPolicyBinding() {} -func (s *VPNService) GetAllVPNVServerAuthenticationLoginSchemaPolicyBinding() {} -func (s *VPNService) GetVPNVServerAuthenticationLoginSchemaPolicyBinding() {} -func (s *VPNService) CountVPNVServerAuthenticationLoginSchemaPolicyBinding() {} + _, err = s.client.Do(req) + return err +} -// vpnvserver_authenticationnegotiatepolcy_binding -func (s *VPNService) AddVPNVServerAuthenticationNegotiatePolicyBinding() {} -func (s *VPNService) DeleteVPNVServerAuthenticationNegotiatePolicyBinding() {} -func (s *VPNService) GetAllVPNVServerAuthenticationNegotiatePolicyBinding() {} -func (s *VPNService) GetVPNVServerAuthenticationNegotiatePolicyBinding() {} -func (s *VPNService) CountVPNVServerAuthenticationNegotiatePolicyBinding() {} +func (s *VPNService) UnsetVPNFormSSOAction(resource models.VPNFormSSOAction) error { + payload := map[string]any{"vpnformssoaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// vpnvserver_authenticationoauthidppolicy_binding -func (s *VPNService) AddVPNVServerAuthenticationOAuthIDPPolicyBinding() {} -func (s *VPNService) DeleteVPNVServerAuthenticationOAuthIDPPolicyBinding() {} -func (s *VPNService) GetAllVPNVServerAuthenticationOAuthIDPPolicyBinding() {} -func (s *VPNService) GetVPNVServerAuthenticationOAuthIDPPolicyBinding() {} -func (s *VPNService) CountVPNVServerAuthenticationOAuthIDPPolicyBinding() {} + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", vpnFormSSOActionURL), bytes.NewReader(data)) + if err != nil { + return err + } -// vpnvserver_authenticationpolicy_binding -func (s *VPNService) AddVPNVServerAuthenticationPolicyBinding() {} -func (s *VPNService) DeleteVPNVServerAuthenticationPolicyBinding() {} -func (s *VPNService) GetAllVPNVServerAuthenticationPolicyBinding() {} -func (s *VPNService) GetVPNVServerAuthenticationPolicyBinding() {} -func (s *VPNService) CountVPNVServerAuthenticationPolicyBinding() {} + _, err = s.client.Do(req) + return err +} -// vpnvserver_authenticationradiuspolicy_binding -func (s *VPNService) AddVPNVServerAuthenticationRADIUSPolicyBinding() {} -func (s *VPNService) DeleteVPNVServerAuthenticationRADIUSPolicyBinding() {} -func (s *VPNService) GetAllVPNVServerAuthenticationRADIUSPolicyBinding() {} -func (s *VPNService) GetVPNVServerAuthenticationRADIUSPolicyBinding() {} -func (s *VPNService) CountVPNVServerAuthenticationRADIUSPolicyBinding() {} +func (s *VPNService) GetAllVPNFormSSOAction() ([]models.VPNFormSSOAction, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnFormSSOActionURL, nil) + if err != nil { + return nil, err + } -// vpnvserver_authenticationsamlidppolicy_binding -func (s *VPNService) AddVPNVServerAuthenticationSAMLIDPPolicyBinding() {} -func (s *VPNService) DeleteVPNVServerAuthenticationSAMLIDPPolicyBinding() {} -func (s *VPNService) GetAllVPNVServerAuthenticationSAMLIDPPolicyBinding() {} -func (s *VPNService) GetVPNVServerAuthenticationSAMLIDPPolicyBinding() {} -func (s *VPNService) CountVPNVServerAuthenticationSAMLIDPPolicyBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// vpnvserver_authenticationsamlpolicy_binding -func (s *VPNService) AddVPNVServerAuthenticationSAMLPolicyBinding() {} -func (s *VPNService) DeleteVPNVServerAuthenticationSAMLPolicyBinding() {} -func (s *VPNService) GetAllVPNVServerAuthenticationSAMLPolicyBinding() {} -func (s *VPNService) GetVPNVServerAuthenticationSAMLPolicyBinding() {} -func (s *VPNService) CountVPNVServerAuthenticationSAMLPolicyBinding() {} + var result struct { + Data []models.VPNFormSSOAction `json:"vpnformssoaction"` + } -// vpnvserver_authenticationtacacspolicy_binding -func (s *VPNService) AddVPNVServerAuthenticationTACACSPolicyBinding() {} -func (s *VPNService) DeleteVPNVServerAuthenticationTACACSPolicyBinding() {} -func (s *VPNService) GetAllVPNVServerAuthenticationTACACSPolicyBinding() {} -func (s *VPNService) GetVPNVServerAuthenticationTACACSPolicyBinding() {} -func (s *VPNService) CountVPNVServerAuthenticationTACACSPolicyBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// vpnvserver_authenticationwebauthpolicy_binding -func (s *VPNService) AddVPNVServerAuthenticationWebAuthPolicyBinding() {} -func (s *VPNService) DeleteVPNVServerAuthenticationWebAuthPolicyBinding() {} -func (s *VPNService) GetAllVPNVServerAuthenticationWebAuthPolicyBinding() {} -func (s *VPNService) GetVPNVServerAuthenticationWebAuthPolicyBinding() {} -func (s *VPNService) CountVPNVServerAuthenticationWebAuthPolicyBinding() {} + return result.Data, nil +} -// vpnvserver_binding -func (s *VPNService) GetAllPVNVServerBinding() {} -func (s *VPNService) GetPVNVServerBinding() {} +func (s *VPNService) GetVPNFormSSOAction(name string) (*models.VPNFormSSOAction, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnFormSSOActionURL, name), nil) + if err != nil { + return nil, err + } -// vpnvserver_cachepolicy_binding -func (s *VPNService) AddVPNVServerCachePolicyBinding() {} -func (s *VPNService) DeleteVPNVServerCachePolicyBinding() {} -func (s *VPNService) GetAllVPNVServerCachePolicyBinding() {} -func (s *VPNService) GetVPNVServerCachePolicyBinding() {} -func (s *VPNService) CountVPNVServerCachePolicyBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// vpnvserver_cspolicy_binding -func (s *VPNService) AddVPNVServerCSPolicyBinding() {} -func (s *VPNService) DeleteVPNVServerCSPolicyBinding() {} -func (s *VPNService) GetAllVPNVServerCSPolicyBinding() {} -func (s *VPNService) GetVPNVServerCSPolicyBinding() {} -func (s *VPNService) CountVPNVServerCSPolicyBinding() {} + var result struct { + Data []models.VPNFormSSOAction `json:"vpnformssoaction"` + } -// vpnvserver_feopolicy_binding -func (s *VPNService) AddVPNVServerFEOPolicyBinding() {} -func (s *VPNService) DeleteVPNVServerFEOPolicyBinding() {} -func (s *VPNService) GetAllVPNVServerFEOPolicyBinding() {} -func (s *VPNService) GetVPNVServerFEOPolicyBinding() {} -func (s *VPNService) CountVPNVServerFEOPolicyBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// vpnvserver_icapolicy_binding -func (s *VPNService) AddVPNVServerICAPolicyBinding() {} -func (s *VPNService) DeleteVPNVServerICAPolicyBinding() {} -func (s *VPNService) GetAllVPNVServerICAPolicyBinding() {} -func (s *VPNService) GetVPNVServerICAPolicyBinding() {} -func (s *VPNService) CountVPNVServerICAPolicyBinding() {} + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } -// vpnvserver_intranetip6_binding -func (s *VPNService) AddVPNVServerIntranetIP6Binding() {} -func (s *VPNService) DeleteVPNVServerIntranetIP6Binding() {} -func (s *VPNService) GetAllVPNVServerIntranetIP6Binding() {} -func (s *VPNService) GetVPNVServerIntranetIP6Binding() {} -func (s *VPNService) CountVPNVServerIntranetIP6Binding() {} + return &result.Data[0], nil +} -// vpnvserver_intranetip_binding -func (s *VPNService) AddVPNVServerIntranetIPBinding() {} -func (s *VPNService) DeleteVPNVServerIntranetIPBinding() {} -func (s *VPNService) GetAllVPNVServerIntranetIPBinding() {} -func (s *VPNService) GetVPNVServerIntranetIPBinding() {} -func (s *VPNService) CountVPNVServerIntranetIPBinding() {} +func (s *VPNService) CountVPNFormSSOAction() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnFormSSOActionURL), nil) + if err != nil { + return 0, err + } -// vpnvserver_responderpolicy_binding -func (s *VPNService) AddVPNVServerResponderPolicyBinding() {} -func (s *VPNService) DeleteVPNVServerResponderPolicyBinding() {} -func (s *VPNService) GetAllVPNVServerResponderPolicyBinding() {} -func (s *VPNService) GetVPNVServerResponderPolicyBinding() {} -func (s *VPNService) CountVPNVServerResponderPolicyBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } -// vpnvserver_rewritepolicy_binding -func (s *VPNService) AddVPNVServerRewritePolicyBinding() {} -func (s *VPNService) DeleteVPNVServerRewritePolicyBinding() {} -func (s *VPNService) GetAllVPNVServerRewritePolicyBinding() {} -func (s *VPNService) GetVPNVServerRewritePolicyBinding() {} -func (s *VPNService) CountVPNVServerRewritePolicyBinding() {} + var result struct { + Data []models.VPNFormSSOAction `json:"vpnformssoaction"` + } -// vpnvserver_sharefileserver_binding -func (s *VPNService) AddVPNVServerShareFileServerBinding() {} -func (s *VPNService) DeleteVPNVServerShareFileServerBinding() {} -func (s *VPNService) GetAllVPNVServerShareFileServerBinding() {} -func (s *VPNService) GetVPNVServerShareFileServerBinding() {} -func (s *VPNService) CountVPNVServerShareFileServerBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } -// vpnvserver_staserver_binding -func (s *VPNService) AddVPNVServerSTAServerBinding() {} -func (s *VPNService) DeleteVPNVServerSTAServerBinding() {} -func (s *VPNService) GetAllVPNVServerSTAServerBinding() {} -func (s *VPNService) GetVPNVServerSTAServerBinding() {} -func (s *VPNService) CountVPNVServerSTAServerBinding() {} + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} -// vpnvserver_vpnclientlessaccesspolicy_binding -func (s *VPNService) AddVPNVServerVPNClientlessAccessPolicyBinding() {} -func (s *VPNService) DeleteVPNVServerVPNClientlessAccessPolicyBinding() {} -func (s *VPNService) GetAllVPNVServerVPNClientlessAccessPolicyBinding() {} -func (s *VPNService) GetVPNVServerVPNClientlessAccessPolicyBinding() {} -func (s *VPNService) CountVPNVServerVPNClientlessAccessPolicyBinding() {} +// vpnglobal_appcontroller_binding +func (s *VPNService) AddVPNGlobalAppControllerBinding(resource models.VPNGlobalAppControllerBinding) error { + payload := map[string]any{"vpnglobal_appcontroller_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } -// vpnvserver_vpnepaprofile_binding -func (s *VPNService) AddVPNVServerVPNEPAProfileBinding() {} -func (s *VPNService) DeleteVPNVServerVPNEPAProfileBinding() {} -func (s *VPNService) GetAllVPNVServerVPNEPAProfileBinding() {} -func (s *VPNService) GetVPNVServerVPNEPAProfileBinding() {} -func (s *VPNService) CountVPNVServerVPNEPAProfileBinding() {} + req, err := s.client.NewRequest(http.MethodPost, vpnGlobalAppControllerBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } -// vpnvserver_vpneula_binding -func (s *VPNService) AddVPNVServerVPNEULABinding() {} -func (s *VPNService) DeleteVPNVServerVPNEULABinding() {} -func (s *VPNService) GetAllVPNVServerVPNEULABinding() {} -func (s *VPNService) GetVPNVServerVPNEULABinding() {} -func (s *VPNService) CountVPNVServerVPNEULABinding() {} + _, err = s.client.Do(req) + return err +} -// vpnvserver_vpnintranetapplication_binding -func (s *VPNService) AddVPNVServerVPNIntranetApplicationBinding() {} -func (s *VPNService) DeleteVPNVServerVPNIntranetApplicationBinding() {} -func (s *VPNService) GetAllVPNVServerVPNIntranetApplicationBinding() {} -func (s *VPNService) GetVPNVServerVPNIntranetApplicationBinding() {} -func (s *VPNService) CountVPNVServerVPNIntranetApplicationBinding() {} +func (s *VPNService) DeleteVPNGlobalAppControllerBinding(appcontroller string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnGlobalAppControllerBindingURL, appcontroller), nil) + if err != nil { + return err + } -// vpnvserver_vpnnexthopserver_binding -func (s *VPNService) AddVPNVServerVPNNextHopServerBinding() {} -func (s *VPNService) DeleteVPNVServerVPNNextHopServerBinding() {} -func (s *VPNService) GetAllVPNVServerVPNNextHopServerBinding() {} -func (s *VPNService) GetVPNVServerVPNNextHopServerBinding() {} -func (s *VPNService) CountVPNVServerVPNNextHopServerBinding() {} + _, err = s.client.Do(req) + return err +} -// vpnvserver_vpnportaltheme_binding -func (s *VPNService) AddVPNVServerVPNPortalThemeBinding() {} -func (s *VPNService) DeleteVPNVServerVPNPortalThemeBinding() {} -func (s *VPNService) GetAllVPNVServerVPNPortalThemeBinding() {} -func (s *VPNService) GetVPNVServerVPNPortalThemeBinding() {} -func (s *VPNService) CountVPNVServerVPNPortalThemeBinding() {} +func (s *VPNService) GetVPNGlobalAppControllerBinding(name string) (*models.VPNGlobalAppControllerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnGlobalAppControllerBindingURL, name), nil) + if err != nil { + return nil, err + } -// vpnvserver_vpnsessionpolicy_binding -func (s *VPNService) AddVPNVServerVPNSessionPolicyBinding() {} -func (s *VPNService) DeleteVPNVServerVPNSessionPolicyBinding() {} -func (s *VPNService) GetAllVPNVServerVPNSessionPolicyBinding() {} -func (s *VPNService) GetVPNVServerVPNSessionPolicyBinding() {} -func (s *VPNService) CountVPNVServerVPNSessionPolicyBinding() {} + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } -// vpnvserver_vpntrafficpolicy_binding -func (s *VPNService) AddVPNVServerVPNTrafficPolicyBinding() {} -func (s *VPNService) DeleteVPNVServerVPNTrafficPolicyBinding() {} -func (s *VPNService) GetAllVPNVServerVPNTrafficPolicyBinding() {} -func (s *VPNService) GetVPNVServerVPNTrafficPolicyBinding() {} -func (s *VPNService) CountVPNVServerVPNTrafficPolicyBinding() {} + var result struct { + Data []models.VPNGlobalAppControllerBinding `json:"vpnglobal_appcontroller_binding"` + } -// vpnvserver_vpnurlpolicy_binding -func (s *VPNService) AddVPNVServerVPNURLPolicyBinding() {} -func (s *VPNService) DeleteVPNVServerVPNURLPolicyBinding() {} -func (s *VPNService) GetAllVPNVServerVPNURLPolicyBinding() {} -func (s *VPNService) GetVPNVServerVPNURLPolicyBinding() {} -func (s *VPNService) CountVPNVServerVPNURLPolicyBinding() {} + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } -// vpnvserver_vpnurl_binding -func (s *VPNService) AddVPNVServerVPNURLBinding() {} -func (s *VPNService) DeleteVPNVServerVPNURLBinding() {} -func (s *VPNService) GetAllVPNVServerVPNURLBinding() {} -func (s *VPNService) GetVPNVServerVPNURLBinding() {} -func (s *VPNService) CountVPNVServerVPNURLBinding() {} + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNGlobalAppControllerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnGlobalAppControllerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNGlobalAppControllerBinding `json:"vpnglobal_appcontroller_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// vpnglobal_auditnslogpolicy_binding +func (s *VPNService) AddVPNGlobalAuditNSLogPolicyBinding(resource models.VPNGlobalAuditNSLogPolicyBinding) error { + payload := map[string]any{"vpnglobal_auditnslogpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnGlobalAuditNSLogPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNGlobalAuditNSLogPolicyBinding(policyname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnGlobalAuditNSLogPolicyBindingURL, policyname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetVPNGlobalAuditNSLogPolicyBinding(name string) (*models.VPNGlobalAuditNSLogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnGlobalAuditNSLogPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNGlobalAuditNSLogPolicyBinding `json:"vpnglobal_auditnslogpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNGlobalAuditNSLogPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnGlobalAuditNSLogPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNGlobalAuditNSLogPolicyBinding `json:"vpnglobal_auditnslogpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// vpnglobal_auditsyslogpolicy_binding +func (s *VPNService) AddVPNGlobalAuditSyslogPolicyBinding(resource models.VPNGlobalAuditSyslogPolicyBinding) error { + payload := map[string]any{"vpnglobal_auditsyslogpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnGlobalAuditSyslogPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNGlobalAuditSyslogPolicyBinding(policyname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnGlobalAuditSyslogPolicyBindingURL, policyname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetVPNGlobalAuditSyslogPolicyBinding(name string) (*models.VPNGlobalAuditSyslogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnGlobalAuditSyslogPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNGlobalAuditSyslogPolicyBinding `json:"vpnglobal_auditsyslogpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("resource not found") + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNGlobalAuditSyslogPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnGlobalAuditSyslogPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNGlobalAuditSyslogPolicyBinding `json:"vpnglobal_auditsyslogpolicy_binding"` + } + + err = json.Unmarshal(resp, &result) + if err != nil { + return 0, fmt.Errorf("failed to unmarshal: %w", err) + } + + if len(result.Data) > 0 { + return int(result.Data[0].Count), nil + } + return 0, fmt.Errorf("failed to parse count") +} + +// vpnglobal_authenticationcertpolicy_binding +func (s *VPNService) AddVPNGlobalAuthenticationCertPolicyBinding(resource models.VPNGlobalAuthenticationCertPolicyBinding) error { + payload := map[string]any{"vpnglobal_authenticationcertpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnGlobalAuthenticationCertPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNGlobalAuthenticationCertPolicyBinding(policyname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnGlobalAuthenticationCertPolicyBindingURL, policyname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetVPNGlobalAuthenticationCertPolicyBinding() ([]models.VPNGlobalAuthenticationCertPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnGlobalAuthenticationCertPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNGlobalAuthenticationCertPolicyBinding `json:"vpnglobal_authenticationcertpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNGlobalAuthenticationCertPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnGlobalAuthenticationCertPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNGlobalAuthenticationCertPolicyBinding `json:"vpnglobal_authenticationcertpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnglobal_authenticationldappolicy_binding +func (s *VPNService) AddVPNGlobalAuthenticationLDAPPolicyBinding(resource models.VPNGlobalAuthenticationLDAPPolicyBinding) error { + payload := map[string]any{"vpnglobal_authenticationldappolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnGlobalAuthenticationLDAPPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNGlobalAuthenticationLDAPPolicyBinding(policyname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnGlobalAuthenticationLDAPPolicyBindingURL, policyname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetVPNGlobalAuthenticationLDAPPolicyBinding() ([]models.VPNGlobalAuthenticationLDAPPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnGlobalAuthenticationLDAPPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNGlobalAuthenticationLDAPPolicyBinding `json:"vpnglobal_authenticationldappolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNGlobalAuthenticationLDAPPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnGlobalAuthenticationLDAPPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNGlobalAuthenticationLDAPPolicyBinding `json:"vpnglobal_authenticationldappolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnglobal_authenticationlocalpolicy_binding +func (s *VPNService) AddVPNGlobalAuthenticationLocalPolicyBinding(resource models.VPNGlobalAuthenticationLocalPolicyBinding) error { + payload := map[string]any{"vpnglobal_authenticationlocalpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnGlobalAuthenticationLocalPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNGlobalAuthenticationLocalPolicyBinding(policyname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnGlobalAuthenticationLocalPolicyBindingURL, policyname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetVPNGlobalAuthenticationLocalPolicyBinding() ([]models.VPNGlobalAuthenticationLocalPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnGlobalAuthenticationLocalPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNGlobalAuthenticationLocalPolicyBinding `json:"vpnglobal_authenticationlocalpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNGlobalAuthenticationLocalPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnGlobalAuthenticationLocalPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNGlobalAuthenticationLocalPolicyBinding `json:"vpnglobal_authenticationlocalpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnglobal_authenticationnegotiatepolicy_binding +func (s *VPNService) AddVPNGlobalAuthenticationNegotiatePolicyBinding(resource models.VPNGlobalAuthenticationNegotiatePolicyBinding) error { + payload := map[string]any{"vpnglobal_authenticationnegotiatepolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnGlobalAuthenticationNegotiatePolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNGlobalAuthenticationNegotiatePolicyBinding(policyname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnGlobalAuthenticationNegotiatePolicyBindingURL, policyname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetVPNGlobalAuthenticationNegotiatePolicyBinding() ([]models.VPNGlobalAuthenticationNegotiatePolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnGlobalAuthenticationNegotiatePolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNGlobalAuthenticationNegotiatePolicyBinding `json:"vpnglobal_authenticationnegotiatepolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNGlobalAuthenticationNegotiatePolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnGlobalAuthenticationNegotiatePolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNGlobalAuthenticationNegotiatePolicyBinding `json:"vpnglobal_authenticationnegotiatepolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnglobal_authenticationpolicy_binding +func (s *VPNService) AddVPNGlobalAuthenticationPolicyBinding(resource models.VPNGlobalAuthenticationPolicyBinding) error { + payload := map[string]any{"vpnglobal_authenticationpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnGlobalAuthenticationPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNGlobalAuthenticationPolicyBinding(policyname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnGlobalAuthenticationPolicyBindingURL, policyname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetVPNGlobalAuthenticationPolicyBinding() ([]models.VPNGlobalAuthenticationPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnGlobalAuthenticationPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNGlobalAuthenticationPolicyBinding `json:"vpnglobal_authenticationpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNGlobalAuthenticationPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnGlobalAuthenticationPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNGlobalAuthenticationPolicyBinding `json:"vpnglobal_authenticationpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnglobal_authenticationradiuspolicy_binding +func (s *VPNService) AddVPNGlobalAuthenticationRADIUSPolicyBinding(resource models.VPNGlobalAuthenticationRADIUSPolicyBinding) error { + payload := map[string]any{"vpnglobal_authenticationradiuspolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnGlobalAuthenticationRADIUSPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNGlobalAuthenticationRADIUSPolicyBinding(policyname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnGlobalAuthenticationRADIUSPolicyBindingURL, policyname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetVPNGlobalAuthenticationRADIUSPolicyBinding() ([]models.VPNGlobalAuthenticationRADIUSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnGlobalAuthenticationRADIUSPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNGlobalAuthenticationRADIUSPolicyBinding `json:"vpnglobal_authenticationradiuspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNGlobalAuthenticationRADIUSPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnGlobalAuthenticationRADIUSPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNGlobalAuthenticationRADIUSPolicyBinding `json:"vpnglobal_authenticationradiuspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnglobal_authenticationsamlpolicy_binding +func (s *VPNService) AddVPNGlobalAuthenticationSAMLPolicyBinding(resource models.VPNGlobalAuthenticationSAMLPolicyBinding) error { + payload := map[string]any{"vpnglobal_authenticationsamlpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnGlobalAuthenticationSAMLPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNGlobalAuthenticationSAMLPolicyBinding(policyname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnGlobalAuthenticationSAMLPolicyBindingURL, policyname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetVPNGlobalAuthenticationSAMLPolicyBinding() ([]models.VPNGlobalAuthenticationSAMLPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnGlobalAuthenticationSAMLPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNGlobalAuthenticationSAMLPolicyBinding `json:"vpnglobal_authenticationsamlpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNGlobalAuthenticationSAMLPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnGlobalAuthenticationSAMLPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNGlobalAuthenticationSAMLPolicyBinding `json:"vpnglobal_authenticationsamlpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnglobal_authenticationtacacspolicy_binding +func (s *VPNService) AddVPNGlobalAuthenticationTACACSPolicy(resource models.VPNGlobalAuthenticationTACACSPolicyBinding) error { + payload := map[string]any{"vpnglobal_authenticationtacacspolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnGlobalAuthenticationTACACSPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNGlobalAuthenticationTACACSPolicy(policyname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnGlobalAuthenticationTACACSPolicyBindingURL, policyname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetVPNGlobalAuthenticationTACACSPolicy() ([]models.VPNGlobalAuthenticationTACACSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnGlobalAuthenticationTACACSPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNGlobalAuthenticationTACACSPolicyBinding `json:"vpnglobal_authenticationtacacspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNGlobalAuthenticationTACACSPolicy() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnGlobalAuthenticationTACACSPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNGlobalAuthenticationTACACSPolicyBinding `json:"vpnglobal_authenticationtacacspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnglobal_binding +func (s *VPNService) GetVPNGlobalBinding() (*models.VPNGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNGlobalBinding `json:"vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("no vpnglobal_binding found") + } + + return &result.Data[0], nil +} + +// vpnglobal_domain_binding +func (s *VPNService) AddVPNGlobalDomainBinding(resource models.VPNGlobalDomainBinding) error { + payload := map[string]any{"vpnglobal_domain_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnGlobalDomainBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNGlobalDomainBinding(intranetdomain string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnGlobalDomainBindingURL, intranetdomain), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetVPNGlobalDomainBinding() ([]models.VPNGlobalDomainBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnGlobalDomainBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNGlobalDomainBinding `json:"vpnglobal_domain_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNGlobalDomainBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnGlobalDomainBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNGlobalDomainBinding `json:"vpnglobal_domain_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnglobal_intranetip6_binding +func (s *VPNService) AddVPNGlobalIntranetIP6Binding(resource models.VPNGlobalIntranetIP6Binding) error { + payload := map[string]any{"vpnglobal_intranetip6_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnGlobalIntranetIP6BindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNGlobalIntranetIP6Binding(intranetip6 string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnGlobalIntranetIP6BindingURL, intranetip6), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetVPNGlobalIntranetIP6Binding() ([]models.VPNGlobalIntranetIP6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnGlobalIntranetIP6BindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNGlobalIntranetIP6Binding `json:"vpnglobal_intranetip6_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNGlobalIntranetIP6Binding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnGlobalIntranetIP6BindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNGlobalIntranetIP6Binding `json:"vpnglobal_intranetip6_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnglobal_intranetip_binding +func (s *VPNService) AddVPNGlobalIntranetIPBinding(resource models.VPNGlobalIntranetIPBinding) error { + payload := map[string]any{"vpnglobal_intranetip_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnGlobalIntranetIPBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNGlobalIntranetIPBinding(intranetip string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnGlobalIntranetIPBindingURL, intranetip), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetVPNGlobalIntranetIPBinding() ([]models.VPNGlobalIntranetIPBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnGlobalIntranetIPBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNGlobalIntranetIPBinding `json:"vpnglobal_intranetip_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNGlobalIntranetIPBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnGlobalIntranetIPBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNGlobalIntranetIPBinding `json:"vpnglobal_intranetip_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnglobal_sharefileserver_binding +func (s *VPNService) AddVPNGlobalShareFileServerBinding(resource models.VPNGlobalShareFileServerBinding) error { + payload := map[string]any{"vpnglobal_sharefileserver_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnGlobalShareFileServerBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNGlobalShareFileServerBinding(sharefile string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnGlobalShareFileServerBindingURL, sharefile), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetVPNGlobalShareFileServerBinding() ([]models.VPNGlobalShareFileServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnGlobalShareFileServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNGlobalShareFileServerBinding `json:"vpnglobal_sharefileserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNGlobalShareFileServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnGlobalShareFileServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNGlobalShareFileServerBinding `json:"vpnglobal_sharefileserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnglobal_sslcertkey_binding +func (s *VPNService) AddVPNGlobalSSLCertKeyBinding(resource models.VPNGlobalSSLCertKeyBinding) error { + payload := map[string]any{"vpnglobal_sslcertkey_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnGlobalSSLCertKeyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNGlobalSSLCertKeyBinding(certkeyname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnGlobalSSLCertKeyBindingURL, certkeyname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetVPNGlobalSSLCertKeyBinding() ([]models.VPNGlobalSSLCertKeyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnGlobalSSLCertKeyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNGlobalSSLCertKeyBinding `json:"vpnglobal_sslcertkey_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNGlobalSSLCertKeyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnGlobalSSLCertKeyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNGlobalSSLCertKeyBinding `json:"vpnglobal_sslcertkey_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnglobal_staserver_binding +func (s *VPNService) AddVPNGlobalSTAServerBinding(resource models.VPNGlobalSTAServerBinding) error { + payload := map[string]any{"vpnglobal_staserver_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnGlobalSTAServerBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNGlobalSTAServerBinding(staserver string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnGlobalSTAServerBindingURL, staserver), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetVPNGlobalSTAServerBinding() ([]models.VPNGlobalSTAServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnGlobalSTAServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNGlobalSTAServerBinding `json:"vpnglobal_staserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNGlobalSTAServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnGlobalSTAServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNGlobalSTAServerBinding `json:"vpnglobal_staserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnglobal_vpnclientlessaccesspolicy_binding +func (s *VPNService) AddVPNGlobalVPNClientLessAccessPolicyBinding(resource models.VPNGlobalVPNClientlessAccessPolicyBinding) error { + payload := map[string]any{"vpnglobal_vpnclientlessaccesspolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnGlobalVPNClientlessAccessPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNGlobalVPNClientLessAccessPolicyBinding(policyname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnGlobalVPNClientlessAccessPolicyBindingURL, policyname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetVPNGlobalVPNClientLessAccessPolicyBinding() ([]models.VPNGlobalVPNClientlessAccessPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnGlobalVPNClientlessAccessPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNGlobalVPNClientlessAccessPolicyBinding `json:"vpnglobal_vpnclientlessaccesspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNGlobalVPNClientLessAccessPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnGlobalVPNClientlessAccessPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNGlobalVPNClientlessAccessPolicyBinding `json:"vpnglobal_vpnclientlessaccesspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnglobal_vpneula_binding +func (s *VPNService) AddVPNGlobalVPNEULABinding(resource models.VPNGlobalVPNEULABinding) error { + payload := map[string]any{"vpnglobal_vpneula_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnGlobalVPNEULABindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNGlobalVPNEULABinding(eula string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnGlobalVPNEULABindingURL, eula), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetVPNGlobalVPNEULABinding() ([]models.VPNGlobalVPNEULABinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnGlobalVPNEULABindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNGlobalVPNEULABinding `json:"vpnglobal_vpneula_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNGlobalVPNEULABinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnGlobalVPNEULABindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNGlobalVPNEULABinding `json:"vpnglobal_vpneula_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnglobal_vpnintranetapplication_binding +func (s *VPNService) AddVPNGlobalVPNIntranetApplicationBinding(resource models.VPNGlobalVPNIntranetApplicationBinding) error { + payload := map[string]any{"vpnglobal_vpnintranetapplication_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnGlobalVPNIntranetApplicationBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNGlobalVPNIntranetApplicationBinding(intranetapplication string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnGlobalVPNIntranetApplicationBindingURL, intranetapplication), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetVPNGlobalVPNIntranetApplicationBinding() ([]models.VPNGlobalVPNIntranetApplicationBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnGlobalVPNIntranetApplicationBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNGlobalVPNIntranetApplicationBinding `json:"vpnglobal_vpnintranetapplication_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNGlobalVPNIntranetApplicationBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnGlobalVPNIntranetApplicationBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNGlobalVPNIntranetApplicationBinding `json:"vpnglobal_vpnintranetapplication_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnglobal_vpnnexthopserver_binding +func (s *VPNService) AddVPNGlobalVPNNextHopServerBinding(resource models.VPNGlobalVPNNextHopServerBinding) error { + payload := map[string]any{"vpnglobal_vpnnexthopserver_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnGlobalVPNNextHopServerBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNGlobalVPNNextHopServerBinding(nexthopserver string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnGlobalVPNNextHopServerBindingURL, nexthopserver), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetVPNGlobalVPNNextHopServerBinding() ([]models.VPNGlobalVPNNextHopServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnGlobalVPNNextHopServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNGlobalVPNNextHopServerBinding `json:"vpnglobal_vpnnexthopserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNGlobalVPNNextHopServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnGlobalVPNNextHopServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNGlobalVPNNextHopServerBinding `json:"vpnglobal_vpnnexthopserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnglobal_vpnportaltheme_binding +func (s *VPNService) AddVPNGlobalVPNPortalThemeBinding(resource models.VPNGlobalVPNPortalThemeBinding) error { + payload := map[string]any{"vpnglobal_vpnportaltheme_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnGlobalVPNPortalThemeBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNGlobalVPNPortalThemeBinding(portaltheme string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnGlobalVPNPortalThemeBindingURL, portaltheme), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetVPNGlobalVPNPortalThemeBinding() ([]models.VPNGlobalVPNPortalThemeBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnGlobalVPNPortalThemeBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNGlobalVPNPortalThemeBinding `json:"vpnglobal_vpnportaltheme_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNGlobalVPNPortalThemeBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnGlobalVPNPortalThemeBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNGlobalVPNPortalThemeBinding `json:"vpnglobal_vpnportaltheme_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnglobal_vpnsessionpolcy_binding +func (s *VPNService) AddVPNGlobalVPNSessionPolicyBinding(resource models.VPNGlobalVPNSessionPolicyBinding) error { + payload := map[string]any{"vpnglobal_vpnsessionpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnGlobalVPNSessionPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNGlobalVPNSessionPolicyBinding(policyname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnGlobalVPNSessionPolicyBindingURL, policyname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetVPNGlobalVPNSessionPolicyBinding() ([]models.VPNGlobalVPNSessionPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnGlobalVPNSessionPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNGlobalVPNSessionPolicyBinding `json:"vpnglobal_vpnsessionpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNGlobalVPNSessionPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnGlobalVPNSessionPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNGlobalVPNSessionPolicyBinding `json:"vpnglobal_vpnsessionpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnglobal_vpntrafficpolicy_binding +func (s *VPNService) AddVPNGlobalVPNTrafficPolicyBinding(resource models.VPNGlobalVPNTrafficPolicyBinding) error { + payload := map[string]any{"vpnglobal_vpntrafficpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnGlobalVPNTrafficPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNGlobalVPNTrafficPolicyBinding(policyname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnGlobalVPNTrafficPolicyBindingURL, policyname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetVPNGlobalVPNTrafficPolicyBinding() ([]models.VPNGlobalVPNTrafficPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnGlobalVPNTrafficPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNGlobalVPNTrafficPolicyBinding `json:"vpnglobal_vpntrafficpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNGlobalVPNTrafficPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnGlobalVPNTrafficPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNGlobalVPNTrafficPolicyBinding `json:"vpnglobal_vpntrafficpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnglobal_vpnurlpolicy_binding +func (s *VPNService) AddVPNGlobalVPNURLPolicyBinding(resource models.VPNGlobalVPNURLPolicyBinding) error { + payload := map[string]any{"vpnglobal_vpnurlpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnGlobalVPNURLPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNGlobalVPNURLPolicyBinding(policyname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnGlobalVPNURLPolicyBindingURL, policyname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetVPNGlobalVPNURLPolicyBinding() ([]models.VPNGlobalVPNURLPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnGlobalVPNURLPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNGlobalVPNURLPolicyBinding `json:"vpnglobal_vpnurlpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNGlobalVPNURLPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnGlobalVPNURLPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNGlobalVPNURLPolicyBinding `json:"vpnglobal_vpnurlpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnglobal_vpnurl_binding +func (s *VPNService) AddVPNGlobalVPNURLBinding(resource models.VPNGlobalVPNURLBinding) error { + payload := map[string]any{"vpnglobal_vpnurl_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnGlobalVPNURLBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNGlobalVPNURLBinding(urlname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnGlobalVPNURLBindingURL, urlname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetVPNGlobalVPNURLBinding() ([]models.VPNGlobalVPNURLBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnGlobalVPNURLBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNGlobalVPNURLBinding `json:"vpnglobal_vpnurl_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNGlobalVPNURLBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnGlobalVPNURLBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNGlobalVPNURLBinding `json:"vpnglobal_vpnurl_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnicaconnection +func (s *VPNService) KillVPNICAConnection(resource models.VPNICAConnection) error { + payload := map[string]any{"vpnicaconnection": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=kill", vpnICAConnectionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNICAConnection() ([]models.VPNICAConnection, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnICAConnectionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNICAConnection `json:"vpnicaconnection"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNICAConnection() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnICAConnectionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNICAConnection `json:"vpnicaconnection"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnicadtlsconnection +func (s *VPNService) GetAllVPNICADTLSConnection() ([]models.VPNICADTLSConnection, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnICADTLSConnectionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNICADTLSConnection `json:"vpnicadtlsconnection"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNICADTLSConnection() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnICADTLSConnectionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNICADTLSConnection `json:"vpnicadtlsconnection"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnintranetapplication +func (s *VPNService) AddVPNIntranetApplication(resource models.VPNIntranetApplication) error { + payload := map[string]any{"vpnintranetapplication": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnIntranetApplicationURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNIntranetApplication(intranetapplication string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnIntranetApplicationURL, intranetapplication), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNIntranetApplication() ([]models.VPNIntranetApplication, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnIntranetApplicationURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNIntranetApplication `json:"vpnintranetapplication"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNIntranetApplication(intranetapplication string) (*models.VPNIntranetApplication, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnIntranetApplicationURL, intranetapplication), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNIntranetApplication `json:"vpnintranetapplication"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnintranetapplication %s not found", intranetapplication) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNIntranetApplication() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnIntranetApplicationURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNIntranetApplication `json:"vpnintranetapplication"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnnexthopserver +func (s *VPNService) AddVPNNextHopServer(resource models.VPNNextHopServer) error { + payload := map[string]any{"vpnnexthopserver": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnNextHopServerURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNNextHopServer(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnNextHopServerURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNNextHopServer() ([]models.VPNNextHopServer, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnNextHopServerURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNNextHopServer `json:"vpnnexthopserver"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNNextHopServer(name string) (*models.VPNNextHopServer, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnNextHopServerURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNNextHopServer `json:"vpnnexthopserver"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnnexthopserver %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNNextHopServer() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnNextHopServerURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNNextHopServer `json:"vpnnexthopserver"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnparameter +func (s *VPNService) UpdateVPNParameter(resource models.VPNParameter) error { + payload := map[string]any{"vpnparameter": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, vpnParameterURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) UnsetVPNParameter(resource models.VPNParameter) error { + payload := map[string]any{"vpnparameter": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", vpnParameterURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNParameter() (*models.VPNParameter, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnParameterURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNParameter `json:"vpnparameter"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnparameter not found") + } + + return &result.Data[0], nil +} + +// vpnpcoipconnection +func (s *VPNService) KillVPNPCoIPConnection(resource models.VPNPCoIPConnection) error { + payload := map[string]any{"vpnpcoipconnection": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=kill", vpnPCoIPConnectionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNPCoIPConnection() ([]models.VPNPCoIPConnection, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnPCoIPConnectionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNPCoIPConnection `json:"vpnpcoipconnection"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNPCoIPConnection() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnPCoIPConnectionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNPCoIPConnection `json:"vpnpcoipconnection"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnpcoipprofile +func (s *VPNService) AddVPNPCoIPProfile(resource models.VPNPCoIPProfile) error { + payload := map[string]any{"vpnpcoipprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnPCoIPProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNPCoIPProfile(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnPCoIPProfileURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) UpdateVPNPCoIPProfile(resource models.VPNPCoIPProfile) error { + payload := map[string]any{"vpnpcoipprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, vpnPCoIPProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) UnsetVPNPCoIPProfile(resource models.VPNPCoIPProfile) error { + payload := map[string]any{"vpnpcoipprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", vpnPCoIPProfileURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNPCoIPProfile() ([]models.VPNPCoIPProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnPCoIPProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNPCoIPProfile `json:"vpnpcoipprofile"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNPCoIPProfile(name string) (*models.VPNPCoIPProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnPCoIPProfileURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNPCoIPProfile `json:"vpnpcoipprofile"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnpcoipprofile %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNPCoIPProfile() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnPCoIPProfileURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNPCoIPProfile `json:"vpnpcoipprofile"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnpcoipvserverprofile +func (s *VPNService) AddVPNPCoIPVServerProfile(resource models.VPNPCoIPVServerProfile) error { + payload := map[string]any{"vpnpcoipvserverprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnPCoIPVServerProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNPCoIPVServerProfile(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnPCoIPVServerProfileURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) UpdateVPNPCoIPVServerProfile(resource models.VPNPCoIPVServerProfile) error { + payload := map[string]any{"vpnpcoipvserverprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, vpnPCoIPVServerProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) UnsetVPNPCoIPVServerProfile(resource models.VPNPCoIPVServerProfile) error { + payload := map[string]any{"vpnpcoipvserverprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", vpnPCoIPVServerProfileURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNPCoIPVServerProfile() ([]models.VPNPCoIPVServerProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnPCoIPVServerProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNPCoIPVServerProfile `json:"vpnpcoipvserverprofile"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNPCoIPVServerProfile(name string) (*models.VPNPCoIPVServerProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnPCoIPVServerProfileURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNPCoIPVServerProfile `json:"vpnpcoipvserverprofile"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnpcoipvserverprofile %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNPCoIPVServerProfile() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnPCoIPVServerProfileURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNPCoIPVServerProfile `json:"vpnpcoipvserverprofile"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnportaltheme +func (s *VPNService) AddVPNPortalTheme(resource models.VPNPortalTheme) error { + payload := map[string]any{"vpnportaltheme": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnPortalThemeURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNPortalTheme(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnPortalThemeURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNPortalTheme() ([]models.VPNPortalTheme, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnPortalThemeURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNPortalTheme `json:"vpnportaltheme"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNPortalTheme(name string) (*models.VPNPortalTheme, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnPortalThemeURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNPortalTheme `json:"vpnportaltheme"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnportaltheme %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNPortalTheme() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnPortalThemeURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNPortalTheme `json:"vpnportaltheme"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnsamlssoprofile +func (s *VPNService) AddVPNSAMLSSOProfile(resource models.VPNSAMLSSOProfile) error { + payload := map[string]any{"vpnsamlssoprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnSAMLSSOProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNSAMLSSOProfile(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnSAMLSSOProfileURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) UpdateVPNSAMLSSOProfile(resource models.VPNSAMLSSOProfile) error { + payload := map[string]any{"vpnsamlssoprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, vpnSAMLSSOProfileURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) UnsetVPNSAMLSSOProfile(resource models.VPNSAMLSSOProfile) error { + payload := map[string]any{"vpnsamlssoprofile": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", vpnSAMLSSOProfileURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNSAMLSSOProfile() ([]models.VPNSAMLSSOProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnSAMLSSOProfileURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNSAMLSSOProfile `json:"vpnsamlssoprofile"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNSAMLSSOProfile(name string) (*models.VPNSAMLSSOProfile, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnSAMLSSOProfileURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNSAMLSSOProfile `json:"vpnsamlssoprofile"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnsamlssoprofile %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNSAMLSSOProfile() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnSAMLSSOProfileURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNSAMLSSOProfile `json:"vpnsamlssoprofile"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnsessionaction +func (s *VPNService) AddVPNSessionAction(resource models.VPNSessionAction) error { + payload := map[string]any{"vpnsessionaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnSessionActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNSessionAction(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnSessionActionURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) UpdateVPNSessionAction(resource models.VPNSessionAction) error { + payload := map[string]any{"vpnsessionaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, vpnSessionActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) UnsetVPNSessionAction(resource models.VPNSessionAction) error { + payload := map[string]any{"vpnsessionaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", vpnSessionActionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNSessionAction() ([]models.VPNSessionAction, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnSessionActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNSessionAction `json:"vpnsessionaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNSessionAction(name string) (*models.VPNSessionAction, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnSessionActionURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNSessionAction `json:"vpnsessionaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnsessionaction %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNSessionAction() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnSessionActionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNSessionAction `json:"vpnsessionaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnsessionpolicy +func (s *VPNService) AddVPNSessionPolicy(resource models.VPNSessionPolicy) error { + payload := map[string]any{"vpnsessionpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnSessionPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNSessionPolicy(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnSessionPolicyURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) UpdateVPNSessionPolicy(resource models.VPNSessionPolicy) error { + payload := map[string]any{"vpnsessionpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, vpnSessionPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) UnsetVPNSessionPolicy(resource models.VPNSessionPolicy) error { + payload := map[string]any{"vpnsessionpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", vpnSessionPolicyURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNSessionPolicy() ([]models.VPNSessionPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnSessionPolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNSessionPolicy `json:"vpnsessionpolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNSessionPolicy(name string) (*models.VPNSessionPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnSessionPolicyURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNSessionPolicy `json:"vpnsessionpolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnsessionpolicy %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNSessionPolicy() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnSessionPolicyURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNSessionPolicy `json:"vpnsessionpolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnsesisonpolicy_aaagroup_binding +func (s *VPNService) GetAllVPNSessionPolicyAAAGroupBinding() ([]models.VPNSessionPolicyAAAGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnSessionPolicyAAAGroupBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNSessionPolicyAAAGroupBinding `json:"vpnsessionpolicy_aaagroup_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNSessionPolicyAAAGroupBinding(name string) (*models.VPNSessionPolicyAAAGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnSessionPolicyAAAGroupBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNSessionPolicyAAAGroupBinding `json:"vpnsessionpolicy_aaagroup_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnsessionpolicy_aaagroup_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNSessionPolicyAAAGroupBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnSessionPolicyAAAGroupBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNSessionPolicyAAAGroupBinding `json:"vpnsessionpolicy_aaagroup_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnsessionpolicy_aaauser_binding +func (s *VPNService) GetAllVPNSessionPolicyAAAUserBinding() ([]models.VPNSessionPolicyAAAUserBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnSessionPolicyAAAUserBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNSessionPolicyAAAUserBinding `json:"vpnsessionpolicy_aaauser_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNSessionPolicyAAAUserBinding(name string) (*models.VPNSessionPolicyAAAUserBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnSessionPolicyAAAUserBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNSessionPolicyAAAUserBinding `json:"vpnsessionpolicy_aaauser_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnsessionpolicy_aaauser_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNSessionPolicyAAAUserBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnSessionPolicyAAAUserBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNSessionPolicyAAAUserBinding `json:"vpnsessionpolicy_aaauser_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnsessionpolicy_binding +func (s *VPNService) GetAllVPNSessionPolicyBinding() ([]models.VPNSessionPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnSessionPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNSessionPolicyBinding `json:"vpnsessionpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNSessionPolicyBinding(name string) (*models.VPNSessionPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnSessionPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNSessionPolicyBinding `json:"vpnsessionpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnsessionpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +// vpnsessionpolicy_vpnglobal_binding +func (s *VPNService) GetAllVPNSessionPolicyVPNGlobalBinding() ([]models.VPNSessionPolicyVPNGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnSessionPolicyVPNGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNSessionPolicyVPNGlobalBinding `json:"vpnsessionpolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNSessionPolicyVPNGlobalBinding(name string) (*models.VPNSessionPolicyVPNGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnSessionPolicyVPNGlobalBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNSessionPolicyVPNGlobalBinding `json:"vpnsessionpolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnsessionpolicy_vpnglobal_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNSessionPolicyVPNGlobalBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnSessionPolicyVPNGlobalBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNSessionPolicyVPNGlobalBinding `json:"vpnsessionpolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnsessionpolicy_vpnvserver_binding +func (s *VPNService) GetAllVPNSessionPolicyVPNVServerBinding() ([]models.VPNSessionPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnSessionPolicyVPNVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNSessionPolicyVPNVServerBinding `json:"vpnsessionpolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNSessionPolicyVPNVServerBinding(name string) (*models.VPNSessionPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnSessionPolicyVPNVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNSessionPolicyVPNVServerBinding `json:"vpnsessionpolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnsessionpolicy_vpnvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNSessionPolicyVPNVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnSessionPolicyVPNVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNSessionPolicyVPNVServerBinding `json:"vpnsessionpolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnsfconfig +func (s *VPNService) GetAllVPNSFConfig() ([]models.VPNSFConfig, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnSFConfigURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNSFConfig `json:"vpnsfconfig"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNSFConfig() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnSFConfigURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNSFConfig `json:"vpnsfconfig"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnstoreinfo +func (s *VPNService) GetAllVPNStoreInfo() ([]models.VPNStoreInfo, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnStoreInfoURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNStoreInfo `json:"vpnstoreinfo"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) CountVPNStoreInfo() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnStoreInfoURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNStoreInfo `json:"vpnstoreinfo"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpntrafficaction +func (s *VPNService) AddVPNTrafficAction(resource models.VPNTrafficAction) error { + payload := map[string]any{"vpntrafficaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnTrafficActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNTrafficAction(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnTrafficActionURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) UpdateVPNTrafficAction(resource models.VPNTrafficAction) error { + payload := map[string]any{"vpntrafficaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, vpnTrafficActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) UnsetVPNTrafficAction(resource models.VPNTrafficAction) error { + payload := map[string]any{"vpntrafficaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", vpnTrafficActionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNTrafficAction() ([]models.VPNTrafficAction, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnTrafficActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNTrafficAction `json:"vpntrafficaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNTrafficAction(name string) (*models.VPNTrafficAction, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnTrafficActionURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNTrafficAction `json:"vpntrafficaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpntrafficaction %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNTrafficAction() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnTrafficActionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNTrafficAction `json:"vpntrafficaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpntrafficpolicy +func (s *VPNService) AddVPNTrafficPolicy(resource models.VPNTrafficPolicy) error { + payload := map[string]any{"vpntrafficpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnTrafficPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNTrafficPolicy(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnTrafficPolicyURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) UpdateVPNTrafficPolicy(resource models.VPNTrafficPolicy) error { + payload := map[string]any{"vpntrafficpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, vpnTrafficPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) UnsetVPNTrafficPolicy(resource models.VPNTrafficPolicy) error { + payload := map[string]any{"vpntrafficpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", vpnTrafficPolicyURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNTrafficPolicy() ([]models.VPNTrafficPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnTrafficPolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNTrafficPolicy `json:"vpntrafficpolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNTrafficPolicy(name string) (*models.VPNTrafficPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnTrafficPolicyURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNTrafficPolicy `json:"vpntrafficpolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpntrafficpolicy %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNTrafficPolicy() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnTrafficPolicyURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNTrafficPolicy `json:"vpntrafficpolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpntrafficpolicy_aaagroup_binding +func (s *VPNService) GetAllVPNTrafficPolicyAAAGroupBinding() ([]models.VPNTrafficPolicyAAAGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnTrafficPolicyAAAGroupBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNTrafficPolicyAAAGroupBinding `json:"vpntrafficpolicy_aaagroup_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNTrafficPolicyAAAGroupBinding(name string) (*models.VPNTrafficPolicyAAAGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnTrafficPolicyAAAGroupBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNTrafficPolicyAAAGroupBinding `json:"vpntrafficpolicy_aaagroup_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpntrafficpolicy_aaagroup_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNTrafficPolicyAAAGroupBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnTrafficPolicyAAAGroupBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNTrafficPolicyAAAGroupBinding `json:"vpntrafficpolicy_aaagroup_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpntrafficpolicy_aaauser_binding +func (s *VPNService) GetAllVPNTrafficPolicyAAAUserBinding() ([]models.VPNTrafficPolicyAAAUserBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnTrafficPolicyAAAUserBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNTrafficPolicyAAAUserBinding `json:"vpntrafficpolicy_aaauser_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNTrafficPolicyAAAUserBinding(name string) (*models.VPNTrafficPolicyAAAUserBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnTrafficPolicyAAAUserBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNTrafficPolicyAAAUserBinding `json:"vpntrafficpolicy_aaauser_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpntrafficpolicy_aaauser_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNTrafficPolicyAAAUserBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnTrafficPolicyAAAUserBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNTrafficPolicyAAAUserBinding `json:"vpntrafficpolicy_aaauser_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpntrafficpolicy_binding +func (s *VPNService) GetAllVPNTrafficPolicyBinding() ([]models.VPNTrafficPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnTrafficPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNTrafficPolicyBinding `json:"vpntrafficpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNTrafficPolicyBinding(name string) (*models.VPNTrafficPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnTrafficPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNTrafficPolicyBinding `json:"vpntrafficpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpntrafficpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +// vpntrafficpolicy_vpnglobal_binding +func (s *VPNService) GetAllVPNTrafficPolicyVPNGlobalBinding() ([]models.VPNTrafficPolicyVPNGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnTrafficPolicyVPNGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNTrafficPolicyVPNGlobalBinding `json:"vpntrafficpolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNTrafficPolicyVPNGlobalBinding(name string) (*models.VPNTrafficPolicyVPNGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnTrafficPolicyVPNGlobalBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNTrafficPolicyVPNGlobalBinding `json:"vpntrafficpolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpntrafficpolicy_vpnglobal_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNTrafficPolicyVPNGlobalBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnTrafficPolicyVPNGlobalBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNTrafficPolicyVPNGlobalBinding `json:"vpntrafficpolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpntrafficpolicy_vpnvserver_binding +func (s *VPNService) GetAllVPNTrafficPolicyVPNVServerBinding() ([]models.VPNTrafficPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnTrafficPolicyVPNVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNTrafficPolicyVPNVServerBinding `json:"vpntrafficpolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNTrafficPolicyVPNVServerBinding(name string) (*models.VPNTrafficPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnTrafficPolicyVPNVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNTrafficPolicyVPNVServerBinding `json:"vpntrafficpolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpntrafficpolicy_vpnvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNTrafficPolicyVPNVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnTrafficPolicyVPNVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNTrafficPolicyVPNVServerBinding `json:"vpntrafficpolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnurl +func (s *VPNService) AddVPNURL(resource models.VPNURL) error { + payload := map[string]any{"vpnurl": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnURLURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNURL(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnURLURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) UpdateVPNURL(resource models.VPNURL) error { + payload := map[string]any{"vpnurl": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, vpnURLURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) UnsetVPNURL(resource models.VPNURL) error { + payload := map[string]any{"vpnurl": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", vpnURLURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNURL() ([]models.VPNURL, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnURLURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNURL `json:"vpnurl"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNURL(name string) (*models.VPNURL, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnURLURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNURL `json:"vpnurl"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnurl %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNURL() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnURLURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNURL `json:"vpnurl"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnurlaction +func (s *VPNService) AddVPNURLAction(resource models.VPNURLAction) error { + payload := map[string]any{"vpnurlaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnURLActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNURLAction(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnURLActionURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) UpdateVPNURLAction(resource models.VPNURLAction) error { + payload := map[string]any{"vpnurlaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, vpnURLActionURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) UnsetVPNURLAction(resource models.VPNURLAction) error { + payload := map[string]any{"vpnurlaction": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", vpnURLActionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) RenameVPNURLAction(name string, newname string) error { + payload := map[string]any{ + "vpnurlaction": map[string]any{ + "name": name, + "newname": newname, + }, + } + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=rename", vpnURLActionURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNURLAction() ([]models.VPNURLAction, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnURLActionURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNURLAction `json:"vpnurlaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNURLAction(name string) (*models.VPNURLAction, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnURLActionURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNURLAction `json:"vpnurlaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnurlaction %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNURLAction() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnURLActionURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNURLAction `json:"vpnurlaction"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnurlpolicy +func (s *VPNService) AddVPNURLPolicy(resource models.VPNURLPolicy) error { + payload := map[string]any{"vpnurlpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnURLPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNURLPolicy(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnURLPolicyURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) UpdateVPNURLPolicy(resource models.VPNURLPolicy) error { + payload := map[string]any{"vpnurlpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, vpnURLPolicyURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) UnsetVPNURLPolicy(resource models.VPNURLPolicy) error { + payload := map[string]any{"vpnurlpolicy": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", vpnURLPolicyURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) RenameVPNURLPolicy(name string, newname string) error { + payload := map[string]any{ + "vpnurlpolicy": map[string]any{ + "name": name, + "newname": newname, + }, + } + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=rename", vpnURLPolicyURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNURLPolicy() ([]models.VPNURLPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnURLPolicyURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNURLPolicy `json:"vpnurlpolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNURLPolicy(name string) (*models.VPNURLPolicy, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnURLPolicyURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNURLPolicy `json:"vpnurlpolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnurlpolicy %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNURLPolicy() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnURLPolicyURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNURLPolicy `json:"vpnurlpolicy"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnurlpolicy_aaagroup_binding +func (s *VPNService) GetAllVPNURLPolicyAAAGroupBinding() ([]models.VPNURLPolicyAAAGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnURLPolicyAAAGroupBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNURLPolicyAAAGroupBinding `json:"vpnurlpolicy_aaagroup_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNURLPolicyAAAGroupBinding(name string) (*models.VPNURLPolicyAAAGroupBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnURLPolicyAAAGroupBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNURLPolicyAAAGroupBinding `json:"vpnurlpolicy_aaagroup_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnurlpolicy_aaagroup_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNURLPolicyAAAGroupBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnURLPolicyAAAGroupBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNURLPolicyAAAGroupBinding `json:"vpnurlpolicy_aaagroup_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnurlpolicy_aaauser_binding +func (s *VPNService) GetAllVPNURLPolicyAAAUserBinding() ([]models.VPNURLPolicyAAAUserBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnURLPolicyAAAUserBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNURLPolicyAAAUserBinding `json:"vpnurlpolicy_aaauser_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNURLPolicyAAAUserBinding(name string) (*models.VPNURLPolicyAAAUserBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnURLPolicyAAAUserBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNURLPolicyAAAUserBinding `json:"vpnurlpolicy_aaauser_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnurlpolicy_aaauser_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNURLPolicyAAAUserBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnURLPolicyAAAUserBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNURLPolicyAAAUserBinding `json:"vpnurlpolicy_aaauser_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnurlpolicy_binding +func (s *VPNService) GetAllVPNURLPolicyBinding() ([]models.VPNURLPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnURLPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNURLPolicyBinding `json:"vpnurlpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNURLPolicyBinding(name string) (*models.VPNURLPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnURLPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNURLPolicyBinding `json:"vpnurlpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnurlpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +// vpnurlpolicy_vpnglobal_binding +func (s *VPNService) GetAllVPNURLPolicyVPNGlobalBinding() ([]models.VPNURLPolicyVPNGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnURLPolicyVPNGlobalBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNURLPolicyVPNGlobalBinding `json:"vpnurlpolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNURLPolicyVPNGlobalBinding(name string) (*models.VPNURLPolicyVPNGlobalBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnURLPolicyVPNGlobalBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNURLPolicyVPNGlobalBinding `json:"vpnurlpolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnurlpolicy_vpnglobal_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNURLPolicyVPNGlobalBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnURLPolicyVPNGlobalBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNURLPolicyVPNGlobalBinding `json:"vpnurlpolicy_vpnglobal_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnurlpolicy_vpnvserver_binding +func (s *VPNService) GetAllVPNURLPolicyVPNVServerBinding() ([]models.VPNURLPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnURLPolicyVPNVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNURLPolicyVPNVServerBinding `json:"vpnurlpolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNURLPolicyVPNVServerBinding(name string) (*models.VPNURLPolicyVPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnURLPolicyVPNVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNURLPolicyVPNVServerBinding `json:"vpnurlpolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnurlpolicy_vpnvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNURLPolicyVPNVServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnURLPolicyVPNVServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNURLPolicyVPNVServerBinding `json:"vpnurlpolicy_vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver +func (s *VPNService) AddVPNVServer(resource models.VPNVServer) error { + payload := map[string]any{"vpnvserver": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServer(name string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", vpnVServerURL, name), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) UpdateVPNVServer(resource models.VPNVServer) error { + payload := map[string]any{"vpnvserver": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPut, vpnVServerURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) UnsetVPNVServer(resource models.VPNVServer) error { + payload := map[string]any{"vpnvserver": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=unset", vpnVServerURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) EnableVPNVServer(name string) error { + payload := map[string]any{"vpnvserver": map[string]string{"name": name}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=enable", vpnVServerURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DisableVPNVServer(name string) error { + payload := map[string]any{"vpnvserver": map[string]string{"name": name}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=disable", vpnVServerURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) RenameVPNVServer(name string, newname string) error { + payload := map[string]any{ + "vpnvserver": map[string]any{ + "name": name, + "newname": newname, + }, + } + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=rename", vpnVServerURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) CheckVPNVServer(name string) error { + payload := map[string]any{"vpnvserver": map[string]string{"name": name}} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, fmt.Sprintf("%s?action=check", vpnVServerURL), bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServer() ([]models.VPNVServer, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServer `json:"vpnvserver"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServer(name string) (*models.VPNVServer, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServer `json:"vpnvserver"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServer() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServer `json:"vpnvserver"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_aaapreauthenticationpolicy_binding +func (s *VPNService) AddVPNVServerAAAPreauthenticationPolicyBinding(resource models.VPNVServerAAAPreauthenticationPolicyBinding) error { + payload := map[string]any{"vpnvserver_aaapreauthenticationpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerAAAPreauthenticationPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerAAAPreauthenticationPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", vpnVServerAAAPreauthenticationPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerAAAPreauthenticationPolicyBinding() ([]models.VPNVServerAAAPreauthenticationPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerAAAPreauthenticationPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAAAPreauthenticationPolicyBinding `json:"vpnvserver_aaapreauthenticationpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerAAAPreauthenticationPolicyBinding(name string) (*models.VPNVServerAAAPreauthenticationPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerAAAPreauthenticationPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAAAPreauthenticationPolicyBinding `json:"vpnvserver_aaapreauthenticationpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_aaapreauthenticationpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerAAAPreauthenticationPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerAAAPreauthenticationPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerAAAPreauthenticationPolicyBinding `json:"vpnvserver_aaapreauthenticationpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_analyticsprofile_binding +func (s *VPNService) AddVPNVServerAnalyticsProfileBinding(resource models.VPNVServerAnalyticsProfileBinding) error { + payload := map[string]any{"vpnvserver_analyticsprofile_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerAnalyticsProfileBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerAnalyticsProfileBinding(name string, analyticsprofile string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=analyticsprofile:%s", vpnVServerAnalyticsProfileBindingURL, name, analyticsprofile), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerAnalyticsProfileBinding() ([]models.VPNVServerAnalyticsProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerAnalyticsProfileBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAnalyticsProfileBinding `json:"vpnvserver_analyticsprofile_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerAnalyticsProfileBinding(name string) (*models.VPNVServerAnalyticsProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerAnalyticsProfileBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAnalyticsProfileBinding `json:"vpnvserver_analyticsprofile_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_analyticsprofile_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerAnalyticsProfileBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerAnalyticsProfileBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerAnalyticsProfileBinding `json:"vpnvserver_analyticsprofile_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_appcontroller_binding +func (s *VPNService) AddVPNVServerAppControllerBinding(resource models.VPNVServerAppControllerBinding) error { + payload := map[string]any{"vpnvserver_appcontroller_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerAppControllerBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerAppControllerBinding(name string, appcontroller string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=appcontroller:%s", vpnVServerAppControllerBindingURL, name, appcontroller), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerAppControllerBinding() ([]models.VPNVServerAppControllerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerAppControllerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAppControllerBinding `json:"vpnvserver_appcontroller_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerAppControllerBinding(name string) (*models.VPNVServerAppControllerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerAppControllerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAppControllerBinding `json:"vpnvserver_appcontroller_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_appcontroller_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerAppControllerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerAppControllerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerAppControllerBinding `json:"vpnvserver_appcontroller_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_appflowpolicy_binding +func (s *VPNService) AddVPNVServerAppFlowPolicyBinding(resource models.VPNVServerAppFlowPolicyBinding) error { + payload := map[string]any{"vpnvserver_appflowpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerAppFlowPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerAppFlowPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", vpnVServerAppFlowPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerAppFlowPolicyBinding() ([]models.VPNVServerAppFlowPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerAppFlowPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAppFlowPolicyBinding `json:"vpnvserver_appflowpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerAppFlowPolicyBinding(name string) (*models.VPNVServerAppFlowPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerAppFlowPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAppFlowPolicyBinding `json:"vpnvserver_appflowpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_appflowpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerAppFlowPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerAppFlowPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerAppFlowPolicyBinding `json:"vpnvserver_appflowpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_auditnslogpolicy_binding +func (s *VPNService) AddVPNVServerAuditNSLogPolicyBinding(resource models.VPNVServerAuditNSLogPolicyBinding) error { + payload := map[string]any{"vpnvserver_auditnslogpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerAuditNSLogPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerAuditNSLogPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", vpnVServerAuditNSLogPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerAuditNSLogPolicyBinding() ([]models.VPNVServerAuditNSLogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerAuditNSLogPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuditNSLogPolicyBinding `json:"vpnvserver_auditnslogpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerAuditNSLogPolicyBinding(name string) (*models.VPNVServerAuditNSLogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerAuditNSLogPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuditNSLogPolicyBinding `json:"vpnvserver_auditnslogpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_auditnslogpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerAuditNSLogPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerAuditNSLogPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerAuditNSLogPolicyBinding `json:"vpnvserver_auditnslogpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_auditsyslogpolicy_binding +func (s *VPNService) AddVPNVServerAuditSyslogPolicyBinding(resource models.VPNVServerAuditSyslogPolicyBinding) error { + payload := map[string]any{"vpnvserver_auditsyslogpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerAuditSyslogPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerAuditSyslogPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", vpnVServerAuditSyslogPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerAuditSyslogPolicyBinding() ([]models.VPNVServerAuditSyslogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerAuditSyslogPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuditSyslogPolicyBinding `json:"vpnvserver_auditsyslogpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerAuditSyslogPolicyBinding(name string) (*models.VPNVServerAuditSyslogPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerAuditSyslogPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuditSyslogPolicyBinding `json:"vpnvserver_auditsyslogpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_auditsyslogpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerAuditSyslogPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerAuditSyslogPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerAuditSyslogPolicyBinding `json:"vpnvserver_auditsyslogpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_authenticationcertpolicy_binding +func (s *VPNService) AddVPNVServerAuthenticationCertPolicyBinding(resource models.VPNVServerAuthenticationCertPolicyBinding) error { + payload := map[string]any{"vpnvserver_authenticationcertpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerAuthenticationCertPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerAuthenticationCertPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", vpnVServerAuthenticationCertPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerAuthenticationCertPolicyBinding() ([]models.VPNVServerAuthenticationCertPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerAuthenticationCertPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuthenticationCertPolicyBinding `json:"vpnvserver_authenticationcertpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerAuthenticationCertPolicyBinding(name string) (*models.VPNVServerAuthenticationCertPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerAuthenticationCertPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuthenticationCertPolicyBinding `json:"vpnvserver_authenticationcertpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_authenticationcertpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerAuthenticationCertPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerAuthenticationCertPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerAuthenticationCertPolicyBinding `json:"vpnvserver_authenticationcertpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_authenticationfapolicy_binding +func (s *VPNService) AddVPNVServerAuthenticationFAPolicyBinding(resource models.VPNVServerAuthenticationDFAPolicyBinding) error { + payload := map[string]any{"vpnvserver_authenticationdfapolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerAuthenticationFAPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerAuthenticationFAPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", vpnVServerAuthenticationFAPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerAuthenticationFAPolicyBinding() ([]models.VPNVServerAuthenticationDFAPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerAuthenticationFAPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuthenticationDFAPolicyBinding `json:"vpnvserver_authenticationdfapolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerAuthenticationFAPolicyBinding(name string) (*models.VPNVServerAuthenticationDFAPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerAuthenticationFAPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuthenticationDFAPolicyBinding `json:"vpnvserver_authenticationdfapolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_authenticationfapolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerAuthenticationFAPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerAuthenticationFAPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerAuthenticationDFAPolicyBinding `json:"vpnvserver_authenticationdfapolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_authenticationldappolicy_binding +func (s *VPNService) AddVPNVServerAuthenticationLDAPPolicyBinding(resource models.VPNVServerAuthenticationLDAPPolicyBinding) error { + payload := map[string]any{"vpnvserver_authenticationldappolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerAuthenticationLDAPPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerAuthenticationLDAPPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", vpnVServerAuthenticationLDAPPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerAuthenticationLDAPPolicyBinding() ([]models.VPNVServerAuthenticationLDAPPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerAuthenticationLDAPPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuthenticationLDAPPolicyBinding `json:"vpnvserver_authenticationldappolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerAuthenticationLDAPPolicyBinding(name string) (*models.VPNVServerAuthenticationLDAPPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerAuthenticationLDAPPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuthenticationLDAPPolicyBinding `json:"vpnvserver_authenticationldappolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_authenticationldappolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerAuthenticationLDAPPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerAuthenticationLDAPPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerAuthenticationLDAPPolicyBinding `json:"vpnvserver_authenticationldappolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_authenticationlocalpolicy_binding +func (s *VPNService) AddVPNVServerAuthenticationLocalPolicyBinding(resource models.VPNVServerAuthenticationLocalPolicyBinding) error { + payload := map[string]any{"vpnvserver_authenticationlocalpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerAuthenticationLocalPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerAuthenticationLocalPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", vpnVServerAuthenticationLocalPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerAuthenticationLocalPolicyBinding() ([]models.VPNVServerAuthenticationLocalPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerAuthenticationLocalPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuthenticationLocalPolicyBinding `json:"vpnvserver_authenticationlocalpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerAuthenticationLocalPolicyBinding(name string) (*models.VPNVServerAuthenticationLocalPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerAuthenticationLocalPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuthenticationLocalPolicyBinding `json:"vpnvserver_authenticationlocalpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_authenticationlocalpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerAuthenticationLocalPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerAuthenticationLocalPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerAuthenticationLocalPolicyBinding `json:"vpnvserver_authenticationlocalpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_authenticationloginschemapolicy_binding +func (s *VPNService) AddVPNVServerAuthenticationLoginSchemaPolicyBinding(resource models.VPNVServerAuthenticationLoginSchemaPolicyBinding) error { + payload := map[string]any{"vpnvserver_authenticationloginschemapolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerAuthenticationLoginSchemaPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerAuthenticationLoginSchemaPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", vpnVServerAuthenticationLoginSchemaPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerAuthenticationLoginSchemaPolicyBinding() ([]models.VPNVServerAuthenticationLoginSchemaPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerAuthenticationLoginSchemaPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuthenticationLoginSchemaPolicyBinding `json:"vpnvserver_authenticationloginschemapolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerAuthenticationLoginSchemaPolicyBinding(name string) (*models.VPNVServerAuthenticationLoginSchemaPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerAuthenticationLoginSchemaPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuthenticationLoginSchemaPolicyBinding `json:"vpnvserver_authenticationloginschemapolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_authenticationloginschemapolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerAuthenticationLoginSchemaPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerAuthenticationLoginSchemaPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerAuthenticationLoginSchemaPolicyBinding `json:"vpnvserver_authenticationloginschemapolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_authenticationnegotiatepolcy_binding +func (s *VPNService) AddVPNVServerAuthenticationNegotiatePolicyBinding(resource models.VPNVServerAuthenticationNegotiatePolicyBinding) error { + payload := map[string]any{"vpnvserver_authenticationnegotiatepolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerAuthenticationNegotiatePolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerAuthenticationNegotiatePolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", vpnVServerAuthenticationNegotiatePolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerAuthenticationNegotiatePolicyBinding() ([]models.VPNVServerAuthenticationNegotiatePolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerAuthenticationNegotiatePolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuthenticationNegotiatePolicyBinding `json:"vpnvserver_authenticationnegotiatepolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerAuthenticationNegotiatePolicyBinding(name string) (*models.VPNVServerAuthenticationNegotiatePolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerAuthenticationNegotiatePolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuthenticationNegotiatePolicyBinding `json:"vpnvserver_authenticationnegotiatepolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_authenticationnegotiatepolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerAuthenticationNegotiatePolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerAuthenticationNegotiatePolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerAuthenticationNegotiatePolicyBinding `json:"vpnvserver_authenticationnegotiatepolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_authenticationoauthidppolicy_binding +func (s *VPNService) AddVPNVServerAuthenticationOAuthIDPPolicyBinding(resource models.VPNVServerAuthenticationOAuthIDPPolicyBinding) error { + payload := map[string]any{"vpnvserver_authenticationoauthidppolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerAuthenticationOAuthIDPPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerAuthenticationOAuthIDPPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", vpnVServerAuthenticationOAuthIDPPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerAuthenticationOAuthIDPPolicyBinding() ([]models.VPNVServerAuthenticationOAuthIDPPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerAuthenticationOAuthIDPPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuthenticationOAuthIDPPolicyBinding `json:"vpnvserver_authenticationoauthidppolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerAuthenticationOAuthIDPPolicyBinding(name string) (*models.VPNVServerAuthenticationOAuthIDPPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerAuthenticationOAuthIDPPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuthenticationOAuthIDPPolicyBinding `json:"vpnvserver_authenticationoauthidppolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_authenticationoauthidppolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerAuthenticationOAuthIDPPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerAuthenticationOAuthIDPPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerAuthenticationOAuthIDPPolicyBinding `json:"vpnvserver_authenticationoauthidppolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_authenticationpolicy_binding +func (s *VPNService) AddVPNVServerAuthenticationPolicyBinding(resource models.VPNVServerAuthenticationPolicyBinding) error { + payload := map[string]any{"vpnvserver_authenticationpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerAuthenticationPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerAuthenticationPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", vpnVServerAuthenticationPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerAuthenticationPolicyBinding() ([]models.VPNVServerAuthenticationPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerAuthenticationPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuthenticationPolicyBinding `json:"vpnvserver_authenticationpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerAuthenticationPolicyBinding(name string) (*models.VPNVServerAuthenticationPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerAuthenticationPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuthenticationPolicyBinding `json:"vpnvserver_authenticationpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_authenticationpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerAuthenticationPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerAuthenticationPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerAuthenticationPolicyBinding `json:"vpnvserver_authenticationpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_authenticationradiuspolicy_binding +func (s *VPNService) AddVPNVServerAuthenticationRADIUSPolicyBinding(resource models.VPNVServerAuthenticationRADIUSPolicyBinding) error { + payload := map[string]any{"vpnvserver_authenticationradiuspolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerAuthenticationRADIUSPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerAuthenticationRADIUSPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", vpnVServerAuthenticationRADIUSPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerAuthenticationRADIUSPolicyBinding() ([]models.VPNVServerAuthenticationRADIUSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerAuthenticationRADIUSPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuthenticationRADIUSPolicyBinding `json:"vpnvserver_authenticationradiuspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerAuthenticationRADIUSPolicyBinding(name string) (*models.VPNVServerAuthenticationRADIUSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerAuthenticationRADIUSPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuthenticationRADIUSPolicyBinding `json:"vpnvserver_authenticationradiuspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_authenticationradiuspolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerAuthenticationRADIUSPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerAuthenticationRADIUSPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerAuthenticationRADIUSPolicyBinding `json:"vpnvserver_authenticationradiuspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_authenticationsamlidppolicy_binding +func (s *VPNService) AddVPNVServerAuthenticationSAMLIDPPolicyBinding(resource models.VPNVServerAuthenticationSAMLIDPPolicyBinding) error { + payload := map[string]any{"vpnvserver_authenticationsamlidppolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerAuthenticationSAMLIDPPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerAuthenticationSAMLIDPPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", vpnVServerAuthenticationSAMLIDPPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerAuthenticationSAMLIDPPolicyBinding() ([]models.VPNVServerAuthenticationSAMLIDPPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerAuthenticationSAMLIDPPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuthenticationSAMLIDPPolicyBinding `json:"vpnvserver_authenticationsamlidppolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerAuthenticationSAMLIDPPolicyBinding(name string) (*models.VPNVServerAuthenticationSAMLIDPPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerAuthenticationSAMLIDPPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuthenticationSAMLIDPPolicyBinding `json:"vpnvserver_authenticationsamlidppolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_authenticationsamlidppolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerAuthenticationSAMLIDPPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerAuthenticationSAMLIDPPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerAuthenticationSAMLIDPPolicyBinding `json:"vpnvserver_authenticationsamlidppolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_authenticationsamlpolicy_binding +func (s *VPNService) AddVPNVServerAuthenticationSAMLPolicyBinding(resource models.VPNVServerAuthenticationSAMLPolicyBinding) error { + payload := map[string]any{"vpnvserver_authenticationsamlpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerAuthenticationSAMLPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerAuthenticationSAMLPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", vpnVServerAuthenticationSAMLPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerAuthenticationSAMLPolicyBinding() ([]models.VPNVServerAuthenticationSAMLPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerAuthenticationSAMLPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuthenticationSAMLPolicyBinding `json:"vpnvserver_authenticationsamlpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerAuthenticationSAMLPolicyBinding(name string) (*models.VPNVServerAuthenticationSAMLPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerAuthenticationSAMLPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuthenticationSAMLPolicyBinding `json:"vpnvserver_authenticationsamlpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_authenticationsamlpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerAuthenticationSAMLPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerAuthenticationSAMLPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerAuthenticationSAMLPolicyBinding `json:"vpnvserver_authenticationsamlpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_authenticationtacacspolicy_binding +func (s *VPNService) AddVPNVServerAuthenticationTACACSPolicyBinding(resource models.VPNVServerAuthenticationTACACSPolicyBinding) error { + payload := map[string]any{"vpnvserver_authenticationtacacspolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerAuthenticationTACACSPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerAuthenticationTACACSPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", vpnVServerAuthenticationTACACSPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerAuthenticationTACACSPolicyBinding() ([]models.VPNVServerAuthenticationTACACSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerAuthenticationTACACSPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuthenticationTACACSPolicyBinding `json:"vpnvserver_authenticationtacacspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerAuthenticationTACACSPolicyBinding(name string) (*models.VPNVServerAuthenticationTACACSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerAuthenticationTACACSPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuthenticationTACACSPolicyBinding `json:"vpnvserver_authenticationtacacspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_authenticationtacacspolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerAuthenticationTACACSPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerAuthenticationTACACSPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerAuthenticationTACACSPolicyBinding `json:"vpnvserver_authenticationtacacspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_authenticationwebauthpolicy_binding +func (s *VPNService) AddVPNVServerAuthenticationWebAuthPolicyBinding(resource models.VPNVServerAuthenticationWebAuthPolicyBinding) error { + payload := map[string]any{"vpnvserver_authenticationwebauthpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerAuthenticationWebAuthPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerAuthenticationWebAuthPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", vpnVServerAuthenticationWebAuthPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerAuthenticationWebAuthPolicyBinding() ([]models.VPNVServerAuthenticationWebAuthPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerAuthenticationWebAuthPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuthenticationWebAuthPolicyBinding `json:"vpnvserver_authenticationwebauthpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerAuthenticationWebAuthPolicyBinding(name string) (*models.VPNVServerAuthenticationWebAuthPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerAuthenticationWebAuthPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerAuthenticationWebAuthPolicyBinding `json:"vpnvserver_authenticationwebauthpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_authenticationwebauthpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerAuthenticationWebAuthPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerAuthenticationWebAuthPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerAuthenticationWebAuthPolicyBinding `json:"vpnvserver_authenticationwebauthpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_binding +func (s *VPNService) GetAllVPNVServerBinding() ([]models.VPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerBinding `json:"vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerBinding(name string) (*models.VPNVServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerBinding `json:"vpnvserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +// vpnvserver_cachepolicy_binding +func (s *VPNService) AddVPNVServerCachePolicyBinding(resource models.VPNVServerCachePolicyBinding) error { + payload := map[string]any{"vpnvserver_cachepolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerCachePolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerCachePolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", vpnVServerCachePolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerCachePolicyBinding() ([]models.VPNVServerCachePolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerCachePolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerCachePolicyBinding `json:"vpnvserver_cachepolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerCachePolicyBinding(name string) (*models.VPNVServerCachePolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerCachePolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerCachePolicyBinding `json:"vpnvserver_cachepolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_cachepolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerCachePolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerCachePolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerCachePolicyBinding `json:"vpnvserver_cachepolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_cspolicy_binding +func (s *VPNService) AddVPNVServerCSPolicyBinding(resource models.VPNVServerCSPolicyBinding) error { + payload := map[string]any{"vpnvserver_cspolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerCSPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerCSPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", vpnVServerCSPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerCSPolicyBinding() ([]models.VPNVServerCSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerCSPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerCSPolicyBinding `json:"vpnvserver_cspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerCSPolicyBinding(name string) (*models.VPNVServerCSPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerCSPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerCSPolicyBinding `json:"vpnvserver_cspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_cspolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerCSPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerCSPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerCSPolicyBinding `json:"vpnvserver_cspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_feopolicy_binding +func (s *VPNService) AddVPNVServerFEOPolicyBinding(resource models.VPNVServerFEOPolicyBinding) error { + payload := map[string]any{"vpnvserver_feopolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerFEOPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerFEOPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", vpnVServerFEOPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerFEOPolicyBinding() ([]models.VPNVServerFEOPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerFEOPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerFEOPolicyBinding `json:"vpnvserver_feopolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerFEOPolicyBinding(name string) (*models.VPNVServerFEOPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerFEOPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerFEOPolicyBinding `json:"vpnvserver_feopolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_feopolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} +func (s *VPNService) CountVPNVServerFEOPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerFEOPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerFEOPolicyBinding `json:"vpnvserver_feopolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_icapolicy_binding +func (s *VPNService) AddVPNVServerICAPolicyBinding(resource models.VPNVServerICAPolicyBinding) error { + payload := map[string]any{"vpnvserver_icapolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerICAPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerICAPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", vpnVServerICAPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerICAPolicyBinding() ([]models.VPNVServerICAPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerICAPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerICAPolicyBinding `json:"vpnvserver_icapolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerICAPolicyBinding(name string) (*models.VPNVServerICAPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerICAPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerICAPolicyBinding `json:"vpnvserver_icapolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_icapolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerICAPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerICAPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerICAPolicyBinding `json:"vpnvserver_icapolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_intranetip6_binding +func (s *VPNService) AddVPNVServerIntranetIP6Binding(resource models.VPNVServerIntranetIP6Binding) error { + payload := map[string]any{"vpnvserver_intranetip6_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerIntranetIP6BindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerIntranetIP6Binding(name string, intranetip6 string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=intranetip6:%s", vpnVServerIntranetIP6BindingURL, name, intranetip6), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerIntranetIP6Binding() ([]models.VPNVServerIntranetIP6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerIntranetIP6BindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerIntranetIP6Binding `json:"vpnvserver_intranetip6_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerIntranetIP6Binding(name string) (*models.VPNVServerIntranetIP6Binding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerIntranetIP6BindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerIntranetIP6Binding `json:"vpnvserver_intranetip6_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_intranetip6_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerIntranetIP6Binding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerIntranetIP6BindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerIntranetIP6Binding `json:"vpnvserver_intranetip6_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_intranetip_binding +func (s *VPNService) AddVPNVServerIntranetIPBinding(resource models.VPNVServerIntranetIPBinding) error { + payload := map[string]any{"vpnvserver_intranetip_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerIntranetIPBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerIntranetIPBinding(name string, intranetip string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=intranetip:%s", vpnVServerIntranetIPBindingURL, name, intranetip), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerIntranetIPBinding() ([]models.VPNVServerIntranetIPBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerIntranetIPBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerIntranetIPBinding `json:"vpnvserver_intranetip_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerIntranetIPBinding(name string) (*models.VPNVServerIntranetIPBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerIntranetIPBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerIntranetIPBinding `json:"vpnvserver_intranetip_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_intranetip_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerIntranetIPBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerIntranetIPBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerIntranetIPBinding `json:"vpnvserver_intranetip_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_responderpolicy_binding +func (s *VPNService) AddVPNVServerResponderPolicyBinding(resource models.VPNVServerResponderPolicyBinding) error { + payload := map[string]any{"vpnvserver_responderpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerResponderPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerResponderPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", vpnVServerResponderPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerResponderPolicyBinding() ([]models.VPNVServerResponderPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerResponderPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerResponderPolicyBinding `json:"vpnvserver_responderpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerResponderPolicyBinding(name string) (*models.VPNVServerResponderPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerResponderPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerResponderPolicyBinding `json:"vpnvserver_responderpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_responderpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerResponderPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerResponderPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerResponderPolicyBinding `json:"vpnvserver_responderpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_rewritepolicy_binding +func (s *VPNService) AddVPNVServerRewritePolicyBinding(resource models.VPNVServerRewritePolicyBinding) error { + payload := map[string]any{"vpnvserver_rewritepolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerRewritePolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerRewritePolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", vpnVServerRewritePolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerRewritePolicyBinding() ([]models.VPNVServerRewritePolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerRewritePolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerRewritePolicyBinding `json:"vpnvserver_rewritepolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerRewritePolicyBinding(name string) (*models.VPNVServerRewritePolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerRewritePolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerRewritePolicyBinding `json:"vpnvserver_rewritepolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_rewritepolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerRewritePolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerRewritePolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerRewritePolicyBinding `json:"vpnvserver_rewritepolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_sharefileserver_binding +func (s *VPNService) AddVPNVServerShareFileServerBinding(resource models.VPNVServerShareFileServerBinding) error { + payload := map[string]any{"vpnvserver_sharefileserver_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerShareFileServerBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerShareFileServerBinding(name string, sharefile string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=sharefile:%s", vpnVServerShareFileServerBindingURL, name, sharefile), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerShareFileServerBinding() ([]models.VPNVServerShareFileServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerShareFileServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerShareFileServerBinding `json:"vpnvserver_sharefileserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerShareFileServerBinding(name string) (*models.VPNVServerShareFileServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerShareFileServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerShareFileServerBinding `json:"vpnvserver_sharefileserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_sharefileserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerShareFileServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerShareFileServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerShareFileServerBinding `json:"vpnvserver_sharefileserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_staserver_binding +func (s *VPNService) AddVPNVServerSTAServerBinding(resource models.VPNVServerSTAServerBinding) error { + payload := map[string]any{"vpnvserver_staserver_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerSTAServerBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerSTAServerBinding(name string, staserver string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=staserver:%s", vpnVServerSTAServerBindingURL, name, staserver), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerSTAServerBinding() ([]models.VPNVServerSTAServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerSTAServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerSTAServerBinding `json:"vpnvserver_staserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerSTAServerBinding(name string) (*models.VPNVServerSTAServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerSTAServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerSTAServerBinding `json:"vpnvserver_staserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_staserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerSTAServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerSTAServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerSTAServerBinding `json:"vpnvserver_staserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_vpnclientlessaccesspolicy_binding +func (s *VPNService) AddVPNVServerVPNClientlessAccessPolicyBinding(resource models.VPNVServerVPNClientlessAccessPolicyBinding) error { + payload := map[string]any{"vpnvserver_vpnclientlessaccesspolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerVPNClientlessAccessPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerVPNClientlessAccessPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", vpnVServerVPNClientlessAccessPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerVPNClientlessAccessPolicyBinding() ([]models.VPNVServerVPNClientlessAccessPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerVPNClientlessAccessPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerVPNClientlessAccessPolicyBinding `json:"vpnvserver_vpnclientlessaccesspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerVPNClientlessAccessPolicyBinding(name string) (*models.VPNVServerVPNClientlessAccessPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerVPNClientlessAccessPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerVPNClientlessAccessPolicyBinding `json:"vpnvserver_vpnclientlessaccesspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_vpnclientlessaccesspolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerVPNClientlessAccessPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerVPNClientlessAccessPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerVPNClientlessAccessPolicyBinding `json:"vpnvserver_vpnclientlessaccesspolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_vpnepaprofile_binding +func (s *VPNService) AddVPNVServerVPNEPAProfileBinding(resource models.VPNVServerVPNEPAProfileBinding) error { + payload := map[string]any{"vpnvserver_vpnepaprofile_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerVPNEPAProfileBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerVPNEPAProfileBinding(name string, epaprofile string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=epaprofile:%s", vpnVServerVPNEPAProfileBindingURL, name, epaprofile), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerVPNEPAProfileBinding() ([]models.VPNVServerVPNEPAProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerVPNEPAProfileBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerVPNEPAProfileBinding `json:"vpnvserver_vpnepaprofile_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerVPNEPAProfileBinding(name string) (*models.VPNVServerVPNEPAProfileBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerVPNEPAProfileBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerVPNEPAProfileBinding `json:"vpnvserver_vpnepaprofile_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_vpnepaprofile_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerVPNEPAProfileBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerVPNEPAProfileBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerVPNEPAProfileBinding `json:"vpnvserver_vpnepaprofile_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_vpneula_binding +func (s *VPNService) AddVPNVServerVPNEULABinding(resource models.VPNVServerVPNEULABinding) error { + payload := map[string]any{"vpnvserver_vpneula_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerVPNEULABindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerVPNEULABinding(name string, eula string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=eula:%s", vpnVServerVPNEULABindingURL, name, eula), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerVPNEULABinding() ([]models.VPNVServerVPNEULABinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerVPNEULABindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerVPNEULABinding `json:"vpnvserver_vpneula_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerVPNEULABinding(name string) (*models.VPNVServerVPNEULABinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerVPNEULABindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerVPNEULABinding `json:"vpnvserver_vpneula_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_vpneula_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerVPNEULABinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerVPNEULABindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerVPNEULABinding `json:"vpnvserver_vpneula_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_vpnintranetapplication_binding +func (s *VPNService) AddVPNVServerVPNIntranetApplicationBinding(resource models.VPNVServerVPNIntranetApplicationBinding) error { + payload := map[string]any{"vpnvserver_vpnintranetapplication_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerVPNIntranetApplicationBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerVPNIntranetApplicationBinding(name string, intranetapplication string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=intranetapplication:%s", vpnVServerVPNIntranetApplicationBindingURL, name, intranetapplication), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerVPNIntranetApplicationBinding() ([]models.VPNVServerVPNIntranetApplicationBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerVPNIntranetApplicationBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerVPNIntranetApplicationBinding `json:"vpnvserver_vpnintranetapplication_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerVPNIntranetApplicationBinding(name string) (*models.VPNVServerVPNIntranetApplicationBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerVPNIntranetApplicationBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerVPNIntranetApplicationBinding `json:"vpnvserver_vpnintranetapplication_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_vpnintranetapplication_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerVPNIntranetApplicationBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerVPNIntranetApplicationBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerVPNIntranetApplicationBinding `json:"vpnvserver_vpnintranetapplication_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_vpnnexthopserver_binding +func (s *VPNService) AddVPNVServerVPNNextHopServerBinding(resource models.VPNVServerVPNNextHopServerBinding) error { + payload := map[string]any{"vpnvserver_vpnnexthopserver_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerVPNNextHopServerBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerVPNNextHopServerBinding(name string, nexthopserver string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=nexthopserver:%s", vpnVServerVPNNextHopServerBindingURL, name, nexthopserver), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerVPNNextHopServerBinding() ([]models.VPNVServerVPNNextHopServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerVPNNextHopServerBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerVPNNextHopServerBinding `json:"vpnvserver_vpnnexthopserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerVPNNextHopServerBinding(name string) (*models.VPNVServerVPNNextHopServerBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerVPNNextHopServerBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerVPNNextHopServerBinding `json:"vpnvserver_vpnnexthopserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_vpnnexthopserver_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerVPNNextHopServerBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerVPNNextHopServerBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerVPNNextHopServerBinding `json:"vpnvserver_vpnnexthopserver_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_vpnportaltheme_binding +func (s *VPNService) AddVPNVServerVPNPortalThemeBinding(resource models.VPNVServerVPNPortalThemeBinding) error { + payload := map[string]any{"vpnvserver_vpnportaltheme_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerVPNPortalThemeBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerVPNPortalThemeBinding(name string, portaltheme string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=portaltheme:%s", vpnVServerVPNPortalThemeBindingURL, name, portaltheme), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerVPNPortalThemeBinding() ([]models.VPNVServerVPNPortalThemeBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerVPNPortalThemeBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerVPNPortalThemeBinding `json:"vpnvserver_vpnportaltheme_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerVPNPortalThemeBinding(name string) (*models.VPNVServerVPNPortalThemeBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerVPNPortalThemeBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerVPNPortalThemeBinding `json:"vpnvserver_vpnportaltheme_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_vpnportaltheme_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerVPNPortalThemeBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerVPNPortalThemeBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerVPNPortalThemeBinding `json:"vpnvserver_vpnportaltheme_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_vpnsessionpolicy_binding +func (s *VPNService) AddVPNVServerVPNSessionPolicyBinding(resource models.VPNVServerVPNSessionPolicyBinding) error { + payload := map[string]any{"vpnvserver_vpnsessionpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerVPNSessionPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerVPNSessionPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", vpnVServerVPNSessionPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerVPNSessionPolicyBinding() ([]models.VPNVServerVPNSessionPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerVPNSessionPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerVPNSessionPolicyBinding `json:"vpnvserver_vpnsessionpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerVPNSessionPolicyBinding(name string) (*models.VPNVServerVPNSessionPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerVPNSessionPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerVPNSessionPolicyBinding `json:"vpnvserver_vpnsessionpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_vpnsessionpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerVPNSessionPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerVPNSessionPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerVPNSessionPolicyBinding `json:"vpnvserver_vpnsessionpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_vpntrafficpolicy_binding +func (s *VPNService) AddVPNVServerVPNTrafficPolicyBinding(resource models.VPNVServerVPNTrafficPolicyBinding) error { + payload := map[string]any{"vpnvserver_vpntrafficpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerVPNTrafficPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerVPNTrafficPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", vpnVServerVPNTrafficPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerVPNTrafficPolicyBinding() ([]models.VPNVServerVPNTrafficPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerVPNTrafficPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerVPNTrafficPolicyBinding `json:"vpnvserver_vpntrafficpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerVPNTrafficPolicyBinding(name string) (*models.VPNVServerVPNTrafficPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerVPNTrafficPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerVPNTrafficPolicyBinding `json:"vpnvserver_vpntrafficpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_vpntrafficpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerVPNTrafficPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerVPNTrafficPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerVPNTrafficPolicyBinding `json:"vpnvserver_vpntrafficpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_vpnurlpolicy_binding +func (s *VPNService) AddVPNVServerVPNURLPolicyBinding(resource models.VPNVServerVPNURLPolicyBinding) error { + payload := map[string]any{"vpnvserver_vpnurlpolicy_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerVPNURLPolicyBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerVPNURLPolicyBinding(name string, policy string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=policy:%s", vpnVServerVPNURLPolicyBindingURL, name, policy), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerVPNURLPolicyBinding() ([]models.VPNVServerVPNURLPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerVPNURLPolicyBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerVPNURLPolicyBinding `json:"vpnvserver_vpnurlpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerVPNURLPolicyBinding(name string) (*models.VPNVServerVPNURLPolicyBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerVPNURLPolicyBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerVPNURLPolicyBinding `json:"vpnvserver_vpnurlpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_vpnurlpolicy_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerVPNURLPolicyBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerVPNURLPolicyBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerVPNURLPolicyBinding `json:"vpnvserver_vpnurlpolicy_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +} + +// vpnvserver_vpnurl_binding +func (s *VPNService) AddVPNVServerVPNURLBinding(resource models.VPNVServerVPNURLBinding) error { + payload := map[string]any{"vpnvserver_vpnurl_binding": resource} + data, err := json.Marshal(payload) + if err != nil { + return err + } + + req, err := s.client.NewRequest(http.MethodPost, vpnVServerVPNURLBindingURL, bytes.NewReader(data)) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) DeleteVPNVServerVPNURLBinding(name string, urlname string) error { + req, err := s.client.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s?args=urlname:%s", vpnVServerVPNURLBindingURL, name, urlname), nil) + if err != nil { + return err + } + + _, err = s.client.Do(req) + return err +} + +func (s *VPNService) GetAllVPNVServerVPNURLBinding() ([]models.VPNVServerVPNURLBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, vpnVServerVPNURLBindingURL, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerVPNURLBinding `json:"vpnvserver_vpnurl_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + return result.Data, nil +} + +func (s *VPNService) GetVPNVServerVPNURLBinding(name string) (*models.VPNVServerVPNURLBinding, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s/%s", vpnVServerVPNURLBindingURL, name), nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(req) + if err != nil { + return nil, err + } + + var result struct { + Data []models.VPNVServerVPNURLBinding `json:"vpnvserver_vpnurl_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return nil, err + } + + if len(result.Data) == 0 { + return nil, fmt.Errorf("vpnvserver_vpnurl_binding %s not found", name) + } + + return &result.Data[0], nil +} + +func (s *VPNService) CountVPNVServerVPNURLBinding() (int, error) { + req, err := s.client.NewRequest(http.MethodGet, fmt.Sprintf("%s?count=yes", vpnVServerVPNURLBindingURL), nil) + if err != nil { + return 0, err + } + + resp, err := s.client.Do(req) + if err != nil { + return 0, err + } + + var result struct { + Data []models.VPNVServerVPNURLBinding `json:"vpnvserver_vpnurl_binding"` + } + if err := json.Unmarshal(resp, &result); err != nil { + return 0, err + } + + if len(result.Data) == 0 { + return 0, nil + } + + return int(result.Data[0].Count), nil +}