summaryrefslogtreecommitdiff
path: root/vendor/github.com/microsoft/azure-devops-go-api/azuredevops/models.go
blob: 0079749ffa2d4c5ca88bbaa229bb3e1285dc3576 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package azuredevops

import (
	"encoding/json"
	"strconv"
	"strings"
	"time"

	"github.com/google/uuid"
)

// ApiResourceLocation Information about the location of a REST API resource
type ApiResourceLocation struct {
	// Area name for this resource
	Area *string `json:"area,omitempty"`
	// Unique Identifier for this location
	Id *uuid.UUID `json:"id,omitempty"`
	// Maximum api version that this resource supports (current server version for this resource)
	MaxVersion *string `json:"maxVersion,omitempty"`
	// Minimum api version that this resource supports
	MinVersion *string `json:"minVersion,omitempty"`
	// The latest version of this resource location that is in "Release" (non-preview) mode
	ReleasedVersion *string `json:"releasedVersion,omitempty"`
	// Resource name
	ResourceName *string `json:"resourceName,omitempty"`
	// The current resource version supported by this resource location
	ResourceVersion *int `json:"resourceVersion,omitempty"`
	// This location's route template (templated relative path)
	RouteTemplate *string `json:"routeTemplate,omitempty"`
}

// WrappedImproperError
type WrappedImproperError struct {
	Count *int           `json:"count,omitempty"`
	Value *ImproperError `json:"value,omitempty"`
}

// ImproperError
type ImproperError struct {
	Message *string `json:"Message,omitempty"`
}

// KeyValuePair
type KeyValuePair struct {
	Key   *interface{} `json:"key,omitempty"`
	Value *interface{} `json:"value,omitempty"`
}

// ResourceAreaInfo
type ResourceAreaInfo struct {
	Id          *uuid.UUID `json:"id,omitempty"`
	LocationUrl *string    `json:"locationUrl,omitempty"`
	Name        *string    `json:"name,omitempty"`
}

type Time struct {
	Time time.Time
}

func (t *Time) UnmarshalJSON(b []byte) error {
	t2 := time.Time{}
	err := json.Unmarshal(b, &t2)

	if err != nil {
		parseError, ok := err.(*time.ParseError)
		if ok {
			if parseError.Value == "\"0001-01-01T00:00:00\"" {
				// ignore errors for 0001-01-01T00:00:00 dates. The Azure DevOps service
				// returns default dates in a format that is invalid for a time.Time. The
				// correct value would have a 'z' at the end to represent utc. We are going
				// to ignore this error, and set the value to the default time.Time value.
				// https://github.com/microsoft/azure-devops-go-api/issues/17
				err = nil
			} else {
				// workaround for bug https://github.com/microsoft/azure-devops-go-api/issues/59
				// policy.CreatePolicyConfiguration returns an invalid date format of form
				// "2006-01-02T15:04:05.999999999"
				var innerError error
				t2, innerError = time.Parse("2006-01-02T15:04:05.999999999", strings.Trim(parseError.Value, "\""))
				if innerError == nil {
					err = nil
				}
			}
		}
	}

	t.Time = t2
	return err
}

func (t *Time) MarshalJSON() ([]byte, error) {
	return json.Marshal(t.Time)
}

// AsQueryParameter formats time value for query parameter usage.
func (t Time) AsQueryParameter() string {
	return t.Time.Format(time.RFC3339Nano)
}

func (t Time) String() string {
	return t.Time.String()
}

func (t Time) Equal(u Time) bool {
	return t.Time.Equal(u.Time)
}

// ServerSystemError
type ServerSystemError struct {
	ClassName      *string            `json:"className,omitempty"`
	InnerException *ServerSystemError `json:"innerException,omitempty"`
	Message        *string            `json:"message,omitempty"`
}

func (e ServerSystemError) Error() string {
	return *e.Message
}

// VssJsonCollectionWrapper -
type VssJsonCollectionWrapper struct {
	Count *int           `json:"count"`
	Value *[]interface{} `json:"value"`
}

// WrappedError
type WrappedError struct {
	ExceptionId      *string                 `json:"$id,omitempty"`
	InnerError       *WrappedError           `json:"innerException,omitempty"`
	Message          *string                 `json:"message,omitempty"`
	TypeName         *string                 `json:"typeName,omitempty"`
	TypeKey          *string                 `json:"typeKey,omitempty"`
	ErrorCode        *int                    `json:"errorCode,omitempty"`
	EventId          *int                    `json:"eventId,omitempty"`
	CustomProperties *map[string]interface{} `json:"customProperties,omitempty"`
	StatusCode       *int
}

func (e WrappedError) Error() string {
	if e.Message == nil {
		if e.StatusCode != nil {
			return "REST call returned status code " + strconv.Itoa(*e.StatusCode)
		}
		return ""
	}
	return *e.Message
}