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

Get chaos environments command #170

Merged
merged 3 commits into from
Jan 15, 2024

Conversation

shivam-Purohit
Copy link
Contributor

refers issue #164

Addition of new commands :

litmusctl get chaos-environment --project-id="" --environment-id=""
litmusctl list chaos-environment --project-id=""

@shivam-Purohit
Copy link
Contributor Author

Suggest if further changes are required.

@shivam-Purohit
Copy link
Contributor Author

@SarthakJain26 @Saranya-jena can I get a review?

environmentList, err := environment.GetEnvironmentList(projectID, credentials);
if err != nil {
if strings.Contains(err.Error(), "permission_denied") {
utils.Red.Println("❌ The specified Project ID doesn't exist.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please update the message to, "You don't have enough permissions to access this resource"

func init() {
GetCmd.AddCommand(ChaosEnvironmentCmd);
ChaosEnvironmentCmd.Flags().String("project-id", "", "Set the project-id to list Chaos Environment from a particular project.")
ChaosEnvironmentCmd.Flags().String("environment-id", "", "Set the environment-id to list Chaos Environment")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
ChaosEnvironmentCmd.Flags().String("environment-id", "", "Set the environment-id to list Chaos Environment")
ChaosEnvironmentCmd.Flags().String("environment-id", "", "Set the environment-id to get Chaos Environment")

}
func init() {
GetCmd.AddCommand(ChaosEnvironmentCmd);
ChaosEnvironmentCmd.Flags().String("project-id", "", "Set the project-id to list Chaos Environment from a particular project.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
ChaosEnvironmentCmd.Flags().String("project-id", "", "Set the project-id to list Chaos Environment from a particular project.")
ChaosEnvironmentCmd.Flags().String("project-id", "", "Set the project-id to get Chaos Environment from a particular project.")

environmentList, err := environment.GetEnvironmentList(projectID, credentials);
if err != nil {
if strings.Contains(err.Error(), "permission_denied") {
utils.Red.Println("❌ The specified Project ID doesn't exist.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please update the message to, "You don't have enough permissions to access this resource"

var ListCmd = &cobra.Command{
Use: "list",
Short: `Examples:
#get list of chaos Chaos Experiments
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
#get list of chaos Chaos Experiments
#get list of chaos Chaos Environments

@SarthakJain26
Copy link
Collaborator

@shivam-Purohit can you please also share the screen shots of the command and the output

@SarthakJain26
Copy link
Collaborator

@shivam-Purohit please add these commands in the readme and usage docs as well

@shivam-Purohit
Copy link
Contributor Author

@shivam-Purohit can you please also share the screen shots of the command and the output

sure!
ubuntuMachine  Running  - Oracle VM VirtualBox 29-12-2023 10_17_17
ubuntuMachine  Running  - Oracle VM VirtualBox 29-12-2023 10_16_26

@shivam-Purohit
Copy link
Contributor Author

@shivam-Purohit please add these commands in the readme and usage docs as well

I added these in 0.23.0. Do we need to add in any other versions? i think we do not need that.

@SarthakJain26 I fixed all the changes you requested. Let me know if further changes are required.

@SarthakJain26
Copy link
Collaborator

@shivam-Purohit , you have displayed the complete response coming from the API which is not a very good user experience. You will have to extract required fields and you can display them in table format. I have attached the screenshot for reference. You can display environmentID, name, createdAt and createdBy fields. Please update the PR accordingly
Screenshot 2023-12-29 at 11 24 06 AM

@shivam-Purohit
Copy link
Contributor Author

hey @SarthakJain26 I am currently getting the response as null in many fields which ig should not. I tried rechecking the API. Is there something I am doing here to retrieve the data?

@SarthakJain26
Copy link
Collaborator

hey @SarthakJain26 I am currently getting the response as null in many fields which ig should not. I tried rechecking the API. Is there something I am doing here to retrieve the data?

@shivam-Purohit Possibly yes. You need to check on what is the graphql request you are sending and then what is the data you are expecting back. While decoding the response from the graphql server you need to check if the struct you are using to decode the response has the required fields or not.

@shivam-Purohit
Copy link
Contributor Author

@SarthakJain26 the error was actually due to query itself which we were sending through api. I changed it a bit for the newcommand.
I also refactored the output and reused some other components for similarity and reusability.
ubuntuMachine  Running  - Oracle VM VirtualBox 07-01-2024 18_21_19

@SarthakJain26
Copy link
Collaborator

Thanks @shivam-Purohit, update output looks awesome

@Nageshbansal
Copy link
Collaborator

Nageshbansal commented Jan 7, 2024

@SarthakJain26, do we need two separate commands for this, i.e., list and get? Maybe get should be enough only to show a list of all environments, as that is what we're doing for experiments and infra.

@SarthakJain26
Copy link
Collaborator

@SarthakJain26, do we need two separate commands for this, i.e., list and get? Maybe get should be enough only to show a list of all environments, as that is what we're doing for experiments and infra.

@Nageshbansal , by convention, list command can be used to list the resources under the project with required info, and get command can be used to get additional info about a particular resource. We can follow the same in other places as well.
Adding to this @shivam-Purohit please let us know if you can add other details also in the get environment command in couple of days so that we can merge this PR and take it in this release.

@shivam-Purohit
Copy link
Contributor Author

@SarthakJain26, do we need two separate commands for this, i.e., list and get? Maybe get should be enough only to show a list of all environments, as that is what we're doing for experiments and infra.

@Nageshbansal , by convention, list command can be used to list the resources under the project with required info, and get command can be used to get additional info about a particular resource. We can follow the same in other places as well. Adding to this @shivam-Purohit please let us know if you can add other details also in the get environment command in couple of days so that we can merge this PR and take it in this release.

type Environment struct {
	ProjectID     string          `json:"projectID"`
	EnvironmentID string          `json:"environmentID"`
	Name          string          `json:"name"`
	Description   *string         `json:"description"`
	Tags          []string        `json:"tags"`
	Type          EnvironmentType `json:"type"`
	CreatedAt     string          `json:"createdAt"`
	CreatedBy     *UserDetails    `json:"createdBy"`
	UpdatedBy     *UserDetails    `json:"updatedBy"`
	UpdatedAt     string          `json:"updatedAt"`
	IsRemoved     *bool           `json:"isRemoved"`
	InfraIDs      []string        `json:"infraIDs"`
}

these are the details we can get from the response. @SarthakJain26 let me know what details you want to add, imo we can add type, description or maybe updated at and updated by.

@SarthakJain26
Copy link
Collaborator

@shivam-Purohit you can also add the InfraIDs along with what you mentioned so that it infras within the environment can be linked.

@shivam-Purohit
Copy link
Contributor Author

@shivam-Purohit you can also add the InfraIDs along with what you mentioned so that it infras within the environment can be linked.

sure!

@shivam-Purohit
Copy link
Contributor Author

shivam-Purohit commented Jan 9, 2024

ubuntuMachine  Running  - Oracle VM VirtualBox 09-01-2024 19_38_40

i also added the environment type after the screenshot was taken. Switched the structure to row like as it was overflowing and difficult to manage in table format. Hope this helps @SarthakJain26

@SarthakJain26
Copy link
Collaborator

@shivam-Purohit can you please fix the fmt issues due to which build pipeline is failing and also sign your commits so that DCO can pass. We can then merge the PR

@shivam-Purohit
Copy link
Contributor Author

can you please fix the fmt issues due to which build pipeline is failing and also sign your commits so that DCO can pass. We can then merge the PR

should I squash the commits into one?

@Nageshbansal
Copy link
Collaborator

Nageshbansal commented Jan 11, 2024

@shivam-Purohit Squashing the commit is not required ( it will be taken care of while merging) , for now please fix the fmt in go files ( you can use gofmt ./... command to format the go files)

@Nageshbansal
Copy link
Collaborator

@shivam-Purohit
Copy link
Contributor Author

@Nageshbansal my first commit was unsigned i could not find any other way to sign it. So I merged it. If the workflows get approval i can test the changes i just made . I use gofmt -w . that should be able to get rid of the fmt error

@shivam-Purohit
Copy link
Contributor Author

@shivam-Purohit can you please fix the fmt issues due to which build pipeline is failing and also sign your commits so that DCO can pass. We can then merge the PR

@SarthakJain26 can you run the workflow again ig this should be fine now at least the fmt error

if environmentListData[i].EnvironmentID == environmentID {
intUpdateTime, err := strconv.ParseInt(environmentListData[i].UpdatedAt, 10, 64)
if err != nil {
fmt.Println("Error converting UpdatedAt to int64:", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

utils.Red.Println

utils.White_B.Print("\nEnter the Project ID: ")
fmt.Scanln(&projectID)

for projectID == "" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use if here?

Copy link
Contributor Author

@shivam-Purohit shivam-Purohit Jan 12, 2024

Choose a reason for hiding this comment

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

I picked it from experiments get command so the same code is repeated there but doesn't make any sense to put for and then exit anyway. If would be a better choice

utils.White_B.Print("\nEnter the Environment ID: ")
fmt.Scanln(&environmentID)

for environmentID == "" {
Copy link
Collaborator

@Jonsy13 Jonsy13 Jan 12, 2024

Choose a reason for hiding this comment

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

Can we use if here?

updatedTime := time.Unix(intUpdateTime, 0).String()
intCreatedTime, err := strconv.ParseInt(environmentListData[i].CreatedAt, 10, 64)
if err != nil {
fmt.Println("Error converting CreatedAt to int64:", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

utils.Red.Println

@Saranya-jena
Copy link
Collaborator

Please make the changes suggested by @Jonsy13 . Rest all looks good. 🚀

Signed-off-by: Shivam Purohit <[email protected]>
@shivam-Purohit
Copy link
Contributor Author

shivam-Purohit commented Jan 12, 2024

@Jonsy13 @Saranya-jena I made the changes suggested you can take a look. Suggest if any further changes needs to be done.

@SarthakJain26
Copy link
Collaborator

@shivam-Purohit please fix the build pipeline

Signed-off-by: Shivam Purohit <[email protected]>
@shivam-Purohit
Copy link
Contributor Author

@SarthakJain26 fixed the fmt error. Hope it resolves the build workflow

@shivam-Purohit
Copy link
Contributor Author

Looks like it worked!

@SarthakJain26 SarthakJain26 merged commit cf8c33a into litmuschaos:master Jan 15, 2024
4 checks passed
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.

5 participants