generated from hashicorp/packer-plugin-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for
http_interface
Adds support for `http_interface` and `http_bind_address`. Signed-off-by: Ryan Johnson <[email protected]>
- Loading branch information
1 parent
8e5830a
commit bca604f
Showing
10 changed files
with
272 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package common | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
) | ||
|
||
// DefaultHttpBindAddress defines the default IP address for the HTTP server. | ||
const DefaultHttpBindAddress = "0.0.0.0" | ||
|
||
// ValidateHTTPAddress validates if the provided HTTP address is valid and | ||
// assigned to an interface. | ||
func ValidateHTTPAddress(httpAddress string) error { | ||
if httpAddress == "" { | ||
return fmt.Errorf("address cannot be empty") | ||
} | ||
if httpAddress == DefaultHttpBindAddress { | ||
return fmt.Errorf("default bind address %s is not allowed", DefaultHttpBindAddress) | ||
} | ||
if net.ParseIP(httpAddress) == nil { | ||
return fmt.Errorf("invalid IP address format: %s", httpAddress) | ||
} | ||
if !IsIPInInterfaces(httpAddress) { | ||
return fmt.Errorf("%s is not assigned to an interface", httpAddress) | ||
} | ||
return nil | ||
} | ||
|
||
// IsIPInInterfaces checks if the provided IP address is assigned to any | ||
// interface in the system. | ||
func IsIPInInterfaces(ipStr string) bool { | ||
interfaces, err := net.Interfaces() | ||
if err != nil { | ||
return false | ||
} | ||
|
||
for _, i := range interfaces { | ||
addrs, err := i.Addrs() | ||
if err != nil { | ||
continue | ||
} | ||
|
||
for _, addr := range addrs { | ||
var ip net.IP | ||
switch v := addr.(type) { | ||
case *net.IPNet: | ||
ip = v.IP | ||
case *net.IPAddr: | ||
ip = v.IP | ||
} | ||
|
||
parsedIP := net.ParseIP(ipStr) | ||
if ip.Equal(parsedIP) { | ||
return true | ||
} | ||
} | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
docs-partials/builder/vsphere/common/BootConfig-not-required.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
<!-- Code generated from the comments of the BootConfig struct in builder/vsphere/common/step_boot_command.go; DO NOT EDIT MANUALLY --> | ||
|
||
- `http_ip` (string) - The IP address to use for the HTTP server started to serve the `http_directory`. | ||
If unset, Packer will automatically discover and assign an IP. | ||
- `http_ip` (string) - The IP address to use for the HTTP server to serve the `http_directory`. | ||
|
||
<!-- End of code generated from the comments of the BootConfig struct in builder/vsphere/common/step_boot_command.go; --> |
Oops, something went wrong.