cloudapi-gql
Advanced tools
+1
-1
@@ -60,3 +60,3 @@ 'use strict'; | ||
| const method = options.method && options.method.toLowerCase() || 'get'; | ||
| try { | ||
@@ -63,0 +63,0 @@ const { payload } = await this._wreck[method](path, wreckOptions); |
+7
-3
@@ -10,3 +10,3 @@ 'use strict'; | ||
| const Package = require('../package.json'); | ||
| const { CloudApi } = require('./cloudapi'); | ||
| const { CloudApi } = require('./cloudapi'); | ||
| const Resolvers = require('./resolvers'); | ||
@@ -32,5 +32,9 @@ | ||
| const register = async (server, { authStrategy, cloudapiUrl }) => { | ||
| const schema = makeExecutableSchema({ typeDefs: Schema.toString(), resolvers: Resolvers }); | ||
| const schema = makeExecutableSchema({ | ||
| typeDefs: Schema.toString(), | ||
| resolvers: Resolvers | ||
| }); | ||
| const graphiOptions = { | ||
| graphiqlPath: (NODE_ENV === 'development') ? '/graphiql' : false, | ||
| graphiqlPath: NODE_ENV === 'development' ? '/graphiql' : false, | ||
| schema, | ||
@@ -37,0 +41,0 @@ resolvers: Resolvers, |
+91
-7
| 'use strict'; | ||
| const ForceArray = require('force-array'); | ||
| const constantCase = require('constant-case'); | ||
| const Hasha = require('hasha'); | ||
| const map = require('apr-map'); | ||
| const Map = require('apr-map'); | ||
| const FWRule = require('fwrule'); | ||
| const CloudApi = require('./cloudapi'); | ||
| const internals = {}; | ||
@@ -14,3 +16,3 @@ | ||
| account: (root, args = {}, request) => { | ||
| return CloudApi('/', args, request); | ||
| return CloudApi('', {}, request); | ||
| }, | ||
@@ -172,3 +174,3 @@ | ||
| return map(machinesList, ({ id }) => internals.resolvers.Query.machine(root, { id }, request)); | ||
| return Map(machinesList, ({ id }) => internals.resolvers.Query.machine(root, { id }, request)); | ||
| }, | ||
@@ -246,2 +248,59 @@ | ||
| // TEMPORARY | ||
| // TODO: run in a worker | ||
| firewall_rules_create_machine: async (root, args, request) => { | ||
| const tags = internals.fromNameValues(args.tags); | ||
| const res = await internals.resolvers.Query.firewall_rules(root, {}, request); | ||
| const rules = res.map(({ rule, ...rest }) => { | ||
| return Object.assign(rest, { | ||
| rule_str: rule, | ||
| rule_obj: FWRule.parse(rule) | ||
| }); | ||
| }); | ||
| const defaultRules = rules.filter(({ enabled, rule_obj = {} }) => { | ||
| return ( | ||
| ForceArray(rule_obj.from).some(frm => frm[0] === 'wildcard') && | ||
| ForceArray(rule_obj.to).some(to => to[0] === 'wildcard') | ||
| ); | ||
| }); | ||
| const filterTagRulePartial = partial => { | ||
| return partial | ||
| .map(partial => ForceArray(partial)) | ||
| .filter(partial => partial[0] === 'tag') | ||
| .filter(partial => { | ||
| const tag = ForceArray(partial[1]); | ||
| const foundTagValue = tags[tag[0]]; | ||
| if (!foundTagValue) { | ||
| return false; | ||
| } | ||
| if (tag.length === 1) { | ||
| return true; | ||
| } | ||
| return foundTagValue === tag[1]; | ||
| }); | ||
| }; | ||
| const tagRules = rules | ||
| .filter(({ enabled, rule_obj = {} }) => { | ||
| const _from = ForceArray(rule_obj.from); | ||
| const _to = ForceArray(rule_obj.to); | ||
| const fromHas = filterTagRulePartial(_from).length; | ||
| const toHas = filterTagRulePartial(_to).length; | ||
| return Boolean(fromHas) || Boolean(toHas); | ||
| }) | ||
| .map(rule => { | ||
| return Object.assign(rule, { tag: true }); | ||
| }); | ||
| return defaultRules.concat(tagRules); | ||
| }, | ||
| vlans: async (root, { id }, request) => { | ||
@@ -396,2 +455,25 @@ if (id) { | ||
| createMachine: async (root, { name, image, networks, affinity, metadata, tags, firewall_enabled, ...args }, request) => { | ||
| const AffinityRuleTypes = { | ||
| MUST_EQUAL: '==', | ||
| MUST_NOT_EQUAL: '==~', | ||
| SHOULD_EQUAL: '!=', | ||
| SHOULD_NOT_EQUAL: '!=~' | ||
| }; | ||
| const payload = { | ||
| name, | ||
| 'package': args.package, | ||
| image, | ||
| networks, | ||
| affinity: affinity.map(({ key, value, type }) => `${key}${AffinityRuleTypes[type]}${value}`), | ||
| ...internals.fromNameValues(tags, 'tag.'), | ||
| ...internals.fromNameValues(metadata, 'tag.'), | ||
| firewall_enabled | ||
| }; | ||
| const { id } = await CloudApi(`/machines`, { method: 'post', payload }, request); | ||
| return internals.resolvers.Query.machine(root, { id }, request); | ||
| }, | ||
| updateMachineMetadata: async (root, { id, metadata }, request) => { | ||
@@ -501,3 +583,3 @@ const payload = internals.fromNameValues(metadata) | ||
| type: ({ type }) => { return (type ? type.toUpperCase() : type); } | ||
| type: ({ type }) => { return (type ? constantCase(type) : type); } | ||
| }, | ||
@@ -518,3 +600,5 @@ Action: { | ||
| return CloudApi(`/fwrules/${id}/machines`, {}, request); | ||
| } | ||
| }, | ||
| rule_str: ({ rule }, args, request) => rule, | ||
| rule_obj: ({ rule }, args, request) => FWRule.parse(rule) | ||
| }, | ||
@@ -551,5 +635,5 @@ Snapshot: { | ||
| return Object.assign(accumulator, { | ||
| [prefix + name]: value | ||
| [prefix + name]: name === 'triton.cns.disable' ? JSON.parse(value) : value | ||
| }); | ||
| }, {}); | ||
| }; |
+35
-9
@@ -0,6 +1,8 @@ | ||
| scalar Any | ||
| enum AffinityRuleType { | ||
| MUST_SAME_NODE | ||
| SHOULD_SAME_NODE | ||
| MUST_DIFF_NODE | ||
| SHOW_DIFF_NODE | ||
| MUST_EQUAL | ||
| SHOULD_EQUAL | ||
| MUST_NOT_EQUAL | ||
| SHOULD_NOT_EQUAL | ||
| } | ||
@@ -88,3 +90,5 @@ | ||
| # Firewall rule | ||
| rule: String | ||
| rule_str: String | ||
| # Firewall rule | ||
| rule_obj: Any | ||
| # Indicates if the rule is global | ||
@@ -98,2 +102,20 @@ global: Boolean | ||
| # temporary!! | ||
| type CreateMachineFirewallRule { | ||
| # Unique identifier for this rule | ||
| id: ID | ||
| # Indicates if the rule is enabled | ||
| enabled: Boolean | ||
| # Firewall rule | ||
| rule_str: String | ||
| # Firewall rule | ||
| rule_obj: Any | ||
| # Indicates if the rule is global | ||
| global: Boolean | ||
| # Human-readable description for the rule | ||
| description: String | ||
| tag: Boolean | ||
| } | ||
| enum CallerType { | ||
@@ -668,2 +690,6 @@ BASIC | ||
| ): FirewallRule | ||
| # temporary!! | ||
| firewall_rules_create_machine( | ||
| tags: [KeyValueInput] | ||
| ): [CreateMachineFirewallRule] | ||
| # List all vlans for the current account | ||
@@ -925,7 +951,7 @@ vlans( | ||
| # Friendly name for this instance; default is the first 8 characters of the machine id. If the name includes the string {{shortId}}, any instances of that tag within the name will be replaced by the first 8 characters of the machine id. | ||
| name: String | ||
| name: String! | ||
| # Id of the package to use on provisioning, obtained from ListPackages | ||
| package: ID | ||
| package: ID! | ||
| # The image UUID | ||
| image: ID | ||
| image: ID! | ||
| # Desired networks ids | ||
@@ -938,3 +964,3 @@ networks: [ID] | ||
| # An arbitrary set of tags can be set at provision time, but they must be prefixed with "tag" | ||
| tag: [KeyValueInput] | ||
| tags: [KeyValueInput] | ||
| # Completely enable or disable firewall for this instance. Default is false | ||
@@ -941,0 +967,0 @@ firewall_enabled: Boolean |
+3
-1
| { | ||
| "name": "cloudapi-gql", | ||
| "version": "4.0.0", | ||
| "version": "4.1.0", | ||
| "license": "MPL-2.0", | ||
@@ -19,3 +19,5 @@ "repository": "github:yldio/joyent-portal", | ||
| "bounce": "^1.2.0", | ||
| "constant-case": "^2.0.0", | ||
| "force-array": "^3.1.0", | ||
| "fwrule": "^1.4.1", | ||
| "graphi": "^5.2.0", | ||
@@ -22,0 +24,0 @@ "graphql-tools": "^2.6.1", |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
223603
1.51%729
11.13%11
22.22%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added