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: Render service.go for entry and config #42

Merged
merged 72 commits into from
Apr 4, 2024
Merged

Conversation

sebastianczech
Copy link
Contributor

@sebastianczech sebastianczech commented Apr 2, 2024

Description

PR delivers mainly new template used to render service.go for entry and config

Motivation and Context

#32

How Has This Been Tested?

Template was checked locally by generating code from the template and trying to created, update and delete:

  • entries: address and service
  • configs: NTP and DNS

New function is tested via unit test.

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist

  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes if appropriate.
  • All new and existing tests passed.

@sebastianczech sebastianczech marked this pull request as ready for review April 2, 2024 12:47
@pimielowski pimielowski self-requested a review April 2, 2024 13:33
Base automatically changed from render-config to main April 2, 2024 16:18
… the issues from `golangci-lint run --enable-all`
Comment on lines 2 to 11
import (
"context"
"fmt"

"github.com/PaloAltoNetworks/pango/errors"
"github.com/PaloAltoNetworks/pango/filtering"
"github.com/PaloAltoNetworks/pango/util"
"github.com/PaloAltoNetworks/pango/xmlapi"
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't statically define imports, just use the importlib helper. Firstly because that's why it exists, and second because even pango will eventually need to import other libs (think subconfig). So let the importlib help with that.

./pkg/imports/manager.go

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used imports manager:

{{renderImports "service"}}

Now that list is static for every template:

func RenderImports(templateType string) (string, error) {

but when I start working with more advanced objects, which are using other objects - I need to import them, so I will extend that logic in other PRs.

templates/sdk/service.tmpl Outdated Show resolved Hide resolved
templates/sdk/service.tmpl Outdated Show resolved Hide resolved
templates/sdk/service.tmpl Show resolved Hide resolved
templates/sdk/service.tmpl Outdated Show resolved Hide resolved
templates/sdk/service.tmpl Outdated Show resolved Hide resolved
package {{packageName .GoSdkPath}}
{{- if .Entry}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entry style normalizations and Config style normalizations should probably be separate files.

This becomes more apparent now that we need to add support for UUID-Entry styled services.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this moment I propose to leave it as it's - in next stages, when I start work on UUID, I can split it. If we will have other template for that login for configs, what should be the output file name , if service.go is going to be reserved for entries ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would still be service.go because it's the service for that namespace. Just the contents of the service is different.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now from the name of the template , we are creating final file:

func (c *Creator) createFullFilePath(templateName string) string {

so from service.tmpl we are creating service.go.
If we want to split it to different templates, but receive file service.go, then I need to rebuild that logic - I propose to do it in other PR, ok?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, then I wouldn't wrap the entirety of the file in an if/else, then. There are not a ton of changes between an Entry service.go and a Config service.go. Be more specific with the template instead of splitting it into separate template files.

templates/sdk/service.tmpl Show resolved Hide resolved
Copy link
Contributor

@pimielowski pimielowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GJ! Please check my comment :)

pkg/translate/imports.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@shinmog shinmog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few things left.

package {{packageName .GoSdkPath}}
{{- if .Entry}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would still be service.go because it's the service for that namespace. Just the contents of the service is different.

templates/sdk/service.tmpl Outdated Show resolved Hide resolved
templates/sdk/service.tmpl Show resolved Hide resolved
Copy link
Contributor

@pimielowski pimielowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Collaborator

@shinmog shinmog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@sebastianczech sebastianczech merged commit ba3131c into main Apr 4, 2024
2 checks passed
@sebastianczech sebastianczech deleted the render-service branch April 4, 2024 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants