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

export command #54

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open

export command #54

wants to merge 34 commits into from

Conversation

daveads
Copy link

@daveads daveads commented Dec 17, 2024

feat: add terraform environment export command

  • Add new permit env export terraform command
  • Support exporting environment configuration to HCL format
  • Add optional API key and output file path parameters
  • Export resources, roles, user sets, resource sets and condition sets

/claim #47

@daveads
Copy link
Author

daveads commented Dec 17, 2024

permitcli.mp4

@daveads
Copy link
Author

daveads commented Dec 17, 2024

@gemanor

@gemanor
Copy link
Collaborator

gemanor commented Dec 29, 2024

Hey @daveads, seems like the CI failed due to build/lint/test issues, can you please test it?

@daveads
Copy link
Author

daveads commented Dec 29, 2024

Hey @daveads, seems like the CI failed due to build/lint/test issues, can you please test it?

okayy

@daveads
Copy link
Author

daveads commented Dec 30, 2024

@gemanor waiting for workflow approval.

Copy link
Collaborator

@gemanor gemanor left a comment

Choose a reason for hiding this comment

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

Hey, in general this is a good start, but it has some core changes needed.

Please see the comments in the code itself, and also address the following:

  • The hooks/components shouldn't be in the command folder. Please use the other components/hooks folders for them
  • The HCL should have a better templating solution. It is better that they will be in .hcl files, and you'll use a template engine to render them. Some of the code that is rendering now
  • Some of the content now is rendered as object object instead of good stringify solution
  • Please run some tests with files that you exported and import it again using TF to ensure the exported file is indeed valid
  • There is no support with the depends_on for the resources, it could lead to race condition when working with terraform. Please add depends_on where relevant

const key = apiKey || authToken;
const { state, setState, exportConfig } = useExport(key);

React.useEffect(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use the convention of importing the function and use them without the React.

import React, { useEffect } from 'react';

...

useEffect(() => {

return;
}
} else {
console.log(hcl);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be printed as part of render function, using the console.log here can be confusing and lead to unmaintainable code

Copy link
Collaborator

Choose a reason for hiding this comment

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

render function, means to render it as part of the command/component return section

}

export const ExportStatus: React.FC<ExportStatusProps> = ({ state, file }) => {
if (state.error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please replace the if (state.error) { convention with {state.error && convention, to make it more readable

() =>
new Permit({
token,
pdp: 'http://localhost:7766',
Copy link
Collaborator

Choose a reason for hiding this comment

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

This variable should be configurable from the function arguments to allow configurable pdp URL for further usages

try {
const warningCollector = createWarningCollector();

let hcl = `# Generated by Permit CLI
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please move all the .hcl code to static .hcl files in a dedicated folder and import them to the code where needed.
It will:

  1. Made the code more readable and keep the indentation
  2. Ensure reusable of code snippets

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is up to you to decide on the import way of this text and use the templates in it

import { Permit } from 'permitio';
import React from 'react';

export const PermitSDK = (token: string) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use the hook naming convention usePermitSDK

key = "${resource.key}"
name = "${resource.name}"${
resource.description ? `\n description = "${resource.description}"` : ''
}${resource.urn ? `\n urn = "${resource.urn}"` : ''}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is redundant probably

@daveads
Copy link
Author

daveads commented Dec 30, 2024

Hey, in general this is a good start, but it has some core changes needed.

Please see the comments in the code itself, and also address the following:

* The hooks/components shouldn't be in the `command` folder. Please use the other `components`/`hooks` folders for them

* The HCL should have a better templating solution. It is better that they will be in `.hcl` files, and you'll use a template engine to render them. Some of the code that is rendering now

* Some of the content now is rendered as `object object` instead of good stringify solution

* Please run some tests with files that you exported and import it again using TF to ensure the exported file is indeed valid

* There is no support with the `depends_on` for the resources, it could lead to race condition when working with terraform. Please add `depends_on` where relevant

alright

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants