Skip to content

Commit

Permalink
changing Vpc to AwsVpc; changing AuthTypeValue to ServiceAccountCrede…
Browse files Browse the repository at this point in the history
…ntial
  • Loading branch information
shinmog committed Dec 10, 2021
1 parent abc72b6 commit 97090a8
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 102 deletions.
160 changes: 80 additions & 80 deletions dev/vminfosource/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
// VM information source.
type Entry struct {
Name string
Vpc *Vpc
AwsVpc *AwsVpc
Esxi *Esxi
Vcenter *Vcenter
GoogleCompute *GoogleCompute // PAN-OS 8.1
}

type Vpc struct {
type AwsVpc struct {
Description string
Disabled bool
Source string
Expand Down Expand Up @@ -54,33 +54,33 @@ type Vcenter struct {
}

type GoogleCompute struct {
Description string
Disabled bool
AuthType string
AuthTypeValue string // encrypted
ProjectId string
ZoneName string
UpdateInterval int
EnableTimeout bool
Timeout int
Description string
Disabled bool
AuthType string
ServiceAccountCredential string // encrypted
ProjectId string
ZoneName string
UpdateInterval int
EnableTimeout bool
Timeout int
}

// Copy copies the information from source Entry `s` to this object. As the
// Name field relates to the XPATH of this object, this field is not copied.
func (o *Entry) Copy(s Entry) {
if s.Vpc == nil {
o.Vpc = nil
if s.AwsVpc == nil {
o.AwsVpc = nil
} else {
s.Vpc = &Vpc{
Description: s.Vpc.Description,
Disabled: s.Vpc.Disabled,
Source: s.Vpc.Source,
AccessKeyId: s.Vpc.AccessKeyId,
SecretAccessKey: s.Vpc.SecretAccessKey,
UpdateInterval: s.Vpc.UpdateInterval,
EnableTimeout: s.Vpc.EnableTimeout,
Timeout: s.Vpc.Timeout,
VpcId: s.Vpc.VpcId,
s.AwsVpc = &AwsVpc{
Description: s.AwsVpc.Description,
Disabled: s.AwsVpc.Disabled,
Source: s.AwsVpc.Source,
AccessKeyId: s.AwsVpc.AccessKeyId,
SecretAccessKey: s.AwsVpc.SecretAccessKey,
UpdateInterval: s.AwsVpc.UpdateInterval,
EnableTimeout: s.AwsVpc.EnableTimeout,
Timeout: s.AwsVpc.Timeout,
VpcId: s.AwsVpc.VpcId,
}
}
if s.Esxi == nil {
Expand Down Expand Up @@ -117,15 +117,15 @@ func (o *Entry) Copy(s Entry) {
o.GoogleCompute = nil
} else {
o.GoogleCompute = &GoogleCompute{
Description: s.GoogleCompute.Description,
Disabled: s.GoogleCompute.Disabled,
AuthType: s.GoogleCompute.AuthType,
AuthTypeValue: s.GoogleCompute.AuthTypeValue,
ProjectId: s.GoogleCompute.ProjectId,
ZoneName: s.GoogleCompute.ZoneName,
UpdateInterval: s.GoogleCompute.UpdateInterval,
EnableTimeout: s.GoogleCompute.EnableTimeout,
Timeout: s.GoogleCompute.Timeout,
Description: s.GoogleCompute.Description,
Disabled: s.GoogleCompute.Disabled,
AuthType: s.GoogleCompute.AuthType,
ServiceAccountCredential: s.GoogleCompute.ServiceAccountCredential,
ProjectId: s.GoogleCompute.ProjectId,
ZoneName: s.GoogleCompute.ZoneName,
UpdateInterval: s.GoogleCompute.UpdateInterval,
EnableTimeout: s.GoogleCompute.EnableTimeout,
Timeout: s.GoogleCompute.Timeout,
}
}
}
Expand Down Expand Up @@ -167,7 +167,7 @@ func (o *container_v1) Normalize() []Entry {
type entry_v1 struct {
XMLName xml.Name `xml:"entry"`
Name string `xml:"name,attr"`
Vpc *vpc `xml:"SourceType>AWS-VPC"`
AwsVpc *vpc `xml:"SourceType>AWS-VPC"`
Esxi *esxi `xml:"SourceType>VMware-ESXi"`
Vcenter *vcenter `xml:"SourceType>VMware-vCenter"`
}
Expand Down Expand Up @@ -254,17 +254,17 @@ func specify_v1(e Entry) interface{} {
Name: e.Name,
}

if e.Vpc != nil {
ans.Vpc = &vpc{
Description: e.Vpc.Description,
Disabled: util.YesNo(e.Vpc.Disabled),
Source: e.Vpc.Source,
AccessKeyId: e.Vpc.AccessKeyId,
SecretAccessKey: e.Vpc.SecretAccessKey,
UpdateInterval: e.Vpc.UpdateInterval,
EnableTimeout: util.YesNo(e.Vpc.EnableTimeout),
Timeout: e.Vpc.Timeout,
VpcId: e.Vpc.VpcId,
if e.AwsVpc != nil {
ans.AwsVpc = &vpc{
Description: e.AwsVpc.Description,
Disabled: util.YesNo(e.AwsVpc.Disabled),
Source: e.AwsVpc.Source,
AccessKeyId: e.AwsVpc.AccessKeyId,
SecretAccessKey: e.AwsVpc.SecretAccessKey,
UpdateInterval: e.AwsVpc.UpdateInterval,
EnableTimeout: util.YesNo(e.AwsVpc.EnableTimeout),
Timeout: e.AwsVpc.Timeout,
VpcId: e.AwsVpc.VpcId,
}
}

Expand Down Expand Up @@ -304,17 +304,17 @@ func (e *entry_v1) normalize() Entry {
Name: e.Name,
}

if e.Vpc != nil {
ans.Vpc = &Vpc{
Description: e.Vpc.Description,
Disabled: util.AsBool(e.Vpc.Disabled),
Source: e.Vpc.Source,
AccessKeyId: e.Vpc.AccessKeyId,
SecretAccessKey: e.Vpc.SecretAccessKey,
UpdateInterval: e.Vpc.UpdateInterval,
EnableTimeout: util.AsBool(e.Vpc.EnableTimeout),
Timeout: e.Vpc.Timeout,
VpcId: e.Vpc.VpcId,
if e.AwsVpc != nil {
ans.AwsVpc = &AwsVpc{
Description: e.AwsVpc.Description,
Disabled: util.AsBool(e.AwsVpc.Disabled),
Source: e.AwsVpc.Source,
AccessKeyId: e.AwsVpc.AccessKeyId,
SecretAccessKey: e.AwsVpc.SecretAccessKey,
UpdateInterval: e.AwsVpc.UpdateInterval,
EnableTimeout: util.AsBool(e.AwsVpc.EnableTimeout),
Timeout: e.AwsVpc.Timeout,
VpcId: e.AwsVpc.VpcId,
}
}

Expand Down Expand Up @@ -375,7 +375,7 @@ func (o *container_v2) Normalize() []Entry {
type entry_v2 struct {
XMLName xml.Name `xml:"entry"`
Name string `xml:"name,attr"`
Vpc *vpc `xml:"SourceType>AWS-VPC"`
AwsVpc *vpc `xml:"SourceType>AWS-VPC"`
Esxi *esxi `xml:"SourceType>VMware-ESXi"`
Vcenter *vcenter `xml:"SourceType>VMware-vCenter"`
GoogleCompute *googleCompute `xml:"SourceType>Google-Compute-Engine"`
Expand Down Expand Up @@ -406,17 +406,17 @@ func specify_v2(e Entry) interface{} {
Name: e.Name,
}

if e.Vpc != nil {
ans.Vpc = &vpc{
Description: e.Vpc.Description,
Disabled: util.YesNo(e.Vpc.Disabled),
Source: e.Vpc.Source,
AccessKeyId: e.Vpc.AccessKeyId,
SecretAccessKey: e.Vpc.SecretAccessKey,
UpdateInterval: e.Vpc.UpdateInterval,
EnableTimeout: util.YesNo(e.Vpc.EnableTimeout),
Timeout: e.Vpc.Timeout,
VpcId: e.Vpc.VpcId,
if e.AwsVpc != nil {
ans.AwsVpc = &vpc{
Description: e.AwsVpc.Description,
Disabled: util.YesNo(e.AwsVpc.Disabled),
Source: e.AwsVpc.Source,
AccessKeyId: e.AwsVpc.AccessKeyId,
SecretAccessKey: e.AwsVpc.SecretAccessKey,
UpdateInterval: e.AwsVpc.UpdateInterval,
EnableTimeout: util.YesNo(e.AwsVpc.EnableTimeout),
Timeout: e.AwsVpc.Timeout,
VpcId: e.AwsVpc.VpcId,
}
}

Expand Down Expand Up @@ -465,7 +465,7 @@ func specify_v2(e Entry) interface{} {
ans.GoogleCompute.Auth.ServiceInGce = &s
case AuthTypeServiceAccount:
ans.GoogleCompute.Auth.ServiceAccount = &gcAuthServiceAccount{
ServiceAccountCredential: e.GoogleCompute.AuthTypeValue,
ServiceAccountCredential: e.GoogleCompute.ServiceAccountCredential,
}
}
}
Expand All @@ -478,17 +478,17 @@ func (e *entry_v2) normalize() Entry {
Name: e.Name,
}

if e.Vpc != nil {
ans.Vpc = &Vpc{
Description: e.Vpc.Description,
Disabled: util.AsBool(e.Vpc.Disabled),
Source: e.Vpc.Source,
AccessKeyId: e.Vpc.AccessKeyId,
SecretAccessKey: e.Vpc.SecretAccessKey,
UpdateInterval: e.Vpc.UpdateInterval,
EnableTimeout: util.AsBool(e.Vpc.EnableTimeout),
Timeout: e.Vpc.Timeout,
VpcId: e.Vpc.VpcId,
if e.AwsVpc != nil {
ans.AwsVpc = &AwsVpc{
Description: e.AwsVpc.Description,
Disabled: util.AsBool(e.AwsVpc.Disabled),
Source: e.AwsVpc.Source,
AccessKeyId: e.AwsVpc.AccessKeyId,
SecretAccessKey: e.AwsVpc.SecretAccessKey,
UpdateInterval: e.AwsVpc.UpdateInterval,
EnableTimeout: util.AsBool(e.AwsVpc.EnableTimeout),
Timeout: e.AwsVpc.Timeout,
VpcId: e.AwsVpc.VpcId,
}
}

Expand Down Expand Up @@ -536,7 +536,7 @@ func (e *entry_v2) normalize() Entry {
ans.GoogleCompute.AuthType = AuthTypeServiceInGce
case e.GoogleCompute.Auth.ServiceAccount != nil:
ans.GoogleCompute.AuthType = AuthTypeServiceAccount
ans.GoogleCompute.AuthTypeValue = e.GoogleCompute.Auth.ServiceAccount.ServiceAccountCredential
ans.GoogleCompute.ServiceAccountCredential = e.GoogleCompute.Auth.ServiceAccount.ServiceAccountCredential
}
}

Expand Down
18 changes: 9 additions & 9 deletions dev/vminfosource/fw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestFwNormalization(t *testing.T) {
}
}

func TestVpcDefaults(t *testing.T) {
func TestAwsVpcDefaults(t *testing.T) {
mc := &testdata.MockClient{
Version: version.Number{6, 1, 0, ""},
}
Expand All @@ -52,14 +52,14 @@ func TestVpcDefaults(t *testing.T) {
ans, err := ns.Get("vsys1", "jack")
if err != nil {
t.Errorf("Error in get: %s", err)
} else if ans.Vpc == nil {
t.Errorf("Vpc is nil")
} else if ans.Vpc.Description != "hi" {
t.Errorf("Vpc description is %q, not \"hi\"", ans.Vpc.Description)
} else if ans.Vpc.UpdateInterval != 60 {
t.Errorf("Vpc update interval is %d", ans.Vpc.UpdateInterval)
} else if ans.Vpc.Timeout != 2 {
t.Errorf("Vpc timeout is %d", ans.Vpc.Timeout)
} else if ans.AwsVpc == nil {
t.Errorf("AwsVpc is nil")
} else if ans.AwsVpc.Description != "hi" {
t.Errorf("AwsVpc description is %q, not \"hi\"", ans.AwsVpc.Description)
} else if ans.AwsVpc.UpdateInterval != 60 {
t.Errorf("AwsVpc update interval is %d", ans.AwsVpc.UpdateInterval)
} else if ans.AwsVpc.Timeout != 2 {
t.Errorf("AwsVpc timeout is %d", ans.AwsVpc.Timeout)
}
}

Expand Down
26 changes: 13 additions & 13 deletions dev/vminfosource/testdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func getTests() []testCase {
return []testCase{
{"v1 vpc disabled", version.Number{6, 1, 0, ""}, Entry{
Name: "one",
Vpc: &Vpc{
AwsVpc: &AwsVpc{
Description: "description",
Disabled: true,
Source: "source",
Expand All @@ -28,7 +28,7 @@ func getTests() []testCase {
}},
{"v1 vpc enable timeout", version.Number{6, 1, 0, ""}, Entry{
Name: "one",
Vpc: &Vpc{
AwsVpc: &AwsVpc{
Description: "description",
Disabled: false,
Source: "source",
Expand Down Expand Up @@ -98,7 +98,7 @@ func getTests() []testCase {
}},
{"v2 vpc disabled", version.Number{8, 1, 0, ""}, Entry{
Name: "one",
Vpc: &Vpc{
AwsVpc: &AwsVpc{
Description: "description",
Disabled: true,
Source: "source",
Expand All @@ -112,7 +112,7 @@ func getTests() []testCase {
}},
{"v2 vpc enable timeout", version.Number{8, 1, 0, ""}, Entry{
Name: "one",
Vpc: &Vpc{
AwsVpc: &AwsVpc{
Description: "description",
Disabled: false,
Source: "source",
Expand Down Expand Up @@ -196,15 +196,15 @@ func getTests() []testCase {
{"v2 google compute enable timeout service account", version.Number{8, 1, 0, ""}, Entry{
Name: "name",
GoogleCompute: &GoogleCompute{
Description: "desc",
Disabled: false,
AuthType: AuthTypeServiceAccount,
AuthTypeValue: "creds json",
ProjectId: "proj",
ZoneName: "zone",
UpdateInterval: 6,
EnableTimeout: true,
Timeout: 5,
Description: "desc",
Disabled: false,
AuthType: AuthTypeServiceAccount,
ServiceAccountCredential: "creds json",
ProjectId: "proj",
ZoneName: "zone",
UpdateInterval: 6,
EnableTimeout: true,
Timeout: 5,
},
}},
}
Expand Down

0 comments on commit 97090a8

Please sign in to comment.