Skip to content

Commit f0c1d2b

Browse files
learned to allow and disallow space ssh access
1 parent d7fd0d4 commit f0c1d2b

6 files changed

Lines changed: 119 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8-
## 2.26.1 - Unreleased
8+
## 2.27.0 - Unreleased
99

1010
### Added
1111

1212
- Added `create-shared-domain` and `delete-shared-domain` commands
13+
- Added `allow-space-ssh` and `disallow-space-ssh`, thanks to a PR by [wanddynosios](https://github.com/wanddynosios)
1314

1415
### Changed
1516

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,40 @@ Delete a space
229229
space: myspace
230230
```
231231

232+
### `allow-space-ssh`
233+
234+
Allow SSH access for the space
235+
236+
| Params | Usage | CLI Version | Description
237+
| --- | --- | --- | ---
238+
| `org` | *Required* | All | The organization to target (*Optional if set in the source config*)
239+
| `space` | *Required* | All | The space to allow SSH access (*Optional if set in the source config*)
240+
241+
```yaml
242+
- put: cloud-foundry
243+
params:
244+
command: allow-space-ssh
245+
org: myorg
246+
space: myspace
247+
```
248+
249+
### `disallow-space-ssh`
250+
251+
Disallow SSH access for the space
252+
253+
| Params | Usage | CLI Version | Description
254+
| --- | --- | --- | ---
255+
| `org` | *Required* | All | The organization to target (*Optional if set in the source config*)
256+
| `space` | *Required* | All | The space to disallow SSH access (*Optional if set in the source config*)
257+
258+
```yaml
259+
- put: cloud-foundry
260+
params:
261+
command: disallow-space-ssh
262+
org: myorg
263+
space: myspace
264+
```
265+
232266
### `create-private-domain`
233267

234268
Create a private domain for a specific org
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11

2-
space=$(get_option '.space')
3-
42
logger::info "Executing $(logger::highlight "$command"): $space"
53

64
cf::target "$org" "$space"
7-
cf::cf allow-space-ssh "$space"
5+
cf::cf allow-space-ssh "$space"
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11

2-
space=$(get_option '.space')
3-
42
logger::info "Executing $(logger::highlight "$command"): $space"
53

64
cf::target "$org" "$space"
7-
cf::cf disallow-space-ssh "$space"
5+
cf::cf disallow-space-ssh "$space"

spec/spec_helper.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,4 +754,25 @@ EOF
754754

755755
return $status
756756
}
757+
758+
test::is_space_ssh_allowed() {
759+
local org=${1:-}
760+
local space=${2:-}
761+
762+
[ -z "${org}" ] && error_and_exit "${FUNCNAME[0]} - org null or not set"
763+
[ -z "${space}" ] && error_and_exit "${FUNCNAME[0]} - space null or not set"
764+
765+
quiet cf::target "$org" "$space"
766+
767+
local output status
768+
if ! output=$(cf::cf space-ssh-allowed "$space"); then
769+
status=${PIPESTATUS[0]}
770+
logger::error "$output"
771+
return $status
772+
fi
773+
774+
test::untarget
775+
776+
[[ "$output" == *"ssh support is enabled"* ]]
777+
}
757778
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env shellspec
2+
3+
set -euo pipefail
4+
5+
Describe 'ssh'
6+
7+
setup() {
8+
org=$(generate_test_name_with_spaces)
9+
space=$(generate_test_name_with_spaces)
10+
11+
source=$(get_source_config "$org" "$space") || error_and_exit "[ERROR] error loading source json config"
12+
13+
test::login
14+
test::create_org_and_space "$org" "$space"
15+
}
16+
17+
teardown() {
18+
test::delete_org_and_space "$org" "$space"
19+
test::logout
20+
}
21+
22+
BeforeAll 'setup'
23+
AfterAll 'teardown'
24+
25+
It 'can disallow space ssh'
26+
disallow_space_ssh() {
27+
local config=$(
28+
%text:expand
29+
#|$source
30+
#|params:
31+
#| command: disallow-space-ssh
32+
#| space: $space
33+
)
34+
put "$config"
35+
}
36+
When call disallow_space_ssh
37+
The status should be success
38+
The output should json '.version | keys == ["timestamp"]'
39+
The error should include "Disabling ssh support for space '$space'"
40+
Assert not test::is_space_ssh_allowed "$org" "$space"
41+
End
42+
43+
It 'can allow space ssh'
44+
allow_space_ssh() {
45+
local config=$(
46+
%text:expand
47+
#|$source
48+
#|params:
49+
#| command: allow-space-ssh
50+
#| space: $space
51+
)
52+
put "$config"
53+
}
54+
When call allow_space_ssh
55+
The status should be success
56+
The output should json '.version | keys == ["timestamp"]'
57+
The error should include "Enabling ssh support for space '$space'"
58+
Assert test::is_space_ssh_allowed "$org" "$space"
59+
End
60+
End

0 commit comments

Comments
 (0)