Skip to content

Commit ea23e24

Browse files
authored
Control plane - get and update app services manifest endpoints (#126)
1 parent 5afaf42 commit ea23e24

File tree

4 files changed

+124
-0
lines changed

4 files changed

+124
-0
lines changed

pkg/controlplane/http/session.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,45 @@ func (s *session) ReloadArtifactVersionManifest(ctx context.Context) (string, er
386386
return jobOutput.ID, nil
387387
}
388388

389+
// GetAppServicesManifests returns app services manifests of tenant related to session's access key
390+
func (s *session) GetAppServicesManifests(
391+
getAppServicesManifestsInput *v3ioc.GetAppServicesManifestsInput) (*v3ioc.GetAppServicesManifestsOutput, error) {
392+
393+
// prepare app services manifests response resource
394+
getAppServicesManifestsOutput := v3ioc.GetAppServicesManifestsOutput{}
395+
396+
if err := s.listResource(getAppServicesManifestsInput.Ctx,
397+
"app_services_manifests",
398+
&getAppServicesManifestsInput.ControlPlaneInput,
399+
&getAppServicesManifestsOutput.ControlPlaneOutput,
400+
&getAppServicesManifestsOutput.AppServicesManifests); err != nil {
401+
return nil, errors.Wrap(err, "Failed to list app services manifests resource")
402+
}
403+
404+
return &getAppServicesManifestsOutput, nil
405+
}
406+
407+
// UpdateAppServicesManifest updates app services manifests of tenant related to session's access key
408+
func (s *session) UpdateAppServicesManifest(
409+
updateAppServicesManifestInput *v3ioc.UpdateAppServicesManifestInput) (*v3ioc.GetJobOutput, error) {
410+
411+
// prepare job response resource
412+
getJobOutput := v3ioc.GetJobOutput{}
413+
414+
// try to update the resource
415+
if err := s.updateResource(updateAppServicesManifestInput.Ctx,
416+
"app_services_manifests",
417+
"app_services_manifest",
418+
&updateAppServicesManifestInput.ControlPlaneInput,
419+
&updateAppServicesManifestInput.AppServicesManifestAttributes,
420+
&getJobOutput.ControlPlaneOutput,
421+
&getJobOutput.JobAttributes); err != nil {
422+
return nil, errors.Wrap(err, "Failed to update app services manifests resource")
423+
}
424+
425+
return &getJobOutput, nil
426+
}
427+
389428
// WaitForJobCompletion waits for completion of job with given id (blocking)
390429
func (s *session) WaitForJobCompletion(ctx context.Context, jobID string, retryInterval, timeout time.Duration) error {
391430
getJobInput := v3ioc.GetJobInput{
@@ -667,6 +706,48 @@ func (s *session) getResource(ctx context.Context,
667706
return nil
668707
}
669708

709+
func (s *session) listResource(ctx context.Context,
710+
path string,
711+
controlPlaneInput *v3ioc.ControlPlaneInput,
712+
controlPlaneOutput *v3ioc.ControlPlaneOutput,
713+
responseData interface{}) error {
714+
715+
// allocate request
716+
httpRequest := fasthttp.AcquireRequest()
717+
defer fasthttp.ReleaseRequest(httpRequest)
718+
719+
responseInstance, err := s.sendRequest(ctx,
720+
&request{
721+
method: http.MethodGet,
722+
path: "api/" + path,
723+
httpRequest: httpRequest,
724+
}, controlPlaneInput.Timeout)
725+
726+
if err != nil {
727+
return errors.Wrapf(err, "Failed to list resource (%s)", path)
728+
}
729+
730+
// if we got cookies, set them
731+
if len(responseInstance.cookies) > 0 {
732+
s.cookies = responseInstance.cookies
733+
}
734+
735+
// unmarshal
736+
if responseInstance.body != nil && controlPlaneOutput != nil {
737+
responseBuffer := bytes.NewBuffer(responseInstance.body)
738+
739+
jsonAPIResponse := jsonapiResources{
740+
Data: responseData,
741+
}
742+
743+
if err := json.NewDecoder(responseBuffer).Decode(&jsonAPIResponse); err != nil {
744+
return errors.Wrap(err, "Failed to decode json api response")
745+
}
746+
}
747+
748+
return nil
749+
}
750+
670751
func (s *session) deleteResource(ctx context.Context,
671752
path string,
672753
kind string,

pkg/controlplane/http/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,7 @@ type jsonapiData struct {
4444
type jsonapiResource struct {
4545
Data jsonapiData `json:"data,omitempty"`
4646
}
47+
48+
type jsonapiResources struct {
49+
Data interface{} `json:"data,omitempty"`
50+
}

pkg/controlplane/resources.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,19 @@ type JobAttributes struct {
207207
UpdatedAt string `json:"updated_at,omitempty"`
208208
Handler string `json:"handler,omitempty"`
209209
}
210+
211+
type AppServicesManifest struct {
212+
Type string `json:"type,omitempty"`
213+
ID int `json:"id,omitempty"`
214+
Attributes AppServicesManifestAttributes `json:"attributes,omitempty"`
215+
}
216+
217+
type AppServicesManifestAttributes struct {
218+
AppServices interface{} `json:"app_services,omitempty"`
219+
ClusterName string `json:"cluster_name,omitempty"`
220+
LastModificationJob string `json:"last_modification_job,omitempty"`
221+
RunningModificationJob string `json:"running_modification_job,omitempty"`
222+
State string `json:"state,omitempty"`
223+
TenantID string `json:"tenant_id,omitempty"`
224+
TenantName string `json:"tenant_name,omitempty"`
225+
}

pkg/controlplane/types.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ type Session interface {
7474
// ReloadArtifactVersionManifestAndWaitForCompletion reloads the platform artifact version manifest and waits for completion (blocking)
7575
ReloadArtifactVersionManifestAndWaitForCompletion(ctx context.Context, retryInterval, timeout time.Duration) error
7676

77+
// UpdateAppServicesManifest updates app services manifests of tenant related to session's access key
78+
UpdateAppServicesManifest(*UpdateAppServicesManifestInput) (*GetJobOutput, error)
79+
80+
// GetAppServicesManifests returns app services manifests of tenant related to session's access key
81+
GetAppServicesManifests(*GetAppServicesManifestsInput) (*GetAppServicesManifestsOutput, error)
82+
7783
// WaitForJobCompletion waits for completion of a job with a given id (blocking)
7884
WaitForJobCompletion(ctx context.Context, jobID string, retryInterval, timeout time.Duration) error
7985

@@ -215,3 +221,20 @@ type JobOutput struct {
215221
ControlPlaneOutput
216222
JobAttributes
217223
}
224+
225+
// GetAppServicesManifestsInput specifies how to get a app services manifests
226+
type GetAppServicesManifestsInput struct {
227+
ControlPlaneInput
228+
}
229+
230+
// GetAppServicesManifestsOutput holds the response from get app services manifests
231+
type GetAppServicesManifestsOutput struct {
232+
ControlPlaneOutput
233+
AppServicesManifests []AppServicesManifest
234+
}
235+
236+
// UpdateAppServicesManifestInput specifies how to get a app services manifests
237+
type UpdateAppServicesManifestInput struct {
238+
ControlPlaneInput
239+
AppServicesManifestAttributes
240+
}

0 commit comments

Comments
 (0)