OPA policy where if kustomize.toolkit.fluxcd.io/reconcile: disabled label is present in helm release yaml it should display a message - open-policy-agent

is their any OPA policy example where i can design a OPA policy like if specific label is present than it should display the message or warning
i mean i want to design an OPA policy where if kustomize.toolkit.fluxcd.io/reconcile: disabled label is present in helm release yaml it should display a message/warning that kustomize disabled label is there in helm release
can anyone please help me

It’s possible to return warning messages to clients from an admission webhook. The format is documented here.
{
"apiVersion": "admission.k8s.io/v1",
"kind": "AdmissionReview",
"response": {
"uid": "<value from request.uid>",
"allowed": true,
"warnings": [
"duplicate envvar entries specified with name MY_ENV",
"memory request less than 4MB specified for container mycontainer, which will not start successfully"
]
}
}
Let's imagine you have an input object like this:
{
"kind": "AdmissionReview",
"request": {
"kind": {
"kind": "HelmRelease",
"version": "v1"
},
"object": {
"metadata": {
"annotations": {
"kustomize.toolkit.fluxcd.io/reconcile": "disabled"
},
"name": "myapp"
}
}
}
}
Using a policy like this would return warnings to your client when called on the /v0/data API
package play
import future.keywords.contains
import future.keywords.if
warn contains msg if {
input.request.kind == "HelmRelease"
input.request.object.metadata.annotations["kustomize.toolkit.fluxcd.io/reconcile"] == "disabled"
msg := "kustomize disabled"
}
response = {
"apiVersion": "admission.k8s.io/v1",
"kind": "AdmissionReview",
"response": {
"uid": "1234",
"allowed": true,
"warnings": warn,
},
}

Related

Strapi. Method Not Allowed custom question

Through postman, I'm trying to send a post request to create a post, but I get an error that is described in the question itself (error code - 405).
On top of all that, I've issued ALL permissions. What is the problem?
grade collection -
and schema.json from grade -
{
"kind": "collectionType",
"collectionName": "grades",
"info": {
"singularName": "grade",
"pluralName": "grades",
"displayName": "grade"
},
"options": {
"draftAndPublish": true
},
"pluginOptions": {},
"attributes": {
"id_post": {
"type": "biginteger"
},
"grade": {
"type": "integer"
}
}
}
from comments, it seems the problem is two extra invisible characters after the url:
this line makes them visible:
[2022-12-21 14:38:39.382] http: POST /api/grades/%0A%0A (4 ms) 40
notice the %0A%0A
remove them or copy paste clean url:
http://localhost:1337/api/grades

Request sent from Swagger UI not resulting in Postman x-www-form-urlencoded response

I'm currently configuring a Swagger file to utilize OAuth to retrieve tokens from a site. For brevity, I have removed my schemes and most of my paths as those are fine.
{
"openapi": "3.0.2",
"info": {
"title": "swagger",
"version": "1.0.0",
"description": ""
},
"servers": [
{
"url": "url"
}
],
"paths": {
"/oauth_token.do": {
"post": {
"requestBody": {
"required": true,
"content": {
"application/x-www-form-urlencoded": {
"schema": {
"type": "object"
}
}
}
}
}
}
},
"components": {
"securitySchemes": {
"OAuth": {
"type": "oauth2",
"flows": {
"password": {
"tokenUrl": "/oauth_token.do",
"refreshUrl": "/oauth_token.do",
"scopes": {
"useraccount": "utilize user account"
}
}
}
}
}
}
"security": [
{
"OAuth": ["useraccount"]
}
]
}
The endpoint for this API specifies that I should use x-www-form-urlencoded in the header as the Content-Type. When executing this request in Postman, it returns 200 with the desired response.
However, with https://editor.swagger.io I input the same postman request to get the fetch failed error with my Authorize button. To test for this, I created a custom path that specifies that the content should be x-www-form-urlencoded and this also fails.
So, what am I missing in this case? Any help would be appreciated.
I believe the issue was I did not fill out some portions I added on the response for path. Instead I opted to only leave description for the 200 response.
The main error I'm getting now is CORS related which is unrelated to the original question. I'll mark this answered for now.

Hasura query action exception

Got a small problem (I guess). I created c# rest web API on docker swarm environment. Rest API is working properly - tested via the postman. Then I tried to compose Hasura service on the same docker swarm environment. The console is working properly also. The problem is with query action.
Code:
Action definition:
type Query {
getWeatherForecast : [WeatherForecastResonse]
}
New types definition:
type WeatherForecastResonse {
date : String
temperatureC : Int
temperature : Int
summary : String
}
Handler:
http://{api ip}:{api port}/WeatherForecast
While trying to execute query:
query MyQuery {
getWeatherForecast {
temperature
summary
date
temperatureC
}
}
All I got from response is error with json:
{
"errors": [
{
"extensions": {
"internal": {
"error": "invalid json: Error in $: not enough input",
"response": {
"status": 405,
"body": "",
"headers": [
{
"value": "Mon, 14 Jun 2021 13:54:00 GMT",
"name": "Date"
},
{
"value": "Kestrel",
"name": "Server"
},
{
"value": "0",
"name": "Content-Length"
},
{
"value": "GET",
"name": "Allow"
}
]
},
"request": {
"body": {
"session_variables": {
"x-hasura-role": "admin"
},
"input": {},
"action": {
"name": "getWeatherForecast"
}
},
"url": "http://{api ip}:{api port}/WeatherForecast",
"headers": []
}
},
"path": "$",
"code": "unexpected"
},
"message": "not a valid json response from webhook"
}
]
}
I got desired response by using postman white calling: http://{api ip}:{api port}/WeatherForecast (GET method)
Where should I improve, to finally get desired result from rest api?
P.S. hasura version: v2.0.0-alpha.4 (tried also with v1.3.3)
UPDATE:
Released a new version of web API. Inside WeatherForecastController included a new method with POST attribute. Query remained the same, but now graphql query returns what I want.
So the question is: Is it possible to call/access web api methods with GET attribute with Hasura action query?
From the version v2.1.0 and above we can do this using the REST Connectors.Hasura Actions RESTConnectors Methods
Go to the Actions tab on the console and create or modify an action. Scroll down to Configure REST Connectors.
In the Configure REST Connectors section, click on Add Request Options Transform
Along with this you can do a lot of other configurations.
No, currently it's not possible, Hasura always makes POST requests to the action handler:
When the action is executed i.e. when the query or the mutation is called, Hasura makes a POST request to the handler with the action arguments and the session variables.
Source: https://hasura.io/docs/latest/graphql/core/actions/action-handlers.html#http-handler

Jira API: Add Comment Using Edit Endpoint

Jira has a an /edit endpoint which can be used to add a comment. There is an example in their documentation that suggests this input body to accomplish this:
{
"update": {
"comment": [
{
"add": {
"body": "It is time to finish this task"
}
}
]
}
}
I create the exact same input in my Java code:
private String createEditBody() {
JsonNodeFactory jsonNodeFactory = JsonNodeFactory.instance;
ObjectNode payload = jsonNodeFactory.objectNode();
ObjectNode update = payload.putObject("update");
ArrayNode comments = update.putArray("comment");
ObjectNode add = comments.addObject();
ObjectNode commentBody = add.putObject("add");
commentBody.put("body", "this is a test");
return payload.toString();
}
but when I send this PUT request I get an error saying that the "Operation value must be of type Atlassian Document Format"!
Checking the ADF format it says that "version", "type" and "content" are required for this format. So although their documentation example doesn't seem to be ADF format, I'm trying to guess the format and change it. Here's what I accomplished after modifying my code:
{
"update": {
"comment": [
{
"add": {
"version": 1,
"type": "paragraph",
"content": [
{
"body": "this is a test"
}
]
}
}
]
}
}
the add operation seems to be an ADF but now I get 500 (internal server error). Can you help me find the issue?
Note that the above example from Atlassian documentation is for "Jira Server Platform" but the instance I'm working with is "Jira Cloud Platform" although I think the behaviour should be the same for this endpoint.
after tinkering with the input body, I was able to form the right request body! This will work:
{
"update": {
"comment": [
{
"add": {
"body": {
"version": 1,
"type": "doc",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "this is a test"
}
]
}
]
}
}
}
]
}
}
The annoying things that I learned along the way:
Jira's documentation is WRONG!! Sending the request in their example will fail!!
after making a few changes, I was able to get 204 from the endpoint while still comment was not being posted! And I guessed that the format is not correct and kept digging! But don't know why Jira returns 204 when it fails!!!

Getting the IoT Edge Module Settings

In the Azure portal, you can see the "IoT Edge Module Settings" :
How do I access this programatically from C#?
When I get the list of modules on the edge device, there doesn't appear to be an option to get the settings?
You use the Microsoft Azure Devices Client SDK/package and attack it this way:
var registryManager = RegistryManager.CreateFromConnectionString(connString); //the connection string for your IOT Hub
var moduleTwins= new List<Twin>();
//var query = registryManager.CreateQuery($"SELECT * FROM devices", 100);
var query = registryManager.CreateQuery("SELECT * FROM devices.modules WHERE deviceId='MyEdgeDevice'",100);
while (query.HasMoreResults) {
var page = await query.GetNextAsTwinAsync();
moduleTwins.AddRange(page);
}
// this gets rid of all that version/metadata noise in a module/device twin
foreach (var module in moduleTwins) {
module.Properties.Reported.ClearMetadata();
module.Properties.Desired.ClearMetadata();
}
Now moduleTwins is now an enumerable list of the Twin object (which is a direct representation of module/device twins). As a fun aside, in there will also be $edgeAgent and $edgeHub twins -- which contain everything - and in the list of modules for edgeAgent, you'll see more of that information for each module (the image, create options, restart policy, etc), which is found in $edgeAgent's properties.desired.modules area
"modules": {
"MyNeatModule": {
"type": "docker",
"settings": {
"image": "myAzureContainerRegistry.io/myneatmodule:amd64.debug",
"createOptions": "{}"
},
"status": "running",
"restartPolicy": "always",
"version": "1.0"
},
and everything you're looking for is in $edgeAgent's properties.reported area:
"modules": {
"SuperNeatAwesomeModule": {
"exitCode": 0,
"statusDescription": "running",
"lastStartTimeUtc": "2018-11-01T18:39:09.8814806Z",
"lastExitTimeUtc": "2018-11-01T18:05:40.8350456Z",
"restartCount": 0,
"lastRestartTimeUtc": "2018-11-01T18:05:40.8350456Z",
"runtimeStatus": "running",
"version": "1.0",
"status": "running",
"restartPolicy": "always",
"type": "docker",
"settings": {
"image": "blahblahblah.azurecr.io/superneatmodule:0.0.2-amd64.debug",
"imageHash": "sha256:ladkjsfaldkjfasdflkjasdfljasfljkasflja4",
"createOptions": "{}",
"env":{}

Resources