Skip to content

Commit 4c29319

Browse files
author
Skr00b@!!
authored
Dev/actiion lib bugfix (#7)
* issue 6 fix. * added edits to README.md
1 parent dbeac94 commit 4c29319

File tree

5 files changed

+37
-138
lines changed

5 files changed

+37
-138
lines changed

README.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,35 @@ This has not been published to npm yet (may not be...)
88

99
So clone or download, run `npm install` in the `fintojs/` directory, and then just set up the network alias as described in the docs linked above (I have only tested with `ifconfig lo0 alias..` not sure about the other stuff). After that, simply follow the directions in the `SYNOPSIS` section below to start her up.
1010

11-
We have some support for the command line options. `-a --addr`, `-p --port`, and `-c --config` are implemented. `-l --log` is not see the synopsis if you need to write to a file (unix only).
11+
We have some support for the command line options. `-a --addr`, `-p --port`, and `-c --config` are implemented. `-l --log` is not; see the synopsis if you need to write to a file (unix only). **You MUST add a ` -- ` at the beginning of cli options or npm will not pass the arguments to the node process (unix only). See SYNOPSIS section for an example.**
1212

13-
We have not tested this on Windows or Cygwin.
13+
We have not tested this on Windows or Cygwin. I'm not sure how npm behaves there. YMMV.
1414

1515
This is currently BETA. Please report any issues.
1616

1717
### SYNOPSIS
1818
```bash
19+
## first cd into the fintojs directory you cloned..
20+
$ cd /path/to/clone/of/fintojs
1921
## with a log
20-
$ sudo node fintojs.js > /path/to/log/file 2>&1
22+
$ sudo npm start > /path/to/log/file 2>&1 &
2123
## without a log
22-
$ sudo node fintojs.js
24+
$ sudo npm start
2325
## without sudo you would need to customize at least the port:
24-
$ node fintojs.js -p 8080
26+
$ npm start -- -p 8080 # note the '--' it's necessary!
2527
```
26-
This should work with all the helpers. Please report any issues or mising features (except the logging, of course).
28+
This should work with all the helpers. Please report any issues or missing features (except the logging, of course).
29+
30+
### TESTING
31+
32+
We have a test script you can use to test your server (**on port 80 only!**) with any credentials you have. This is a good way to test to see if your configuration is working, if the server is up, etc:
33+
34+
```bash
35+
## again in the fintojs directory you cloned...
36+
$ npm test [<federated-role-alias>]
37+
```
38+
where the *<federated-role-alias>* is the configured key to a federated role ARN you have configured in your `.fintorc` file. This is optional. If you leave it out, it will use the default role configured in `.fintorc`
39+
40+
The report is not the greatest, you will be able to see which helpers passed or failed and then it will be your job to check logs, server output, etc to find out what's wrong. If an investigation concludes that you did everything right (or at least believe so..), and tests are still failing, open an issue ticket and describe how to reproduce the issue.
41+
42+

lib/ActionLib.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ ActionLib.prototype.__getArnJson__ = function(acct,callback) {
126126
ActionLib.prototype.__getParts__ = function(req) {
127127
this.parts = [];
128128
req.url = req.url.replace(/\/+/, '/');
129+
req.url = req.url.replace(/\/+$/, ''); // a slash at the end is not RESTful
129130
this.parts = req.url.split('/');
130131
this.parts.shift(); //gets rid of the root, which is blank.
131132
return this.parts;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fintojs",
3-
"version": "0.2.0",
3+
"version": "0.4.0",
44
"description": "Fintojs is based upon finto (https://github.com/threadwaste/finto) written by Tony M. It is basically an sts service interface to resolve multiple iam roles for aws. Please read more documentation here: https://github.com/threadwaste/finto/blob/master/README.md",
55
"main": "finto.js",
66
"scripts": {

server.js

Lines changed: 0 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -76,127 +76,3 @@ server.listen(config.serverSettings, function() {
7676

7777

7878
} );
79-
80-
81-
/******************** NO LONGER NEEDED *********************
82-
function getAction(req, callback) {
83-
var parts = [],
84-
getString,
85-
getParts,
86-
action = '',
87-
roleReqObj = {},
88-
roleE,
89-
arnLib = new iamArnLib(),
90-
acct;
91-
// console.log("<===== called getaction");
92-
//TODO: make scalable.
93-
req.url = req.url.replace(/\/+/, '/');
94-
parts = req.url.split('/');
95-
parts.shift(); //gets rid of the root which has nothing.
96-
// console.log(parts);
97-
if (req.method === "PUT") {
98-
99-
//also for /roles -> PUT
100-
101-
try {
102-
roleReqObj = JSON.parse(postData);
103-
activeRole = roleReqObj.alias;
104-
if (! arnLib.getArn(activeRole)) {
105-
callback(activeRole + " role not found!");
106-
} else {
107-
callback(null, JSON.stringify({ active_role: activeRole }, null, ' '));
108-
}
109-
110-
} catch(roleE) {
111-
// console.log("caught error...");
112-
callback(roleE);
113-
114-
}
115-
return;
116-
}
117-
if (/roles/.test(req.url)) {
118-
// /roles -> GET
119-
// /roles/specificRole
120-
// /roles/specificRole/credentials
121-
// /roles?status=active <-- not implemented!
122-
// console.log("<==== roles test positive in url")
123-
action = parts[0];
124-
switch (parts.length) {
125-
case 2:
126-
// console.log("parts length: " + parts.length);
127-
action = 'arn'
128-
acct = parts[1]; //arn request for acct
129-
break;
130-
case 3:
131-
acct = parts[1];
132-
action = parts[2]; //credentials action for acct
133-
134-
}
135-
}
136-
// this needs to be split up to it's own action.. because we are supposed to return the active alias or credentials depending on whether or not there is an alias in the url.
137-
else if (/security-credentials/.test(req.url)) {
138-
139-
switch(parts.length) {
140-
case 4:
141-
action = parts[parts.length-1]; //should be security-credentials
142-
break;
143-
case 5:
144-
action = parts[parts.length-2]; //should be security-credentials
145-
acct = parts[parts.length-1]; //should be role key
146-
break;
147-
default:
148-
callback("bad security-credentials request!");
149-
}
150-
}
151-
if (/\?/.test(action)) {
152-
action = (action.split('?'))[0];
153-
}
154-
//console.log("action: " + action);
155-
156-
// Heavy lifting of action handling. TODO: break this out into a controller.
157-
switch(action) {
158-
case "roles": {
159-
// console.log("<===== found roles action ");
160-
161-
callback(null, ActionLib.getRoles(req, activeRole));
162-
break;
163-
};
164-
case "arn": {
165-
166-
ActionLib.getArnJson(acct, function(err, arnJson) {
167-
if (err) {
168-
callback(err)
169-
} else {
170-
// console.log("<===== arn json: " + arnJson);
171-
callback(null, arnJson);
172-
}
173-
});
174-
break;
175-
};
176-
case "security-credentials":
177-
if (!acct) {
178-
callback(null, activeRole);
179-
break;
180-
}
181-
182-
case "credentials": {
183-
stsLibInst.getCreds(acct,function(err, creds) {
184-
if (err) {
185-
callback(err);
186-
} else {
187-
callback(null, creds);
188-
}
189-
190-
});
191-
break;
192-
193-
}
194-
default: {
195-
callback("No Action Defined!");
196-
}
197-
198-
}
199-
200-
201-
}
202-
********************************/

test/ServerTest.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ httpOptions = {
1616

1717
async.parallel({
1818
'finto-ls': function(callback) {
19+
console.log("doing finto-ls..")
1920
httpOptions.path = "/roles";
2021
httpOptions.method= "GET";
2122
http.get(httpOptions, function(resp) {
@@ -38,6 +39,7 @@ async.parallel({
3839
})
3940
},
4041
'finto-set': function(callback) {
42+
console.log("doing finto-set..")
4143
httpOptions.path = "/roles";
4244
httpOptions.method = "PUT";
4345
var req = http.request(httpOptions);
@@ -66,6 +68,7 @@ async.parallel({
6668

6769
},
6870
'finto-active': function(callback) {
71+
console.log("doing finto-active..")
6972
httpOptions.path = "/roles?status=active";
7073
httpOptions.method = "GET";
7174

@@ -97,8 +100,8 @@ async.parallel({
97100

98101
new Promise(function(resolve,reject) {
99102

100-
101-
httpOptions.path = "/latest/meta-data/iam/security-credentials";
103+
console.log("doing security-credentials..")
104+
httpOptions.path = "/latest/meta-data/iam/security-credentials/";
102105
httpOptions.method = "GET";
103106
var respJson = {};
104107
http.get(httpOptions, function(resp) {
@@ -108,28 +111,30 @@ async.parallel({
108111
reject(false);
109112
}
110113
else if (respRole === roleAlias){
111-
// console.log("resolving...")
114+
// console.log("resolving...respRole:" + respRole + " roleAlias: " + roleAlias);
112115
resolve(respRole);
113116
} else {
114-
// console.log("couldn't resolve.. calling reject")
117+
// console.log("couldn't resolve.. calling reject")
115118
reject(false);
116119
}
117120
})
118121
})
119122
}).then(function(result) {
123+
console.log("doing security-credentials/" + result)
124+
// console.log("what is the result from the first call? " + result);
120125
httpOptions.path = "/latest/meta-data/iam/security-credentials/" + result;
121126
httpOptions.method = "GET";
122127
http.get(httpOptions, function(resp) {
123128
getData(resp, function(credData){
124129
var credJson;
125130
try {
126131
credJson = JSON.parse(credData);
127-
132+
// console.log("credJson: " + JSON.stringify(credJson));
128133
if (credJson.Code === "Success") {
129-
// console.log("cred data was success...")
134+
// console.log("cred data was success...")
130135
callback(null, true);
131136
} else {
132-
// console.log("credata was not success...")
137+
// console.log("credata was not success...")
133138
callback(null, false);
134139
}
135140
} catch(jsonE) {
@@ -140,6 +145,7 @@ async.parallel({
140145

141146
},
142147
function(result) {
148+
// console.log("reject function: " + result);
143149
callback(null,result); //should be false.
144150

145151
})

0 commit comments

Comments
 (0)