@@ -72,7 +72,7 @@ func ProofBlueprint(req ProofBlueprintWire, http *gorequest.SuperAgent, cfg *Con
7272 * "template": "<base64 encoded template>"
7373 * }
7474 */
75- type CreateBlueprintResponse struct {
75+ type BlueprintResponse struct {
7676 Name string `json:"name"`
7777 Description string `json:"description"`
7878 Revision string `json:"revision"`
@@ -88,12 +88,12 @@ type CreateBlueprintRequest struct {
8888 Template string `json:"template"`
8989}
9090
91- func CreateBlueprint (req CreateBlueprintRequest , http * gorequest.SuperAgent , cfg * Config ) (out CreateBlueprintResponse , err []error ) {
91+ func CreateBlueprint (req CreateBlueprintRequest , http * gorequest.SuperAgent , cfg * Config ) (out BlueprintResponse , err []error ) {
9292
9393 r , body , errs := AugmentRequest (
9494 http .Post (cfg .Endpoint + "/v1/blueprints" ), cfg ).Send (req ).EndBytes ()
9595
96- var result CreateBlueprintResponse
96+ var result BlueprintResponse
9797
9898 if errs != nil {
9999 return result , errs
@@ -112,16 +112,43 @@ func CreateBlueprint(req CreateBlueprintRequest, http *gorequest.SuperAgent, cfg
112112
113113/////////////////// LISTING BLUEPRINTS ///////////////////
114114
115- // func ListBlueprints(http *gorequest.SuperAgent, cfg *Config) (out CreateBlueprintResponse, err []error) {
116- // }
115+ func ListBlueprints (http * gorequest.SuperAgent , cfg * Config ) (list []BlueprintResponse , err []error ) {
116+ uri := cfg .Endpoint + "/v1/blueprints"
117+ r , body , errs := AugmentRequest (http .Get (uri ), cfg ).EndBytes ()
118+
119+ if errs != nil {
120+ return nil , errs
121+ }
122+
123+ if r .StatusCode / 100 != 2 {
124+ errs = append (errs , errors .New ("Unexpected response from Nelson server" ))
125+ return nil , errs
126+ } else {
127+ var list []BlueprintResponse
128+ if err := json .Unmarshal (body , & list ); err != nil {
129+ panic (err )
130+ }
131+ return list , errs
132+ }
133+ }
134+
135+ func PrintListBlueprints (bps []BlueprintResponse ) {
136+ var tabulized = [][]string {}
137+ for _ , r := range bps {
138+ name := r .Name + "@" + r .Revision
139+ tabulized = append (tabulized , []string {name , r .Description , r .Sha256 , javaEpochToHumanizedTime (r .CreatedAt )})
140+ }
141+
142+ RenderTableToStdout ([]string {"Reference" , "Description" , "Sha256" , "Created" }, tabulized )
143+ }
117144
118145/////////////////// INSPECTING BLUEPRINTS ///////////////////
119146
120- func InspectBlueprint (namedRevision string , http * gorequest.SuperAgent , cfg * Config ) (out CreateBlueprintResponse , err []error ) {
147+ func InspectBlueprint (namedRevision string , http * gorequest.SuperAgent , cfg * Config ) (out BlueprintResponse , err []error ) {
121148 r , body , errs := AugmentRequest (
122149 http .Get (cfg .Endpoint + "/v1/blueprints/" + namedRevision ), cfg ).EndBytes ()
123150
124- var result CreateBlueprintResponse
151+ var result BlueprintResponse
125152
126153 if errs != nil {
127154 return result , errs
0 commit comments