11package cloudgov
22
3- import (
4- "errors"
5- "fmt"
3+ import "context"
64
7- "github.com/cloudfoundry/go-cfclient/v3/resource"
8- )
9-
10- // Stuff we'll need to implement, for ref
11- //
12- // mapRoute()
13- //
14- // addNetworkPolicy()
15- // removeNetworkPolicy()
165type ClientAPI interface {
176 connect (url string , creds * Creds ) error
187
198 appGet (id string ) (* App , error )
209 appPush (m * AppManifest ) (* App , error )
2110 appDelete (id string ) error
2211 appsList () (apps []* App , err error )
12+
13+ sshCode () (string , error )
14+ mapRoute (ctx context.Context , app * App , domain string , space string , host string , path string , port int ) error
15+ addNetworkPolicy (app * App , dest string , space string , port string ) error
2316}
2417
2518type CredsGetter interface {
@@ -46,8 +39,10 @@ func (e CloudGovClientError) Error() string {
4639 return e .msg
4740}
4841
49- // TODO: we should pull this out of VCAP_APPLICATION
50- const apiRootURLDefault = "https://api.fr.cloud.gov"
42+ const (
43+ apiRootURLDefault = "https://api.fr-stage.cloud.gov"
44+ internalDomainGUID = "8a5d6a8c-cfc1-4fc4-afc9-aa563ff9df5e"
45+ )
5146
5247func New (i ClientAPI , o * Opts ) (* Client , error ) {
5348 if o == nil {
@@ -83,9 +78,10 @@ func (c *Client) Connect() (*Client, error) {
8378}
8479
8580type App struct {
86- Name string
87- GUID string
88- State string
81+ Name string
82+ GUID string
83+ State string
84+ SpaceGUID string
8985}
9086
9187func (c * Client ) AppGet (id string ) (* App , error ) {
@@ -102,34 +98,15 @@ func (c *Client) AppsList() ([]*App, error) {
10298
10399// TODO: this abstraction might belong in /cmd,
104100// unless it can be further generalized to all pushes
105- func (c * Client ) ServicePush (manifest * AppManifest ) (* App , error ) {
101+ func (c * Client ) Push (manifest * AppManifest ) (* App , error ) {
106102 containerID := manifest .Name
107103
108104 if containerID == "" {
109- return nil , CloudGovClientError {"ServicePush : AppManifest.Name must be defined" }
105+ return nil , CloudGovClientError {"Push : AppManifest.Name must be defined" }
110106 }
111107
112108 if manifest .OrgName == "" || manifest .SpaceName == "" {
113- return nil , CloudGovClientError {"ServicePush: AppManifest must have Org and Space names" }
114- }
115-
116- // check for an old instance of the service, delete if found
117- app , err := c .AppGet (containerID )
118- if err != nil {
119- var cferr resource.CloudFoundryError
120- if errors .As (err , & cferr ) {
121- err = nil
122- if cferr .Code != 10010 {
123- return nil , fmt .Errorf ("unexpected cferr checking for existing app: %w" , cferr )
124- }
125- } else {
126- return nil , fmt .Errorf ("error checking for existing service (%v): %w" , containerID , err )
127- }
128- }
129- if app != nil {
130- if err := c .AppDelete (containerID ); err != nil {
131- return nil , fmt .Errorf ("error deleting existing service (%v): %w" , containerID , err )
132- }
109+ return nil , CloudGovClientError {"Push: AppManifest must have Org and Space names" }
133110 }
134111
135112 return c .appPush (manifest )
@@ -144,7 +121,7 @@ func (c *Client) ServicesPush(manifests []*AppManifest) ([]*App, error) {
144121 apps := make ([]* App , len (manifests ))
145122
146123 for i , s := range manifests {
147- app , err := c .ServicePush (s )
124+ app , err := c .Push (s )
148125 if err != nil {
149126 return nil , err
150127 }
@@ -153,3 +130,11 @@ func (c *Client) ServicesPush(manifests []*AppManifest) ([]*App, error) {
153130
154131 return apps , nil
155132}
133+
134+ func (c * Client ) SSHCode () (string , error ) {
135+ return c .sshCode ()
136+ }
137+
138+ func (c * Client ) MapServiceRoute (app * App ) error {
139+ return c .mapRoute (context .Background (), app , internalDomainGUID , app .SpaceGUID , app .Name , "" , 0 )
140+ }
0 commit comments