Skip to content

Commit bc690c6

Browse files
authored
✨ Add support for organization. (#26)
* checkpoint Signed-off-by: Jeff Ortel <[email protected]> * checkpoint Signed-off-by: Jeff Ortel <[email protected]> * checkpoint Signed-off-by: Jeff Ortel <[email protected]> * checkpoint Signed-off-by: Jeff Ortel <[email protected]> --------- Signed-off-by: Jeff Ortel <[email protected]>
1 parent 1ac1586 commit bc690c6

File tree

3 files changed

+60
-23
lines changed

3 files changed

+60
-23
lines changed

cmd/cloudfoundry/provider.go

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
137137
type 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.
143152
type 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.
149182
func (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 {

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/cloudfoundry/go-cfclient/v3 v3.0.0-alpha.12.0.20250712142925-13a7dc5466ad
99
github.com/goccy/go-json v0.10.2
1010
github.com/jortel/go-utils v0.1.4
11-
github.com/konveyor/asset-generation v0.1.12
11+
github.com/konveyor/asset-generation v0.1.13-0.20251104205826-798eefac101e
1212
github.com/konveyor/tackle2-addon v0.8.0-alpha.1
1313
github.com/konveyor/tackle2-hub v0.8.0-beta.4.0.20250915141536-ccf24542dd57
1414
github.com/onsi/gomega v1.38.2
@@ -102,7 +102,7 @@ require (
102102
github.com/sirupsen/logrus v1.9.3 // indirect
103103
github.com/spf13/cast v1.7.0 // indirect
104104
github.com/spf13/pflag v1.0.5 // indirect
105-
github.com/stretchr/testify v1.10.0 // indirect
105+
github.com/stretchr/testify v1.11.0 // indirect
106106
github.com/trivago/tgo v1.0.7 // indirect
107107
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
108108
github.com/ugorji/go/codec v1.2.11 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
158158
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
159159
github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk=
160160
github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
161-
github.com/konveyor/asset-generation v0.1.12 h1:G3ZUzCzC+Shl0WqhZ8s/1rt26z2jEbZM9q2WmUGyjF0=
162-
github.com/konveyor/asset-generation v0.1.12/go.mod h1:DYew3e2TaiI0OB05HThjlD/YcO8rZTa+o8JmNPY4uQI=
161+
github.com/konveyor/asset-generation v0.1.13-0.20251104205826-798eefac101e h1:KlmKcDY/MuZD4PGTr7ItcJzZGYkP21LaxfdJxsv0Jdc=
162+
github.com/konveyor/asset-generation v0.1.13-0.20251104205826-798eefac101e/go.mod h1:X5K2VuEV+PEBAI5O+9mNVDtCW4vFWDvFYRThpea+56U=
163163
github.com/konveyor/tackle2-addon v0.8.0-alpha.1 h1:KpeGiJC/YQOUkvp6tOahwz8P/B98nt7oqz/YCnbHK10=
164164
github.com/konveyor/tackle2-addon v0.8.0-alpha.1/go.mod h1:mITXAU1o/8ZdBoGacaTZxXORfFe1q2S74W9RfTHHm7A=
165165
github.com/konveyor/tackle2-hub v0.8.0-beta.4.0.20250915141536-ccf24542dd57 h1:M+V7tWyMoX1Ewty3W0A4P0jBjx+NAWyA9Oi0qclSnSk=
@@ -260,8 +260,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
260260
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
261261
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
262262
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
263-
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
264-
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
263+
github.com/stretchr/testify v1.11.0 h1:ib4sjIrwZKxE5u/Japgo/7SJV3PvgjGiRNAvTVGqQl8=
264+
github.com/stretchr/testify v1.11.0/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
265265
github.com/trivago/tgo v1.0.7 h1:uaWH/XIy9aWYWpjm2CU3RpcqZXmX2ysQ9/Go+d9gyrM=
266266
github.com/trivago/tgo v1.0.7/go.mod h1:w4dpD+3tzNIIiIfkWWa85w5/B77tlvdZckQ+6PkFnhc=
267267
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=

0 commit comments

Comments
 (0)