I'm following the FOSRest documentation on API versioning.
However it's not clear to me how the headers connect it to a specific controller using media_type.
Right now I'm sending the headers: Accept: application/json;version=1.0 with Chrome extension Postman to /api/user/status
However I'm getting a No route found for "POST /api/user/status" error
Here's my configuration:
routing.yml:
type: rest
prefix: /api
resource: Acme\Bundle\SomeBundle\Controller\DefaultController
DefaultController.php:
use FOS\RestBundle\Controller\Annotations\Version;
/**
* #Version("1.0")
* #RouteResource("User", pluralize=false)
*/
class User
...
public function postStatusAction()
config.yml
fos_rest:
versioning:
enabled: true
resolvers:
query: false
custom_header: false
media_type:
enabled: true
regex: '/(v|version)=(?P<version>[0-9\.]+)/'
routing_loader:
default_format: json
view:
mime_types:
json: ['application/json;version=1.0']
format_listener:
enabled: true
console debug:router post_user_status
| Route Name | post_user_status |
| Path | /api/user/status.{_format} |
| Path Regex | #^/api/user/status(?:\.(?P<_format>json|xml|html))?$#s |
| Host | ANY |
| Host Regex | |
| Scheme | ANY |
| Method | POST |
| Requirements | _format: json|xml|html |
| Class | Symfony\Component\Routing\Route |
| Defaults | _controller: AcmeSomeBundle:Default:postStatus |
| | _format: json |
| Options | compiler_class: Symfony\Component\Routing\RouteCompiler |
+--------------+---------------------------------------------------------+
I've also tried to no avail in routing.yml condition: "request.attributes.get('version') == '1.0'"
What am I missing?
Thanks in part to #Mohammad in the comments for pointing me in the right direction I eventually found the answer.
While looking over the FOSRest versioning documentation again the instructions are to be taken quite literally.
One of the requirements states
You must configure the possible mime types for all supported versions:
Which means that since I only had:
view:
mime_types:
json: ['application/json;version=1.0']
Even if the in the header sent requested an API version that didn't exist it kept defaulting to this no matter what.
The correct config is
view:
mime_types:
json: ['application/json','application/json;version=1.0']
along with Mohhamad's mention that media_type headers require format_listener
format_listener:
enabled: true
rules:
- { path: '^/api', priorities: ['json'], fallback_format: json, prefer_extension: false }
With this it routes correctly to the right API version number.
It also finally routes to a 404 response if the version number is incorrect or if there is no API version header.
Related
i follow this instructions in order to get AKS audit logs.
https://learn.microsoft.com/en-us/azure/aks/view-master-logs
i cant find some basic fields such as stage,level,username..
how can i see the "k8s audit" with the full log?
Here is an example query to get started. It expands the log_s field and removes some of the noise to try and give just logs for when a user has modified a resource in Kubernetes. The requestURI and requestObject fields will give you the most info about what the user was doing.
AzureDiagnostics
| where Category == "kube-audit"
| extend log_j=parse_json(log_s)
| extend requestURI=log_j.requestURI
| extend verb=log_j.verb
| extend username=log_j.user.username
| extend requestObject = parse_json(log_j.requestObject)
| where verb !in ("get", "list", "watch", "")
| where username !in ("aksService", "masterclient", "nodeclient")
| where username !startswith "system:serviceaccount:kube-system"
| where requestURI startswith "/api/"
| where requestURI !startswith "/api/v1/nodes/"
| where requestURI !startswith "/api/v1/namespaces/kube-system/"
| where requestURI !startswith "/api/v1/namespaces/ingress-basic/"
I have feature file with a scenario that uses a variable eg: 1.
I am calling this scenario from another feature file but this time I want to pass another variable eg: 2
Feature file A: generateDocument.feature
#generatedoc
Scenario: Verify able to generate document for user
Given path somepath
And header Content-Type = 'application/json'
And request {"userId": "abc123"}
When method POST
Then status 200
* table documentId
| id | docTitle |
| '#notnull' | "ijk" |
| '#notnull' | "xyz" |
And match response[*].id == $documentId[*].id
And match response[*].title == $documentId[*].docTitle
Feature file B: useDocument.feature
call read('generateDocument.feature#generatedoc') { userId: 'abc456'}
So when I run feature file A, it should use the variable 'abc123', but when I run the feature file B, it should use the variable 'abc456'
But currently when I run feature file B, it still uses 'abc123'
Please do this in A - so it becomes a re-usable feature.
And request {"userId": "#(userId)"}
Now you need to call it 2 times (maybe in 2 different features and it will work):
Feature B:
call read('generateDocument.feature') { userId: 'abc456' }
Feature C:
call read('generateDocument.feature') { userId: 'abc123' }
I need to replace a value inside the URL
test/lambda-migration/v1/quote'
The v1 needs to be parameterized to take different value, and these values will come from another feature file. My code looks kike this:
Feature file -1
Scenario Outline: Lambda API registration
Given url ApiAdminURL
json myReq = read('swagger-lambda.json')
And request myReq
When method post
Then status
def responsefromsubscriber = call read('Subscriber.feature') { InvokeStatus: '#(InvokeStatus)', version: '<version>' }
match responsefromsubscriber.InvokeStatus == 200
Examples:
| responseCode | version |
| 200 | v1 |
Feature File - 2
Given url internalGateway
print 'Version: ' , version
def LocalVersion = version
print 'LocalVersion: ' , LocalVersion
And path 'test/lambda-migration/#(LocalVersion)/quote'
And header Authorization = accessTokenforInvokation
When method get
This is not replacing #(LocalVersion) to v1
And path 'test/lambda-migration/#(LocalVersion)/quote'
This is wrong. Please read this part of the docs: https://github.com/intuit/karate#rules-for-embedded-expressions
Also note that path supports a comma-delimited form:
Try:
And path 'test/lambda-migration', LocalVersion, 'quote'
I'm having some difficulty with sending a simple GET request via Postman (An application extension in google chrome) to my Laravel 5.2 server. Here are some details to what I'm doing:
Route here:
Next is the code containing the route
Code here (within the laravel routes.php file):
Finally the error that gets thrown
Error Here
I've gone through multiple tutorials (if resources are needed I will post them on request) and videos and yet I think I may have overlooked something. I've even dived into the source code of Laravel's Route handler but it doesn't even get to the method:
$request->send();
located within the public\index.php file on line 56.
When I perform the:
php artisan route:list
I get the following response:
+--------+----------+-----------------------+------+--------------------------------------------------------+-----------------------------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+-----------------------+------+------------------------------------------------------------------------------+-------------+
| | POST | here | | Closure | web |
| | GET|HEAD | user/:id/validate| | \Controllers\UserController#getOAuthValidation | web,api |
+--------+----------+-----------------------+------+--------------------------------------------------------+-----------------------------------+
If ANYONE can shed some light on this I would greatly appreciate it.
strange. Your routes file is /user/validate but your route is expecting an id.
I'm assuming that the validate method requires an id field in its signature?
Remove that, or change your postman get to /user/1/validate
I have an app that use google Auth to auth users, i'm trying to do some functional testing using codeception framework, but when i try to run the functional testing i got the following error
[InvalidArgumentException]
Driver [google] not supported.
Is there is any problem to define Google Auth in codeception or may be pass by it ? , it's working just fine with my application but it's not working in the testing
Here is my Auth config file
return array(
/*
|--------------------------------------------------------------------------
| Default Authentication Driver
|--------------------------------------------------------------------------
|
| This option controls the authentication driver that will be utilized.
| This driver manages the retrieval and authentication of the users
| attempting to get access to protected areas of your application.
|
| Supported: "database", "eloquent"
|
*/
'driver' => 'google',
/*
|--------------------------------------------------------------------------
| Authentication Model
|--------------------------------------------------------------------------
|
| When using the "Eloquent" authentication driver, we need to know which
| Eloquent model should be used to retrieve your users. Of course, it
| is often just the "User" model but you may use whatever you like.
|
*/
'model' => 'User',
/*
|--------------------------------------------------------------------------
| Authentication Table
|--------------------------------------------------------------------------
|
| When using the "Database" authentication driver, we need to know which
| table should be used to retrieve your users. We have chosen a basic
| default value but you may easily change it to any table you like.
|
*/
'table' => 'users',
/*
|--------------------------------------------------------------------------
| Password Reminder Settings
|--------------------------------------------------------------------------
|
| Here you may set the settings for password reminders, including a view
| that should be used as your password reminder e-mail. You will also
| be able to set the name of the table that holds the reset tokens.
|
| The "expire" time is the number of minutes that the reminder should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'reminder' => array(
'email' => 'emails.auth.reminder',
'table' => 'password_reminders',
'expire' => 60,
),
);
Also i tried to add the following in the _boostrap.php regarding the functional testing but still it can't pass the google driver, i think there is something wrong here .
Auth::LoginUsingId(1);