Skip to content

Commit

Permalink
Merge pull request #363 from appgate/v21-api-update
Browse files Browse the repository at this point in the history
V21-api-update
  • Loading branch information
kajes authored Oct 10, 2024
2 parents da5efee + f573b77 commit 477bf46
Show file tree
Hide file tree
Showing 53 changed files with 274 additions and 798 deletions.
14 changes: 3 additions & 11 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/v20/openapi"
"github.com/appgate/sdp-api-client-go/api/v21/openapi"
"github.com/cenkalti/backoff/v4"
"github.com/hashicorp/go-version"
"golang.org/x/net/http/httpproxy"
Expand Down Expand Up @@ -171,22 +171,14 @@ func guessVersion(clientVersion int) (*version.Version, error) {
// TODO query GET /appliance controller and check exact version.
// POST /login does not include version anymore.
switch clientVersion {
case Version13:
return version.NewVersion("5.2.0+estimated")
case Version14:
return version.NewVersion("5.3.0+estimated")
case Version15:
return version.NewVersion("5.4.0+estimated")
case Version16:
return version.NewVersion("5.5.0+estimated")
case Version17:
return version.NewVersion("6.0.0+estimated")
case Version18:
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")
case Version21:
return version.NewVersion("6.4.0+estimated")
}
return nil, fmt.Errorf("could not determine appliance version with client version %d", clientVersion)
}
Expand Down
55 changes: 28 additions & 27 deletions 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/v20/openapi"
"github.com/appgate/sdp-api-client-go/api/v21/openapi"
"github.com/google/uuid"
"github.com/hashicorp/go-version"
)
Expand Down Expand Up @@ -144,9 +144,10 @@ func TestLoginNotAcceptable(t *testing.T) {
}

var (
computed54TestVersion, _ = version.NewVersion("5.4.0+estimated")
computed61TestVersion, _ = version.NewVersion("6.1.0+estimated")
computed64TestVersion, _ = version.NewVersion("6.4.0+estimated")

loginResponse54 = `
loginResponse61 = `
{
"user": {
"name": "admin",
Expand All @@ -173,8 +174,8 @@ var (
{
"id": "string",
"message": "string",
"minSupportedVersion": 7,
"maxSupportedVersion": 15
"minSupportedVersion": 18,
"maxSupportedVersion": 21
}
`
)
Expand All @@ -195,16 +196,16 @@ func TestClient(t *testing.T) {
wantInsecure bool
}{
{
name: "test 5.4 login",
name: "test 6.1 login",
fields: fields{
ResponseBody: loginResponse54,
ResponseBody: loginResponse61,
},
wantErr: false,
expectedVersion: computed54TestVersion,
expectedVersion: computed64TestVersion,
config: &Config{
Username: "admin",
Password: "admin",
Version: 15,
Version: 18,
LoginTimeout: 1,
Insecure: true,
},
Expand All @@ -214,10 +215,10 @@ func TestClient(t *testing.T) {
{
name: "invalid client version",
fields: fields{
ResponseBody: loginResponse54,
ResponseBody: loginResponse61,
},
wantErr: true,
expectedVersion: computed54TestVersion,
expectedVersion: computed61TestVersion,
config: &Config{
Username: "admin",
Password: "admin",
Expand All @@ -231,14 +232,14 @@ func TestClient(t *testing.T) {
{
name: "500 login response",
fields: fields{
ResponseBody: loginResponse54,
ResponseBody: loginResponse61,
},
wantErr: true,
expectedVersion: computed54TestVersion,
expectedVersion: computed61TestVersion,
config: &Config{
Username: "admin",
Password: "admin",
Version: 15,
Version: 18,
LoginTimeout: 1,
Insecure: true,
},
Expand All @@ -248,14 +249,14 @@ func TestClient(t *testing.T) {
{
name: "502 login response",
fields: fields{
ResponseBody: loginResponse54,
ResponseBody: loginResponse61,
},
wantErr: true,
expectedVersion: computed54TestVersion,
expectedVersion: computed61TestVersion,
config: &Config{
Username: "admin",
Password: "admin",
Version: 15,
Version: 18,
LoginTimeout: 1,
Insecure: true,
},
Expand All @@ -265,14 +266,14 @@ func TestClient(t *testing.T) {
{
name: "503 login response",
fields: fields{
ResponseBody: loginResponse54,
ResponseBody: loginResponse61,
},
wantErr: true,
expectedVersion: computed54TestVersion,
expectedVersion: computed61TestVersion,
config: &Config{
Username: "admin",
Password: "admin",
Version: 15,
Version: 18,
LoginTimeout: 1,
Insecure: true,
},
Expand All @@ -285,7 +286,7 @@ func TestClient(t *testing.T) {
ResponseBody: loginResponse406,
},
wantErr: true,
expectedVersion: computed54TestVersion,
expectedVersion: computed61TestVersion,
config: &Config{
Username: "admin",
Password: "admin",
Expand All @@ -299,15 +300,15 @@ func TestClient(t *testing.T) {
{
name: "test with invalid pem",
fields: fields{
ResponseBody: loginResponse54,
ResponseBody: loginResponse61,
},
wantErr: false,
wantClientErr: true,
expectedVersion: computed54TestVersion,
expectedVersion: computed61TestVersion,
config: &Config{
Username: "admin",
Password: "admin",
Version: 15,
Version: 18,
LoginTimeout: 1,
Insecure: false,
PemFilePath: "test-fixtures/invalid_cert.pem",
Expand All @@ -318,15 +319,15 @@ func TestClient(t *testing.T) {
{
name: "test with pem file",
fields: fields{
ResponseBody: loginResponse54,
ResponseBody: loginResponse61,
},
wantErr: false,
wantClientErr: false,
expectedVersion: computed54TestVersion,
expectedVersion: computed64TestVersion,
config: &Config{
Username: "admin",
Password: "admin",
Version: 15,
Version: 18,
LoginTimeout: 1,
Insecure: false,
PemFilePath: "test-fixtures/cert.pem",
Expand Down
8 changes: 1 addition & 7 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/v20/openapi"
"github.com/appgate/sdp-api-client-go/api/v21/openapi"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down Expand Up @@ -61,7 +61,6 @@ func dataSourceAppgateApplianceSeedRead(d *schema.ResourceData, meta interface{}
return err
}
api := meta.(*Client).API.AppliancesApi
currentVersion := meta.(*Client).ApplianceVersion
ctx := context.TODO()
applianceID, iok := d.GetOk("appliance_id")

Expand Down Expand Up @@ -95,11 +94,6 @@ func dataSourceAppgateApplianceSeedRead(d *schema.ResourceData, meta interface{}
cloudKey, cloudOk := d.GetOk("provide_cloud_ssh_key")

sshConfig := openapi.NewSSHConfig()
// AllowCustomization and ValidityDays is only available in >= 5.5
if currentVersion.LessThan(Appliance55Version) {
sshConfig.AllowCustomization = nil
sshConfig.ValidityDays = nil
}
if passwordOk {
sshConfig.Password = openapi.PtrString(password.(string))
d.Set("password", password.(string))
Expand Down
14 changes: 0 additions & 14 deletions appgate/data_source_appgate_appliance_seed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ func TestAccAppgateApplianceSeedDataSource(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccSeedTest(rName),
PreConfig: func() {
applianceTestForFiveFive(t)
},
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "appliance_id", resourceName, "id"),
resource.TestCheckResourceAttrSet("data.appgatesdp_appliance_seed.test_gateway_seed_file", "password"),
Expand Down Expand Up @@ -53,17 +50,6 @@ resource "appgatesdp_appliance" "new_test_gateway" {
override_spa_mode = "UDP-TCP"
}
peer_interface {
hostname = "envy-10-97-168-1338.devops"
https_port = "1338"
allow_sources {
address = "1.3.3.8"
netmask = 32
nic = "eth0"
}
}
site = data.appgatesdp_site.default_site.id
networking {
nics {
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/v20/openapi"
"github.com/appgate/sdp-api-client-go/api/v21/openapi"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down
2 changes: 1 addition & 1 deletion 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/v20/openapi"
"github.com/appgate/sdp-api-client-go/api/v21/openapi"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
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/v20/openapi"
"github.com/appgate/sdp-api-client-go/api/v21/openapi"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down
2 changes: 1 addition & 1 deletion appgate/find_resource_by_name.go

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

22 changes: 6 additions & 16 deletions appgate/identity_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import (
"fmt"
"log"

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

"github.com/hashicorp/go-version"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

Expand Down Expand Up @@ -52,7 +51,7 @@ func identityProviderSchema() map[string]*schema.Schema {
return
}
}
errs = append(errs, fmt.Errorf("type must be on of %v, got %s", list, s))
errs = append(errs, fmt.Errorf("type must be one of %v, got %s", list, s))
return
},
},
Expand Down Expand Up @@ -421,7 +420,7 @@ func ldapProviderSchema() map[string]*schema.Schema {
}

// readProviderFromConfig reads all the common attributes for the IdentityProviders.
func readProviderFromConfig(d *schema.ResourceData, provider openapi.ConfigurableIdentityProvider, currentVersion *version.Version) (*openapi.ConfigurableIdentityProvider, error) {
func readProviderFromConfig(d *schema.ResourceData, provider openapi.ConfigurableIdentityProvider) (*openapi.ConfigurableIdentityProvider, error) {
base, err := readBaseEntityFromConfig(d)
if err != nil {
return &provider, err
Expand All @@ -440,18 +439,6 @@ func readProviderFromConfig(d *schema.ResourceData, provider openapi.Configurabl
provider.SetAdminProvider(v.(bool))
}

// device_limit_per_user is only available on 5.5 or higher on root level,
// previous version has this on on_boarding_two_factor.device_limit_per_user
if v, ok := d.GetOk("device_limit_per_user"); ok {
if currentVersion.LessThan(Appliance55Version) {
return &provider, fmt.Errorf(
"device_limit_per_user is only available on 5.5, your current version is %s, Use on_boarding_two_factor.device_limit_per_user for appliances less then 5.5",
currentVersion.String(),
)
}
provider.SetDeviceLimitPerUser(int32(v.(int)))
}

if v, ok := d.GetOk("on_boarding_two_factor"); ok {
onboarding, err := readOnBoardingTwoFactorFromConfig(v.([]interface{}))
if err != nil {
Expand All @@ -472,6 +459,9 @@ func readProviderFromConfig(d *schema.ResourceData, provider openapi.Configurabl
if v, ok := d.GetOk("ip_pool_v6"); ok {
provider.SetIpPoolV6(v.(string))
}
if v, ok := d.GetOk("device_limit_per_user"); ok {
provider.SetDeviceLimitPerUser(int32(v.(int)))
}
if v, ok := d.GetOk("user_scripts"); ok {
us, err := readArrayOfStringsFromConfig(v.([]interface{}))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion appgate/identity_provider_migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func resourceIdentityProvidereUpgradeV0(_ context.Context, rawState map[string]i
return nil, nil
}
currentVersion := meta.(*Client).ApplianceVersion
if currentVersion.GreaterThanOrEqual(Appliance55Version) {
if currentVersion.GreaterThanOrEqual(Appliance64Version) {
if v, ok := rawState["on_boarding_two_factor"]; ok {
twoFA := v.(map[string]interface{})
if v, ok := twoFA["device_limit_per_user"]; ok {
Expand Down
Loading

0 comments on commit 477bf46

Please sign in to comment.