@@ -80,6 +80,26 @@ func (c *RegistrarClient) setZosVersion(v string, safeToUpgrade bool) (err error
8080 return errors .Wrap (err , "failed to construct registrar url" )
8181 }
8282
83+ sendRequest := func (body bytes.Buffer ) (resp * http.Response , err error ) {
84+ req , err := http .NewRequest ("PUT" , url , & body )
85+ if err != nil {
86+ return resp , errors .Wrap (err , "failed to construct http request to the registrar" )
87+ }
88+
89+ authHeader , err := c .signRequest (time .Now ().Unix ())
90+ if err != nil {
91+ return resp , errors .Wrap (err , "failed to sign request" )
92+ }
93+ req .Header .Set ("X-Auth" , authHeader )
94+ req .Header .Set ("Content-Type" , "application/json" )
95+
96+ resp , err = c .httpClient .Do (req )
97+ if err != nil {
98+ return resp , errors .Wrap (err , "failed to send request to get zos version from the registrar" )
99+ }
100+ return resp , nil
101+ }
102+
83103 version := ZosVersion {
84104 Version : v ,
85105 SafeToUpgrade : safeToUpgrade ,
@@ -91,24 +111,35 @@ func (c *RegistrarClient) setZosVersion(v string, safeToUpgrade bool) (err error
91111 return errors .Wrap (err , "failed to encode request body" )
92112 }
93113
94- req , err := http . NewRequest ( "PUT" , url , & body )
114+ resp , err := sendRequest ( body )
95115 if err != nil {
96- return errors . Wrap ( err , "failed to construct http request to the registrar" )
116+ return err
97117 }
118+ defer resp .Body .Close ()
98119
99- authHeader , err := c . signRequest ( time . Now (). Unix ())
100- if err != nil {
101- return errors . Wrap ( err , "failed to sign request" )
102- }
103- req . Header . Set ( "X-Auth" , authHeader )
104- req . Header . Set ( "Content-Type" , "application/json" )
120+ if resp . StatusCode == http . StatusBadRequest {
121+ // fallback to old encoded format
122+ jsonData , err := json . Marshal ( version )
123+ if err != nil {
124+ return errors . Wrap ( err , "failed to marshal zos version" )
125+ }
105126
106- resp , err := c .httpClient .Do (req )
107- if err != nil {
108- return errors .Wrap (err , "failed to send request to get zos version from the registrar" )
109- }
127+ encodedVersion := struct {
128+ Version string `json:"version"`
129+ }{
130+ Version : base64 .StdEncoding .EncodeToString (jsonData ),
131+ }
110132
111- defer resp .Body .Close ()
133+ jsonData , err = json .Marshal (encodedVersion )
134+ if err != nil {
135+ return errors .Wrap (err , "failed to marshal zos version in hex format" )
136+ }
137+
138+ resp , err = sendRequest (* bytes .NewBuffer (jsonData ))
139+ if err != nil {
140+ return err
141+ }
142+ }
112143
113144 if resp .StatusCode != http .StatusOK {
114145 return parseResponseError (resp .Body )
0 commit comments