// NewCmdServiceAccount is a wrapper for the Kubernetes CLI set serviceaccount command
515558
func NewCmdServiceAccount(fullName string, f kcmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
	cmd := set.NewCmdServiceAccount(f, streams)
	cmd.Long = setServiceaccountLong
	cmd.Example = fmt.Sprintf(setServiceaccountExample, fullName)

	return cmd
}
926649
func NewSetServiceAccountOptions(streams genericclioptions.IOStreams) *SetServiceAccountOptions {
	return &SetServiceAccountOptions{
		PrintFlags:  genericclioptions.NewPrintFlags("serviceaccount updated").WithTypeSetter(scheme.Scheme),
		RecordFlags: genericclioptions.NewRecordFlags(),

		Recorder: genericclioptions.NoopRecorder{},

		IOStreams: streams,
	}
}
238822
func (c *ServicedCli) cmdServiceVariableSet(ctx *cli.Context) {
	args := ctx.Args()
	if len(args) < 3 {
		fmt.Printf("Incorrect Usage.\n\n")
		cli.ShowCommandHelp(ctx, "set")
		return
	}

	svcDetails, _, err := c.searchForService(args[0], ctx.Bool("no-prefix-match"))
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return
	}

	service, err := c.driver.GetService(svcDetails.ID)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return
	}

	key := args[1]
	value := args[2]
	if service.Context == nil {
		service.Context = make(map[string]interface{})
	}
	service.Context[key] = value
	if service, err := c.driver.UpdateServiceObj(*service); err != nil {
		fmt.Fprintln(os.Stderr, err)
	} else if service == nil {
		fmt.Fprintln(os.Stderr, "received nil service")
	} else {
		fmt.Println(service.ID)
	}
}
1081829
func NewAccount(service *goa.Service, db *store.DB) *AccountController {
	return &AccountController{
		Controller: service.NewController("Account"),
		db:         db,
	}
}
377060
func (c *ServicedCli) cmdServiceConfigList(ctx *cli.Context) {
	args := ctx.Args()
	if len(args) < 1 {
		fmt.Printf("Incorrect Usage.\n\n")
		cli.ShowCommandHelp(ctx, "list")
		c.exit(1)
		return
	}

	svcDetails, _, err := c.searchForService(args[0], ctx.Bool("no-prefix-match"))
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		c.exit(1)
		return
	}

	service, err := c.driver.GetService(svcDetails.ID)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		c.exit(1)
		return
	}

	configs := service.ConfigFiles

	if len(args) < 2 {
		configList := make([]string, 0)

		for filename := range configs {
			configList = append(configList, filename)
		}
		configJson := map[string]([]string){
			"ConfigFiles": configList,
		}
		if configJsonOut, err := json.MarshalIndent(configJson, " ", "  "); err != nil {
			fmt.Fprintln(os.Stderr, err)
			c.exit(1)
			return
		} else {
			fmt.Printf("%s\n\n", configJsonOut)
			return
		}
	} else {
		filename := args[1]
		if _, found := configs[filename]; found {
			fmt.Printf("%s", configs[filename].Content)
		} else {
			fmt.Printf("Config file %s not found.\n", filename)
			c.exit(1)
			return
		}
	}
	return
}
660624
func NewAddCAASCommand(cloudMetadataStore CloudMetadataStore) cmd.Command {
	store := jujuclient.NewFileClientStore()
	cmd := &AddCAASCommand{
		OptionalControllerCommand: modelcmd.OptionalControllerCommand{Store: store},
		cloudMetadataStore:        cloudMetadataStore,
		store:                     store,
		newClientConfigReader: func(caasType string) (clientconfig.ClientConfigFunc, error) {
			return clientconfig.NewClientConfigReader(caasType)
		},
	}
	cmd.addCloudAPIFunc = func() (AddCloudAPI, error) {
		root, err := cmd.NewAPIRoot(cmd.store, cmd.controllerName, "")
		if err != nil {
			return nil, errors.Trace(err)
		}
		return cloudapi.NewClient(root), nil
	}

	cmd.brokerGetter = cmd.newK8sClusterBroker
	cmd.getAllCloudDetails = jujucmdcloud.GetAllCloudDetails
	return modelcmd.WrapBase(cmd)
}
139153
func (c *ServicedCli) cmdServiceSnapshot(ctx *cli.Context) {
	nArgs := len(ctx.Args())
	if nArgs < 1 {
		fmt.Printf("Incorrect Usage.\n\n")
		cli.ShowCommandHelp(ctx, "snapshot")
		c.exit(1)
		return
	}

	description := ""
	if nArgs <= 3 {
		description = ctx.String("description")
	}

	svc, _, err := c.searchForService(ctx.Args().First(), ctx.Bool("no-prefix-match"))
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		c.exit(1)
		return
	}

	//get the tags (if any)
	tag := ctx.String("tag")

	cfg := api.SnapshotConfig{
		ServiceID: svc.ID,
		Message:   description,
		Tag:       tag,
	}
	if snapshot, err := c.driver.AddSnapshot(cfg); err != nil {
		fmt.Fprintln(os.Stderr, err)
		c.exit(1)
	} else if snapshot == "" {
		fmt.Fprintln(os.Stderr, "received nil snapshot")
		c.exit(1)
	} else {
		fmt.Println(snapshot)
	}
	return
}
120290
func NewDNSProviderServiceAccount(saFile string) (*DNSProvider, error) {
	if saFile == "" {
		return nil, fmt.Errorf("googlecloud: Service Account file missing")
	}

	saKey, err := ioutil.ReadFile(saFile)
	if err != nil {
		return nil, fmt.Errorf("googlecloud: unable to read Service Account file: %v", err)
	}

	return NewDNSProviderServiceAccountKey(saKey)
}
300049
func (c *ServicedCli) cmdServiceSetIP(ctx *cli.Context) {
	args := ctx.Args()
	if len(args) < 3 {
		fmt.Printf("Incorrect Usage.\n\n")
		cli.ShowCommandHelp(ctx, "set-ip")
		c.exit(1)
		return
	}

	if args[len(args)-1] == "--generate-bash-completion" {
		// CC-892: Disable bash completion after SERVICE_ID because possible matches
		// are unavailable outside the container.
		return
	}

	svc, _, err := c.searchForService(ctx.Args().First(), ctx.Bool("no-prefix-match"))
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		c.exit(1)
		return
	}

	var endpointName string
	if len(args) > 1 {
		endpointName = args[1]
	}

	var ipAddress string
	if len(args) > 2 {
		ipAddress = args[2]
	}

	if ctx.Int("port") < 1 {
		fmt.Printf("Please specify the valid port number.\n\n")
		cli.ShowCommandHelp(ctx, "set-ip")
		c.exit(1)
		return
	}

	if ctx.String("proto") == "" {
		fmt.Printf("Please specify port protocol.\n\n")
		cli.ShowCommandHelp(ctx, "set-ip")
		c.exit(1)
		return
	}

	cfg := api.IPConfig{
		ServiceID:    svc.ID,
		IPAddress:    ipAddress,
		Port:         uint16(ctx.Int("port")),
		Proto:        ctx.String("proto"),
		EndpointName: endpointName,
	}

	if err := c.driver.SetIP(cfg); err != nil {
		fmt.Fprintln(os.Stderr, err)
		c.exit(1)
	}
	return
}
1072832
func (e *DockercfgDeletedController) getServiceAccount(secret *v1.Secret) (*v1.ServiceAccount, error) {
	saName, saUID := secret.Annotations[v1.ServiceAccountNameKey], secret.Annotations[v1.ServiceAccountUIDKey]
	if len(saName) == 0 || len(saUID) == 0 {
		return nil, nil
	}

	serviceAccount, err := e.client.CoreV1().ServiceAccounts(secret.Namespace).Get(saName, metav1.GetOptions{})
	if err != nil {
		return nil, err
	}

	if saUID != string(serviceAccount.UID) {
		return nil, fmt.Errorf("secret (%v) service account UID (%v) does not match service account (%v) UID (%v)", secret.Name, saUID, serviceAccount.Name, serviceAccount.UID)
	}
	return serviceAccount, nil
}
744543
func (c *UsersController) CreateUserAsServiceAccount(ctx *app.CreateUserAsServiceAccountUsersContext) error {

	isSvcAccount, err := isServiceAccount(ctx, serviceNameAuth)
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"err": err,
		}, "failed to determine if account is a service account")
		return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(err))

	}
	if !isSvcAccount {
		log.Error(ctx, map[string]interface{}{
			"identity_id": ctx.ID,
		}, "account used to call create api is not a service account")
		return jsonapi.JSONErrorResponse(ctx, goa.ErrUnauthorized(errs.New("a non-service account tried to create a user.")))
	}

	return c.createUserInDB(ctx)
}
1026356
func (i *Handle) doGetServicesCmd(svc *Service) ([]*Service, error) {
	var res []*Service

	msgs, err := i.doCmdwithResponse(svc, nil, ipvsCmdGetService)
	if err != nil {
		return nil, err
	}

	for _, msg := range msgs {
		srv, err := i.parseService(msg)
		if err != nil {
			return nil, err
		}
		res = append(res, srv)
	}

	return res, nil
}
549498
func NewMockServiceAccountInterface(ctrl *gomock.Controller) *MockServiceAccountInterface {
	mock := &MockServiceAccountInterface{ctrl: ctrl}
	mock.recorder = &MockServiceAccountInterfaceMockRecorder{mock}
	return mock
}
685637
func (c *ServicedCli) cmdServiceEdit(ctx *cli.Context) {
	args := ctx.Args()
	if len(args) < 1 {
		fmt.Printf("Incorrect Usage.\n\n")
		cli.ShowCommandHelp(ctx, "edit")
		c.exit(1)
		return
	}

	svcDetails, _, err := c.searchForService(args[0], ctx.Bool("no-prefix-match"))
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		c.exit(1)
		return
	}

	service, err := c.driver.GetService(svcDetails.ID)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		c.exit(1)
		return
	}

	jsonService, err := json.MarshalIndent(service, " ", "  ")
	if err != nil {
		fmt.Fprintf(os.Stderr, "error marshalling service: %s\n", err)
		c.exit(1)
		return
	}

	name := fmt.Sprintf("serviced_service_edit_%s", service.ID)
	reader, err := openEditor(jsonService, name, ctx.String("editor"))
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		c.exit(1)
		return
	}

	if service, err := c.driver.UpdateService(reader); err != nil {
		fmt.Fprintln(os.Stderr, err)
		c.exit(1)
	} else if service == nil {
		fmt.Fprintln(os.Stderr, "received nil service")
		c.exit(1)
	} else {
		fmt.Println(service.ID)
	}
	return
}
935913
func (v *version) ServiceAccounts() ServiceAccountInformer {
	return &serviceAccountInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions}
}
55360
func NewAddCloudCommand(cloudMetadataStore CloudMetadataStore) cmd.Command {
	cloudCallCtx := context.NewCloudCallContext()
	store := jujuclient.NewFileClientStore()
	c := &AddCloudCommand{
		OptionalControllerCommand: modelcmd.OptionalControllerCommand{Store: store},
		cloudMetadataStore:        cloudMetadataStore,
		CloudCallCtx:              cloudCallCtx,
		// Ping is provider.Ping except in tests where we don't actually want to
		// require a valid cloud.
		Ping: func(p environs.EnvironProvider, endpoint string) error {
			return p.Ping(cloudCallCtx, endpoint)
		},
		store: store,
	}
	c.addCloudAPIFunc = c.cloudAPI
	return modelcmd.WrapBase(c)
}
948689
func (c *gceCloudImplementation) ServiceAccount() (string, error) {
	if c.projectInfo == nil {
		// Find the project info from the compute API, which includes the default service account
		glog.V(2).Infof("fetching project %q from compute API", c.project)
		p, err := c.compute.Projects.Get(c.project).Do()
		if err != nil {
			return "", fmt.Errorf("error fetching info for project %q: %v", c.project, err)
		}

		c.projectInfo = p
	}

	if c.projectInfo.DefaultServiceAccount == "" {
		return "", fmt.Errorf("compute project %q did not have DefaultServiceAccount", c.project)
	}

	return c.projectInfo.DefaultServiceAccount, nil
}