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

V20 #357

Merged
merged 7 commits into from
Apr 25, 2024
Merged

V20 #357

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
8 changes: 4 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ jobs:
steps:

- name: Set up Go 1.x
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: ^1.20
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Get dependencies
run: |
Expand All @@ -38,14 +38,14 @@ jobs:
name: "Static analysis"
runs-on: "ubuntu-latest"
steps:
- uses: WillAbides/setup-go-faster@v1.7.0
- uses: WillAbides/setup-go-faster@v1.14.0
with:
go-version: "1.20.x"
- run: "GO111MODULE=on go install honnef.co/go/tools/cmd/staticcheck@2023.1.2"
- uses: actions/checkout@v1
with:
fetch-depth: 1
- uses: actions/cache@v2
- uses: actions/cache@v4
with:
path: ~/.cache/staticcheck
key: staticcheck-${{ github.sha }}
Expand Down
14 changes: 6 additions & 8 deletions appgate/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"sync"
"time"

"github.com/appgate/sdp-api-client-go/api/v19/openapi"
"github.com/appgate/sdp-api-client-go/api/v20/openapi"
"github.com/cenkalti/backoff/v4"
"github.com/hashicorp/go-version"
"golang.org/x/net/http/httpproxy"
Expand Down Expand Up @@ -185,6 +185,8 @@ func guessVersion(clientVersion int) (*version.Version, error) {
return version.NewVersion("6.1.0+estimated")
case Version19:
return version.NewVersion("6.2.0+estimated")
case Version20:
return version.NewVersion("6.3.0+estimated")
}
return nil, fmt.Errorf("could not determine appliance version with client version %d", clientVersion)
}
Expand Down Expand Up @@ -283,13 +285,9 @@ func (c *Client) login(ctx context.Context) (*openapi.LoginResponse, error) {
err := backoff.Retry(func() error {
login, response, err := c.API.LoginApi.LoginPost(ctx).LoginRequest(loginOpts).Execute()
if response == nil {
if err != nil {
if err, ok := err.(*url.Error); ok {
if err, ok := err.Unwrap().(x509.UnknownAuthorityError); ok {
return &backoff.PermanentError{
Err: fmt.Errorf("Import certificate or toggle APPGATE_INSECURE - %s", err),
}
}
if err != nil && errors.As(err, &x509.UnknownAuthorityError{}) {
return &backoff.PermanentError{
Err: fmt.Errorf("Import certificate or toggle APPGATE_INSECURE - %s", err),
}
}
log.Printf("[DEBUG] Login failed, No response %s", err)
Expand Down
2 changes: 1 addition & 1 deletion appgate/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"testing"
"time"

"github.com/appgate/sdp-api-client-go/api/v19/openapi"
"github.com/appgate/sdp-api-client-go/api/v20/openapi"
"github.com/google/uuid"
"github.com/hashicorp/go-version"
)
Expand Down
6 changes: 1 addition & 5 deletions appgate/data_source_appgate_appliance_seed.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"log"
"net/http"

"github.com/appgate/sdp-api-client-go/api/v19/openapi"
"github.com/appgate/sdp-api-client-go/api/v20/openapi"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down Expand Up @@ -112,10 +112,6 @@ func dataSourceAppgateApplianceSeedRead(d *schema.ResourceData, meta interface{}
sshConfig.ProvideCloudSSHKey = openapi.PtrBool(cloudKey.(bool))
d.Set("provide_cloud_ssh_key", true)
}
if _, lvOk := d.GetOk("latest_version"); lvOk {
exportRequest = exportRequest.LatestVersion(true)
d.Set("latest_version", true)
}
exportRequest = exportRequest.SSHConfig(*sshConfig)
seedmap, _, err := exportRequest.Authorization(token).Execute()
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion appgate/data_source_appgate_appliance_seed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func TestAccAppgateApplianceSeedDataSource(t *testing.T) {
},
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "appliance_id", resourceName, "id"),
resource.TestCheckResourceAttrSet("data.appgatesdp_appliance_seed.test_gateway_seed_file", "latest_version"),
resource.TestCheckResourceAttrSet("data.appgatesdp_appliance_seed.test_gateway_seed_file", "password"),
resource.TestCheckResourceAttrSet("data.appgatesdp_appliance_seed.test_gateway_seed_file", "seed_file"),
),
Expand Down
2 changes: 1 addition & 1 deletion appgate/data_source_appgate_certificate_authority.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"log"

"github.com/appgate/sdp-api-client-go/api/v19/openapi"
"github.com/appgate/sdp-api-client-go/api/v20/openapi"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down
8 changes: 1 addition & 7 deletions appgate/data_source_appgate_global_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

"github.com/appgate/sdp-api-client-go/api/v19/openapi"
"github.com/appgate/sdp-api-client-go/api/v20/openapi"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down Expand Up @@ -53,11 +53,6 @@ func dataSourceGlobalSettings() *schema.Resource {
Deprecated: "Whether there is a backup passphrase set or not. Deprecated as of 5.0. Use backupApiEnabled instead.",
Computed: true,
},
"fips": {
Type: schema.TypeBool,
Description: "FIPS 140-2 Compliant Tunneling.",
Computed: true,
},
"geo_ip_updates": {
Type: schema.TypeBool,
Description: "Whether the automatic GeoIp updates are enabled or not.",
Expand Down Expand Up @@ -102,7 +97,6 @@ func dataSourceAppgateGlobalSettingsRead(d *schema.ResourceData, meta interface{
d.Set("login_banner_message", settings.GetLoginBannerMessage())
d.Set("message_of_the_day", settings.GetMessageOfTheDay())
d.Set("backup_api_enabled", settings.GetBackupApiEnabled())
d.Set("fips", settings.GetFips())
d.Set("geo_ip_updates", settings.GetGeoIpUpdates())
d.Set("audit_log_persistence_mode", settings.GetAuditLogPersistenceMode())
d.Set("app_discovery_domains", settings.GetAppDiscoveryDomains())
Expand Down
1 change: 0 additions & 1 deletion appgate/data_source_appgate_global_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func TestAccAppgateGlobalSettingsDataSource(t *testing.T) {

resource.TestCheckResourceAttrSet("data.appgatesdp_global_settings.test", "backup_api_enabled"),

resource.TestCheckResourceAttrSet("data.appgatesdp_global_settings.test", "fips"),
resource.TestCheckResourceAttrSet("data.appgatesdp_global_settings.test", "geo_ip_updates"),
resource.TestCheckResourceAttrSet("data.appgatesdp_global_settings.test", "audit_log_persistence_mode"),

Expand Down
2 changes: 1 addition & 1 deletion appgate/data_source_appgate_identity_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"log"

"github.com/appgate/sdp-api-client-go/api/v19/openapi"
"github.com/appgate/sdp-api-client-go/api/v20/openapi"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down
64 changes: 59 additions & 5 deletions appgate/find_resource_by_name.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 4 additions & 28 deletions appgate/identity_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"
"log"

"github.com/appgate/sdp-api-client-go/api/v19/openapi"
"github.com/appgate/sdp-api-client-go/api/v20/openapi"
"github.com/appgate/terraform-provider-appgatesdp/appgate/hashcode"

"github.com/hashicorp/go-version"
Expand Down Expand Up @@ -453,7 +453,7 @@ func readProviderFromConfig(d *schema.ResourceData, provider openapi.Configurabl
}

if v, ok := d.GetOk("on_boarding_two_factor"); ok {
onboarding, err := readOnBoardingTwoFactorFromConfig(v.([]interface{}), currentVersion)
onboarding, err := readOnBoardingTwoFactorFromConfig(v.([]interface{}))
if err != nil {
return &provider, err
}
Expand Down Expand Up @@ -511,7 +511,7 @@ func readProviderFromConfig(d *schema.ResourceData, provider openapi.Configurabl
return &provider, nil
}

func readOnBoardingTwoFactorFromConfig(input []interface{}, currentVersion *version.Version) (openapi.ConfigurableIdentityProviderAllOfOnBoarding2FA, error) {
func readOnBoardingTwoFactorFromConfig(input []interface{}) (openapi.ConfigurableIdentityProviderAllOfOnBoarding2FA, error) {
onboarding := openapi.ConfigurableIdentityProviderAllOfOnBoarding2FA{}
for _, r := range input {
raw := r.(map[string]interface{})
Expand All @@ -521,24 +521,6 @@ func readOnBoardingTwoFactorFromConfig(input []interface{}, currentVersion *vers
if v, ok := raw["message"]; ok {
onboarding.SetMessage(v.(string))
}
if v, ok := raw["device_limit_per_user"]; ok {
val := int32(v.(int))
log.Printf("[DEBUG] on_boarding_two_factor.device_limit_per_user only available in version 5.4 or less got %v - %v", val, currentVersion.LessThan(Appliance55Version))
if currentVersion.LessThan(Appliance55Version) && val > 0 {
onboarding.SetDeviceLimitPerUser(val)
} else if val > 0 {
// device_limit_per_user is not allowed in 5.5
return onboarding, fmt.Errorf(
"on_boarding_two_factor.device_limit_per_user is deprecated in %s. Use root level field instead. Got %d",
currentVersion.String(),
val,
)
} else {
// else omit devicelmit per user from the request.
log.Printf("[DEBUG] on_boarding_two_factor.device_limit_per_user is not allowed on %s, omitted it from request, use root level instead", currentVersion.String())
onboarding.DeviceLimitPerUser = nil
}
}

if v, ok := raw["claim_suffix"]; ok {
onboarding.SetClaimSuffix(v.(string))
Expand Down Expand Up @@ -667,20 +649,14 @@ func flattenIdentityProviderOnDemandClaimsMappning(claims []openapi.OnDemandClai
return schema.NewSet(resourceIdentityProviderOnDemandClaimMappingsHash, out)
}

func flattenIdentityProviderOnboarding2fa(input openapi.ConfigurableIdentityProviderAllOfOnBoarding2FA, currentVersion *version.Version) []interface{} {
func flattenIdentityProviderOnboarding2fa(input openapi.ConfigurableIdentityProviderAllOfOnBoarding2FA) []interface{} {
o := make(map[string]interface{})
if v, ok := input.GetMfaProviderIdOk(); ok {
o["mfa_provider_id"] = v
}
if v, ok := input.GetMessageOk(); ok {
o["message"] = v
}
// we will only save device_limit_per_user in the statefile if the currentversion still supports it.
if currentVersion.LessThan(Appliance55Version) {
if v, ok := input.GetDeviceLimitPerUserOk(); ok {
o["device_limit_per_user"] = int(*v)
}
}
if v, ok := input.GetClaimSuffixOk(); ok {
o["claim_suffix"] = v
}
Expand Down
12 changes: 7 additions & 5 deletions appgate/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ const (
Version17 int = 17
Version18 int = 18
Version19 int = 19
Version20 int = 20
// DefaultClientVersion is the latest support version of appgate sdp client that is supported.
// its not recommended to change this value.
DefaultClientVersion = Version18
MinimumSupportedVersion = Version16
DefaultClientVersion = Version20
MinimumSupportedVersion = Version18
)

var (
Expand All @@ -44,6 +45,7 @@ var (
Version17: "6.0.0",
Version18: "6.1.0",
Version19: "6.2.0",
Version20: "6.3.0",
}

Appliance53Version, _ = version.NewVersion(ApplianceVersionMap[Version14])
Expand All @@ -52,6 +54,7 @@ var (
Appliance60Version, _ = version.NewVersion(ApplianceVersionMap[Version17])
Appliance61Version, _ = version.NewVersion(ApplianceVersionMap[Version18])
Appliance62Version, _ = version.NewVersion(ApplianceVersionMap[Version19])
Appliance63Version, _ = version.NewVersion(ApplianceVersionMap[Version20])
)

// Provider function returns the object that implements the terraform.ResourceProvider interface, specifically a schema.Provider
Expand Down Expand Up @@ -192,7 +195,6 @@ func Provider() *schema.Provider {
"appgatesdp_local_user": resourceAppgateLocalUser(),
"appgatesdp_license": resourceAppgateLicense(),
"appgatesdp_admin_mfa_settings": resourceAdminMfaSettings(),
"appgatesdp_client_connections": resourceClientConnections(),
"appgatesdp_blacklist_user": resourceAppgateBlacklistUser(),
"appgatesdp_radius_identity_provider": resourceAppgateRadiusProvider(),
"appgatesdp_oidc_identity_provider": resourceAppgateOidcProvider(),
Expand All @@ -206,12 +208,12 @@ func Provider() *schema.Provider {
}

provider.ConfigureContextFunc = func(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
return providerConfigure(ctx, d, provider.UserAgent("appgatesdp", pkgversion.ProviderVersion))
return providerConfigure(d, provider.UserAgent("appgatesdp", pkgversion.ProviderVersion))
}
return provider
}

func providerConfigure(ctx context.Context, d *schema.ResourceData, ua string) (interface{}, diag.Diagnostics) {
func providerConfigure(d *schema.ResourceData, ua string) (interface{}, diag.Diagnostics) {
// Warning or errors can be collected in a slice type
var diags diag.Diagnostics
config := Config{
Expand Down
Loading
Loading