-
Notifications
You must be signed in to change notification settings - Fork 30
feat(vpn): Add wait handlers for VPN gateway creation, update and deletion #7071
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
Open
s-inter
wants to merge
19
commits into
main
Choose a base branch
from
si/vpn-waiter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+608
−2
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
a05a8f6
feat: Add wait handlers for VPN gateway creation, update and deletion
s-inter 806af61
chore: ran sync-tidy
s-inter a67637a
chore: Update VPN service to version 0.7.0
s-inter 3b20f53
Merge branch 'main' into si/vpn-waiter
s-inter 1bd1e22
Revert "chore: Update VPN service to version 0.7.0"
s-inter ac31dc1
Merge remote-tracking branch 'origin/main' into si/vpn-waiter
s-inter e2e933b
feat(vpn): implement gateway wait handlers and corresponding tests fo…
s-inter f1ca97a
feat(vpn): update changelog and version to v0.8.0
s-inter 7f957ff
feat(vpn): add example for VPN Gateway and Connection management
s-inter 69721d5
refactor(vpn): remove default HTTP error status codes in DeleteGatewa…
s-inter 0223925
refactor(vpn): change public interface to separate Create and Update …
s-inter 66e27aa
fix(vpn): fix linter issues
s-inter 1093613
Merge branch 'main' into si/vpn-waiter
s-inter 05ec585
fix(vpn): revert unwanted change
s-inter 2e8ddc4
fix(vpn): examples use go 1.25
s-inter 430e4d6
Merge branch 'main' into si/vpn-waiter
s-inter fa096e3
Merge branch 'main' into si/vpn-waiter
s-inter 0b8069c
fix(vpn): fix changelog message
s-inter c408573
fix(vpn): fix changelog message
s-inter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,16 @@ | ||
| module github.com/stackitcloud/stackit-sdk-go/examples/vpn | ||
|
|
||
| go 1.25 | ||
|
|
||
| // This is not needed in production. This is only here to point the golangci linter to the local version instead of the last release on GitHub. | ||
| replace github.com/stackitcloud/stackit-sdk-go/services/vpn => ../../services/vpn | ||
|
|
||
| require ( | ||
| github.com/stackitcloud/stackit-sdk-go/core v0.26.0 | ||
| github.com/stackitcloud/stackit-sdk-go/services/vpn v0.8.0 | ||
| ) | ||
|
|
||
| require ( | ||
| github.com/golang-jwt/jwt/v5 v5.3.1 // indirect | ||
| github.com/google/uuid v1.6.0 // indirect | ||
| ) |
This file contains hidden or 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,8 @@ | ||
| github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY= | ||
| github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE= | ||
| github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= | ||
| github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= | ||
| github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= | ||
| github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||
| github.com/stackitcloud/stackit-sdk-go/core v0.26.0 h1:jQEb9gkehfp6VCP6TcYk7BI10cz4l0KM2L6hqYBH2QA= | ||
| github.com/stackitcloud/stackit-sdk-go/core v0.26.0/go.mod h1:WU1hhxnjXw2EV7CYa1nlEvNpMiRY6CvmIOaHuL3pOaA= |
This file contains hidden or 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,97 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "os" | ||
|
|
||
| "github.com/stackitcloud/stackit-sdk-go/core/config" | ||
| vpn "github.com/stackitcloud/stackit-sdk-go/services/vpn/v1api" | ||
| ) | ||
|
|
||
| func main() { | ||
| region := "eu01" // Region where the resources will be created | ||
| projectId := "PROJECT_ID" // the uuid of your STACKIT project | ||
| planId := "PLAN_ID" // the id of the plan you want to use for the VPN Gateway. You can get the available plans with `ListPlans`. | ||
|
|
||
| // STACKIT VPN enforces the following requirements for a secure PSK: | ||
| // - must be at least 20 characters long | ||
| // - must be at least 16 different characters | ||
| // - must have at least one upper case letter | ||
| // - must have at least one lower case letter | ||
| // - must have at least one number | ||
| psk := "Super.$ecret_Shared3Key12345" | ||
|
|
||
| // Create a new API client, that uses default authentication and configuration | ||
| vpnClient, err := vpn.NewAPIClient( | ||
| config.WithRegion(region), | ||
| ) | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Creating API client: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| // Create a VPN Gateway | ||
| createVpnGatewayPayload := vpn.CreateGatewayPayload{ | ||
| DisplayName: "exampleVpnGateway", | ||
| PlanId: planId, | ||
| RoutingType: vpn.ROUTINGTYPE_ROUTE_BASED, | ||
| AvailabilityZones: vpn.CreateGatewayPayloadAvailabilityZones{ | ||
| Tunnel1: "eu01-1", | ||
| Tunnel2: "eu01-2", | ||
| }, | ||
| } | ||
|
|
||
| gatewayResp, err := vpnClient.DefaultAPI.CreateGateway(context.Background(), projectId, vpn.Region(region)).CreateGatewayPayload(createVpnGatewayPayload).Execute() | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error when calling `CreateVpnGateway`: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
| fmt.Printf("Created VPN Gateway with id \"%s\".\n", *gatewayResp.Id) | ||
|
|
||
| // Create a VPN Connection | ||
| phase1 := vpn.TunnelConfigurationPhase1{ | ||
| DhGroups: []string{"ecp384"}, | ||
| EncryptionAlgorithms: []string{"aes256"}, | ||
| IntegrityAlgorithms: []string{"sha2_384"}, | ||
| } | ||
| phase2 := vpn.TunnelConfigurationPhase2{ | ||
| DhGroups: []string{"ecp384"}, | ||
| EncryptionAlgorithms: []string{"aes256"}, | ||
| IntegrityAlgorithms: []string{"sha2_384"}, | ||
| } | ||
| tunnel := vpn.TunnelConfiguration{ | ||
| Phase1: phase1, | ||
| Phase2: phase2, | ||
| PreSharedKey: &psk, | ||
| RemoteAddress: "0.0.0.0", | ||
| } | ||
|
|
||
| createGatewayConnectionPayload := vpn.CreateGatewayConnectionPayload{ | ||
| DisplayName: "exampleVpnConnection", | ||
| Tunnel1: tunnel, | ||
| Tunnel2: tunnel, | ||
| } | ||
| connectionResp, err := vpnClient.DefaultAPI.CreateGatewayConnection(context.Background(), projectId, vpn.Region(region), *gatewayResp.Id).CreateGatewayConnectionPayload(createGatewayConnectionPayload).Execute() | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error when calling `CreateVpnConnection`: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
| fmt.Printf("Created VPN Connection with id \"%s\".\n", *connectionResp.Id) | ||
|
|
||
| // Delete the VPN Connection | ||
| err = vpnClient.DefaultAPI.DeleteGatewayConnection(context.Background(), projectId, vpn.Region(region), *gatewayResp.Id, *connectionResp.Id).Execute() | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error when calling `DeleteVpnConnection`: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
| fmt.Printf("Deleted VPN Connection with id \"%s\".\n", *connectionResp.Id) | ||
|
|
||
| // Delete the VPN Gateway | ||
| err = vpnClient.DefaultAPI.DeleteGateway(context.Background(), projectId, vpn.Region(region), *gatewayResp.Id).Execute() | ||
| if err != nil { | ||
| fmt.Fprintf(os.Stderr, "Error when calling `DeleteVpnGateway`: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
| fmt.Printf("Deleted VPN Gateway with id \"%s\".\n", *gatewayResp.Id) | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 +1 @@ | ||
| v0.7.0 | ||
| v0.8.0 |
This file contains hidden or 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 hidden or 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,59 @@ | ||
| package wait | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "time" | ||
|
|
||
| "github.com/stackitcloud/stackit-sdk-go/core/wait" | ||
| vpn "github.com/stackitcloud/stackit-sdk-go/services/vpn/v1api" | ||
| ) | ||
|
|
||
| func createOrUpdateGatewayWaitHandler(ctx context.Context, a vpn.DefaultAPI, projectId string, region vpn.Region, gatewayId string) *wait.AsyncActionHandler[vpn.GatewayResponse] { | ||
| waitConfig := wait.WaiterHelper[vpn.GatewayResponse, vpn.GatewayStatus]{ | ||
| FetchInstance: a.GetGateway(ctx, projectId, region, gatewayId).Execute, | ||
| GetState: func(resp *vpn.GatewayResponse) (vpn.GatewayStatus, error) { | ||
| if resp == nil { | ||
| return "", errors.New("could not get gateway status: response is nil") | ||
| } | ||
| if resp.State == nil { | ||
| return "", errors.New("could not get gateway status: state is nil") | ||
| } | ||
| return *resp.State, nil | ||
| }, | ||
| ActiveState: []vpn.GatewayStatus{vpn.GATEWAYSTATUS_READY}, | ||
| ErrorState: []vpn.GatewayStatus{vpn.GATEWAYSTATUS_ERROR, vpn.GATEWAYSTATUS_DELETING}, | ||
| } | ||
|
|
||
| handler := wait.New(waitConfig.Wait()) | ||
| handler.SetTimeout(45 * time.Minute) | ||
| return handler | ||
| } | ||
|
|
||
| func CreateGatewayWaitHandler(ctx context.Context, a vpn.DefaultAPI, projectId string, region vpn.Region, gatewayId string) *wait.AsyncActionHandler[vpn.GatewayResponse] { | ||
| return createOrUpdateGatewayWaitHandler(ctx, a, projectId, region, gatewayId) | ||
| } | ||
|
|
||
| func UpdateGatewayWaitHandler(ctx context.Context, a vpn.DefaultAPI, projectId string, region vpn.Region, gatewayId string) *wait.AsyncActionHandler[vpn.GatewayResponse] { | ||
| return createOrUpdateGatewayWaitHandler(ctx, a, projectId, region, gatewayId) | ||
| } | ||
|
|
||
| func DeleteGatewayWaitHandler(ctx context.Context, a vpn.DefaultAPI, projectId string, region vpn.Region, gatewayId string) *wait.AsyncActionHandler[vpn.GatewayResponse] { | ||
| waitConfig := wait.WaiterHelper[vpn.GatewayResponse, vpn.GatewayStatus]{ | ||
| FetchInstance: a.GetGateway(ctx, projectId, region, gatewayId).Execute, | ||
| GetState: func(resp *vpn.GatewayResponse) (vpn.GatewayStatus, error) { | ||
| if resp == nil { | ||
| return "", errors.New("could not get gateway status: response is nil") | ||
| } | ||
| if resp.State == nil { | ||
| return "", errors.New("could not get gateway status: state is nil") | ||
| } | ||
| return *resp.State, nil | ||
| }, | ||
| ErrorState: []vpn.GatewayStatus{vpn.GATEWAYSTATUS_ERROR}, | ||
| } | ||
|
|
||
| handler := wait.New(waitConfig.Wait()) | ||
| handler.SetTimeout(20 * time.Minute) | ||
| return handler | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.