Jenkinsfile split array - jenkins

Given the following example:
def servers = "sftp.host.com:32025|GB,sftp.host.com:32029|ES,sftp.host.com:32030|PT,sftp.host.com:32027|FI,"
servers.split(',').each {
it.split("\\|").each {
println("sftp address: ${it[0]} countrycode: ${it[1]}\n")
}
}
The idea was to extract some fields from a delimited list of , then get address|countryCode out from that field to process further, but the only thing i am getting out is the first letter of each field.
sftp address: s countrycode: f
sftp address: G countrycode: B
...
Not sure whats going on here?

Working Code
def servers = "sftp.host.com:32025|GB,sftp.host.com:32029|ES,sftp.host.com:32030|PT,sftp.host.com:32027|FI,"
servers.split(',').each {
def itParts = it.split(/\|/)
println "sftp address: ${itParts[0]} countrycode: ${itParts[1]}"
}
Code Output
sftp address: sftp.host.com:32025 countrycode: GB
sftp address: sftp.host.com:32029 countrycode: ES
sftp address: sftp.host.com:32030 countrycode: PT
sftp address: sftp.host.com:32027 countrycode: FI

Related

Neo4j GraphQL how to check if node exists before connecting to it

B"H
I've seen this question and I want to do the same thing with the GraphQL driver for Neo4j. I think the answer lies somewhere in combining AND and OR operators found here, of some sort, but not sure how.
To illustrate the question, say I have this type:
type Comment {
id: ID #id
timeAdded: DateTime! #timestamp(
operations: [CREATE]
)
writer: User! #relationship(
type: "WRITTEN_BY",
direction: IN
)
content: String
}
type User {
id: ID #id
name: String
commentsWritten: [Comment!]! #relationship(
type: "WRITTEN_BY",
direction: OUT
)
}
type Mutation {
addComment(authorID: String)
}
and this resolver to add a new comment (where "Comment" is a reference to the OGM model of the Comment type):
addComment: async (
src,
args,
ctx
) => {
var authorID = args/*edit*/.authorID //let's say this is passed
//from request headers / JWT token or something
var adCom = await Comment.create({
input: [
{
content: args.content,
writer: {
connect: {
where: {
node: {
users: {
id: authorID
}
}
}
}
}
}
]
})
return adCom;
}
So it attempts to connect to that user with that ID. but if there is no user with that ID, I don't want to create anything [not only do I not want to connect it].
I could run another query to find a User with that ID, and test if it went through, but was wondering if it's possible to do everything in one call

Hashing password with nestjs and mongoose crashes on production

In my nestjs app i'm using mongoose's pre-save method to hash the password.
Locally it works fine. but on production/docker, it causes the whole nest app to crash. Here is the code:
export const UserSchema = new mongoose.Schema({
email: { type: String, unique: true, lowercase: true, trim: true },
password: {
type: String,
minlength: [8, 'Password must be 8 characters or more.'],
maxlength: 100,
},
username: String,
...
phone: { type: String, default: '' },
});
UserSchema.pre('save', async function (next: mongoose.HookNextFunction) {
try {
if (!this.isModified('password')) {
return next();
}
const saltRounds = 14;
const hashed = await bcrypt.hash(this['password'], saltRounds);
this['password'] = hashed;
return next();
} catch (err) {
return next(err);
}
});
Again, locally it works, but in docker any user saving is causing a crash ('exited with code 0').
Do you see anything wrong in this code, or do you have a better way of doing this?
Gosh! I've been wasting days on this. Here is the solution. bcrypt tends to fail on nodejs apps (wait, what? bcrypt? the npm package with 487K weekly downloads? yes.)
An alternative is bcryptjs, a javascript version that is a bit slower, but hey, it works!
Get it at your nearest npm store: https://www.npmjs.com/package/bcryptjs.
Here is where i found it: https://github.com/kelektiv/node.bcrypt.js/issues/432

Why does "run seedDb" fail when I add in relations between nodes moving from graphql to neo4j

I got the demo example from grand-stack and was able to start up graphql, start up the Neo4J sandbox and populate the test database using
npm run seedDb
However, when I try to write my own data entries to populate into a neo4j database, I cannot get the relation between nodes to work at all. The error message is the most non-useful message (and I believe it is from the apollo client, and is a status code 400 error). I simplified the code to the most simplest case to make it work, and it still does not. Here is the schema.graphql file:
type Patient {
id: ID!
name: String
reviews: [Review] #relation(name:"WROTE", direction:"OUT")
}
type Review {
id: ID!
stars: Int
text: String
date: Date
user: Patient #relation(name: "WROTE", direction: "IN")
}
and here is the seed-mutation.js file:
export default /* GraphQL */ `
mutation {
p1: CreatePatient(
id: "p1",
name: "John Doe 1"
) {
id
name
}
r1: CreateReview(id: "r1", stars: 4, text: "Great IPA selection!", date: { formatted: "2016-01-03"}) {
id
}
ar1: AddUserReviews(from: { id: "p1"}, to: { id: "r1" }) { from {id}}
}
`;
When I do "npm run seedDb", this yields the error message:
{ Error: Network error: Response not successful: Received status code 400
at new ApolloError (/Users/xxxx/Downloads/grand-stack-starter-master/api/node_modules/apollo-client/bundle.esm.js:60:28)
at Object.error (/Users/xxxx/Downloads/grand-stack-starter-master/api/node_modules/apollo-client/bundle.esm.js:1032:48)
at notifySubscription (/Users/xxxx/Downloads/grand-stack-starter-master/api/node_modules/zen-observable/lib/Observable.js:134:18)
at onNotify (/Users/xxxx/Downloads/grand-stack-starter-master/api/node_modules/zen-observable/lib/Observable.js:165:3)
at SubscriptionObserver.error (/Users/xxxx/Downloads/grand-stack-starter-master/api/node_modules/zen-observable/lib/Observable.js:224:7)
at /Users/xxxx/Downloads/grand-stack-starter-master/api/node_modules/apollo-link-http/src/httpLink.ts:184:20
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7)
graphQLErrors: [],
networkError:
{ ServerError: Response not successful: Received status code 400
at Object.exports.throwServerError (/Users/xxxx/Downloads/grand-stack-starter-master/api/node_modules/apollo-link-http-common/src/index.ts:114:17)
at /Users/xxxx/Downloads/grand-stack-starter-master/api/node_modules/apollo-link-http-common/src/index.ts:145:11
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7)
name: 'ServerError',
response:
Response {
size: 0,
timeout: 0,
[Symbol(Body internals)]: [Object],
[Symbol(Response internals)]: [Object] },
statusCode: 400,
result: { errors: [Array] } },
message: 'Network error: Response not successful: Received status code 400',
extraInfo: undefined }
I started with multiple complex codes and this is pretty much the most stripped down version. When I run the seedDB command after the seed-mutation.js file was modified to:
export default /* GraphQL */ `
mutation {
p1: CreatePatient(
id: "p1",
name: "John Doe 1"
) {
id
name
}
r1: CreateReview(id: "r1", stars: 4, text: "Great IPA selection!", date: { formatted: "2016-01-03"}) {
id
}
}
`;
the database gets populated, however the two nodes are not connected to each other, as expected (basically, this is the code with the AddUserReviews removed). How do I build the relation between the nodes through using graphql and seedDb? What am I missing?
You can use GraphQL Playground to inspect the GraphQL API (in the "Docs" tab):
to ensure the mutations you are calling have the correct name and arguments. From inspecting the schema, it looks like instead of AddUserReviews, you want AddPatientReviews?

Cannot invoke function with an argument list of type in Swift Test class

I am attempting to write a test as shown below, but I receive the following compiler error => Cannot invoke 'include' with an argument list of type '([User], userId: String)'.
func testInclude() {
var users = mockUsers()
XCTAssert(self.viewController.include(users, userId: "2"), "Pass")
}
The mockUsers function is as shown below.
func mockUsers() -> [User]{
var users = [User(userId: "1", username: "soupguy", gender: 0, name: "Bob"),
User(userId: "2", username: "breadeater", gender: 1, name: "Alice"),
User(userId: "3", username: "lawnmowersrule", gender: 0, name: "Alex")]
return users
}
The include function that is being tested is shown below.
public func include(array: [User], userId: String) -> Bool {
for item in array {
if item.userId == userId {
return true
}
}
return false
}
I have tried changing types and storing the results in temporary variables, but have had no success in getting the test to compile.
My best guess is that one of your 'func' are wrong, go back and check all of you functions and cleaning your project form product tab on the Xcode menu bar might help as well.

Using Ruby on Rails and Savon gem to send a shipment request, very specific issue

after reading documentation several times and browsing the internet, I decided to ask for help. I have to make a SOAP request, sending a complicated object that looks like this :
http://mountainstream.ms/so1.png
http://mountainstream.ms/so2.png
http://mountainstream.ms/so3.png
I try to use a Ruby instance variable to hold the data in a hash. It looks like this:
##order[:pickupDate] = { pickupDate: '', readyTime: '08:00', closeTime: '20:00'}
##order[:service] = { shipper: shipper, packaging: packaging }
package = [weight, length, height, width, shape, packaging, packageValue]
##order[:packages] = package
##order[:packageServiceOptions] = { insurance: insurance, cod: cod, description: description, remarks: remarks }
##order[:inpostMachines] = { senderMachine: '', recipientMachine: '', alternativeRecipientMachine: '' }
##order[:sender] = { contact: { companyName: sender_company_name,
personName: sender_name,
phoneNumber: sender_phone,
emailAddress: sender_email
},
address: { street: sender_street,
postalCode: sender_po,
city: sender_city,
stateOrProvinceCode: sender_state,
country: sender_country
}}
##order[:recipient] = { contact: { companyName: rec_company_name,
personName: rec_name,
phoneNumber: rec_phone,
emailAddress: rec_email
},
address: { street: rec_street,
postalCode: rec_po,
city: rec_city,
stateOrProvinceCode: rec_state,
country: rec_country
}}
response = ##client.call(:rate_shipment, message: { shipementToEvaluate: ##order,
apiKey: apiKey, sessionId: ##sessionId})
When I send this, the response includes errors:
`<h1>CException</h1> <p>Argument 1 passed to ShipmentValidator::__construct() must be an instance of Shipment, null given, called in /api/protected/controllers/ShipServiceController.php on line 252 and defined</p>`
I tried to rearrange the hash to no avail, what am I doing wrong here?

Resources