Skip to content

Commit 8ed41ce

Browse files
authored
Releasing version 2.3.0 (#124)
Releasing version 2.3.0
1 parent c4639e5 commit 8ed41ce

File tree

92 files changed

+4751
-52
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+4751
-52
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66

7+
## 2.3.0 - 2018-08-23
8+
### Added
9+
- Support for fault domain in the Identity Service
10+
- Support for Autonomous Data Warehouse and Autonomous Transaction Processing in the Database service
11+
- Support for resizing an offline volume in the Block Storage service
12+
- Nil interface when polymorphic json response object is null
13+
714
## 2.2.0 - 2018-07-26
815
### Added
916
- Support for fault domains in the Compute service

common/client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ func (client BaseClient) Call(ctx context.Context, request *http.Request) (respo
285285
Logln("not dumping body too big")
286286
dumpBody = false
287287
}
288-
if dump, e := httputil.DumpRequest(request, dumpBody); e == nil {
288+
if dump, e := httputil.DumpRequestOut(request, dumpBody); e == nil {
289289
Logf("Dump Request %v", string(dump))
290290
} else {
291291
Debugln(e)

common/helpers.go

+45-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"encoding/pem"
1010
"fmt"
1111
"reflect"
12+
"strconv"
1213
"strings"
1314
"time"
1415
)
@@ -81,15 +82,33 @@ func PointerString(datastruct interface{}) (representation string) {
8182
return
8283
}
8384

84-
// SDKTime a time struct, which renders to/from json using RFC339
85+
// SDKTime a struct that parses/renders to/from json using RFC339 date-time information
8586
type SDKTime struct {
8687
time.Time
8788
}
8889

90+
// SDKDate a struct that parses/renders to/from json using only date information
91+
type SDKDate struct {
92+
//Date date information
93+
Date time.Time
94+
}
95+
8996
func sdkTimeFromTime(t time.Time) SDKTime {
9097
return SDKTime{t}
9198
}
9299

100+
func sdkDateFromTime(t time.Time) SDKDate {
101+
return SDKDate{Date: t}
102+
}
103+
104+
func formatTime(t SDKTime) string {
105+
return t.Format(sdkTimeFormat)
106+
}
107+
108+
func formatDate(t SDKDate) string {
109+
return t.Date.Format(sdkDateFormat)
110+
}
111+
93112
func now() *SDKTime {
94113
t := SDKTime{time.Now()}
95114
return &t
@@ -98,13 +117,13 @@ func now() *SDKTime {
98117
var timeType = reflect.TypeOf(SDKTime{})
99118
var timeTypePtr = reflect.TypeOf(&SDKTime{})
100119

101-
const sdkTimeFormat = time.RFC3339
120+
var sdkDateType = reflect.TypeOf(SDKDate{})
121+
var sdkDateTypePtr = reflect.TypeOf(&SDKDate{})
102122

123+
//Formats for sdk supported time representations
124+
const sdkTimeFormat = time.RFC3339
103125
const rfc1123OptionalLeadingDigitsInDay = "Mon, _2 Jan 2006 15:04:05 MST"
104-
105-
func formatTime(t SDKTime) string {
106-
return t.Format(sdkTimeFormat)
107-
}
126+
const sdkDateFormat = "2006-01-02"
108127

109128
func tryParsingTimeWithValidFormatsForHeaders(data []byte, headerName string) (t time.Time, err error) {
110129
header := strings.ToLower(headerName)
@@ -149,6 +168,26 @@ func (t *SDKTime) MarshalJSON() (buff []byte, e error) {
149168
return
150169
}
151170

171+
// UnmarshalJSON unmarshals from json
172+
func (t *SDKDate) UnmarshalJSON(data []byte) (e error) {
173+
if string(data) == `"null"` {
174+
t.Date = time.Time{}
175+
return
176+
}
177+
178+
t.Date, e = tryParsing(data,
179+
strconv.Quote(sdkDateFormat),
180+
)
181+
return
182+
}
183+
184+
// MarshalJSON marshals to JSON
185+
func (t *SDKDate) MarshalJSON() (buff []byte, e error) {
186+
s := t.Date.Format(sdkDateFormat)
187+
buff = []byte(strconv.Quote(s))
188+
return
189+
}
190+
152191
// PrivateKeyFromBytes is a helper function that will produce a RSA private
153192
// key from bytes.
154193
func PrivateKeyFromBytes(pemData []byte, password *string) (key *rsa.PrivateKey, e error) {

common/helpers_test.go

+77
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
package common
44

55
import (
6+
"encoding/json"
67
"fmt"
78
"github.com/stretchr/testify/assert"
9+
"reflect"
810
"testing"
11+
"time"
912
)
1013

1114
func TestStructToString(t *testing.T) {
@@ -82,3 +85,77 @@ func TestDateParsing_LastModifiedHeaderDate(t *testing.T) {
8285
assert.Equal(t, tt.Day(), 2)
8386
}
8487
}
88+
89+
func TestFormattedTimeMarshaling(t *testing.T) {
90+
sampleTime, _ := time.Parse(time.UnixDate, "Mon Jan 02 15:04:05 MST 2006")
91+
testIO := []struct {
92+
name string
93+
t *SDKDate
94+
expectedJSON string
95+
expectedError error
96+
}{
97+
{
98+
name: "formatting time to simple date format",
99+
t: &SDKDate{Date: sampleTime},
100+
expectedJSON: `"2006-01-02"`,
101+
expectedError: nil,
102+
},
103+
{
104+
name: "formatting nil",
105+
t: nil,
106+
expectedJSON: `null`,
107+
expectedError: nil,
108+
},
109+
}
110+
111+
for _, tc := range testIO {
112+
t.Run(tc.name, func(t *testing.T) {
113+
bytes, e := json.Marshal(&tc.t)
114+
assert.Equal(t, tc.expectedError, e)
115+
assert.Equal(t, tc.expectedJSON, string(bytes))
116+
})
117+
}
118+
119+
}
120+
121+
func TestFormattedTimeUnMarshaling(t *testing.T) {
122+
sampleTime, _ := time.Parse(time.UnixDate, "Mon Jan 02 15:04:05 MST 2006")
123+
testIO := []struct {
124+
name string
125+
json string
126+
expectedTime *SDKDate
127+
expectedError error
128+
}{
129+
{
130+
name: "unmarshaling time to simple date format",
131+
expectedTime: &SDKDate{Date: sampleTime},
132+
json: `"2006-01-02"`,
133+
expectedError: nil,
134+
},
135+
{
136+
name: "unmarshaling time to simple RFC3339 format",
137+
expectedTime: &SDKDate{Date: sampleTime},
138+
json: `"2006-01-02T15:04:05Z"`,
139+
expectedError: &time.ParseError{},
140+
},
141+
{
142+
name: "unmarshaling null",
143+
expectedTime: &SDKDate{},
144+
json: `"null"`,
145+
expectedError: nil,
146+
},
147+
}
148+
149+
for _, tc := range testIO {
150+
t.Run(tc.name, func(t *testing.T) {
151+
newTime := SDKDate{}
152+
e := json.Unmarshal([]byte(tc.json), &newTime)
153+
assert.IsType(t, reflect.TypeOf(tc.expectedError), reflect.TypeOf(e))
154+
if tc.expectedError != nil {
155+
return
156+
}
157+
assert.Equal(t, tc.expectedTime.Date.Format(sdkDateFormat), newTime.Date.Format(sdkDateFormat))
158+
})
159+
}
160+
161+
}

common/http.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ func toStringValue(v reflect.Value, field reflect.StructField) (string, error) {
4242
return formatTime(t), nil
4343
}
4444

45+
if v.Type() == sdkDateType {
46+
t := v.Interface().(SDKDate)
47+
return formatDate(t), nil
48+
}
49+
4550
switch v.Kind() {
4651
case reflect.Bool:
4752
return strconv.FormatBool(v.Bool()), nil
@@ -165,7 +170,8 @@ func omitNilFieldsInJSON(data interface{}, value reflect.Value) (interface{}, er
165170
continue
166171
}
167172

168-
if currentFieldValue.Type() == timeType || currentFieldValue.Type() == timeTypePtr {
173+
if currentFieldValue.Type() == timeType || currentFieldValue.Type() == timeTypePtr ||
174+
currentField.Type == sdkDateType || currentField.Type == sdkDateTypePtr {
169175
continue
170176
}
171177
// does it need to be adjusted?
@@ -643,6 +649,16 @@ func analyzeValue(stringValue string, kind reflect.Kind, field reflect.StructFie
643649
val = reflect.ValueOf(sdkTime)
644650
valPointer = reflect.ValueOf(&sdkTime)
645651
return
652+
case sdkDateType.Kind():
653+
var t time.Time
654+
t, err = tryParsingTimeWithValidFormatsForHeaders([]byte(stringValue), field.Name)
655+
if err != nil {
656+
return
657+
}
658+
sdkDate := sdkDateFromTime(t)
659+
val = reflect.ValueOf(sdkDate)
660+
valPointer = reflect.ValueOf(&sdkDate)
661+
return
646662
case reflect.Bool:
647663
var bVal bool
648664
if bVal, err = strconv.ParseBool(stringValue); err != nil {

0 commit comments

Comments
 (0)