@@ -80,6 +80,26 @@ func (c *RegistrarClient) setZosVersion(v string, safeToUpgrade bool) (err error
80
80
return errors .Wrap (err , "failed to construct registrar url" )
81
81
}
82
82
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
+
83
103
version := ZosVersion {
84
104
Version : v ,
85
105
SafeToUpgrade : safeToUpgrade ,
@@ -91,24 +111,35 @@ func (c *RegistrarClient) setZosVersion(v string, safeToUpgrade bool) (err error
91
111
return errors .Wrap (err , "failed to encode request body" )
92
112
}
93
113
94
- req , err := http . NewRequest ( "PUT" , url , & body )
114
+ resp , err := sendRequest ( body )
95
115
if err != nil {
96
- return errors . Wrap ( err , "failed to construct http request to the registrar" )
116
+ return err
97
117
}
118
+ defer resp .Body .Close ()
98
119
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
+ }
105
126
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
+ }
110
132
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
+ }
112
143
113
144
if resp .StatusCode != http .StatusOK {
114
145
return parseResponseError (resp .Body )
0 commit comments