Skip to content
This repository was archived by the owner on Jul 19, 2022. It is now read-only.

Commit ad50cd6

Browse files
fix create-service-broker to only target org and space if space_scoped: true
1 parent 500bf9c commit ad50cd6

File tree

5 files changed

+95
-12
lines changed

5 files changed

+95
-12
lines changed

CHANGELOG.md

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

7+
## 2.5.1 - 2018-04-03
8+
### Fixed
9+
- `create-service-broker` command now only targets an org and space if `space_scoped: true`
10+
- Remove un-necessary cf_target call from `create-domain`
11+
712
## 2.5.0 - 2018-04-02
813
### Added
914
- `scale` command - Change or view the instance count, disk space limit, and memory limit for an app

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,15 @@ Delete a space
153153

154154
Create a domain in an org for later use
155155

156-
* `org`: *Optional.* The organization to target (required if not set in the source config)
157-
* `space`: *Optional.* The space to target (required if not set in the source config)
156+
* `org`: *Optional.* The organization to create the domain in (required if not set in the source config)
158157
* `domain`: *Optional.* The domain to add to the organization
159158

160159
```yml
161160
- put: cf-create-domain
162161
resource: cf-env
163162
params:
164163
command: create-domain
164+
org: myorg
165165
domain: example.com
166166
```
167167

assets/out

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ echo "$params" | jq -c '.commands[]' | while read -r options; do
122122
elif [ "create-domain" = "$command" ]; then
123123
domain=$(echo $options | jq -r '.domain //empty')
124124
printf '\e[92m[INFO]\e[0m Executing \e[33m%s\e[0m: %s\n' "$command" "$domain"
125-
cf_target "$org" "$space"
126125
if cf_has_private_domain "$org" "$domain"; then
127126
printf '\e[92m[INFO]\e[0m \e[95mDomain %s already exists\e[0m\n' "$domain"
128127
else
@@ -309,7 +308,9 @@ echo "$params" | jq -c '.commands[]' | while read -r options; do
309308
url=$(echo $options | jq -r '.url //empty')
310309
is_space_scoped=$(echo $options | jq -r '.space_scoped //"false"')
311310
printf '\e[92m[INFO]\e[0m Executing \e[33m%s\e[0m: %s\n' "$command" "$service_broker"
312-
cf_target "$org" "$space"
311+
if [ "true" = "$is_space_scoped" ]; then
312+
cf_target "$org" "$space"
313+
fi
313314
cf_create_service_broker "$service_broker" "$username" "$password" "$url" "$is_space_scoped"
314315
elif [ "enable-service-access" = "$command" ]; then
315316
service_broker=$(echo $options | jq -r '.service_broker //empty')

itest/helpers.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ source $resource_dir/cf-functions.sh
2626

2727
run() {
2828
export TMPDIR=$(mktemp -d $TMPDIR_ROOT/cf-cli-tests.XXXXXX)
29-
29+
cf logout
3030
printf 'running \e[33m%s\e[0m...\n' "$@"
3131
eval "$@" 2>&1 | sed -e 's/^/ /g'
3232
echo ""

itest/put.sh

Lines changed: 84 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ domain=$testprefix-domain-$timestamp.com
6161

6262
app_name=$testprefix-app-$timestamp
6363
broker_name=$testprefix-broker
64+
broker_space_scoped_name=$testprefix-space-scoped-broker
6465

6566
users_csv=$(cat <<EOF
6667
Username,Password,Org,Space,OrgManager,BillingManager,OrgAuditor,SpaceManager,SpaceDeveloper,SpaceAuditor
@@ -87,8 +88,6 @@ source=$(jq -n \
8788
skip_cert_check: "true",
8889
username: $username,
8990
password: $password,
90-
org: $org,
91-
space: $space,
9291
debug: false,
9392
cf_color: $cf_color,
9493
cf_dial_timeout: $cf_dial_timeout,
@@ -471,6 +470,8 @@ it_can_zero_downtime_push() {
471470
--arg app_name "$app_name" \
472471
'{
473472
command: "zero-downtime-push",
473+
org: $org,
474+
space: $space,
474475
manifest: "static-app/manifest.yml",
475476
current_app_name: $app_name,
476477
environment_variables: {
@@ -610,6 +611,8 @@ it_can_scale_an_app_instances() {
610611
--arg instances "2" \
611612
'{
612613
command: "scale",
614+
org: $org,
615+
space: $space,
613616
app_name: $app_name,
614617
instances: $instances
615618
}')
@@ -633,6 +636,8 @@ it_can_scale_an_app_disk_quota() {
633636
--arg disk_quota "512M" \
634637
'{
635638
command: "scale",
639+
org: $org,
640+
space: $space,
636641
app_name: $app_name,
637642
disk_quota: $disk_quota
638643
}')
@@ -656,6 +661,8 @@ it_can_scale_an_app_memory() {
656661
--arg memory "512M" \
657662
'{
658663
command: "scale",
664+
org: $org,
665+
space: $space,
659666
app_name: $app_name,
660667
memory: $memory
661668
}')
@@ -681,6 +688,8 @@ it_can_scale_an_app() {
681688
--arg memory "1G" \
682689
'{
683690
command: "scale",
691+
org: $org,
692+
space: $space,
684693
app_name: $app_name,
685694
instances: $instances,
686695
disk_quota: $disk_quota,
@@ -703,10 +712,10 @@ it_can_create_a_domain() {
703712

704713
local params=$(jq -n \
705714
--arg org "$org" \
706-
--arg space "$space" \
707715
--arg domain "$domain" \
708716
'{
709717
command: "create-domain",
718+
org: $org,
710719
domain: $domain
711720
}')
712721

@@ -724,10 +733,10 @@ it_can_delete_a_domain() {
724733

725734
local params=$(jq -n \
726735
--arg org "$org" \
727-
--arg space "$space" \
728736
--arg domain "$domain" \
729737
'{
730738
command: "delete-domain",
739+
org: $org,
731740
domain: $domain
732741
}')
733742

@@ -750,6 +759,8 @@ it_can_map_a_route() {
750759
--arg domain "$domain" \
751760
'{
752761
command: "map-route",
762+
org: $org,
763+
space: $space,
753764
app_name: $app_name,
754765
domain: $domain
755766
}')
@@ -773,6 +784,8 @@ it_can_map_a_route_with_hostname() {
773784
--arg hostname "$app_name" \
774785
'{
775786
command: "map-route",
787+
org: $org,
788+
space: $space,
776789
app_name: $app_name,
777790
domain: $domain,
778791
hostname: $hostname
@@ -798,6 +811,8 @@ it_can_map_a_route_with_hostname_and_path() {
798811
--arg path "foo" \
799812
'{
800813
command: "map-route",
814+
org: $org,
815+
space: $space,
801816
app_name: $app_name,
802817
domain: $domain,
803818
hostname: $hostname,
@@ -824,6 +839,8 @@ it_can_unmap_a_route_with_hostname_and_path() {
824839
--arg path "foo" \
825840
'{
826841
command: "unmap-route",
842+
org: $org,
843+
space: $space,
827844
app_name: $app_name,
828845
domain: $domain,
829846
hostname: $hostname,
@@ -849,6 +866,8 @@ it_can_unmap_a_route_with_hostname() {
849866
--arg hostname "$app_name" \
850867
'{
851868
command: "unmap-route",
869+
org: $org,
870+
space: $space,
852871
app_name: $app_name,
853872
domain: $domain,
854873
hostname: $hostname
@@ -872,6 +891,8 @@ it_can_unmap_a_route() {
872891
--arg domain "$domain" \
873892
'{
874893
command: "unmap-route",
894+
org: $org,
895+
space: $space,
875896
app_name: $app_name,
876897
domain: $domain
877898
}')
@@ -884,6 +905,61 @@ it_can_unmap_a_route() {
884905
# TODO: check that the route was unmapped
885906
}
886907

908+
it_can_create_a_service_broker_space_scoped() {
909+
local working_dir=$(mktemp -d $TMPDIR/put-src.XXXXXX)
910+
911+
local commit=dddec578676b8dcbe06158e3ac0b34edc6f5de6e
912+
913+
# if tests are running in concourse, the overview-broker.zip is provided
914+
# by the pipeline. Otherwise, if we are running locally, we'll need to
915+
# download it.
916+
local broker_dir=$working_dir/broker
917+
if [ -d "/opt/service-broker" ]; then
918+
broker_dir=/opt/service-broker
919+
else
920+
mkdir -p $broker_dir
921+
fi
922+
923+
if [ ! -f "$broker_dir/overview-broker.zip" ]; then
924+
wget https://github.com/mattmcneeney/overview-broker/archive/$commit.zip -O $broker_dir/overview-broker.zip
925+
fi
926+
927+
if [ ! -d "$broker_dir/overview-broker-$commit" ]; then
928+
unzip $broker_dir/overview-broker.zip -d $broker_dir
929+
fi
930+
931+
cf_login "$cf_api" "$cf_username" "$cf_password" "$cf_skip_cert_check"
932+
cf_target "$org" "$space"
933+
cf push "${broker_space_scoped_name}" -p "$broker_dir/overview-broker-$commit" #-b "https://github.com/cloudfoundry/nodejs-buildpack#v1.6.11"
934+
cf logout
935+
936+
local params=$(jq -n \
937+
--arg org "$org" \
938+
--arg space "$space" \
939+
--arg service_broker "${broker_space_scoped_name}" \
940+
--arg username admin \
941+
--arg password password \
942+
--arg url "https://${broker_space_scoped_name}.$cf_apps_domain" \
943+
'{
944+
command: "create-service-broker",
945+
org: $org,
946+
space: $space,
947+
service_broker: $service_broker,
948+
username: $username,
949+
password: $password,
950+
url: $url,
951+
space_scoped: true
952+
}')
953+
954+
local config=$(echo $source | jq --argjson params "$params" '.params = $params')
955+
956+
put_with_params "$config" "$working_dir" | jq -e '
957+
.version | keys == ["timestamp"]
958+
'
959+
960+
cf_service_broker_exists "${broker_space_scoped_name}"
961+
}
962+
887963
it_can_create_a_service_broker() {
888964
local working_dir=$(mktemp -d $TMPDIR/put-src.XXXXXX)
889965

@@ -907,8 +983,10 @@ it_can_create_a_service_broker() {
907983
unzip $broker_dir/overview-broker.zip -d $broker_dir
908984
fi
909985

986+
cf_login "$cf_api" "$cf_username" "$cf_password" "$cf_skip_cert_check"
910987
cf_target "$org" "$space"
911-
cf push "$broker_name" -p "$broker_dir/overview-broker-$commit" -b "https://github.com/cloudfoundry/nodejs-buildpack#v1.6.11"
988+
cf push "$broker_name" -p "$broker_dir/overview-broker-$commit"
989+
cf logout
912990

913991
local params=$(jq -n \
914992
--arg org "$org" \
@@ -919,8 +997,6 @@ it_can_create_a_service_broker() {
919997
--arg url "https://$broker_name.$cf_apps_domain" \
920998
'{
921999
command: "create-service-broker",
922-
org: $org,
923-
space: $space,
9241000
service_broker: $service_broker,
9251001
username: $username,
9261002
password: $password,
@@ -1403,6 +1479,7 @@ run it_can_create_a_user_with_password
14031479
run it_can_create_a_user_with_origin
14041480
run it_can_create_users_from_file
14051481

1482+
run it_can_create_a_service_broker_space_scoped
14061483
run it_can_create_a_service_broker
14071484
# run again to prove that it won't error out if it already exists
14081485
run it_can_create_a_service_broker

0 commit comments

Comments
 (0)