Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[openapi2kong] Fix server port parsing #105

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions openapi2kong/oas3_testfiles/04a-servers-upstream.expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"_format_version": "3.0",
"services": [
{
"host": "server2.com",
"id": "0907c4ab-d9e4-5d21-813b-c57a97eeaad9",
"name": "simple-api-overview",
"path": "/",
"plugins": [],
"port": 65000,
"protocol": "https",
"routes": [
{
"id": "eee036de-517e-59cf-a2e0-17b3adfa31b5",
"methods": [
"GET"
],
"name": "simple-api-overview_opsid",
"paths": [
"~/$"
],
"plugins": [],
"regex_priority": 200,
"strip_path": false,
"tags": [
"OAS3_import",
"OAS3file_04a-servers-upstream.yaml"
]
}
],
"tags": [
"OAS3_import",
"OAS3file_04a-servers-upstream.yaml"
]
}
],
"upstreams": []
}
17 changes: 17 additions & 0 deletions openapi2kong/oas3_testfiles/04a-servers-upstream.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# properly parses ports, see issue #104
# https://github.com/Kong/go-apiops/issues/104
openapi: '3.0.0'
info:
title: Simple API overview
version: v2
servers:
- url: https://server2.com:65000/
paths:
/:
get:
operationId: OpsId
summary: List API versions
responses:
'200':
description: |-
200 response
6 changes: 5 additions & 1 deletion openapi2kong/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,11 @@ func CreateKongService(
if service["port"] == nil {
if targets[0].Port() != "" {
// port is provided, so parse it
service["port"], _ = strconv.ParseInt(targets[0].Port(), 10, 16)
parsedPort, err := strconv.ParseUint(targets[0].Port(), 10, 16)
if err != nil {
return nil, nil, err
}
service["port"] = parsedPort
} else {
// no port provided, so set it based on scheme, where https/443 is the default
if scheme != httpScheme {
Expand Down