Yii2 routing problems,don't recognise parameters - web

Every time a make request to http://localhost/users?username="john.doe", I get 404 error.
The following code is Controller code to control routes.
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'only' => [ 'users'],
'rules' => [
[
'actions' => ['users'],
'allow' => true,
'roles' => ['#'],
]
]
],
];
}
Controller action code.
public function actionUsers($username)
{
if (Yii::$app->request->isAjax) {
return Users::find()->where('username', $username)->one();
}
}
PS: I'm make ajax request.

Assuming you action actionUsers is inside a controller name MyuserController then your link should be
http://localhost/myuser/users?username="john.doe"
Your link must contain also the name of the controller (not only the name of the action)

Related

DocuSign Api creating envelope in Production

I have a problem with creating Envelope through the Api.
The authorization is performed without errors.
$options = new \DocuSign\eSign\Api\AuthenticationApi\LoginOptions();
$loginInformation = $authenticationApi->login($options);
I get this in response:
LoginInformation {
#container: array:2 [
"api_password" => null
"login_accounts" => array:1 [
0 => LoginAccount {
#container: array:11 [
"account_id" => "xxxxx"
"account_id_guid" => null
"base_url" => "https://na2.docusign.net/restapi/v2/accounts/xxxxx"
"email" => "xxxxx#xxxxxx.com"
"is_default" => "true"
"login_account_settings" => null
"login_user_settings" => null
"name" => "xxxxxxx, LLC"
"site_description" => ""
"user_id" => "xxxxxxxxxxxxxxxxxxx"
"user_name" => "xxxxxx Contracts Team"
]
}
]
]
}
But when I’m trying to create the Envelope this way:
$envelopeApi->createEnvelope($this->config->getAccountId(), $envelop_definition, $options);
I get this error: «[401] Error connecting to the API (https://www.docusign.net/restapi/v2/accounts/xxxxx/envelopes)”
This error notifies me that I’m not authorized. This code works properly in Sandbox.
I think that the problem is in settings of account - maybe there is a lack of special rights...
You need to use the right production platform. The right production platform is determined by the DocuSign Account ID.
See step 1 in the Post Go Live document.

Logstash fingerprint filter not working

I have a logstash filter that extracts an api token string from an XML payload. I don't want to store the actual API token in elasticsearch, I want to store a hashed version. My filter file is as follows:
filter {
xml {
source => "xml_request"
store_xml => "false"
force_array => "false"
xpath => [ "//authentication/apiKey/text()", "api_key" ]
}
if [api_key] =~ /.+/ {
fingerprint {
method => "SHA256"
key => "some_random_string"
source => "api_key"
target => "api_key"
}
}
}
Unfortunately the fingerprint filter does not seem to be working because the api_key value is always the value from the XML input and not SHA256 hashed. I have tried setting the target field to a new field (e.g. api_key_hashed) to test, but the new field does not show up. Can anyone shed some light please?
I do not know if this helps, but you can try:
fingerprint {
add_field => {
"apikey" => "%{api_key}"
remove_field => [ "%{api_key}" ]
}
add_field => {
"api_key" => "%{apikey}"
remove_field => [ "%{apikey}" ]
}
}
Otherwise, you can try:
GROK_OVERRIDE or GROK ADD FIELD or DROP ADD FIELD

Merging another web.php file in config/web.php of yii2

We are two groups developing a project made in Yii2 basic. The problem we are facing right now is we have different web.php under config. Our group would like to include our web.php (which was renamed to extras.php) inside the web.php of another group. The difference is we added variables under components of $config of web.php. Yes, we can manually add our new variables under components of $config from the other team but we prefer to use separate files that is why we renamed the other web.php to extras.php.
A small preview of web.php looks like this
$params = require(__DIR__ . '/params.php');
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'language'=> isset($_SESSION['language_local']) ? $_SESSION['language_local']:'en',
'components' => [
'nagios' => [
'class' => 'app\components\nagios',
],
'hostlistsql' => [
'class' => 'app\components\hostlistsql',
],
'request' => [empty) - this is required by cookie validation
'cookieValidationKey' => 'nYwdMpu-dw004qwFRZmqZOzzC3xdnL8b',
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
],
'params' => $params,
];
extras.php looks like this
$params = require(__DIR__ . '/params.php');
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'language'=> isset($_SESSION['language_local']) ? $_SESSION['language_local']:'en',
'components' => [
'user_functions' => [
'class' => 'app\components\UserFunctions',
],
'user_extras' => [
'class' => 'app\components\UserExtras',
],
'request' => [empty) - this is required by cookie validation
'cookieValidationKey' => 'nYwdMpu-dw004qwFRZmqZOzzC3xdnL8b',
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
],
'params' => $params,
];
What approach should we take to include extras.php inside web.php?
EDIT:
SOLUTION:
Inside web/index.php has
$config = require(__DIR__ . '/../config/web.php');
I changed it instead to
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../config/web.php'),
require(__DIR__ . '/../config/extras.php')
);
Why would you want to include extras.php inside web.php instead of just merging them?
Here is how the same thing is handled in yii2 advanced https://github.com/yiisoft/yii2-app-advanced/blob/master/environments/dev/frontend/web/index.php
As you can see common..main.php is merged with common..main-local.php is merged with frontend..main.php is merged with frontend..main-local.php
There are 4 files that are merged to get to the end 1 single config file. Eazy as pie.
If you really want to merge things inside web.php do a
$config = [....];
return yii\helpers\ArrayHelper::merge(
$config,
require(__DIR__ . 'extras.php'),
);
Do you guys have any version control system (like git, Bitbucket, etc...) ?
You could let only the things you have in common in the web.php file and the rest coming from a external file.
Since each group will have a different file, i would recommend create a constant that decides which file is being used. Following your example:
web.php:
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'language'=> isset($_SESSION['language_local']) ? $_SESSION['language_local']:'en',
'components' => EXTRAS ? require(__DIR__ . '/components2.php') : require(__DIR__ . '/components1.php'),
'params' => require(__DIR__ . '/params.php')
];
Example of components2.php:
return [
'user_functions' => [
'class' => 'app\components\UserFunctions',
],
'user_extras' => [
'class' => 'app\components\UserExtras',
],
'request' => [empty) - this is required by cookie validation
'cookieValidationKey' => 'nYwdMpu-dw004qwFRZmqZOzzC3xdnL8b',
],
'cache' => [
'class' => 'yii\caching\FileCache',
]
]
And EXTRAS is a constant defined elsewhere. You could do that in web/index.php (follow the YII_DEBUG and YII_ENV samples) and add it in your ignored files, if you didn't already.

Sync'ing ACL permissions in a NodeJS application using MongoDB

Currently using the Node ACL module from:
https://github.com/OptimalBits/node_acl
This is working a treat but now the requirement is have to reflect any changes to our security config in our ACL layer.
What Im looking for is a clean way to iterate over the roles defined in our security config, decide whether the permissions/resources have changed and if they have update or remove them.
Here is a sample security config file, take the scenario where 'put' is removed from the resource /projectId.
"roles":{
"itemRole":[
{
"roles":"owner-projectId",
"allows":[
{
"resources":"/projectId",
"permissions": ["put", "post", "patch","get","delete"]
},
{
"resources":"/projectId/settings",
"permissions": ["put"]
}
]
},
{
"roles":"collaborator-projectId",
"allows":[
{
"resources":"/itemId",
"permissions":["put","post", "patch","get"]
},
{
"resources":"/api/resource/itemId",
"permissions":["put", "post", "patch","get"]
}
]
},
{
"roles":"spectator-newId",
"allows":[ ]
},
{
"roles":"admin-newId",
"allows":[
{
"resources":"/api/resource/itemId/update",
"permissions":[ "put"]
}
]
}
]
}
The following query will allow me iterate over the different roles and return all the allows for that resources, these allow_* should match what is currently in the security.config:
db.getCollection('authACLresources').find( { _bucketname: {"$regex":"allows_*"}, key: { '$in': [ 'spectator-2bc240c6ffa988260b501922' ] }})
I can then look at the different permissions and compare - just wondering if there is a better way to do this? I know the node ACL module has a method called whatResources but doesn't give you the permissions just the resources.

Cannot parse array into defined type

I am using following puppet class
class myclass{
$foo = [{"id" => "bar", "ip" => "1.1.1.1"}, {"id" => "baz", "ip" => "2.2.2.2"}]
map {$foo:}
define map () { notify {$name['id']: } }
}
But this gives me
err: Could not retrieve catalog from remote server: Could not intern from pson: Could not convert from pson: Could not find relationship target "Change_config::Map[ip1.1.1.1idbar]"
warning: Not using cache on failed catalog
err: Could not retrieve catalog; skipping run
What is the reason for this ?
Regards,
Malintha Adikari
Your array contains hashes. The resource declaration syntax works only for arrays of strings.
$foo = ["bar", "baz"]
map {$foo:}
define map () { notify {$name: } }
If you want to pass data with each resource title, you need to
build a hash of your data, not an array of hashes
use the create_resources function
Untested example code:
$foo = {
"bar" => { "ip" => "1.1.1.1" },
"baz" => { "ip" => "2.2.2.2" },
}
create_resources('map', $foo)
define map ($ip="") { notify { "$name has ip $ip": } }

Resources