github.com/safedep/dry@v0.0.0-20241016050132-a15651f0548b/apiguard/tykgen/api_hot_reload.go (about) 1 2 /* 3 * Tyk Gateway API 4 * 5 * The Tyk Gateway API is the primary means for integrating your application with the Tyk API Gateway system. This API is very small, and has no granular permissions system. It is intended to be used purely for internal automation and integration. **Warning: Under no circumstances should outside parties be granted access to this API.** The Tyk Gateway API is capable of: * Managing session objects (key generation) * Managing and listing policies * Managing and listing API Definitions (only when not using the Dashboard) * Hot reloads / reloading a cluster configuration * OAuth client creation (only when not using the Dashboard) In order to use the Gateway API, you'll need to set the `secret` parameter in your tyk.conf file. The shared secret you set should then be sent along as a header with each Gateway API Request in order for it to be successful: ``` x-tyk-authorization: <your-secret> ``` <br/> <b>The Tyk Gateway API is subsumed by the Tyk Dashboard API in Pro installations.</b> 6 * 7 * API version: 5.5.0 8 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) 9 */ 10 package swagger 11 12 import ( 13 "context" 14 "io/ioutil" 15 "net/http" 16 "net/url" 17 "strings" 18 "github.com/antihax/optional" 19 ) 20 21 // Linger please 22 var ( 23 _ context.Context 24 ) 25 26 type HotReloadApiService service 27 /* 28 HotReloadApiService Hot-reload a single node 29 Tyk is capable of reloading configurations without having to stop serving requests. This means that API configurations can be added at runtime, or even modified at runtime and those rules applied immediately without any downtime. 30 * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). 31 * @param optional nil or *HotReloadApiHotReloadOpts - Optional Parameters: 32 * @param "Block" (optional.Bool) - Block a response until the reload is performed. This can be useful in scripting environments like CI/CD workflows. 33 @return ApiStatusMessage 34 */ 35 36 type HotReloadApiHotReloadOpts struct { 37 Block optional.Bool 38 } 39 40 func (a *HotReloadApiService) HotReload(ctx context.Context, localVarOptionals *HotReloadApiHotReloadOpts) (ApiStatusMessage, *http.Response, error) { 41 var ( 42 localVarHttpMethod = strings.ToUpper("Get") 43 localVarPostBody interface{} 44 localVarFileName string 45 localVarFileBytes []byte 46 localVarReturnValue ApiStatusMessage 47 ) 48 49 // create path and map variables 50 localVarPath := a.client.cfg.BasePath + "/tyk/reload/" 51 52 localVarHeaderParams := make(map[string]string) 53 localVarQueryParams := url.Values{} 54 localVarFormParams := url.Values{} 55 56 if localVarOptionals != nil && localVarOptionals.Block.IsSet() { 57 localVarQueryParams.Add("block", parameterToString(localVarOptionals.Block.Value(), "")) 58 } 59 // to determine the Content-Type header 60 localVarHttpContentTypes := []string{} 61 62 // set Content-Type header 63 localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) 64 if localVarHttpContentType != "" { 65 localVarHeaderParams["Content-Type"] = localVarHttpContentType 66 } 67 68 // to determine the Accept header 69 localVarHttpHeaderAccepts := []string{"application/json"} 70 71 // set Accept header 72 localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) 73 if localVarHttpHeaderAccept != "" { 74 localVarHeaderParams["Accept"] = localVarHttpHeaderAccept 75 } 76 if ctx != nil { 77 // API Key Authentication 78 if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { 79 var key string 80 if auth.Prefix != "" { 81 key = auth.Prefix + " " + auth.Key 82 } else { 83 key = auth.Key 84 } 85 localVarHeaderParams["X-Tyk-Authorization"] = key 86 87 } 88 } 89 r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) 90 if err != nil { 91 return localVarReturnValue, nil, err 92 } 93 94 localVarHttpResponse, err := a.client.callAPI(r) 95 if err != nil || localVarHttpResponse == nil { 96 return localVarReturnValue, localVarHttpResponse, err 97 } 98 99 localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) 100 localVarHttpResponse.Body.Close() 101 if err != nil { 102 return localVarReturnValue, localVarHttpResponse, err 103 } 104 105 if localVarHttpResponse.StatusCode < 300 { 106 // If we succeed, return the data, otherwise pass on to decode error. 107 err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 108 if err == nil { 109 return localVarReturnValue, localVarHttpResponse, err 110 } 111 } 112 113 if localVarHttpResponse.StatusCode >= 300 { 114 newErr := GenericSwaggerError{ 115 body: localVarBody, 116 error: localVarHttpResponse.Status, 117 } 118 if localVarHttpResponse.StatusCode == 200 { 119 var v ApiStatusMessage 120 err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 121 if err != nil { 122 newErr.error = err.Error() 123 return localVarReturnValue, localVarHttpResponse, newErr 124 } 125 newErr.model = v 126 return localVarReturnValue, localVarHttpResponse, newErr 127 } 128 return localVarReturnValue, localVarHttpResponse, newErr 129 } 130 131 return localVarReturnValue, localVarHttpResponse, nil 132 } 133 /* 134 HotReloadApiService Hot-reload a Tyk group 135 To reload a whole group of Tyk nodes (without using the Dashboard or host manager). You can send an API request to a single node, this node will then send a notification through the pub/sub infrastructure to all other listening nodes (including the host manager if it is being used to manage NginX) which will then trigger a global reload. 136 * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). 137 @return ApiStatusMessage 138 */ 139 func (a *HotReloadApiService) HotReloadGroup(ctx context.Context) (ApiStatusMessage, *http.Response, error) { 140 var ( 141 localVarHttpMethod = strings.ToUpper("Get") 142 localVarPostBody interface{} 143 localVarFileName string 144 localVarFileBytes []byte 145 localVarReturnValue ApiStatusMessage 146 ) 147 148 // create path and map variables 149 localVarPath := a.client.cfg.BasePath + "/tyk/reload/group" 150 151 localVarHeaderParams := make(map[string]string) 152 localVarQueryParams := url.Values{} 153 localVarFormParams := url.Values{} 154 155 // to determine the Content-Type header 156 localVarHttpContentTypes := []string{} 157 158 // set Content-Type header 159 localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) 160 if localVarHttpContentType != "" { 161 localVarHeaderParams["Content-Type"] = localVarHttpContentType 162 } 163 164 // to determine the Accept header 165 localVarHttpHeaderAccepts := []string{"application/json"} 166 167 // set Accept header 168 localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) 169 if localVarHttpHeaderAccept != "" { 170 localVarHeaderParams["Accept"] = localVarHttpHeaderAccept 171 } 172 if ctx != nil { 173 // API Key Authentication 174 if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { 175 var key string 176 if auth.Prefix != "" { 177 key = auth.Prefix + " " + auth.Key 178 } else { 179 key = auth.Key 180 } 181 localVarHeaderParams["X-Tyk-Authorization"] = key 182 183 } 184 } 185 r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) 186 if err != nil { 187 return localVarReturnValue, nil, err 188 } 189 190 localVarHttpResponse, err := a.client.callAPI(r) 191 if err != nil || localVarHttpResponse == nil { 192 return localVarReturnValue, localVarHttpResponse, err 193 } 194 195 localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) 196 localVarHttpResponse.Body.Close() 197 if err != nil { 198 return localVarReturnValue, localVarHttpResponse, err 199 } 200 201 if localVarHttpResponse.StatusCode < 300 { 202 // If we succeed, return the data, otherwise pass on to decode error. 203 err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 204 if err == nil { 205 return localVarReturnValue, localVarHttpResponse, err 206 } 207 } 208 209 if localVarHttpResponse.StatusCode >= 300 { 210 newErr := GenericSwaggerError{ 211 body: localVarBody, 212 error: localVarHttpResponse.Status, 213 } 214 if localVarHttpResponse.StatusCode == 200 { 215 var v ApiStatusMessage 216 err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")); 217 if err != nil { 218 newErr.error = err.Error() 219 return localVarReturnValue, localVarHttpResponse, newErr 220 } 221 newErr.model = v 222 return localVarReturnValue, localVarHttpResponse, newErr 223 } 224 return localVarReturnValue, localVarHttpResponse, newErr 225 } 226 227 return localVarReturnValue, localVarHttpResponse, nil 228 }