// DecorateService annotates the service with the Kinesis hook
12308
func (lad *LogAggregatorDecorator) DecorateService(context map[string]interface{},
	serviceName string,
	template *gocf.Template,
	S3Bucket string,
	S3Key string,
	buildID string,
	awsSession *session.Session,
	noop bool,
	logger *logrus.Logger) error {

	// Create the Kinesis Stream
	template.AddResource(lad.kinesisStreamResourceName, lad.kinesisResource)

	// Create the IAM role
	putRecordPriv := spartaIAMBuilder.Allow("kinesis:PutRecord").
		ForResource().
		Attr(lad.kinesisStreamResourceName, "Arn").
		ToPolicyStatement()
	passRolePriv := spartaIAMBuilder.Allow("iam:PassRole").
		ForResource().
		Literal("arn:aws:iam::").
		AccountID(":").
		Literal("role/").
		Literal(lad.iamRoleNameResourceName).
		ToPolicyStatement()

	statements := make([]spartaIAM.PolicyStatement, 0)
	statements = append(statements,
		putRecordPriv,
		passRolePriv,
	)
	iamPolicyList := gocf.IAMRolePolicyList{}
	iamPolicyList = append(iamPolicyList,
		gocf.IAMRolePolicy{
			PolicyDocument: sparta.ArbitraryJSONObject{
				"Version":   "2012-10-17",
				"Statement": statements,
			},
			PolicyName: gocf.String("LogAggregatorPolicy"),
		},
	)
	iamLogAggregatorRole := &gocf.IAMRole{
		RoleName:                 gocf.String(lad.iamRoleNameResourceName),
		AssumeRolePolicyDocument: LogAggregatorAssumePolicyDocument,
		Policies:                 &iamPolicyList,
	}
	template.AddResource(lad.iamRoleNameResourceName, iamLogAggregatorRole)

	return nil
}
712199
func (a *basicAuth) DecorateRequest(req *http.Request) {
	req.SetBasicAuth(a.username, a.password)
}
502228
func (l *State) AddService(service *structs.NodeService, token string) error {
	l.Lock()
	defer l.Unlock()
	return l.addServiceLocked(service, token)
}
24955
func (m *KubernetesMonitor) decorateRuntime(puID string, runtimeInfo policy.RuntimeReader, event common.Event,
	podName, podNamespace string) (err error) {

	// Do nothing on other events apart from start event.
	if event != common.EventStart {
		return nil
	}

	puRuntime, ok := runtimeInfo.(*policy.PURuntime)
	if !ok {
		zap.L().Error("Found invalid runtime for puid", zap.String("puid", puID))
		return fmt.Errorf("invalid runtime for puid:%s", puID)
	}

	extensions := policy.ExtendedMap{}

	// pause container with host net set to true.
	if runtimeInfo.PUType() == common.LinuxProcessPU {
		extensions[constants.DockerHostMode] = "true"
		extensions[constants.DockerHostPUID] = puID
		options := puRuntime.Options()
		options.PolicyExtensions = extensions

		// set Options on docker runtime.
		puRuntime.SetOptions(options)
		return nil
	}

	pausePUID := ""
	puIDs := m.cache.getPUIDsbyPod(podNamespace, podName)
	// get the puid of the pause container.
	for _, id := range puIDs {
		rtm := m.cache.getDockerRuntimeByPUID(id)
		if rtm == nil {
			continue
		}

		if isPodInfraContainer(rtm) && rtm.PUType() == common.LinuxProcessPU {
			pausePUID = id
			break
		}

		// if the pause container is not host net container, nothing to do.
		if isPodInfraContainer(rtm) {
			return nil
		}
	}

	extensions[constants.DockerHostPUID] = pausePUID
	options := puRuntime.Options()
	options.PolicyExtensions = extensions
	// set Options on docker runtime.
	puRuntime.SetOptions(options)

	return nil
}
1076209
func NewService(kv Store) *Service {
	return &Service{
		Logger:         zap.NewNop(),
		IDGenerator:    snowflake.NewIDGenerator(),
		TokenGenerator: rand.NewTokenGenerator(64),
		Hash:           &Bcrypt{},
		kv:             kv,
		time:           time.Now,
	}
}
1328778
func NewService(r cargo.HandlingEventRepository, f cargo.HandlingEventFactory, h EventHandler) Service {
	return &service{
		handlingEventRepository: r,
		handlingEventFactory:    f,
		handlingEventHandler:    h,
	}
}
1038675
func (a *accessToken) DecorateRequest(req *http.Request) {
	var token string

	// try to get new token and fall back to parent token
	if a.scope != "" {
		token, _ = a.manager.TokenForScope(a.scope)
	}

	if token == "" {
		token = a.accessToken
	}

	req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
}
1322221
func ReStartService() error {
	// TODO(tsm): refactor to make use of service.RestartableService
	svc, err := discoverService(ServiceName)
	if err != nil {
		return errors.Trace(err)
	}
	return restartService(svc)
}
1285742
func InitService(serviceName string) error {
	h := &handler{
		tosvc:   make(chan bool),
		fromsvc: make(chan error),
	}

	service = h
	var err error
	go func() {
		err = svc.Run(serviceName, h)
		h.fromsvc <- err
	}()

	// Wait for the first signal from the service handler.
	err = <-h.fromsvc
	if err != nil {
		return err
	}
	klog.Infof("Running %s as a Windows service!", serviceName)
	return nil
}
1299574
func NewService() *Service {
	return &Service{
		TokenGenerator: rand.NewTokenGenerator(64),
		IDGenerator:    snowflake.NewIDGenerator(),
		time:           time.Now,
	}
}
1033884
func (d *decorator) Decorate(proposal *peer.Proposal, input *peer.ChaincodeInput) *peer.ChaincodeInput {
	return input
}
3543
func (s Strategy) Decorate(obj runtime.Object) error {
	switch t := obj.(type) {
	case *imageapi.ImageStream:
		t.Status.DockerImageRepository = s.dockerImageRepository(t, true)
		t.Status.PublicDockerImageRepository = s.publicDockerImageRepository(t)
	case *imageapi.ImageStreamList:
		for i := range t.Items {
			is := &t.Items[i]
			is.Status.DockerImageRepository = s.dockerImageRepository(is, true)
			is.Status.PublicDockerImageRepository = s.publicDockerImageRepository(is)
		}
	default:
		return kerrors.NewBadRequest(fmt.Sprintf("not an ImageStream nor ImageStreamList: %v", obj))
	}
	return nil
}
628078
func (extension DecoderExtension) DecorateDecoder(typ reflect2.Type, decoder ValDecoder) ValDecoder {
	return decoder
}
920796
func (_m *FacadeInterface) AddServiceTemplate(ctx datastore.Context, serviceTemplate servicetemplate.ServiceTemplate, reloadLogstashConfig bool) (string, error) {
	ret := _m.Called(ctx, serviceTemplate, reloadLogstashConfig)

	var r0 string
	if rf, ok := ret.Get(0).(func(datastore.Context, servicetemplate.ServiceTemplate, bool) string); ok {
		r0 = rf(ctx, serviceTemplate, reloadLogstashConfig)
	} else {
		r0 = ret.Get(0).(string)
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(datastore.Context, servicetemplate.ServiceTemplate, bool) error); ok {
		r1 = rf(ctx, serviceTemplate, reloadLogstashConfig)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
677366
func (r *registry) initDecoratorPlugin(p *plugin.Plugin) {
	constructorSymbol, err := p.Lookup(decoratorPluginFactory)
	if err != nil {
		panicWithLookupError(decoratorPluginFactory, err)
	}
	constructor, ok := constructorSymbol.(func() decoration.Decorator)
	if !ok {
		panicWithDefinitionError(decoratorPluginFactory)
	}
	decorator := constructor()
	if decorator != nil {
		r.decorators = append(r.decorators, constructor())
	}
}
836080
func (w *ControllersWriter) WriteInitService(encoders, decoders []*EncoderTemplateData) error {
	ctx := map[string]interface{}{
		"API":      design.Design,
		"Encoders": encoders,
		"Decoders": decoders,
	}
	return w.ExecuteTemplate("service", serviceT, nil, ctx)
}
66664
func (lad *LogAggregatorDecorator) DecorateTemplate(serviceName string,
	lambdaResourceName string,
	lambdaResource gocf.LambdaFunction,
	resourceMetadata map[string]interface{},
	S3Bucket string,
	S3Key string,
	buildID string,
	template *gocf.Template,
	context map[string]interface{},
	logger *logrus.Logger) error {

	// The relay function should consume the stream
	if lad.logRelay.LogicalResourceName() == lambdaResourceName {
		// Need to add a Lambda EventSourceMapping
		eventSourceMappingResourceName := sparta.CloudFormationResourceName("LogAggregator",
			"EventSourceMapping",
			lambdaResourceName)

		template.AddResource(eventSourceMappingResourceName, &gocf.LambdaEventSourceMapping{
			StartingPosition: gocf.String(lad.kinesisMapping.StartingPosition),
			BatchSize:        gocf.Integer(lad.kinesisMapping.BatchSize),
			EventSourceArn:   gocf.GetAtt(lad.kinesisStreamResourceName, "Arn"),
			FunctionName:     gocf.GetAtt(lambdaResourceName, "Arn"),
		})
	} else {
		// The other functions should publish their logs to the stream
		subscriptionName := logAggregatorResName(fmt.Sprintf("Lambda%s", lambdaResourceName))
		subscriptionFilterRes := &gocf.LogsSubscriptionFilter{
			DestinationArn: gocf.GetAtt(lad.kinesisStreamResourceName, "Arn"),
			RoleArn:        gocf.GetAtt(lad.iamRoleNameResourceName, "Arn"),
			LogGroupName: gocf.Join("",
				gocf.String("/aws/lambda/"),
				gocf.Ref(lambdaResourceName)),
			FilterPattern: gocf.String("{$.level = info || $.level = warning || $.level = error }"),
		}
		template.AddResource(subscriptionName, subscriptionFilterRes)
	}
	return nil
}