MCPcopy Create free account
hub / github.com/cloudfoundry/cli / EnableServiceAccess

Method EnableServiceAccess

actor/v7action/service_access.go:86–143  ·  view source on GitHub ↗
(offeringName, brokerName, orgName, planName string)

Source from the content-addressed store, hash-verified

84}
85
86func (actor *Actor) EnableServiceAccess(offeringName, brokerName, orgName, planName string) (SkippedPlans, Warnings, error) {
87 var allWarnings Warnings
88
89 offering, offeringWarnings, err := actor.CloudControllerClient.GetServiceOfferingByNameAndBroker(offeringName, brokerName)
90 allWarnings = append(allWarnings, offeringWarnings...)
91 if err != nil {
92 return nil, allWarnings, actionerror.EnrichAPIErrors(err)
93 }
94
95 plansQuery := buildPlansFilterForUpdate(offering.GUID, planName)
96 plans, planWarnings, err := actor.CloudControllerClient.GetServicePlans(plansQuery...)
97 allWarnings = append(allWarnings, planWarnings...)
98 if err != nil {
99 return nil, allWarnings, err
100 }
101
102 if len(plans) == 0 {
103 return nil, allWarnings, actionerror.ServicePlanNotFoundError{
104 PlanName: planName,
105 OfferingName: offeringName,
106 }
107 }
108
109 if offeringIsSpaceScoped(plans) {
110 return nil, allWarnings, actionerror.ServicePlanVisibilityTypeError{}
111 }
112
113 visibility := resources.ServicePlanVisibility{Type: resources.ServicePlanVisibilityPublic}
114 if orgName != "" {
115 org, orgWarnings, err := actor.GetOrganizationByName(orgName)
116 allWarnings = append(allWarnings, orgWarnings...)
117 if err != nil {
118 return nil, allWarnings, err
119 }
120
121 visibility.Type = resources.ServicePlanVisibilityOrganization
122 visibility.Organizations = []resources.ServicePlanVisibilityDetail{{GUID: org.GUID}}
123 }
124
125 var skipped SkippedPlans
126 for _, plan := range plans {
127 if plan.VisibilityType == resources.ServicePlanVisibilityPublic && visibility.Type == resources.ServicePlanVisibilityOrganization {
128 skipped = append(skipped, plan.Name)
129 continue
130 }
131
132 _, visibilityWarnings, err := actor.CloudControllerClient.UpdateServicePlanVisibility(
133 plan.GUID,
134 visibility,
135 )
136 allWarnings = append(allWarnings, visibilityWarnings...)
137 if err != nil {
138 return nil, allWarnings, err
139 }
140 }
141
142 return skipped, allWarnings, nil
143}

Callers

nothing calls this directly

Implementers 1

FakeActorcommand/v7/v7fakes/fake_actor.go

Calls 7

GetOrganizationByNameMethod · 0.95
EnrichAPIErrorsFunction · 0.92
offeringIsSpaceScopedFunction · 0.85
GetServicePlansMethod · 0.65

Tested by

no test coverage detected