@@ -38,10 +38,11 @@ func (p *Provider) Fetch(application *api.Application) (m *api.Manifest, err err
3838 return
3939 }
4040 ref := cfp.AppReference {
41+ OrgName : coordinates .Organization ,
4142 SpaceName : coordinates .Space ,
4243 AppName : coordinates .Name ,
4344 }
44- client , err := p .client (ref . SpaceName )
45+ client , err := p .client (coordinates . Filter () )
4546 if err != nil {
4647 return
4748 }
@@ -63,34 +64,32 @@ func (p *Provider) Find(filter api.Map) (found []api.Application, err error) {
6364 if err != nil {
6465 return
6566 }
66- client , err := p .client (f . Spaces ... )
67+ client , err := p .client (f )
6768 if err != nil {
6869 return
6970 }
70- spaces , err := client .ListApps ()
71+ refs , err := client .ListApps ()
7172 if err != nil {
7273 return
7374 }
7475 schema , err := addon .Schema .Find ("platform" , "cloudfoundry" , "coordinates" )
7576 if err != nil {
7677 return
7778 }
78- for space , applications := range spaces {
79- if ! f .MatchSpace (space ) {
80- continue
81- }
79+ for _ , applications := range refs {
8280 for _ , ref := range applications {
8381 appRef := ref .(cfp.AppReference )
84- if ! f .MatchName (appRef . AppName ) {
82+ if ! f .Match (appRef ) {
8583 continue
8684 }
8785 r := api.Application {}
8886 r .Name = appRef .AppName
8987 r .Coordinates = & jsd.Document {
9088 Schema : schema .Name ,
9189 Content : json.Map {
92- "name" : appRef .AppName ,
93- "space" : space ,
90+ "organization" : appRef .OrgName ,
91+ "space" : appRef .SpaceName ,
92+ "name" : appRef .AppName ,
9493 },
9594 }
9695 found = append (found , r )
@@ -105,7 +104,7 @@ func (p *Provider) Tag() string {
105104}
106105
107106// client returns a cloudfoundry client.
108- func (p * Provider ) client (spaces ... string ) (client * cfp.CloudFoundryProvider , err error ) {
107+ func (p * Provider ) client (filter Filter ) (client * cfp.CloudFoundryProvider , err error ) {
109108 options := []cf.Option {
110109 cf .SkipTLSValidation (),
111110 }
@@ -123,7 +122,8 @@ func (p *Provider) client(spaces ...string) (client *cfp.CloudFoundryProvider, e
123122 }
124123 pConfig := & cfp.Config {
125124 CloudFoundryConfig : cfConfig ,
126- SpaceNames : spaces ,
125+ OrgNames : filter .Organizations ,
126+ SpaceNames : filter .Spaces ,
127127 }
128128 client , err = cfp .New (pConfig , & addon .Log , true )
129129 if err != nil {
@@ -135,18 +135,55 @@ func (p *Provider) client(spaces ...string) (client *cfp.CloudFoundryProvider, e
135135
136136// Coordinates - platform coordinates.
137137type Coordinates struct {
138- Space string `json:"space"`
139- Name string `json:"name"`
138+ Organization string `json:"organization"`
139+ Space string `json:"space"`
140+ Name string `json:"name"`
141+ }
142+
143+ // Filter returns a filter.
144+ func (c * Coordinates ) Filter () (f Filter ) {
145+ f .Organizations = []string {c .Organization }
146+ f .Spaces = []string {c .Space }
147+ f .Names = []string {c .Name }
148+ return
140149}
141150
142151// Filter applications.
143152type Filter struct {
144- Spaces []string `json:"spaces"`
145- Names []string `json:"names"`
153+ Organizations []string `json:"organizations"`
154+ Spaces []string `json:"spaces"`
155+ Names []string `json:"names"`
156+ }
157+
158+ // Match returns true when the ref matches the filter.
159+ func (f * Filter ) Match (ref cfp.AppReference ) (match bool ) {
160+ match = f .MatchOrganization (ref .OrgName ) &&
161+ f .MatchSpace (ref .SpaceName ) &&
162+ f .MatchName (ref .AppName )
163+ return
164+ }
165+
166+ // MatchOrganization returns true when the organization name matches the filter.
167+ func (f * Filter ) MatchOrganization (name string ) (match bool ) {
168+ if len (f .Organizations ) == 0 {
169+ match = true
170+ return
171+ }
172+ for _ , s := range f .Organizations {
173+ match = s == name
174+ if match {
175+ break
176+ }
177+ }
178+ return
146179}
147180
148- // MatchSpace returns true when the application name matches the filter.
181+ // MatchSpace returns true when the space name matches the filter.
149182func (f * Filter ) MatchSpace (name string ) (match bool ) {
183+ if len (f .Spaces ) == 0 {
184+ match = true
185+ return
186+ }
150187 for _ , s := range f .Spaces {
151188 match = s == name
152189 if match {
0 commit comments