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

feat: Defer retrieval of system info and plugin data #169

Merged
merged 2 commits into from
Oct 1, 2024
Merged
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
43 changes: 25 additions & 18 deletions assets/pango/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ type Client struct {

// Variables determined at runtime.
Version version.Number `json:"-"`
SystemInfo map[string]string `json:"-"`
Plugin []plugin.Info `json:"-"`
systemInfo map[string]string `json:"-"`
plugins []plugin.Info `json:"-"`

// Internal variables.
con *http.Client
Expand All @@ -81,9 +81,24 @@ func (c *Client) Versioning() version.Number {
return c.Version
}

// Plugins returns the list of plugins.
func (c *Client) Plugins() []plugin.Info {
return c.Plugin
func (c *Client) SystemInfo(ctx context.Context) (map[string]string, error) {
if c.systemInfo == nil {
if err := c.RetrieveSystemInfo(ctx); err != nil {
return nil, err
}
}

return c.systemInfo, nil
}

func (c *Client) Plugins(ctx context.Context) ([]plugin.Info, error) {
if c.plugin == nil {
if err := c.RetrievePlugins(ctx); err != nil {
return nil, err
}
}

return c.plugin, nil
}

// GetTarget returns the Target param, used in certain API calls.
Expand All @@ -93,11 +108,11 @@ func (c *Client) GetTarget() string {

// IsPanorama returns true if this is Panorama.
func (c *Client) IsPanorama() (bool, error) {
if len(c.SystemInfo) == 0 {
if len(c.systemInfo) == 0 {
return false, fmt.Errorf("SystemInfo is nil")
}

model, ok := c.SystemInfo["model"]
model, ok := c.systemInfo["model"]
if !ok {
return false, fmt.Errorf("model not present in SystemInfo")
}
Expand Down Expand Up @@ -314,14 +329,6 @@ func (c *Client) Initialize(ctx context.Context) error {
}
}

if err = c.RetrieveSystemInfo(ctx); err != nil {
return err
}

if err = c.RetrievePlugins(ctx); err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -352,12 +359,12 @@ func (c *Client) RetrieveSystemInfo(ctx context.Context) error {
return err
}

c.SystemInfo = make(map[string]string, len(ans.System.Tags))
c.systemInfo = make(map[string]string, len(ans.System.Tags))
for _, t := range ans.System.Tags {
if t.TrimmedText == nil {
continue
}
c.SystemInfo[t.XMLName.Local] = *t.TrimmedText
c.systemInfo[t.XMLName.Local] = *t.TrimmedText
if t.XMLName.Local == "sw-version" {
c.Version, err = version.New(*t.TrimmedText)
if err != nil {
Expand Down Expand Up @@ -453,7 +460,7 @@ func (c *Client) RetrievePlugins(ctx context.Context) error {
return err
}

c.Plugin = ans.Listing()
c.plugin = ans.Listing()

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion assets/pango/util/pangoclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
type PangoClient interface {
// Basics.
Versioning() version.Number
Plugins() []plugin.Info
Plugins(context.Context) ([]plugin.Info, error)
GetTarget() string
IsPanorama() (bool, error)
IsFirewall() (bool, error)
Expand Down