How to redirect using F5 iRules with a variable in the URL - redirect

Hi I'm new to F5 iRule.
I'm trying to redirect
https://website1.com/userid=1234
to
https://website2.com/userid=1234
such that whatever value the userid may have will be carried over after redirection.
I'm thinking userid value should be set to a variable.
Can someone share what code to use? Thanks!
So https://website1.com/userid=8888 should go to https://website2.com/userid=8888 and so on.

You shouldn't need a variable if that pattern is consistent. A simple rule would be:
when HTTP_REQUEST {
if { [HTTP::host] eq "website1.com" } {
HTTP::redirect https://websitesite2.com[HTTP::uri]
}
}
However, if you are on v11.4+, you really should use a local traffic policy for this as it is more performant as a built-in feature of TMOS.
ltm policy sample_site_redirect {
controls { forwarding }
last-modified 2018-12-20:09:33:02
requires { http }
rules {
full_uri_redirect {
actions {
0 {
http-reply
redirect
location tcl:https://website2.com[HTTP::uri]
}
}
conditions {
0 {
http-host
host
values { website1.com }
}
}
}
}
status published
strategy first-match
}
if all traffic to the virtual server this rule or policy is attached to is intended for website1 only, you can eliminate those conditions. I didn't want to assume. If it's only the URI starting with /user= that you want to match, and redirect on, you can do that this way:
when HTTP_REQUEST {
if { ([HTTP::host] eq "website1.com") && ([string tolower [HTTP::uri]] starts_with "/user=") } {
HTTP::redirect https://website2.com[HTTP::uri]
}
}

Related

GitHub Projects Beta - How to get the data from a view in the API

My company is using the new GitHub projects beta and we're really enjoying the experience, but we're facing a problem and it is how to export the data from a specific view (or even all the data) with all the custom columns that we have.
The ideal solution for us is to get this same data as JSON using the API.
Using https://api.github.com/orgs/.../issues does not work because the issues does not have the custom columns that we create inside the project, and https://api.github.com/orgs/.../projects does not have the data of the issues.
Any idea or work-around to get this data easily using APIs?
After reading the feedback post on GitHub, it's not possible to do it with API, just GraphQL, at least for now.
So my problem was solved with this useful code.
To get the first 100 project from your organization and their ID:
query{
organization(login: "MY_ORG") {
projectsNext(first: 20) {
nodes {
id
title
}
}
}
}
To get the first 100 issues and drafts from a specific project:
{
node(id: "My_Project_ID") {
... on ProjectNext {
items(first: 100, after: null) {
edges {
cursor
}
nodes {
content {
... on Issue {
title
assignees(first: 1) {
nodes {
login
}
}
milestone {
title
}
labels(first: 5) {
nodes {
name
}
}
repository{
name
}
}
}
fieldValues(first: 15) {
nodes {
value
projectField {
name
settings
}
}
}
}
}
}
}
}
Those codes can be easily tested in THIS LINK

Jenkins Multibranch-Pipeline JobDSL can't specify github url

I'm creating a Multibranch Pipeline job with JobDSL , and I want to specify my github url , but it's not working.
The job which I created it display "https://github.com/jackson/multibranch-Pipeline.git" ,
not https://mycompanygithub.com/jackson/multibranch-Pipeline.git
Any idea how theses other parameters can be added in ?
or other solution
multibranchPipelineJob('Jenkins/Multibranch-Pipeline/GitHub_Basic') {
branchSources {
branchSource {
source {
github {
repositoryUrl('https://mycompanygithub.com')
credentialsId('mycredentialsid')
repoOwner('jackson')
repository('multibranch-Pipeline.git')
configuredByUrl(true)
}
}
}
}
}
Actually your configuration is correct, your are just missing one parameter: apiUri
// The server to connect to.
apiUri(String value)
Without it, it takes the default github.com as the base domain for the repository regardless of what is configured in the repositoryUrl parameter.
Try the following:
multibranchPipelineJob('Jenkins/Multibranch-Pipeline/GitHub_Basic') {
branchSources {
branchSource {
source {
github {
apiUri('https://mycompanygithub.com/api/v3')
repositoryUrl('https://mycompanygithub.com')
credentialsId('mycredentialsid')
repoOwner('jackson')
repository('multibranch-Pipeline.git')
configuredByUrl(true)
}
}
}
}
}
By the way you can see the full documentation of the Job DSL of this plugin at the following URL on your own Jenkins server:
YOUR_JENKINS_URL/plugin/job-dsl/api-viewer/index.html#method/javaposse.jobdsl.dsl.DslFactory.multibranchPipelineJob

Nesting authorize directives in spray

It seems it is impossible to nest authorized directives in spray due to this line: https://github.com/spray/spray/blob/76ab89c25ce6d4ff2c4b286efcc92ee02ced6eff/spray-routing/src/main/scala/spray/routing/directives/SecurityDirectives.scala#L55
I'm referring to doing things like this:
val route = {
...
authorize(userIsAdmin) {
path("generic" / "admin" / "stuff") { ... } ~
path("users" / Segment) { u =>
authorize(canModifyUser) {
...
}
} ~
path("quotas") {
authorize(canModifyQuotas) {
...
}
}
}
}
One could of course refactor this to include userIsAdmin into the canModifyUser and canModifyQuota checks, but with orthogonal access rights, that could get out of hand fast.
What is the reason for that line? It doesn't seem logical to me why we are cancelling any further authorization failures.
Full disclosure: The route will actually get rejected if one of the nested checks fail, but it will give a 404 error (EmptyRejection) instead of the expected AuthorizationFailedRejection.

KRL: Pragmatically access current ruleset id

How do I get the name of the current ruleset in a KRL rule? I find that I often write
notify("a421x70","Your Message Here") with sticky = true;
but when I copy the ruleset I have to go through and change the "a421x70" part. It would be so much better to have the current ruleset in a variable and use that in my notify() action.
In the pre block of a rule you can
rid = meta:rid();
http://docs.kynetx.com/docs/Meta_Info
Example:
ruleset a60x598 {
meta {
name "appid tester"
description <<
getting app rid pragmatically
>>
author "Michael Grace"
logging off
}
rule get_rid_rule {
select when web pageview ".*"
pre {
rid = meta:rid();
}
{
notify("Current App rid is", "#{rid}") with sticky = true;
}
}
}

raise_event from client not working in dev

I have the following code, and raising the web event doesn't do what it should do. I have disabled all of my extensions to ensure that it isn't something there. Please help. I find it hard to build an app if I can't debug my junk. HELP ME!!!
dispatch {
// Some example dispatch domains
// domain "example.com"
domain "google.com"
}
global {
}
rule temp_rule is active{
select when pageview ".*"
pre{
}
{
notify("111",'123');
emit<<
var tempapp = KOBJ.get_application("a710x19");
tempapp.raise_event("temp2");
>>;
}
}
rule temp2 is active{
select when web temp2
pre{
}
{
notify("222",'<div id="fbp_fblogo">123</div>');
emit<<
try{
console.log("TEMP2'd");
}catch(e){}
>>;
}
}
The problem is that your event name contains a numeral. Event names are only to contain letters.
Remove the 2 from your raise_event call in your emit and from your select statement and it will work.