-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from gcarrarom/feature/clean-token
Feature/clean token
- Loading branch information
Showing
6 changed files
with
195 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +0,0 @@ | ||
class kcleaner < Formula | ||
include Language::Python::Virtualenv | ||
|
||
desc " A little CLI tool to help keeping Config Files clean" | ||
homepage "https://fancywhale.ca/" | ||
url "https://files.pythonhosted.org/packages/ff/d2/c8ef2dc18777b1a01b58513db9a11a9d32173e99b66d4e096358a825bb9a/PyYAML-5.1b1.tar.gz#sha256=b21fadf0e343c3738cc956be9d24ee7a83d3260ff1a6805f860b4f5d4645b7b9" | ||
sha256 "b21fadf0e343c3738cc956be9d24ee7a83d3260ff1a6805f860b4f5d4645b7b9" | ||
head "https://github.com/gcarrarom/kubeconfig-cleaner-cli.git" | ||
|
||
# TODO: If you're submitting an existing package, make sure you include your | ||
# bottle block here. | ||
|
||
depends_on :python3 | ||
|
||
resource "Click" do | ||
url "https://files.pythonhosted.org/packages/fa/37/45185cb5abbc30d7257104c434fe0b07e5a195a6847506c074527aa599ec/Click-7.0-py2.py3-none-any.whl#sha256=2335065e6395b9e67ca716de5f7526736bfa6ceead690adf616d925bdc622b13" | ||
sha256 "2335065e6395b9e67ca716de5f7526736bfa6ceead690adf616d925bdc622b13" | ||
end | ||
|
||
resource "setuptools" do | ||
url "https://files.pythonhosted.org/packages/d1/6a/4b2fcefd2ea0868810e92d519dacac1ddc64a2e53ba9e3422c3b62b378a6/setuptools-40.8.0-py2.py3-none-any.whl#sha256=e8496c0079f3ac30052ffe69b679bd876c5265686127a3159cfa415669b7f9ab" | ||
sha256 "e8496c0079f3ac30052ffe69b679bd876c5265686127a3159cfa415669b7f9ab" | ||
end | ||
|
||
resource "iterfzf" do | ||
url "https://files.pythonhosted.org/packages/a1/7d/a4a5de90f3cdd825cf9bfcb6ea6270533ec8127b1e328eecf7b499084c59/iterfzf-0.4.0.17.3.tar.gz#sha256=d58497135ea417777e9f518356ca3613198ffa155667a7ac918495cab9c22abb" | ||
sha256 "d58497135ea417777e9f518356ca3613198ffa155667a7ac918495cab9c22abb" | ||
end | ||
|
||
def install | ||
virtualenv_install_with_resources | ||
end | ||
|
||
# TODO: Add your package's tests here | ||
end | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
setup( | ||
name='kcleaner', | ||
version='0.2.1', | ||
version='0.3.0', | ||
author='Gui Martins', | ||
url='https://fancywhale.ca/', | ||
author_email='[email protected]', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
from kcleaner import remove_resource, get_file | ||
from testfixtures import log_capture | ||
import click | ||
from click.testing import CliRunner | ||
import pytest | ||
import yaml | ||
from mock import patch | ||
|
||
runner = CliRunner() | ||
sample_yaml_no_token = """ | ||
apiVersion: v1 | ||
clusters: | ||
- cluster: | ||
server: https://super.coolcluster.fancywhale.ca | ||
name: SuperCoolCluster | ||
contexts: | ||
- context: | ||
cluster: SuperCoolCluster | ||
user: SuperCoolUserName | ||
name: SuperCoolContext1 | ||
current-context: SuperCoolContext | ||
kind: Config | ||
preferences: {} | ||
users: | ||
- name: SuperCoolUserName1 | ||
user: | ||
auth-provider: | ||
config: | ||
apiserver-id: some-id-that-makes-sense | ||
client-id: some-id-that-makes-sense | ||
tenant-id: some-id-that-makes-sense | ||
name: some-auth-provider | ||
""" | ||
sample_yaml_token = """ | ||
apiVersion: v1 | ||
clusters: | ||
- cluster: | ||
server: https://super.coolcluster.fancywhale.ca | ||
name: SuperCoolCluster | ||
contexts: | ||
- context: | ||
cluster: SuperCoolCluster | ||
user: SuperCoolUserName | ||
name: SuperCoolContext1 | ||
current-context: SuperCoolContext | ||
kind: Config | ||
preferences: {} | ||
users: | ||
- name: SuperCoolUserName1 | ||
user: | ||
auth-provider: | ||
config: | ||
access-token: SomeRandomToken | ||
apiserver-id: some-id-that-makes-sense | ||
client-id: some-id-that-makes-sense | ||
expires-in: '3600' | ||
expires-on: '1559593884' | ||
refresh-token: SomeRandomRefreshToken | ||
tenant-id: some-id-that-makes-sense | ||
name: some-auth-provider | ||
""" | ||
|
||
@log_capture() | ||
def test_none_parameters(capture): | ||
|
||
with pytest.raises(SystemExit) as pytest_wrapped_e: | ||
remove_resource(None, None) | ||
|
||
assert pytest_wrapped_e.value.code == 50 | ||
capture.check_present( | ||
('root', 'ERROR', 'Config File cannot be "None"!'), | ||
) | ||
|
||
@log_capture() | ||
def test_removing_type_none(capture): | ||
|
||
with pytest.raises(SystemExit) as pytest_wrapped_e: | ||
remove_resource("", None) | ||
|
||
assert pytest_wrapped_e.value.code == 50 | ||
capture.check_present( | ||
('root', 'ERROR', 'Removing type cannot be "None"!'), | ||
) | ||
|
||
@log_capture() | ||
def test_config_file_empty(capture): | ||
|
||
with pytest.raises(SystemExit) as pytest_wrapped_e: | ||
remove_resource("", "") | ||
|
||
assert pytest_wrapped_e.value.code == 51 | ||
capture.check_present( | ||
('root', 'ERROR', 'Parameters cannot be empty!'), | ||
) | ||
|
||
@log_capture() | ||
@patch('kcleaner.iterfzf') | ||
def test_remove_token_not_available(test_patch, capture): | ||
with runner.isolated_filesystem(): | ||
|
||
with open(f'./SampleConfigFile', 'w') as f: | ||
f.write(sample_yaml_no_token) | ||
|
||
config_file = get_file("./SampleConfigFile") | ||
|
||
test_patch.return_value = "" | ||
|
||
with pytest.raises(SystemExit) as pytest_wrapped_e: | ||
new_config = remove_resource(config_file, "token") | ||
|
||
assert pytest_wrapped_e.value.code == 52 | ||
capture.check_present( | ||
('root', 'ERROR', 'No resources to remove selected!'), | ||
) | ||
|
||
@log_capture() | ||
@patch('kcleaner.iterfzf') | ||
def test_remove_token(test_patch, capture): | ||
name_to_remove = "SuperCoolUserName1" | ||
with runner.isolated_filesystem(): | ||
|
||
with open(f'./SampleConfigFile', 'w') as f: | ||
f.write(sample_yaml_token) | ||
with open(f'./SampleConfigFileToTest', 'w') as f: | ||
f.write(sample_yaml_no_token) | ||
|
||
config_file = get_file("./SampleConfigFile") | ||
config_to_test = get_file("./SampleConfigFileToTest") | ||
|
||
test_patch.return_value = f"{name_to_remove}" | ||
|
||
new_config = remove_resource(config_file, "token") | ||
|
||
assert new_config == config_to_test | ||
capture.check_present( | ||
('root', 'DEBUG', f'Removing token information from the user(s) {name_to_remove}'), | ||
('root', 'DEBUG', f'removing tokens from user {name_to_remove}'), | ||
('root', 'DEBUG', 'Token Removed successfully!'), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters