Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

Commit

Permalink
Clean Up & Refactoring Merge (#58)
Browse files Browse the repository at this point in the history
* Add Github Workflow Actions for Nodejs
* Update nodejs.yml
* Update package.json
* Vue code cleanup
* Add App Engine Deployment Files
* Lint fixes
* Fix and Extend Tests
* Updating README with additional claraficiations
* Update Explain Proto and GRPC calls to handle streaming responses 
* Removal of cached and json data options.  
* Comment clean-up
* Deleting ResourceNode file
  • Loading branch information
garrettwong authored Apr 29, 2020
1 parent e7f875b commit 88be99c
Show file tree
Hide file tree
Showing 34 changed files with 443 additions and 3,258 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches: [ master, dev, actions ]
pull_request:
branches: [ master, dev, actions ]

jobs:
build:

runs-on: ubuntu-latest
env:
ui-dir: ./forseti-visualizer-ui
api-dir: ./forseti-api

strategy:
matrix:
node-version: [10.x, 12.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install Packages
working-directory: ./forseti-visualizer-ui
run: npm install
- name: Run Build
working-directory: ./forseti-visualizer-ui
run: npm run build --if-present
- name: Run Test
working-directory: ./forseti-visualizer-ui
run: npm test
- name: Install Packaages
working-directory: ./forseti-api
run: npm install
- name: Run Build
working-directory: ./forseti-api
run: npm run build --if-present
- name: Run Test
working-directory: ./forseti-api
run: npm test
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ npm start

## Alternative Deployments

There are other solution deployment pipelines described here for Docker, GCE, GKE and Cloud Run. Each of these are dependent on a Docker Image of Forseti Visualizer.
There are other solution deployment pipelines described here for Docker, GCE, GKE and Cloud Run. Each of these are dependent on a Docker Image of Forseti Visualizer. A **prerequisite** of these is to first configure your local environment for local development - ensure that you have gone through the Getting Started Section.

### Docker

Expand All @@ -113,9 +113,9 @@ cp ../forseti-api/source.env source.env
./build-images.sh

# verify that the docker image has been built
docker images | grep
docker images | grep "forseti-visualizer"

# verify that the docker image can be run
# create a docker readable source file for environment var injection
cat > dockersource.env << EOF
API_HOST=0.0.0.0
API_PORT=8080
Expand All @@ -130,9 +130,10 @@ EOF

PROJECT_ID="forseti-visualizer" # << REPLACE THIS WITH YOUR PROJECT_ID
IMAGE_NAME="forseti-visualizer"
FULL_IAMGE_NAME="gcr.io/$PROJECT_ID/$IMAGE_NAME"
FULL_IMAGE_NAME="gcr.io/$PROJECT_ID/$IMAGE_NAME"

docker run --env-file dockersource.env --name forsetivisualizer --rm -d -p 8080:8080 $FULL_IAMGE_NAME
# You will need to determine how to connect to the Cloud SQL Database. This can be done via (--network host), which may not work on Mac, via installing Cloud SQL Proxy on the Docker Image, and a number of other methods. It is not implemented as a default at this time.
docker run --env-file dockersource.env --name forsetivisualizer --rm -d -p 8080:8080 $FULL_IMAGE_NAME
docker ps

# navigate to http://localhost:8080/
Expand All @@ -156,7 +157,7 @@ docker ps

### Cloud Run

```bash
```bash
./deployments/deploy-cloudrun.sh
```

Expand Down
38 changes: 38 additions & 0 deletions forseti-api/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# [START gae_flex_quickstart_yaml]
runtime: custom
env: flex
env_variables:
API_HOST: "0.0.0.0"
API_PORT: "8080"
CLOUDSQL_HOSTNAME: "172.17.0.1"
CLOUDSQL_USERNAME: "root"
CLOUDSQL_PASSWORD: ""
CLOUDSQL_SCHEMA: "forseti_security"
FORSETI_SERVER_VM_CHANNEL: "35.232.32.159:50051"
FORSETI_DATA_MODEL_HANDLE: "f240aa3a5bc9fd9acfaf50fdd3620534"
PROJECT_ID: "forsetivisualizer"

beta_settings:
cloud_sql_instances: devops-shared-vpc:us-central1:forseti-server-db-4ebc72af=tcp:3306

# This sample incurs costs to run on the App Engine flexible environment.
# The settings below are to reduce costs during testing and are not appropriate
# for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/nodejs/configuring-your-app-with-app-yaml
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 10
network:
instance_tag: tag-name
name: projects/devops-shared-vpc/global/networks/default
subnetwork_name: default

# [END gae_flex_quickstart_yaml]


## KNOWN ISSUES:
## projects without the -compute@ default account
## ERROR: (gcloud.app.deploy) Error Response: [13] An internal error occurred while creating a Google Cloud Storage bucket.
6 changes: 3 additions & 3 deletions forseti-api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 17 additions & 33 deletions forseti-api/protos/explain.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ package explain;
service Explain {
rpc Ping(PingRequest) returns (PingReply) {}

rpc ListResources (ListResourcesRequest) returns (ListResourcesReply) {}
rpc ListGroupMembers (ListGroupMembersRequest) returns (ListGroupMembersReply) {}
rpc ListRoles (ListRolesRequest) returns (ListRolesReply) {}
rpc ListResources (ListResourcesRequest) returns (stream Resource) {}
rpc ListGroupMembers (ListGroupMembersRequest) returns (stream GroupMember) {}
rpc ListRoles (ListRolesRequest) returns (stream Role) {}
rpc GetIamPolicy (GetIamPolicyRequest) returns (GetIamPolicyReply) {}
rpc CheckIamPolicy (CheckIamPolicyRequest) returns (CheckIamPolicyReply) {}

rpc GetAccessByPermissions(GetAccessByPermissionsRequest) returns (stream Access) {}
rpc GetAccessByResources(GetAccessByResourcesRequest) returns (GetAccessByResourcesReply) {}
rpc GetAccessByMembers(GetAccessByMembersRequest) returns (GetAccessByMembersReply) {}
rpc GetAccessByResources(GetAccessByResourcesRequest) returns (stream Access) {}
rpc GetAccessByMembers(GetAccessByMembersRequest) returns (stream MemberAccess) {}
rpc GetPermissionsByRoles(GetPermissionsByRolesRequest) returns (GetPermissionsByRolesReply) {}

rpc ExplainGranted(ExplainGrantedRequest) returns (ExplainGrantedReply) {}
rpc ExplainDenied(ExplainDeniedRequest) returns (ExplainDeniedReply) {}
rpc ExplainDenied(ExplainDeniedRequest) returns (stream BindingStrategy) {}


}
Expand All @@ -47,24 +47,24 @@ message ListResourcesRequest {
string prefix = 1;
}

message ListResourcesReply {
repeated string full_resource_names = 1;
message Resource {
string full_resource_name = 1;
}

message ListGroupMembersRequest {
string prefix = 1;
}

message ListGroupMembersReply {
repeated string member_names = 1;
message GroupMember {
string member_name = 1;
}

message ListRolesRequest {
string prefix = 1;
}

message ListRolesReply {
repeated string role_names = 1;
message Role {
string role_name = 1;
}

message GetIamPolicyRequest {
Expand Down Expand Up @@ -127,10 +127,6 @@ message BindingStrategy {
int32 overgranting = 2;
}

message ExplainDeniedReply {
repeated BindingStrategy strategies = 1;
}

message ExplainDeniedRequest {
string member = 1;
repeated string permissions = 2;
Expand Down Expand Up @@ -170,26 +166,14 @@ message GetAccessByResourcesRequest {
bool expand_groups = 3;
}

message GetAccessByResourcesReply {
message Access {
repeated string members = 1;
string resource = 2;
string role = 3;
}
repeated Access accesses = 1;
}

message GetAccessByMembersRequest {
string member_name = 1;
repeated string permission_names = 2;
bool expand_resources = 3;
}

message GetAccessByMembersReply {
message Access {
string member = 1;
repeated string resources = 2;
string role = 3;
}
repeated Access accesses = 1;
}
message MemberAccess {
string member = 1;
repeated string resources = 2;
string role = 3;
}
12 changes: 7 additions & 5 deletions forseti-api/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ app.use(express.static(publicPath, staticConf));

/* API Route Configuration */

// set up the default /api route
app.use('/api', api({}));

// set up the main route '/'
app.get('/', (req, res) => {
Expand Down Expand Up @@ -87,10 +89,10 @@ app.get('/', (req, res) => {
});
});

// set up the default /api route
app.use('/api', api({}));


// EXPOSE APP using the API_HOST and API_PORT environment variables
app.listen(process.env['API_PORT'], process.env['API_HOST']);
console.log(`Running on http://${process.env['API_HOST']}:${process.env['API_PORT']}`);
let apiHost = process.env['API_HOST'] || '0.0.0.0';
let apiPort = process.env['API_PORT'] || 8080;

app.listen(apiPort, apiHost);
console.log(`Running on http://${apiHost}:${apiPort}`);
13 changes: 3 additions & 10 deletions forseti-api/server/api/forseti.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,9 @@ export default ({
if (error) {
console.log('Error: ', error);
} else {
for (let i = 0; i < results.accesses.length; i++) {
for (let j = 0; j < results.accesses[i].resources.length; j++) {
console.log(results.accesses[i]);
console.log(results.accesses[i].resources[j]);
}
}

res.json(results.accesses);
console.log('Results', results);

res.json(results);
}
});
});
Expand All @@ -94,8 +89,6 @@ export default ({
else {
console.log(results);

// TODO:

res.json(results.accesses);
}
});
Expand Down
21 changes: 14 additions & 7 deletions forseti-api/server/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

const Telnet = require('telnet-client');

import {
version
} from '../../package.json';
import RenderHelpers from '../render-helpers';
import {
Router
} from 'express';
Expand All @@ -40,9 +43,12 @@ export default ({
}));





// perhaps expose some API metadata at the root
api.get('/version', (req, res) => {
res.json({version});
return;
});

// perhaps expose some API metadata at the root
api.get('/', (req, res) => {
Expand All @@ -54,8 +60,9 @@ export default ({

let connection = new Telnet();

if (process.env['CLOUDSQL_HOSTNAME'] === '') {
res.render('error')
if (!process.env['CLOUDSQL_HOSTNAME']) {
RenderHelpers.renderError(res, version);
return;
}

console.log('Attempting connection to: ' + process.env['CLOUDSQL_HOSTNAME']);
Expand All @@ -70,15 +77,15 @@ export default ({
connection.connect(params)
.then(function (prompt) {
console.log('Connected to Cloud SQL');
renderIndex(res, true);
RenderHelpers.renderIndex(res, version, true);
}, function (error) {
console.log('Not connected to Cloud SQL', error);
renderIndex(res, false);
RenderHelpers.renderIndex(res, version, false);
})
.catch(function (error) {
// handle the throw (timeout)
console.log('Not connected to Cloud SQL', error);
renderIndex(res, false);
RenderHelpers.renderIndex(res, version, false);
});
});

Expand Down
Loading

0 comments on commit 88be99c

Please sign in to comment.