Compare commits
36 Commits
Author | SHA1 | Date |
---|---|---|
|
9f36304f0d | |
|
3ce353dcfc | |
|
9c4c3351ac | |
|
094d1ec037 | |
|
b1dba98cfb | |
|
f06f4f9d52 | |
|
734ea7dcb3 | |
|
902cab3da2 | |
|
1780d64f2f | |
|
32f32320d6 | |
|
ff915a9b2e | |
|
0980230d37 | |
|
4f498493a6 | |
|
5b4f3cd6c8 | |
|
327ffaa710 | |
|
86377b15a1 | |
|
ca5e75b3df | |
|
a422a8a7a5 | |
|
fd531ae0e0 | |
|
06bfd1a21c | |
|
f8426a7006 | |
|
c34fbbc134 | |
|
34a2702e07 | |
|
d5b1d839cd | |
|
a6b5157f7e | |
|
5d8e1be588 | |
|
d304f7d7a4 | |
|
025938a208 | |
|
2ff8c1fa5d | |
|
47ba363e58 | |
|
6b276da3af | |
|
1a69cc5d24 | |
|
6c628850a7 | |
|
49ebc8b936 | |
|
95fad15b01 | |
|
9fe2a37e07 |
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
"""Extract steps containing special env variable COMMIT_HOOKS from Github workflow"""
|
||||
import yaml
|
||||
import argparse
|
||||
|
||||
# Parse command-line arguments
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("workflow_file",
|
||||
help="Path to the GitHub Actions workflow file")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
# Load the GitHub Actions workflow file as YAML
|
||||
with open(args.workflow_file, "r") as file:
|
||||
data = yaml.safe_load(file)
|
||||
|
||||
print("#!/bin/bash")
|
||||
# Loop over all jobs
|
||||
for job_name, job in data["jobs"].items():
|
||||
# Loop over all steps in the job
|
||||
for step in job["steps"]:
|
||||
# Check if the step has a KCIDB_HOOKS environment variable
|
||||
if "env" in step and step["env"].get("COMMIT_HOOKS") == "pre-commit":
|
||||
# Print the name of the step
|
||||
print(f"\n# {step['name']}")
|
||||
# Extract the command(s) from the step
|
||||
command = step.get("run", [])
|
||||
# Print the command(s)
|
||||
for line in command if isinstance(command, list) else [command]:
|
||||
print(line)
|
|
@ -0,0 +1,6 @@
|
|||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "gomod"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
|
@ -19,6 +19,8 @@ jobs:
|
|||
uses: actions/checkout@v2
|
||||
|
||||
- name: gofmt check
|
||||
env:
|
||||
COMMIT_HOOKS: pre-commit
|
||||
run: |
|
||||
if [ "$(gofmt -s -l . | wc -l)" -ne 0 ]
|
||||
then
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
name: release-pipeline
|
||||
on:
|
||||
create:
|
||||
tags:
|
||||
- '**'
|
||||
|
||||
jobs:
|
||||
homebrew:
|
||||
name: Bump Homebrew formula
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Extract version
|
||||
id: extract-version
|
||||
run: |
|
||||
echo "tag-name=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
|
||||
|
||||
- uses: mislav/bump-homebrew-formula-action@v3
|
||||
with:
|
||||
formula-name: litmusctl
|
||||
tag-name: ${{ steps.extract-version.outputs.tag-name }}
|
||||
download-url: https://github.com/litmuschaos/litmusctl/archive/refs/tags/${{ steps.extract-version.outputs.tag-name }}.tar.gz
|
||||
env:
|
||||
COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }}
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
# If there are whitespace errors, print the offending file names and fail.
|
||||
# git diff-index --check --cached $against --
|
||||
|
||||
# Execute steps extracted from GitHub Actions
|
||||
. <(./.github-workflow-script .github/workflows/build.yml)
|
|
@ -70,6 +70,16 @@ To run tests, use the following command:
|
|||
go test ./...
|
||||
```
|
||||
|
||||
## **Contributing Prerequisites**
|
||||
|
||||
Setting up pre-commit:
|
||||
|
||||
Execute the following command to create a symbolic link named `pre-commit` in the `.git/hooks` directory that points to the `.pre-commit`.
|
||||
|
||||
```bash
|
||||
ln -s ../../.pre-commit .git/hooks/pre-commit
|
||||
```
|
||||
|
||||
## **Contributing Guidelines**
|
||||
|
||||
If you wish to contribute to **`litmusctl`**, please follow our [contributing guidelines](https://github.com/litmuschaos/litmus/blob/master/CONTRIBUTING.md). Your contributions are valuable, and adhering to these guidelines ensures a smooth and collaborative development process.
|
||||
|
|
234
README.md
234
README.md
|
@ -30,6 +30,71 @@ To check compatibility of litmusctl with Chaos Center
|
|||
<th>litmusctl version</th>
|
||||
<th>Lowest Chaos Center supported version</th>
|
||||
<th>Highest Chaos Center supported version</th>
|
||||
<tr>
|
||||
<td>1.16.0</td>
|
||||
<td>3.0.0</td>
|
||||
<td>3.19.0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1.15.0</td>
|
||||
<td>3.0.0</td>
|
||||
<td>3.18.0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1.14.0</td>
|
||||
<td>3.0.0</td>
|
||||
<td>3.15.0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1.13.0</td>
|
||||
<td>3.0.0</td>
|
||||
<td>3.14.0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1.12.0</td>
|
||||
<td>3.0.0</td>
|
||||
<td>3.13.0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1.11.0</td>
|
||||
<td>3.0.0</td>
|
||||
<td>3.12.0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1.10.0</td>
|
||||
<td>3.0.0</td>
|
||||
<td>3.11.0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1.9.0</td>
|
||||
<td>3.0.0</td>
|
||||
<td>3.10.0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1.8.0</td>
|
||||
<td>3.0.0</td>
|
||||
<td>3.9.1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1.7.0</td>
|
||||
<td>3.0.0</td>
|
||||
<td>3.8.0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1.6.0</td>
|
||||
<td>3.0.0</td>
|
||||
<td>3.7.0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1.5.0</td>
|
||||
<td>3.0.0</td>
|
||||
<td>3.6.0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1.4.0</td>
|
||||
<td>3.0.0</td>
|
||||
<td>3.5.0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>1.3.0</td>
|
||||
<td>3.0.0</td>
|
||||
|
@ -50,31 +115,6 @@ To check compatibility of litmusctl with Chaos Center
|
|||
<td>3.0.0</td>
|
||||
<td>3.1.0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>0.24.0</td>
|
||||
<td>3.0.0-beta9</td>
|
||||
<td>3.0.0-beta12</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>0.23.0</td>
|
||||
<td>3.0.0-beta9</td>
|
||||
<td>3.0.0-beta12</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>0.22.0</td>
|
||||
<td>2.9.0</td>
|
||||
<td>3.0.0-beta8</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>0.21.0</td>
|
||||
<td>2.9.0</td>
|
||||
<td>3.0.0-beta8</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>0.20.0</td>
|
||||
<td>2.9.0</td>
|
||||
<td>3.0.0-beta8</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
## Installation
|
||||
|
@ -83,109 +123,109 @@ To install the latest version of litmusctl follow the below steps:
|
|||
|
||||
<table>
|
||||
<th>Platforms</th>
|
||||
<th>1.3.0</th>
|
||||
<th>1.2.0</th>
|
||||
<th>1.1.0</th>
|
||||
<th>1.0.0</th>
|
||||
<th>0.24.0</th>
|
||||
<th>0.23.0</th>
|
||||
<th>0.22.0</th>
|
||||
<th>0.21.0</th>
|
||||
<th>1.16.0</th>
|
||||
<th>1.15.0</th>
|
||||
<th>1.14.0</th>
|
||||
<th>1.13.0</th>
|
||||
<th>1.12.0</th>
|
||||
<th>1.11.0</th>
|
||||
<th>1.10.0</th>
|
||||
<th>1.9.0</th>
|
||||
<th>master(Unreleased)</th>
|
||||
<tr>
|
||||
<td>litmusctl-darwin-amd64 (MacOS)</td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-darwin-amd64-1.3.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-darwin-amd64-1.2.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-darwin-amd64-1.1.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-darwin-amd64-1.0.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-darwin-amd64-0.24.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-darwin-amd64-0.23.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-darwin-amd64-0.22.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-darwin-amd64-0.21.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-darwin-amd64-1.16.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-darwin-amd64-1.15.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-darwin-amd64-1.14.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-darwin-amd64-1.13.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-darwin-amd64-1.12.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-darwin-amd64-1.11.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-darwin-amd64-1.10.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-darwin-amd64-1.9.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-darwin-amd64-master.tar.gz">Click here</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>litmusctl-linux-386</td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-386-1.3.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-386-1.2.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-386-1.1.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-386-1.0.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-386-0.24.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-386-0.23.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-386-0.22.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-386-0.21.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-386-1.16.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-386-1.15.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-386-1.14.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-386-1.13.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-386-1.12.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-386-1.11.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-386-1.10.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-386-1.9.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-386-master.tar.gz">Click here</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>litmusctl-linux-amd64</td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-amd64-1.3.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-amd64-1.2.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-amd64-1.1.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-amd64-1.0.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-amd64-0.24.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-amd64-0.23.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-amd64-0.22.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-amd64-0.21.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-amd64-1.16.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-amd64-1.15.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-amd64-1.14.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-amd64-1.13.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-amd64-1.12.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-amd64-1.11.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-amd64-1.10.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-amd64-1.9.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-amd64-master.tar.gz">Click here</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>litmusctl-linux-arm</td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm-1.3.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm-1.2.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm-1.1.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm-1.0.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm-0.24.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm-0.23.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm-0.22.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm-0.21.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm-1.16.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm-1.15.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm-1.14.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm-1.13.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm-1.12.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm-1.11.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm-1.10.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm-1.9.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm-master.tar.gz">Click here</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>litmusctl-linux-arm64</td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm64-1.3.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm64-1.2.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm64-1.1.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm64-1.0.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm64-0.24.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm64-0.23.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm64-0.22.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm64-0.21.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm64-1.16.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm64-1.15.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm64-1.14.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm64-1.13.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm64-1.12.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm64-1.11.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm64-1.10.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm64-1.9.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-linux-arm64-master.tar.gz">Click here</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>litmusctl-windows-386</td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-386-1.3.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-386-1.2.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-386-1.1.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-386-1.0.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-386-0.24.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-386-0.23.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-386-0.22.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-386-0.21.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-386-1.16.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-386-1.15.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-386-1.14.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-386-1.13.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-386-1.12.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-386-1.11.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-386-1.10.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-386-1.9.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-386-master.tar.gz">Click here</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>litmusctl-windows-amd64</td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-amd64-1.3.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-amd64-1.2.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-amd64-1.1.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-amd64-1.0.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-amd64-0.24.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-amd64-0.23.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-amd64-0.22.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-amd64-0.21.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-amd64-1.16.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-amd64-1.15.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-amd64-1.14.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-amd64-1.13.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-amd64-1.12.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-amd64-1.11.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-amd64-1.10.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-amd64-1.9.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-amd64-master.tar.gz">Click here</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>litmusctl-windows-arm</td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-arm-1.3.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-arm-1.2.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-arm-1.1.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-arm-1.0.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-arm-0.24.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-arm-0.23.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-arm-0.22.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-arm-0.21.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-arm-1.16.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-arm-1.15.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-arm-1.14.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-arm-1.13.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-arm-1.12.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-arm-1.11.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-arm-1.10.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-arm-1.9.0.tar.gz">Click here</a></td>
|
||||
<td><a href="https://litmusctl-production-bucket.s3.amazonaws.com/litmusctl-windows-arm-master.tar.gz">Click here</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
|
@ -174,14 +174,11 @@ Installation Mode: cluster
|
|||
|
||||
🤷 Do you want to continue with the above details? [Y/N]: Y
|
||||
👍 Continuing Chaos Infrastructure connection!!
|
||||
Applying YAML:
|
||||
https://preview.litmuschaos.io/api/file/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbHVzdGVyX2lkIjoiMDUyZmFlN2UtZGM0MS00YmU4LWJiYTgtMmM4ZTYyNDFkN2I0In0.i31QQDG92X5nD6P_-7TfeAAarZqLvUTFfnAghJYXPiM.yaml
|
||||
|
||||
💡 Connecting Chaos Infrastructure to ChaosCenter.
|
||||
🏃 Chaos Infrastructure is running!!
|
||||
|
||||
🚀 Chaos Infrastructure Connection Successful!! 🎉
|
||||
👉 Litmus Chaos Infrastructure can be accessed here: https://preview.litmuschaos.io/targets
|
||||
```
|
||||
|
||||
#### Verify the new Chaos Infrastructure Connection\*\*
|
||||
|
@ -240,6 +237,18 @@ Enter the Chaos Experiment ID: test_exp
|
|||
|
||||
### Additional commands
|
||||
|
||||
- To change the ChaosCenter account's password use the `update password` command:
|
||||
|
||||
```shell
|
||||
litmusctl update password
|
||||
✓ Username: admin
|
||||
✓ Old Password: ********
|
||||
✓ New Password: ********
|
||||
✓ Confirm Password: ********
|
||||
|
||||
Password updated successfully!
|
||||
```
|
||||
|
||||
- To view the current configuration of `.litmusconfig`, type:
|
||||
|
||||
```shell
|
||||
|
@ -313,6 +322,20 @@ Enter the Environment Name: test2
|
|||
🚀 New Chaos Environment creation successful!! 🎉
|
||||
```
|
||||
|
||||
- To delete an Environment, apply the following command :
|
||||
|
||||
```shell
|
||||
litmusctl delete chaos-environment
|
||||
|
||||
Enter the Project ID: eb7fc0a0-5878-4454-a9db-b67d283713bc
|
||||
|
||||
Enter the Environment ID: testenv
|
||||
|
||||
Are you sure you want to delete this Chaos Environment? (y/n):y
|
||||
|
||||
🚀 Chaos Environment deleted successfully.
|
||||
```
|
||||
|
||||
- To view all the projects with the user, use the `get projects` command.
|
||||
|
||||
```shell
|
||||
|
|
|
@ -167,15 +167,12 @@ Service Account: litmus (new)
|
|||
Installation Mode: cluster
|
||||
|
||||
🤷 Do you want to continue with the above details? [Y/N]: Y
|
||||
👍 Continuing Chaos Delegate connection!!
|
||||
Applying YAML:
|
||||
https://preview.litmuschaos.io/api/file/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbHVzdGVyX2lkIjoiMDUyZmFlN2UtZGM0MS00YmU4LWJiYTgtMmM4ZTYyNDFkN2I0In0.i31QQDG92X5nD6P_-7TfeAAarZqLvUTFfnAghJYXPiM.yaml
|
||||
👍 Continuing Chaos Infrastructure connection!!
|
||||
|
||||
💡 Connecting Chaos Delegate to ChaosCenter.
|
||||
💡 Connecting Chaos Infrastructure to ChaosCenter.
|
||||
🏃 Chaos Delegate is running!!
|
||||
|
||||
🚀 Chaos Delegate Connection Successful!! 🎉
|
||||
👉 Litmus Chaos Delegates can be accessed here: https://preview.litmuschaos.io/targets
|
||||
🚀 Chaos Infrastructure Connection Successful!! 🎉
|
||||
```
|
||||
|
||||
#### Verify the new Chaos Delegate Connection\*\*
|
||||
|
@ -203,6 +200,18 @@ litmusctl create chaos-scenario -f custom-chaos-scenario.yml --project-id="" --c
|
|||
|
||||
### Additional commands
|
||||
|
||||
- To change the ChaosCenter account's password use the `update password` command:
|
||||
|
||||
```shell
|
||||
litmusctl update password
|
||||
✓ Username: admin
|
||||
✓ Old Password: ********
|
||||
✓ New Password: ********
|
||||
✓ Confirm Password: ********
|
||||
|
||||
Password updated successfully!
|
||||
```
|
||||
|
||||
- To view the current configuration of `.litmusconfig`, type:
|
||||
|
||||
```shell
|
||||
|
|
100
go.mod
100
go.mod
|
@ -1,81 +1,87 @@
|
|||
module github.com/litmuschaos/litmusctl
|
||||
|
||||
go 1.20
|
||||
go 1.21
|
||||
|
||||
require (
|
||||
github.com/argoproj/argo-workflows/v3 v3.3.1
|
||||
github.com/fatih/color v1.13.0
|
||||
github.com/argoproj/argo-workflows/v3 v3.5.5
|
||||
github.com/fatih/color v1.17.0
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible
|
||||
github.com/gorhill/cronexpr v0.0.0-20180427100037-88b0669f7d75
|
||||
github.com/litmuschaos/chaos-operator v0.0.0-20230718113617-6819a4be12e4
|
||||
github.com/litmuschaos/litmus/chaoscenter/graphql/server v0.0.0-20240115142759-7a29dc1eb1d8
|
||||
github.com/manifoldco/promptui v0.9.0
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
github.com/spf13/cobra v1.3.0
|
||||
github.com/spf13/viper v1.10.1
|
||||
github.com/sirupsen/logrus v1.9.3
|
||||
github.com/spf13/cobra v1.8.0
|
||||
github.com/spf13/viper v1.18.2
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
k8s.io/api v0.27.3
|
||||
k8s.io/apimachinery v0.27.3
|
||||
k8s.io/api v0.29.2
|
||||
k8s.io/apimachinery v0.29.2
|
||||
k8s.io/client-go v12.0.0+incompatible
|
||||
sigs.k8s.io/yaml v1.3.0
|
||||
sigs.k8s.io/yaml v1.4.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/chzyer/readline v1.5.1 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.5.1 // indirect
|
||||
github.com/go-logr/logr v1.2.3 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.19.6 // indirect
|
||||
github.com/go-openapi/jsonreference v0.20.1 // indirect
|
||||
github.com/go-openapi/swag v0.22.3 // indirect
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||
github.com/emicklei/go-restful/v3 v3.12.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
github.com/go-logr/logr v1.4.1 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.21.0 // indirect
|
||||
github.com/go-openapi/jsonreference v0.21.0 // indirect
|
||||
github.com/go-openapi/swag v0.23.0 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/google/gnostic v0.5.7-v3refs // indirect
|
||||
github.com/google/go-cmp v0.5.9 // indirect
|
||||
github.com/golang/protobuf v1.5.4 // indirect
|
||||
github.com/google/gnostic v0.7.0 // indirect
|
||||
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
|
||||
github.com/google/gofuzz v1.2.0 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/imdario/mergo v0.3.12 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||
github.com/imdario/mergo v0.3.13 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/josharian/intern v1.0.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/magiconair/properties v1.8.5 // indirect
|
||||
github.com/magiconair/properties v1.8.7 // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/mattn/go-colorable v0.1.12 // indirect
|
||||
github.com/mattn/go-isatty v0.0.17 // indirect
|
||||
github.com/mitchellh/mapstructure v1.4.3 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/pelletier/go-toml v1.9.4 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/spf13/afero v1.8.0 // indirect
|
||||
github.com/spf13/cast v1.4.1 // indirect
|
||||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
|
||||
github.com/sagikazarmark/locafero v0.4.0 // indirect
|
||||
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
|
||||
github.com/sourcegraph/conc v0.3.0 // indirect
|
||||
github.com/spf13/afero v1.11.0 // indirect
|
||||
github.com/spf13/cast v1.6.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/subosito/gotenv v1.2.0 // indirect
|
||||
golang.org/x/net v0.17.0 // indirect
|
||||
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
|
||||
golang.org/x/sys v0.13.0 // indirect
|
||||
golang.org/x/term v0.13.0 // indirect
|
||||
golang.org/x/text v0.13.0 // indirect
|
||||
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/genproto v0.0.0-20220218161850-94dd64e39d7c // indirect
|
||||
google.golang.org/grpc v1.44.0 // indirect
|
||||
google.golang.org/protobuf v1.28.1 // indirect
|
||||
github.com/subosito/gotenv v1.6.0 // indirect
|
||||
go.uber.org/atomic v1.9.0 // indirect
|
||||
go.uber.org/multierr v1.9.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
|
||||
golang.org/x/net v0.22.0 // indirect
|
||||
golang.org/x/oauth2 v0.18.0 // indirect
|
||||
golang.org/x/sys v0.18.0 // indirect
|
||||
golang.org/x/term v0.18.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
golang.org/x/time v0.5.0 // indirect
|
||||
google.golang.org/appengine v1.6.8 // indirect
|
||||
google.golang.org/genproto v0.0.0-20240311173647-c811ad7063a7 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240311173647-c811ad7063a7 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240311173647-c811ad7063a7 // indirect
|
||||
google.golang.org/grpc v1.62.1 // indirect
|
||||
google.golang.org/protobuf v1.33.0 // indirect
|
||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||
gopkg.in/ini.v1 v1.66.3 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
k8s.io/klog/v2 v2.90.1 // indirect
|
||||
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
|
||||
k8s.io/utils v0.0.0-20230209194617-a36077c30491 // indirect
|
||||
k8s.io/klog/v2 v2.120.1 // indirect
|
||||
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
|
||||
k8s.io/utils v0.0.0-20240310230437-4693a0247e57 // indirect
|
||||
sigs.k8s.io/controller-runtime v0.11.1 // indirect
|
||||
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
|
||||
)
|
||||
|
||||
// Pinned to kubernetes-1.21.2
|
||||
|
|
|
@ -51,7 +51,7 @@ func CreateEnvironment(pid string, request models.CreateEnvironmentRequest, cred
|
|||
}
|
||||
}
|
||||
|
||||
func GetEnvironmentList(pid string, cred types.Credentials) (ListEnvironmentData, error) {
|
||||
func ListChaosEnvironments(pid string, cred types.Credentials) (ListEnvironmentData, error) {
|
||||
var err error
|
||||
var gqlReq CreateEnvironmentListGQLRequest
|
||||
gqlReq.Query = ListEnvironmentQuery
|
||||
|
@ -93,3 +93,91 @@ func GetEnvironmentList(pid string, cred types.Credentials) (ListEnvironmentData
|
|||
return ListEnvironmentData{}, err
|
||||
}
|
||||
}
|
||||
func GetChaosEnvironment(pid string, envid string, cred types.Credentials) (GetEnvironmentData, error) {
|
||||
var err error
|
||||
var gqlReq CreateEnvironmentGetGQLRequest
|
||||
gqlReq.Query = GetEnvironmentQuery
|
||||
|
||||
gqlReq.Variables.ProjectID = pid
|
||||
gqlReq.Variables.EnvironmentID = envid
|
||||
query, err := json.Marshal(gqlReq)
|
||||
if err != nil {
|
||||
return GetEnvironmentData{}, err
|
||||
}
|
||||
resp, err := apis.SendRequest(
|
||||
apis.SendRequestParams{
|
||||
Endpoint: cred.ServerEndpoint + utils.GQLAPIPath,
|
||||
Token: cred.Token,
|
||||
},
|
||||
query,
|
||||
string(types.Post),
|
||||
)
|
||||
if err != nil {
|
||||
return GetEnvironmentData{}, errors.New("Error in Getting Chaos Environment: " + err.Error())
|
||||
}
|
||||
bodyBytes, err := io.ReadAll(resp.Body)
|
||||
defer resp.Body.Close()
|
||||
if err != nil {
|
||||
return GetEnvironmentData{}, errors.New("Error in Getting Chaos Environment: " + err.Error())
|
||||
}
|
||||
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
var getEnvironment GetEnvironmentData
|
||||
err = json.Unmarshal(bodyBytes, &getEnvironment)
|
||||
if err != nil {
|
||||
return GetEnvironmentData{}, errors.New("Error in Getting Chaos Environment: " + err.Error())
|
||||
}
|
||||
if len(getEnvironment.Errors) > 0 {
|
||||
return GetEnvironmentData{}, errors.New(getEnvironment.Errors[0].Message)
|
||||
}
|
||||
return getEnvironment, nil
|
||||
} else {
|
||||
return GetEnvironmentData{}, err
|
||||
}
|
||||
}
|
||||
|
||||
func DeleteEnvironment(pid string, envid string, cred types.Credentials) (DeleteChaosEnvironmentData, error) {
|
||||
var err error
|
||||
var gqlReq CreateEnvironmentDeleteGQLRequest
|
||||
gqlReq.Query = DeleteEnvironmentQuery
|
||||
|
||||
gqlReq.Variables.EnvironmentID = envid
|
||||
gqlReq.Variables.ProjectID = pid
|
||||
query, err := json.Marshal(gqlReq)
|
||||
if err != nil {
|
||||
return DeleteChaosEnvironmentData{}, err
|
||||
}
|
||||
resp, err := apis.SendRequest(
|
||||
apis.SendRequestParams{
|
||||
Endpoint: cred.ServerEndpoint + utils.GQLAPIPath,
|
||||
Token: cred.Token,
|
||||
},
|
||||
query,
|
||||
string(types.Post),
|
||||
)
|
||||
if err != nil {
|
||||
return DeleteChaosEnvironmentData{}, errors.New("Error in Deleting Chaos Environment: " + err.Error())
|
||||
}
|
||||
|
||||
bodyBytes, err := io.ReadAll(resp.Body)
|
||||
defer resp.Body.Close()
|
||||
if err != nil {
|
||||
return DeleteChaosEnvironmentData{}, errors.New("Error in Deleting Chaos Environment: " + err.Error())
|
||||
}
|
||||
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
var deletedEnvironment DeleteChaosEnvironmentData
|
||||
err = json.Unmarshal(bodyBytes, &deletedEnvironment)
|
||||
if err != nil {
|
||||
return DeleteChaosEnvironmentData{}, err
|
||||
}
|
||||
|
||||
if len(deletedEnvironment.Errors) > 0 {
|
||||
return DeleteChaosEnvironmentData{}, errors.New(deletedEnvironment.Errors[0].Message)
|
||||
}
|
||||
|
||||
return deletedEnvironment, nil
|
||||
} else {
|
||||
return DeleteChaosEnvironmentData{}, errors.New("Error while deleting the Chaos Environment")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,24 @@ const (
|
|||
}
|
||||
}
|
||||
`
|
||||
GetEnvironmentQuery = `query getEnvironment($projectID: ID!, $environmentID : ID!) {
|
||||
getEnvironment(projectID: $projectID,environmentID: $environmentID){
|
||||
environmentID
|
||||
name
|
||||
createdAt
|
||||
updatedAt
|
||||
createdBy{
|
||||
username
|
||||
}
|
||||
updatedBy{
|
||||
username
|
||||
}
|
||||
infraIDs
|
||||
type
|
||||
tags
|
||||
}
|
||||
}`
|
||||
|
||||
ListEnvironmentQuery = `query listEnvironments($projectID: ID!, $request: ListEnvironmentRequest) {
|
||||
listEnvironments(projectID: $projectID,request: $request){
|
||||
environments {
|
||||
|
@ -29,4 +47,11 @@ const (
|
|||
}
|
||||
}
|
||||
}`
|
||||
|
||||
DeleteEnvironmentQuery = `mutation deleteEnvironment($projectID: ID!, $environmentID: ID!) {
|
||||
deleteEnvironment(
|
||||
projectID: $projectID
|
||||
environmentID: $environmentID
|
||||
)
|
||||
}`
|
||||
)
|
||||
|
|
|
@ -22,6 +22,26 @@ type CreateEnvironmentData struct {
|
|||
EnvironmentDetails model.Environment `json:"createEnvironment"`
|
||||
}
|
||||
|
||||
type GetEnvironmentData struct {
|
||||
Errors []struct {
|
||||
Message string `json:"message"`
|
||||
Path []string `json:"path"`
|
||||
} `json:"errors"`
|
||||
Data GetEnvironment `json:"data"`
|
||||
}
|
||||
|
||||
type GetEnvironment struct {
|
||||
EnvironmentDetails model.Environment `json:"getEnvironment"`
|
||||
}
|
||||
|
||||
type CreateEnvironmentGetGQLRequest struct {
|
||||
Query string `json:"query"`
|
||||
Variables struct {
|
||||
ProjectID string `json:"projectID"`
|
||||
EnvironmentID string `json:"environmentID"`
|
||||
}
|
||||
}
|
||||
|
||||
type ListEnvironmentData struct {
|
||||
Errors []struct {
|
||||
Message string `json:"message"`
|
||||
|
@ -41,3 +61,23 @@ type CreateEnvironmentListGQLRequest struct {
|
|||
Request model.ListEnvironmentRequest `json:"request"`
|
||||
}
|
||||
}
|
||||
|
||||
type CreateEnvironmentDeleteGQLRequest struct {
|
||||
Query string `json:"query"`
|
||||
Variables struct {
|
||||
ProjectID string `json:"projectID"`
|
||||
EnvironmentID string `json:"environmentID"`
|
||||
}
|
||||
}
|
||||
|
||||
type DeleteChaosEnvironmentData struct {
|
||||
Errors []struct {
|
||||
Message string `json:"message"`
|
||||
Path []string `json:"path"`
|
||||
} `json:"errors"`
|
||||
Data DeleteChaosEnvironmentDetails `json:"data"`
|
||||
}
|
||||
|
||||
type DeleteChaosEnvironmentDetails struct {
|
||||
DeleteChaosEnvironment string `json:"deleteChaosExperiment"`
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ const (
|
|||
infraID
|
||||
name
|
||||
token
|
||||
manifest
|
||||
}
|
||||
}
|
||||
`
|
||||
|
|
|
@ -0,0 +1,197 @@
|
|||
package probe
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
models "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model"
|
||||
"github.com/litmuschaos/litmusctl/pkg/apis"
|
||||
"github.com/litmuschaos/litmusctl/pkg/types"
|
||||
"github.com/litmuschaos/litmusctl/pkg/utils"
|
||||
)
|
||||
|
||||
func GetProbeRequest(pid string, probeID string, cred types.Credentials) (GetProbeResponse, error) {
|
||||
var gqlReq GetProbeGQLRequest
|
||||
gqlReq.Query = GetProbeQuery
|
||||
gqlReq.Variables.ProjectID = pid
|
||||
gqlReq.Variables.ProbeName = probeID
|
||||
|
||||
query, err := json.Marshal(gqlReq)
|
||||
if err != nil {
|
||||
return GetProbeResponse{}, errors.New("Error in getting requested probe" + err.Error())
|
||||
}
|
||||
|
||||
resp, err := apis.SendRequest(
|
||||
apis.SendRequestParams{
|
||||
Endpoint: cred.ServerEndpoint + utils.GQLAPIPath,
|
||||
Token: cred.Token,
|
||||
},
|
||||
query,
|
||||
string(types.Post),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return GetProbeResponse{}, errors.New("Error in getting requested probe" + err.Error())
|
||||
}
|
||||
|
||||
bodyBytes, err := io.ReadAll(resp.Body)
|
||||
defer resp.Body.Close()
|
||||
if err != nil {
|
||||
return GetProbeResponse{}, errors.New("Error in getting requested probe" + err.Error())
|
||||
}
|
||||
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
var getProbeResponse GetProbeResponse
|
||||
err = json.Unmarshal(bodyBytes, &getProbeResponse)
|
||||
if err != nil {
|
||||
return GetProbeResponse{}, errors.New("Error in getting requested probe" + err.Error())
|
||||
}
|
||||
if len(getProbeResponse.Errors) > 0 {
|
||||
return GetProbeResponse{}, errors.New(getProbeResponse.Errors[0].Message)
|
||||
}
|
||||
return getProbeResponse, nil
|
||||
|
||||
} else {
|
||||
return GetProbeResponse{}, errors.New("Unmatched status code:" + string(bodyBytes))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func ListProbeRequest(pid string, probetypes []*models.ProbeType, cred types.Credentials) (ListProbeResponse, error) {
|
||||
var gqlReq ListProbeGQLRequest
|
||||
gqlReq.Query = ListProbeQuery
|
||||
gqlReq.Variables.ProjectID = pid
|
||||
gqlReq.Variables.Filter = models.ProbeFilterInput{
|
||||
Type: probetypes,
|
||||
}
|
||||
|
||||
query, err := json.Marshal(gqlReq)
|
||||
if err != nil {
|
||||
return ListProbeResponse{}, errors.New("Error in listing probes" + err.Error())
|
||||
}
|
||||
resp, err := apis.SendRequest(
|
||||
apis.SendRequestParams{
|
||||
Endpoint: cred.ServerEndpoint + utils.GQLAPIPath,
|
||||
Token: cred.Token,
|
||||
},
|
||||
query,
|
||||
string(types.Post),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return ListProbeResponse{}, errors.New("Error in listing probes" + err.Error())
|
||||
}
|
||||
|
||||
bodyBytes, err := io.ReadAll(resp.Body)
|
||||
defer resp.Body.Close()
|
||||
if err != nil {
|
||||
return ListProbeResponse{}, errors.New("Error in listing probes" + err.Error())
|
||||
}
|
||||
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
var listProbeResponse ListProbeResponse
|
||||
err = json.Unmarshal(bodyBytes, &listProbeResponse)
|
||||
if err != nil {
|
||||
return ListProbeResponse{}, errors.New("Error in listing probes" + err.Error())
|
||||
}
|
||||
if len(listProbeResponse.Errors) > 0 {
|
||||
return ListProbeResponse{}, errors.New(listProbeResponse.Errors[0].Message)
|
||||
}
|
||||
return listProbeResponse, nil
|
||||
|
||||
} else {
|
||||
return ListProbeResponse{}, errors.New("Unmatched status code:" + string(bodyBytes))
|
||||
}
|
||||
}
|
||||
|
||||
func DeleteProbeRequest(pid string, probeid string, cred types.Credentials) (DeleteProbeResponse, error) {
|
||||
var gqlReq DeleteProbeGQLRequest
|
||||
gqlReq.Query = DeleteProbeQuery
|
||||
gqlReq.Variables.ProjectID = pid
|
||||
gqlReq.Variables.ProbeName = probeid
|
||||
|
||||
query, err := json.Marshal(gqlReq)
|
||||
if err != nil {
|
||||
return DeleteProbeResponse{}, errors.New("Error in deleting probe" + err.Error())
|
||||
}
|
||||
resp, err := apis.SendRequest(
|
||||
apis.SendRequestParams{
|
||||
Endpoint: cred.ServerEndpoint + utils.GQLAPIPath,
|
||||
Token: cred.Token,
|
||||
},
|
||||
query,
|
||||
string(types.Post),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return DeleteProbeResponse{}, errors.New("Error in deleting probe" + err.Error())
|
||||
}
|
||||
|
||||
bodyBytes, err := io.ReadAll(resp.Body)
|
||||
defer resp.Body.Close()
|
||||
if err != nil {
|
||||
return DeleteProbeResponse{}, errors.New("Error in deleting probe" + err.Error())
|
||||
}
|
||||
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
var deleteProbeResponse DeleteProbeResponse
|
||||
err = json.Unmarshal(bodyBytes, &deleteProbeResponse)
|
||||
if err != nil {
|
||||
return DeleteProbeResponse{}, errors.New("Error in deleting probe" + err.Error())
|
||||
}
|
||||
if len(deleteProbeResponse.Errors) > 0 {
|
||||
return DeleteProbeResponse{}, errors.New(deleteProbeResponse.Errors[0].Message)
|
||||
}
|
||||
return deleteProbeResponse, nil
|
||||
|
||||
} else {
|
||||
return DeleteProbeResponse{}, errors.New("Unmatched status code:" + string(bodyBytes))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func GetProbeYAMLRequest(pid string, request models.GetProbeYAMLRequest, cred types.Credentials) (GetProbeYAMLResponse, error) {
|
||||
var gqlReq GetProbeYAMLGQLRequest
|
||||
gqlReq.Query = GetProbeYAMLQuery
|
||||
gqlReq.Variables.ProjectID = pid
|
||||
gqlReq.Variables.Request = request
|
||||
|
||||
query, err := json.Marshal(gqlReq)
|
||||
if err != nil {
|
||||
return GetProbeYAMLResponse{}, errors.New("Error in getting probe details" + err.Error())
|
||||
}
|
||||
resp, err := apis.SendRequest(
|
||||
apis.SendRequestParams{
|
||||
Endpoint: cred.ServerEndpoint + utils.GQLAPIPath,
|
||||
Token: cred.Token,
|
||||
},
|
||||
query,
|
||||
string(types.Post),
|
||||
)
|
||||
if err != nil {
|
||||
return GetProbeYAMLResponse{}, errors.New("Error in getting probe details" + err.Error())
|
||||
}
|
||||
|
||||
bodyBytes, err := io.ReadAll(resp.Body)
|
||||
defer resp.Body.Close()
|
||||
if err != nil {
|
||||
return GetProbeYAMLResponse{}, errors.New("Error in getting probe details" + err.Error())
|
||||
}
|
||||
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
var getProbeYAMLResponse GetProbeYAMLResponse
|
||||
err = json.Unmarshal(bodyBytes, &getProbeYAMLResponse)
|
||||
if err != nil {
|
||||
return GetProbeYAMLResponse{}, errors.New("Error in getting probes details" + err.Error())
|
||||
}
|
||||
if len(getProbeYAMLResponse.Errors) > 0 {
|
||||
return GetProbeYAMLResponse{}, errors.New(getProbeYAMLResponse.Errors[0].Message)
|
||||
}
|
||||
return getProbeYAMLResponse, nil
|
||||
|
||||
} else {
|
||||
return GetProbeYAMLResponse{}, errors.New("Unmatched status code:" + string(bodyBytes))
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
package probe
|
||||
|
||||
const (
|
||||
ListProbeQuery = `query ListProbes($projectID: ID!, $probeNames: [ID!], $filter: ProbeFilterInput) {
|
||||
listProbes(projectID: $projectID, probeNames: $probeNames, filter: $filter) {
|
||||
name
|
||||
type
|
||||
createdAt
|
||||
createdBy{
|
||||
username
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
GetProbeQuery = `query getProbe($projectID: ID!, $probeName: ID!) {
|
||||
getProbe(projectID: $projectID, probeName: $probeName) {
|
||||
name
|
||||
description
|
||||
type
|
||||
infrastructureType
|
||||
kubernetesHTTPProperties{
|
||||
probeTimeout
|
||||
interval
|
||||
retry
|
||||
attempt
|
||||
probePollingInterval
|
||||
initialDelay
|
||||
evaluationTimeout
|
||||
stopOnFailure
|
||||
}
|
||||
kubernetesCMDProperties{
|
||||
probeTimeout
|
||||
interval
|
||||
retry
|
||||
attempt
|
||||
probePollingInterval
|
||||
initialDelay
|
||||
evaluationTimeout
|
||||
stopOnFailure
|
||||
}
|
||||
k8sProperties {
|
||||
probeTimeout
|
||||
interval
|
||||
retry
|
||||
attempt
|
||||
probePollingInterval
|
||||
initialDelay
|
||||
evaluationTimeout
|
||||
stopOnFailure
|
||||
}
|
||||
promProperties {
|
||||
probeTimeout
|
||||
interval
|
||||
retry
|
||||
attempt
|
||||
probePollingInterval
|
||||
initialDelay
|
||||
evaluationTimeout
|
||||
stopOnFailure
|
||||
}
|
||||
createdAt
|
||||
createdBy{
|
||||
username
|
||||
}
|
||||
updatedAt
|
||||
updatedBy{
|
||||
username
|
||||
}
|
||||
tags
|
||||
}
|
||||
}
|
||||
`
|
||||
GetProbeYAMLQuery = `query getProbeYAML($projectID: ID!, $request: GetProbeYAMLRequest!) {
|
||||
getProbeYAML(projectID: $projectID, request: $request)
|
||||
}
|
||||
`
|
||||
|
||||
DeleteProbeQuery = `mutation deleteProbe($probeName: ID!, $projectID: ID!) {
|
||||
deleteProbe(probeName: $probeName, projectID: $projectID)
|
||||
}
|
||||
`
|
||||
)
|
|
@ -0,0 +1,82 @@
|
|||
package probe
|
||||
|
||||
import model "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model"
|
||||
|
||||
type GetProbeGQLRequest struct {
|
||||
Query string `json:"query"`
|
||||
Variables struct {
|
||||
ProjectID string `json:"projectID"`
|
||||
ProbeName string `json:"probeName"`
|
||||
} `json:"variables"`
|
||||
}
|
||||
|
||||
type GetProbeResponse struct {
|
||||
Errors []struct {
|
||||
Message string `json:"message"`
|
||||
Path []string `json:"path"`
|
||||
} `json:"errors"`
|
||||
Data GetProbeResponseData `json:"data"`
|
||||
}
|
||||
|
||||
type GetProbeResponseData struct {
|
||||
GetProbe model.Probe `json:"getProbe"`
|
||||
}
|
||||
|
||||
type ListProbeGQLRequest struct {
|
||||
Query string `json:"query"`
|
||||
Variables struct {
|
||||
ProjectID string `json:"projectID"`
|
||||
Filter model.ProbeFilterInput `json:"filter"`
|
||||
} `json:"variables"`
|
||||
}
|
||||
|
||||
type ListProbeResponse struct {
|
||||
Errors []struct {
|
||||
Message string `json:"message"`
|
||||
Path []string `json:"path"`
|
||||
} `json:"errors"`
|
||||
Data ListProbeResponseData `json:"data"`
|
||||
}
|
||||
|
||||
type ListProbeResponseData struct {
|
||||
Probes []model.Probe `json:"listProbes"`
|
||||
}
|
||||
type DeleteProbeGQLRequest struct {
|
||||
Query string `json:"query"`
|
||||
Variables struct {
|
||||
ProbeName string `json:"probeName"`
|
||||
ProjectID string `json:"projectID"`
|
||||
} `json:"variables"`
|
||||
}
|
||||
|
||||
type DeleteProbeResponse struct {
|
||||
Errors []struct {
|
||||
Message string `json:"message"`
|
||||
Path []string `json:"path"`
|
||||
} `json:"errors"`
|
||||
Data DeleteProbeResponseData `json:"data"`
|
||||
}
|
||||
|
||||
type DeleteProbeResponseData struct {
|
||||
DeleteProbe bool `json:"deleteProbe"`
|
||||
}
|
||||
|
||||
type GetProbeYAMLGQLRequest struct {
|
||||
Query string `json:"query"`
|
||||
Variables struct {
|
||||
ProjectID string `json:"projectID"`
|
||||
Request model.GetProbeYAMLRequest `json:"request"`
|
||||
} `json:"variables"`
|
||||
}
|
||||
|
||||
type GetProbeYAMLResponse struct {
|
||||
Errors []struct {
|
||||
Message string `json:"message"`
|
||||
Path []string `json:"path"`
|
||||
} `json:"errors"`
|
||||
Data GetProbeYAMLResponseData `json:"data"`
|
||||
}
|
||||
|
||||
type GetProbeYAMLResponseData struct {
|
||||
GetProbeYAML string `json:"getProbeYAML"`
|
||||
}
|
|
@ -82,10 +82,14 @@ func CreateProjectRequest(projectName string, cred types.Credentials) (CreatePro
|
|||
}
|
||||
|
||||
type listProjectResponse struct {
|
||||
Data []struct {
|
||||
ID string `json:"ProjectID"`
|
||||
Name string `json:"Name"`
|
||||
CreatedAt int64 `json:"CreatedAt"`
|
||||
Message string `json:"message"`
|
||||
Data struct {
|
||||
Projects []struct {
|
||||
ID string `json:"projectID"` // Adjusted field name
|
||||
Name string `json:"name"`
|
||||
CreatedAt int64 `json:"createdAt"`
|
||||
} `json:"projects"`
|
||||
TotalNumberOfProjects int `json:"totalNumberOfProjects"`
|
||||
} `json:"data"`
|
||||
Errors []struct {
|
||||
Message string `json:"message"`
|
||||
|
@ -104,7 +108,6 @@ func ListProject(cred types.Credentials) (listProjectResponse, error) {
|
|||
if err != nil {
|
||||
return listProjectResponse{}, err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
|
@ -112,6 +115,7 @@ func ListProject(cred types.Credentials) (listProjectResponse, error) {
|
|||
err = json.Unmarshal(bodyBytes, &data)
|
||||
if err != nil {
|
||||
return listProjectResponse{}, err
|
||||
|
||||
}
|
||||
|
||||
if len(data.Errors) > 0 {
|
||||
|
|
|
@ -32,6 +32,7 @@ func SendRequest(params SendRequestParams, payload []byte, method string) (*http
|
|||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("Authorization", params.Token)
|
||||
req.Header.Set("Referer", params.Endpoint)
|
||||
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
|
@ -125,11 +126,12 @@ func UpgradeInfra(c context.Context, cred types.Credentials, projectID string, i
|
|||
|
||||
}
|
||||
|
||||
yamlOutput, err := k8s.UpgradeInfra([]byte(manifest.Data.GetManifest), kubeconfig)
|
||||
|
||||
yamlOutput, err := k8s.ApplyManifest([]byte(manifest.Data.GetManifest), kubeconfig)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
logrus.Println("🚀 Successfully Upgraded Chaos Infrastructure")
|
||||
|
||||
utils.White.Print("\n", yamlOutput)
|
||||
|
||||
// Creating a backup for current subscriber-config in the SUBSCRIBER
|
||||
|
|
|
@ -16,7 +16,9 @@ limitations under the License.
|
|||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
|
@ -173,6 +175,37 @@ var setAccountCmd = &cobra.Command{
|
|||
utils.PrintError(err)
|
||||
}
|
||||
utils.White_B.Printf("\naccount.username/%s configured", claims["username"].(string))
|
||||
credentials, err := utils.GetCredentials(cmd)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
}
|
||||
endpoint := credentials.Endpoint + utils.AuthAPIPath + "/get_user/" + claims["uid"].(string)
|
||||
userResp, err := apis.SendRequest(
|
||||
apis.SendRequestParams{
|
||||
Endpoint: endpoint,
|
||||
Token: "Bearer " + credentials.Token,
|
||||
},
|
||||
nil,
|
||||
string(types.Get),
|
||||
)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
}
|
||||
bodyBytes, err := io.ReadAll(userResp.Body)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
}
|
||||
var userResponse map[string]interface{}
|
||||
err = json.Unmarshal(bodyBytes, &userResponse)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
}
|
||||
|
||||
isInitialLogin := userResponse["isInitialLogin"].(bool)
|
||||
if isInitialLogin {
|
||||
utils.White_B.Println("\n❗ This is your first time login. Update your default password to perform further operations.")
|
||||
utils.White.Println(fmt.Sprintf("Use '%s' to update your password.", utils.White_B.Sprint("litmusctl update password")))
|
||||
}
|
||||
} else {
|
||||
utils.Red.Println("\nError: some flags are missing. Run 'litmusctl config set-account --help' for usage. ")
|
||||
}
|
||||
|
|
|
@ -16,9 +16,10 @@ limitations under the License.
|
|||
package connect
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/litmuschaos/litmusctl/pkg/apis/environment"
|
||||
"github.com/litmuschaos/litmusctl/pkg/apis/infrastructure"
|
||||
|
||||
|
@ -178,7 +179,7 @@ var infraCmd = &cobra.Command{
|
|||
infra_ops.PrintExistingInfra(infraList)
|
||||
os.Exit(1)
|
||||
}
|
||||
envIDs, err := environment.GetEnvironmentList(newInfra.ProjectId, credentials)
|
||||
envIDs, err := environment.ListChaosEnvironments(newInfra.ProjectId, credentials)
|
||||
utils.PrintError(err)
|
||||
|
||||
// Check if Environment exists
|
||||
|
@ -235,34 +236,25 @@ var infraCmd = &cobra.Command{
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
path := fmt.Sprintf("%s%s/%s.yaml", credentials.Endpoint, utils.ChaosYamlPath, infra.Data.RegisterInfraDetails.Token)
|
||||
utils.White_B.Print("Applying YAML:\n", path)
|
||||
|
||||
// Print error message in case Data field is null in response
|
||||
if (infra.Data == infrastructure.RegisterInfra{}) {
|
||||
utils.White_B.Print("\n🚫 Chaos new infrastructure connection failed: " + infra.Errors[0].Message + "\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
//Apply infra connection yaml
|
||||
yamlOutput, err := k8s.ApplyYaml(k8s.ApplyYamlParams{
|
||||
Token: infra.Data.RegisterInfraDetails.Token,
|
||||
Endpoint: credentials.Endpoint,
|
||||
YamlPath: utils.ChaosYamlPath,
|
||||
}, kubeconfig, false)
|
||||
yamlOutput, err := k8s.ApplyManifest([]byte(infra.Data.RegisterInfraDetails.Manifest), kubeconfig)
|
||||
if err != nil {
|
||||
utils.Red.Print("\n❌ Failed to apply connection yaml: \n" + err.Error() + "\n")
|
||||
utils.White_B.Print("\n Error: \n" + err.Error())
|
||||
utils.Red.Println("\n❌ failed to apply infra manifest, error: " + err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
logrus.Println("🚀 Successfully Connected Chaos Infrastructure")
|
||||
|
||||
utils.White_B.Print("\n", yamlOutput)
|
||||
utils.White.Print("\n", yamlOutput)
|
||||
|
||||
// Watch subscriber pod status
|
||||
k8s.WatchPod(k8s.WatchPodParams{Namespace: newInfra.Namespace, Label: utils.ChaosInfraLabel}, &kubeconfig)
|
||||
|
||||
utils.White_B.Println("\n🚀 Chaos new infrastructure connection successful!! 🎉")
|
||||
utils.White_B.Println("👉 Litmus Chaos Infrastructure can be accessed here: " + fmt.Sprintf("%s/%s", credentials.Endpoint, utils.ChaosInfraPath))
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ var environmentCmd = &cobra.Command{
|
|||
}
|
||||
newEnvironment.Type = models.EnvironmentType(envType)
|
||||
|
||||
envs, err := environment.GetEnvironmentList(pid, credentials)
|
||||
envs, err := environment.ListChaosEnvironments(pid, credentials)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
}
|
||||
|
|
|
@ -27,6 +27,12 @@ var DeleteCmd = &cobra.Command{
|
|||
#delete a Chaos Experiment
|
||||
litmusctl delete chaos-experiment c520650e-7cb6-474c-b0f0-4df07b2b025b --project-id=c520650e-7cb6-474c-b0f0-4df07b2b025b
|
||||
|
||||
#delete a Chaos Environment
|
||||
litmusctl delete chaos-environment --project-id=8adf62d5-64f8-4c66-ab53-63729db9dd9a --environment-id=environmentexample
|
||||
|
||||
#delete a Probe
|
||||
litmusctl delete probe --project-id=8adf62d5-64f8-4c66-ab53-63729db9dd9a --probe-id=exampleprobe
|
||||
|
||||
Note: The default location of the config file is $HOME/.litmusconfig, and can be overridden by a --config flag
|
||||
`,
|
||||
}
|
||||
|
|
|
@ -0,0 +1,156 @@
|
|||
/*
|
||||
Copyright © 2021 The LitmusChaos Authors
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
package delete
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/litmuschaos/litmusctl/pkg/apis/environment"
|
||||
|
||||
"github.com/litmuschaos/litmusctl/pkg/apis"
|
||||
"github.com/litmuschaos/litmusctl/pkg/utils"
|
||||
"github.com/manifoldco/promptui"
|
||||
"github.com/spf13/cobra"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// experimentCmd represents the Chaos Experiment command
|
||||
var environmentCmd = &cobra.Command{
|
||||
Use: "chaos-environment",
|
||||
Short: `Delete a Chaos environment
|
||||
Example:
|
||||
#delete a Chaos Environment
|
||||
litmusctl delete chaos-environment --project-id=8adf62d5-64f8-4c66-ab53-63729db9dd9a --environment-id=environmentexample
|
||||
|
||||
Note: The default location of the config file is $HOME/.litmusconfig, and can be overridden by a --config flag
|
||||
`,
|
||||
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
// Fetch user credentials
|
||||
credentials, err := utils.GetCredentials(cmd)
|
||||
utils.PrintError(err)
|
||||
|
||||
projectID, err := cmd.Flags().GetString("project-id")
|
||||
utils.PrintError(err)
|
||||
|
||||
environmentID, err := cmd.Flags().GetString("environment-id")
|
||||
utils.PrintError(err)
|
||||
|
||||
// Handle blank input for project ID
|
||||
|
||||
if projectID == "" {
|
||||
prompt := promptui.Prompt{
|
||||
Label: "Enter the Project ID",
|
||||
}
|
||||
result, err := prompt.Run()
|
||||
if err != nil {
|
||||
utils.Red.Println("⛔ Error:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
projectID = result
|
||||
}
|
||||
|
||||
if environmentID == "" {
|
||||
prompt := promptui.Prompt{
|
||||
Label: "Enter the Environment ID",
|
||||
}
|
||||
result, err := prompt.Run()
|
||||
if err != nil {
|
||||
utils.Red.Println("⛔ Error:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
environmentID = result
|
||||
}
|
||||
|
||||
// Handle blank input for Chaos Environment ID
|
||||
if environmentID == "" {
|
||||
utils.Red.Println("⛔ Chaos Environment ID can't be empty!!")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Perform authorization
|
||||
userDetails, err := apis.GetProjectDetails(credentials)
|
||||
utils.PrintError(err)
|
||||
var editAccess = false
|
||||
var project apis.Project
|
||||
for _, p := range userDetails.Data.Projects {
|
||||
if p.ID == projectID {
|
||||
project = p
|
||||
}
|
||||
}
|
||||
for _, member := range project.Members {
|
||||
if (member.UserID == userDetails.Data.ID) && (member.Role == "Owner" || member.Role == "Editor") {
|
||||
editAccess = true
|
||||
}
|
||||
}
|
||||
if !editAccess {
|
||||
utils.Red.Println("⛔ User doesn't have edit access to the project!!")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
environmentGet, err := environment.GetChaosEnvironment(projectID, environmentID, credentials)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "permission_denied") {
|
||||
utils.Red.Println("❌ You don't have enough permissions to delete an environment.")
|
||||
os.Exit(1)
|
||||
} else {
|
||||
utils.PrintError(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
environmentGetData := environmentGet.Data.EnvironmentDetails
|
||||
if len(environmentGetData.InfraIDs) > 0 {
|
||||
utils.Red.Println("Chaos Infras present in the Chaos Environment" +
|
||||
", delete the Chaos Infras first to delete the Environment")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// confirm before deletion
|
||||
prompt := promptui.Prompt{
|
||||
Label: "Are you sure you want to delete this Chaos Environment? (y/n)",
|
||||
AllowEdit: true,
|
||||
}
|
||||
|
||||
result, err := prompt.Run()
|
||||
if err != nil {
|
||||
utils.Red.Println("⛔ Error:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if result != "y" {
|
||||
utils.White_B.Println("\n❌ Chaos Environment was not deleted.")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// Make API call
|
||||
_, err = environment.DeleteEnvironment(projectID, environmentID, credentials)
|
||||
if err != nil {
|
||||
utils.Red.Println("\n❌ Error in deleting Chaos Environment: ", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
utils.White_B.Println("\n🚀 Chaos Environment successfully deleted.")
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
DeleteCmd.AddCommand(environmentCmd)
|
||||
|
||||
environmentCmd.Flags().String("project-id", "", "Set the project-id to delete Chaos Environment for the particular project. To see the projects, apply litmusctl get projects")
|
||||
environmentCmd.Flags().String("environment-id", "", "Set the environment-id to delete the particular Chaos Environment.")
|
||||
}
|
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
Copyright © 2021 The LitmusChaos Authors
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.W
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
package delete
|
||||
|
||||
import (
|
||||
"github.com/litmuschaos/litmusctl/pkg/apis"
|
||||
"github.com/litmuschaos/litmusctl/pkg/apis/probe"
|
||||
"github.com/litmuschaos/litmusctl/pkg/utils"
|
||||
"os"
|
||||
|
||||
"github.com/manifoldco/promptui"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var probeCmd = &cobra.Command{
|
||||
Use: "probe",
|
||||
Short: `Delete a Probe
|
||||
Example:
|
||||
#delete a Probe
|
||||
litmusctl delete probe --project-id=c520650e-7cb6-474c-b0f0-4df07b2b025b --probe-id="example"
|
||||
Note: The default location of the config file is $HOME/.litmusconfig, and can be overridden by a --config flag
|
||||
`,
|
||||
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
// Fetch user credentials
|
||||
credentials, err := utils.GetCredentials(cmd)
|
||||
utils.PrintError(err)
|
||||
|
||||
projectID, err := cmd.Flags().GetString("project-id")
|
||||
utils.PrintError(err)
|
||||
|
||||
// Handle blank input for project ID
|
||||
|
||||
if projectID == "" {
|
||||
prompt := promptui.Prompt{
|
||||
Label: "Enter the Project ID",
|
||||
}
|
||||
result, err := prompt.Run()
|
||||
if err != nil {
|
||||
utils.Red.Println("⛔ Error:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
projectID = result
|
||||
}
|
||||
probeID, err := cmd.Flags().GetString("probe-id")
|
||||
// Handle blank input for Probe ID
|
||||
if probeID == "" {
|
||||
prompt := promptui.Prompt{
|
||||
Label: "Enter the Probe ID",
|
||||
}
|
||||
IDinput, err := prompt.Run()
|
||||
if err != nil {
|
||||
utils.Red.Println("⛔ Error:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
probeID = IDinput
|
||||
}
|
||||
|
||||
// Perform authorization
|
||||
userDetails, err := apis.GetProjectDetails(credentials)
|
||||
utils.PrintError(err)
|
||||
var editAccess = false
|
||||
var project apis.Project
|
||||
for _, p := range userDetails.Data.Projects {
|
||||
if p.ID == projectID {
|
||||
project = p
|
||||
}
|
||||
}
|
||||
for _, member := range project.Members {
|
||||
if (member.UserID == userDetails.Data.ID) && (member.Role == "Owner" || member.Role == "Editor") {
|
||||
editAccess = true
|
||||
}
|
||||
}
|
||||
if !editAccess {
|
||||
utils.Red.Println("⛔ User doesn't have edit access to the project!!")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// confirm before deletion
|
||||
|
||||
prompt := promptui.Prompt{
|
||||
Label: "Are you sure you want to delete this probe and all the associations with experiment runs from the chaos control plane (y/n)",
|
||||
AllowEdit: true,
|
||||
}
|
||||
result, err := prompt.Run()
|
||||
if err != nil {
|
||||
utils.Red.Println("⛔ Error:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if result != "y" {
|
||||
utils.White_B.Println("\n❌ Probe was not deleted.")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// Make API call
|
||||
deleteProbe, err := probe.DeleteProbeRequest(projectID, probeID, credentials)
|
||||
if err != nil {
|
||||
utils.Red.Println("\n❌ Error in deleting Probe: ", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if deleteProbe.Data.DeleteProbe {
|
||||
utils.White_B.Println("\n🚀 Probe was successfully deleted.")
|
||||
} else {
|
||||
utils.White_B.Println("\n❌ Failed to delete Probe. Please check if the ID is correct or not.")
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
DeleteCmd.AddCommand(probeCmd)
|
||||
|
||||
probeCmd.Flags().String("project-id", "", "Set the project-id to delete Probe for the particular project. To see the projects, apply litmusctl get projects")
|
||||
probeCmd.Flags().String("probe-id", "", "Set the probe-id to delete that particular probe. To see the probes, apply litmusctl get probes")
|
||||
}
|
|
@ -27,6 +27,9 @@ var DescribeCmd = &cobra.Command{
|
|||
#describe a Chaos Experiment
|
||||
litmusctl describe chaos-experiment d861b650-1549-4574-b2ba-ab754058dd04 --project-id="d861b650-1549-4574-b2ba-ab754058dd04"
|
||||
|
||||
#describe a Probe
|
||||
litmusctl describe probe --project-id="d861b650-1549-4574-b2ba-ab754058dd04" --probe-id="exampleProbe"
|
||||
|
||||
Note: The default location of the config file is $HOME/.litmusconfig, and can be overridden by a --config flag
|
||||
`,
|
||||
}
|
||||
|
|
|
@ -102,22 +102,27 @@ var experimentCmd = &cobra.Command{
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
expOutput, err := cmd.Flags().GetString("output")
|
||||
utils.PrintError(err)
|
||||
// Add an output format prompt
|
||||
prompt := promptui.Select{
|
||||
Label: "Select an output format",
|
||||
Items: []string{"YAML", "JSON"},
|
||||
}
|
||||
i, _, err := prompt.Run()
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
os.Exit(1)
|
||||
if expOutput == "" {
|
||||
prompt := promptui.Select{
|
||||
Label: "Select an output format",
|
||||
Items: []string{"yaml", "json"},
|
||||
}
|
||||
_, value, err := prompt.Run()
|
||||
expOutput = value
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
switch i {
|
||||
case 0:
|
||||
switch expOutput {
|
||||
case "yaml":
|
||||
// Output as YAML (default)
|
||||
utils.PrintInYamlFormat(string(yamlManifest))
|
||||
case 1:
|
||||
case "json":
|
||||
// Output as JSON
|
||||
jsonData, err := yaml.YAMLToJSON(yamlManifest)
|
||||
if err != nil {
|
||||
|
@ -144,4 +149,5 @@ func init() {
|
|||
DescribeCmd.AddCommand(experimentCmd)
|
||||
|
||||
experimentCmd.Flags().String("project-id", "", "Set the project-id to list Chaos Experiments from the particular project. To see the projects, apply litmusctl get projects")
|
||||
experimentCmd.Flags().String("output", "", "Set the output format for the experiment")
|
||||
}
|
||||
|
|
|
@ -0,0 +1,126 @@
|
|||
// /*
|
||||
// Copyright © 2021 The LitmusChaos Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// */
|
||||
|
||||
package describe
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model"
|
||||
apis "github.com/litmuschaos/litmusctl/pkg/apis/probe"
|
||||
"github.com/litmuschaos/litmusctl/pkg/utils"
|
||||
"github.com/manifoldco/promptui"
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
var probeCmd = &cobra.Command{
|
||||
Use: "probe",
|
||||
Short: "Describe a Probe within the project",
|
||||
Long: `Describe a Probe within the project`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
credentials, err := utils.GetCredentials(cmd)
|
||||
utils.PrintError(err)
|
||||
|
||||
var getProbeYAMLRequest model.GetProbeYAMLRequest
|
||||
|
||||
pid, err := cmd.Flags().GetString("project-id")
|
||||
utils.PrintError(err)
|
||||
|
||||
if pid == "" {
|
||||
prompt := promptui.Prompt{
|
||||
Label: "Enter the Project ID",
|
||||
}
|
||||
result, err := prompt.Run()
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
pid = result
|
||||
}
|
||||
|
||||
var probeID string
|
||||
probeID, err = cmd.Flags().GetString("probe-id")
|
||||
utils.PrintError(err)
|
||||
// Handle blank input for Probe ID
|
||||
|
||||
if probeID == "" {
|
||||
utils.White_B.Print("\nEnter the Probe ID: ")
|
||||
fmt.Scanln(&probeID)
|
||||
|
||||
if probeID == "" {
|
||||
utils.Red.Println("⛔ Probe ID can't be empty!!")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
getProbeYAMLRequest.ProbeName = probeID
|
||||
|
||||
probeMode, err := cmd.Flags().GetString("mode")
|
||||
utils.PrintError(err)
|
||||
|
||||
if probeMode == "" {
|
||||
prompt := promptui.Select{
|
||||
Label: "Please select the probe mode ?",
|
||||
Items: []string{"SOT", "EOT", "Edge", "Continuous", "OnChaos"},
|
||||
}
|
||||
_, option, err := prompt.Run()
|
||||
if err != nil {
|
||||
fmt.Printf("Prompt failed %v\n", err)
|
||||
return
|
||||
}
|
||||
probeMode = option
|
||||
fmt.Printf("You chose %q\n", option)
|
||||
}
|
||||
getProbeYAMLRequest.Mode = model.Mode(probeMode)
|
||||
getProbeYAML, err := apis.GetProbeYAMLRequest(pid, getProbeYAMLRequest, credentials)
|
||||
if err != nil {
|
||||
utils.Red.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
getProbeYAMLData := getProbeYAML.Data.GetProbeYAML
|
||||
|
||||
probeOutput, err := cmd.Flags().GetString("output")
|
||||
utils.PrintError(err)
|
||||
|
||||
switch probeOutput {
|
||||
case "json":
|
||||
jsonData, _ := yaml.YAMLToJSON([]byte(getProbeYAMLData))
|
||||
var prettyJSON bytes.Buffer
|
||||
err = json.Indent(&prettyJSON, jsonData, "", " ")
|
||||
if err != nil {
|
||||
utils.Red.Println("❌ Error formatting JSON: " + err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Println(prettyJSON.String())
|
||||
|
||||
default:
|
||||
utils.PrintInYamlFormat(getProbeYAMLData)
|
||||
}
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
DescribeCmd.AddCommand(probeCmd)
|
||||
probeCmd.Flags().String("project-id", "", "Set the project-id to get Probe details from the particular project. To see the projects, apply litmusctl get projects")
|
||||
probeCmd.Flags().String("probe-id", "", "Set the probe-id to get the Probe details in Yaml format")
|
||||
probeCmd.Flags().String("mode", "", "Set the mode for the probes from SOT/EOT/Edge/Continuous/OnChaos ")
|
||||
probeCmd.Flags().String("output", "", "Set the output format for the probe")
|
||||
}
|
|
@ -1,115 +0,0 @@
|
|||
/*
|
||||
Copyright © 2021 The LitmusChaos Authors
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package get
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
|
||||
"github.com/litmuschaos/litmusctl/pkg/apis/environment"
|
||||
"github.com/litmuschaos/litmusctl/pkg/utils"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var ChaosEnvironmentCmd = &cobra.Command{
|
||||
Use: "chaos-environment",
|
||||
Short: "Get Chaos Environment within the project",
|
||||
Long: `Display the Chaos Environments within the project with the targeted id `,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
credentials, err := utils.GetCredentials(cmd)
|
||||
utils.PrintError(err)
|
||||
|
||||
projectID, err := cmd.Flags().GetString("project-id")
|
||||
utils.PrintError(err)
|
||||
|
||||
if projectID == "" {
|
||||
utils.White_B.Print("\nEnter the Project ID: ")
|
||||
fmt.Scanln(&projectID)
|
||||
|
||||
if projectID == "" {
|
||||
utils.Red.Println("⛔ Project ID can't be empty!!")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
environmentID, err := cmd.Flags().GetString("environment-id")
|
||||
utils.PrintError(err)
|
||||
|
||||
if environmentID == "" {
|
||||
utils.White_B.Print("\nEnter the Environment ID: ")
|
||||
fmt.Scanln(&environmentID)
|
||||
|
||||
if environmentID == "" {
|
||||
utils.Red.Println("⛔ Environment ID can't be empty!!")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
environmentList, err := environment.GetEnvironmentList(projectID, credentials)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "permission_denied") {
|
||||
utils.Red.Println("❌ You don't have enough permissions to access this resource.")
|
||||
os.Exit(1)
|
||||
} else {
|
||||
utils.PrintError(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
environmentListData := environmentList.Data.ListEnvironmentDetails.Environments
|
||||
writer := tabwriter.NewWriter(os.Stdout, 30, 8, 0, '\t', tabwriter.AlignRight)
|
||||
writer.Flush()
|
||||
for i := 0; i < len(environmentListData); i++ {
|
||||
if environmentListData[i].EnvironmentID == environmentID {
|
||||
intUpdateTime, err := strconv.ParseInt(environmentListData[i].UpdatedAt, 10, 64)
|
||||
if err != nil {
|
||||
utils.Red.Println("Error converting UpdatedAt to int64:", err)
|
||||
continue
|
||||
}
|
||||
updatedTime := time.Unix(intUpdateTime, 0).String()
|
||||
intCreatedTime, err := strconv.ParseInt(environmentListData[i].CreatedAt, 10, 64)
|
||||
if err != nil {
|
||||
utils.Red.Println("Error converting CreatedAt to int64:", err)
|
||||
continue
|
||||
}
|
||||
createdTime := time.Unix(intCreatedTime, 0).String()
|
||||
writer.Flush()
|
||||
utils.White_B.Fprintln(writer, "CHAOS ENVIRONMENT DETAILS")
|
||||
utils.White.Fprintln(writer, "CHAOS ENVIRONMENT ID\t", environmentListData[i].EnvironmentID)
|
||||
utils.White.Fprintln(writer, "CHAOS ENVIRONMENT NAME\t", environmentListData[i].Name)
|
||||
utils.White.Fprintln(writer, "CHAOS ENVIRONMENT Type\t", environmentListData[i].Type)
|
||||
utils.White.Fprintln(writer, "CREATED AT\t", createdTime)
|
||||
utils.White.Fprintln(writer, "CREATED BY\t", environmentListData[i].CreatedBy.Username)
|
||||
utils.White.Fprintln(writer, "UPDATED AT\t", updatedTime)
|
||||
utils.White.Fprintln(writer, "UPDATED BY\t", environmentListData[i].UpdatedBy.Username)
|
||||
utils.White.Fprintln(writer, "CHAOS INFRA IDs\t", strings.Join(environmentListData[i].InfraIDs, ", "))
|
||||
break
|
||||
}
|
||||
}
|
||||
writer.Flush()
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
GetCmd.AddCommand(ChaosEnvironmentCmd)
|
||||
ChaosEnvironmentCmd.Flags().String("project-id", "", "Set the project-id to get Chaos Environment from a particular project.")
|
||||
ChaosEnvironmentCmd.Flags().String("environment-id", "", "Set the environment-id to get Chaos Environment")
|
||||
}
|
|
@ -0,0 +1,164 @@
|
|||
/*
|
||||
Copyright © 2021 The LitmusChaos Authors
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package get
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
|
||||
"github.com/litmuschaos/litmusctl/pkg/apis/environment"
|
||||
"github.com/litmuschaos/litmusctl/pkg/utils"
|
||||
"github.com/manifoldco/promptui"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var GetChaosEnvironmentsCmd = &cobra.Command{
|
||||
Use: "chaos-environments",
|
||||
Short: "Get Chaos Environments within the project",
|
||||
Long: `Display the Chaos Environments within the project with the targeted id `,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
credentials, err := utils.GetCredentials(cmd)
|
||||
utils.PrintError(err)
|
||||
|
||||
projectID, err := cmd.Flags().GetString("project-id")
|
||||
utils.PrintError(err)
|
||||
|
||||
if projectID == "" {
|
||||
utils.White_B.Print("\nEnter the Project ID: ")
|
||||
fmt.Scanln(&projectID)
|
||||
|
||||
for projectID == "" {
|
||||
utils.Red.Println("⛔ Project ID can't be empty!!")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
environmentID, err := cmd.Flags().GetString("environment-id")
|
||||
utils.PrintError(err)
|
||||
|
||||
if environmentID == "" {
|
||||
environmentList, err := environment.ListChaosEnvironments(projectID, credentials)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "permission_denied") {
|
||||
utils.Red.Println("❌ You don't have enough permissions to access this resource.")
|
||||
os.Exit(1)
|
||||
} else {
|
||||
utils.PrintError(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
environmentListData := environmentList.Data.ListEnvironmentDetails.Environments
|
||||
|
||||
itemsPerPage := 5
|
||||
page := 1
|
||||
totalEnvironments := len(environmentListData)
|
||||
|
||||
writer := tabwriter.NewWriter(os.Stdout, 30, 8, 0, '\t', tabwriter.AlignRight)
|
||||
utils.White_B.Fprintln(writer, "CHAOS ENVIRONMENT ID\tCHAOS ENVIRONMENT NAME\tCREATED AT\tCREATED BY")
|
||||
for {
|
||||
writer.Flush()
|
||||
// calculating the start and end indices for the current page
|
||||
start := (page - 1) * itemsPerPage
|
||||
if start >= totalEnvironments {
|
||||
writer.Flush()
|
||||
utils.Red.Println("No more environments to display")
|
||||
break
|
||||
}
|
||||
end := start + itemsPerPage
|
||||
if end > totalEnvironments {
|
||||
end = totalEnvironments
|
||||
|
||||
}
|
||||
for _, environment := range environmentListData[start:end] {
|
||||
intTime, err := strconv.ParseInt(environment.CreatedAt, 10, 64)
|
||||
if err != nil {
|
||||
fmt.Println("Error converting CreatedAt to int64:", err)
|
||||
continue
|
||||
}
|
||||
humanTime := time.Unix(intTime, 0)
|
||||
utils.White.Fprintln(
|
||||
writer,
|
||||
environment.EnvironmentID+"\t"+environment.Name+"\t"+humanTime.String()+"\t"+environment.CreatedBy.Username,
|
||||
)
|
||||
}
|
||||
writer.Flush()
|
||||
// Check if it's the last item or if user wants to see more
|
||||
paginationPrompt := promptui.Prompt{
|
||||
Label: "Press Enter to show more environments (or type 'q' to quit)",
|
||||
AllowEdit: true,
|
||||
Default: "",
|
||||
}
|
||||
|
||||
userInput, err := paginationPrompt.Run()
|
||||
utils.PrintError(err)
|
||||
|
||||
if userInput == "q" {
|
||||
break
|
||||
}
|
||||
// Move to the next page
|
||||
page++
|
||||
}
|
||||
} else {
|
||||
environmentGet, err := environment.GetChaosEnvironment(projectID, environmentID, credentials)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "permission_denied") {
|
||||
utils.Red.Println("❌ You don't have enough permissions to access this resource.")
|
||||
os.Exit(1)
|
||||
} else {
|
||||
utils.PrintError(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
environmentGetData := environmentGet.Data.EnvironmentDetails
|
||||
writer := tabwriter.NewWriter(os.Stdout, 30, 8, 0, '\t', tabwriter.AlignRight)
|
||||
writer.Flush()
|
||||
intUpdateTime, err := strconv.ParseInt(environmentGetData.UpdatedAt, 10, 64)
|
||||
if err != nil {
|
||||
utils.Red.Println("Error converting UpdatedAt to int64:", err)
|
||||
}
|
||||
updatedTime := time.Unix(intUpdateTime, 0).String()
|
||||
intCreatedTime, err := strconv.ParseInt(environmentGetData.CreatedAt, 10, 64)
|
||||
if err != nil {
|
||||
utils.Red.Println("Error converting CreatedAt to int64:", err)
|
||||
}
|
||||
createdTime := time.Unix(intCreatedTime, 0).String()
|
||||
writer.Flush()
|
||||
utils.White_B.Fprintln(writer, "CHAOS ENVIRONMENT DETAILS")
|
||||
utils.White.Fprintln(writer, "CHAOS ENVIRONMENT ID\t", environmentGetData.EnvironmentID)
|
||||
utils.White.Fprintln(writer, "CHAOS ENVIRONMENT NAME\t", environmentGetData.Name)
|
||||
utils.White.Fprintln(writer, "CHAOS ENVIRONMENT Type\t", environmentGetData.Type)
|
||||
utils.White.Fprintln(writer, "CREATED AT\t", createdTime)
|
||||
utils.White.Fprintln(writer, "CREATED BY\t", environmentGetData.CreatedBy.Username)
|
||||
utils.White.Fprintln(writer, "UPDATED AT\t", updatedTime)
|
||||
utils.White.Fprintln(writer, "UPDATED BY\t", environmentGetData.UpdatedBy.Username)
|
||||
utils.White.Fprintln(writer, "CHAOS INFRA IDs\t", strings.Join(environmentGetData.InfraIDs, ", "))
|
||||
utils.White.Fprintln(writer, "TAGS\t", strings.Join(environmentGetData.Tags, ", "))
|
||||
writer.Flush()
|
||||
}
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
GetCmd.AddCommand(GetChaosEnvironmentsCmd)
|
||||
GetChaosEnvironmentsCmd.Flags().String("project-id", "", "Set the project-id to list Chaos Environments from a particular project.")
|
||||
GetChaosEnvironmentsCmd.Flags().String("environment-id", "", "Set the environment-id to get details about a Chaos Environment.")
|
||||
}
|
|
@ -77,14 +77,16 @@ var experimentsCmd = &cobra.Command{
|
|||
}
|
||||
}
|
||||
|
||||
outputFormat := ""
|
||||
outputPrompt := promptui.Select{
|
||||
Label: "Select an output format",
|
||||
Items: []string{"table", "json", "yaml"},
|
||||
}
|
||||
_, outputFormat, err = outputPrompt.Run()
|
||||
outputFormat, err := cmd.Flags().GetString("output")
|
||||
utils.PrintError(err)
|
||||
|
||||
if outputFormat == "" {
|
||||
outputPrompt := promptui.Select{
|
||||
Label: "Select an output format",
|
||||
Items: []string{"table", "json", "yaml"},
|
||||
}
|
||||
_, outputFormat, err = outputPrompt.Run()
|
||||
utils.PrintError(err)
|
||||
}
|
||||
switch outputFormat {
|
||||
case "json":
|
||||
utils.PrintInJsonFormat(experiments.Data)
|
||||
|
|
|
@ -35,6 +35,12 @@ var GetCmd = &cobra.Command{
|
|||
#get list of Chaos Experiment runs
|
||||
litmusctl get chaos-experiment-runs --project-id=""
|
||||
|
||||
#get list of Chaos Environments
|
||||
litmusctl get chaos-environments --project-id=""
|
||||
|
||||
#get list of Probes in a Project
|
||||
litmusctl get probes --project-id=""
|
||||
|
||||
Note: The default location of the config file is $HOME/.litmusconfig, and can be overridden by a --config flag
|
||||
`,
|
||||
}
|
||||
|
|
|
@ -0,0 +1,294 @@
|
|||
/*
|
||||
Copyright © 2021 The LitmusChaos Authors
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
package get
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
|
||||
models "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model"
|
||||
apis "github.com/litmuschaos/litmusctl/pkg/apis/probe"
|
||||
"github.com/litmuschaos/litmusctl/pkg/types"
|
||||
"github.com/litmuschaos/litmusctl/pkg/utils"
|
||||
"github.com/manifoldco/promptui"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var probesCmd = &cobra.Command{
|
||||
Use: "probes",
|
||||
Short: "Display list of probes",
|
||||
Long: `Display list of probes`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
credentials, err := utils.GetCredentials(cmd)
|
||||
utils.PrintError(err)
|
||||
|
||||
var projectID string
|
||||
projectID, err = cmd.Flags().GetString("project-id")
|
||||
utils.PrintError(err)
|
||||
|
||||
if projectID == "" {
|
||||
utils.White_B.Print("\nEnter the Project ID: ")
|
||||
fmt.Scanln(&projectID)
|
||||
|
||||
if projectID == "" {
|
||||
utils.Red.Println("⛔ Project ID can't be empty!!")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
ProbeID, err := cmd.Flags().GetString("probe-id")
|
||||
|
||||
if ProbeID == "" {
|
||||
getProbeList(projectID, cmd, credentials)
|
||||
} else {
|
||||
getProbeDetails(projectID, ProbeID, credentials)
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
GetCmd.AddCommand(probesCmd)
|
||||
|
||||
probesCmd.Flags().String("project-id", "", "Set the project-id to get Probe from a particular project.")
|
||||
probesCmd.Flags().BoolP("non-interactive", "n", false, "Set it to true for non interactive mode | Note: Always set the boolean flag as --non-interactive=Boolean")
|
||||
probesCmd.Flags().String("probe-types", "", "Set the probe-types as comma separated values to filter the probes")
|
||||
probesCmd.Flags().String("probe-id", "", "Set the probe-details to the ID of probe for getting all the details related to the probe.")
|
||||
}
|
||||
|
||||
func getProbeList(projectID string, cmd *cobra.Command, credentials types.Credentials) {
|
||||
|
||||
// calls the probeList endpoint for the list of probes
|
||||
var selectedItems []*models.ProbeType
|
||||
NoninteractiveMode, err := cmd.Flags().GetBool("non-interactive")
|
||||
utils.PrintError(err)
|
||||
|
||||
if NoninteractiveMode == false {
|
||||
prompt := promptui.Select{
|
||||
Label: "Do you want to enable advance filter probes?",
|
||||
Items: []string{"Yes", "No"},
|
||||
}
|
||||
_, option, err := prompt.Run()
|
||||
if err != nil {
|
||||
fmt.Printf("Prompt failed %v\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("You chose %q\n", option)
|
||||
|
||||
if option == "Yes" {
|
||||
items := []models.ProbeType{"httpProbe", "cmdProbe", "promProbe", "k8sProbe", "done"}
|
||||
for {
|
||||
prompt := promptui.Select{
|
||||
Label: "Select ProbeType",
|
||||
Items: items,
|
||||
Templates: &promptui.SelectTemplates{
|
||||
Active: `▸ {{ . | cyan }}`,
|
||||
Inactive: ` {{ . | white }}`,
|
||||
Selected: `{{ "✔" | green }} {{ . | bold }}`,
|
||||
},
|
||||
}
|
||||
|
||||
selectedIndex, result, err := prompt.Run()
|
||||
if err != nil {
|
||||
fmt.Printf("Prompt failed %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if items[selectedIndex] == "done" {
|
||||
break
|
||||
}
|
||||
|
||||
final := models.ProbeType(result)
|
||||
selectedItems = append(selectedItems, &final)
|
||||
items = append(items[:selectedIndex], items[selectedIndex+1:]...)
|
||||
|
||||
}
|
||||
|
||||
fmt.Printf("Selected Probe Types: %v\n", selectedItems)
|
||||
}
|
||||
} else {
|
||||
var probeTypes string
|
||||
probeTypes, err = cmd.Flags().GetString("probe-types")
|
||||
values := strings.Split(probeTypes, ",")
|
||||
for _, value := range values {
|
||||
probeType := models.ProbeType(value)
|
||||
selectedItems = append(selectedItems, &probeType)
|
||||
}
|
||||
}
|
||||
|
||||
probes_get, _ := apis.ListProbeRequest(projectID, selectedItems, credentials)
|
||||
probes_data := probes_get.Data.Probes
|
||||
|
||||
itemsPerPage := 5
|
||||
page := 1
|
||||
totalProbes := len(probes_data)
|
||||
|
||||
writer := tabwriter.NewWriter(os.Stdout, 8, 8, 8, '\t', tabwriter.AlignRight)
|
||||
utils.White_B.Fprintln(writer, "PROBE ID\t PROBE TYPE\t REFERENCED BY\t CREATED BY\t CREATED AT")
|
||||
|
||||
for {
|
||||
writer.Flush()
|
||||
start := (page - 1) * itemsPerPage
|
||||
if start >= totalProbes {
|
||||
utils.Red.Println("No more probes to display")
|
||||
break
|
||||
}
|
||||
end := start + itemsPerPage
|
||||
if end > totalProbes {
|
||||
end = totalProbes
|
||||
}
|
||||
for _, probe := range probes_data[start:end] {
|
||||
intTime, err := strconv.ParseInt(probe.CreatedAt, 10, 64)
|
||||
if err != nil {
|
||||
fmt.Println("Error converting CreatedAt to int64:", err)
|
||||
continue
|
||||
}
|
||||
humanTime := time.Unix(intTime, 0)
|
||||
var probeReferencedBy int
|
||||
if probe.ReferencedBy != nil {
|
||||
probeReferencedBy = *probe.ReferencedBy
|
||||
}
|
||||
|
||||
utils.White.Fprintln(writer, probe.Name+"\t"+fmt.Sprintf("%v", probe.Type)+"\t"+fmt.Sprintf("%d", probeReferencedBy)+"\t"+probe.CreatedBy.Username+"\t"+humanTime.String())
|
||||
}
|
||||
writer.Flush()
|
||||
|
||||
paginationPrompt := promptui.Prompt{
|
||||
Label: "Press Enter to show more probes (or type 'q' to quit)",
|
||||
AllowEdit: true,
|
||||
Default: "",
|
||||
}
|
||||
|
||||
userInput, err := paginationPrompt.Run()
|
||||
utils.PrintError(err)
|
||||
|
||||
if userInput == "q" {
|
||||
break
|
||||
}
|
||||
page++
|
||||
}
|
||||
|
||||
}
|
||||
func getProbeDetails(projectID, ProbeID string, credentials types.Credentials) {
|
||||
//call the probe get endpoint to get the probes details
|
||||
probeGet, err := apis.GetProbeRequest(projectID, ProbeID, credentials)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "permission_denied") {
|
||||
utils.Red.Println("❌ You don't have enough permissions to access this resource.")
|
||||
os.Exit(1)
|
||||
} else {
|
||||
utils.PrintError(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
probeGetData := probeGet.Data.GetProbe
|
||||
writer := tabwriter.NewWriter(os.Stdout, 30, 8, 2, '\t', tabwriter.AlignRight)
|
||||
intUpdateTime, err := strconv.ParseInt(probeGetData.UpdatedAt, 10, 64)
|
||||
if err != nil {
|
||||
utils.Red.Println("Error converting UpdatedAt to int64:", err)
|
||||
}
|
||||
updatedTime := time.Unix(intUpdateTime, 0).String()
|
||||
intCreatedTime, err := strconv.ParseInt(probeGetData.CreatedAt, 10, 64)
|
||||
if err != nil {
|
||||
utils.Red.Println("Error converting CreatedAt to int64:", err)
|
||||
}
|
||||
createdTime := time.Unix(intCreatedTime, 0).String()
|
||||
utils.White_B.Fprintln(writer, "PROBE DETAILS")
|
||||
utils.White.Fprintln(writer, "PROBE ID \t", probeGetData.Name)
|
||||
utils.White.Fprintln(writer, "PROBE DESCRIPTION \t", *probeGetData.Description)
|
||||
utils.White.Fprintln(writer, "PROBE TYPE \t", probeGetData.Type)
|
||||
utils.White.Fprintln(writer, "PROBE INFRASTRUCTURE TYPE \t", probeGetData.InfrastructureType)
|
||||
|
||||
switch probeGetData.Type {
|
||||
case "httpProbe":
|
||||
printHTTPProbeDetails(writer, probeGetData)
|
||||
case "cmdProbe":
|
||||
printCmdProbeDetails(writer, probeGetData)
|
||||
case "k8sProbe":
|
||||
printK8sProbeDetails(writer, probeGetData)
|
||||
case "promProbe":
|
||||
printPromProbeDetails(writer, probeGetData)
|
||||
}
|
||||
|
||||
utils.White.Fprintln(writer, "CREATED AT\t", createdTime)
|
||||
utils.White.Fprintln(writer, "CREATED BY\t", probeGetData.CreatedBy.Username)
|
||||
utils.White.Fprintln(writer, "UPDATED AT\t", updatedTime)
|
||||
utils.White.Fprintln(writer, "UPDATED BY\t", probeGetData.UpdatedBy.Username)
|
||||
utils.White.Fprintln(writer, "TAGS\t", strings.Join(probeGetData.Tags, ", "))
|
||||
if probeGetData.ReferencedBy != nil {
|
||||
utils.White.Fprintln(writer, "REFERENCED BY\t", *probeGetData.ReferencedBy)
|
||||
}
|
||||
writer.Flush()
|
||||
}
|
||||
|
||||
func printHTTPProbeDetails(writer *tabwriter.Writer, probeData models.Probe) {
|
||||
utils.White.Fprintln(writer, "TIMEOUT \t", probeData.KubernetesHTTPProperties.ProbeTimeout)
|
||||
utils.White.Fprintln(writer, "INTERVAL \t", probeData.KubernetesHTTPProperties.Interval)
|
||||
printOptionalIntProperty(writer, "ATTEMPT", probeData.KubernetesHTTPProperties.Attempt)
|
||||
printOptionalIntProperty(writer, "RETRY", probeData.KubernetesHTTPProperties.Retry)
|
||||
printOptionalProperty(writer, "POLLING INTERVAL", probeData.KubernetesHTTPProperties.ProbePollingInterval)
|
||||
printOptionalProperty(writer, "INITIAL DELAY", probeData.KubernetesHTTPProperties.InitialDelay)
|
||||
printOptionalProperty(writer, "EVALUATION TIMEOUT", probeData.KubernetesHTTPProperties.EvaluationTimeout)
|
||||
printOptionalBoolProperty(writer, "STOP ON FAILURE", probeData.KubernetesHTTPProperties.StopOnFailure)
|
||||
}
|
||||
func printCmdProbeDetails(writer *tabwriter.Writer, probeData models.Probe) {
|
||||
utils.White.Fprintln(writer, "TIMEOUT \t", probeData.KubernetesCMDProperties.ProbeTimeout)
|
||||
utils.White.Fprintln(writer, "INTERVAL \t", probeData.KubernetesCMDProperties.Interval)
|
||||
printOptionalIntProperty(writer, "ATTEMPT", probeData.KubernetesCMDProperties.Attempt)
|
||||
printOptionalIntProperty(writer, "RETRY", probeData.KubernetesCMDProperties.Retry)
|
||||
printOptionalProperty(writer, "POLLING INTERVAL", probeData.KubernetesCMDProperties.ProbePollingInterval)
|
||||
printOptionalProperty(writer, "INITIAL DELAY", probeData.KubernetesCMDProperties.InitialDelay)
|
||||
printOptionalProperty(writer, "EVALUATION TIMEOUT", probeData.KubernetesCMDProperties.EvaluationTimeout)
|
||||
printOptionalBoolProperty(writer, "STOP ON FAILURE", probeData.KubernetesCMDProperties.StopOnFailure)
|
||||
}
|
||||
func printK8sProbeDetails(writer *tabwriter.Writer, probeData models.Probe) {
|
||||
utils.White.Fprintln(writer, "TIMEOUT \t", probeData.K8sProperties.ProbeTimeout)
|
||||
utils.White.Fprintln(writer, "INTERVAL \t", probeData.K8sProperties.Interval)
|
||||
printOptionalIntProperty(writer, "ATTEMPT", probeData.K8sProperties.Attempt)
|
||||
printOptionalIntProperty(writer, "RETRY", probeData.K8sProperties.Retry)
|
||||
printOptionalProperty(writer, "POLLING INTERVAL", probeData.K8sProperties.ProbePollingInterval)
|
||||
printOptionalProperty(writer, "INITIAL DELAY", probeData.K8sProperties.InitialDelay)
|
||||
printOptionalProperty(writer, "EVALUATION TIMEOUT", probeData.K8sProperties.EvaluationTimeout)
|
||||
printOptionalBoolProperty(writer, "STOP ON FAILURE", probeData.K8sProperties.StopOnFailure)
|
||||
}
|
||||
func printPromProbeDetails(writer *tabwriter.Writer, probeData models.Probe) {
|
||||
utils.White.Fprintln(writer, "TIMEOUT \t", probeData.PromProperties.ProbeTimeout)
|
||||
utils.White.Fprintln(writer, "INTERVAL \t", probeData.PromProperties.Interval)
|
||||
printOptionalIntProperty(writer, "ATTEMPT", probeData.PromProperties.Attempt)
|
||||
printOptionalIntProperty(writer, "RETRY", probeData.PromProperties.Retry)
|
||||
printOptionalProperty(writer, "POLLING INTERVAL", probeData.PromProperties.ProbePollingInterval)
|
||||
printOptionalProperty(writer, "INITIAL DELAY", probeData.PromProperties.InitialDelay)
|
||||
printOptionalProperty(writer, "EVALUATION TIMEOUT", probeData.PromProperties.EvaluationTimeout)
|
||||
printOptionalBoolProperty(writer, "STOP ON FAILURE", probeData.PromProperties.StopOnFailure)
|
||||
}
|
||||
func printOptionalProperty(writer *tabwriter.Writer, name string, value *string) {
|
||||
if value != nil {
|
||||
utils.White.Fprintln(writer, name+"\t", *value)
|
||||
}
|
||||
}
|
||||
func printOptionalIntProperty(writer *tabwriter.Writer, name string, value *int) {
|
||||
if value != nil {
|
||||
utils.White.Fprintln(writer, name+"\t", *value)
|
||||
}
|
||||
}
|
||||
func printOptionalBoolProperty(writer *tabwriter.Writer, name string, value *bool) {
|
||||
if value != nil {
|
||||
utils.White.Fprintln(writer, name+"\t", *value)
|
||||
}
|
||||
}
|
|
@ -45,12 +45,12 @@ var projectsCmd = &cobra.Command{
|
|||
utils.PrintInJsonFormat(projects.Data)
|
||||
|
||||
case "yaml":
|
||||
utils.PrintInYamlFormat(projects.Data)
|
||||
utils.PrintInYamlFormat(projects.Data.Projects)
|
||||
|
||||
case "":
|
||||
itemsPerPage := 5
|
||||
page := 1
|
||||
totalProjects := len(projects.Data)
|
||||
totalProjects := len(projects.Data.Projects)
|
||||
|
||||
for {
|
||||
// calculating the start and end indices for the current page
|
||||
|
@ -69,9 +69,9 @@ var projectsCmd = &cobra.Command{
|
|||
// displaying the projects for the current page
|
||||
writer := tabwriter.NewWriter(os.Stdout, 8, 8, 8, '\t', tabwriter.AlignRight)
|
||||
utils.White_B.Fprintln(writer, "PROJECT ID\tPROJECT NAME\tCREATED AT")
|
||||
for _, project := range projects.Data[start:end] {
|
||||
for _, project := range projects.Data.Projects[start:end] {
|
||||
intTime := project.CreatedAt
|
||||
humanTime := time.Unix(intTime, 0)
|
||||
humanTime := time.Unix(intTime/1000, 0) // Convert milliseconds to second
|
||||
utils.White.Fprintln(writer, project.ID+"\t"+project.Name+"\t"+humanTime.String()+"\t")
|
||||
}
|
||||
writer.Flush()
|
||||
|
|
|
@ -1,121 +0,0 @@
|
|||
/*
|
||||
Copyright © 2021 The LitmusChaos Authors
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package list
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
|
||||
"github.com/litmuschaos/litmusctl/pkg/apis/environment"
|
||||
"github.com/litmuschaos/litmusctl/pkg/utils"
|
||||
"github.com/manifoldco/promptui"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var ListChaosEnvironmentCmd = &cobra.Command{
|
||||
Use: "chaos-environments",
|
||||
Short: "Get Chaos Environments within the project",
|
||||
Long: `Display the Chaos Environments within the project with the targeted id `,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
credentials, err := utils.GetCredentials(cmd)
|
||||
utils.PrintError(err)
|
||||
|
||||
projectID, err := cmd.Flags().GetString("project-id")
|
||||
utils.PrintError(err)
|
||||
|
||||
if projectID == "" {
|
||||
utils.White_B.Print("\nEnter the Project ID: ")
|
||||
fmt.Scanln(&projectID)
|
||||
|
||||
for projectID == "" {
|
||||
utils.Red.Println("⛔ Project ID can't be empty!!")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
environmentList, err := environment.GetEnvironmentList(projectID, credentials)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "permission_denied") {
|
||||
utils.Red.Println("❌ You don't have enough permissions to access this resource.")
|
||||
os.Exit(1)
|
||||
} else {
|
||||
utils.PrintError(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
environmentListData := environmentList.Data.ListEnvironmentDetails.Environments
|
||||
|
||||
itemsPerPage := 5
|
||||
page := 1
|
||||
totalEnvironments := len(environmentListData)
|
||||
|
||||
writer := tabwriter.NewWriter(os.Stdout, 30, 8, 0, '\t', tabwriter.AlignRight)
|
||||
utils.White_B.Fprintln(writer, "CHAOS ENVIRONMENT ID\tCHAOS ENVIRONMENT NAME\tCREATED AT\tCREATED BY")
|
||||
for {
|
||||
writer.Flush()
|
||||
// calculating the start and end indices for the current page
|
||||
start := (page - 1) * itemsPerPage
|
||||
if start >= totalEnvironments {
|
||||
writer.Flush()
|
||||
utils.Red.Println("No more environments to display")
|
||||
break
|
||||
}
|
||||
end := start + itemsPerPage
|
||||
if end > totalEnvironments {
|
||||
end = totalEnvironments
|
||||
|
||||
}
|
||||
for _, environment := range environmentListData[start:end] {
|
||||
intTime, err := strconv.ParseInt(environment.CreatedAt, 10, 64)
|
||||
if err != nil {
|
||||
fmt.Println("Error converting CreatedAt to int64:", err)
|
||||
continue
|
||||
}
|
||||
humanTime := time.Unix(intTime, 0)
|
||||
utils.White.Fprintln(
|
||||
writer,
|
||||
environment.EnvironmentID+"\t"+environment.Name+"\t"+humanTime.String()+"\t"+environment.CreatedBy.Username,
|
||||
)
|
||||
}
|
||||
writer.Flush()
|
||||
// Check if it's the last item or if user wants to see more
|
||||
paginationPrompt := promptui.Prompt{
|
||||
Label: "Press Enter to show more environments (or type 'q' to quit)",
|
||||
AllowEdit: true,
|
||||
Default: "",
|
||||
}
|
||||
|
||||
userInput, err := paginationPrompt.Run()
|
||||
utils.PrintError(err)
|
||||
|
||||
if userInput == "q" {
|
||||
break
|
||||
}
|
||||
// Move to the next page
|
||||
page++
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
ListCmd.AddCommand(ListChaosEnvironmentCmd)
|
||||
ListChaosEnvironmentCmd.Flags().String("project-id", "", "Set the project-id to list Chaos Environments from a particular project.")
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
Copyright © 2021 The LitmusChaos Authors
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
package list
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// getCmd represents the get command
|
||||
var ListCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: `Examples:
|
||||
#get list of chaos Chaos Environments
|
||||
litmusctl list chaos-environment --project-id=""
|
||||
|
||||
Note: The default location of the config file is $HOME/.litmusconfig, and can be overridden by a --config flag
|
||||
`,
|
||||
}
|
|
@ -37,7 +37,6 @@ import (
|
|||
"github.com/litmuschaos/litmusctl/pkg/cmd/config"
|
||||
"github.com/litmuschaos/litmusctl/pkg/cmd/create"
|
||||
"github.com/litmuschaos/litmusctl/pkg/cmd/get"
|
||||
"github.com/litmuschaos/litmusctl/pkg/cmd/list"
|
||||
config2 "github.com/litmuschaos/litmusctl/pkg/config"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
|
@ -76,7 +75,6 @@ func init() {
|
|||
rootCmd.AddCommand(upgrade.UpgradeCmd)
|
||||
rootCmd.AddCommand(save.SaveCmd)
|
||||
rootCmd.AddCommand(run.RunCmd)
|
||||
rootCmd.AddCommand(list.ListCmd)
|
||||
rootCmd.AddCommand(update.UpdateCmd)
|
||||
|
||||
// Here you will define your flags and configuration settings.
|
||||
|
|
|
@ -23,9 +23,6 @@ import (
|
|||
models "github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model"
|
||||
"github.com/litmuschaos/litmusctl/pkg/apis/experiment"
|
||||
|
||||
//"time"
|
||||
|
||||
//"github.com/gorhill/cronexpr"
|
||||
"github.com/litmuschaos/litmusctl/pkg/apis"
|
||||
"github.com/litmuschaos/litmusctl/pkg/utils"
|
||||
|
||||
|
@ -123,21 +120,22 @@ var experimentCmd = &cobra.Command{
|
|||
if (saveExperiment.Data == experiment.SavedExperimentDetails{}) {
|
||||
|
||||
if strings.Contains(err.Error(), "multiple write errors") {
|
||||
utils.Red.Println("\n❌ Chaos Experiment/" + chaosExperimentRequest.Name + " already exists")
|
||||
utils.Red.Println("\n❌ Chaos Experiment " + chaosExperimentRequest.Name + " already exists")
|
||||
os.Exit(1)
|
||||
}
|
||||
if strings.Contains(err.Error(), "no documents in result") {
|
||||
utils.Red.Println("❌ The specified Project ID or Chaos Infrastructure ID doesn't exist.")
|
||||
os.Exit(1)
|
||||
} else {
|
||||
utils.White_B.Print("\n❌ Chaos Experiment/" + chaosExperimentRequest.Name + " failed to be created: " + err.Error())
|
||||
utils.White_B.Print("\n❌ Chaos Experiment " + chaosExperimentRequest.Name + " failed to be created: " + err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Successful creation
|
||||
utils.White_B.Println("\n🚀 Chaos Experiment/" + chaosExperimentRequest.Name + " successfully saved 🎉")
|
||||
utils.White_B.Println("\n🚀 Chaos Experiment " + chaosExperimentRequest.Name + " successfully saved 🎉")
|
||||
utils.White_B.Println("\nChaos Experiment ID: " + chaosExperimentRequest.ID)
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
package update
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/litmuschaos/litmusctl/pkg/apis"
|
||||
"github.com/litmuschaos/litmusctl/pkg/types"
|
||||
"github.com/litmuschaos/litmusctl/pkg/utils"
|
||||
"github.com/manifoldco/promptui"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var PasswordCmd = &cobra.Command{
|
||||
Use: "password",
|
||||
Short: `Updates an account's password.
|
||||
Examples(s)
|
||||
#update a user's password
|
||||
litmusctl update password
|
||||
`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
var (
|
||||
updatePasswordRequest types.UpdatePasswordInput
|
||||
)
|
||||
|
||||
credentials, err := utils.GetCredentials(cmd)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
}
|
||||
|
||||
promptUsername := promptui.Prompt{
|
||||
Label: "Username",
|
||||
}
|
||||
updatePasswordRequest.Username, err = promptUsername.Run()
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
}
|
||||
|
||||
promptOldPassword := promptui.Prompt{
|
||||
Label: "Old Password",
|
||||
Mask: '*',
|
||||
}
|
||||
updatePasswordRequest.OldPassword, err = promptOldPassword.Run()
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
}
|
||||
|
||||
NEW_PASSWORD:
|
||||
|
||||
promptNewPassword := promptui.Prompt{
|
||||
Label: "New Password",
|
||||
Mask: '*',
|
||||
}
|
||||
updatePasswordRequest.NewPassword, err = promptNewPassword.Run()
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
}
|
||||
|
||||
promptConfirmPassword := promptui.Prompt{
|
||||
Label: "Confirm New Password",
|
||||
Mask: '*',
|
||||
}
|
||||
confirmPassword, err := promptConfirmPassword.Run()
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
}
|
||||
|
||||
if updatePasswordRequest.NewPassword != confirmPassword {
|
||||
utils.Red.Println("\nPasswords do not match. Please try again.")
|
||||
goto NEW_PASSWORD
|
||||
}
|
||||
payloadBytes, _ := json.Marshal(updatePasswordRequest)
|
||||
|
||||
resp, err := apis.SendRequest(
|
||||
apis.SendRequestParams{
|
||||
Endpoint: credentials.Endpoint + utils.AuthAPIPath + "/update/password",
|
||||
Token: "Bearer " + credentials.Token,
|
||||
},
|
||||
payloadBytes,
|
||||
string(types.Post),
|
||||
)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
bodyBytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
utils.White_B.Println("\nPassword updated successfully!")
|
||||
} else {
|
||||
err := errors.New("Unmatched status code: " + string(bodyBytes))
|
||||
if err != nil {
|
||||
utils.Red.Println("\nError updating password: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
UpdateCmd.AddCommand(PasswordCmd)
|
||||
}
|
|
@ -1,98 +1,15 @@
|
|||
package update
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
|
||||
"github.com/litmuschaos/litmusctl/pkg/utils"
|
||||
homedir "github.com/mitchellh/go-homedir"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var UpdateCmd = &cobra.Command{
|
||||
Use: "update",
|
||||
Short: "Changes the version of litmusctl",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Long: ``,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
updateVersion := args[0]
|
||||
homeDir, err := homedir.Dir()
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
}
|
||||
|
||||
var assetURL string = "https://litmusctl-production-bucket.s3.amazonaws.com/"
|
||||
var binaryName string = "litmusctl"
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
if runtime.GOARCH == "386" {
|
||||
binaryName += "-windows-386-" + updateVersion + ".tar.gz"
|
||||
assetURL += binaryName
|
||||
} else if runtime.GOARCH == "amd64" {
|
||||
binaryName += "-windows-amd64-" + updateVersion + ".tar.gz"
|
||||
assetURL += binaryName
|
||||
} else {
|
||||
binaryName += "-windows-arm64-" + updateVersion + ".tar.gz"
|
||||
assetURL += binaryName
|
||||
}
|
||||
case "linux":
|
||||
if runtime.GOARCH == "arm64" {
|
||||
binaryName += "-linux-arm64-" + updateVersion + ".tar.gz"
|
||||
assetURL += binaryName
|
||||
} else if runtime.GOARCH == "amd64" {
|
||||
binaryName += "-linux-amd64-" + updateVersion + ".tar.gz"
|
||||
assetURL += binaryName
|
||||
} else if runtime.GOARCH == "arm" {
|
||||
binaryName += "-linux-arm-" + updateVersion + ".tar.gz"
|
||||
assetURL += binaryName
|
||||
} else {
|
||||
binaryName += "-linux-386-" + updateVersion + ".tar.gz"
|
||||
assetURL += binaryName
|
||||
}
|
||||
case "darwin":
|
||||
if runtime.GOARCH == "amd64" {
|
||||
binaryName += "-darwin-amd64-" + updateVersion + ".tar.gz"
|
||||
assetURL += binaryName
|
||||
}
|
||||
}
|
||||
|
||||
utils.White.Print("Downloading:\n")
|
||||
|
||||
resp2, err := http.Get(assetURL)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
}
|
||||
|
||||
tempFile, err := os.CreateTemp("", binaryName)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
}
|
||||
defer os.Remove(tempFile.Name())
|
||||
|
||||
_, err = io.Copy(tempFile, resp2.Body)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
}
|
||||
utils.White_B.Print("OK\n")
|
||||
|
||||
tempFile.Close()
|
||||
|
||||
tarCmd := exec.Command("tar", "xzf", tempFile.Name(), "-C", homeDir)
|
||||
tarCmd.Stdout = os.Stdout
|
||||
tarCmd.Stderr = os.Stderr
|
||||
|
||||
utils.White_B.Print("Extracting binary...\n")
|
||||
err = tarCmd.Run()
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
}
|
||||
|
||||
utils.White_B.Print("Binary extracted successfully\n")
|
||||
},
|
||||
Use: "update",
|
||||
Short: `It updates ChaosCenter account's details.
|
||||
Examples
|
||||
|
||||
#update password
|
||||
litmusctl update password
|
||||
`,
|
||||
}
|
||||
|
|
|
@ -16,10 +16,14 @@ limitations under the License.
|
|||
package version
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
|
||||
"github.com/litmuschaos/litmusctl/pkg/utils"
|
||||
|
||||
homedir "github.com/mitchellh/go-homedir"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
@ -44,3 +48,92 @@ var VersionCmd = &cobra.Command{
|
|||
utils.White_B.Print("]\n")
|
||||
},
|
||||
}
|
||||
|
||||
var UpdateCmd = &cobra.Command{
|
||||
Use: "update",
|
||||
Short: "Changes the version of litmusctl",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Long: ``,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
updateVersion := args[0]
|
||||
homeDir, err := homedir.Dir()
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
}
|
||||
|
||||
var assetURL string = "https://litmusctl-production-bucket.s3.amazonaws.com/"
|
||||
var binaryName string = "litmusctl"
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
if runtime.GOARCH == "386" {
|
||||
binaryName += "-windows-386-" + updateVersion + ".tar.gz"
|
||||
assetURL += binaryName
|
||||
} else if runtime.GOARCH == "amd64" {
|
||||
binaryName += "-windows-amd64-" + updateVersion + ".tar.gz"
|
||||
assetURL += binaryName
|
||||
} else {
|
||||
binaryName += "-windows-arm64-" + updateVersion + ".tar.gz"
|
||||
assetURL += binaryName
|
||||
}
|
||||
case "linux":
|
||||
if runtime.GOARCH == "arm64" {
|
||||
binaryName += "-linux-arm64-" + updateVersion + ".tar.gz"
|
||||
assetURL += binaryName
|
||||
} else if runtime.GOARCH == "amd64" {
|
||||
binaryName += "-linux-amd64-" + updateVersion + ".tar.gz"
|
||||
assetURL += binaryName
|
||||
} else if runtime.GOARCH == "arm" {
|
||||
binaryName += "-linux-arm-" + updateVersion + ".tar.gz"
|
||||
assetURL += binaryName
|
||||
} else {
|
||||
binaryName += "-linux-386-" + updateVersion + ".tar.gz"
|
||||
assetURL += binaryName
|
||||
}
|
||||
case "darwin":
|
||||
if runtime.GOARCH == "amd64" {
|
||||
binaryName += "-darwin-amd64-" + updateVersion + ".tar.gz"
|
||||
assetURL += binaryName
|
||||
}
|
||||
}
|
||||
|
||||
utils.White.Print("Downloading:\n")
|
||||
|
||||
resp2, err := http.Get(assetURL)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
}
|
||||
|
||||
tempFile, err := os.CreateTemp("", binaryName)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
}
|
||||
defer os.Remove(tempFile.Name())
|
||||
|
||||
_, err = io.Copy(tempFile, resp2.Body)
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
}
|
||||
utils.White_B.Print("OK\n")
|
||||
|
||||
tempFile.Close()
|
||||
|
||||
tarCmd := exec.Command("tar", "xzf", tempFile.Name(), "-C", homeDir)
|
||||
tarCmd.Stdout = os.Stdout
|
||||
tarCmd.Stderr = os.Stderr
|
||||
|
||||
utils.White_B.Print("Extracting binary...\n")
|
||||
err = tarCmd.Run()
|
||||
if err != nil {
|
||||
utils.PrintError(err)
|
||||
return
|
||||
}
|
||||
|
||||
utils.White_B.Print("Binary extracted successfully\n")
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
VersionCmd.AddCommand(UpdateCmd)
|
||||
}
|
||||
|
|
|
@ -138,7 +138,7 @@ ENVIRONMENT:
|
|||
}
|
||||
|
||||
// Check if Chaos Environment with the given name exists
|
||||
Env, err := environment.GetEnvironmentList(pid, c)
|
||||
Env, err := environment.ListChaosEnvironments(pid, c)
|
||||
if err != nil {
|
||||
return types.Infra{}, err
|
||||
}
|
||||
|
|
|
@ -21,11 +21,8 @@ import (
|
|||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"k8s.io/client-go/discovery/cached/memory"
|
||||
|
@ -282,70 +279,8 @@ func ValidSA(namespace string, kubeconfig *string) (string, bool) {
|
|||
return sa, false
|
||||
}
|
||||
|
||||
// Token: Authorization token
|
||||
// EndPoint: Endpoint in .litmusconfig
|
||||
// YamlPath: Path of yaml file
|
||||
type ApplyYamlParams struct {
|
||||
Token string
|
||||
Endpoint string
|
||||
YamlPath string
|
||||
}
|
||||
|
||||
func ApplyYaml(params ApplyYamlParams, kubeconfig string, isLocal bool) (output string, err error) {
|
||||
path := params.YamlPath
|
||||
if !isLocal {
|
||||
path = fmt.Sprintf("%s%s/%s.yaml", params.Endpoint, params.YamlPath, params.Token)
|
||||
req, err := http.NewRequest("GET", path, nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
resp_body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
err = os.WriteFile("chaos-infra-manifest.yaml", resp_body, 0644)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
path = "chaos-infra-manifest.yaml"
|
||||
}
|
||||
|
||||
args := []string{"kubectl", "apply", "-f", path}
|
||||
if kubeconfig != "" {
|
||||
args = append(args, []string{"--kubeconfig", kubeconfig}...)
|
||||
} else {
|
||||
args = []string{"kubectl", "apply", "-f", path}
|
||||
}
|
||||
|
||||
cmd := exec.Command(args[0], args[1:]...)
|
||||
var stdout, stderr bytes.Buffer
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stderr
|
||||
err = cmd.Run()
|
||||
outStr, errStr := stdout.String(), stderr.String()
|
||||
|
||||
// err, can have exit status 1
|
||||
if err != nil {
|
||||
// if we get standard error then, return the same
|
||||
if errStr != "" {
|
||||
return "", fmt.Errorf(errStr)
|
||||
}
|
||||
|
||||
// if not standard error found, return error
|
||||
return "", err
|
||||
}
|
||||
|
||||
// If no error found, return standard output
|
||||
return outStr, nil
|
||||
}
|
||||
|
||||
// UpgradeInfra upgrades the Chaos Infrastructure using the provided manifest and kubeconfig with the help of client-go library.
|
||||
func UpgradeInfra(manifest []byte, kubeconfig string) (string, error) {
|
||||
// ApplyManifest applies the provided manifest and kubeconfig with the help of client-go library.
|
||||
func ApplyManifest(manifest []byte, kubeconfig string) (string, error) {
|
||||
|
||||
// Get Kubernetes and dynamic clients along with the configuration.
|
||||
_, kubeClient, dynamicClient, err := getClientAndConfig(kubeconfig)
|
||||
|
@ -365,10 +300,7 @@ func UpgradeInfra(manifest []byte, kubeconfig string) (string, error) {
|
|||
return "", err
|
||||
}
|
||||
|
||||
logrus.Println("🚀 Successfully Upgraded Chaos Infra")
|
||||
|
||||
return "Success", nil
|
||||
|
||||
}
|
||||
|
||||
// retrieves the Kubernetes and dynamic clients along with the configuration.
|
||||
|
|
|
@ -41,3 +41,9 @@ type Credentials struct {
|
|||
Endpoint string
|
||||
ServerEndpoint string
|
||||
}
|
||||
|
||||
type UpdatePasswordInput struct {
|
||||
Username string `json:"username,omitempty"`
|
||||
OldPassword string
|
||||
NewPassword string
|
||||
}
|
||||
|
|
|
@ -123,6 +123,9 @@ func PrintInYamlFormat(inf interface{}) {
|
|||
}
|
||||
|
||||
func GenerateRandomString(n int) (string, error) {
|
||||
if n <= 0 {
|
||||
return "", fmt.Errorf("length should not be negative")
|
||||
}
|
||||
const letters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-"
|
||||
ret := make([]byte, n)
|
||||
for i := 0; i < n; i++ {
|
||||
|
|
|
@ -26,5 +26,18 @@ var (
|
|||
"1.1.0": {"3.0.0", "3.1.0", "3.2.0"},
|
||||
"1.2.0": {"3.0.0", "3.1.0", "3.2.0", "3.3.0"},
|
||||
"1.3.0": {"3.0.0", "3.1.0", "3.2.0", "3.3.0", "3.4.0"},
|
||||
"1.4.0": {"3.0.0", "3.1.0", "3.2.0", "3.3.0", "3.4.0", "3.5.0"},
|
||||
"1.5.0": {"3.0.0", "3.1.0", "3.2.0", "3.3.0", "3.4.0", "3.5.0", "3.6.0"},
|
||||
"1.6.0": {"3.0.0", "3.1.0", "3.2.0", "3.3.0", "3.4.0", "3.5.0", "3.6.0", "3.6.1", "3.7.0"},
|
||||
"1.7.0": {"3.0.0", "3.1.0", "3.2.0", "3.3.0", "3.4.0", "3.5.0", "3.6.0", "3.6.1", "3.7.0", "3.8.0"},
|
||||
"1.8.0": {"3.0.0", "3.1.0", "3.2.0", "3.3.0", "3.4.0", "3.5.0", "3.6.0", "3.6.1", "3.7.0", "3.8.0", "3.9.0", "3.9.1"},
|
||||
"1.9.0": {"3.0.0", "3.1.0", "3.2.0", "3.3.0", "3.4.0", "3.5.0", "3.6.0", "3.6.1", "3.7.0", "3.8.0", "3.9.0", "3.9.1", "3.10.0"},
|
||||
"1.10.0": {"3.0.0", "3.1.0", "3.2.0", "3.3.0", "3.4.0", "3.5.0", "3.6.0", "3.6.1", "3.7.0", "3.8.0", "3.9.0", "3.9.1", "3.10.0", "3.11.0"},
|
||||
"1.11.0": {"3.0.0", "3.1.0", "3.2.0", "3.3.0", "3.4.0", "3.5.0", "3.6.0", "3.6.1", "3.7.0", "3.8.0", "3.9.0", "3.9.1", "3.10.0", "3.11.0", "3.12.0"},
|
||||
"1.12.0": {"3.0.0", "3.1.0", "3.2.0", "3.3.0", "3.4.0", "3.5.0", "3.6.0", "3.6.1", "3.7.0", "3.8.0", "3.9.0", "3.9.1", "3.10.0", "3.11.0", "3.12.0", "3.13.0"},
|
||||
"1.13.0": {"3.0.0", "3.1.0", "3.2.0", "3.3.0", "3.4.0", "3.5.0", "3.6.0", "3.6.1", "3.7.0", "3.8.0", "3.9.0", "3.9.1", "3.10.0", "3.11.0", "3.12.0", "3.13.0", "3.14.0"},
|
||||
"1.14.0": {"3.0.0", "3.1.0", "3.2.0", "3.3.0", "3.4.0", "3.5.0", "3.6.0", "3.6.1", "3.7.0", "3.8.0", "3.9.0", "3.9.1", "3.10.0", "3.11.0", "3.12.0", "3.13.0", "3.14.0", "3.15.0"},
|
||||
"1.15.0": {"3.0.0", "3.1.0", "3.2.0", "3.3.0", "3.4.0", "3.5.0", "3.6.0", "3.6.1", "3.7.0", "3.8.0", "3.9.0", "3.9.1", "3.10.0", "3.11.0", "3.12.0", "3.13.0", "3.14.0", "3.15.0", "3.16.0", "3.17.0", "3.18.0"},
|
||||
"1.16.0": {"3.0.0", "3.1.0", "3.2.0", "3.3.0", "3.4.0", "3.5.0", "3.6.0", "3.6.1", "3.7.0", "3.8.0", "3.9.0", "3.9.1", "3.10.0", "3.11.0", "3.12.0", "3.13.0", "3.14.0", "3.15.0", "3.16.0", "3.17.0", "3.18.0", "3.19.0"},
|
||||
}
|
||||
)
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
go test fuzz v1
|
||||
int(-82)
|
|
@ -0,0 +1,41 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func isValidString(s string) bool {
|
||||
// Define the set of valid characters
|
||||
validChars := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"
|
||||
|
||||
// Iterate over each character in the string
|
||||
for _, char := range s {
|
||||
// Check if the character is not in the set of valid characters
|
||||
if !strings.ContainsRune(validChars, char) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func FuzzGenerateRandomString(f *testing.F) {
|
||||
f.Add(10)
|
||||
f.Fuzz(func(t *testing.T, n int) {
|
||||
randomString, err := GenerateRandomString(n)
|
||||
if err != nil && n > 0 {
|
||||
t.Errorf("Error generating random string: %v", err)
|
||||
}
|
||||
// Perform checks on the generated string
|
||||
// Check if the length matches the expected length
|
||||
if n >= 0 && len(randomString) != n {
|
||||
t.Errorf("Generated string length doesn't match expected length")
|
||||
}
|
||||
|
||||
// Check if the string contains only valid characters
|
||||
if !isValidString(randomString) {
|
||||
t.Errorf("Generated string contains invalid characters")
|
||||
}
|
||||
})
|
||||
|
||||
}
|
Loading…
Reference in New Issue