## Description
<!-- **Please link some issue here describing what you are trying to achieve.**
In case there is no issue present for your PR, please consider creating one.
At least please give us some description what you are trying to achieve and why your change is needed. -->
relates to #1234
## Checklist
- [ ] Issue was linked above
- [ ] Code format was applied: `make fmt`
- [ ] Examples were added / adjusted (see `examples/` directory)
- [x] Docs are up-to-date: `make generate-docs` (will be checked by CI)
- [ ] Unit tests got implemented or updated
- [ ] Acceptance tests got implemented or updated (see e.g. [here](f5f99d1709/stackit/internal/services/dns/dns_acc_test.go))
- [x] Unit tests are passing: `make test` (will be checked by CI)
- [x] No linter issues: `make lint` (will be checked by CI)
Reviewed-on: #4
Reviewed-by: Andre_Harms <andre.harms@stackit.cloud>
Co-authored-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
Co-committed-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
138 lines
6.2 KiB
Go
138 lines
6.2 KiB
Go
/*
|
|
STACKIT IaaS API
|
|
|
|
This API allows you to create and modify IaaS resources.
|
|
|
|
API version: 2beta1
|
|
*/
|
|
|
|
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
|
|
|
|
package iaasbeta
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"regexp"
|
|
)
|
|
|
|
// AllowedAddressesInner - struct for AllowedAddressesInner
|
|
type AllowedAddressesInner struct {
|
|
String *string
|
|
}
|
|
|
|
// stringAsAllowedAddressesInner is a convenience function that returns string wrapped in AllowedAddressesInner
|
|
func StringAsAllowedAddressesInner(v *string) AllowedAddressesInner {
|
|
return AllowedAddressesInner{
|
|
String: v,
|
|
}
|
|
}
|
|
|
|
// Unmarshal JSON data into one of the pointers in the struct
|
|
func (dst *AllowedAddressesInner) UnmarshalJSON(data []byte) error {
|
|
var err error
|
|
match := 0
|
|
// Workaround until upstream issue is fixed:
|
|
// https://github.com/OpenAPITools/openapi-generator/issues/21751
|
|
// Tracking issue on our side: https://jira.schwarz/browse/STACKITSDK-226
|
|
// try to unmarshal data into String
|
|
dstAllowedAddressesInner1 := &AllowedAddressesInner{}
|
|
err = json.Unmarshal(data, &dstAllowedAddressesInner1.String)
|
|
if err == nil {
|
|
jsonString, _ := json.Marshal(&dstAllowedAddressesInner1.String)
|
|
regex := `/((^\\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\\s*$)|(^\\s*((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*$))/`
|
|
regex = regexp.MustCompile("^\\/|\\/$").ReplaceAllString(regex, "$1") // Remove beginning slash and ending slash
|
|
regex = regexp.MustCompile("\\\\(.)").ReplaceAllString(regex, "$1") // Remove duplicate escaping char for dots
|
|
rawString := regexp.MustCompile(`^"|"$`).ReplaceAllString(*dstAllowedAddressesInner1.String, "$1") // Remove quotes
|
|
isMatched, _ := regexp.MatchString(regex, rawString)
|
|
if string(jsonString) != "{}" && isMatched { // empty struct
|
|
dst.String = dstAllowedAddressesInner1.String
|
|
match++
|
|
}
|
|
}
|
|
|
|
// try to unmarshal data into String
|
|
dstAllowedAddressesInner2 := &AllowedAddressesInner{}
|
|
err = json.Unmarshal(data, &dstAllowedAddressesInner2.String)
|
|
if err == nil {
|
|
jsonString, _ := json.Marshal(&dstAllowedAddressesInner2.String)
|
|
regex := `/^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\/(3[0-2]|2[0-9]|1[0-9]|[0-9]))$|^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))(\/((1(1[0-9]|2[0-8]))|([0-9][0-9])|([0-9])))?$/`
|
|
regex = regexp.MustCompile("^\\/|\\/$").ReplaceAllString(regex, "$1") // Remove beginning slash and ending slash
|
|
regex = regexp.MustCompile("\\\\(.)").ReplaceAllString(regex, "$1") // Remove duplicate escaping char for dots
|
|
rawString := regexp.MustCompile(`^"|"$`).ReplaceAllString(*dstAllowedAddressesInner2.String, "$1") // Remove quotes
|
|
isMatched, _ := regexp.MatchString(regex, rawString)
|
|
if string(jsonString) != "{}" && isMatched { // empty struct
|
|
dst.String = dstAllowedAddressesInner2.String
|
|
match++
|
|
}
|
|
}
|
|
|
|
if match > 1 { // more than 1 match
|
|
// reset to nil
|
|
dst.String = nil
|
|
|
|
return fmt.Errorf("data matches more than one schema in oneOf(AllowedAddressesInner)")
|
|
} else if match == 1 {
|
|
return nil // exactly one match
|
|
} else { // no match
|
|
return fmt.Errorf("data failed to match schemas in oneOf(AllowedAddressesInner)")
|
|
}
|
|
}
|
|
|
|
// Marshal data from the first non-nil pointers in the struct to JSON
|
|
func (src AllowedAddressesInner) MarshalJSON() ([]byte, error) {
|
|
if src.String != nil {
|
|
return json.Marshal(&src.String)
|
|
}
|
|
|
|
return []byte("{}"), nil // no data in oneOf schemas => empty JSON object
|
|
}
|
|
|
|
// Get the actual instance
|
|
func (obj *AllowedAddressesInner) GetActualInstance() interface{} {
|
|
if obj == nil {
|
|
return nil
|
|
}
|
|
if obj.String != nil {
|
|
return obj.String
|
|
}
|
|
|
|
// all schemas are nil
|
|
return nil
|
|
}
|
|
|
|
type NullableAllowedAddressesInner struct {
|
|
value *AllowedAddressesInner
|
|
isSet bool
|
|
}
|
|
|
|
func (v NullableAllowedAddressesInner) Get() *AllowedAddressesInner {
|
|
return v.value
|
|
}
|
|
|
|
func (v *NullableAllowedAddressesInner) Set(val *AllowedAddressesInner) {
|
|
v.value = val
|
|
v.isSet = true
|
|
}
|
|
|
|
func (v NullableAllowedAddressesInner) IsSet() bool {
|
|
return v.isSet
|
|
}
|
|
|
|
func (v *NullableAllowedAddressesInner) Unset() {
|
|
v.value = nil
|
|
v.isSet = false
|
|
}
|
|
|
|
func NewNullableAllowedAddressesInner(val *AllowedAddressesInner) *NullableAllowedAddressesInner {
|
|
return &NullableAllowedAddressesInner{value: val, isSet: true}
|
|
}
|
|
|
|
func (v NullableAllowedAddressesInner) MarshalJSON() ([]byte, error) {
|
|
return json.Marshal(v.value)
|
|
}
|
|
|
|
func (v *NullableAllowedAddressesInner) UnmarshalJSON(src []byte) error {
|
|
v.isSet = true
|
|
return json.Unmarshal(src, &v.value)
|
|
}
|