Skip to content

Commit

Permalink
Cherry pick fix (#78)
Browse files Browse the repository at this point in the history
* fix the cherry pick of commits that changed crd/conversion

* must have missed a commit that exposed ConverJobMethod.

* Another fix that must have been missed

* DashboardURL support (#59)

* Add logic for dashboard url

* adding dashboard url

* Fix tests

* Add Spec.Alpha map

* Add parsing test

* Add conversions using alpha string

* Temporarily lock to broker-client-go dashboard branch

* Fix make check

* Bump broker-client-go

* Add updated lock file

* fixing testdata location

* Adding method for recovery function.

* fixing gopkg lock
  • Loading branch information
Shawn Hurley authored May 11, 2018
1 parent 697a231 commit 7e3b976
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 68 deletions.
22 changes: 17 additions & 5 deletions bundle/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
type ExecutorAccessors interface {
PodName() string
LastStatus() StatusMessage
DashboardURL() string
ExtractedCredentials() *ExtractedCredentials
}

Expand All @@ -59,6 +60,7 @@ type Executor interface {

type executor struct {
extractedCredentials *ExtractedCredentials
dashboardURL string
podName string
lastStatus StatusMessage
statusChan chan StatusMessage
Expand Down Expand Up @@ -87,6 +89,11 @@ func (e *executor) LastStatus() StatusMessage {
return e.lastStatus
}

// DashboardURL - Returns the dashboard URL of the APB
func (e *executor) DashboardURL() string {
return e.dashboardURL
}

// ExtractedCredentials - Credentials extracted from the APB while running,
// if they were discovered.
func (e *executor) ExtractedCredentials() *ExtractedCredentials {
Expand Down Expand Up @@ -135,11 +142,16 @@ func (e *executor) actionFinishedWithError(err error) {
}
}

func (e *executor) updateDescription(newDescription string) {
status := e.lastStatus
status.Description = newDescription
e.lastStatus = status
e.statusChan <- status
func (e *executor) updateDescription(newDescription string, dashboardURL string) {
if newDescription != "" {
status := e.lastStatus
status.Description = newDescription
e.lastStatus = status
e.statusChan <- status
}
if dashboardURL != "" {
e.dashboardURL = dashboardURL
}
}

// executeApb - Runs an APB Action with a provided set of inputs
Expand Down
22 changes: 22 additions & 0 deletions bundle/ext_creds.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,28 @@ var (
ErrExtractedCredentialsNotFound = fmt.Errorf("credentials not found")
)

// RecoverExtractCredentials - Recover extracted credentials.
func RecoverExtractCredentials(podname, ns, fqname, id string, method JobMethod, targets []string, rt int) error {
defer runtime.Provider.DestroySandbox(podname, ns, targets, clusterConfig.Namespace, clusterConfig.KeepNamespace, clusterConfig.KeepNamespaceOnError)
credBytes, err := runtime.Provider.ExtractCredentials(podname, ns, rt)
if err != nil {
log.Errorf("bundle unable to extract credentials - %v", err)
return err
}
creds, err := buildExtractedCredentials(credBytes)
if err != nil {
log.Errorf("bundle unable to build extracted credentials - %v", err)
return err
}
labels := map[string]string{"apbAction": string(method), "apbName": fqname}
err = runtime.Provider.CreateExtractedCredential(id, clusterConfig.Namespace, creds.Credentials, labels)
if err != nil {
log.Errorf("Bundle unable to save extracted credentials - %v", err)
return err
}
return nil
}

// GetExtractedCredentials - Will get the extracted credentials for a caller of the APB package.
func GetExtractedCredentials(id string) (*ExtractedCredentials, error) {
creds, err := runtime.Provider.GetExtractedCredential(id, clusterConfig.Namespace)
Expand Down
14 changes: 14 additions & 0 deletions bundle/mock_executor.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions bundle/testdata/alpha_apb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 1.0
name: demo-apb
description: This is a sample application generated by apb init
bindable: False
async: optional
metadata:
displayName: demo
plans:
- name: default
description: This default plan deploys demo-apb
free: True
metadata: {}
parameters: []
alpha:
dashboard_redirect: True
12 changes: 7 additions & 5 deletions bundle/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ type Spec struct {
Metadata map[string]interface{} `json:"metadata,omitempty"`
Async string `json:"async"`
Plans []Plan `json:"plans"`
Alpha map[string]interface{} `json:"alpha,omitempty"`
}

// GetPlan - retrieves a plan from a spec by name. Will return
Expand Down Expand Up @@ -289,11 +290,12 @@ func NewSpecManifest(specs []*Spec) SpecManifest {

// ServiceInstance - Service Instance describes a running service.
type ServiceInstance struct {
ID uuid.UUID `json:"id"`
Spec *Spec `json:"spec"`
Context *Context `json:"context"`
Parameters *Parameters `json:"parameters"`
BindingIDs map[string]bool `json:"binding_ids"`
ID uuid.UUID `json:"id"`
Spec *Spec `json:"spec"`
Context *Context `json:"context"`
Parameters *Parameters `json:"parameters"`
BindingIDs map[string]bool `json:"binding_ids"`
DashboardURL string `json:"dashboard_url"`
}

// AddBinding - Add binding ID to service instance
Expand Down
53 changes: 50 additions & 3 deletions bundle/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"path/filepath"
"reflect"
"testing"

Expand All @@ -28,6 +30,17 @@ import (
yaml "gopkg.in/yaml.v2"
)

const alphaApbTestFile = "alpha_apb.yml"

func loadTestFile(t *testing.T, name string) []byte {
path := filepath.Join("testdata", name)
bytes, err := ioutil.ReadFile(path)
if err != nil {
t.Fatal(err)
}
return bytes
}

const PlanName = "dev"
const PlanDescription = "Mediawiki123 apb implementation"

Expand Down Expand Up @@ -156,6 +169,13 @@ const SpecPlans = `
]
`

var SpecAlpha = map[string]interface{}{"dashboard_redirect": true}
var SpecAlphaStr = `
{
"dashboard_redirect": true
}
`

var SpecJSON = fmt.Sprintf(`
{
"id": "",
Expand All @@ -167,12 +187,12 @@ var SpecJSON = fmt.Sprintf(`
"image": "%s",
"bindable": %t,
"async": "%s",
"plans": %s
"plans": %s,
"alpha": %s
}
`, SpecDescription, SpecVersion, SpecRuntime, SpecName, SpecImage, SpecBindable, SpecAsync, SpecPlans)
`, SpecDescription, SpecVersion, SpecRuntime, SpecName, SpecImage, SpecBindable, SpecAsync, SpecPlans, SpecAlphaStr)

func TestSpecLoadJSON(t *testing.T) {

s := Spec{}
err := LoadJSON(SpecJSON, &s)
if err != nil {
Expand All @@ -187,6 +207,7 @@ func TestSpecLoadJSON(t *testing.T) {
ft.Equal(t, s.Bindable, SpecBindable)
ft.Equal(t, s.Async, SpecAsync)
ft.True(t, reflect.DeepEqual(s.Plans[0].Parameters, expectedPlanParameters))
ft.True(t, reflect.DeepEqual(s.Alpha, SpecAlpha))
}

func EncodedApb() string {
Expand All @@ -204,6 +225,7 @@ func TestSpecDumpJSON(t *testing.T) {
Bindable: SpecBindable,
Async: SpecAsync,
Plans: []Plan{p},
Alpha: SpecAlpha,
}

var knownMap interface{}
Expand Down Expand Up @@ -410,3 +432,28 @@ func TestBuildExtractedCredentials(t *testing.T) {
ft.Equal(t, bd.Credentials["user"], "duder_two", "user is not duder_two")
ft.Equal(t, bd.Credentials["pass"], "dog8two", "password is not dog8two")
}

func TestAlphaParser(t *testing.T) {
spec := &Spec{}
testYaml := loadTestFile(t, alphaApbTestFile)
if err := yaml.Unmarshal(testYaml, spec); err != nil {
t.Fatal(err)
}

if len(spec.Alpha) == 0 {
t.Error("spec.Alpha should not be empty")
}

var val interface{}
var dr, ok bool

if val, ok = spec.Alpha["dashboard_redirect"]; !ok {
t.Error("spec.Alpha should contain dashboard_redirect key")
}

if dr, ok = val.(bool); !ok {
t.Error(`spec.Alpha["dashboard_redirect"] should assert to bool`)
}

ft.True(t, dr)
}
Loading

0 comments on commit 7e3b976

Please sign in to comment.