Skip to content

Instantly share code, notes, and snippets.

curl -L https://istio.io/downloadIstio | sh -
cd istio-1.4.3
export PATH=$PWD/bin:$PATH
istioctl manifest apply --set profile=demo --set values.tracing.enabled=true --set values.tracing.provider=zipkin
kubectl label namespace default istio-injection=enabled
kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml
kubectl apply -f samples/bookinfo/networking/destination-rule-all.yaml
kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml
export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')
echo $INGRESS_PORT
curl -L https://istio.io/downloadIstio | sh -
cd istio-1.4.3
export PATH=$PWD/bin:$PATH
istioctl manifest apply --set profile=demo
kubectl label namespace default istio-injection=enabled
kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml
kubectl apply -f samples/bookinfo/networking/destination-rule-all.yaml
kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml
export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')
echo $INGRESS_PORT
import { isSuperAdminResolver, isAdminResolver } from '../baseResolvers';
export default {
Mutation: {
// createProject is a mutation resolver that requires user with SUPER_ADMIn role
createProject: isSuperAdminResolver(
(root, { input }, context) =>
context.Projects.createProject(input, context.user.userId),
{
category: 'PROJECT',
// For resolvers that require authenticated users with SUPER_ADMIN role
export const isSuperAdminResolver = (resolver, trackDetails) =>
isAuthenticated.createResolver((root, args, context) => {
if (context.user.role !== Constants.UsersRolesToIds.SUPER_ADMIN) {
throw new Errors.ForbiddenError();
}
return executeWithTracking(resolver, root, args, context, trackDetails);
});
// For resolvers that require authenticated users with ADMIN role
export const isAdminResolver = (resolver, trackDetails) =>
isAuthenticated.createResolver((root, args, context) => {
if (![Constants.UsersRolesToIds.ADMIN, Constants.UsersRolesToIds.SUPER_ADMIN]
.includes(context.user.role)) {
throw new Errors.ForbiddenError();
}
return executeWithTracking(resolver, root, args, context, trackDetails);
});
// Authenticated users logic
export const isAuthenticated = baseResolver.createResolver(
(root, args, context) => {
if (!context.user) throw new Errors.AuthenticationRequiredError();
});
// For resolvers that require authenticated users
export const isAuthenticatedResolver = (resolver, trackDetails) =>
isAuthenticated.createResolver((root, args, context) =>
executeWithTracking(resolver, root, args, context, trackDetails));
import { createResolver } from 'apollo-resolvers';
import { isInstance } from 'apollo-errors';
import winston from 'winston';
import _ from 'lodash';
import Errors from '../errors';
import Constants from '../constants';
import Configuration from '../configuration';
// Simple resolvers call tracking logic
const trackAction = ({ userId, ...actionTracking }, data) => {
import gql from 'graphql-tag';
const query = gql`
{
project(id: 5) {
title!
description
}
}
`