Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pkger): add resource links to a stack's resources from public HTTP API list/read calls #19075

Merged
merged 1 commit into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

1. [19066](https://github.com/influxdata/influxdb/pull/19066): Drop deprecated /packages route tree

### Features

1. [19075](https://github.com/influxdata/influxdb/pull/19075): Aadd resource links to a stack's resources from public HTTP API list/read calls

### Bug Fixes

1. [19043](https://github.com/influxdata/influxdb/pull/19043): Enforce all influx CLI flag args are valid
Expand Down
5 changes: 5 additions & 0 deletions http/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8504,6 +8504,11 @@ components:
$ref: "#/components/schemas/TemplateKind"
metaName:
type: string
links:
type: object
properties:
self:
type: string
urls:
type: array
items:
Expand Down
12 changes: 1 addition & 11 deletions pkger/http_remote_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,7 @@ func convertRespStackResources(resources []RespStackResource) ([]StackResource,
Kind: r.Kind,
}
for _, a := range r.Associations {
sra := StackResourceAssociation{
Kind: a.Kind,
MetaName: a.MetaName,
}
if sra.MetaName == "" && a.PkgName != nil {
sra.MetaName = *a.PkgName
}
sr.Associations = append(sr.Associations, sra)
sr.Associations = append(sr.Associations, StackResourceAssociation(a))
}

resID, err := influxdb.IDFromString(r.ID)
Expand All @@ -346,9 +339,6 @@ func convertRespStackResources(resources []RespStackResource) ([]StackResource,
}
sr.ID = *resID

if sr.MetaName == "" && r.PkgName != nil {
sr.MetaName = *r.PkgName
}
out = append(out, sr)
}
return out, nil
Expand Down
47 changes: 37 additions & 10 deletions pkger/http_server_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net/http"
"net/url"
"path"
"time"

"github.com/go-chi/chi"
Expand Down Expand Up @@ -85,19 +86,17 @@ type (
Kind Kind `json:"kind"`
MetaName string `json:"templateMetaName"`
Associations []RespStackResourceAssoc `json:"associations"`

// PkgName is deprecated moving forward, will support until it is
// ripped out.
PkgName *string `json:"pkgName,omitempty"`
Links RespStackResourceLinks `json:"links"`
}

// RespStackResourceAssoc is the response for a stack resource's associations.
RespStackResourceAssoc struct {
Kind Kind `json:"kind"`
MetaName string `json:"metaName"`
}

//PkgName is to be deprecated moving forward
PkgName *string `json:"pkgName,omitempty"`
RespStackResourceLinks struct {
Self string `json:"self"`
}
)

Expand Down Expand Up @@ -389,16 +388,14 @@ func convertStackEvent(ev StackEvent) RespStackEvent {
for _, r := range ev.Resources {
asses := make([]RespStackResourceAssoc, 0, len(r.Associations))
for _, a := range r.Associations {
asses = append(asses, RespStackResourceAssoc{
Kind: a.Kind,
MetaName: a.MetaName,
})
asses = append(asses, RespStackResourceAssoc(a))
}
resources = append(resources, RespStackResource{
APIVersion: r.APIVersion,
ID: r.ID.String(),
Kind: r.Kind,
MetaName: r.MetaName,
Links: stackResLinks(r),
Associations: asses,
})
}
Expand All @@ -414,6 +411,36 @@ func convertStackEvent(ev StackEvent) RespStackEvent {
}
}

func stackResLinks(r StackResource) RespStackResourceLinks {
var linkResource string
switch r.Kind {
case KindBucket:
linkResource = "buckets"
case KindCheck, KindCheckDeadman, KindCheckThreshold:
linkResource = "checks"
case KindDashboard:
linkResource = "dashboards"
case KindLabel:
linkResource = "labels"
case KindNotificationEndpoint,
KindNotificationEndpointHTTP,
KindNotificationEndpointPagerDuty,
KindNotificationEndpointSlack:
linkResource = "notificationEndpoints"
case KindNotificationRule:
linkResource = "notificationRules"
case KindTask:
linkResource = "tasks"
case KindTelegraf:
linkResource = "telegrafs"
case KindVariable:
linkResource = "variables"
}
return RespStackResourceLinks{
Self: path.Join("/api/v2", linkResource, r.ID.String()),
}
}

func stackIDFromReq(r *http.Request) (influxdb.ID, error) {
stackID, err := influxdb.IDFromString(chi.URLParam(r, "stack_id"))
if err != nil {
Expand Down
Loading