id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequencelengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
sequencelengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
161,700
argoproj/argo-cd
util/config/reader.go
MarshalLocalYAMLFile
func MarshalLocalYAMLFile(path string, obj interface{}) error { yamlData, err := yaml.Marshal(obj) if err == nil { err = ioutil.WriteFile(path, yamlData, 0600) } return err }
go
func MarshalLocalYAMLFile(path string, obj interface{}) error { yamlData, err := yaml.Marshal(obj) if err == nil { err = ioutil.WriteFile(path, yamlData, 0600) } return err }
[ "func", "MarshalLocalYAMLFile", "(", "path", "string", ",", "obj", "interface", "{", "}", ")", "error", "{", "yamlData", ",", "err", ":=", "yaml", ".", "Marshal", "(", "obj", ")", "\n", "if", "err", "==", "nil", "{", "err", "=", "ioutil", ".", "WriteFile", "(", "path", ",", "yamlData", ",", "0600", ")", "\n", "}", "\n", "return", "err", "\n", "}" ]
// MarshalLocalYAMLFile writes JSON or YAML to a file on disk. // The caller is responsible for checking error return values.
[ "MarshalLocalYAMLFile", "writes", "JSON", "or", "YAML", "to", "a", "file", "on", "disk", ".", "The", "caller", "is", "responsible", "for", "checking", "error", "return", "values", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/config/reader.go#L34-L40
161,701
argoproj/argo-cd
util/config/reader.go
UnmarshalLocalFile
func UnmarshalLocalFile(path string, obj interface{}) error { data, err := ioutil.ReadFile(path) if err == nil { err = unmarshalObject(data, obj) } return err }
go
func UnmarshalLocalFile(path string, obj interface{}) error { data, err := ioutil.ReadFile(path) if err == nil { err = unmarshalObject(data, obj) } return err }
[ "func", "UnmarshalLocalFile", "(", "path", "string", ",", "obj", "interface", "{", "}", ")", "error", "{", "data", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "path", ")", "\n", "if", "err", "==", "nil", "{", "err", "=", "unmarshalObject", "(", "data", ",", "obj", ")", "\n", "}", "\n", "return", "err", "\n", "}" ]
// UnmarshalLocalFile retrieves JSON or YAML from a file on disk. // The caller is responsible for checking error return values.
[ "UnmarshalLocalFile", "retrieves", "JSON", "or", "YAML", "from", "a", "file", "on", "disk", ".", "The", "caller", "is", "responsible", "for", "checking", "error", "return", "values", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/config/reader.go#L44-L50
161,702
argoproj/argo-cd
util/config/reader.go
UnmarshalRemoteFile
func UnmarshalRemoteFile(url string, obj interface{}) error { data, err := ReadRemoteFile(url) if err == nil { err = unmarshalObject(data, obj) } return err }
go
func UnmarshalRemoteFile(url string, obj interface{}) error { data, err := ReadRemoteFile(url) if err == nil { err = unmarshalObject(data, obj) } return err }
[ "func", "UnmarshalRemoteFile", "(", "url", "string", ",", "obj", "interface", "{", "}", ")", "error", "{", "data", ",", "err", ":=", "ReadRemoteFile", "(", "url", ")", "\n", "if", "err", "==", "nil", "{", "err", "=", "unmarshalObject", "(", "data", ",", "obj", ")", "\n", "}", "\n", "return", "err", "\n", "}" ]
// UnmarshalRemoteFile retrieves JSON or YAML through a GET request. // The caller is responsible for checking error return values.
[ "UnmarshalRemoteFile", "retrieves", "JSON", "or", "YAML", "through", "a", "GET", "request", ".", "The", "caller", "is", "responsible", "for", "checking", "error", "return", "values", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/config/reader.go#L54-L60
161,703
argoproj/argo-cd
util/config/reader.go
ReadRemoteFile
func ReadRemoteFile(url string) ([]byte, error) { var data []byte resp, err := http.Get(url) if err == nil { defer func() { _ = resp.Body.Close() }() data, err = ioutil.ReadAll(resp.Body) } return data, err }
go
func ReadRemoteFile(url string) ([]byte, error) { var data []byte resp, err := http.Get(url) if err == nil { defer func() { _ = resp.Body.Close() }() data, err = ioutil.ReadAll(resp.Body) } return data, err }
[ "func", "ReadRemoteFile", "(", "url", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "data", "[", "]", "byte", "\n", "resp", ",", "err", ":=", "http", ".", "Get", "(", "url", ")", "\n", "if", "err", "==", "nil", "{", "defer", "func", "(", ")", "{", "_", "=", "resp", ".", "Body", ".", "Close", "(", ")", "\n", "}", "(", ")", "\n", "data", ",", "err", "=", "ioutil", ".", "ReadAll", "(", "resp", ".", "Body", ")", "\n", "}", "\n", "return", "data", ",", "err", "\n", "}" ]
// ReadRemoteFile issues a GET request to retrieve the contents of the specified URL as a byte array. // The caller is responsible for checking error return values.
[ "ReadRemoteFile", "issues", "a", "GET", "request", "to", "retrieve", "the", "contents", "of", "the", "specified", "URL", "as", "a", "byte", "array", ".", "The", "caller", "is", "responsible", "for", "checking", "error", "return", "values", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/config/reader.go#L64-L74
161,704
argoproj/argo-cd
util/argo/argo.go
FormatAppConditions
func FormatAppConditions(conditions []argoappv1.ApplicationCondition) string { formattedConditions := make([]string, 0) for _, condition := range conditions { formattedConditions = append(formattedConditions, fmt.Sprintf("%s: %s", condition.Type, condition.Message)) } return strings.Join(formattedConditions, ";") }
go
func FormatAppConditions(conditions []argoappv1.ApplicationCondition) string { formattedConditions := make([]string, 0) for _, condition := range conditions { formattedConditions = append(formattedConditions, fmt.Sprintf("%s: %s", condition.Type, condition.Message)) } return strings.Join(formattedConditions, ";") }
[ "func", "FormatAppConditions", "(", "conditions", "[", "]", "argoappv1", ".", "ApplicationCondition", ")", "string", "{", "formattedConditions", ":=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "for", "_", ",", "condition", ":=", "range", "conditions", "{", "formattedConditions", "=", "append", "(", "formattedConditions", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "condition", ".", "Type", ",", "condition", ".", "Message", ")", ")", "\n", "}", "\n", "return", "strings", ".", "Join", "(", "formattedConditions", ",", "\"", "\"", ")", "\n", "}" ]
// FormatAppConditions returns string representation of give app condition list
[ "FormatAppConditions", "returns", "string", "representation", "of", "give", "app", "condition", "list" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/argo/argo.go#L41-L47
161,705
argoproj/argo-cd
util/argo/argo.go
FilterByProjects
func FilterByProjects(apps []argoappv1.Application, projects []string) []argoappv1.Application { if len(projects) == 0 { return apps } projectsMap := make(map[string]bool) for i := range projects { projectsMap[projects[i]] = true } items := make([]argoappv1.Application, 0) for i := 0; i < len(apps); i++ { a := apps[i] if _, ok := projectsMap[a.Spec.GetProject()]; ok { items = append(items, a) } } return items }
go
func FilterByProjects(apps []argoappv1.Application, projects []string) []argoappv1.Application { if len(projects) == 0 { return apps } projectsMap := make(map[string]bool) for i := range projects { projectsMap[projects[i]] = true } items := make([]argoappv1.Application, 0) for i := 0; i < len(apps); i++ { a := apps[i] if _, ok := projectsMap[a.Spec.GetProject()]; ok { items = append(items, a) } } return items }
[ "func", "FilterByProjects", "(", "apps", "[", "]", "argoappv1", ".", "Application", ",", "projects", "[", "]", "string", ")", "[", "]", "argoappv1", ".", "Application", "{", "if", "len", "(", "projects", ")", "==", "0", "{", "return", "apps", "\n", "}", "\n", "projectsMap", ":=", "make", "(", "map", "[", "string", "]", "bool", ")", "\n", "for", "i", ":=", "range", "projects", "{", "projectsMap", "[", "projects", "[", "i", "]", "]", "=", "true", "\n", "}", "\n", "items", ":=", "make", "(", "[", "]", "argoappv1", ".", "Application", ",", "0", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "apps", ")", ";", "i", "++", "{", "a", ":=", "apps", "[", "i", "]", "\n", "if", "_", ",", "ok", ":=", "projectsMap", "[", "a", ".", "Spec", ".", "GetProject", "(", ")", "]", ";", "ok", "{", "items", "=", "append", "(", "items", ",", "a", ")", "\n", "}", "\n", "}", "\n", "return", "items", "\n\n", "}" ]
// FilterByProjects returns applications which belongs to the specified project
[ "FilterByProjects", "returns", "applications", "which", "belongs", "to", "the", "specified", "project" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/argo/argo.go#L50-L67
161,706
argoproj/argo-cd
util/argo/argo.go
RefreshApp
func RefreshApp(appIf v1alpha1.ApplicationInterface, name string, refreshType argoappv1.RefreshType) (*argoappv1.Application, error) { metadata := map[string]interface{}{ "metadata": map[string]interface{}{ "annotations": map[string]string{ common.AnnotationKeyRefresh: string(refreshType), }, }, } var err error patch, err := json.Marshal(metadata) if err != nil { return nil, err } for attempt := 0; attempt < 5; attempt++ { app, err := appIf.Patch(name, types.MergePatchType, patch) if err != nil { if !apierr.IsConflict(err) { return nil, err } } else { log.Infof("Requested app '%s' refresh", name) return app, nil } time.Sleep(100 * time.Millisecond) } return nil, err }
go
func RefreshApp(appIf v1alpha1.ApplicationInterface, name string, refreshType argoappv1.RefreshType) (*argoappv1.Application, error) { metadata := map[string]interface{}{ "metadata": map[string]interface{}{ "annotations": map[string]string{ common.AnnotationKeyRefresh: string(refreshType), }, }, } var err error patch, err := json.Marshal(metadata) if err != nil { return nil, err } for attempt := 0; attempt < 5; attempt++ { app, err := appIf.Patch(name, types.MergePatchType, patch) if err != nil { if !apierr.IsConflict(err) { return nil, err } } else { log.Infof("Requested app '%s' refresh", name) return app, nil } time.Sleep(100 * time.Millisecond) } return nil, err }
[ "func", "RefreshApp", "(", "appIf", "v1alpha1", ".", "ApplicationInterface", ",", "name", "string", ",", "refreshType", "argoappv1", ".", "RefreshType", ")", "(", "*", "argoappv1", ".", "Application", ",", "error", ")", "{", "metadata", ":=", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "map", "[", "string", "]", "string", "{", "common", ".", "AnnotationKeyRefresh", ":", "string", "(", "refreshType", ")", ",", "}", ",", "}", ",", "}", "\n", "var", "err", "error", "\n", "patch", ",", "err", ":=", "json", ".", "Marshal", "(", "metadata", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "for", "attempt", ":=", "0", ";", "attempt", "<", "5", ";", "attempt", "++", "{", "app", ",", "err", ":=", "appIf", ".", "Patch", "(", "name", ",", "types", ".", "MergePatchType", ",", "patch", ")", "\n", "if", "err", "!=", "nil", "{", "if", "!", "apierr", ".", "IsConflict", "(", "err", ")", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "else", "{", "log", ".", "Infof", "(", "\"", "\"", ",", "name", ")", "\n", "return", "app", ",", "nil", "\n", "}", "\n", "time", ".", "Sleep", "(", "100", "*", "time", ".", "Millisecond", ")", "\n", "}", "\n", "return", "nil", ",", "err", "\n", "}" ]
// RefreshApp updates the refresh annotation of an application to coerce the controller to process it
[ "RefreshApp", "updates", "the", "refresh", "annotation", "of", "an", "application", "to", "coerce", "the", "controller", "to", "process", "it" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/argo/argo.go#L70-L96
161,707
argoproj/argo-cd
util/argo/argo.go
WaitForRefresh
func WaitForRefresh(ctx context.Context, appIf v1alpha1.ApplicationInterface, name string, timeout *time.Duration) (*argoappv1.Application, error) { var cancel context.CancelFunc if timeout != nil { ctx, cancel = context.WithTimeout(ctx, *timeout) defer cancel() } ch := kube.WatchWithRetry(ctx, func() (i watch.Interface, e error) { fieldSelector := fields.ParseSelectorOrDie(fmt.Sprintf("metadata.name=%s", name)) listOpts := metav1.ListOptions{FieldSelector: fieldSelector.String()} return appIf.Watch(listOpts) }) for next := range ch { if next.Error != nil { return nil, next.Error } app, ok := next.Object.(*argoappv1.Application) if !ok { return nil, fmt.Errorf("Application event object failed conversion: %v", next) } annotations := app.GetAnnotations() if annotations == nil { annotations = make(map[string]string) } if _, ok := annotations[common.AnnotationKeyRefresh]; !ok { return app, nil } } return nil, fmt.Errorf("application refresh deadline exceeded") }
go
func WaitForRefresh(ctx context.Context, appIf v1alpha1.ApplicationInterface, name string, timeout *time.Duration) (*argoappv1.Application, error) { var cancel context.CancelFunc if timeout != nil { ctx, cancel = context.WithTimeout(ctx, *timeout) defer cancel() } ch := kube.WatchWithRetry(ctx, func() (i watch.Interface, e error) { fieldSelector := fields.ParseSelectorOrDie(fmt.Sprintf("metadata.name=%s", name)) listOpts := metav1.ListOptions{FieldSelector: fieldSelector.String()} return appIf.Watch(listOpts) }) for next := range ch { if next.Error != nil { return nil, next.Error } app, ok := next.Object.(*argoappv1.Application) if !ok { return nil, fmt.Errorf("Application event object failed conversion: %v", next) } annotations := app.GetAnnotations() if annotations == nil { annotations = make(map[string]string) } if _, ok := annotations[common.AnnotationKeyRefresh]; !ok { return app, nil } } return nil, fmt.Errorf("application refresh deadline exceeded") }
[ "func", "WaitForRefresh", "(", "ctx", "context", ".", "Context", ",", "appIf", "v1alpha1", ".", "ApplicationInterface", ",", "name", "string", ",", "timeout", "*", "time", ".", "Duration", ")", "(", "*", "argoappv1", ".", "Application", ",", "error", ")", "{", "var", "cancel", "context", ".", "CancelFunc", "\n", "if", "timeout", "!=", "nil", "{", "ctx", ",", "cancel", "=", "context", ".", "WithTimeout", "(", "ctx", ",", "*", "timeout", ")", "\n", "defer", "cancel", "(", ")", "\n", "}", "\n", "ch", ":=", "kube", ".", "WatchWithRetry", "(", "ctx", ",", "func", "(", ")", "(", "i", "watch", ".", "Interface", ",", "e", "error", ")", "{", "fieldSelector", ":=", "fields", ".", "ParseSelectorOrDie", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "name", ")", ")", "\n", "listOpts", ":=", "metav1", ".", "ListOptions", "{", "FieldSelector", ":", "fieldSelector", ".", "String", "(", ")", "}", "\n", "return", "appIf", ".", "Watch", "(", "listOpts", ")", "\n", "}", ")", "\n", "for", "next", ":=", "range", "ch", "{", "if", "next", ".", "Error", "!=", "nil", "{", "return", "nil", ",", "next", ".", "Error", "\n", "}", "\n", "app", ",", "ok", ":=", "next", ".", "Object", ".", "(", "*", "argoappv1", ".", "Application", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "next", ")", "\n", "}", "\n", "annotations", ":=", "app", ".", "GetAnnotations", "(", ")", "\n", "if", "annotations", "==", "nil", "{", "annotations", "=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "}", "\n", "if", "_", ",", "ok", ":=", "annotations", "[", "common", ".", "AnnotationKeyRefresh", "]", ";", "!", "ok", "{", "return", "app", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}" ]
// WaitForRefresh watches an application until its comparison timestamp is after the refresh timestamp // If refresh timestamp is not present, will use current timestamp at time of call
[ "WaitForRefresh", "watches", "an", "application", "until", "its", "comparison", "timestamp", "is", "after", "the", "refresh", "timestamp", "If", "refresh", "timestamp", "is", "not", "present", "will", "use", "current", "timestamp", "at", "time", "of", "call" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/argo/argo.go#L100-L128
161,708
argoproj/argo-cd
util/argo/argo.go
GetAppProject
func GetAppProject(spec *argoappv1.ApplicationSpec, projLister applicationsv1.AppProjectLister, ns string) (*argoappv1.AppProject, error) { return projLister.AppProjects(ns).Get(spec.GetProject()) }
go
func GetAppProject(spec *argoappv1.ApplicationSpec, projLister applicationsv1.AppProjectLister, ns string) (*argoappv1.AppProject, error) { return projLister.AppProjects(ns).Get(spec.GetProject()) }
[ "func", "GetAppProject", "(", "spec", "*", "argoappv1", ".", "ApplicationSpec", ",", "projLister", "applicationsv1", ".", "AppProjectLister", ",", "ns", "string", ")", "(", "*", "argoappv1", ".", "AppProject", ",", "error", ")", "{", "return", "projLister", ".", "AppProjects", "(", "ns", ")", ".", "Get", "(", "spec", ".", "GetProject", "(", ")", ")", "\n", "}" ]
// GetAppProject returns a project from an application
[ "GetAppProject", "returns", "a", "project", "from", "an", "application" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/argo/argo.go#L258-L260
161,709
argoproj/argo-cd
util/argo/argo.go
verifyAppYAML
func verifyAppYAML(ctx context.Context, repoRes *argoappv1.Repository, spec *argoappv1.ApplicationSpec, repoClient repository.RepoServerServiceClient) error { // Default revision to HEAD if unspecified if spec.Source.TargetRevision == "" { spec.Source.TargetRevision = "HEAD" } req := repository.GetFileRequest{ Repo: &argoappv1.Repository{ Repo: spec.Source.RepoURL, }, Revision: spec.Source.TargetRevision, Path: path.Join(spec.Source.Path, "app.yaml"), } if repoRes != nil { req.Repo.Username = repoRes.Username req.Repo.Password = repoRes.Password req.Repo.SSHPrivateKey = repoRes.SSHPrivateKey } getRes, err := repoClient.GetFile(ctx, &req) if err != nil { return fmt.Errorf("Unable to load app.yaml: %v", err) } // Verify the specified environment is defined in the app spec if spec.Source.Ksonnet == nil { return fmt.Errorf("Ksonnet environment not specified") } dest, err := ksonnet.Destination(getRes.Data, spec.Source.Ksonnet.Environment) if err != nil { return err } // If server and namespace are not supplied, pull it from the app.yaml if spec.Destination.Server == "" { spec.Destination.Server = dest.Server } if spec.Destination.Namespace == "" { spec.Destination.Namespace = dest.Namespace } return nil }
go
func verifyAppYAML(ctx context.Context, repoRes *argoappv1.Repository, spec *argoappv1.ApplicationSpec, repoClient repository.RepoServerServiceClient) error { // Default revision to HEAD if unspecified if spec.Source.TargetRevision == "" { spec.Source.TargetRevision = "HEAD" } req := repository.GetFileRequest{ Repo: &argoappv1.Repository{ Repo: spec.Source.RepoURL, }, Revision: spec.Source.TargetRevision, Path: path.Join(spec.Source.Path, "app.yaml"), } if repoRes != nil { req.Repo.Username = repoRes.Username req.Repo.Password = repoRes.Password req.Repo.SSHPrivateKey = repoRes.SSHPrivateKey } getRes, err := repoClient.GetFile(ctx, &req) if err != nil { return fmt.Errorf("Unable to load app.yaml: %v", err) } // Verify the specified environment is defined in the app spec if spec.Source.Ksonnet == nil { return fmt.Errorf("Ksonnet environment not specified") } dest, err := ksonnet.Destination(getRes.Data, spec.Source.Ksonnet.Environment) if err != nil { return err } // If server and namespace are not supplied, pull it from the app.yaml if spec.Destination.Server == "" { spec.Destination.Server = dest.Server } if spec.Destination.Namespace == "" { spec.Destination.Namespace = dest.Namespace } return nil }
[ "func", "verifyAppYAML", "(", "ctx", "context", ".", "Context", ",", "repoRes", "*", "argoappv1", ".", "Repository", ",", "spec", "*", "argoappv1", ".", "ApplicationSpec", ",", "repoClient", "repository", ".", "RepoServerServiceClient", ")", "error", "{", "// Default revision to HEAD if unspecified", "if", "spec", ".", "Source", ".", "TargetRevision", "==", "\"", "\"", "{", "spec", ".", "Source", ".", "TargetRevision", "=", "\"", "\"", "\n", "}", "\n\n", "req", ":=", "repository", ".", "GetFileRequest", "{", "Repo", ":", "&", "argoappv1", ".", "Repository", "{", "Repo", ":", "spec", ".", "Source", ".", "RepoURL", ",", "}", ",", "Revision", ":", "spec", ".", "Source", ".", "TargetRevision", ",", "Path", ":", "path", ".", "Join", "(", "spec", ".", "Source", ".", "Path", ",", "\"", "\"", ")", ",", "}", "\n", "if", "repoRes", "!=", "nil", "{", "req", ".", "Repo", ".", "Username", "=", "repoRes", ".", "Username", "\n", "req", ".", "Repo", ".", "Password", "=", "repoRes", ".", "Password", "\n", "req", ".", "Repo", ".", "SSHPrivateKey", "=", "repoRes", ".", "SSHPrivateKey", "\n", "}", "\n", "getRes", ",", "err", ":=", "repoClient", ".", "GetFile", "(", "ctx", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// Verify the specified environment is defined in the app spec", "if", "spec", ".", "Source", ".", "Ksonnet", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "dest", ",", "err", ":=", "ksonnet", ".", "Destination", "(", "getRes", ".", "Data", ",", "spec", ".", "Source", ".", "Ksonnet", ".", "Environment", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// If server and namespace are not supplied, pull it from the app.yaml", "if", "spec", ".", "Destination", ".", "Server", "==", "\"", "\"", "{", "spec", ".", "Destination", ".", "Server", "=", "dest", ".", "Server", "\n", "}", "\n", "if", "spec", ".", "Destination", ".", "Namespace", "==", "\"", "\"", "{", "spec", ".", "Destination", ".", "Namespace", "=", "dest", ".", "Namespace", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// verifyAppYAML verifies that a ksonnet app.yaml is functional
[ "verifyAppYAML", "verifies", "that", "a", "ksonnet", "app", ".", "yaml", "is", "functional" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/argo/argo.go#L297-L339
161,710
argoproj/argo-cd
util/argo/argo.go
verifyHelmChart
func verifyHelmChart(ctx context.Context, repoRes *argoappv1.Repository, spec *argoappv1.ApplicationSpec, repoClient repository.RepoServerServiceClient) []argoappv1.ApplicationCondition { var conditions []argoappv1.ApplicationCondition if spec.Destination.Server == "" || spec.Destination.Namespace == "" { conditions = append(conditions, argoappv1.ApplicationCondition{ Type: argoappv1.ApplicationConditionInvalidSpecError, Message: errDestinationMissing, }) } req := repository.GetFileRequest{ Repo: &argoappv1.Repository{ Repo: spec.Source.RepoURL, }, Revision: spec.Source.TargetRevision, Path: path.Join(spec.Source.Path, "Chart.yaml"), } if repoRes != nil { req.Repo.Username = repoRes.Username req.Repo.Password = repoRes.Password req.Repo.SSHPrivateKey = repoRes.SSHPrivateKey } _, err := repoClient.GetFile(ctx, &req) if err != nil { conditions = append(conditions, argoappv1.ApplicationCondition{ Type: argoappv1.ApplicationConditionInvalidSpecError, Message: fmt.Sprintf("Unable to load Chart.yaml: %v", err), }) } return conditions }
go
func verifyHelmChart(ctx context.Context, repoRes *argoappv1.Repository, spec *argoappv1.ApplicationSpec, repoClient repository.RepoServerServiceClient) []argoappv1.ApplicationCondition { var conditions []argoappv1.ApplicationCondition if spec.Destination.Server == "" || spec.Destination.Namespace == "" { conditions = append(conditions, argoappv1.ApplicationCondition{ Type: argoappv1.ApplicationConditionInvalidSpecError, Message: errDestinationMissing, }) } req := repository.GetFileRequest{ Repo: &argoappv1.Repository{ Repo: spec.Source.RepoURL, }, Revision: spec.Source.TargetRevision, Path: path.Join(spec.Source.Path, "Chart.yaml"), } if repoRes != nil { req.Repo.Username = repoRes.Username req.Repo.Password = repoRes.Password req.Repo.SSHPrivateKey = repoRes.SSHPrivateKey } _, err := repoClient.GetFile(ctx, &req) if err != nil { conditions = append(conditions, argoappv1.ApplicationCondition{ Type: argoappv1.ApplicationConditionInvalidSpecError, Message: fmt.Sprintf("Unable to load Chart.yaml: %v", err), }) } return conditions }
[ "func", "verifyHelmChart", "(", "ctx", "context", ".", "Context", ",", "repoRes", "*", "argoappv1", ".", "Repository", ",", "spec", "*", "argoappv1", ".", "ApplicationSpec", ",", "repoClient", "repository", ".", "RepoServerServiceClient", ")", "[", "]", "argoappv1", ".", "ApplicationCondition", "{", "var", "conditions", "[", "]", "argoappv1", ".", "ApplicationCondition", "\n", "if", "spec", ".", "Destination", ".", "Server", "==", "\"", "\"", "||", "spec", ".", "Destination", ".", "Namespace", "==", "\"", "\"", "{", "conditions", "=", "append", "(", "conditions", ",", "argoappv1", ".", "ApplicationCondition", "{", "Type", ":", "argoappv1", ".", "ApplicationConditionInvalidSpecError", ",", "Message", ":", "errDestinationMissing", ",", "}", ")", "\n", "}", "\n", "req", ":=", "repository", ".", "GetFileRequest", "{", "Repo", ":", "&", "argoappv1", ".", "Repository", "{", "Repo", ":", "spec", ".", "Source", ".", "RepoURL", ",", "}", ",", "Revision", ":", "spec", ".", "Source", ".", "TargetRevision", ",", "Path", ":", "path", ".", "Join", "(", "spec", ".", "Source", ".", "Path", ",", "\"", "\"", ")", ",", "}", "\n", "if", "repoRes", "!=", "nil", "{", "req", ".", "Repo", ".", "Username", "=", "repoRes", ".", "Username", "\n", "req", ".", "Repo", ".", "Password", "=", "repoRes", ".", "Password", "\n", "req", ".", "Repo", ".", "SSHPrivateKey", "=", "repoRes", ".", "SSHPrivateKey", "\n", "}", "\n", "_", ",", "err", ":=", "repoClient", ".", "GetFile", "(", "ctx", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "conditions", "=", "append", "(", "conditions", ",", "argoappv1", ".", "ApplicationCondition", "{", "Type", ":", "argoappv1", ".", "ApplicationConditionInvalidSpecError", ",", "Message", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "err", ")", ",", "}", ")", "\n", "}", "\n", "return", "conditions", "\n", "}" ]
// verifyHelmChart verifies a helm chart is functional // verifyHelmChart verifies a helm chart is functional
[ "verifyHelmChart", "verifies", "a", "helm", "chart", "is", "functional", "verifyHelmChart", "verifies", "a", "helm", "chart", "is", "functional" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/argo/argo.go#L343-L371
161,711
argoproj/argo-cd
util/argo/argo.go
verifyGenerateManifests
func verifyGenerateManifests( ctx context.Context, repoRes *argoappv1.Repository, helmRepos []*argoappv1.HelmRepository, spec *argoappv1.ApplicationSpec, repoClient repository.RepoServerServiceClient) []argoappv1.ApplicationCondition { var conditions []argoappv1.ApplicationCondition if spec.Destination.Server == "" || spec.Destination.Namespace == "" { conditions = append(conditions, argoappv1.ApplicationCondition{ Type: argoappv1.ApplicationConditionInvalidSpecError, Message: errDestinationMissing, }) } req := repository.ManifestRequest{ Repo: &argoappv1.Repository{ Repo: spec.Source.RepoURL, }, HelmRepos: helmRepos, Revision: spec.Source.TargetRevision, Namespace: spec.Destination.Namespace, ApplicationSource: &spec.Source, } if repoRes != nil { req.Repo.Username = repoRes.Username req.Repo.Password = repoRes.Password req.Repo.SSHPrivateKey = repoRes.SSHPrivateKey } // Only check whether we can access the application's path, // and not whether it actually contains any manifests. _, err := repoClient.GenerateManifest(ctx, &req) if err != nil { conditions = append(conditions, argoappv1.ApplicationCondition{ Type: argoappv1.ApplicationConditionInvalidSpecError, Message: fmt.Sprintf("Unable to generate manifests in %s: %v", spec.Source.Path, err), }) } return conditions }
go
func verifyGenerateManifests( ctx context.Context, repoRes *argoappv1.Repository, helmRepos []*argoappv1.HelmRepository, spec *argoappv1.ApplicationSpec, repoClient repository.RepoServerServiceClient) []argoappv1.ApplicationCondition { var conditions []argoappv1.ApplicationCondition if spec.Destination.Server == "" || spec.Destination.Namespace == "" { conditions = append(conditions, argoappv1.ApplicationCondition{ Type: argoappv1.ApplicationConditionInvalidSpecError, Message: errDestinationMissing, }) } req := repository.ManifestRequest{ Repo: &argoappv1.Repository{ Repo: spec.Source.RepoURL, }, HelmRepos: helmRepos, Revision: spec.Source.TargetRevision, Namespace: spec.Destination.Namespace, ApplicationSource: &spec.Source, } if repoRes != nil { req.Repo.Username = repoRes.Username req.Repo.Password = repoRes.Password req.Repo.SSHPrivateKey = repoRes.SSHPrivateKey } // Only check whether we can access the application's path, // and not whether it actually contains any manifests. _, err := repoClient.GenerateManifest(ctx, &req) if err != nil { conditions = append(conditions, argoappv1.ApplicationCondition{ Type: argoappv1.ApplicationConditionInvalidSpecError, Message: fmt.Sprintf("Unable to generate manifests in %s: %v", spec.Source.Path, err), }) } return conditions }
[ "func", "verifyGenerateManifests", "(", "ctx", "context", ".", "Context", ",", "repoRes", "*", "argoappv1", ".", "Repository", ",", "helmRepos", "[", "]", "*", "argoappv1", ".", "HelmRepository", ",", "spec", "*", "argoappv1", ".", "ApplicationSpec", ",", "repoClient", "repository", ".", "RepoServerServiceClient", ")", "[", "]", "argoappv1", ".", "ApplicationCondition", "{", "var", "conditions", "[", "]", "argoappv1", ".", "ApplicationCondition", "\n", "if", "spec", ".", "Destination", ".", "Server", "==", "\"", "\"", "||", "spec", ".", "Destination", ".", "Namespace", "==", "\"", "\"", "{", "conditions", "=", "append", "(", "conditions", ",", "argoappv1", ".", "ApplicationCondition", "{", "Type", ":", "argoappv1", ".", "ApplicationConditionInvalidSpecError", ",", "Message", ":", "errDestinationMissing", ",", "}", ")", "\n", "}", "\n", "req", ":=", "repository", ".", "ManifestRequest", "{", "Repo", ":", "&", "argoappv1", ".", "Repository", "{", "Repo", ":", "spec", ".", "Source", ".", "RepoURL", ",", "}", ",", "HelmRepos", ":", "helmRepos", ",", "Revision", ":", "spec", ".", "Source", ".", "TargetRevision", ",", "Namespace", ":", "spec", ".", "Destination", ".", "Namespace", ",", "ApplicationSource", ":", "&", "spec", ".", "Source", ",", "}", "\n", "if", "repoRes", "!=", "nil", "{", "req", ".", "Repo", ".", "Username", "=", "repoRes", ".", "Username", "\n", "req", ".", "Repo", ".", "Password", "=", "repoRes", ".", "Password", "\n", "req", ".", "Repo", ".", "SSHPrivateKey", "=", "repoRes", ".", "SSHPrivateKey", "\n", "}", "\n\n", "// Only check whether we can access the application's path,", "// and not whether it actually contains any manifests.", "_", ",", "err", ":=", "repoClient", ".", "GenerateManifest", "(", "ctx", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "conditions", "=", "append", "(", "conditions", ",", "argoappv1", ".", "ApplicationCondition", "{", "Type", ":", "argoappv1", ".", "ApplicationConditionInvalidSpecError", ",", "Message", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "spec", ".", "Source", ".", "Path", ",", "err", ")", ",", "}", ")", "\n", "}", "\n\n", "return", "conditions", "\n", "}" ]
// verifyGenerateManifests verifies a repo path can generate manifests
[ "verifyGenerateManifests", "verifies", "a", "repo", "path", "can", "generate", "manifests" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/argo/argo.go#L374-L410
161,712
argoproj/argo-cd
util/argo/argo.go
SetAppOperation
func SetAppOperation(appIf v1alpha1.ApplicationInterface, appName string, op *argoappv1.Operation) (*argoappv1.Application, error) { for { a, err := appIf.Get(appName, metav1.GetOptions{}) if err != nil { return nil, err } if a.Operation != nil { return nil, status.Errorf(codes.FailedPrecondition, "another operation is already in progress") } a.Operation = op a.Status.OperationState = nil a, err = appIf.Update(a) if op.Sync == nil { return nil, status.Errorf(codes.InvalidArgument, "Operation unspecified") } if err == nil { return a, nil } if !apierr.IsConflict(err) { return nil, err } log.Warnf("Failed to set operation for app '%s' due to update conflict. Retrying again...", appName) } }
go
func SetAppOperation(appIf v1alpha1.ApplicationInterface, appName string, op *argoappv1.Operation) (*argoappv1.Application, error) { for { a, err := appIf.Get(appName, metav1.GetOptions{}) if err != nil { return nil, err } if a.Operation != nil { return nil, status.Errorf(codes.FailedPrecondition, "another operation is already in progress") } a.Operation = op a.Status.OperationState = nil a, err = appIf.Update(a) if op.Sync == nil { return nil, status.Errorf(codes.InvalidArgument, "Operation unspecified") } if err == nil { return a, nil } if !apierr.IsConflict(err) { return nil, err } log.Warnf("Failed to set operation for app '%s' due to update conflict. Retrying again...", appName) } }
[ "func", "SetAppOperation", "(", "appIf", "v1alpha1", ".", "ApplicationInterface", ",", "appName", "string", ",", "op", "*", "argoappv1", ".", "Operation", ")", "(", "*", "argoappv1", ".", "Application", ",", "error", ")", "{", "for", "{", "a", ",", "err", ":=", "appIf", ".", "Get", "(", "appName", ",", "metav1", ".", "GetOptions", "{", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "a", ".", "Operation", "!=", "nil", "{", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "FailedPrecondition", ",", "\"", "\"", ")", "\n", "}", "\n", "a", ".", "Operation", "=", "op", "\n", "a", ".", "Status", ".", "OperationState", "=", "nil", "\n", "a", ",", "err", "=", "appIf", ".", "Update", "(", "a", ")", "\n", "if", "op", ".", "Sync", "==", "nil", "{", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "InvalidArgument", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "err", "==", "nil", "{", "return", "a", ",", "nil", "\n", "}", "\n", "if", "!", "apierr", ".", "IsConflict", "(", "err", ")", "{", "return", "nil", ",", "err", "\n", "}", "\n", "log", ".", "Warnf", "(", "\"", "\"", ",", "appName", ")", "\n", "}", "\n", "}" ]
// SetAppOperation updates an application with the specified operation, retrying conflict errors
[ "SetAppOperation", "updates", "an", "application", "with", "the", "specified", "operation", "retrying", "conflict", "errors" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/argo/argo.go#L413-L436
161,713
argoproj/argo-cd
util/argo/argo.go
ContainsSyncResource
func ContainsSyncResource(name string, gvk schema.GroupVersionKind, rr []argoappv1.SyncOperationResource) bool { for _, r := range rr { if r.HasIdentity(name, gvk) { return true } } return false }
go
func ContainsSyncResource(name string, gvk schema.GroupVersionKind, rr []argoappv1.SyncOperationResource) bool { for _, r := range rr { if r.HasIdentity(name, gvk) { return true } } return false }
[ "func", "ContainsSyncResource", "(", "name", "string", ",", "gvk", "schema", ".", "GroupVersionKind", ",", "rr", "[", "]", "argoappv1", ".", "SyncOperationResource", ")", "bool", "{", "for", "_", ",", "r", ":=", "range", "rr", "{", "if", "r", ".", "HasIdentity", "(", "name", ",", "gvk", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// ContainsSyncResource determines if the given resource exists in the provided slice of sync operation resources.
[ "ContainsSyncResource", "determines", "if", "the", "given", "resource", "exists", "in", "the", "provided", "slice", "of", "sync", "operation", "resources", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/argo/argo.go#L439-L446
161,714
argoproj/argo-cd
pkg/client/clientset/versioned/typed/application/v1alpha1/fake/fake_appproject.go
Get
func (c *FakeAppProjects) Get(name string, options v1.GetOptions) (result *v1alpha1.AppProject, err error) { obj, err := c.Fake. Invokes(testing.NewGetAction(appprojectsResource, c.ns, name), &v1alpha1.AppProject{}) if obj == nil { return nil, err } return obj.(*v1alpha1.AppProject), err }
go
func (c *FakeAppProjects) Get(name string, options v1.GetOptions) (result *v1alpha1.AppProject, err error) { obj, err := c.Fake. Invokes(testing.NewGetAction(appprojectsResource, c.ns, name), &v1alpha1.AppProject{}) if obj == nil { return nil, err } return obj.(*v1alpha1.AppProject), err }
[ "func", "(", "c", "*", "FakeAppProjects", ")", "Get", "(", "name", "string", ",", "options", "v1", ".", "GetOptions", ")", "(", "result", "*", "v1alpha1", ".", "AppProject", ",", "err", "error", ")", "{", "obj", ",", "err", ":=", "c", ".", "Fake", ".", "Invokes", "(", "testing", ".", "NewGetAction", "(", "appprojectsResource", ",", "c", ".", "ns", ",", "name", ")", ",", "&", "v1alpha1", ".", "AppProject", "{", "}", ")", "\n\n", "if", "obj", "==", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "obj", ".", "(", "*", "v1alpha1", ".", "AppProject", ")", ",", "err", "\n", "}" ]
// Get takes name of the appProject, and returns the corresponding appProject object, and an error if there is any.
[ "Get", "takes", "name", "of", "the", "appProject", "and", "returns", "the", "corresponding", "appProject", "object", "and", "an", "error", "if", "there", "is", "any", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/pkg/client/clientset/versioned/typed/application/v1alpha1/fake/fake_appproject.go#L26-L34
161,715
argoproj/argo-cd
pkg/client/clientset/versioned/typed/application/v1alpha1/fake/fake_appproject.go
List
func (c *FakeAppProjects) List(opts v1.ListOptions) (result *v1alpha1.AppProjectList, err error) { obj, err := c.Fake. Invokes(testing.NewListAction(appprojectsResource, appprojectsKind, c.ns, opts), &v1alpha1.AppProjectList{}) if obj == nil { return nil, err } label, _, _ := testing.ExtractFromListOptions(opts) if label == nil { label = labels.Everything() } list := &v1alpha1.AppProjectList{ListMeta: obj.(*v1alpha1.AppProjectList).ListMeta} for _, item := range obj.(*v1alpha1.AppProjectList).Items { if label.Matches(labels.Set(item.Labels)) { list.Items = append(list.Items, item) } } return list, err }
go
func (c *FakeAppProjects) List(opts v1.ListOptions) (result *v1alpha1.AppProjectList, err error) { obj, err := c.Fake. Invokes(testing.NewListAction(appprojectsResource, appprojectsKind, c.ns, opts), &v1alpha1.AppProjectList{}) if obj == nil { return nil, err } label, _, _ := testing.ExtractFromListOptions(opts) if label == nil { label = labels.Everything() } list := &v1alpha1.AppProjectList{ListMeta: obj.(*v1alpha1.AppProjectList).ListMeta} for _, item := range obj.(*v1alpha1.AppProjectList).Items { if label.Matches(labels.Set(item.Labels)) { list.Items = append(list.Items, item) } } return list, err }
[ "func", "(", "c", "*", "FakeAppProjects", ")", "List", "(", "opts", "v1", ".", "ListOptions", ")", "(", "result", "*", "v1alpha1", ".", "AppProjectList", ",", "err", "error", ")", "{", "obj", ",", "err", ":=", "c", ".", "Fake", ".", "Invokes", "(", "testing", ".", "NewListAction", "(", "appprojectsResource", ",", "appprojectsKind", ",", "c", ".", "ns", ",", "opts", ")", ",", "&", "v1alpha1", ".", "AppProjectList", "{", "}", ")", "\n\n", "if", "obj", "==", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "label", ",", "_", ",", "_", ":=", "testing", ".", "ExtractFromListOptions", "(", "opts", ")", "\n", "if", "label", "==", "nil", "{", "label", "=", "labels", ".", "Everything", "(", ")", "\n", "}", "\n", "list", ":=", "&", "v1alpha1", ".", "AppProjectList", "{", "ListMeta", ":", "obj", ".", "(", "*", "v1alpha1", ".", "AppProjectList", ")", ".", "ListMeta", "}", "\n", "for", "_", ",", "item", ":=", "range", "obj", ".", "(", "*", "v1alpha1", ".", "AppProjectList", ")", ".", "Items", "{", "if", "label", ".", "Matches", "(", "labels", ".", "Set", "(", "item", ".", "Labels", ")", ")", "{", "list", ".", "Items", "=", "append", "(", "list", ".", "Items", ",", "item", ")", "\n", "}", "\n", "}", "\n", "return", "list", ",", "err", "\n", "}" ]
// List takes label and field selectors, and returns the list of AppProjects that match those selectors.
[ "List", "takes", "label", "and", "field", "selectors", "and", "returns", "the", "list", "of", "AppProjects", "that", "match", "those", "selectors", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/pkg/client/clientset/versioned/typed/application/v1alpha1/fake/fake_appproject.go#L37-L56
161,716
argoproj/argo-cd
pkg/client/clientset/versioned/typed/application/v1alpha1/fake/fake_appproject.go
Watch
func (c *FakeAppProjects) Watch(opts v1.ListOptions) (watch.Interface, error) { return c.Fake. InvokesWatch(testing.NewWatchAction(appprojectsResource, c.ns, opts)) }
go
func (c *FakeAppProjects) Watch(opts v1.ListOptions) (watch.Interface, error) { return c.Fake. InvokesWatch(testing.NewWatchAction(appprojectsResource, c.ns, opts)) }
[ "func", "(", "c", "*", "FakeAppProjects", ")", "Watch", "(", "opts", "v1", ".", "ListOptions", ")", "(", "watch", ".", "Interface", ",", "error", ")", "{", "return", "c", ".", "Fake", ".", "InvokesWatch", "(", "testing", ".", "NewWatchAction", "(", "appprojectsResource", ",", "c", ".", "ns", ",", "opts", ")", ")", "\n\n", "}" ]
// Watch returns a watch.Interface that watches the requested appProjects.
[ "Watch", "returns", "a", "watch", ".", "Interface", "that", "watches", "the", "requested", "appProjects", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/pkg/client/clientset/versioned/typed/application/v1alpha1/fake/fake_appproject.go#L59-L63
161,717
argoproj/argo-cd
pkg/client/clientset/versioned/typed/application/v1alpha1/fake/fake_appproject.go
Delete
func (c *FakeAppProjects) Delete(name string, options *v1.DeleteOptions) error { _, err := c.Fake. Invokes(testing.NewDeleteAction(appprojectsResource, c.ns, name), &v1alpha1.AppProject{}) return err }
go
func (c *FakeAppProjects) Delete(name string, options *v1.DeleteOptions) error { _, err := c.Fake. Invokes(testing.NewDeleteAction(appprojectsResource, c.ns, name), &v1alpha1.AppProject{}) return err }
[ "func", "(", "c", "*", "FakeAppProjects", ")", "Delete", "(", "name", "string", ",", "options", "*", "v1", ".", "DeleteOptions", ")", "error", "{", "_", ",", "err", ":=", "c", ".", "Fake", ".", "Invokes", "(", "testing", ".", "NewDeleteAction", "(", "appprojectsResource", ",", "c", ".", "ns", ",", "name", ")", ",", "&", "v1alpha1", ".", "AppProject", "{", "}", ")", "\n\n", "return", "err", "\n", "}" ]
// Delete takes name of the appProject and deletes it. Returns an error if one occurs.
[ "Delete", "takes", "name", "of", "the", "appProject", "and", "deletes", "it", ".", "Returns", "an", "error", "if", "one", "occurs", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/pkg/client/clientset/versioned/typed/application/v1alpha1/fake/fake_appproject.go#L88-L93
161,718
argoproj/argo-cd
pkg/client/clientset/versioned/typed/application/v1alpha1/fake/fake_appproject.go
Patch
func (c *FakeAppProjects) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.AppProject, err error) { obj, err := c.Fake. Invokes(testing.NewPatchSubresourceAction(appprojectsResource, c.ns, name, data, subresources...), &v1alpha1.AppProject{}) if obj == nil { return nil, err } return obj.(*v1alpha1.AppProject), err }
go
func (c *FakeAppProjects) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.AppProject, err error) { obj, err := c.Fake. Invokes(testing.NewPatchSubresourceAction(appprojectsResource, c.ns, name, data, subresources...), &v1alpha1.AppProject{}) if obj == nil { return nil, err } return obj.(*v1alpha1.AppProject), err }
[ "func", "(", "c", "*", "FakeAppProjects", ")", "Patch", "(", "name", "string", ",", "pt", "types", ".", "PatchType", ",", "data", "[", "]", "byte", ",", "subresources", "...", "string", ")", "(", "result", "*", "v1alpha1", ".", "AppProject", ",", "err", "error", ")", "{", "obj", ",", "err", ":=", "c", ".", "Fake", ".", "Invokes", "(", "testing", ".", "NewPatchSubresourceAction", "(", "appprojectsResource", ",", "c", ".", "ns", ",", "name", ",", "data", ",", "subresources", "...", ")", ",", "&", "v1alpha1", ".", "AppProject", "{", "}", ")", "\n\n", "if", "obj", "==", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "obj", ".", "(", "*", "v1alpha1", ".", "AppProject", ")", ",", "err", "\n", "}" ]
// Patch applies the patch and returns the patched appProject.
[ "Patch", "applies", "the", "patch", "and", "returns", "the", "patched", "appProject", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/pkg/client/clientset/versioned/typed/application/v1alpha1/fake/fake_appproject.go#L104-L112
161,719
argoproj/argo-cd
controller/metrics/metrics.go
NewMetricsServer
func NewMetricsServer(addr string, appLister applister.ApplicationLister) *MetricsServer { mux := http.NewServeMux() appRegistry := NewAppRegistry(appLister) appRegistry.MustRegister(prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{})) appRegistry.MustRegister(prometheus.NewGoCollector()) mux.Handle(MetricsPath, promhttp.HandlerFor(appRegistry, promhttp.HandlerOpts{})) syncCounter := prometheus.NewCounterVec( prometheus.CounterOpts{ Name: "argocd_app_sync_total", Help: "Number of application syncs.", }, append(descAppDefaultLabels, "phase"), ) appRegistry.MustRegister(syncCounter) k8sRequestCounter := prometheus.NewCounterVec( prometheus.CounterOpts{ Name: "argocd_app_k8s_request_total", Help: "Number of kubernetes requests executed during application reconciliation.", }, append(descAppDefaultLabels, "response_code"), ) appRegistry.MustRegister(k8sRequestCounter) reconcileHistogram := prometheus.NewHistogramVec( prometheus.HistogramOpts{ Name: "argocd_app_reconcile", Help: "Application reconciliation performance.", // Buckets chosen after observing a ~2100ms mean reconcile time Buckets: []float64{0.25, .5, 1, 2, 4, 8, 16}, }, append(descAppDefaultLabels), ) appRegistry.MustRegister(reconcileHistogram) return &MetricsServer{ Server: &http.Server{ Addr: addr, Handler: mux, }, syncCounter: syncCounter, k8sRequestCounter: k8sRequestCounter, reconcileHistogram: reconcileHistogram, } }
go
func NewMetricsServer(addr string, appLister applister.ApplicationLister) *MetricsServer { mux := http.NewServeMux() appRegistry := NewAppRegistry(appLister) appRegistry.MustRegister(prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{})) appRegistry.MustRegister(prometheus.NewGoCollector()) mux.Handle(MetricsPath, promhttp.HandlerFor(appRegistry, promhttp.HandlerOpts{})) syncCounter := prometheus.NewCounterVec( prometheus.CounterOpts{ Name: "argocd_app_sync_total", Help: "Number of application syncs.", }, append(descAppDefaultLabels, "phase"), ) appRegistry.MustRegister(syncCounter) k8sRequestCounter := prometheus.NewCounterVec( prometheus.CounterOpts{ Name: "argocd_app_k8s_request_total", Help: "Number of kubernetes requests executed during application reconciliation.", }, append(descAppDefaultLabels, "response_code"), ) appRegistry.MustRegister(k8sRequestCounter) reconcileHistogram := prometheus.NewHistogramVec( prometheus.HistogramOpts{ Name: "argocd_app_reconcile", Help: "Application reconciliation performance.", // Buckets chosen after observing a ~2100ms mean reconcile time Buckets: []float64{0.25, .5, 1, 2, 4, 8, 16}, }, append(descAppDefaultLabels), ) appRegistry.MustRegister(reconcileHistogram) return &MetricsServer{ Server: &http.Server{ Addr: addr, Handler: mux, }, syncCounter: syncCounter, k8sRequestCounter: k8sRequestCounter, reconcileHistogram: reconcileHistogram, } }
[ "func", "NewMetricsServer", "(", "addr", "string", ",", "appLister", "applister", ".", "ApplicationLister", ")", "*", "MetricsServer", "{", "mux", ":=", "http", ".", "NewServeMux", "(", ")", "\n", "appRegistry", ":=", "NewAppRegistry", "(", "appLister", ")", "\n", "appRegistry", ".", "MustRegister", "(", "prometheus", ".", "NewProcessCollector", "(", "prometheus", ".", "ProcessCollectorOpts", "{", "}", ")", ")", "\n", "appRegistry", ".", "MustRegister", "(", "prometheus", ".", "NewGoCollector", "(", ")", ")", "\n", "mux", ".", "Handle", "(", "MetricsPath", ",", "promhttp", ".", "HandlerFor", "(", "appRegistry", ",", "promhttp", ".", "HandlerOpts", "{", "}", ")", ")", "\n\n", "syncCounter", ":=", "prometheus", ".", "NewCounterVec", "(", "prometheus", ".", "CounterOpts", "{", "Name", ":", "\"", "\"", ",", "Help", ":", "\"", "\"", ",", "}", ",", "append", "(", "descAppDefaultLabels", ",", "\"", "\"", ")", ",", ")", "\n", "appRegistry", ".", "MustRegister", "(", "syncCounter", ")", "\n", "k8sRequestCounter", ":=", "prometheus", ".", "NewCounterVec", "(", "prometheus", ".", "CounterOpts", "{", "Name", ":", "\"", "\"", ",", "Help", ":", "\"", "\"", ",", "}", ",", "append", "(", "descAppDefaultLabels", ",", "\"", "\"", ")", ",", ")", "\n", "appRegistry", ".", "MustRegister", "(", "k8sRequestCounter", ")", "\n\n", "reconcileHistogram", ":=", "prometheus", ".", "NewHistogramVec", "(", "prometheus", ".", "HistogramOpts", "{", "Name", ":", "\"", "\"", ",", "Help", ":", "\"", "\"", ",", "// Buckets chosen after observing a ~2100ms mean reconcile time", "Buckets", ":", "[", "]", "float64", "{", "0.25", ",", ".5", ",", "1", ",", "2", ",", "4", ",", "8", ",", "16", "}", ",", "}", ",", "append", "(", "descAppDefaultLabels", ")", ",", ")", "\n\n", "appRegistry", ".", "MustRegister", "(", "reconcileHistogram", ")", "\n\n", "return", "&", "MetricsServer", "{", "Server", ":", "&", "http", ".", "Server", "{", "Addr", ":", "addr", ",", "Handler", ":", "mux", ",", "}", ",", "syncCounter", ":", "syncCounter", ",", "k8sRequestCounter", ":", "k8sRequestCounter", ",", "reconcileHistogram", ":", "reconcileHistogram", ",", "}", "\n", "}" ]
// NewMetricsServer returns a new prometheus server which collects application metrics
[ "NewMetricsServer", "returns", "a", "new", "prometheus", "server", "which", "collects", "application", "metrics" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/controller/metrics/metrics.go#L62-L107
161,720
argoproj/argo-cd
controller/metrics/metrics.go
IncSync
func (m *MetricsServer) IncSync(app *argoappv1.Application, state *argoappv1.OperationState) { if !state.Phase.Completed() { return } m.syncCounter.WithLabelValues(app.Namespace, app.Name, app.Spec.GetProject(), string(state.Phase)).Inc() }
go
func (m *MetricsServer) IncSync(app *argoappv1.Application, state *argoappv1.OperationState) { if !state.Phase.Completed() { return } m.syncCounter.WithLabelValues(app.Namespace, app.Name, app.Spec.GetProject(), string(state.Phase)).Inc() }
[ "func", "(", "m", "*", "MetricsServer", ")", "IncSync", "(", "app", "*", "argoappv1", ".", "Application", ",", "state", "*", "argoappv1", ".", "OperationState", ")", "{", "if", "!", "state", ".", "Phase", ".", "Completed", "(", ")", "{", "return", "\n", "}", "\n", "m", ".", "syncCounter", ".", "WithLabelValues", "(", "app", ".", "Namespace", ",", "app", ".", "Name", ",", "app", ".", "Spec", ".", "GetProject", "(", ")", ",", "string", "(", "state", ".", "Phase", ")", ")", ".", "Inc", "(", ")", "\n", "}" ]
// IncSync increments the sync counter for an application
[ "IncSync", "increments", "the", "sync", "counter", "for", "an", "application" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/controller/metrics/metrics.go#L110-L115
161,721
argoproj/argo-cd
controller/metrics/metrics.go
IncKubernetesRequest
func (m *MetricsServer) IncKubernetesRequest(app *argoappv1.Application, statusCode int) { m.k8sRequestCounter.WithLabelValues(app.Namespace, app.Name, app.Spec.GetProject(), strconv.Itoa(statusCode)).Inc() }
go
func (m *MetricsServer) IncKubernetesRequest(app *argoappv1.Application, statusCode int) { m.k8sRequestCounter.WithLabelValues(app.Namespace, app.Name, app.Spec.GetProject(), strconv.Itoa(statusCode)).Inc() }
[ "func", "(", "m", "*", "MetricsServer", ")", "IncKubernetesRequest", "(", "app", "*", "argoappv1", ".", "Application", ",", "statusCode", "int", ")", "{", "m", ".", "k8sRequestCounter", ".", "WithLabelValues", "(", "app", ".", "Namespace", ",", "app", ".", "Name", ",", "app", ".", "Spec", ".", "GetProject", "(", ")", ",", "strconv", ".", "Itoa", "(", "statusCode", ")", ")", ".", "Inc", "(", ")", "\n", "}" ]
// IncKubernetesRequest increments the kubernetes requests counter for an application
[ "IncKubernetesRequest", "increments", "the", "kubernetes", "requests", "counter", "for", "an", "application" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/controller/metrics/metrics.go#L118-L120
161,722
argoproj/argo-cd
controller/metrics/metrics.go
IncReconcile
func (m *MetricsServer) IncReconcile(app *argoappv1.Application, duration time.Duration) { m.reconcileHistogram.WithLabelValues(app.Namespace, app.Name, app.Spec.GetProject()).Observe(duration.Seconds()) }
go
func (m *MetricsServer) IncReconcile(app *argoappv1.Application, duration time.Duration) { m.reconcileHistogram.WithLabelValues(app.Namespace, app.Name, app.Spec.GetProject()).Observe(duration.Seconds()) }
[ "func", "(", "m", "*", "MetricsServer", ")", "IncReconcile", "(", "app", "*", "argoappv1", ".", "Application", ",", "duration", "time", ".", "Duration", ")", "{", "m", ".", "reconcileHistogram", ".", "WithLabelValues", "(", "app", ".", "Namespace", ",", "app", ".", "Name", ",", "app", ".", "Spec", ".", "GetProject", "(", ")", ")", ".", "Observe", "(", "duration", ".", "Seconds", "(", ")", ")", "\n", "}" ]
// IncReconcile increments the reconcile counter for an application
[ "IncReconcile", "increments", "the", "reconcile", "counter", "for", "an", "application" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/controller/metrics/metrics.go#L123-L125
161,723
argoproj/argo-cd
controller/metrics/metrics.go
NewAppRegistry
func NewAppRegistry(appLister applister.ApplicationLister) *prometheus.Registry { registry := prometheus.NewRegistry() registry.MustRegister(NewAppCollector(appLister)) return registry }
go
func NewAppRegistry(appLister applister.ApplicationLister) *prometheus.Registry { registry := prometheus.NewRegistry() registry.MustRegister(NewAppCollector(appLister)) return registry }
[ "func", "NewAppRegistry", "(", "appLister", "applister", ".", "ApplicationLister", ")", "*", "prometheus", ".", "Registry", "{", "registry", ":=", "prometheus", ".", "NewRegistry", "(", ")", "\n", "registry", ".", "MustRegister", "(", "NewAppCollector", "(", "appLister", ")", ")", "\n", "return", "registry", "\n", "}" ]
// NewAppRegistry creates a new prometheus registry that collects applications
[ "NewAppRegistry", "creates", "a", "new", "prometheus", "registry", "that", "collects", "applications" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/controller/metrics/metrics.go#L139-L143
161,724
argoproj/argo-cd
util/localconfig/localconfig.go
Claims
func (u *User) Claims() (*jwt.StandardClaims, error) { parser := &jwt.Parser{ SkipClaimsValidation: true, } claims := jwt.StandardClaims{} _, _, err := parser.ParseUnverified(u.AuthToken, &claims) if err != nil { return nil, err } return &claims, nil }
go
func (u *User) Claims() (*jwt.StandardClaims, error) { parser := &jwt.Parser{ SkipClaimsValidation: true, } claims := jwt.StandardClaims{} _, _, err := parser.ParseUnverified(u.AuthToken, &claims) if err != nil { return nil, err } return &claims, nil }
[ "func", "(", "u", "*", "User", ")", "Claims", "(", ")", "(", "*", "jwt", ".", "StandardClaims", ",", "error", ")", "{", "parser", ":=", "&", "jwt", ".", "Parser", "{", "SkipClaimsValidation", ":", "true", ",", "}", "\n", "claims", ":=", "jwt", ".", "StandardClaims", "{", "}", "\n", "_", ",", "_", ",", "err", ":=", "parser", ".", "ParseUnverified", "(", "u", ".", "AuthToken", ",", "&", "claims", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "claims", ",", "nil", "\n", "}" ]
// Claims returns the standard claims from the JWT claims
[ "Claims", "returns", "the", "standard", "claims", "from", "the", "JWT", "claims" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/localconfig/localconfig.go#L59-L69
161,725
argoproj/argo-cd
util/localconfig/localconfig.go
ReadLocalConfig
func ReadLocalConfig(path string) (*LocalConfig, error) { var err error var config LocalConfig err = configUtil.UnmarshalLocalFile(path, &config) if os.IsNotExist(err) { return nil, nil } err = ValidateLocalConfig(config) if err != nil { return nil, err } return &config, nil }
go
func ReadLocalConfig(path string) (*LocalConfig, error) { var err error var config LocalConfig err = configUtil.UnmarshalLocalFile(path, &config) if os.IsNotExist(err) { return nil, nil } err = ValidateLocalConfig(config) if err != nil { return nil, err } return &config, nil }
[ "func", "ReadLocalConfig", "(", "path", "string", ")", "(", "*", "LocalConfig", ",", "error", ")", "{", "var", "err", "error", "\n", "var", "config", "LocalConfig", "\n", "err", "=", "configUtil", ".", "UnmarshalLocalFile", "(", "path", ",", "&", "config", ")", "\n", "if", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "nil", ",", "nil", "\n", "}", "\n", "err", "=", "ValidateLocalConfig", "(", "config", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "config", ",", "nil", "\n", "}" ]
// ReadLocalConfig loads up the local configuration file. Returns nil if config does not exist
[ "ReadLocalConfig", "loads", "up", "the", "local", "configuration", "file", ".", "Returns", "nil", "if", "config", "does", "not", "exist" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/localconfig/localconfig.go#L72-L84
161,726
argoproj/argo-cd
util/localconfig/localconfig.go
WriteLocalConfig
func WriteLocalConfig(config LocalConfig, configPath string) error { err := os.MkdirAll(path.Dir(configPath), os.ModePerm) if err != nil { return err } return configUtil.MarshalLocalYAMLFile(configPath, config) }
go
func WriteLocalConfig(config LocalConfig, configPath string) error { err := os.MkdirAll(path.Dir(configPath), os.ModePerm) if err != nil { return err } return configUtil.MarshalLocalYAMLFile(configPath, config) }
[ "func", "WriteLocalConfig", "(", "config", "LocalConfig", ",", "configPath", "string", ")", "error", "{", "err", ":=", "os", ".", "MkdirAll", "(", "path", ".", "Dir", "(", "configPath", ")", ",", "os", ".", "ModePerm", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "configUtil", ".", "MarshalLocalYAMLFile", "(", "configPath", ",", "config", ")", "\n", "}" ]
// WriteLocalConfig writes a new local configuration file.
[ "WriteLocalConfig", "writes", "a", "new", "local", "configuration", "file", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/localconfig/localconfig.go#L97-L103
161,727
argoproj/argo-cd
util/localconfig/localconfig.go
ResolveContext
func (l *LocalConfig) ResolveContext(name string) (*Context, error) { if name == "" { name = l.CurrentContext } for _, ctx := range l.Contexts { if ctx.Name == name { server, err := l.GetServer(ctx.Server) if err != nil { return nil, err } user, err := l.GetUser(ctx.User) if err != nil { return nil, err } return &Context{ Name: ctx.Name, Server: *server, User: *user, }, nil } } return nil, fmt.Errorf("Context '%s' undefined", name) }
go
func (l *LocalConfig) ResolveContext(name string) (*Context, error) { if name == "" { name = l.CurrentContext } for _, ctx := range l.Contexts { if ctx.Name == name { server, err := l.GetServer(ctx.Server) if err != nil { return nil, err } user, err := l.GetUser(ctx.User) if err != nil { return nil, err } return &Context{ Name: ctx.Name, Server: *server, User: *user, }, nil } } return nil, fmt.Errorf("Context '%s' undefined", name) }
[ "func", "(", "l", "*", "LocalConfig", ")", "ResolveContext", "(", "name", "string", ")", "(", "*", "Context", ",", "error", ")", "{", "if", "name", "==", "\"", "\"", "{", "name", "=", "l", ".", "CurrentContext", "\n", "}", "\n", "for", "_", ",", "ctx", ":=", "range", "l", ".", "Contexts", "{", "if", "ctx", ".", "Name", "==", "name", "{", "server", ",", "err", ":=", "l", ".", "GetServer", "(", "ctx", ".", "Server", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "user", ",", "err", ":=", "l", ".", "GetUser", "(", "ctx", ".", "User", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "Context", "{", "Name", ":", "ctx", ".", "Name", ",", "Server", ":", "*", "server", ",", "User", ":", "*", "user", ",", "}", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "name", ")", "\n", "}" ]
// ResolveContext resolves the specified context. If unspecified, resolves the current context
[ "ResolveContext", "resolves", "the", "specified", "context", ".", "If", "unspecified", "resolves", "the", "current", "context" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/localconfig/localconfig.go#L106-L128
161,728
argoproj/argo-cd
util/localconfig/localconfig.go
DefaultConfigDir
func DefaultConfigDir() (string, error) { usr, err := user.Current() if err != nil { return "", err } return path.Join(usr.HomeDir, ".argocd"), nil }
go
func DefaultConfigDir() (string, error) { usr, err := user.Current() if err != nil { return "", err } return path.Join(usr.HomeDir, ".argocd"), nil }
[ "func", "DefaultConfigDir", "(", ")", "(", "string", ",", "error", ")", "{", "usr", ",", "err", ":=", "user", ".", "Current", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "return", "path", ".", "Join", "(", "usr", ".", "HomeDir", ",", "\"", "\"", ")", ",", "nil", "\n", "}" ]
// DefaultConfigDir returns the local configuration path for settings such as cached authentication tokens.
[ "DefaultConfigDir", "returns", "the", "local", "configuration", "path", "for", "settings", "such", "as", "cached", "authentication", "tokens", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/localconfig/localconfig.go#L179-L185
161,729
argoproj/argo-cd
util/localconfig/localconfig.go
DefaultLocalConfigPath
func DefaultLocalConfigPath() (string, error) { dir, err := DefaultConfigDir() if err != nil { return "", err } return path.Join(dir, "config"), nil }
go
func DefaultLocalConfigPath() (string, error) { dir, err := DefaultConfigDir() if err != nil { return "", err } return path.Join(dir, "config"), nil }
[ "func", "DefaultLocalConfigPath", "(", ")", "(", "string", ",", "error", ")", "{", "dir", ",", "err", ":=", "DefaultConfigDir", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "return", "path", ".", "Join", "(", "dir", ",", "\"", "\"", ")", ",", "nil", "\n", "}" ]
// DefaultLocalConfigPath returns the local configuration path for settings such as cached authentication tokens.
[ "DefaultLocalConfigPath", "returns", "the", "local", "configuration", "path", "for", "settings", "such", "as", "cached", "authentication", "tokens", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/localconfig/localconfig.go#L188-L194
161,730
argoproj/argo-cd
util/tls/tls.go
BestEffortSystemCertPool
func BestEffortSystemCertPool() *x509.CertPool { rootCAs, _ := x509.SystemCertPool() if rootCAs == nil { return x509.NewCertPool() } return rootCAs }
go
func BestEffortSystemCertPool() *x509.CertPool { rootCAs, _ := x509.SystemCertPool() if rootCAs == nil { return x509.NewCertPool() } return rootCAs }
[ "func", "BestEffortSystemCertPool", "(", ")", "*", "x509", ".", "CertPool", "{", "rootCAs", ",", "_", ":=", "x509", ".", "SystemCertPool", "(", ")", "\n", "if", "rootCAs", "==", "nil", "{", "return", "x509", ".", "NewCertPool", "(", ")", "\n", "}", "\n", "return", "rootCAs", "\n", "}" ]
// BestEffortSystemCertPool returns system cert pool as best effort, otherwise an empty cert pool
[ "BestEffortSystemCertPool", "returns", "system", "cert", "pool", "as", "best", "effort", "otherwise", "an", "empty", "cert", "pool" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/tls/tls.go#L54-L60
161,731
argoproj/argo-cd
util/tls/tls.go
generatePEM
func generatePEM(opts CertOptions) ([]byte, []byte, error) { certBytes, privateKey, err := generate(opts) if err != nil { return nil, nil, err } certpem := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: certBytes}) keypem := pem.EncodeToMemory(pemBlockForKey(privateKey)) return certpem, keypem, nil }
go
func generatePEM(opts CertOptions) ([]byte, []byte, error) { certBytes, privateKey, err := generate(opts) if err != nil { return nil, nil, err } certpem := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: certBytes}) keypem := pem.EncodeToMemory(pemBlockForKey(privateKey)) return certpem, keypem, nil }
[ "func", "generatePEM", "(", "opts", "CertOptions", ")", "(", "[", "]", "byte", ",", "[", "]", "byte", ",", "error", ")", "{", "certBytes", ",", "privateKey", ",", "err", ":=", "generate", "(", "opts", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "certpem", ":=", "pem", ".", "EncodeToMemory", "(", "&", "pem", ".", "Block", "{", "Type", ":", "\"", "\"", ",", "Bytes", ":", "certBytes", "}", ")", "\n", "keypem", ":=", "pem", ".", "EncodeToMemory", "(", "pemBlockForKey", "(", "privateKey", ")", ")", "\n", "return", "certpem", ",", "keypem", ",", "nil", "\n", "}" ]
// generatePEM generates a new certificate and key and returns it as PEM encoded bytes
[ "generatePEM", "generates", "a", "new", "certificate", "and", "key", "and", "returns", "it", "as", "PEM", "encoded", "bytes" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/tls/tls.go#L205-L213
161,732
argoproj/argo-cd
util/tls/tls.go
GenerateX509KeyPair
func GenerateX509KeyPair(opts CertOptions) (*tls.Certificate, error) { certpem, keypem, err := generatePEM(opts) if err != nil { return nil, err } cert, err := tls.X509KeyPair(certpem, keypem) if err != nil { return nil, err } return &cert, nil }
go
func GenerateX509KeyPair(opts CertOptions) (*tls.Certificate, error) { certpem, keypem, err := generatePEM(opts) if err != nil { return nil, err } cert, err := tls.X509KeyPair(certpem, keypem) if err != nil { return nil, err } return &cert, nil }
[ "func", "GenerateX509KeyPair", "(", "opts", "CertOptions", ")", "(", "*", "tls", ".", "Certificate", ",", "error", ")", "{", "certpem", ",", "keypem", ",", "err", ":=", "generatePEM", "(", "opts", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "cert", ",", "err", ":=", "tls", ".", "X509KeyPair", "(", "certpem", ",", "keypem", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "cert", ",", "nil", "\n", "}" ]
// GenerateX509KeyPair generates a X509 key pair
[ "GenerateX509KeyPair", "generates", "a", "X509", "key", "pair" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/tls/tls.go#L216-L226
161,733
argoproj/argo-cd
util/tls/tls.go
EncodeX509KeyPair
func EncodeX509KeyPair(cert tls.Certificate) ([]byte, []byte) { certpem := []byte{} for _, certtmp := range cert.Certificate { certpem = append(certpem, pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: certtmp})...) } keypem := pem.EncodeToMemory(pemBlockForKey(cert.PrivateKey)) return certpem, keypem }
go
func EncodeX509KeyPair(cert tls.Certificate) ([]byte, []byte) { certpem := []byte{} for _, certtmp := range cert.Certificate { certpem = append(certpem, pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: certtmp})...) } keypem := pem.EncodeToMemory(pemBlockForKey(cert.PrivateKey)) return certpem, keypem }
[ "func", "EncodeX509KeyPair", "(", "cert", "tls", ".", "Certificate", ")", "(", "[", "]", "byte", ",", "[", "]", "byte", ")", "{", "certpem", ":=", "[", "]", "byte", "{", "}", "\n", "for", "_", ",", "certtmp", ":=", "range", "cert", ".", "Certificate", "{", "certpem", "=", "append", "(", "certpem", ",", "pem", ".", "EncodeToMemory", "(", "&", "pem", ".", "Block", "{", "Type", ":", "\"", "\"", ",", "Bytes", ":", "certtmp", "}", ")", "...", ")", "\n", "}", "\n", "keypem", ":=", "pem", ".", "EncodeToMemory", "(", "pemBlockForKey", "(", "cert", ".", "PrivateKey", ")", ")", "\n", "return", "certpem", ",", "keypem", "\n", "}" ]
// EncodeX509KeyPair encodes a TLS Certificate into its pem encoded format for storage
[ "EncodeX509KeyPair", "encodes", "a", "TLS", "Certificate", "into", "its", "pem", "encoded", "format", "for", "storage" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/tls/tls.go#L229-L237
161,734
argoproj/argo-cd
util/tls/tls.go
EncodeX509KeyPairString
func EncodeX509KeyPairString(cert tls.Certificate) (string, string) { certpem, keypem := EncodeX509KeyPair(cert) return string(certpem), string(keypem) }
go
func EncodeX509KeyPairString(cert tls.Certificate) (string, string) { certpem, keypem := EncodeX509KeyPair(cert) return string(certpem), string(keypem) }
[ "func", "EncodeX509KeyPairString", "(", "cert", "tls", ".", "Certificate", ")", "(", "string", ",", "string", ")", "{", "certpem", ",", "keypem", ":=", "EncodeX509KeyPair", "(", "cert", ")", "\n", "return", "string", "(", "certpem", ")", ",", "string", "(", "keypem", ")", "\n", "}" ]
// EncodeX509KeyPairString encodes a TLS Certificate into its pem encoded string format
[ "EncodeX509KeyPairString", "encodes", "a", "TLS", "Certificate", "into", "its", "pem", "encoded", "string", "format" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/tls/tls.go#L240-L243
161,735
argoproj/argo-cd
cmd/argocd-util/main.go
NewExportCommand
func NewExportCommand() *cobra.Command { var ( clientConfig clientcmd.ClientConfig out string ) var command = cobra.Command{ Use: "export", Short: "Export all Argo CD data to stdout (default) or a file", Run: func(c *cobra.Command, args []string) { config, err := clientConfig.ClientConfig() errors.CheckError(err) namespace, _, err := clientConfig.Namespace() errors.CheckError(err) var writer io.Writer if out == "-" { writer = os.Stdout } else { f, err := os.Create(out) errors.CheckError(err) defer util.Close(f) writer = bufio.NewWriter(f) } acdClients := newArgoCDClientsets(config, namespace) acdConfigMap, err := acdClients.configMaps.Get(common.ArgoCDConfigMapName, metav1.GetOptions{}) errors.CheckError(err) export(writer, *acdConfigMap) acdRBACConfigMap, err := acdClients.configMaps.Get(common.ArgoCDRBACConfigMapName, metav1.GetOptions{}) errors.CheckError(err) export(writer, *acdRBACConfigMap) referencedSecrets := getReferencedSecrets(*acdConfigMap) secrets, err := acdClients.secrets.List(metav1.ListOptions{}) errors.CheckError(err) for _, secret := range secrets.Items { if isArgoCDSecret(referencedSecrets, secret) { export(writer, secret) } } projects, err := acdClients.projects.List(metav1.ListOptions{}) errors.CheckError(err) for _, proj := range projects.Items { export(writer, proj) } applications, err := acdClients.applications.List(metav1.ListOptions{}) errors.CheckError(err) for _, app := range applications.Items { export(writer, app) } }, } clientConfig = cli.AddKubectlFlagsToCmd(&command) command.Flags().StringVarP(&out, "out", "o", "-", "Output to the specified file instead of stdout") return &command }
go
func NewExportCommand() *cobra.Command { var ( clientConfig clientcmd.ClientConfig out string ) var command = cobra.Command{ Use: "export", Short: "Export all Argo CD data to stdout (default) or a file", Run: func(c *cobra.Command, args []string) { config, err := clientConfig.ClientConfig() errors.CheckError(err) namespace, _, err := clientConfig.Namespace() errors.CheckError(err) var writer io.Writer if out == "-" { writer = os.Stdout } else { f, err := os.Create(out) errors.CheckError(err) defer util.Close(f) writer = bufio.NewWriter(f) } acdClients := newArgoCDClientsets(config, namespace) acdConfigMap, err := acdClients.configMaps.Get(common.ArgoCDConfigMapName, metav1.GetOptions{}) errors.CheckError(err) export(writer, *acdConfigMap) acdRBACConfigMap, err := acdClients.configMaps.Get(common.ArgoCDRBACConfigMapName, metav1.GetOptions{}) errors.CheckError(err) export(writer, *acdRBACConfigMap) referencedSecrets := getReferencedSecrets(*acdConfigMap) secrets, err := acdClients.secrets.List(metav1.ListOptions{}) errors.CheckError(err) for _, secret := range secrets.Items { if isArgoCDSecret(referencedSecrets, secret) { export(writer, secret) } } projects, err := acdClients.projects.List(metav1.ListOptions{}) errors.CheckError(err) for _, proj := range projects.Items { export(writer, proj) } applications, err := acdClients.applications.List(metav1.ListOptions{}) errors.CheckError(err) for _, app := range applications.Items { export(writer, app) } }, } clientConfig = cli.AddKubectlFlagsToCmd(&command) command.Flags().StringVarP(&out, "out", "o", "-", "Output to the specified file instead of stdout") return &command }
[ "func", "NewExportCommand", "(", ")", "*", "cobra", ".", "Command", "{", "var", "(", "clientConfig", "clientcmd", ".", "ClientConfig", "\n", "out", "string", "\n", ")", "\n", "var", "command", "=", "cobra", ".", "Command", "{", "Use", ":", "\"", "\"", ",", "Short", ":", "\"", "\"", ",", "Run", ":", "func", "(", "c", "*", "cobra", ".", "Command", ",", "args", "[", "]", "string", ")", "{", "config", ",", "err", ":=", "clientConfig", ".", "ClientConfig", "(", ")", "\n", "errors", ".", "CheckError", "(", "err", ")", "\n", "namespace", ",", "_", ",", "err", ":=", "clientConfig", ".", "Namespace", "(", ")", "\n", "errors", ".", "CheckError", "(", "err", ")", "\n\n", "var", "writer", "io", ".", "Writer", "\n", "if", "out", "==", "\"", "\"", "{", "writer", "=", "os", ".", "Stdout", "\n", "}", "else", "{", "f", ",", "err", ":=", "os", ".", "Create", "(", "out", ")", "\n", "errors", ".", "CheckError", "(", "err", ")", "\n", "defer", "util", ".", "Close", "(", "f", ")", "\n", "writer", "=", "bufio", ".", "NewWriter", "(", "f", ")", "\n", "}", "\n\n", "acdClients", ":=", "newArgoCDClientsets", "(", "config", ",", "namespace", ")", "\n", "acdConfigMap", ",", "err", ":=", "acdClients", ".", "configMaps", ".", "Get", "(", "common", ".", "ArgoCDConfigMapName", ",", "metav1", ".", "GetOptions", "{", "}", ")", "\n", "errors", ".", "CheckError", "(", "err", ")", "\n", "export", "(", "writer", ",", "*", "acdConfigMap", ")", "\n", "acdRBACConfigMap", ",", "err", ":=", "acdClients", ".", "configMaps", ".", "Get", "(", "common", ".", "ArgoCDRBACConfigMapName", ",", "metav1", ".", "GetOptions", "{", "}", ")", "\n", "errors", ".", "CheckError", "(", "err", ")", "\n", "export", "(", "writer", ",", "*", "acdRBACConfigMap", ")", "\n\n", "referencedSecrets", ":=", "getReferencedSecrets", "(", "*", "acdConfigMap", ")", "\n", "secrets", ",", "err", ":=", "acdClients", ".", "secrets", ".", "List", "(", "metav1", ".", "ListOptions", "{", "}", ")", "\n", "errors", ".", "CheckError", "(", "err", ")", "\n", "for", "_", ",", "secret", ":=", "range", "secrets", ".", "Items", "{", "if", "isArgoCDSecret", "(", "referencedSecrets", ",", "secret", ")", "{", "export", "(", "writer", ",", "secret", ")", "\n", "}", "\n", "}", "\n", "projects", ",", "err", ":=", "acdClients", ".", "projects", ".", "List", "(", "metav1", ".", "ListOptions", "{", "}", ")", "\n", "errors", ".", "CheckError", "(", "err", ")", "\n", "for", "_", ",", "proj", ":=", "range", "projects", ".", "Items", "{", "export", "(", "writer", ",", "proj", ")", "\n", "}", "\n", "applications", ",", "err", ":=", "acdClients", ".", "applications", ".", "List", "(", "metav1", ".", "ListOptions", "{", "}", ")", "\n", "errors", ".", "CheckError", "(", "err", ")", "\n", "for", "_", ",", "app", ":=", "range", "applications", ".", "Items", "{", "export", "(", "writer", ",", "app", ")", "\n", "}", "\n", "}", ",", "}", "\n\n", "clientConfig", "=", "cli", ".", "AddKubectlFlagsToCmd", "(", "&", "command", ")", "\n", "command", ".", "Flags", "(", ")", ".", "StringVarP", "(", "&", "out", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "return", "&", "command", "\n", "}" ]
// NewExportCommand defines a new command for exporting Kubernetes and Argo CD resources.
[ "NewExportCommand", "defines", "a", "new", "command", "for", "exporting", "Kubernetes", "and", "Argo", "CD", "resources", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/cmd/argocd-util/main.go#L358-L415
161,736
argoproj/argo-cd
cmd/argocd-util/main.go
getReferencedSecrets
func getReferencedSecrets(un unstructured.Unstructured) map[string]bool { var cm apiv1.ConfigMap err := runtime.DefaultUnstructuredConverter.FromUnstructured(un.Object, &cm) errors.CheckError(err) referencedSecrets := make(map[string]bool) if reposRAW, ok := cm.Data["repositories"]; ok { repoCreds := make([]settings.RepoCredentials, 0) err := yaml.Unmarshal([]byte(reposRAW), &repoCreds) errors.CheckError(err) for _, cred := range repoCreds { if cred.PasswordSecret != nil { referencedSecrets[cred.PasswordSecret.Name] = true } if cred.SSHPrivateKeySecret != nil { referencedSecrets[cred.SSHPrivateKeySecret.Name] = true } if cred.UsernameSecret != nil { referencedSecrets[cred.UsernameSecret.Name] = true } } } if helmReposRAW, ok := cm.Data["helm.repositories"]; ok { helmRepoCreds := make([]settings.HelmRepoCredentials, 0) err := yaml.Unmarshal([]byte(helmReposRAW), &helmRepoCreds) errors.CheckError(err) for _, cred := range helmRepoCreds { if cred.CASecret != nil { referencedSecrets[cred.CASecret.Name] = true } if cred.CertSecret != nil { referencedSecrets[cred.CertSecret.Name] = true } if cred.KeySecret != nil { referencedSecrets[cred.KeySecret.Name] = true } if cred.UsernameSecret != nil { referencedSecrets[cred.UsernameSecret.Name] = true } if cred.PasswordSecret != nil { referencedSecrets[cred.PasswordSecret.Name] = true } } } return referencedSecrets }
go
func getReferencedSecrets(un unstructured.Unstructured) map[string]bool { var cm apiv1.ConfigMap err := runtime.DefaultUnstructuredConverter.FromUnstructured(un.Object, &cm) errors.CheckError(err) referencedSecrets := make(map[string]bool) if reposRAW, ok := cm.Data["repositories"]; ok { repoCreds := make([]settings.RepoCredentials, 0) err := yaml.Unmarshal([]byte(reposRAW), &repoCreds) errors.CheckError(err) for _, cred := range repoCreds { if cred.PasswordSecret != nil { referencedSecrets[cred.PasswordSecret.Name] = true } if cred.SSHPrivateKeySecret != nil { referencedSecrets[cred.SSHPrivateKeySecret.Name] = true } if cred.UsernameSecret != nil { referencedSecrets[cred.UsernameSecret.Name] = true } } } if helmReposRAW, ok := cm.Data["helm.repositories"]; ok { helmRepoCreds := make([]settings.HelmRepoCredentials, 0) err := yaml.Unmarshal([]byte(helmReposRAW), &helmRepoCreds) errors.CheckError(err) for _, cred := range helmRepoCreds { if cred.CASecret != nil { referencedSecrets[cred.CASecret.Name] = true } if cred.CertSecret != nil { referencedSecrets[cred.CertSecret.Name] = true } if cred.KeySecret != nil { referencedSecrets[cred.KeySecret.Name] = true } if cred.UsernameSecret != nil { referencedSecrets[cred.UsernameSecret.Name] = true } if cred.PasswordSecret != nil { referencedSecrets[cred.PasswordSecret.Name] = true } } } return referencedSecrets }
[ "func", "getReferencedSecrets", "(", "un", "unstructured", ".", "Unstructured", ")", "map", "[", "string", "]", "bool", "{", "var", "cm", "apiv1", ".", "ConfigMap", "\n", "err", ":=", "runtime", ".", "DefaultUnstructuredConverter", ".", "FromUnstructured", "(", "un", ".", "Object", ",", "&", "cm", ")", "\n", "errors", ".", "CheckError", "(", "err", ")", "\n", "referencedSecrets", ":=", "make", "(", "map", "[", "string", "]", "bool", ")", "\n", "if", "reposRAW", ",", "ok", ":=", "cm", ".", "Data", "[", "\"", "\"", "]", ";", "ok", "{", "repoCreds", ":=", "make", "(", "[", "]", "settings", ".", "RepoCredentials", ",", "0", ")", "\n", "err", ":=", "yaml", ".", "Unmarshal", "(", "[", "]", "byte", "(", "reposRAW", ")", ",", "&", "repoCreds", ")", "\n", "errors", ".", "CheckError", "(", "err", ")", "\n", "for", "_", ",", "cred", ":=", "range", "repoCreds", "{", "if", "cred", ".", "PasswordSecret", "!=", "nil", "{", "referencedSecrets", "[", "cred", ".", "PasswordSecret", ".", "Name", "]", "=", "true", "\n", "}", "\n", "if", "cred", ".", "SSHPrivateKeySecret", "!=", "nil", "{", "referencedSecrets", "[", "cred", ".", "SSHPrivateKeySecret", ".", "Name", "]", "=", "true", "\n", "}", "\n", "if", "cred", ".", "UsernameSecret", "!=", "nil", "{", "referencedSecrets", "[", "cred", ".", "UsernameSecret", ".", "Name", "]", "=", "true", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "helmReposRAW", ",", "ok", ":=", "cm", ".", "Data", "[", "\"", "\"", "]", ";", "ok", "{", "helmRepoCreds", ":=", "make", "(", "[", "]", "settings", ".", "HelmRepoCredentials", ",", "0", ")", "\n", "err", ":=", "yaml", ".", "Unmarshal", "(", "[", "]", "byte", "(", "helmReposRAW", ")", ",", "&", "helmRepoCreds", ")", "\n", "errors", ".", "CheckError", "(", "err", ")", "\n", "for", "_", ",", "cred", ":=", "range", "helmRepoCreds", "{", "if", "cred", ".", "CASecret", "!=", "nil", "{", "referencedSecrets", "[", "cred", ".", "CASecret", ".", "Name", "]", "=", "true", "\n", "}", "\n", "if", "cred", ".", "CertSecret", "!=", "nil", "{", "referencedSecrets", "[", "cred", ".", "CertSecret", ".", "Name", "]", "=", "true", "\n", "}", "\n", "if", "cred", ".", "KeySecret", "!=", "nil", "{", "referencedSecrets", "[", "cred", ".", "KeySecret", ".", "Name", "]", "=", "true", "\n", "}", "\n", "if", "cred", ".", "UsernameSecret", "!=", "nil", "{", "referencedSecrets", "[", "cred", ".", "UsernameSecret", ".", "Name", "]", "=", "true", "\n", "}", "\n", "if", "cred", ".", "PasswordSecret", "!=", "nil", "{", "referencedSecrets", "[", "cred", ".", "PasswordSecret", ".", "Name", "]", "=", "true", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "referencedSecrets", "\n", "}" ]
// getReferencedSecrets examines the argocd-cm config for any referenced repo secrets and returns a // map of all referenced secrets.
[ "getReferencedSecrets", "examines", "the", "argocd", "-", "cm", "config", "for", "any", "referenced", "repo", "secrets", "and", "returns", "a", "map", "of", "all", "referenced", "secrets", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/cmd/argocd-util/main.go#L419-L463
161,737
argoproj/argo-cd
cmd/argocd-util/main.go
export
func export(w io.Writer, un unstructured.Unstructured) { name := un.GetName() finalizers := un.GetFinalizers() apiVersion := un.GetAPIVersion() kind := un.GetKind() labels := un.GetLabels() annotations := un.GetAnnotations() unstructured.RemoveNestedField(un.Object, "metadata") un.SetName(name) un.SetFinalizers(finalizers) un.SetAPIVersion(apiVersion) un.SetKind(kind) un.SetLabels(labels) un.SetAnnotations(annotations) data, err := yaml.Marshal(un.Object) errors.CheckError(err) _, err = w.Write(data) errors.CheckError(err) _, err = w.Write([]byte(yamlSeparator)) errors.CheckError(err) }
go
func export(w io.Writer, un unstructured.Unstructured) { name := un.GetName() finalizers := un.GetFinalizers() apiVersion := un.GetAPIVersion() kind := un.GetKind() labels := un.GetLabels() annotations := un.GetAnnotations() unstructured.RemoveNestedField(un.Object, "metadata") un.SetName(name) un.SetFinalizers(finalizers) un.SetAPIVersion(apiVersion) un.SetKind(kind) un.SetLabels(labels) un.SetAnnotations(annotations) data, err := yaml.Marshal(un.Object) errors.CheckError(err) _, err = w.Write(data) errors.CheckError(err) _, err = w.Write([]byte(yamlSeparator)) errors.CheckError(err) }
[ "func", "export", "(", "w", "io", ".", "Writer", ",", "un", "unstructured", ".", "Unstructured", ")", "{", "name", ":=", "un", ".", "GetName", "(", ")", "\n", "finalizers", ":=", "un", ".", "GetFinalizers", "(", ")", "\n", "apiVersion", ":=", "un", ".", "GetAPIVersion", "(", ")", "\n", "kind", ":=", "un", ".", "GetKind", "(", ")", "\n", "labels", ":=", "un", ".", "GetLabels", "(", ")", "\n", "annotations", ":=", "un", ".", "GetAnnotations", "(", ")", "\n", "unstructured", ".", "RemoveNestedField", "(", "un", ".", "Object", ",", "\"", "\"", ")", "\n", "un", ".", "SetName", "(", "name", ")", "\n", "un", ".", "SetFinalizers", "(", "finalizers", ")", "\n", "un", ".", "SetAPIVersion", "(", "apiVersion", ")", "\n", "un", ".", "SetKind", "(", "kind", ")", "\n", "un", ".", "SetLabels", "(", "labels", ")", "\n", "un", ".", "SetAnnotations", "(", "annotations", ")", "\n", "data", ",", "err", ":=", "yaml", ".", "Marshal", "(", "un", ".", "Object", ")", "\n", "errors", ".", "CheckError", "(", "err", ")", "\n", "_", ",", "err", "=", "w", ".", "Write", "(", "data", ")", "\n", "errors", ".", "CheckError", "(", "err", ")", "\n", "_", ",", "err", "=", "w", ".", "Write", "(", "[", "]", "byte", "(", "yamlSeparator", ")", ")", "\n", "errors", ".", "CheckError", "(", "err", ")", "\n", "}" ]
// export writes the unstructured object and removes extraneous cruft from output before writing
[ "export", "writes", "the", "unstructured", "object", "and", "removes", "extraneous", "cruft", "from", "output", "before", "writing" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/cmd/argocd-util/main.go#L491-L511
161,738
argoproj/argo-cd
cmd/argocd-util/main.go
NewClusterConfig
func NewClusterConfig() *cobra.Command { var ( clientConfig clientcmd.ClientConfig ) var command = &cobra.Command{ Use: "kubeconfig CLUSTER_URL OUTPUT_PATH", Short: "Generates kubeconfig for the specified cluster", Run: func(c *cobra.Command, args []string) { if len(args) != 2 { c.HelpFunc()(c, args) os.Exit(1) } serverUrl := args[0] output := args[1] conf, err := clientConfig.ClientConfig() errors.CheckError(err) namespace, _, err := clientConfig.Namespace() errors.CheckError(err) kubeclientset, err := kubernetes.NewForConfig(conf) errors.CheckError(err) cluster, err := db.NewDB(namespace, settings.NewSettingsManager(context.Background(), kubeclientset, namespace), kubeclientset).GetCluster(context.Background(), serverUrl) errors.CheckError(err) err = kube.WriteKubeConfig(cluster.RESTConfig(), namespace, output) errors.CheckError(err) }, } clientConfig = cli.AddKubectlFlagsToCmd(command) return command }
go
func NewClusterConfig() *cobra.Command { var ( clientConfig clientcmd.ClientConfig ) var command = &cobra.Command{ Use: "kubeconfig CLUSTER_URL OUTPUT_PATH", Short: "Generates kubeconfig for the specified cluster", Run: func(c *cobra.Command, args []string) { if len(args) != 2 { c.HelpFunc()(c, args) os.Exit(1) } serverUrl := args[0] output := args[1] conf, err := clientConfig.ClientConfig() errors.CheckError(err) namespace, _, err := clientConfig.Namespace() errors.CheckError(err) kubeclientset, err := kubernetes.NewForConfig(conf) errors.CheckError(err) cluster, err := db.NewDB(namespace, settings.NewSettingsManager(context.Background(), kubeclientset, namespace), kubeclientset).GetCluster(context.Background(), serverUrl) errors.CheckError(err) err = kube.WriteKubeConfig(cluster.RESTConfig(), namespace, output) errors.CheckError(err) }, } clientConfig = cli.AddKubectlFlagsToCmd(command) return command }
[ "func", "NewClusterConfig", "(", ")", "*", "cobra", ".", "Command", "{", "var", "(", "clientConfig", "clientcmd", ".", "ClientConfig", "\n", ")", "\n", "var", "command", "=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"", "\"", ",", "Short", ":", "\"", "\"", ",", "Run", ":", "func", "(", "c", "*", "cobra", ".", "Command", ",", "args", "[", "]", "string", ")", "{", "if", "len", "(", "args", ")", "!=", "2", "{", "c", ".", "HelpFunc", "(", ")", "(", "c", ",", "args", ")", "\n", "os", ".", "Exit", "(", "1", ")", "\n", "}", "\n", "serverUrl", ":=", "args", "[", "0", "]", "\n", "output", ":=", "args", "[", "1", "]", "\n", "conf", ",", "err", ":=", "clientConfig", ".", "ClientConfig", "(", ")", "\n", "errors", ".", "CheckError", "(", "err", ")", "\n", "namespace", ",", "_", ",", "err", ":=", "clientConfig", ".", "Namespace", "(", ")", "\n", "errors", ".", "CheckError", "(", "err", ")", "\n", "kubeclientset", ",", "err", ":=", "kubernetes", ".", "NewForConfig", "(", "conf", ")", "\n", "errors", ".", "CheckError", "(", "err", ")", "\n\n", "cluster", ",", "err", ":=", "db", ".", "NewDB", "(", "namespace", ",", "settings", ".", "NewSettingsManager", "(", "context", ".", "Background", "(", ")", ",", "kubeclientset", ",", "namespace", ")", ",", "kubeclientset", ")", ".", "GetCluster", "(", "context", ".", "Background", "(", ")", ",", "serverUrl", ")", "\n", "errors", ".", "CheckError", "(", "err", ")", "\n", "err", "=", "kube", ".", "WriteKubeConfig", "(", "cluster", ".", "RESTConfig", "(", ")", ",", "namespace", ",", "output", ")", "\n", "errors", ".", "CheckError", "(", "err", ")", "\n", "}", ",", "}", "\n", "clientConfig", "=", "cli", ".", "AddKubectlFlagsToCmd", "(", "command", ")", "\n", "return", "command", "\n", "}" ]
// NewClusterConfig returns a new instance of `argocd-util kubeconfig` command
[ "NewClusterConfig", "returns", "a", "new", "instance", "of", "argocd", "-", "util", "kubeconfig", "command" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/cmd/argocd-util/main.go#L514-L543
161,739
argoproj/argo-cd
server/application/application.go
NewServer
func NewServer( namespace string, kubeclientset kubernetes.Interface, appclientset appclientset.Interface, repoClientset reposerver.Clientset, cache *cache.Cache, kubectl kube.Kubectl, db db.ArgoDB, enf *rbac.Enforcer, projectLock *util.KeyLock, settingsMgr *settings.SettingsManager, ) ApplicationServiceServer { return &Server{ ns: namespace, appclientset: appclientset, kubeclientset: kubeclientset, cache: cache, db: db, repoClientset: repoClientset, kubectl: kubectl, enf: enf, projectLock: projectLock, auditLogger: argo.NewAuditLogger(namespace, kubeclientset, "argocd-server"), gitFactory: git.NewFactory(), settingsMgr: settingsMgr, } }
go
func NewServer( namespace string, kubeclientset kubernetes.Interface, appclientset appclientset.Interface, repoClientset reposerver.Clientset, cache *cache.Cache, kubectl kube.Kubectl, db db.ArgoDB, enf *rbac.Enforcer, projectLock *util.KeyLock, settingsMgr *settings.SettingsManager, ) ApplicationServiceServer { return &Server{ ns: namespace, appclientset: appclientset, kubeclientset: kubeclientset, cache: cache, db: db, repoClientset: repoClientset, kubectl: kubectl, enf: enf, projectLock: projectLock, auditLogger: argo.NewAuditLogger(namespace, kubeclientset, "argocd-server"), gitFactory: git.NewFactory(), settingsMgr: settingsMgr, } }
[ "func", "NewServer", "(", "namespace", "string", ",", "kubeclientset", "kubernetes", ".", "Interface", ",", "appclientset", "appclientset", ".", "Interface", ",", "repoClientset", "reposerver", ".", "Clientset", ",", "cache", "*", "cache", ".", "Cache", ",", "kubectl", "kube", ".", "Kubectl", ",", "db", "db", ".", "ArgoDB", ",", "enf", "*", "rbac", ".", "Enforcer", ",", "projectLock", "*", "util", ".", "KeyLock", ",", "settingsMgr", "*", "settings", ".", "SettingsManager", ",", ")", "ApplicationServiceServer", "{", "return", "&", "Server", "{", "ns", ":", "namespace", ",", "appclientset", ":", "appclientset", ",", "kubeclientset", ":", "kubeclientset", ",", "cache", ":", "cache", ",", "db", ":", "db", ",", "repoClientset", ":", "repoClientset", ",", "kubectl", ":", "kubectl", ",", "enf", ":", "enf", ",", "projectLock", ":", "projectLock", ",", "auditLogger", ":", "argo", ".", "NewAuditLogger", "(", "namespace", ",", "kubeclientset", ",", "\"", "\"", ")", ",", "gitFactory", ":", "git", ".", "NewFactory", "(", ")", ",", "settingsMgr", ":", "settingsMgr", ",", "}", "\n", "}" ]
// NewServer returns a new instance of the Application service
[ "NewServer", "returns", "a", "new", "instance", "of", "the", "Application", "service" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/application/application.go#L61-L88
161,740
argoproj/argo-cd
server/application/application.go
appRBACName
func appRBACName(app appv1.Application) string { return fmt.Sprintf("%s/%s", app.Spec.GetProject(), app.Name) }
go
func appRBACName(app appv1.Application) string { return fmt.Sprintf("%s/%s", app.Spec.GetProject(), app.Name) }
[ "func", "appRBACName", "(", "app", "appv1", ".", "Application", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "app", ".", "Spec", ".", "GetProject", "(", ")", ",", "app", ".", "Name", ")", "\n", "}" ]
// appRBACName formats fully qualified application name for RBAC check
[ "appRBACName", "formats", "fully", "qualified", "application", "name", "for", "RBAC", "check" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/application/application.go#L91-L93
161,741
argoproj/argo-cd
server/application/application.go
List
func (s *Server) List(ctx context.Context, q *ApplicationQuery) (*appv1.ApplicationList, error) { appList, err := s.appclientset.ArgoprojV1alpha1().Applications(s.ns).List(metav1.ListOptions{}) if err != nil { return nil, err } newItems := make([]appv1.Application, 0) for _, a := range appList.Items { if s.enf.Enforce(ctx.Value("claims"), rbacpolicy.ResourceApplications, rbacpolicy.ActionGet, appRBACName(a)) { newItems = append(newItems, a) } } newItems = argoutil.FilterByProjects(newItems, q.Projects) for i := range newItems { app := newItems[i] newItems[i] = app } appList.Items = newItems return appList, nil }
go
func (s *Server) List(ctx context.Context, q *ApplicationQuery) (*appv1.ApplicationList, error) { appList, err := s.appclientset.ArgoprojV1alpha1().Applications(s.ns).List(metav1.ListOptions{}) if err != nil { return nil, err } newItems := make([]appv1.Application, 0) for _, a := range appList.Items { if s.enf.Enforce(ctx.Value("claims"), rbacpolicy.ResourceApplications, rbacpolicy.ActionGet, appRBACName(a)) { newItems = append(newItems, a) } } newItems = argoutil.FilterByProjects(newItems, q.Projects) for i := range newItems { app := newItems[i] newItems[i] = app } appList.Items = newItems return appList, nil }
[ "func", "(", "s", "*", "Server", ")", "List", "(", "ctx", "context", ".", "Context", ",", "q", "*", "ApplicationQuery", ")", "(", "*", "appv1", ".", "ApplicationList", ",", "error", ")", "{", "appList", ",", "err", ":=", "s", ".", "appclientset", ".", "ArgoprojV1alpha1", "(", ")", ".", "Applications", "(", "s", ".", "ns", ")", ".", "List", "(", "metav1", ".", "ListOptions", "{", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "newItems", ":=", "make", "(", "[", "]", "appv1", ".", "Application", ",", "0", ")", "\n", "for", "_", ",", "a", ":=", "range", "appList", ".", "Items", "{", "if", "s", ".", "enf", ".", "Enforce", "(", "ctx", ".", "Value", "(", "\"", "\"", ")", ",", "rbacpolicy", ".", "ResourceApplications", ",", "rbacpolicy", ".", "ActionGet", ",", "appRBACName", "(", "a", ")", ")", "{", "newItems", "=", "append", "(", "newItems", ",", "a", ")", "\n", "}", "\n", "}", "\n", "newItems", "=", "argoutil", ".", "FilterByProjects", "(", "newItems", ",", "q", ".", "Projects", ")", "\n", "for", "i", ":=", "range", "newItems", "{", "app", ":=", "newItems", "[", "i", "]", "\n", "newItems", "[", "i", "]", "=", "app", "\n", "}", "\n", "appList", ".", "Items", "=", "newItems", "\n", "return", "appList", ",", "nil", "\n", "}" ]
// List returns list of applications
[ "List", "returns", "list", "of", "applications" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/application/application.go#L96-L114
161,742
argoproj/argo-cd
server/application/application.go
Create
func (s *Server) Create(ctx context.Context, q *ApplicationCreateRequest) (*appv1.Application, error) { if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceApplications, rbacpolicy.ActionCreate, appRBACName(q.Application)); err != nil { return nil, err } s.projectLock.Lock(q.Application.Spec.Project) defer s.projectLock.Unlock(q.Application.Spec.Project) a := q.Application err := s.validateAndNormalizeApp(ctx, &a) if err != nil { return nil, err } out, err := s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Create(&a) if apierr.IsAlreadyExists(err) { // act idempotent if existing spec matches new spec existing, getErr := s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Get(a.Name, metav1.GetOptions{}) if getErr != nil { return nil, status.Errorf(codes.Internal, "unable to check existing application details: %v", getErr) } if q.Upsert != nil && *q.Upsert { if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceApplications, rbacpolicy.ActionUpdate, appRBACName(a)); err != nil { return nil, err } existing.Spec = a.Spec out, err = s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Update(existing) } else { if !reflect.DeepEqual(existing.Spec, a.Spec) { return nil, status.Errorf(codes.InvalidArgument, "existing application spec is different, use upsert flag to force update") } return existing, nil } } if err == nil { s.logEvent(out, ctx, argo.EventReasonResourceCreated, "created application") } return out, err }
go
func (s *Server) Create(ctx context.Context, q *ApplicationCreateRequest) (*appv1.Application, error) { if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceApplications, rbacpolicy.ActionCreate, appRBACName(q.Application)); err != nil { return nil, err } s.projectLock.Lock(q.Application.Spec.Project) defer s.projectLock.Unlock(q.Application.Spec.Project) a := q.Application err := s.validateAndNormalizeApp(ctx, &a) if err != nil { return nil, err } out, err := s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Create(&a) if apierr.IsAlreadyExists(err) { // act idempotent if existing spec matches new spec existing, getErr := s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Get(a.Name, metav1.GetOptions{}) if getErr != nil { return nil, status.Errorf(codes.Internal, "unable to check existing application details: %v", getErr) } if q.Upsert != nil && *q.Upsert { if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceApplications, rbacpolicy.ActionUpdate, appRBACName(a)); err != nil { return nil, err } existing.Spec = a.Spec out, err = s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Update(existing) } else { if !reflect.DeepEqual(existing.Spec, a.Spec) { return nil, status.Errorf(codes.InvalidArgument, "existing application spec is different, use upsert flag to force update") } return existing, nil } } if err == nil { s.logEvent(out, ctx, argo.EventReasonResourceCreated, "created application") } return out, err }
[ "func", "(", "s", "*", "Server", ")", "Create", "(", "ctx", "context", ".", "Context", ",", "q", "*", "ApplicationCreateRequest", ")", "(", "*", "appv1", ".", "Application", ",", "error", ")", "{", "if", "err", ":=", "s", ".", "enf", ".", "EnforceErr", "(", "ctx", ".", "Value", "(", "\"", "\"", ")", ",", "rbacpolicy", ".", "ResourceApplications", ",", "rbacpolicy", ".", "ActionCreate", ",", "appRBACName", "(", "q", ".", "Application", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "s", ".", "projectLock", ".", "Lock", "(", "q", ".", "Application", ".", "Spec", ".", "Project", ")", "\n", "defer", "s", ".", "projectLock", ".", "Unlock", "(", "q", ".", "Application", ".", "Spec", ".", "Project", ")", "\n\n", "a", ":=", "q", ".", "Application", "\n", "err", ":=", "s", ".", "validateAndNormalizeApp", "(", "ctx", ",", "&", "a", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "out", ",", "err", ":=", "s", ".", "appclientset", ".", "ArgoprojV1alpha1", "(", ")", ".", "Applications", "(", "s", ".", "ns", ")", ".", "Create", "(", "&", "a", ")", "\n", "if", "apierr", ".", "IsAlreadyExists", "(", "err", ")", "{", "// act idempotent if existing spec matches new spec", "existing", ",", "getErr", ":=", "s", ".", "appclientset", ".", "ArgoprojV1alpha1", "(", ")", ".", "Applications", "(", "s", ".", "ns", ")", ".", "Get", "(", "a", ".", "Name", ",", "metav1", ".", "GetOptions", "{", "}", ")", "\n", "if", "getErr", "!=", "nil", "{", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "Internal", ",", "\"", "\"", ",", "getErr", ")", "\n", "}", "\n", "if", "q", ".", "Upsert", "!=", "nil", "&&", "*", "q", ".", "Upsert", "{", "if", "err", ":=", "s", ".", "enf", ".", "EnforceErr", "(", "ctx", ".", "Value", "(", "\"", "\"", ")", ",", "rbacpolicy", ".", "ResourceApplications", ",", "rbacpolicy", ".", "ActionUpdate", ",", "appRBACName", "(", "a", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "existing", ".", "Spec", "=", "a", ".", "Spec", "\n", "out", ",", "err", "=", "s", ".", "appclientset", ".", "ArgoprojV1alpha1", "(", ")", ".", "Applications", "(", "s", ".", "ns", ")", ".", "Update", "(", "existing", ")", "\n", "}", "else", "{", "if", "!", "reflect", ".", "DeepEqual", "(", "existing", ".", "Spec", ",", "a", ".", "Spec", ")", "{", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "InvalidArgument", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "existing", ",", "nil", "\n", "}", "\n", "}", "\n\n", "if", "err", "==", "nil", "{", "s", ".", "logEvent", "(", "out", ",", "ctx", ",", "argo", ".", "EventReasonResourceCreated", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "out", ",", "err", "\n", "}" ]
// Create creates an application
[ "Create", "creates", "an", "application" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/application/application.go#L117-L155
161,743
argoproj/argo-cd
server/application/application.go
GetManifests
func (s *Server) GetManifests(ctx context.Context, q *ApplicationManifestQuery) (*repository.ManifestResponse, error) { a, err := s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Get(*q.Name, metav1.GetOptions{}) if err != nil { return nil, err } if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceApplications, rbacpolicy.ActionGet, appRBACName(*a)); err != nil { return nil, err } repo := s.getRepo(ctx, a.Spec.Source.RepoURL) conn, repoClient, err := s.repoClientset.NewRepoServerClient() if err != nil { return nil, err } defer util.Close(conn) revision := a.Spec.Source.TargetRevision if q.Revision != "" { revision = q.Revision } settings, err := s.settingsMgr.GetSettings() if err != nil { return nil, err } helmRepos, err := s.db.ListHelmRepos(ctx) if err != nil { return nil, err } tools := make([]*appv1.ConfigManagementPlugin, len(settings.ConfigManagementPlugins)) for i := range settings.ConfigManagementPlugins { tools[i] = &settings.ConfigManagementPlugins[i] } manifestInfo, err := repoClient.GenerateManifest(ctx, &repository.ManifestRequest{ Repo: repo, Revision: revision, AppLabelKey: settings.GetAppInstanceLabelKey(), AppLabelValue: a.Name, Namespace: a.Spec.Destination.Namespace, ApplicationSource: &a.Spec.Source, HelmRepos: helmRepos, Plugins: tools, }) if err != nil { return nil, err } return manifestInfo, nil }
go
func (s *Server) GetManifests(ctx context.Context, q *ApplicationManifestQuery) (*repository.ManifestResponse, error) { a, err := s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Get(*q.Name, metav1.GetOptions{}) if err != nil { return nil, err } if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceApplications, rbacpolicy.ActionGet, appRBACName(*a)); err != nil { return nil, err } repo := s.getRepo(ctx, a.Spec.Source.RepoURL) conn, repoClient, err := s.repoClientset.NewRepoServerClient() if err != nil { return nil, err } defer util.Close(conn) revision := a.Spec.Source.TargetRevision if q.Revision != "" { revision = q.Revision } settings, err := s.settingsMgr.GetSettings() if err != nil { return nil, err } helmRepos, err := s.db.ListHelmRepos(ctx) if err != nil { return nil, err } tools := make([]*appv1.ConfigManagementPlugin, len(settings.ConfigManagementPlugins)) for i := range settings.ConfigManagementPlugins { tools[i] = &settings.ConfigManagementPlugins[i] } manifestInfo, err := repoClient.GenerateManifest(ctx, &repository.ManifestRequest{ Repo: repo, Revision: revision, AppLabelKey: settings.GetAppInstanceLabelKey(), AppLabelValue: a.Name, Namespace: a.Spec.Destination.Namespace, ApplicationSource: &a.Spec.Source, HelmRepos: helmRepos, Plugins: tools, }) if err != nil { return nil, err } return manifestInfo, nil }
[ "func", "(", "s", "*", "Server", ")", "GetManifests", "(", "ctx", "context", ".", "Context", ",", "q", "*", "ApplicationManifestQuery", ")", "(", "*", "repository", ".", "ManifestResponse", ",", "error", ")", "{", "a", ",", "err", ":=", "s", ".", "appclientset", ".", "ArgoprojV1alpha1", "(", ")", ".", "Applications", "(", "s", ".", "ns", ")", ".", "Get", "(", "*", "q", ".", "Name", ",", "metav1", ".", "GetOptions", "{", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", ":=", "s", ".", "enf", ".", "EnforceErr", "(", "ctx", ".", "Value", "(", "\"", "\"", ")", ",", "rbacpolicy", ".", "ResourceApplications", ",", "rbacpolicy", ".", "ActionGet", ",", "appRBACName", "(", "*", "a", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "repo", ":=", "s", ".", "getRepo", "(", "ctx", ",", "a", ".", "Spec", ".", "Source", ".", "RepoURL", ")", "\n\n", "conn", ",", "repoClient", ",", "err", ":=", "s", ".", "repoClientset", ".", "NewRepoServerClient", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "util", ".", "Close", "(", "conn", ")", "\n", "revision", ":=", "a", ".", "Spec", ".", "Source", ".", "TargetRevision", "\n", "if", "q", ".", "Revision", "!=", "\"", "\"", "{", "revision", "=", "q", ".", "Revision", "\n", "}", "\n", "settings", ",", "err", ":=", "s", ".", "settingsMgr", ".", "GetSettings", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "helmRepos", ",", "err", ":=", "s", ".", "db", ".", "ListHelmRepos", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "tools", ":=", "make", "(", "[", "]", "*", "appv1", ".", "ConfigManagementPlugin", ",", "len", "(", "settings", ".", "ConfigManagementPlugins", ")", ")", "\n", "for", "i", ":=", "range", "settings", ".", "ConfigManagementPlugins", "{", "tools", "[", "i", "]", "=", "&", "settings", ".", "ConfigManagementPlugins", "[", "i", "]", "\n", "}", "\n", "manifestInfo", ",", "err", ":=", "repoClient", ".", "GenerateManifest", "(", "ctx", ",", "&", "repository", ".", "ManifestRequest", "{", "Repo", ":", "repo", ",", "Revision", ":", "revision", ",", "AppLabelKey", ":", "settings", ".", "GetAppInstanceLabelKey", "(", ")", ",", "AppLabelValue", ":", "a", ".", "Name", ",", "Namespace", ":", "a", ".", "Spec", ".", "Destination", ".", "Namespace", ",", "ApplicationSource", ":", "&", "a", ".", "Spec", ".", "Source", ",", "HelmRepos", ":", "helmRepos", ",", "Plugins", ":", "tools", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "manifestInfo", ",", "nil", "\n", "}" ]
// GetManifests returns application manifests
[ "GetManifests", "returns", "application", "manifests" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/application/application.go#L158-L204
161,744
argoproj/argo-cd
server/application/application.go
Get
func (s *Server) Get(ctx context.Context, q *ApplicationQuery) (*appv1.Application, error) { appIf := s.appclientset.ArgoprojV1alpha1().Applications(s.ns) a, err := appIf.Get(*q.Name, metav1.GetOptions{}) if err != nil { return nil, err } if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceApplications, rbacpolicy.ActionGet, appRBACName(*a)); err != nil { return nil, err } if q.Refresh != nil { refreshType := appv1.RefreshTypeNormal if *q.Refresh == string(appv1.RefreshTypeHard) { refreshType = appv1.RefreshTypeHard } _, err = argoutil.RefreshApp(appIf, *q.Name, refreshType) if err != nil { return nil, err } a, err = argoutil.WaitForRefresh(ctx, appIf, *q.Name, nil) if err != nil { return nil, err } } return a, nil }
go
func (s *Server) Get(ctx context.Context, q *ApplicationQuery) (*appv1.Application, error) { appIf := s.appclientset.ArgoprojV1alpha1().Applications(s.ns) a, err := appIf.Get(*q.Name, metav1.GetOptions{}) if err != nil { return nil, err } if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceApplications, rbacpolicy.ActionGet, appRBACName(*a)); err != nil { return nil, err } if q.Refresh != nil { refreshType := appv1.RefreshTypeNormal if *q.Refresh == string(appv1.RefreshTypeHard) { refreshType = appv1.RefreshTypeHard } _, err = argoutil.RefreshApp(appIf, *q.Name, refreshType) if err != nil { return nil, err } a, err = argoutil.WaitForRefresh(ctx, appIf, *q.Name, nil) if err != nil { return nil, err } } return a, nil }
[ "func", "(", "s", "*", "Server", ")", "Get", "(", "ctx", "context", ".", "Context", ",", "q", "*", "ApplicationQuery", ")", "(", "*", "appv1", ".", "Application", ",", "error", ")", "{", "appIf", ":=", "s", ".", "appclientset", ".", "ArgoprojV1alpha1", "(", ")", ".", "Applications", "(", "s", ".", "ns", ")", "\n", "a", ",", "err", ":=", "appIf", ".", "Get", "(", "*", "q", ".", "Name", ",", "metav1", ".", "GetOptions", "{", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", ":=", "s", ".", "enf", ".", "EnforceErr", "(", "ctx", ".", "Value", "(", "\"", "\"", ")", ",", "rbacpolicy", ".", "ResourceApplications", ",", "rbacpolicy", ".", "ActionGet", ",", "appRBACName", "(", "*", "a", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "q", ".", "Refresh", "!=", "nil", "{", "refreshType", ":=", "appv1", ".", "RefreshTypeNormal", "\n", "if", "*", "q", ".", "Refresh", "==", "string", "(", "appv1", ".", "RefreshTypeHard", ")", "{", "refreshType", "=", "appv1", ".", "RefreshTypeHard", "\n", "}", "\n", "_", ",", "err", "=", "argoutil", ".", "RefreshApp", "(", "appIf", ",", "*", "q", ".", "Name", ",", "refreshType", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "a", ",", "err", "=", "argoutil", ".", "WaitForRefresh", "(", "ctx", ",", "appIf", ",", "*", "q", ".", "Name", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "return", "a", ",", "nil", "\n", "}" ]
// Get returns an application by name
[ "Get", "returns", "an", "application", "by", "name" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/application/application.go#L207-L231
161,745
argoproj/argo-cd
server/application/application.go
ListResourceEvents
func (s *Server) ListResourceEvents(ctx context.Context, q *ApplicationResourceEventsQuery) (*v1.EventList, error) { a, err := s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Get(*q.Name, metav1.GetOptions{}) if err != nil { return nil, err } if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceApplications, rbacpolicy.ActionGet, appRBACName(*a)); err != nil { return nil, err } var ( kubeClientset kubernetes.Interface fieldSelector string namespace string ) // There are two places where we get events. If we are getting application events, we query // our own cluster. If it is events on a resource on an external cluster, then we query the // external cluster using its rest.Config if q.ResourceName == "" && q.ResourceUID == "" { kubeClientset = s.kubeclientset namespace = a.Namespace fieldSelector = fields.SelectorFromSet(map[string]string{ "involvedObject.name": a.Name, "involvedObject.uid": string(a.UID), "involvedObject.namespace": a.Namespace, }).String() } else { namespace = q.ResourceNamespace var config *rest.Config config, _, err = s.getApplicationClusterConfig(*q.Name) if err != nil { return nil, err } kubeClientset, err = kubernetes.NewForConfig(config) if err != nil { return nil, err } fieldSelector = fields.SelectorFromSet(map[string]string{ "involvedObject.name": q.ResourceName, "involvedObject.uid": q.ResourceUID, "involvedObject.namespace": namespace, }).String() } log.Infof("Querying for resource events with field selector: %s", fieldSelector) opts := metav1.ListOptions{FieldSelector: fieldSelector} return kubeClientset.CoreV1().Events(namespace).List(opts) }
go
func (s *Server) ListResourceEvents(ctx context.Context, q *ApplicationResourceEventsQuery) (*v1.EventList, error) { a, err := s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Get(*q.Name, metav1.GetOptions{}) if err != nil { return nil, err } if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceApplications, rbacpolicy.ActionGet, appRBACName(*a)); err != nil { return nil, err } var ( kubeClientset kubernetes.Interface fieldSelector string namespace string ) // There are two places where we get events. If we are getting application events, we query // our own cluster. If it is events on a resource on an external cluster, then we query the // external cluster using its rest.Config if q.ResourceName == "" && q.ResourceUID == "" { kubeClientset = s.kubeclientset namespace = a.Namespace fieldSelector = fields.SelectorFromSet(map[string]string{ "involvedObject.name": a.Name, "involvedObject.uid": string(a.UID), "involvedObject.namespace": a.Namespace, }).String() } else { namespace = q.ResourceNamespace var config *rest.Config config, _, err = s.getApplicationClusterConfig(*q.Name) if err != nil { return nil, err } kubeClientset, err = kubernetes.NewForConfig(config) if err != nil { return nil, err } fieldSelector = fields.SelectorFromSet(map[string]string{ "involvedObject.name": q.ResourceName, "involvedObject.uid": q.ResourceUID, "involvedObject.namespace": namespace, }).String() } log.Infof("Querying for resource events with field selector: %s", fieldSelector) opts := metav1.ListOptions{FieldSelector: fieldSelector} return kubeClientset.CoreV1().Events(namespace).List(opts) }
[ "func", "(", "s", "*", "Server", ")", "ListResourceEvents", "(", "ctx", "context", ".", "Context", ",", "q", "*", "ApplicationResourceEventsQuery", ")", "(", "*", "v1", ".", "EventList", ",", "error", ")", "{", "a", ",", "err", ":=", "s", ".", "appclientset", ".", "ArgoprojV1alpha1", "(", ")", ".", "Applications", "(", "s", ".", "ns", ")", ".", "Get", "(", "*", "q", ".", "Name", ",", "metav1", ".", "GetOptions", "{", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", ":=", "s", ".", "enf", ".", "EnforceErr", "(", "ctx", ".", "Value", "(", "\"", "\"", ")", ",", "rbacpolicy", ".", "ResourceApplications", ",", "rbacpolicy", ".", "ActionGet", ",", "appRBACName", "(", "*", "a", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "(", "kubeClientset", "kubernetes", ".", "Interface", "\n", "fieldSelector", "string", "\n", "namespace", "string", "\n", ")", "\n", "// There are two places where we get events. If we are getting application events, we query", "// our own cluster. If it is events on a resource on an external cluster, then we query the", "// external cluster using its rest.Config", "if", "q", ".", "ResourceName", "==", "\"", "\"", "&&", "q", ".", "ResourceUID", "==", "\"", "\"", "{", "kubeClientset", "=", "s", ".", "kubeclientset", "\n", "namespace", "=", "a", ".", "Namespace", "\n", "fieldSelector", "=", "fields", ".", "SelectorFromSet", "(", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "a", ".", "Name", ",", "\"", "\"", ":", "string", "(", "a", ".", "UID", ")", ",", "\"", "\"", ":", "a", ".", "Namespace", ",", "}", ")", ".", "String", "(", ")", "\n", "}", "else", "{", "namespace", "=", "q", ".", "ResourceNamespace", "\n", "var", "config", "*", "rest", ".", "Config", "\n", "config", ",", "_", ",", "err", "=", "s", ".", "getApplicationClusterConfig", "(", "*", "q", ".", "Name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "kubeClientset", ",", "err", "=", "kubernetes", ".", "NewForConfig", "(", "config", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "fieldSelector", "=", "fields", ".", "SelectorFromSet", "(", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "q", ".", "ResourceName", ",", "\"", "\"", ":", "q", ".", "ResourceUID", ",", "\"", "\"", ":", "namespace", ",", "}", ")", ".", "String", "(", ")", "\n", "}", "\n\n", "log", ".", "Infof", "(", "\"", "\"", ",", "fieldSelector", ")", "\n", "opts", ":=", "metav1", ".", "ListOptions", "{", "FieldSelector", ":", "fieldSelector", "}", "\n", "return", "kubeClientset", ".", "CoreV1", "(", ")", ".", "Events", "(", "namespace", ")", ".", "List", "(", "opts", ")", "\n", "}" ]
// ListResourceEvents returns a list of event resources
[ "ListResourceEvents", "returns", "a", "list", "of", "event", "resources" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/application/application.go#L234-L279
161,746
argoproj/argo-cd
server/application/application.go
Update
func (s *Server) Update(ctx context.Context, q *ApplicationUpdateRequest) (*appv1.Application, error) { if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceApplications, rbacpolicy.ActionUpdate, appRBACName(*q.Application)); err != nil { return nil, err } s.projectLock.Lock(q.Application.Spec.Project) defer s.projectLock.Unlock(q.Application.Spec.Project) a := q.Application err := s.validateAndNormalizeApp(ctx, a) if err != nil { return nil, err } out, err := s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Update(a) if err == nil { s.logEvent(a, ctx, argo.EventReasonResourceUpdated, "updated application") } return out, err }
go
func (s *Server) Update(ctx context.Context, q *ApplicationUpdateRequest) (*appv1.Application, error) { if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceApplications, rbacpolicy.ActionUpdate, appRBACName(*q.Application)); err != nil { return nil, err } s.projectLock.Lock(q.Application.Spec.Project) defer s.projectLock.Unlock(q.Application.Spec.Project) a := q.Application err := s.validateAndNormalizeApp(ctx, a) if err != nil { return nil, err } out, err := s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Update(a) if err == nil { s.logEvent(a, ctx, argo.EventReasonResourceUpdated, "updated application") } return out, err }
[ "func", "(", "s", "*", "Server", ")", "Update", "(", "ctx", "context", ".", "Context", ",", "q", "*", "ApplicationUpdateRequest", ")", "(", "*", "appv1", ".", "Application", ",", "error", ")", "{", "if", "err", ":=", "s", ".", "enf", ".", "EnforceErr", "(", "ctx", ".", "Value", "(", "\"", "\"", ")", ",", "rbacpolicy", ".", "ResourceApplications", ",", "rbacpolicy", ".", "ActionUpdate", ",", "appRBACName", "(", "*", "q", ".", "Application", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "s", ".", "projectLock", ".", "Lock", "(", "q", ".", "Application", ".", "Spec", ".", "Project", ")", "\n", "defer", "s", ".", "projectLock", ".", "Unlock", "(", "q", ".", "Application", ".", "Spec", ".", "Project", ")", "\n\n", "a", ":=", "q", ".", "Application", "\n", "err", ":=", "s", ".", "validateAndNormalizeApp", "(", "ctx", ",", "a", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "out", ",", "err", ":=", "s", ".", "appclientset", ".", "ArgoprojV1alpha1", "(", ")", ".", "Applications", "(", "s", ".", "ns", ")", ".", "Update", "(", "a", ")", "\n", "if", "err", "==", "nil", "{", "s", ".", "logEvent", "(", "a", ",", "ctx", ",", "argo", ".", "EventReasonResourceUpdated", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "out", ",", "err", "\n", "}" ]
// Update updates an application
[ "Update", "updates", "an", "application" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/application/application.go#L282-L300
161,747
argoproj/argo-cd
server/application/application.go
UpdateSpec
func (s *Server) UpdateSpec(ctx context.Context, q *ApplicationUpdateSpecRequest) (*appv1.ApplicationSpec, error) { s.projectLock.Lock(q.Spec.Project) defer s.projectLock.Unlock(q.Spec.Project) a, err := s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Get(*q.Name, metav1.GetOptions{}) if err != nil { return nil, err } if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceApplications, rbacpolicy.ActionUpdate, appRBACName(*a)); err != nil { return nil, err } a.Spec = q.Spec err = s.validateAndNormalizeApp(ctx, a) if err != nil { return nil, err } normalizedSpec := a.Spec.DeepCopy() for i := 0; i < 10; i++ { a.Spec = *normalizedSpec _, err = s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Update(a) if err == nil { s.logEvent(a, ctx, argo.EventReasonResourceUpdated, "updated application spec") return normalizedSpec, nil } if !apierr.IsConflict(err) { return nil, err } a, err = s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Get(*q.Name, metav1.GetOptions{}) if err != nil { return nil, err } } return nil, status.Errorf(codes.Internal, "Failed to update application spec. Too many conflicts") }
go
func (s *Server) UpdateSpec(ctx context.Context, q *ApplicationUpdateSpecRequest) (*appv1.ApplicationSpec, error) { s.projectLock.Lock(q.Spec.Project) defer s.projectLock.Unlock(q.Spec.Project) a, err := s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Get(*q.Name, metav1.GetOptions{}) if err != nil { return nil, err } if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceApplications, rbacpolicy.ActionUpdate, appRBACName(*a)); err != nil { return nil, err } a.Spec = q.Spec err = s.validateAndNormalizeApp(ctx, a) if err != nil { return nil, err } normalizedSpec := a.Spec.DeepCopy() for i := 0; i < 10; i++ { a.Spec = *normalizedSpec _, err = s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Update(a) if err == nil { s.logEvent(a, ctx, argo.EventReasonResourceUpdated, "updated application spec") return normalizedSpec, nil } if !apierr.IsConflict(err) { return nil, err } a, err = s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Get(*q.Name, metav1.GetOptions{}) if err != nil { return nil, err } } return nil, status.Errorf(codes.Internal, "Failed to update application spec. Too many conflicts") }
[ "func", "(", "s", "*", "Server", ")", "UpdateSpec", "(", "ctx", "context", ".", "Context", ",", "q", "*", "ApplicationUpdateSpecRequest", ")", "(", "*", "appv1", ".", "ApplicationSpec", ",", "error", ")", "{", "s", ".", "projectLock", ".", "Lock", "(", "q", ".", "Spec", ".", "Project", ")", "\n", "defer", "s", ".", "projectLock", ".", "Unlock", "(", "q", ".", "Spec", ".", "Project", ")", "\n\n", "a", ",", "err", ":=", "s", ".", "appclientset", ".", "ArgoprojV1alpha1", "(", ")", ".", "Applications", "(", "s", ".", "ns", ")", ".", "Get", "(", "*", "q", ".", "Name", ",", "metav1", ".", "GetOptions", "{", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", ":=", "s", ".", "enf", ".", "EnforceErr", "(", "ctx", ".", "Value", "(", "\"", "\"", ")", ",", "rbacpolicy", ".", "ResourceApplications", ",", "rbacpolicy", ".", "ActionUpdate", ",", "appRBACName", "(", "*", "a", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "a", ".", "Spec", "=", "q", ".", "Spec", "\n", "err", "=", "s", ".", "validateAndNormalizeApp", "(", "ctx", ",", "a", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "normalizedSpec", ":=", "a", ".", "Spec", ".", "DeepCopy", "(", ")", "\n\n", "for", "i", ":=", "0", ";", "i", "<", "10", ";", "i", "++", "{", "a", ".", "Spec", "=", "*", "normalizedSpec", "\n", "_", ",", "err", "=", "s", ".", "appclientset", ".", "ArgoprojV1alpha1", "(", ")", ".", "Applications", "(", "s", ".", "ns", ")", ".", "Update", "(", "a", ")", "\n", "if", "err", "==", "nil", "{", "s", ".", "logEvent", "(", "a", ",", "ctx", ",", "argo", ".", "EventReasonResourceUpdated", ",", "\"", "\"", ")", "\n", "return", "normalizedSpec", ",", "nil", "\n", "}", "\n", "if", "!", "apierr", ".", "IsConflict", "(", "err", ")", "{", "return", "nil", ",", "err", "\n", "}", "\n", "a", ",", "err", "=", "s", ".", "appclientset", ".", "ArgoprojV1alpha1", "(", ")", ".", "Applications", "(", "s", ".", "ns", ")", ".", "Get", "(", "*", "q", ".", "Name", ",", "metav1", ".", "GetOptions", "{", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "Internal", ",", "\"", "\"", ")", "\n", "}" ]
// UpdateSpec updates an application spec and filters out any invalid parameter overrides
[ "UpdateSpec", "updates", "an", "application", "spec", "and", "filters", "out", "any", "invalid", "parameter", "overrides" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/application/application.go#L303-L337
161,748
argoproj/argo-cd
server/application/application.go
Patch
func (s *Server) Patch(ctx context.Context, q *ApplicationPatchRequest) (*appv1.Application, error) { patch, err := jsonpatch.DecodePatch([]byte(q.Patch)) if err != nil { return nil, err } app, err := s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Get(*q.Name, metav1.GetOptions{}) if err != nil { return nil, err } if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceApplications, rbacpolicy.ActionUpdate, appRBACName(*app)); err != nil { return nil, err } jsonApp, err := json.Marshal(app) if err != nil { return nil, err } patchApp, err := patch.Apply(jsonApp) if err != nil { return nil, err } s.logEvent(app, ctx, argo.EventReasonResourceUpdated, fmt.Sprintf("patched application %s/%s", app.Namespace, app.Name)) err = json.Unmarshal(patchApp, &app) if err != nil { return nil, err } err = s.validateAndNormalizeApp(ctx, app) if err != nil { return nil, err } return s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Update(app) }
go
func (s *Server) Patch(ctx context.Context, q *ApplicationPatchRequest) (*appv1.Application, error) { patch, err := jsonpatch.DecodePatch([]byte(q.Patch)) if err != nil { return nil, err } app, err := s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Get(*q.Name, metav1.GetOptions{}) if err != nil { return nil, err } if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceApplications, rbacpolicy.ActionUpdate, appRBACName(*app)); err != nil { return nil, err } jsonApp, err := json.Marshal(app) if err != nil { return nil, err } patchApp, err := patch.Apply(jsonApp) if err != nil { return nil, err } s.logEvent(app, ctx, argo.EventReasonResourceUpdated, fmt.Sprintf("patched application %s/%s", app.Namespace, app.Name)) err = json.Unmarshal(patchApp, &app) if err != nil { return nil, err } err = s.validateAndNormalizeApp(ctx, app) if err != nil { return nil, err } return s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Update(app) }
[ "func", "(", "s", "*", "Server", ")", "Patch", "(", "ctx", "context", ".", "Context", ",", "q", "*", "ApplicationPatchRequest", ")", "(", "*", "appv1", ".", "Application", ",", "error", ")", "{", "patch", ",", "err", ":=", "jsonpatch", ".", "DecodePatch", "(", "[", "]", "byte", "(", "q", ".", "Patch", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "app", ",", "err", ":=", "s", ".", "appclientset", ".", "ArgoprojV1alpha1", "(", ")", ".", "Applications", "(", "s", ".", "ns", ")", ".", "Get", "(", "*", "q", ".", "Name", ",", "metav1", ".", "GetOptions", "{", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", ":=", "s", ".", "enf", ".", "EnforceErr", "(", "ctx", ".", "Value", "(", "\"", "\"", ")", ",", "rbacpolicy", ".", "ResourceApplications", ",", "rbacpolicy", ".", "ActionUpdate", ",", "appRBACName", "(", "*", "app", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "jsonApp", ",", "err", ":=", "json", ".", "Marshal", "(", "app", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "patchApp", ",", "err", ":=", "patch", ".", "Apply", "(", "jsonApp", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "s", ".", "logEvent", "(", "app", ",", "ctx", ",", "argo", ".", "EventReasonResourceUpdated", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "app", ".", "Namespace", ",", "app", ".", "Name", ")", ")", "\n\n", "err", "=", "json", ".", "Unmarshal", "(", "patchApp", ",", "&", "app", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "err", "=", "s", ".", "validateAndNormalizeApp", "(", "ctx", ",", "app", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "s", ".", "appclientset", ".", "ArgoprojV1alpha1", "(", ")", ".", "Applications", "(", "s", ".", "ns", ")", ".", "Update", "(", "app", ")", "\n", "}" ]
// Patch patches an application
[ "Patch", "patches", "an", "application" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/application/application.go#L340-L379
161,749
argoproj/argo-cd
server/application/application.go
Delete
func (s *Server) Delete(ctx context.Context, q *ApplicationDeleteRequest) (*ApplicationResponse, error) { a, err := s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Get(*q.Name, metav1.GetOptions{}) if err != nil && !apierr.IsNotFound(err) { return nil, err } s.projectLock.Lock(a.Spec.Project) defer s.projectLock.Unlock(a.Spec.Project) if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceApplications, rbacpolicy.ActionDelete, appRBACName(*a)); err != nil { return nil, err } patchFinalizer := false if q.Cascade == nil || *q.Cascade { if !a.CascadedDeletion() { a.SetCascadedDeletion(true) patchFinalizer = true } } else { if a.CascadedDeletion() { a.SetCascadedDeletion(false) patchFinalizer = true } } if patchFinalizer { // Prior to v0.6, the cascaded deletion finalizer was set during app creation. // For backward compatibility, we always calculate the patch to see if we need to // set/unset the finalizer (in case we are dealing with an app created prior to v0.6) patch, err := json.Marshal(map[string]interface{}{ "metadata": map[string]interface{}{ "finalizers": a.Finalizers, }, }) if err != nil { return nil, err } _, err = s.appclientset.ArgoprojV1alpha1().Applications(a.Namespace).Patch(a.Name, types.MergePatchType, patch) if err != nil { return nil, err } } err = s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Delete(*q.Name, &metav1.DeleteOptions{}) if err != nil && !apierr.IsNotFound(err) { return nil, err } s.logEvent(a, ctx, argo.EventReasonResourceDeleted, "deleted application") return &ApplicationResponse{}, nil }
go
func (s *Server) Delete(ctx context.Context, q *ApplicationDeleteRequest) (*ApplicationResponse, error) { a, err := s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Get(*q.Name, metav1.GetOptions{}) if err != nil && !apierr.IsNotFound(err) { return nil, err } s.projectLock.Lock(a.Spec.Project) defer s.projectLock.Unlock(a.Spec.Project) if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceApplications, rbacpolicy.ActionDelete, appRBACName(*a)); err != nil { return nil, err } patchFinalizer := false if q.Cascade == nil || *q.Cascade { if !a.CascadedDeletion() { a.SetCascadedDeletion(true) patchFinalizer = true } } else { if a.CascadedDeletion() { a.SetCascadedDeletion(false) patchFinalizer = true } } if patchFinalizer { // Prior to v0.6, the cascaded deletion finalizer was set during app creation. // For backward compatibility, we always calculate the patch to see if we need to // set/unset the finalizer (in case we are dealing with an app created prior to v0.6) patch, err := json.Marshal(map[string]interface{}{ "metadata": map[string]interface{}{ "finalizers": a.Finalizers, }, }) if err != nil { return nil, err } _, err = s.appclientset.ArgoprojV1alpha1().Applications(a.Namespace).Patch(a.Name, types.MergePatchType, patch) if err != nil { return nil, err } } err = s.appclientset.ArgoprojV1alpha1().Applications(s.ns).Delete(*q.Name, &metav1.DeleteOptions{}) if err != nil && !apierr.IsNotFound(err) { return nil, err } s.logEvent(a, ctx, argo.EventReasonResourceDeleted, "deleted application") return &ApplicationResponse{}, nil }
[ "func", "(", "s", "*", "Server", ")", "Delete", "(", "ctx", "context", ".", "Context", ",", "q", "*", "ApplicationDeleteRequest", ")", "(", "*", "ApplicationResponse", ",", "error", ")", "{", "a", ",", "err", ":=", "s", ".", "appclientset", ".", "ArgoprojV1alpha1", "(", ")", ".", "Applications", "(", "s", ".", "ns", ")", ".", "Get", "(", "*", "q", ".", "Name", ",", "metav1", ".", "GetOptions", "{", "}", ")", "\n", "if", "err", "!=", "nil", "&&", "!", "apierr", ".", "IsNotFound", "(", "err", ")", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "s", ".", "projectLock", ".", "Lock", "(", "a", ".", "Spec", ".", "Project", ")", "\n", "defer", "s", ".", "projectLock", ".", "Unlock", "(", "a", ".", "Spec", ".", "Project", ")", "\n\n", "if", "err", ":=", "s", ".", "enf", ".", "EnforceErr", "(", "ctx", ".", "Value", "(", "\"", "\"", ")", ",", "rbacpolicy", ".", "ResourceApplications", ",", "rbacpolicy", ".", "ActionDelete", ",", "appRBACName", "(", "*", "a", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "patchFinalizer", ":=", "false", "\n", "if", "q", ".", "Cascade", "==", "nil", "||", "*", "q", ".", "Cascade", "{", "if", "!", "a", ".", "CascadedDeletion", "(", ")", "{", "a", ".", "SetCascadedDeletion", "(", "true", ")", "\n", "patchFinalizer", "=", "true", "\n", "}", "\n", "}", "else", "{", "if", "a", ".", "CascadedDeletion", "(", ")", "{", "a", ".", "SetCascadedDeletion", "(", "false", ")", "\n", "patchFinalizer", "=", "true", "\n", "}", "\n", "}", "\n\n", "if", "patchFinalizer", "{", "// Prior to v0.6, the cascaded deletion finalizer was set during app creation.", "// For backward compatibility, we always calculate the patch to see if we need to", "// set/unset the finalizer (in case we are dealing with an app created prior to v0.6)", "patch", ",", "err", ":=", "json", ".", "Marshal", "(", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "a", ".", "Finalizers", ",", "}", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "_", ",", "err", "=", "s", ".", "appclientset", ".", "ArgoprojV1alpha1", "(", ")", ".", "Applications", "(", "a", ".", "Namespace", ")", ".", "Patch", "(", "a", ".", "Name", ",", "types", ".", "MergePatchType", ",", "patch", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n\n", "err", "=", "s", ".", "appclientset", ".", "ArgoprojV1alpha1", "(", ")", ".", "Applications", "(", "s", ".", "ns", ")", ".", "Delete", "(", "*", "q", ".", "Name", ",", "&", "metav1", ".", "DeleteOptions", "{", "}", ")", "\n", "if", "err", "!=", "nil", "&&", "!", "apierr", ".", "IsNotFound", "(", "err", ")", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "s", ".", "logEvent", "(", "a", ",", "ctx", ",", "argo", ".", "EventReasonResourceDeleted", ",", "\"", "\"", ")", "\n", "return", "&", "ApplicationResponse", "{", "}", ",", "nil", "\n", "}" ]
// Delete removes an application and all associated resources
[ "Delete", "removes", "an", "application", "and", "all", "associated", "resources" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/application/application.go#L382-L433
161,750
argoproj/argo-cd
server/application/application.go
PatchResource
func (s *Server) PatchResource(ctx context.Context, q *ApplicationResourcePatchRequest) (*ApplicationResourceResponse, error) { resourceRequest := &ApplicationResourceRequest{ Name: q.Name, Namespace: q.Namespace, ResourceName: q.ResourceName, Kind: q.Kind, Version: q.Version, Group: q.Group, } res, config, a, err := s.getAppResource(ctx, rbacpolicy.ActionUpdate, resourceRequest) if err != nil { return nil, err } if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceApplications, rbacpolicy.ActionUpdate, appRBACName(*a)); err != nil { return nil, err } manifest, err := s.kubectl.PatchResource(config, res.GroupKindVersion(), res.Name, res.Namespace, types.PatchType(q.PatchType), []byte(q.Patch)) if err != nil { return nil, err } err = replaceSecretValues(manifest) if err != nil { return nil, err } data, err := json.Marshal(manifest.Object) if err != nil { return nil, err } s.logEvent(a, ctx, argo.EventReasonResourceUpdated, fmt.Sprintf("patched resource %s/%s '%s'", q.Group, q.Kind, q.ResourceName)) return &ApplicationResourceResponse{ Manifest: string(data), }, nil }
go
func (s *Server) PatchResource(ctx context.Context, q *ApplicationResourcePatchRequest) (*ApplicationResourceResponse, error) { resourceRequest := &ApplicationResourceRequest{ Name: q.Name, Namespace: q.Namespace, ResourceName: q.ResourceName, Kind: q.Kind, Version: q.Version, Group: q.Group, } res, config, a, err := s.getAppResource(ctx, rbacpolicy.ActionUpdate, resourceRequest) if err != nil { return nil, err } if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceApplications, rbacpolicy.ActionUpdate, appRBACName(*a)); err != nil { return nil, err } manifest, err := s.kubectl.PatchResource(config, res.GroupKindVersion(), res.Name, res.Namespace, types.PatchType(q.PatchType), []byte(q.Patch)) if err != nil { return nil, err } err = replaceSecretValues(manifest) if err != nil { return nil, err } data, err := json.Marshal(manifest.Object) if err != nil { return nil, err } s.logEvent(a, ctx, argo.EventReasonResourceUpdated, fmt.Sprintf("patched resource %s/%s '%s'", q.Group, q.Kind, q.ResourceName)) return &ApplicationResourceResponse{ Manifest: string(data), }, nil }
[ "func", "(", "s", "*", "Server", ")", "PatchResource", "(", "ctx", "context", ".", "Context", ",", "q", "*", "ApplicationResourcePatchRequest", ")", "(", "*", "ApplicationResourceResponse", ",", "error", ")", "{", "resourceRequest", ":=", "&", "ApplicationResourceRequest", "{", "Name", ":", "q", ".", "Name", ",", "Namespace", ":", "q", ".", "Namespace", ",", "ResourceName", ":", "q", ".", "ResourceName", ",", "Kind", ":", "q", ".", "Kind", ",", "Version", ":", "q", ".", "Version", ",", "Group", ":", "q", ".", "Group", ",", "}", "\n", "res", ",", "config", ",", "a", ",", "err", ":=", "s", ".", "getAppResource", "(", "ctx", ",", "rbacpolicy", ".", "ActionUpdate", ",", "resourceRequest", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", ":=", "s", ".", "enf", ".", "EnforceErr", "(", "ctx", ".", "Value", "(", "\"", "\"", ")", ",", "rbacpolicy", ".", "ResourceApplications", ",", "rbacpolicy", ".", "ActionUpdate", ",", "appRBACName", "(", "*", "a", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "manifest", ",", "err", ":=", "s", ".", "kubectl", ".", "PatchResource", "(", "config", ",", "res", ".", "GroupKindVersion", "(", ")", ",", "res", ".", "Name", ",", "res", ".", "Namespace", ",", "types", ".", "PatchType", "(", "q", ".", "PatchType", ")", ",", "[", "]", "byte", "(", "q", ".", "Patch", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "err", "=", "replaceSecretValues", "(", "manifest", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "data", ",", "err", ":=", "json", ".", "Marshal", "(", "manifest", ".", "Object", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "s", ".", "logEvent", "(", "a", ",", "ctx", ",", "argo", ".", "EventReasonResourceUpdated", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "q", ".", "Group", ",", "q", ".", "Kind", ",", "q", ".", "ResourceName", ")", ")", "\n", "return", "&", "ApplicationResourceResponse", "{", "Manifest", ":", "string", "(", "data", ")", ",", "}", ",", "nil", "\n", "}" ]
// PatchResource patches a resource
[ "PatchResource", "patches", "a", "resource" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/application/application.go#L601-L634
161,751
argoproj/argo-cd
server/application/application.go
DeleteResource
func (s *Server) DeleteResource(ctx context.Context, q *ApplicationResourceDeleteRequest) (*ApplicationResponse, error) { resourceRequest := &ApplicationResourceRequest{ Name: q.Name, Namespace: q.Namespace, ResourceName: q.ResourceName, Kind: q.Kind, Version: q.Version, Group: q.Group, } res, config, a, err := s.getAppResource(ctx, rbacpolicy.ActionDelete, resourceRequest) if err != nil { return nil, err } if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceApplications, rbacpolicy.ActionDelete, appRBACName(*a)); err != nil { return nil, err } var force bool if q.Force != nil { force = *q.Force } err = s.kubectl.DeleteResource(config, res.GroupKindVersion(), res.Name, res.Namespace, force) if err != nil { return nil, err } s.logEvent(a, ctx, argo.EventReasonResourceDeleted, fmt.Sprintf("deleted resource %s/%s '%s'", q.Group, q.Kind, q.ResourceName)) return &ApplicationResponse{}, nil }
go
func (s *Server) DeleteResource(ctx context.Context, q *ApplicationResourceDeleteRequest) (*ApplicationResponse, error) { resourceRequest := &ApplicationResourceRequest{ Name: q.Name, Namespace: q.Namespace, ResourceName: q.ResourceName, Kind: q.Kind, Version: q.Version, Group: q.Group, } res, config, a, err := s.getAppResource(ctx, rbacpolicy.ActionDelete, resourceRequest) if err != nil { return nil, err } if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceApplications, rbacpolicy.ActionDelete, appRBACName(*a)); err != nil { return nil, err } var force bool if q.Force != nil { force = *q.Force } err = s.kubectl.DeleteResource(config, res.GroupKindVersion(), res.Name, res.Namespace, force) if err != nil { return nil, err } s.logEvent(a, ctx, argo.EventReasonResourceDeleted, fmt.Sprintf("deleted resource %s/%s '%s'", q.Group, q.Kind, q.ResourceName)) return &ApplicationResponse{}, nil }
[ "func", "(", "s", "*", "Server", ")", "DeleteResource", "(", "ctx", "context", ".", "Context", ",", "q", "*", "ApplicationResourceDeleteRequest", ")", "(", "*", "ApplicationResponse", ",", "error", ")", "{", "resourceRequest", ":=", "&", "ApplicationResourceRequest", "{", "Name", ":", "q", ".", "Name", ",", "Namespace", ":", "q", ".", "Namespace", ",", "ResourceName", ":", "q", ".", "ResourceName", ",", "Kind", ":", "q", ".", "Kind", ",", "Version", ":", "q", ".", "Version", ",", "Group", ":", "q", ".", "Group", ",", "}", "\n", "res", ",", "config", ",", "a", ",", "err", ":=", "s", ".", "getAppResource", "(", "ctx", ",", "rbacpolicy", ".", "ActionDelete", ",", "resourceRequest", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "err", ":=", "s", ".", "enf", ".", "EnforceErr", "(", "ctx", ".", "Value", "(", "\"", "\"", ")", ",", "rbacpolicy", ".", "ResourceApplications", ",", "rbacpolicy", ".", "ActionDelete", ",", "appRBACName", "(", "*", "a", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "force", "bool", "\n", "if", "q", ".", "Force", "!=", "nil", "{", "force", "=", "*", "q", ".", "Force", "\n", "}", "\n", "err", "=", "s", ".", "kubectl", ".", "DeleteResource", "(", "config", ",", "res", ".", "GroupKindVersion", "(", ")", ",", "res", ".", "Name", ",", "res", ".", "Namespace", ",", "force", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "s", ".", "logEvent", "(", "a", ",", "ctx", ",", "argo", ".", "EventReasonResourceDeleted", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "q", ".", "Group", ",", "q", ".", "Kind", ",", "q", ".", "ResourceName", ")", ")", "\n", "return", "&", "ApplicationResponse", "{", "}", ",", "nil", "\n", "}" ]
// DeleteResource deletes a specificed resource
[ "DeleteResource", "deletes", "a", "specificed", "resource" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/application/application.go#L637-L664
161,752
argoproj/argo-cd
server/application/application.go
Sync
func (s *Server) Sync(ctx context.Context, syncReq *ApplicationSyncRequest) (*appv1.Application, error) { appIf := s.appclientset.ArgoprojV1alpha1().Applications(s.ns) a, err := appIf.Get(*syncReq.Name, metav1.GetOptions{}) if err != nil { return nil, err } if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceApplications, rbacpolicy.ActionSync, appRBACName(*a)); err != nil { return nil, err } if a.DeletionTimestamp != nil { return nil, status.Errorf(codes.FailedPrecondition, "application is deleting") } if a.Spec.SyncPolicy != nil && a.Spec.SyncPolicy.Automated != nil { if syncReq.Revision != "" && syncReq.Revision != a.Spec.Source.TargetRevision { return nil, status.Errorf(codes.FailedPrecondition, "Cannot sync to %s: auto-sync currently set to %s", syncReq.Revision, a.Spec.Source.TargetRevision) } } commitSHA, displayRevision, err := s.resolveRevision(ctx, a, syncReq) if err != nil { return nil, status.Errorf(codes.FailedPrecondition, err.Error()) } op := appv1.Operation{ Sync: &appv1.SyncOperation{ Revision: commitSHA, Prune: syncReq.Prune, DryRun: syncReq.DryRun, SyncStrategy: syncReq.Strategy, Resources: syncReq.Resources, }, } a, err = argo.SetAppOperation(appIf, *syncReq.Name, &op) if err == nil { partial := "" if len(syncReq.Resources) > 0 { partial = "partial " } s.logEvent(a, ctx, argo.EventReasonOperationStarted, fmt.Sprintf("initiated %ssync to %s", partial, displayRevision)) } return a, err }
go
func (s *Server) Sync(ctx context.Context, syncReq *ApplicationSyncRequest) (*appv1.Application, error) { appIf := s.appclientset.ArgoprojV1alpha1().Applications(s.ns) a, err := appIf.Get(*syncReq.Name, metav1.GetOptions{}) if err != nil { return nil, err } if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceApplications, rbacpolicy.ActionSync, appRBACName(*a)); err != nil { return nil, err } if a.DeletionTimestamp != nil { return nil, status.Errorf(codes.FailedPrecondition, "application is deleting") } if a.Spec.SyncPolicy != nil && a.Spec.SyncPolicy.Automated != nil { if syncReq.Revision != "" && syncReq.Revision != a.Spec.Source.TargetRevision { return nil, status.Errorf(codes.FailedPrecondition, "Cannot sync to %s: auto-sync currently set to %s", syncReq.Revision, a.Spec.Source.TargetRevision) } } commitSHA, displayRevision, err := s.resolveRevision(ctx, a, syncReq) if err != nil { return nil, status.Errorf(codes.FailedPrecondition, err.Error()) } op := appv1.Operation{ Sync: &appv1.SyncOperation{ Revision: commitSHA, Prune: syncReq.Prune, DryRun: syncReq.DryRun, SyncStrategy: syncReq.Strategy, Resources: syncReq.Resources, }, } a, err = argo.SetAppOperation(appIf, *syncReq.Name, &op) if err == nil { partial := "" if len(syncReq.Resources) > 0 { partial = "partial " } s.logEvent(a, ctx, argo.EventReasonOperationStarted, fmt.Sprintf("initiated %ssync to %s", partial, displayRevision)) } return a, err }
[ "func", "(", "s", "*", "Server", ")", "Sync", "(", "ctx", "context", ".", "Context", ",", "syncReq", "*", "ApplicationSyncRequest", ")", "(", "*", "appv1", ".", "Application", ",", "error", ")", "{", "appIf", ":=", "s", ".", "appclientset", ".", "ArgoprojV1alpha1", "(", ")", ".", "Applications", "(", "s", ".", "ns", ")", "\n", "a", ",", "err", ":=", "appIf", ".", "Get", "(", "*", "syncReq", ".", "Name", ",", "metav1", ".", "GetOptions", "{", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", ":=", "s", ".", "enf", ".", "EnforceErr", "(", "ctx", ".", "Value", "(", "\"", "\"", ")", ",", "rbacpolicy", ".", "ResourceApplications", ",", "rbacpolicy", ".", "ActionSync", ",", "appRBACName", "(", "*", "a", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "a", ".", "DeletionTimestamp", "!=", "nil", "{", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "FailedPrecondition", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "a", ".", "Spec", ".", "SyncPolicy", "!=", "nil", "&&", "a", ".", "Spec", ".", "SyncPolicy", ".", "Automated", "!=", "nil", "{", "if", "syncReq", ".", "Revision", "!=", "\"", "\"", "&&", "syncReq", ".", "Revision", "!=", "a", ".", "Spec", ".", "Source", ".", "TargetRevision", "{", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "FailedPrecondition", ",", "\"", "\"", ",", "syncReq", ".", "Revision", ",", "a", ".", "Spec", ".", "Source", ".", "TargetRevision", ")", "\n", "}", "\n", "}", "\n\n", "commitSHA", ",", "displayRevision", ",", "err", ":=", "s", ".", "resolveRevision", "(", "ctx", ",", "a", ",", "syncReq", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "status", ".", "Errorf", "(", "codes", ".", "FailedPrecondition", ",", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n\n", "op", ":=", "appv1", ".", "Operation", "{", "Sync", ":", "&", "appv1", ".", "SyncOperation", "{", "Revision", ":", "commitSHA", ",", "Prune", ":", "syncReq", ".", "Prune", ",", "DryRun", ":", "syncReq", ".", "DryRun", ",", "SyncStrategy", ":", "syncReq", ".", "Strategy", ",", "Resources", ":", "syncReq", ".", "Resources", ",", "}", ",", "}", "\n", "a", ",", "err", "=", "argo", ".", "SetAppOperation", "(", "appIf", ",", "*", "syncReq", ".", "Name", ",", "&", "op", ")", "\n", "if", "err", "==", "nil", "{", "partial", ":=", "\"", "\"", "\n", "if", "len", "(", "syncReq", ".", "Resources", ")", ">", "0", "{", "partial", "=", "\"", "\"", "\n", "}", "\n", "s", ".", "logEvent", "(", "a", ",", "ctx", ",", "argo", ".", "EventReasonOperationStarted", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "partial", ",", "displayRevision", ")", ")", "\n", "}", "\n", "return", "a", ",", "err", "\n", "}" ]
// Sync syncs an application to its target state
[ "Sync", "syncs", "an", "application", "to", "its", "target", "state" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/application/application.go#L792-L833
161,753
argoproj/argo-cd
server/application/application.go
resolveRevision
func (s *Server) resolveRevision(ctx context.Context, app *appv1.Application, syncReq *ApplicationSyncRequest) (string, string, error) { ambiguousRevision := syncReq.Revision if ambiguousRevision == "" { ambiguousRevision = app.Spec.Source.TargetRevision } if git.IsCommitSHA(ambiguousRevision) { // If it's already a commit SHA, then no need to look it up return ambiguousRevision, ambiguousRevision, nil } repo, err := s.db.GetRepository(ctx, app.Spec.Source.RepoURL) if err != nil { // If we couldn't retrieve from the repo service, assume public repositories repo = &appv1.Repository{Repo: app.Spec.Source.RepoURL} } gitClient, err := s.gitFactory.NewClient(repo.Repo, "", repo.Username, repo.Password, repo.SSHPrivateKey, repo.InsecureIgnoreHostKey) if err != nil { return "", "", err } commitSHA, err := gitClient.LsRemote(ambiguousRevision) if err != nil { return "", "", err } displayRevision := fmt.Sprintf("%s (%s)", ambiguousRevision, commitSHA) return commitSHA, displayRevision, nil }
go
func (s *Server) resolveRevision(ctx context.Context, app *appv1.Application, syncReq *ApplicationSyncRequest) (string, string, error) { ambiguousRevision := syncReq.Revision if ambiguousRevision == "" { ambiguousRevision = app.Spec.Source.TargetRevision } if git.IsCommitSHA(ambiguousRevision) { // If it's already a commit SHA, then no need to look it up return ambiguousRevision, ambiguousRevision, nil } repo, err := s.db.GetRepository(ctx, app.Spec.Source.RepoURL) if err != nil { // If we couldn't retrieve from the repo service, assume public repositories repo = &appv1.Repository{Repo: app.Spec.Source.RepoURL} } gitClient, err := s.gitFactory.NewClient(repo.Repo, "", repo.Username, repo.Password, repo.SSHPrivateKey, repo.InsecureIgnoreHostKey) if err != nil { return "", "", err } commitSHA, err := gitClient.LsRemote(ambiguousRevision) if err != nil { return "", "", err } displayRevision := fmt.Sprintf("%s (%s)", ambiguousRevision, commitSHA) return commitSHA, displayRevision, nil }
[ "func", "(", "s", "*", "Server", ")", "resolveRevision", "(", "ctx", "context", ".", "Context", ",", "app", "*", "appv1", ".", "Application", ",", "syncReq", "*", "ApplicationSyncRequest", ")", "(", "string", ",", "string", ",", "error", ")", "{", "ambiguousRevision", ":=", "syncReq", ".", "Revision", "\n", "if", "ambiguousRevision", "==", "\"", "\"", "{", "ambiguousRevision", "=", "app", ".", "Spec", ".", "Source", ".", "TargetRevision", "\n", "}", "\n", "if", "git", ".", "IsCommitSHA", "(", "ambiguousRevision", ")", "{", "// If it's already a commit SHA, then no need to look it up", "return", "ambiguousRevision", ",", "ambiguousRevision", ",", "nil", "\n", "}", "\n", "repo", ",", "err", ":=", "s", ".", "db", ".", "GetRepository", "(", "ctx", ",", "app", ".", "Spec", ".", "Source", ".", "RepoURL", ")", "\n", "if", "err", "!=", "nil", "{", "// If we couldn't retrieve from the repo service, assume public repositories", "repo", "=", "&", "appv1", ".", "Repository", "{", "Repo", ":", "app", ".", "Spec", ".", "Source", ".", "RepoURL", "}", "\n", "}", "\n", "gitClient", ",", "err", ":=", "s", ".", "gitFactory", ".", "NewClient", "(", "repo", ".", "Repo", ",", "\"", "\"", ",", "repo", ".", "Username", ",", "repo", ".", "Password", ",", "repo", ".", "SSHPrivateKey", ",", "repo", ".", "InsecureIgnoreHostKey", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "\"", "\"", ",", "err", "\n", "}", "\n", "commitSHA", ",", "err", ":=", "gitClient", ".", "LsRemote", "(", "ambiguousRevision", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "\"", "\"", ",", "err", "\n", "}", "\n", "displayRevision", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "ambiguousRevision", ",", "commitSHA", ")", "\n", "return", "commitSHA", ",", "displayRevision", ",", "nil", "\n", "}" ]
// resolveRevision resolves the git revision specified either in the sync request, or the // application source, into a concrete commit SHA that will be used for a sync operation.
[ "resolveRevision", "resolves", "the", "git", "revision", "specified", "either", "in", "the", "sync", "request", "or", "the", "application", "source", "into", "a", "concrete", "commit", "SHA", "that", "will", "be", "used", "for", "a", "sync", "operation", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/application/application.go#L886-L910
161,754
argoproj/argo-cd
util/dex/config.go
replaceMapSecrets
func replaceMapSecrets(obj map[string]interface{}, secretValues map[string]string) map[string]interface{} { newObj := make(map[string]interface{}) for k, v := range obj { switch val := v.(type) { case map[string]interface{}: newObj[k] = replaceMapSecrets(val, secretValues) case []interface{}: newObj[k] = replaceListSecrets(val, secretValues) case string: newObj[k] = settings.ReplaceStringSecret(val, secretValues) default: newObj[k] = val } } return newObj }
go
func replaceMapSecrets(obj map[string]interface{}, secretValues map[string]string) map[string]interface{} { newObj := make(map[string]interface{}) for k, v := range obj { switch val := v.(type) { case map[string]interface{}: newObj[k] = replaceMapSecrets(val, secretValues) case []interface{}: newObj[k] = replaceListSecrets(val, secretValues) case string: newObj[k] = settings.ReplaceStringSecret(val, secretValues) default: newObj[k] = val } } return newObj }
[ "func", "replaceMapSecrets", "(", "obj", "map", "[", "string", "]", "interface", "{", "}", ",", "secretValues", "map", "[", "string", "]", "string", ")", "map", "[", "string", "]", "interface", "{", "}", "{", "newObj", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "for", "k", ",", "v", ":=", "range", "obj", "{", "switch", "val", ":=", "v", ".", "(", "type", ")", "{", "case", "map", "[", "string", "]", "interface", "{", "}", ":", "newObj", "[", "k", "]", "=", "replaceMapSecrets", "(", "val", ",", "secretValues", ")", "\n", "case", "[", "]", "interface", "{", "}", ":", "newObj", "[", "k", "]", "=", "replaceListSecrets", "(", "val", ",", "secretValues", ")", "\n", "case", "string", ":", "newObj", "[", "k", "]", "=", "settings", ".", "ReplaceStringSecret", "(", "val", ",", "secretValues", ")", "\n", "default", ":", "newObj", "[", "k", "]", "=", "val", "\n", "}", "\n", "}", "\n", "return", "newObj", "\n", "}" ]
// replaceMapSecrets takes a json object and recursively looks for any secret key references in the // object and replaces the value with the secret value
[ "replaceMapSecrets", "takes", "a", "json", "object", "and", "recursively", "looks", "for", "any", "secret", "key", "references", "in", "the", "object", "and", "replaces", "the", "value", "with", "the", "secret", "value" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/dex/config.go#L71-L86
161,755
argoproj/argo-cd
server/server.go
initializeDefaultProject
func initializeDefaultProject(opts ArgoCDServerOpts) error { defaultProj := &v1alpha1.AppProject{ ObjectMeta: metav1.ObjectMeta{Name: common.DefaultAppProjectName, Namespace: opts.Namespace}, Spec: v1alpha1.AppProjectSpec{ SourceRepos: []string{"*"}, Destinations: []v1alpha1.ApplicationDestination{{Server: "*", Namespace: "*"}}, ClusterResourceWhitelist: []metav1.GroupKind{{Group: "*", Kind: "*"}}, }, } _, err := opts.AppClientset.ArgoprojV1alpha1().AppProjects(opts.Namespace).Create(defaultProj) if apierrors.IsAlreadyExists(err) { return nil } return err }
go
func initializeDefaultProject(opts ArgoCDServerOpts) error { defaultProj := &v1alpha1.AppProject{ ObjectMeta: metav1.ObjectMeta{Name: common.DefaultAppProjectName, Namespace: opts.Namespace}, Spec: v1alpha1.AppProjectSpec{ SourceRepos: []string{"*"}, Destinations: []v1alpha1.ApplicationDestination{{Server: "*", Namespace: "*"}}, ClusterResourceWhitelist: []metav1.GroupKind{{Group: "*", Kind: "*"}}, }, } _, err := opts.AppClientset.ArgoprojV1alpha1().AppProjects(opts.Namespace).Create(defaultProj) if apierrors.IsAlreadyExists(err) { return nil } return err }
[ "func", "initializeDefaultProject", "(", "opts", "ArgoCDServerOpts", ")", "error", "{", "defaultProj", ":=", "&", "v1alpha1", ".", "AppProject", "{", "ObjectMeta", ":", "metav1", ".", "ObjectMeta", "{", "Name", ":", "common", ".", "DefaultAppProjectName", ",", "Namespace", ":", "opts", ".", "Namespace", "}", ",", "Spec", ":", "v1alpha1", ".", "AppProjectSpec", "{", "SourceRepos", ":", "[", "]", "string", "{", "\"", "\"", "}", ",", "Destinations", ":", "[", "]", "v1alpha1", ".", "ApplicationDestination", "{", "{", "Server", ":", "\"", "\"", ",", "Namespace", ":", "\"", "\"", "}", "}", ",", "ClusterResourceWhitelist", ":", "[", "]", "metav1", ".", "GroupKind", "{", "{", "Group", ":", "\"", "\"", ",", "Kind", ":", "\"", "\"", "}", "}", ",", "}", ",", "}", "\n\n", "_", ",", "err", ":=", "opts", ".", "AppClientset", ".", "ArgoprojV1alpha1", "(", ")", ".", "AppProjects", "(", "opts", ".", "Namespace", ")", ".", "Create", "(", "defaultProj", ")", "\n", "if", "apierrors", ".", "IsAlreadyExists", "(", "err", ")", "{", "return", "nil", "\n", "}", "\n", "return", "err", "\n", "}" ]
// initializeDefaultProject creates the default project if it does not already exist
[ "initializeDefaultProject", "creates", "the", "default", "project", "if", "it", "does", "not", "already", "exist" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/server.go#L133-L148
161,756
argoproj/argo-cd
server/server.go
NewServer
func NewServer(ctx context.Context, opts ArgoCDServerOpts) *ArgoCDServer { settingsMgr := settings_util.NewSettingsManager(ctx, opts.KubeClientset, opts.Namespace) settings, err := settingsMgr.InitializeSettings() errors.CheckError(err) err = initializeDefaultProject(opts) errors.CheckError(err) sessionMgr := util_session.NewSessionManager(settingsMgr, opts.DexServerAddr) factory := appinformer.NewFilteredSharedInformerFactory(opts.AppClientset, 0, opts.Namespace, func(options *metav1.ListOptions) {}) projInformer := factory.Argoproj().V1alpha1().AppProjects().Informer() projLister := factory.Argoproj().V1alpha1().AppProjects().Lister().AppProjects(opts.Namespace) enf := rbac.NewEnforcer(opts.KubeClientset, opts.Namespace, common.ArgoCDRBACConfigMapName, nil) enf.EnableEnforce(!opts.DisableAuth) err = enf.SetBuiltinPolicy(assets.BuiltinPolicyCSV) errors.CheckError(err) enf.EnableLog(os.Getenv(common.EnvVarRBACDebug) == "1") policyEnf := rbacpolicy.NewRBACPolicyEnforcer(enf, projLister) enf.SetClaimsEnforcerFunc(policyEnf.EnforceClaims) return &ArgoCDServer{ ArgoCDServerOpts: opts, log: log.NewEntry(log.StandardLogger()), settings: settings, sessionMgr: sessionMgr, settingsMgr: settingsMgr, enf: enf, projInformer: projInformer, } }
go
func NewServer(ctx context.Context, opts ArgoCDServerOpts) *ArgoCDServer { settingsMgr := settings_util.NewSettingsManager(ctx, opts.KubeClientset, opts.Namespace) settings, err := settingsMgr.InitializeSettings() errors.CheckError(err) err = initializeDefaultProject(opts) errors.CheckError(err) sessionMgr := util_session.NewSessionManager(settingsMgr, opts.DexServerAddr) factory := appinformer.NewFilteredSharedInformerFactory(opts.AppClientset, 0, opts.Namespace, func(options *metav1.ListOptions) {}) projInformer := factory.Argoproj().V1alpha1().AppProjects().Informer() projLister := factory.Argoproj().V1alpha1().AppProjects().Lister().AppProjects(opts.Namespace) enf := rbac.NewEnforcer(opts.KubeClientset, opts.Namespace, common.ArgoCDRBACConfigMapName, nil) enf.EnableEnforce(!opts.DisableAuth) err = enf.SetBuiltinPolicy(assets.BuiltinPolicyCSV) errors.CheckError(err) enf.EnableLog(os.Getenv(common.EnvVarRBACDebug) == "1") policyEnf := rbacpolicy.NewRBACPolicyEnforcer(enf, projLister) enf.SetClaimsEnforcerFunc(policyEnf.EnforceClaims) return &ArgoCDServer{ ArgoCDServerOpts: opts, log: log.NewEntry(log.StandardLogger()), settings: settings, sessionMgr: sessionMgr, settingsMgr: settingsMgr, enf: enf, projInformer: projInformer, } }
[ "func", "NewServer", "(", "ctx", "context", ".", "Context", ",", "opts", "ArgoCDServerOpts", ")", "*", "ArgoCDServer", "{", "settingsMgr", ":=", "settings_util", ".", "NewSettingsManager", "(", "ctx", ",", "opts", ".", "KubeClientset", ",", "opts", ".", "Namespace", ")", "\n", "settings", ",", "err", ":=", "settingsMgr", ".", "InitializeSettings", "(", ")", "\n", "errors", ".", "CheckError", "(", "err", ")", "\n", "err", "=", "initializeDefaultProject", "(", "opts", ")", "\n", "errors", ".", "CheckError", "(", "err", ")", "\n", "sessionMgr", ":=", "util_session", ".", "NewSessionManager", "(", "settingsMgr", ",", "opts", ".", "DexServerAddr", ")", "\n\n", "factory", ":=", "appinformer", ".", "NewFilteredSharedInformerFactory", "(", "opts", ".", "AppClientset", ",", "0", ",", "opts", ".", "Namespace", ",", "func", "(", "options", "*", "metav1", ".", "ListOptions", ")", "{", "}", ")", "\n", "projInformer", ":=", "factory", ".", "Argoproj", "(", ")", ".", "V1alpha1", "(", ")", ".", "AppProjects", "(", ")", ".", "Informer", "(", ")", "\n", "projLister", ":=", "factory", ".", "Argoproj", "(", ")", ".", "V1alpha1", "(", ")", ".", "AppProjects", "(", ")", ".", "Lister", "(", ")", ".", "AppProjects", "(", "opts", ".", "Namespace", ")", "\n\n", "enf", ":=", "rbac", ".", "NewEnforcer", "(", "opts", ".", "KubeClientset", ",", "opts", ".", "Namespace", ",", "common", ".", "ArgoCDRBACConfigMapName", ",", "nil", ")", "\n", "enf", ".", "EnableEnforce", "(", "!", "opts", ".", "DisableAuth", ")", "\n", "err", "=", "enf", ".", "SetBuiltinPolicy", "(", "assets", ".", "BuiltinPolicyCSV", ")", "\n", "errors", ".", "CheckError", "(", "err", ")", "\n", "enf", ".", "EnableLog", "(", "os", ".", "Getenv", "(", "common", ".", "EnvVarRBACDebug", ")", "==", "\"", "\"", ")", "\n\n", "policyEnf", ":=", "rbacpolicy", ".", "NewRBACPolicyEnforcer", "(", "enf", ",", "projLister", ")", "\n", "enf", ".", "SetClaimsEnforcerFunc", "(", "policyEnf", ".", "EnforceClaims", ")", "\n\n", "return", "&", "ArgoCDServer", "{", "ArgoCDServerOpts", ":", "opts", ",", "log", ":", "log", ".", "NewEntry", "(", "log", ".", "StandardLogger", "(", ")", ")", ",", "settings", ":", "settings", ",", "sessionMgr", ":", "sessionMgr", ",", "settingsMgr", ":", "settingsMgr", ",", "enf", ":", "enf", ",", "projInformer", ":", "projInformer", ",", "}", "\n", "}" ]
// NewServer returns a new instance of the Argo CD API server
[ "NewServer", "returns", "a", "new", "instance", "of", "the", "Argo", "CD", "API", "server" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/server.go#L151-L181
161,757
argoproj/argo-cd
server/server.go
Shutdown
func (a *ArgoCDServer) Shutdown() { log.Info("Shut down requested") stopCh := a.stopCh a.stopCh = nil if stopCh != nil { close(stopCh) } }
go
func (a *ArgoCDServer) Shutdown() { log.Info("Shut down requested") stopCh := a.stopCh a.stopCh = nil if stopCh != nil { close(stopCh) } }
[ "func", "(", "a", "*", "ArgoCDServer", ")", "Shutdown", "(", ")", "{", "log", ".", "Info", "(", "\"", "\"", ")", "\n", "stopCh", ":=", "a", ".", "stopCh", "\n", "a", ".", "stopCh", "=", "nil", "\n", "if", "stopCh", "!=", "nil", "{", "close", "(", "stopCh", ")", "\n", "}", "\n", "}" ]
// Shutdown stops the Argo CD server
[ "Shutdown", "stops", "the", "Argo", "CD", "server" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/server.go#L281-L288
161,758
argoproj/argo-cd
server/server.go
watchSettings
func (a *ArgoCDServer) watchSettings(ctx context.Context) { updateCh := make(chan *settings_util.ArgoCDSettings, 1) a.settingsMgr.Subscribe(updateCh) prevURL := a.settings.URL prevOIDCConfig := a.settings.OIDCConfigRAW prevDexCfgBytes, err := dex.GenerateDexConfigYAML(a.settings) errors.CheckError(err) prevGitHubSecret := a.settings.WebhookGitHubSecret prevGitLabSecret := a.settings.WebhookGitLabSecret prevBitBucketUUID := a.settings.WebhookBitbucketUUID var prevCert, prevCertKey string if a.settings.Certificate != nil { prevCert, prevCertKey = tlsutil.EncodeX509KeyPairString(*a.settings.Certificate) } for { newSettings := <-updateCh a.settings = newSettings newDexCfgBytes, err := dex.GenerateDexConfigYAML(a.settings) errors.CheckError(err) if string(newDexCfgBytes) != string(prevDexCfgBytes) { log.Infof("dex config modified. restarting") break } if prevOIDCConfig != a.settings.OIDCConfigRAW { log.Infof("odic config modified. restarting") break } if prevURL != a.settings.URL { log.Infof("url modified. restarting") break } if prevGitHubSecret != a.settings.WebhookGitHubSecret { log.Infof("github secret modified. restarting") break } if prevGitLabSecret != a.settings.WebhookGitLabSecret { log.Infof("gitlab secret modified. restarting") break } if prevBitBucketUUID != a.settings.WebhookBitbucketUUID { log.Infof("bitbucket uuid modified. restarting") break } var newCert, newCertKey string if a.settings.Certificate != nil { newCert, newCertKey = tlsutil.EncodeX509KeyPairString(*a.settings.Certificate) } if newCert != prevCert || newCertKey != prevCertKey { log.Infof("tls certificate modified. restarting") break } } log.Info("shutting down settings watch") a.Shutdown() a.settingsMgr.Unsubscribe(updateCh) close(updateCh) }
go
func (a *ArgoCDServer) watchSettings(ctx context.Context) { updateCh := make(chan *settings_util.ArgoCDSettings, 1) a.settingsMgr.Subscribe(updateCh) prevURL := a.settings.URL prevOIDCConfig := a.settings.OIDCConfigRAW prevDexCfgBytes, err := dex.GenerateDexConfigYAML(a.settings) errors.CheckError(err) prevGitHubSecret := a.settings.WebhookGitHubSecret prevGitLabSecret := a.settings.WebhookGitLabSecret prevBitBucketUUID := a.settings.WebhookBitbucketUUID var prevCert, prevCertKey string if a.settings.Certificate != nil { prevCert, prevCertKey = tlsutil.EncodeX509KeyPairString(*a.settings.Certificate) } for { newSettings := <-updateCh a.settings = newSettings newDexCfgBytes, err := dex.GenerateDexConfigYAML(a.settings) errors.CheckError(err) if string(newDexCfgBytes) != string(prevDexCfgBytes) { log.Infof("dex config modified. restarting") break } if prevOIDCConfig != a.settings.OIDCConfigRAW { log.Infof("odic config modified. restarting") break } if prevURL != a.settings.URL { log.Infof("url modified. restarting") break } if prevGitHubSecret != a.settings.WebhookGitHubSecret { log.Infof("github secret modified. restarting") break } if prevGitLabSecret != a.settings.WebhookGitLabSecret { log.Infof("gitlab secret modified. restarting") break } if prevBitBucketUUID != a.settings.WebhookBitbucketUUID { log.Infof("bitbucket uuid modified. restarting") break } var newCert, newCertKey string if a.settings.Certificate != nil { newCert, newCertKey = tlsutil.EncodeX509KeyPairString(*a.settings.Certificate) } if newCert != prevCert || newCertKey != prevCertKey { log.Infof("tls certificate modified. restarting") break } } log.Info("shutting down settings watch") a.Shutdown() a.settingsMgr.Unsubscribe(updateCh) close(updateCh) }
[ "func", "(", "a", "*", "ArgoCDServer", ")", "watchSettings", "(", "ctx", "context", ".", "Context", ")", "{", "updateCh", ":=", "make", "(", "chan", "*", "settings_util", ".", "ArgoCDSettings", ",", "1", ")", "\n", "a", ".", "settingsMgr", ".", "Subscribe", "(", "updateCh", ")", "\n\n", "prevURL", ":=", "a", ".", "settings", ".", "URL", "\n", "prevOIDCConfig", ":=", "a", ".", "settings", ".", "OIDCConfigRAW", "\n", "prevDexCfgBytes", ",", "err", ":=", "dex", ".", "GenerateDexConfigYAML", "(", "a", ".", "settings", ")", "\n", "errors", ".", "CheckError", "(", "err", ")", "\n", "prevGitHubSecret", ":=", "a", ".", "settings", ".", "WebhookGitHubSecret", "\n", "prevGitLabSecret", ":=", "a", ".", "settings", ".", "WebhookGitLabSecret", "\n", "prevBitBucketUUID", ":=", "a", ".", "settings", ".", "WebhookBitbucketUUID", "\n", "var", "prevCert", ",", "prevCertKey", "string", "\n", "if", "a", ".", "settings", ".", "Certificate", "!=", "nil", "{", "prevCert", ",", "prevCertKey", "=", "tlsutil", ".", "EncodeX509KeyPairString", "(", "*", "a", ".", "settings", ".", "Certificate", ")", "\n", "}", "\n\n", "for", "{", "newSettings", ":=", "<-", "updateCh", "\n", "a", ".", "settings", "=", "newSettings", "\n", "newDexCfgBytes", ",", "err", ":=", "dex", ".", "GenerateDexConfigYAML", "(", "a", ".", "settings", ")", "\n", "errors", ".", "CheckError", "(", "err", ")", "\n", "if", "string", "(", "newDexCfgBytes", ")", "!=", "string", "(", "prevDexCfgBytes", ")", "{", "log", ".", "Infof", "(", "\"", "\"", ")", "\n", "break", "\n", "}", "\n", "if", "prevOIDCConfig", "!=", "a", ".", "settings", ".", "OIDCConfigRAW", "{", "log", ".", "Infof", "(", "\"", "\"", ")", "\n", "break", "\n", "}", "\n", "if", "prevURL", "!=", "a", ".", "settings", ".", "URL", "{", "log", ".", "Infof", "(", "\"", "\"", ")", "\n", "break", "\n", "}", "\n", "if", "prevGitHubSecret", "!=", "a", ".", "settings", ".", "WebhookGitHubSecret", "{", "log", ".", "Infof", "(", "\"", "\"", ")", "\n", "break", "\n", "}", "\n", "if", "prevGitLabSecret", "!=", "a", ".", "settings", ".", "WebhookGitLabSecret", "{", "log", ".", "Infof", "(", "\"", "\"", ")", "\n", "break", "\n", "}", "\n", "if", "prevBitBucketUUID", "!=", "a", ".", "settings", ".", "WebhookBitbucketUUID", "{", "log", ".", "Infof", "(", "\"", "\"", ")", "\n", "break", "\n", "}", "\n", "var", "newCert", ",", "newCertKey", "string", "\n", "if", "a", ".", "settings", ".", "Certificate", "!=", "nil", "{", "newCert", ",", "newCertKey", "=", "tlsutil", ".", "EncodeX509KeyPairString", "(", "*", "a", ".", "settings", ".", "Certificate", ")", "\n", "}", "\n", "if", "newCert", "!=", "prevCert", "||", "newCertKey", "!=", "prevCertKey", "{", "log", ".", "Infof", "(", "\"", "\"", ")", "\n", "break", "\n", "}", "\n", "}", "\n", "log", ".", "Info", "(", "\"", "\"", ")", "\n", "a", ".", "Shutdown", "(", ")", "\n", "a", ".", "settingsMgr", ".", "Unsubscribe", "(", "updateCh", ")", "\n", "close", "(", "updateCh", ")", "\n", "}" ]
// watchSettings watches the configmap and secret for any setting updates that would warrant a // restart of the API server.
[ "watchSettings", "watches", "the", "configmap", "and", "secret", "for", "any", "setting", "updates", "that", "would", "warrant", "a", "restart", "of", "the", "API", "server", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/server.go#L292-L350
161,759
argoproj/argo-cd
server/server.go
translateGrpcCookieHeader
func (a *ArgoCDServer) translateGrpcCookieHeader(ctx context.Context, w http.ResponseWriter, resp golang_proto.Message) error { if sessionResp, ok := resp.(*session.SessionResponse); ok { flags := []string{"path=/"} if !a.Insecure { flags = append(flags, "Secure") } cookie, err := httputil.MakeCookieMetadata(common.AuthCookieName, sessionResp.Token, flags...) if err != nil { return err } w.Header().Set("Set-Cookie", cookie) } return nil }
go
func (a *ArgoCDServer) translateGrpcCookieHeader(ctx context.Context, w http.ResponseWriter, resp golang_proto.Message) error { if sessionResp, ok := resp.(*session.SessionResponse); ok { flags := []string{"path=/"} if !a.Insecure { flags = append(flags, "Secure") } cookie, err := httputil.MakeCookieMetadata(common.AuthCookieName, sessionResp.Token, flags...) if err != nil { return err } w.Header().Set("Set-Cookie", cookie) } return nil }
[ "func", "(", "a", "*", "ArgoCDServer", ")", "translateGrpcCookieHeader", "(", "ctx", "context", ".", "Context", ",", "w", "http", ".", "ResponseWriter", ",", "resp", "golang_proto", ".", "Message", ")", "error", "{", "if", "sessionResp", ",", "ok", ":=", "resp", ".", "(", "*", "session", ".", "SessionResponse", ")", ";", "ok", "{", "flags", ":=", "[", "]", "string", "{", "\"", "\"", "}", "\n", "if", "!", "a", ".", "Insecure", "{", "flags", "=", "append", "(", "flags", ",", "\"", "\"", ")", "\n", "}", "\n", "cookie", ",", "err", ":=", "httputil", ".", "MakeCookieMetadata", "(", "common", ".", "AuthCookieName", ",", "sessionResp", ".", "Token", ",", "flags", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "w", ".", "Header", "(", ")", ".", "Set", "(", "\"", "\"", ",", "cookie", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// TranslateGrpcCookieHeader conditionally sets a cookie on the response.
[ "TranslateGrpcCookieHeader", "conditionally", "sets", "a", "cookie", "on", "the", "response", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/server.go#L432-L446
161,760
argoproj/argo-cd
server/server.go
registerDexHandlers
func (a *ArgoCDServer) registerDexHandlers(mux *http.ServeMux) { if !a.settings.IsSSOConfigured() { return } // Run dex OpenID Connect Identity Provider behind a reverse proxy (served at /api/dex) var err error mux.HandleFunc(common.DexAPIEndpoint+"/", dexutil.NewDexHTTPReverseProxy(a.DexServerAddr)) tlsConfig := a.settings.TLSConfig() tlsConfig.InsecureSkipVerify = true a.ssoClientApp, err = oidc.NewClientApp(a.settings, a.Cache, a.DexServerAddr) errors.CheckError(err) mux.HandleFunc(common.LoginEndpoint, a.ssoClientApp.HandleLogin) mux.HandleFunc(common.CallbackEndpoint, a.ssoClientApp.HandleCallback) }
go
func (a *ArgoCDServer) registerDexHandlers(mux *http.ServeMux) { if !a.settings.IsSSOConfigured() { return } // Run dex OpenID Connect Identity Provider behind a reverse proxy (served at /api/dex) var err error mux.HandleFunc(common.DexAPIEndpoint+"/", dexutil.NewDexHTTPReverseProxy(a.DexServerAddr)) tlsConfig := a.settings.TLSConfig() tlsConfig.InsecureSkipVerify = true a.ssoClientApp, err = oidc.NewClientApp(a.settings, a.Cache, a.DexServerAddr) errors.CheckError(err) mux.HandleFunc(common.LoginEndpoint, a.ssoClientApp.HandleLogin) mux.HandleFunc(common.CallbackEndpoint, a.ssoClientApp.HandleCallback) }
[ "func", "(", "a", "*", "ArgoCDServer", ")", "registerDexHandlers", "(", "mux", "*", "http", ".", "ServeMux", ")", "{", "if", "!", "a", ".", "settings", ".", "IsSSOConfigured", "(", ")", "{", "return", "\n", "}", "\n", "// Run dex OpenID Connect Identity Provider behind a reverse proxy (served at /api/dex)", "var", "err", "error", "\n", "mux", ".", "HandleFunc", "(", "common", ".", "DexAPIEndpoint", "+", "\"", "\"", ",", "dexutil", ".", "NewDexHTTPReverseProxy", "(", "a", ".", "DexServerAddr", ")", ")", "\n", "tlsConfig", ":=", "a", ".", "settings", ".", "TLSConfig", "(", ")", "\n", "tlsConfig", ".", "InsecureSkipVerify", "=", "true", "\n", "a", ".", "ssoClientApp", ",", "err", "=", "oidc", ".", "NewClientApp", "(", "a", ".", "settings", ",", "a", ".", "Cache", ",", "a", ".", "DexServerAddr", ")", "\n", "errors", ".", "CheckError", "(", "err", ")", "\n", "mux", ".", "HandleFunc", "(", "common", ".", "LoginEndpoint", ",", "a", ".", "ssoClientApp", ".", "HandleLogin", ")", "\n", "mux", ".", "HandleFunc", "(", "common", ".", "CallbackEndpoint", ",", "a", ".", "ssoClientApp", ".", "HandleCallback", ")", "\n", "}" ]
// registerDexHandlers will register dex HTTP handlers, creating the the OAuth client app
[ "registerDexHandlers", "will", "register", "dex", "HTTP", "handlers", "creating", "the", "the", "OAuth", "client", "app" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/server.go#L524-L537
161,761
argoproj/argo-cd
server/server.go
newRedirectServer
func newRedirectServer(port int) *http.Server { return &http.Server{ Addr: fmt.Sprintf("localhost:%d", port), Handler: http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { target := "https://" + req.Host + req.URL.Path if len(req.URL.RawQuery) > 0 { target += "?" + req.URL.RawQuery } http.Redirect(w, req, target, http.StatusTemporaryRedirect) }), } }
go
func newRedirectServer(port int) *http.Server { return &http.Server{ Addr: fmt.Sprintf("localhost:%d", port), Handler: http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { target := "https://" + req.Host + req.URL.Path if len(req.URL.RawQuery) > 0 { target += "?" + req.URL.RawQuery } http.Redirect(w, req, target, http.StatusTemporaryRedirect) }), } }
[ "func", "newRedirectServer", "(", "port", "int", ")", "*", "http", ".", "Server", "{", "return", "&", "http", ".", "Server", "{", "Addr", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "port", ")", ",", "Handler", ":", "http", ".", "HandlerFunc", "(", "func", "(", "w", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "target", ":=", "\"", "\"", "+", "req", ".", "Host", "+", "req", ".", "URL", ".", "Path", "\n", "if", "len", "(", "req", ".", "URL", ".", "RawQuery", ")", ">", "0", "{", "target", "+=", "\"", "\"", "+", "req", ".", "URL", ".", "RawQuery", "\n", "}", "\n", "http", ".", "Redirect", "(", "w", ",", "req", ",", "target", ",", "http", ".", "StatusTemporaryRedirect", ")", "\n", "}", ")", ",", "}", "\n", "}" ]
// newRedirectServer returns an HTTP server which does a 307 redirect to the HTTPS server
[ "newRedirectServer", "returns", "an", "HTTP", "server", "which", "does", "a", "307", "redirect", "to", "the", "HTTPS", "server" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/server.go#L540-L551
161,762
argoproj/argo-cd
server/server.go
newAPIServerMetricsServer
func newAPIServerMetricsServer() *http.Server { mux := http.NewServeMux() mux.Handle("/metrics", promhttp.Handler()) return &http.Server{ Addr: fmt.Sprintf("0.0.0.0:%d", common.PortArgoCDAPIServerMetrics), Handler: mux, } }
go
func newAPIServerMetricsServer() *http.Server { mux := http.NewServeMux() mux.Handle("/metrics", promhttp.Handler()) return &http.Server{ Addr: fmt.Sprintf("0.0.0.0:%d", common.PortArgoCDAPIServerMetrics), Handler: mux, } }
[ "func", "newAPIServerMetricsServer", "(", ")", "*", "http", ".", "Server", "{", "mux", ":=", "http", ".", "NewServeMux", "(", ")", "\n", "mux", ".", "Handle", "(", "\"", "\"", ",", "promhttp", ".", "Handler", "(", ")", ")", "\n", "return", "&", "http", ".", "Server", "{", "Addr", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "common", ".", "PortArgoCDAPIServerMetrics", ")", ",", "Handler", ":", "mux", ",", "}", "\n", "}" ]
// newAPIServerMetricsServer returns HTTP server which serves prometheus metrics on gRPC requests
[ "newAPIServerMetricsServer", "returns", "HTTP", "server", "which", "serves", "prometheus", "metrics", "on", "gRPC", "requests" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/server.go#L604-L611
161,763
argoproj/argo-cd
server/server.go
newStaticAssetsHandler
func newStaticAssetsHandler(dir string, baseHRef string) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { acceptHTML := false for _, acceptType := range strings.Split(r.Header.Get("Accept"), ",") { if acceptType == "text/html" || acceptType == "html" { acceptHTML = true break } } fileRequest := r.URL.Path != "/index.html" && strings.Contains(r.URL.Path, ".") // serve index.html for non file requests to support HTML5 History API if acceptHTML && !fileRequest && (r.Method == "GET" || r.Method == "HEAD") { for k, v := range noCacheHeaders { w.Header().Set(k, v) } indexHtmlPath, err := indexFilePath(path.Join(dir, "index.html"), baseHRef) if err != nil { http.Error(w, fmt.Sprintf("Unable to access index.html: %v", err), http.StatusInternalServerError) return } http.ServeFile(w, r, indexHtmlPath) } else { http.ServeFile(w, r, path.Join(dir, r.URL.Path)) } } }
go
func newStaticAssetsHandler(dir string, baseHRef string) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, r *http.Request) { acceptHTML := false for _, acceptType := range strings.Split(r.Header.Get("Accept"), ",") { if acceptType == "text/html" || acceptType == "html" { acceptHTML = true break } } fileRequest := r.URL.Path != "/index.html" && strings.Contains(r.URL.Path, ".") // serve index.html for non file requests to support HTML5 History API if acceptHTML && !fileRequest && (r.Method == "GET" || r.Method == "HEAD") { for k, v := range noCacheHeaders { w.Header().Set(k, v) } indexHtmlPath, err := indexFilePath(path.Join(dir, "index.html"), baseHRef) if err != nil { http.Error(w, fmt.Sprintf("Unable to access index.html: %v", err), http.StatusInternalServerError) return } http.ServeFile(w, r, indexHtmlPath) } else { http.ServeFile(w, r, path.Join(dir, r.URL.Path)) } } }
[ "func", "newStaticAssetsHandler", "(", "dir", "string", ",", "baseHRef", "string", ")", "func", "(", "http", ".", "ResponseWriter", ",", "*", "http", ".", "Request", ")", "{", "return", "func", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "acceptHTML", ":=", "false", "\n", "for", "_", ",", "acceptType", ":=", "range", "strings", ".", "Split", "(", "r", ".", "Header", ".", "Get", "(", "\"", "\"", ")", ",", "\"", "\"", ")", "{", "if", "acceptType", "==", "\"", "\"", "||", "acceptType", "==", "\"", "\"", "{", "acceptHTML", "=", "true", "\n", "break", "\n", "}", "\n", "}", "\n", "fileRequest", ":=", "r", ".", "URL", ".", "Path", "!=", "\"", "\"", "&&", "strings", ".", "Contains", "(", "r", ".", "URL", ".", "Path", ",", "\"", "\"", ")", "\n\n", "// serve index.html for non file requests to support HTML5 History API", "if", "acceptHTML", "&&", "!", "fileRequest", "&&", "(", "r", ".", "Method", "==", "\"", "\"", "||", "r", ".", "Method", "==", "\"", "\"", ")", "{", "for", "k", ",", "v", ":=", "range", "noCacheHeaders", "{", "w", ".", "Header", "(", ")", ".", "Set", "(", "k", ",", "v", ")", "\n", "}", "\n", "indexHtmlPath", ",", "err", ":=", "indexFilePath", "(", "path", ".", "Join", "(", "dir", ",", "\"", "\"", ")", ",", "baseHRef", ")", "\n", "if", "err", "!=", "nil", "{", "http", ".", "Error", "(", "w", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "err", ")", ",", "http", ".", "StatusInternalServerError", ")", "\n", "return", "\n", "}", "\n", "http", ".", "ServeFile", "(", "w", ",", "r", ",", "indexHtmlPath", ")", "\n", "}", "else", "{", "http", ".", "ServeFile", "(", "w", ",", "r", ",", "path", ".", "Join", "(", "dir", ",", "r", ".", "URL", ".", "Path", ")", ")", "\n", "}", "\n", "}", "\n", "}" ]
// newStaticAssetsHandler returns an HTTP handler to serve UI static assets
[ "newStaticAssetsHandler", "returns", "an", "HTTP", "handler", "to", "serve", "UI", "static", "assets" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/server.go#L614-L640
161,764
argoproj/argo-cd
server/server.go
mustRegisterGWHandler
func mustRegisterGWHandler(register registerFunc, ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) { err := register(ctx, mux, endpoint, opts) if err != nil { panic(err) } }
go
func mustRegisterGWHandler(register registerFunc, ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) { err := register(ctx, mux, endpoint, opts) if err != nil { panic(err) } }
[ "func", "mustRegisterGWHandler", "(", "register", "registerFunc", ",", "ctx", "context", ".", "Context", ",", "mux", "*", "runtime", ".", "ServeMux", ",", "endpoint", "string", ",", "opts", "[", "]", "grpc", ".", "DialOption", ")", "{", "err", ":=", "register", "(", "ctx", ",", "mux", ",", "endpoint", ",", "opts", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "}" ]
// mustRegisterGWHandler is a convenience function to register a gateway handler
[ "mustRegisterGWHandler", "is", "a", "convenience", "function", "to", "register", "a", "gateway", "handler" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/server.go#L645-L650
161,765
argoproj/argo-cd
server/server.go
authenticate
func (a *ArgoCDServer) authenticate(ctx context.Context) (context.Context, error) { if a.DisableAuth { return ctx, nil } md, ok := metadata.FromIncomingContext(ctx) if !ok { return ctx, ErrNoSession } tokenString := getToken(md) if tokenString == "" { return ctx, ErrNoSession } claims, err := a.sessionMgr.VerifyToken(tokenString) if err != nil { return ctx, status.Errorf(codes.Unauthenticated, "invalid session: %v", err) } // Add claims to the context to inspect for RBAC ctx = context.WithValue(ctx, "claims", claims) return ctx, nil }
go
func (a *ArgoCDServer) authenticate(ctx context.Context) (context.Context, error) { if a.DisableAuth { return ctx, nil } md, ok := metadata.FromIncomingContext(ctx) if !ok { return ctx, ErrNoSession } tokenString := getToken(md) if tokenString == "" { return ctx, ErrNoSession } claims, err := a.sessionMgr.VerifyToken(tokenString) if err != nil { return ctx, status.Errorf(codes.Unauthenticated, "invalid session: %v", err) } // Add claims to the context to inspect for RBAC ctx = context.WithValue(ctx, "claims", claims) return ctx, nil }
[ "func", "(", "a", "*", "ArgoCDServer", ")", "authenticate", "(", "ctx", "context", ".", "Context", ")", "(", "context", ".", "Context", ",", "error", ")", "{", "if", "a", ".", "DisableAuth", "{", "return", "ctx", ",", "nil", "\n", "}", "\n", "md", ",", "ok", ":=", "metadata", ".", "FromIncomingContext", "(", "ctx", ")", "\n", "if", "!", "ok", "{", "return", "ctx", ",", "ErrNoSession", "\n", "}", "\n", "tokenString", ":=", "getToken", "(", "md", ")", "\n", "if", "tokenString", "==", "\"", "\"", "{", "return", "ctx", ",", "ErrNoSession", "\n", "}", "\n", "claims", ",", "err", ":=", "a", ".", "sessionMgr", ".", "VerifyToken", "(", "tokenString", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ctx", ",", "status", ".", "Errorf", "(", "codes", ".", "Unauthenticated", ",", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "// Add claims to the context to inspect for RBAC", "ctx", "=", "context", ".", "WithValue", "(", "ctx", ",", "\"", "\"", ",", "claims", ")", "\n", "return", "ctx", ",", "nil", "\n", "}" ]
// Authenticate checks for the presence of a valid token when accessing server-side resources.
[ "Authenticate", "checks", "for", "the", "presence", "of", "a", "valid", "token", "when", "accessing", "server", "-", "side", "resources", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/server.go#L653-L672
161,766
argoproj/argo-cd
server/server.go
getToken
func getToken(md metadata.MD) string { // check the "token" metadata tokens, ok := md[apiclient.MetaDataTokenKey] if ok && len(tokens) > 0 { return tokens[0] } // check the HTTP cookie for _, cookieToken := range md["grpcgateway-cookie"] { header := http.Header{} header.Add("Cookie", cookieToken) request := http.Request{Header: header} token, err := request.Cookie(common.AuthCookieName) if err == nil { return token.Value } } return "" }
go
func getToken(md metadata.MD) string { // check the "token" metadata tokens, ok := md[apiclient.MetaDataTokenKey] if ok && len(tokens) > 0 { return tokens[0] } // check the HTTP cookie for _, cookieToken := range md["grpcgateway-cookie"] { header := http.Header{} header.Add("Cookie", cookieToken) request := http.Request{Header: header} token, err := request.Cookie(common.AuthCookieName) if err == nil { return token.Value } } return "" }
[ "func", "getToken", "(", "md", "metadata", ".", "MD", ")", "string", "{", "// check the \"token\" metadata", "tokens", ",", "ok", ":=", "md", "[", "apiclient", ".", "MetaDataTokenKey", "]", "\n", "if", "ok", "&&", "len", "(", "tokens", ")", ">", "0", "{", "return", "tokens", "[", "0", "]", "\n", "}", "\n", "// check the HTTP cookie", "for", "_", ",", "cookieToken", ":=", "range", "md", "[", "\"", "\"", "]", "{", "header", ":=", "http", ".", "Header", "{", "}", "\n", "header", ".", "Add", "(", "\"", "\"", ",", "cookieToken", ")", "\n", "request", ":=", "http", ".", "Request", "{", "Header", ":", "header", "}", "\n", "token", ",", "err", ":=", "request", ".", "Cookie", "(", "common", ".", "AuthCookieName", ")", "\n", "if", "err", "==", "nil", "{", "return", "token", ".", "Value", "\n", "}", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// getToken extracts the token from gRPC metadata or cookie headers
[ "getToken", "extracts", "the", "token", "from", "gRPC", "metadata", "or", "cookie", "headers" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/server.go#L675-L692
161,767
argoproj/argo-cd
util/http/http.go
MakeCookieMetadata
func MakeCookieMetadata(key, value string, flags ...string) (string, error) { components := []string{ fmt.Sprintf("%s=%s", key, value), } components = append(components, flags...) header := strings.Join(components, "; ") const maxLength = 4093 if len(header) > maxLength { return "", fmt.Errorf("invalid cookie, longer than max length %v", maxLength) } return header, nil }
go
func MakeCookieMetadata(key, value string, flags ...string) (string, error) { components := []string{ fmt.Sprintf("%s=%s", key, value), } components = append(components, flags...) header := strings.Join(components, "; ") const maxLength = 4093 if len(header) > maxLength { return "", fmt.Errorf("invalid cookie, longer than max length %v", maxLength) } return header, nil }
[ "func", "MakeCookieMetadata", "(", "key", ",", "value", "string", ",", "flags", "...", "string", ")", "(", "string", ",", "error", ")", "{", "components", ":=", "[", "]", "string", "{", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "key", ",", "value", ")", ",", "}", "\n", "components", "=", "append", "(", "components", ",", "flags", "...", ")", "\n", "header", ":=", "strings", ".", "Join", "(", "components", ",", "\"", "\"", ")", "\n\n", "const", "maxLength", "=", "4093", "\n", "if", "len", "(", "header", ")", ">", "maxLength", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "maxLength", ")", "\n", "}", "\n", "return", "header", ",", "nil", "\n", "}" ]
// MakeCookieMetadata generates a string representing a Web cookie. Yum!
[ "MakeCookieMetadata", "generates", "a", "string", "representing", "a", "Web", "cookie", ".", "Yum!" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/http/http.go#L13-L25
161,768
argoproj/argo-cd
util/ksonnet/ksonnet.go
Destination
func Destination(data []byte, environment string) (*v1alpha1.ApplicationDestination, error) { var appSpec struct { Environments map[string]struct { Destination v1alpha1.ApplicationDestination } } err := yaml.Unmarshal(data, &appSpec) if err != nil { return nil, fmt.Errorf("could not unmarshal ksonnet spec app.yaml: %v", err) } envSpec, ok := appSpec.Environments[environment] if !ok { return nil, fmt.Errorf("environment '%s' does not exist in ksonnet app", environment) } return &envSpec.Destination, nil }
go
func Destination(data []byte, environment string) (*v1alpha1.ApplicationDestination, error) { var appSpec struct { Environments map[string]struct { Destination v1alpha1.ApplicationDestination } } err := yaml.Unmarshal(data, &appSpec) if err != nil { return nil, fmt.Errorf("could not unmarshal ksonnet spec app.yaml: %v", err) } envSpec, ok := appSpec.Environments[environment] if !ok { return nil, fmt.Errorf("environment '%s' does not exist in ksonnet app", environment) } return &envSpec.Destination, nil }
[ "func", "Destination", "(", "data", "[", "]", "byte", ",", "environment", "string", ")", "(", "*", "v1alpha1", ".", "ApplicationDestination", ",", "error", ")", "{", "var", "appSpec", "struct", "{", "Environments", "map", "[", "string", "]", "struct", "{", "Destination", "v1alpha1", ".", "ApplicationDestination", "\n", "}", "\n", "}", "\n", "err", ":=", "yaml", ".", "Unmarshal", "(", "data", ",", "&", "appSpec", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "envSpec", ",", "ok", ":=", "appSpec", ".", "Environments", "[", "environment", "]", "\n", "if", "!", "ok", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "environment", ")", "\n", "}", "\n\n", "return", "&", "envSpec", ".", "Destination", ",", "nil", "\n", "}" ]
// Destination returns the deployment destination for an environment in app spec data
[ "Destination", "returns", "the", "deployment", "destination", "for", "an", "environment", "in", "app", "spec", "data" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/ksonnet/ksonnet.go#L21-L38
161,769
argoproj/argo-cd
util/ksonnet/ksonnet.go
KsonnetVersion
func KsonnetVersion() (string, error) { ksApp := ksonnetApp{} out, err := ksApp.ksCmd("", "version") if err != nil { return "", fmt.Errorf("unable to determine ksonnet version: %v", err) } ksonnetVersionStr := strings.Split(out, "\n")[0] parts := strings.SplitN(ksonnetVersionStr, ":", 2) if len(parts) != 2 { return "", fmt.Errorf("unexpected version string format: %s", ksonnetVersionStr) } return strings.TrimSpace(parts[1]), nil }
go
func KsonnetVersion() (string, error) { ksApp := ksonnetApp{} out, err := ksApp.ksCmd("", "version") if err != nil { return "", fmt.Errorf("unable to determine ksonnet version: %v", err) } ksonnetVersionStr := strings.Split(out, "\n")[0] parts := strings.SplitN(ksonnetVersionStr, ":", 2) if len(parts) != 2 { return "", fmt.Errorf("unexpected version string format: %s", ksonnetVersionStr) } return strings.TrimSpace(parts[1]), nil }
[ "func", "KsonnetVersion", "(", ")", "(", "string", ",", "error", ")", "{", "ksApp", ":=", "ksonnetApp", "{", "}", "\n", "out", ",", "err", ":=", "ksApp", ".", "ksCmd", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "ksonnetVersionStr", ":=", "strings", ".", "Split", "(", "out", ",", "\"", "\\n", "\"", ")", "[", "0", "]", "\n", "parts", ":=", "strings", ".", "SplitN", "(", "ksonnetVersionStr", ",", "\"", "\"", ",", "2", ")", "\n", "if", "len", "(", "parts", ")", "!=", "2", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ksonnetVersionStr", ")", "\n", "}", "\n", "return", "strings", ".", "TrimSpace", "(", "parts", "[", "1", "]", ")", ",", "nil", "\n", "}" ]
// KsonnetVersion returns the version of ksonnet used when running ksonnet commands
[ "KsonnetVersion", "returns", "the", "version", "of", "ksonnet", "used", "when", "running", "ksonnet", "commands" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/ksonnet/ksonnet.go#L60-L72
161,770
argoproj/argo-cd
util/ksonnet/ksonnet.go
NewKsonnetApp
func NewKsonnetApp(path string) (KsonnetApp, error) { ksApp := ksonnetApp{rootDir: path} // ensure that the file exists if _, err := ksApp.appYamlPath(); err != nil { return nil, err } return &ksApp, nil }
go
func NewKsonnetApp(path string) (KsonnetApp, error) { ksApp := ksonnetApp{rootDir: path} // ensure that the file exists if _, err := ksApp.appYamlPath(); err != nil { return nil, err } return &ksApp, nil }
[ "func", "NewKsonnetApp", "(", "path", "string", ")", "(", "KsonnetApp", ",", "error", ")", "{", "ksApp", ":=", "ksonnetApp", "{", "rootDir", ":", "path", "}", "\n", "// ensure that the file exists", "if", "_", ",", "err", ":=", "ksApp", ".", "appYamlPath", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "ksApp", ",", "nil", "\n", "}" ]
// NewKsonnetApp tries to create a new wrapper to run commands on the `ks` command-line tool.
[ "NewKsonnetApp", "tries", "to", "create", "a", "new", "wrapper", "to", "run", "commands", "on", "the", "ks", "command", "-", "line", "tool", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/ksonnet/ksonnet.go#L79-L86
161,771
argoproj/argo-cd
util/ksonnet/ksonnet.go
Show
func (k *ksonnetApp) Show(environment string) ([]*unstructured.Unstructured, error) { out, err := k.ksCmd("show", environment) if err != nil { return nil, fmt.Errorf("`ks show` failed: %v", err) } return kube.SplitYAML(out) }
go
func (k *ksonnetApp) Show(environment string) ([]*unstructured.Unstructured, error) { out, err := k.ksCmd("show", environment) if err != nil { return nil, fmt.Errorf("`ks show` failed: %v", err) } return kube.SplitYAML(out) }
[ "func", "(", "k", "*", "ksonnetApp", ")", "Show", "(", "environment", "string", ")", "(", "[", "]", "*", "unstructured", ".", "Unstructured", ",", "error", ")", "{", "out", ",", "err", ":=", "k", ".", "ksCmd", "(", "\"", "\"", ",", "environment", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "kube", ".", "SplitYAML", "(", "out", ")", "\n", "}" ]
// Show generates a concatenated list of Kubernetes manifests in the given environment.
[ "Show", "generates", "a", "concatenated", "list", "of", "Kubernetes", "manifests", "in", "the", "given", "environment", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/ksonnet/ksonnet.go#L123-L129
161,772
argoproj/argo-cd
util/ksonnet/ksonnet.go
Destination
func (k *ksonnetApp) Destination(environment string) (*v1alpha1.ApplicationDestination, error) { p, err := k.appYamlPath() if err != nil { return nil, err } data, err := ioutil.ReadFile(p) if err != nil { return nil, err } return Destination(data, environment) }
go
func (k *ksonnetApp) Destination(environment string) (*v1alpha1.ApplicationDestination, error) { p, err := k.appYamlPath() if err != nil { return nil, err } data, err := ioutil.ReadFile(p) if err != nil { return nil, err } return Destination(data, environment) }
[ "func", "(", "k", "*", "ksonnetApp", ")", "Destination", "(", "environment", "string", ")", "(", "*", "v1alpha1", ".", "ApplicationDestination", ",", "error", ")", "{", "p", ",", "err", ":=", "k", ".", "appYamlPath", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "data", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "p", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "Destination", "(", "data", ",", "environment", ")", "\n", "}" ]
// Destination returns the deployment destination for an environment
[ "Destination", "returns", "the", "deployment", "destination", "for", "an", "environment" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/ksonnet/ksonnet.go#L132-L142
161,773
argoproj/argo-cd
util/ksonnet/ksonnet.go
ListParams
func (k *ksonnetApp) ListParams(environment string) ([]*v1alpha1.KsonnetParameter, error) { args := []string{"param", "list", "--output", "json"} if environment != "" { args = append(args, "--env", environment) } out, err := k.ksCmd(args...) if err != nil { return nil, err } // Auxiliary data to hold unmarshaled JSON output, which may use different field names var ksParams struct { Data []struct { Component string `json:"component"` Key string `json:"param"` Value string `json:"value"` } `json:"data"` } if err := json.Unmarshal([]byte(out), &ksParams); err != nil { return nil, err } var params []*v1alpha1.KsonnetParameter for _, ksParam := range ksParams.Data { value := strings.Trim(ksParam.Value, `'"`) params = append(params, &v1alpha1.KsonnetParameter{ Component: ksParam.Component, Name: ksParam.Key, Value: value, }) } return params, nil }
go
func (k *ksonnetApp) ListParams(environment string) ([]*v1alpha1.KsonnetParameter, error) { args := []string{"param", "list", "--output", "json"} if environment != "" { args = append(args, "--env", environment) } out, err := k.ksCmd(args...) if err != nil { return nil, err } // Auxiliary data to hold unmarshaled JSON output, which may use different field names var ksParams struct { Data []struct { Component string `json:"component"` Key string `json:"param"` Value string `json:"value"` } `json:"data"` } if err := json.Unmarshal([]byte(out), &ksParams); err != nil { return nil, err } var params []*v1alpha1.KsonnetParameter for _, ksParam := range ksParams.Data { value := strings.Trim(ksParam.Value, `'"`) params = append(params, &v1alpha1.KsonnetParameter{ Component: ksParam.Component, Name: ksParam.Key, Value: value, }) } return params, nil }
[ "func", "(", "k", "*", "ksonnetApp", ")", "ListParams", "(", "environment", "string", ")", "(", "[", "]", "*", "v1alpha1", ".", "KsonnetParameter", ",", "error", ")", "{", "args", ":=", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", "}", "\n", "if", "environment", "!=", "\"", "\"", "{", "args", "=", "append", "(", "args", ",", "\"", "\"", ",", "environment", ")", "\n", "}", "\n", "out", ",", "err", ":=", "k", ".", "ksCmd", "(", "args", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "// Auxiliary data to hold unmarshaled JSON output, which may use different field names", "var", "ksParams", "struct", "{", "Data", "[", "]", "struct", "{", "Component", "string", "`json:\"component\"`", "\n", "Key", "string", "`json:\"param\"`", "\n", "Value", "string", "`json:\"value\"`", "\n", "}", "`json:\"data\"`", "\n", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "[", "]", "byte", "(", "out", ")", ",", "&", "ksParams", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "params", "[", "]", "*", "v1alpha1", ".", "KsonnetParameter", "\n", "for", "_", ",", "ksParam", ":=", "range", "ksParams", ".", "Data", "{", "value", ":=", "strings", ".", "Trim", "(", "ksParam", ".", "Value", ",", "`'\"`", ")", "\n", "params", "=", "append", "(", "params", ",", "&", "v1alpha1", ".", "KsonnetParameter", "{", "Component", ":", "ksParam", ".", "Component", ",", "Name", ":", "ksParam", ".", "Key", ",", "Value", ":", "value", ",", "}", ")", "\n", "}", "\n", "return", "params", ",", "nil", "\n", "}" ]
// ListParams returns list of ksonnet parameters
[ "ListParams", "returns", "list", "of", "ksonnet", "parameters" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/ksonnet/ksonnet.go#L145-L175
161,774
argoproj/argo-cd
util/ksonnet/ksonnet.go
SetComponentParams
func (k *ksonnetApp) SetComponentParams(environment string, component string, param string, value string) error { _, err := k.ksCmd("param", "set", component, param, value, "--env", environment) return err }
go
func (k *ksonnetApp) SetComponentParams(environment string, component string, param string, value string) error { _, err := k.ksCmd("param", "set", component, param, value, "--env", environment) return err }
[ "func", "(", "k", "*", "ksonnetApp", ")", "SetComponentParams", "(", "environment", "string", ",", "component", "string", ",", "param", "string", ",", "value", "string", ")", "error", "{", "_", ",", "err", ":=", "k", ".", "ksCmd", "(", "\"", "\"", ",", "\"", "\"", ",", "component", ",", "param", ",", "value", ",", "\"", "\"", ",", "environment", ")", "\n", "return", "err", "\n", "}" ]
// SetComponentParams updates component parameter in specified environment.
[ "SetComponentParams", "updates", "component", "parameter", "in", "specified", "environment", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/ksonnet/ksonnet.go#L178-L181
161,775
argoproj/argo-cd
server/settings/settings.go
Get
func (s *Server) Get(ctx context.Context, q *SettingsQuery) (*Settings, error) { argoCDSettings, err := s.mgr.GetSettings() if err != nil { return nil, err } overrides := make(map[string]*v1alpha1.ResourceOverride) for k := range argoCDSettings.ResourceOverrides { val := argoCDSettings.ResourceOverrides[k] overrides[k] = &val } set := Settings{ URL: argoCDSettings.URL, AppLabelKey: argoCDSettings.GetAppInstanceLabelKey(), ResourceOverrides: overrides, } if argoCDSettings.DexConfig != "" { var cfg DexConfig err = yaml.Unmarshal([]byte(argoCDSettings.DexConfig), &cfg) if err == nil { set.DexConfig = &cfg } } if oidcConfig := argoCDSettings.OIDCConfig(); oidcConfig != nil { set.OIDCConfig = &OIDCConfig{ Name: oidcConfig.Name, Issuer: oidcConfig.Issuer, ClientID: oidcConfig.ClientID, CLIClientID: oidcConfig.CLIClientID, } } return &set, nil }
go
func (s *Server) Get(ctx context.Context, q *SettingsQuery) (*Settings, error) { argoCDSettings, err := s.mgr.GetSettings() if err != nil { return nil, err } overrides := make(map[string]*v1alpha1.ResourceOverride) for k := range argoCDSettings.ResourceOverrides { val := argoCDSettings.ResourceOverrides[k] overrides[k] = &val } set := Settings{ URL: argoCDSettings.URL, AppLabelKey: argoCDSettings.GetAppInstanceLabelKey(), ResourceOverrides: overrides, } if argoCDSettings.DexConfig != "" { var cfg DexConfig err = yaml.Unmarshal([]byte(argoCDSettings.DexConfig), &cfg) if err == nil { set.DexConfig = &cfg } } if oidcConfig := argoCDSettings.OIDCConfig(); oidcConfig != nil { set.OIDCConfig = &OIDCConfig{ Name: oidcConfig.Name, Issuer: oidcConfig.Issuer, ClientID: oidcConfig.ClientID, CLIClientID: oidcConfig.CLIClientID, } } return &set, nil }
[ "func", "(", "s", "*", "Server", ")", "Get", "(", "ctx", "context", ".", "Context", ",", "q", "*", "SettingsQuery", ")", "(", "*", "Settings", ",", "error", ")", "{", "argoCDSettings", ",", "err", ":=", "s", ".", "mgr", ".", "GetSettings", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "overrides", ":=", "make", "(", "map", "[", "string", "]", "*", "v1alpha1", ".", "ResourceOverride", ")", "\n", "for", "k", ":=", "range", "argoCDSettings", ".", "ResourceOverrides", "{", "val", ":=", "argoCDSettings", ".", "ResourceOverrides", "[", "k", "]", "\n", "overrides", "[", "k", "]", "=", "&", "val", "\n", "}", "\n", "set", ":=", "Settings", "{", "URL", ":", "argoCDSettings", ".", "URL", ",", "AppLabelKey", ":", "argoCDSettings", ".", "GetAppInstanceLabelKey", "(", ")", ",", "ResourceOverrides", ":", "overrides", ",", "}", "\n", "if", "argoCDSettings", ".", "DexConfig", "!=", "\"", "\"", "{", "var", "cfg", "DexConfig", "\n", "err", "=", "yaml", ".", "Unmarshal", "(", "[", "]", "byte", "(", "argoCDSettings", ".", "DexConfig", ")", ",", "&", "cfg", ")", "\n", "if", "err", "==", "nil", "{", "set", ".", "DexConfig", "=", "&", "cfg", "\n", "}", "\n", "}", "\n", "if", "oidcConfig", ":=", "argoCDSettings", ".", "OIDCConfig", "(", ")", ";", "oidcConfig", "!=", "nil", "{", "set", ".", "OIDCConfig", "=", "&", "OIDCConfig", "{", "Name", ":", "oidcConfig", ".", "Name", ",", "Issuer", ":", "oidcConfig", ".", "Issuer", ",", "ClientID", ":", "oidcConfig", ".", "ClientID", ",", "CLIClientID", ":", "oidcConfig", ".", "CLIClientID", ",", "}", "\n", "}", "\n", "return", "&", "set", ",", "nil", "\n", "}" ]
// Get returns Argo CD settings
[ "Get", "returns", "Argo", "CD", "settings" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/settings/settings.go#L24-L56
161,776
argoproj/argo-cd
server/settings/settings.go
AuthFuncOverride
func (s *Server) AuthFuncOverride(ctx context.Context, fullMethodName string) (context.Context, error) { return ctx, nil }
go
func (s *Server) AuthFuncOverride(ctx context.Context, fullMethodName string) (context.Context, error) { return ctx, nil }
[ "func", "(", "s", "*", "Server", ")", "AuthFuncOverride", "(", "ctx", "context", ".", "Context", ",", "fullMethodName", "string", ")", "(", "context", ".", "Context", ",", "error", ")", "{", "return", "ctx", ",", "nil", "\n", "}" ]
// AuthFuncOverride disables authentication for settings service
[ "AuthFuncOverride", "disables", "authentication", "for", "settings", "service" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/settings/settings.go#L59-L61
161,777
argoproj/argo-cd
util/json/json.go
NewDecoder
func (j *JSONMarshaler) NewDecoder(r io.Reader) gwruntime.Decoder { return json.NewDecoder(r) }
go
func (j *JSONMarshaler) NewDecoder(r io.Reader) gwruntime.Decoder { return json.NewDecoder(r) }
[ "func", "(", "j", "*", "JSONMarshaler", ")", "NewDecoder", "(", "r", "io", ".", "Reader", ")", "gwruntime", ".", "Decoder", "{", "return", "json", ".", "NewDecoder", "(", "r", ")", "\n", "}" ]
// NewDecoder implements gwruntime.Marshaler.
[ "NewDecoder", "implements", "gwruntime", ".", "Marshaler", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/json/json.go#L24-L26
161,778
argoproj/argo-cd
util/json/json.go
NewEncoder
func (j *JSONMarshaler) NewEncoder(w io.Writer) gwruntime.Encoder { return json.NewEncoder(w) }
go
func (j *JSONMarshaler) NewEncoder(w io.Writer) gwruntime.Encoder { return json.NewEncoder(w) }
[ "func", "(", "j", "*", "JSONMarshaler", ")", "NewEncoder", "(", "w", "io", ".", "Writer", ")", "gwruntime", ".", "Encoder", "{", "return", "json", ".", "NewEncoder", "(", "w", ")", "\n", "}" ]
// NewEncoder implements gwruntime.Marshaler.
[ "NewEncoder", "implements", "gwruntime", ".", "Marshaler", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/json/json.go#L29-L31
161,779
argoproj/argo-cd
util/json/json.go
Unmarshal
func (j *JSONMarshaler) Unmarshal(data []byte, v interface{}) error { return json.Unmarshal(data, v) }
go
func (j *JSONMarshaler) Unmarshal(data []byte, v interface{}) error { return json.Unmarshal(data, v) }
[ "func", "(", "j", "*", "JSONMarshaler", ")", "Unmarshal", "(", "data", "[", "]", "byte", ",", "v", "interface", "{", "}", ")", "error", "{", "return", "json", ".", "Unmarshal", "(", "data", ",", "v", ")", "\n", "}" ]
// Unmarshal implements gwruntime.Marshaler.
[ "Unmarshal", "implements", "gwruntime", ".", "Marshaler", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/json/json.go#L34-L36
161,780
argoproj/argo-cd
util/json/json.go
RemoveMapFields
func RemoveMapFields(config, live map[string]interface{}) map[string]interface{} { result := map[string]interface{}{} for k, v1 := range config { v2, ok := live[k] if !ok { continue } if v2 != nil { v2 = removeFields(v1, v2) } result[k] = v2 } return result }
go
func RemoveMapFields(config, live map[string]interface{}) map[string]interface{} { result := map[string]interface{}{} for k, v1 := range config { v2, ok := live[k] if !ok { continue } if v2 != nil { v2 = removeFields(v1, v2) } result[k] = v2 } return result }
[ "func", "RemoveMapFields", "(", "config", ",", "live", "map", "[", "string", "]", "interface", "{", "}", ")", "map", "[", "string", "]", "interface", "{", "}", "{", "result", ":=", "map", "[", "string", "]", "interface", "{", "}", "{", "}", "\n", "for", "k", ",", "v1", ":=", "range", "config", "{", "v2", ",", "ok", ":=", "live", "[", "k", "]", "\n", "if", "!", "ok", "{", "continue", "\n", "}", "\n", "if", "v2", "!=", "nil", "{", "v2", "=", "removeFields", "(", "v1", ",", "v2", ")", "\n", "}", "\n", "result", "[", "k", "]", "=", "v2", "\n", "}", "\n", "return", "result", "\n", "}" ]
// RemoveMapFields remove all non-existent fields in the live that don't exist in the config
[ "RemoveMapFields", "remove", "all", "non", "-", "existent", "fields", "in", "the", "live", "that", "don", "t", "exist", "in", "the", "config" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/json/json.go#L51-L64
161,781
argoproj/argo-cd
util/json/json.go
MustMarshal
func MustMarshal(v interface{}) []byte { bytes, err := json.Marshal(v) if err != nil { panic(err) } return bytes }
go
func MustMarshal(v interface{}) []byte { bytes, err := json.Marshal(v) if err != nil { panic(err) } return bytes }
[ "func", "MustMarshal", "(", "v", "interface", "{", "}", ")", "[", "]", "byte", "{", "bytes", ",", "err", ":=", "json", ".", "Marshal", "(", "v", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "bytes", "\n", "}" ]
// MustMarshal is a convenience function to marshal an object successfully or panic
[ "MustMarshal", "is", "a", "convenience", "function", "to", "marshal", "an", "object", "successfully", "or", "panic" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/json/json.go#L84-L90
161,782
argoproj/argo-cd
pkg/client/informers/externalversions/application/v1alpha1/application.go
NewApplicationInformer
func NewApplicationInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { return NewFilteredApplicationInformer(client, namespace, resyncPeriod, indexers, nil) }
go
func NewApplicationInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { return NewFilteredApplicationInformer(client, namespace, resyncPeriod, indexers, nil) }
[ "func", "NewApplicationInformer", "(", "client", "versioned", ".", "Interface", ",", "namespace", "string", ",", "resyncPeriod", "time", ".", "Duration", ",", "indexers", "cache", ".", "Indexers", ")", "cache", ".", "SharedIndexInformer", "{", "return", "NewFilteredApplicationInformer", "(", "client", ",", "namespace", ",", "resyncPeriod", ",", "indexers", ",", "nil", ")", "\n", "}" ]
// NewApplicationInformer constructs a new informer for Application type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server.
[ "NewApplicationInformer", "constructs", "a", "new", "informer", "for", "Application", "type", ".", "Always", "prefer", "using", "an", "informer", "factory", "to", "get", "a", "shared", "informer", "instead", "of", "getting", "an", "independent", "one", ".", "This", "reduces", "memory", "footprint", "and", "number", "of", "connections", "to", "the", "server", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/pkg/client/informers/externalversions/application/v1alpha1/application.go#L34-L36
161,783
argoproj/argo-cd
pkg/client/informers/externalversions/application/v1alpha1/application.go
NewFilteredApplicationInformer
func NewFilteredApplicationInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options v1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } return client.ArgoprojV1alpha1().Applications(namespace).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } return client.ArgoprojV1alpha1().Applications(namespace).Watch(options) }, }, &applicationv1alpha1.Application{}, resyncPeriod, indexers, ) }
go
func NewFilteredApplicationInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options v1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } return client.ArgoprojV1alpha1().Applications(namespace).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } return client.ArgoprojV1alpha1().Applications(namespace).Watch(options) }, }, &applicationv1alpha1.Application{}, resyncPeriod, indexers, ) }
[ "func", "NewFilteredApplicationInformer", "(", "client", "versioned", ".", "Interface", ",", "namespace", "string", ",", "resyncPeriod", "time", ".", "Duration", ",", "indexers", "cache", ".", "Indexers", ",", "tweakListOptions", "internalinterfaces", ".", "TweakListOptionsFunc", ")", "cache", ".", "SharedIndexInformer", "{", "return", "cache", ".", "NewSharedIndexInformer", "(", "&", "cache", ".", "ListWatch", "{", "ListFunc", ":", "func", "(", "options", "v1", ".", "ListOptions", ")", "(", "runtime", ".", "Object", ",", "error", ")", "{", "if", "tweakListOptions", "!=", "nil", "{", "tweakListOptions", "(", "&", "options", ")", "\n", "}", "\n", "return", "client", ".", "ArgoprojV1alpha1", "(", ")", ".", "Applications", "(", "namespace", ")", ".", "List", "(", "options", ")", "\n", "}", ",", "WatchFunc", ":", "func", "(", "options", "v1", ".", "ListOptions", ")", "(", "watch", ".", "Interface", ",", "error", ")", "{", "if", "tweakListOptions", "!=", "nil", "{", "tweakListOptions", "(", "&", "options", ")", "\n", "}", "\n", "return", "client", ".", "ArgoprojV1alpha1", "(", ")", ".", "Applications", "(", "namespace", ")", ".", "Watch", "(", "options", ")", "\n", "}", ",", "}", ",", "&", "applicationv1alpha1", ".", "Application", "{", "}", ",", "resyncPeriod", ",", "indexers", ",", ")", "\n", "}" ]
// NewFilteredApplicationInformer constructs a new informer for Application type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server.
[ "NewFilteredApplicationInformer", "constructs", "a", "new", "informer", "for", "Application", "type", ".", "Always", "prefer", "using", "an", "informer", "factory", "to", "get", "a", "shared", "informer", "instead", "of", "getting", "an", "independent", "one", ".", "This", "reduces", "memory", "footprint", "and", "number", "of", "connections", "to", "the", "server", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/pkg/client/informers/externalversions/application/v1alpha1/application.go#L41-L61
161,784
argoproj/argo-cd
util/db/db.go
NewDB
func NewDB(namespace string, settingsMgr *settings.SettingsManager, kubeclientset kubernetes.Interface) ArgoDB { return &db{ settingsMgr: settingsMgr, ns: namespace, kubeclientset: kubeclientset, } }
go
func NewDB(namespace string, settingsMgr *settings.SettingsManager, kubeclientset kubernetes.Interface) ArgoDB { return &db{ settingsMgr: settingsMgr, ns: namespace, kubeclientset: kubeclientset, } }
[ "func", "NewDB", "(", "namespace", "string", ",", "settingsMgr", "*", "settings", ".", "SettingsManager", ",", "kubeclientset", "kubernetes", ".", "Interface", ")", "ArgoDB", "{", "return", "&", "db", "{", "settingsMgr", ":", "settingsMgr", ",", "ns", ":", "namespace", ",", "kubeclientset", ":", "kubeclientset", ",", "}", "\n", "}" ]
// NewDB returns a new instance of the argo database
[ "NewDB", "returns", "a", "new", "instance", "of", "the", "argo", "database" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/db/db.go#L49-L55
161,785
argoproj/argo-cd
util/git/git.go
removeSuffix
func removeSuffix(s, suffix string) string { if strings.HasSuffix(s, suffix) { return s[0 : len(s)-len(suffix)] } return s }
go
func removeSuffix(s, suffix string) string { if strings.HasSuffix(s, suffix) { return s[0 : len(s)-len(suffix)] } return s }
[ "func", "removeSuffix", "(", "s", ",", "suffix", "string", ")", "string", "{", "if", "strings", ".", "HasSuffix", "(", "s", ",", "suffix", ")", "{", "return", "s", "[", "0", ":", "len", "(", "s", ")", "-", "len", "(", "suffix", ")", "]", "\n", "}", "\n", "return", "s", "\n", "}" ]
// removeSuffix idempotently removes a given suffix
[ "removeSuffix", "idempotently", "removes", "a", "given", "suffix" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/git/git.go#L18-L23
161,786
argoproj/argo-cd
util/git/git.go
IsSSHURL
func IsSSHURL(url string) bool { return strings.HasPrefix(url, "git@") || strings.HasPrefix(url, "ssh://") }
go
func IsSSHURL(url string) bool { return strings.HasPrefix(url, "git@") || strings.HasPrefix(url, "ssh://") }
[ "func", "IsSSHURL", "(", "url", "string", ")", "bool", "{", "return", "strings", ".", "HasPrefix", "(", "url", ",", "\"", "\"", ")", "||", "strings", ".", "HasPrefix", "(", "url", ",", "\"", "\"", ")", "\n", "}" ]
// IsSSHURL returns true if supplied URL is SSH URL
[ "IsSSHURL", "returns", "true", "if", "supplied", "URL", "is", "SSH", "URL" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/git/git.go#L63-L65
161,787
argoproj/argo-cd
pkg/client/informers/externalversions/application/v1alpha1/appproject.go
NewAppProjectInformer
func NewAppProjectInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { return NewFilteredAppProjectInformer(client, namespace, resyncPeriod, indexers, nil) }
go
func NewAppProjectInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { return NewFilteredAppProjectInformer(client, namespace, resyncPeriod, indexers, nil) }
[ "func", "NewAppProjectInformer", "(", "client", "versioned", ".", "Interface", ",", "namespace", "string", ",", "resyncPeriod", "time", ".", "Duration", ",", "indexers", "cache", ".", "Indexers", ")", "cache", ".", "SharedIndexInformer", "{", "return", "NewFilteredAppProjectInformer", "(", "client", ",", "namespace", ",", "resyncPeriod", ",", "indexers", ",", "nil", ")", "\n", "}" ]
// NewAppProjectInformer constructs a new informer for AppProject type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server.
[ "NewAppProjectInformer", "constructs", "a", "new", "informer", "for", "AppProject", "type", ".", "Always", "prefer", "using", "an", "informer", "factory", "to", "get", "a", "shared", "informer", "instead", "of", "getting", "an", "independent", "one", ".", "This", "reduces", "memory", "footprint", "and", "number", "of", "connections", "to", "the", "server", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/pkg/client/informers/externalversions/application/v1alpha1/appproject.go#L34-L36
161,788
argoproj/argo-cd
server/version/version.pb.gw.go
RegisterVersionServiceHandler
func RegisterVersionServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { return RegisterVersionServiceHandlerClient(ctx, mux, NewVersionServiceClient(conn)) }
go
func RegisterVersionServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { return RegisterVersionServiceHandlerClient(ctx, mux, NewVersionServiceClient(conn)) }
[ "func", "RegisterVersionServiceHandler", "(", "ctx", "context", ".", "Context", ",", "mux", "*", "runtime", ".", "ServeMux", ",", "conn", "*", "grpc", ".", "ClientConn", ")", "error", "{", "return", "RegisterVersionServiceHandlerClient", "(", "ctx", ",", "mux", ",", "NewVersionServiceClient", "(", "conn", ")", ")", "\n", "}" ]
// RegisterVersionServiceHandler registers the http handlers for service VersionService to "mux". // The handlers forward requests to the grpc endpoint over "conn".
[ "RegisterVersionServiceHandler", "registers", "the", "http", "handlers", "for", "service", "VersionService", "to", "mux", ".", "The", "handlers", "forward", "requests", "to", "the", "grpc", "endpoint", "over", "conn", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/version/version.pb.gw.go#L68-L70
161,789
argoproj/argo-cd
util/db/helmrepository.go
ListHelmRepos
func (db *db) ListHelmRepos(ctx context.Context) ([]*appv1.HelmRepository, error) { s, err := db.settingsMgr.GetSettings() if err != nil { return nil, err } repos := make([]*appv1.HelmRepository, len(s.HelmRepositories)) for i, helmRepoInfo := range s.HelmRepositories { repo, err := db.getHelmRepo(ctx, helmRepoInfo.URL, s) if err != nil { return nil, err } repos[i] = repo } return repos, nil }
go
func (db *db) ListHelmRepos(ctx context.Context) ([]*appv1.HelmRepository, error) { s, err := db.settingsMgr.GetSettings() if err != nil { return nil, err } repos := make([]*appv1.HelmRepository, len(s.HelmRepositories)) for i, helmRepoInfo := range s.HelmRepositories { repo, err := db.getHelmRepo(ctx, helmRepoInfo.URL, s) if err != nil { return nil, err } repos[i] = repo } return repos, nil }
[ "func", "(", "db", "*", "db", ")", "ListHelmRepos", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "*", "appv1", ".", "HelmRepository", ",", "error", ")", "{", "s", ",", "err", ":=", "db", ".", "settingsMgr", ".", "GetSettings", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "repos", ":=", "make", "(", "[", "]", "*", "appv1", ".", "HelmRepository", ",", "len", "(", "s", ".", "HelmRepositories", ")", ")", "\n", "for", "i", ",", "helmRepoInfo", ":=", "range", "s", ".", "HelmRepositories", "{", "repo", ",", "err", ":=", "db", ".", "getHelmRepo", "(", "ctx", ",", "helmRepoInfo", ".", "URL", ",", "s", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "repos", "[", "i", "]", "=", "repo", "\n", "}", "\n", "return", "repos", ",", "nil", "\n", "}" ]
// ListHelmRepoURLs lists configured helm repositories
[ "ListHelmRepoURLs", "lists", "configured", "helm", "repositories" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/util/db/helmrepository.go#L53-L68
161,790
argoproj/argo-cd
server/project/project.pb.gw.go
RegisterProjectServiceHandler
func RegisterProjectServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { return RegisterProjectServiceHandlerClient(ctx, mux, NewProjectServiceClient(conn)) }
go
func RegisterProjectServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { return RegisterProjectServiceHandlerClient(ctx, mux, NewProjectServiceClient(conn)) }
[ "func", "RegisterProjectServiceHandler", "(", "ctx", "context", ".", "Context", ",", "mux", "*", "runtime", ".", "ServeMux", ",", "conn", "*", "grpc", ".", "ClientConn", ")", "error", "{", "return", "RegisterProjectServiceHandlerClient", "(", "ctx", ",", "mux", ",", "NewProjectServiceClient", "(", "conn", ")", ")", "\n", "}" ]
// RegisterProjectServiceHandler registers the http handlers for service ProjectService to "mux". // The handlers forward requests to the grpc endpoint over "conn".
[ "RegisterProjectServiceHandler", "registers", "the", "http", "handlers", "for", "service", "ProjectService", "to", "mux", ".", "The", "handlers", "forward", "requests", "to", "the", "grpc", "endpoint", "over", "conn", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/project/project.pb.gw.go#L291-L293
161,791
argoproj/argo-cd
controller/cache/cluster.go
startMissingWatches
func (c *clusterInfo) startMissingWatches() error { apis, err := c.kubectl.GetAPIResources(c.cluster.RESTConfig(), c.settings) if err != nil { return err } for i := range apis { api := apis[i] if _, ok := c.apisMeta[api.GroupKind]; !ok { ctx, cancel := context.WithCancel(context.Background()) info := &apiMeta{namespaced: api.Meta.Namespaced, watchCancel: cancel} c.apisMeta[api.GroupKind] = info go c.watchEvents(ctx, api, info) } } return nil }
go
func (c *clusterInfo) startMissingWatches() error { apis, err := c.kubectl.GetAPIResources(c.cluster.RESTConfig(), c.settings) if err != nil { return err } for i := range apis { api := apis[i] if _, ok := c.apisMeta[api.GroupKind]; !ok { ctx, cancel := context.WithCancel(context.Background()) info := &apiMeta{namespaced: api.Meta.Namespaced, watchCancel: cancel} c.apisMeta[api.GroupKind] = info go c.watchEvents(ctx, api, info) } } return nil }
[ "func", "(", "c", "*", "clusterInfo", ")", "startMissingWatches", "(", ")", "error", "{", "apis", ",", "err", ":=", "c", ".", "kubectl", ".", "GetAPIResources", "(", "c", ".", "cluster", ".", "RESTConfig", "(", ")", ",", "c", ".", "settings", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "for", "i", ":=", "range", "apis", "{", "api", ":=", "apis", "[", "i", "]", "\n", "if", "_", ",", "ok", ":=", "c", ".", "apisMeta", "[", "api", ".", "GroupKind", "]", ";", "!", "ok", "{", "ctx", ",", "cancel", ":=", "context", ".", "WithCancel", "(", "context", ".", "Background", "(", ")", ")", "\n", "info", ":=", "&", "apiMeta", "{", "namespaced", ":", "api", ".", "Meta", ".", "Namespaced", ",", "watchCancel", ":", "cancel", "}", "\n", "c", ".", "apisMeta", "[", "api", ".", "GroupKind", "]", "=", "info", "\n", "go", "c", ".", "watchEvents", "(", "ctx", ",", "api", ",", "info", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// startMissingWatches lists supported cluster resources and start watching for changes unless watch is already running
[ "startMissingWatches", "lists", "supported", "cluster", "resources", "and", "start", "watching", "for", "changes", "unless", "watch", "is", "already", "running" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/controller/cache/cluster.go#L169-L186
161,792
argoproj/argo-cd
server/cluster/cluster.go
NewServer
func NewServer(db db.ArgoDB, enf *rbac.Enforcer, cache *cache.Cache) *Server { return &Server{ db: db, enf: enf, cache: cache, } }
go
func NewServer(db db.ArgoDB, enf *rbac.Enforcer, cache *cache.Cache) *Server { return &Server{ db: db, enf: enf, cache: cache, } }
[ "func", "NewServer", "(", "db", "db", ".", "ArgoDB", ",", "enf", "*", "rbac", ".", "Enforcer", ",", "cache", "*", "cache", ".", "Cache", ")", "*", "Server", "{", "return", "&", "Server", "{", "db", ":", "db", ",", "enf", ":", "enf", ",", "cache", ":", "cache", ",", "}", "\n", "}" ]
// NewServer returns a new instance of the Cluster service
[ "NewServer", "returns", "a", "new", "instance", "of", "the", "Cluster", "service" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/cluster/cluster.go#L34-L40
161,793
argoproj/argo-cd
server/cluster/cluster.go
List
func (s *Server) List(ctx context.Context, q *ClusterQuery) (*appv1.ClusterList, error) { clusterList, err := s.db.ListClusters(ctx) if err != nil { return nil, err } clustersByServer := make(map[string][]appv1.Cluster) for _, clust := range clusterList.Items { if s.enf.Enforce(ctx.Value("claims"), rbacpolicy.ResourceClusters, rbacpolicy.ActionGet, clust.Server) { clustersByServer[clust.Server] = append(clustersByServer[clust.Server], clust) } } servers := make([]string, 0) for server := range clustersByServer { servers = append(servers, server) } items := make([]appv1.Cluster, len(servers)) err = util.RunAllAsync(len(servers), func(i int) error { clusters := clustersByServer[servers[i]] clust := clusters[0] warningMessage := "" if len(clusters) > 1 { warningMessage = fmt.Sprintf("There are %d credentials configured this cluster.", len(clusters)) } if clust.ConnectionState.Status == "" { clust.ConnectionState = s.getConnectionState(ctx, clust, warningMessage) } items[i] = *redact(&clust) return nil }) if err != nil { return nil, err } clusterList.Items = items return clusterList, err }
go
func (s *Server) List(ctx context.Context, q *ClusterQuery) (*appv1.ClusterList, error) { clusterList, err := s.db.ListClusters(ctx) if err != nil { return nil, err } clustersByServer := make(map[string][]appv1.Cluster) for _, clust := range clusterList.Items { if s.enf.Enforce(ctx.Value("claims"), rbacpolicy.ResourceClusters, rbacpolicy.ActionGet, clust.Server) { clustersByServer[clust.Server] = append(clustersByServer[clust.Server], clust) } } servers := make([]string, 0) for server := range clustersByServer { servers = append(servers, server) } items := make([]appv1.Cluster, len(servers)) err = util.RunAllAsync(len(servers), func(i int) error { clusters := clustersByServer[servers[i]] clust := clusters[0] warningMessage := "" if len(clusters) > 1 { warningMessage = fmt.Sprintf("There are %d credentials configured this cluster.", len(clusters)) } if clust.ConnectionState.Status == "" { clust.ConnectionState = s.getConnectionState(ctx, clust, warningMessage) } items[i] = *redact(&clust) return nil }) if err != nil { return nil, err } clusterList.Items = items return clusterList, err }
[ "func", "(", "s", "*", "Server", ")", "List", "(", "ctx", "context", ".", "Context", ",", "q", "*", "ClusterQuery", ")", "(", "*", "appv1", ".", "ClusterList", ",", "error", ")", "{", "clusterList", ",", "err", ":=", "s", ".", "db", ".", "ListClusters", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "clustersByServer", ":=", "make", "(", "map", "[", "string", "]", "[", "]", "appv1", ".", "Cluster", ")", "\n", "for", "_", ",", "clust", ":=", "range", "clusterList", ".", "Items", "{", "if", "s", ".", "enf", ".", "Enforce", "(", "ctx", ".", "Value", "(", "\"", "\"", ")", ",", "rbacpolicy", ".", "ResourceClusters", ",", "rbacpolicy", ".", "ActionGet", ",", "clust", ".", "Server", ")", "{", "clustersByServer", "[", "clust", ".", "Server", "]", "=", "append", "(", "clustersByServer", "[", "clust", ".", "Server", "]", ",", "clust", ")", "\n", "}", "\n", "}", "\n", "servers", ":=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "for", "server", ":=", "range", "clustersByServer", "{", "servers", "=", "append", "(", "servers", ",", "server", ")", "\n", "}", "\n\n", "items", ":=", "make", "(", "[", "]", "appv1", ".", "Cluster", ",", "len", "(", "servers", ")", ")", "\n", "err", "=", "util", ".", "RunAllAsync", "(", "len", "(", "servers", ")", ",", "func", "(", "i", "int", ")", "error", "{", "clusters", ":=", "clustersByServer", "[", "servers", "[", "i", "]", "]", "\n", "clust", ":=", "clusters", "[", "0", "]", "\n", "warningMessage", ":=", "\"", "\"", "\n", "if", "len", "(", "clusters", ")", ">", "1", "{", "warningMessage", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "len", "(", "clusters", ")", ")", "\n", "}", "\n", "if", "clust", ".", "ConnectionState", ".", "Status", "==", "\"", "\"", "{", "clust", ".", "ConnectionState", "=", "s", ".", "getConnectionState", "(", "ctx", ",", "clust", ",", "warningMessage", ")", "\n", "}", "\n", "items", "[", "i", "]", "=", "*", "redact", "(", "&", "clust", ")", "\n", "return", "nil", "\n", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "clusterList", ".", "Items", "=", "items", "\n", "return", "clusterList", ",", "err", "\n", "}" ]
// List returns list of clusters
[ "List", "returns", "list", "of", "clusters" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/cluster/cluster.go#L76-L112
161,794
argoproj/argo-cd
server/cluster/cluster.go
Get
func (s *Server) Get(ctx context.Context, q *ClusterQuery) (*appv1.Cluster, error) { if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceClusters, rbacpolicy.ActionGet, q.Server); err != nil { return nil, err } clust, err := s.db.GetCluster(ctx, q.Server) return redact(clust), err }
go
func (s *Server) Get(ctx context.Context, q *ClusterQuery) (*appv1.Cluster, error) { if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceClusters, rbacpolicy.ActionGet, q.Server); err != nil { return nil, err } clust, err := s.db.GetCluster(ctx, q.Server) return redact(clust), err }
[ "func", "(", "s", "*", "Server", ")", "Get", "(", "ctx", "context", ".", "Context", ",", "q", "*", "ClusterQuery", ")", "(", "*", "appv1", ".", "Cluster", ",", "error", ")", "{", "if", "err", ":=", "s", ".", "enf", ".", "EnforceErr", "(", "ctx", ".", "Value", "(", "\"", "\"", ")", ",", "rbacpolicy", ".", "ResourceClusters", ",", "rbacpolicy", ".", "ActionGet", ",", "q", ".", "Server", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "clust", ",", "err", ":=", "s", ".", "db", ".", "GetCluster", "(", "ctx", ",", "q", ".", "Server", ")", "\n", "return", "redact", "(", "clust", ")", ",", "err", "\n", "}" ]
// Get returns a cluster from a query
[ "Get", "returns", "a", "cluster", "from", "a", "query" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/cluster/cluster.go#L195-L201
161,795
argoproj/argo-cd
server/cluster/cluster.go
Update
func (s *Server) Update(ctx context.Context, q *ClusterUpdateRequest) (*appv1.Cluster, error) { if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceClusters, rbacpolicy.ActionUpdate, q.Cluster.Server); err != nil { return nil, err } err := kube.TestConfig(q.Cluster.RESTConfig()) if err != nil { return nil, err } clust, err := s.db.UpdateCluster(ctx, q.Cluster) return redact(clust), err }
go
func (s *Server) Update(ctx context.Context, q *ClusterUpdateRequest) (*appv1.Cluster, error) { if err := s.enf.EnforceErr(ctx.Value("claims"), rbacpolicy.ResourceClusters, rbacpolicy.ActionUpdate, q.Cluster.Server); err != nil { return nil, err } err := kube.TestConfig(q.Cluster.RESTConfig()) if err != nil { return nil, err } clust, err := s.db.UpdateCluster(ctx, q.Cluster) return redact(clust), err }
[ "func", "(", "s", "*", "Server", ")", "Update", "(", "ctx", "context", ".", "Context", ",", "q", "*", "ClusterUpdateRequest", ")", "(", "*", "appv1", ".", "Cluster", ",", "error", ")", "{", "if", "err", ":=", "s", ".", "enf", ".", "EnforceErr", "(", "ctx", ".", "Value", "(", "\"", "\"", ")", ",", "rbacpolicy", ".", "ResourceClusters", ",", "rbacpolicy", ".", "ActionUpdate", ",", "q", ".", "Cluster", ".", "Server", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "err", ":=", "kube", ".", "TestConfig", "(", "q", ".", "Cluster", ".", "RESTConfig", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "clust", ",", "err", ":=", "s", ".", "db", ".", "UpdateCluster", "(", "ctx", ",", "q", ".", "Cluster", ")", "\n", "return", "redact", "(", "clust", ")", ",", "err", "\n", "}" ]
// Update updates a cluster
[ "Update", "updates", "a", "cluster" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/server/cluster/cluster.go#L204-L214
161,796
argoproj/argo-cd
hack/update-openapi-validation/main.go
main
func main() { if len(os.Args) != 3 { log.Fatalf("Usage: %s CRDSPEC TYPE", os.Args[0]) } crdPath := os.Args[1] typePath := os.Args[2] data, err := ioutil.ReadFile(crdPath) if err != nil { log.Fatal(err) } var crd apiextensions.CustomResourceDefinition err = yaml.Unmarshal(data, &crd) if err != nil { log.Fatal(err) } crd.Spec.Validation = crdutil.GetCustomResourceValidation(typePath, v1alpha1.GetOpenAPIDefinitions) jsonBytes, err := json.Marshal(crd) if err != nil { log.Fatal(err) } var r unstructured.Unstructured if err := json.Unmarshal(jsonBytes, &r.Object); err != nil { log.Fatal(err) } unstructured.RemoveNestedField(r.Object, "status") unstructured.RemoveNestedField(r.Object, "metadata", "creationTimestamp") jsonBytes, err = json.MarshalIndent(r.Object, "", " ") if err != nil { log.Fatal(err) } yamlBytes, err := yaml.JSONToYAML(jsonBytes) if err != nil { log.Fatal(err) } err = ioutil.WriteFile(crdPath, yamlBytes, 0644) if err != nil { panic(err) } os.Exit(0) }
go
func main() { if len(os.Args) != 3 { log.Fatalf("Usage: %s CRDSPEC TYPE", os.Args[0]) } crdPath := os.Args[1] typePath := os.Args[2] data, err := ioutil.ReadFile(crdPath) if err != nil { log.Fatal(err) } var crd apiextensions.CustomResourceDefinition err = yaml.Unmarshal(data, &crd) if err != nil { log.Fatal(err) } crd.Spec.Validation = crdutil.GetCustomResourceValidation(typePath, v1alpha1.GetOpenAPIDefinitions) jsonBytes, err := json.Marshal(crd) if err != nil { log.Fatal(err) } var r unstructured.Unstructured if err := json.Unmarshal(jsonBytes, &r.Object); err != nil { log.Fatal(err) } unstructured.RemoveNestedField(r.Object, "status") unstructured.RemoveNestedField(r.Object, "metadata", "creationTimestamp") jsonBytes, err = json.MarshalIndent(r.Object, "", " ") if err != nil { log.Fatal(err) } yamlBytes, err := yaml.JSONToYAML(jsonBytes) if err != nil { log.Fatal(err) } err = ioutil.WriteFile(crdPath, yamlBytes, 0644) if err != nil { panic(err) } os.Exit(0) }
[ "func", "main", "(", ")", "{", "if", "len", "(", "os", ".", "Args", ")", "!=", "3", "{", "log", ".", "Fatalf", "(", "\"", "\"", ",", "os", ".", "Args", "[", "0", "]", ")", "\n", "}", "\n", "crdPath", ":=", "os", ".", "Args", "[", "1", "]", "\n", "typePath", ":=", "os", ".", "Args", "[", "2", "]", "\n\n", "data", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "crdPath", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatal", "(", "err", ")", "\n", "}", "\n", "var", "crd", "apiextensions", ".", "CustomResourceDefinition", "\n", "err", "=", "yaml", ".", "Unmarshal", "(", "data", ",", "&", "crd", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatal", "(", "err", ")", "\n", "}", "\n", "crd", ".", "Spec", ".", "Validation", "=", "crdutil", ".", "GetCustomResourceValidation", "(", "typePath", ",", "v1alpha1", ".", "GetOpenAPIDefinitions", ")", "\n\n", "jsonBytes", ",", "err", ":=", "json", ".", "Marshal", "(", "crd", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatal", "(", "err", ")", "\n", "}", "\n\n", "var", "r", "unstructured", ".", "Unstructured", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "jsonBytes", ",", "&", "r", ".", "Object", ")", ";", "err", "!=", "nil", "{", "log", ".", "Fatal", "(", "err", ")", "\n", "}", "\n\n", "unstructured", ".", "RemoveNestedField", "(", "r", ".", "Object", ",", "\"", "\"", ")", "\n", "unstructured", ".", "RemoveNestedField", "(", "r", ".", "Object", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "jsonBytes", ",", "err", "=", "json", ".", "MarshalIndent", "(", "r", ".", "Object", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatal", "(", "err", ")", "\n", "}", "\n", "yamlBytes", ",", "err", ":=", "yaml", ".", "JSONToYAML", "(", "jsonBytes", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatal", "(", "err", ")", "\n", "}", "\n\n", "err", "=", "ioutil", ".", "WriteFile", "(", "crdPath", ",", "yamlBytes", ",", "0644", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "os", ".", "Exit", "(", "0", ")", "\n\n", "}" ]
// Generate OpenAPI spec definitions for Rollout Resource
[ "Generate", "OpenAPI", "spec", "definitions", "for", "Rollout", "Resource" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/hack/update-openapi-validation/main.go#L18-L63
161,797
argoproj/argo-cd
pkg/apiclient/apiclient.go
NewClient
func NewClient(opts *ClientOptions) (Client, error) { var c client localCfg, err := localconfig.ReadLocalConfig(opts.ConfigPath) if err != nil { return nil, err } c.proxyMutex = &sync.Mutex{} var ctxName string if localCfg != nil { configCtx, err := localCfg.ResolveContext(opts.Context) if err != nil { return nil, err } if configCtx != nil { c.ServerAddr = configCtx.Server.Server if configCtx.Server.CACertificateAuthorityData != "" { c.CertPEMData, err = base64.StdEncoding.DecodeString(configCtx.Server.CACertificateAuthorityData) if err != nil { return nil, err } } c.PlainText = configCtx.Server.PlainText c.Insecure = configCtx.Server.Insecure c.GRPCWeb = configCtx.Server.GRPCWeb c.AuthToken = configCtx.User.AuthToken c.RefreshToken = configCtx.User.RefreshToken ctxName = configCtx.Name } } if opts.UserAgent != "" { c.UserAgent = opts.UserAgent } else { c.UserAgent = fmt.Sprintf("%s/%s", common.ArgoCDUserAgentName, argocd.GetVersion().Version) } // Override server address if specified in env or CLI flag if serverFromEnv := os.Getenv(EnvArgoCDServer); serverFromEnv != "" { c.ServerAddr = serverFromEnv } if opts.ServerAddr != "" { c.ServerAddr = opts.ServerAddr } // Make sure we got the server address and auth token from somewhere if c.ServerAddr == "" { return nil, errors.New("Argo CD server address unspecified") } if parts := strings.Split(c.ServerAddr, ":"); len(parts) == 1 { // If port is unspecified, assume the most likely port c.ServerAddr += ":443" } // Override auth-token if specified in env variable or CLI flag if authFromEnv := os.Getenv(EnvArgoCDAuthToken); authFromEnv != "" { c.AuthToken = authFromEnv } if opts.AuthToken != "" { c.AuthToken = opts.AuthToken } // Override certificate data if specified from CLI flag if opts.CertFile != "" { b, err := ioutil.ReadFile(opts.CertFile) if err != nil { return nil, err } c.CertPEMData = b } // Override insecure/plaintext options if specified from CLI if opts.PlainText { c.PlainText = true } if opts.Insecure { c.Insecure = true } if opts.GRPCWeb { c.GRPCWeb = true } if localCfg != nil { err = c.refreshAuthToken(localCfg, ctxName, opts.ConfigPath) if err != nil { return nil, err } } return &c, nil }
go
func NewClient(opts *ClientOptions) (Client, error) { var c client localCfg, err := localconfig.ReadLocalConfig(opts.ConfigPath) if err != nil { return nil, err } c.proxyMutex = &sync.Mutex{} var ctxName string if localCfg != nil { configCtx, err := localCfg.ResolveContext(opts.Context) if err != nil { return nil, err } if configCtx != nil { c.ServerAddr = configCtx.Server.Server if configCtx.Server.CACertificateAuthorityData != "" { c.CertPEMData, err = base64.StdEncoding.DecodeString(configCtx.Server.CACertificateAuthorityData) if err != nil { return nil, err } } c.PlainText = configCtx.Server.PlainText c.Insecure = configCtx.Server.Insecure c.GRPCWeb = configCtx.Server.GRPCWeb c.AuthToken = configCtx.User.AuthToken c.RefreshToken = configCtx.User.RefreshToken ctxName = configCtx.Name } } if opts.UserAgent != "" { c.UserAgent = opts.UserAgent } else { c.UserAgent = fmt.Sprintf("%s/%s", common.ArgoCDUserAgentName, argocd.GetVersion().Version) } // Override server address if specified in env or CLI flag if serverFromEnv := os.Getenv(EnvArgoCDServer); serverFromEnv != "" { c.ServerAddr = serverFromEnv } if opts.ServerAddr != "" { c.ServerAddr = opts.ServerAddr } // Make sure we got the server address and auth token from somewhere if c.ServerAddr == "" { return nil, errors.New("Argo CD server address unspecified") } if parts := strings.Split(c.ServerAddr, ":"); len(parts) == 1 { // If port is unspecified, assume the most likely port c.ServerAddr += ":443" } // Override auth-token if specified in env variable or CLI flag if authFromEnv := os.Getenv(EnvArgoCDAuthToken); authFromEnv != "" { c.AuthToken = authFromEnv } if opts.AuthToken != "" { c.AuthToken = opts.AuthToken } // Override certificate data if specified from CLI flag if opts.CertFile != "" { b, err := ioutil.ReadFile(opts.CertFile) if err != nil { return nil, err } c.CertPEMData = b } // Override insecure/plaintext options if specified from CLI if opts.PlainText { c.PlainText = true } if opts.Insecure { c.Insecure = true } if opts.GRPCWeb { c.GRPCWeb = true } if localCfg != nil { err = c.refreshAuthToken(localCfg, ctxName, opts.ConfigPath) if err != nil { return nil, err } } return &c, nil }
[ "func", "NewClient", "(", "opts", "*", "ClientOptions", ")", "(", "Client", ",", "error", ")", "{", "var", "c", "client", "\n", "localCfg", ",", "err", ":=", "localconfig", ".", "ReadLocalConfig", "(", "opts", ".", "ConfigPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "c", ".", "proxyMutex", "=", "&", "sync", ".", "Mutex", "{", "}", "\n", "var", "ctxName", "string", "\n", "if", "localCfg", "!=", "nil", "{", "configCtx", ",", "err", ":=", "localCfg", ".", "ResolveContext", "(", "opts", ".", "Context", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "configCtx", "!=", "nil", "{", "c", ".", "ServerAddr", "=", "configCtx", ".", "Server", ".", "Server", "\n", "if", "configCtx", ".", "Server", ".", "CACertificateAuthorityData", "!=", "\"", "\"", "{", "c", ".", "CertPEMData", ",", "err", "=", "base64", ".", "StdEncoding", ".", "DecodeString", "(", "configCtx", ".", "Server", ".", "CACertificateAuthorityData", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "c", ".", "PlainText", "=", "configCtx", ".", "Server", ".", "PlainText", "\n", "c", ".", "Insecure", "=", "configCtx", ".", "Server", ".", "Insecure", "\n", "c", ".", "GRPCWeb", "=", "configCtx", ".", "Server", ".", "GRPCWeb", "\n", "c", ".", "AuthToken", "=", "configCtx", ".", "User", ".", "AuthToken", "\n", "c", ".", "RefreshToken", "=", "configCtx", ".", "User", ".", "RefreshToken", "\n", "ctxName", "=", "configCtx", ".", "Name", "\n", "}", "\n", "}", "\n", "if", "opts", ".", "UserAgent", "!=", "\"", "\"", "{", "c", ".", "UserAgent", "=", "opts", ".", "UserAgent", "\n", "}", "else", "{", "c", ".", "UserAgent", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "common", ".", "ArgoCDUserAgentName", ",", "argocd", ".", "GetVersion", "(", ")", ".", "Version", ")", "\n", "}", "\n", "// Override server address if specified in env or CLI flag", "if", "serverFromEnv", ":=", "os", ".", "Getenv", "(", "EnvArgoCDServer", ")", ";", "serverFromEnv", "!=", "\"", "\"", "{", "c", ".", "ServerAddr", "=", "serverFromEnv", "\n", "}", "\n", "if", "opts", ".", "ServerAddr", "!=", "\"", "\"", "{", "c", ".", "ServerAddr", "=", "opts", ".", "ServerAddr", "\n", "}", "\n", "// Make sure we got the server address and auth token from somewhere", "if", "c", ".", "ServerAddr", "==", "\"", "\"", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "parts", ":=", "strings", ".", "Split", "(", "c", ".", "ServerAddr", ",", "\"", "\"", ")", ";", "len", "(", "parts", ")", "==", "1", "{", "// If port is unspecified, assume the most likely port", "c", ".", "ServerAddr", "+=", "\"", "\"", "\n", "}", "\n", "// Override auth-token if specified in env variable or CLI flag", "if", "authFromEnv", ":=", "os", ".", "Getenv", "(", "EnvArgoCDAuthToken", ")", ";", "authFromEnv", "!=", "\"", "\"", "{", "c", ".", "AuthToken", "=", "authFromEnv", "\n", "}", "\n", "if", "opts", ".", "AuthToken", "!=", "\"", "\"", "{", "c", ".", "AuthToken", "=", "opts", ".", "AuthToken", "\n", "}", "\n", "// Override certificate data if specified from CLI flag", "if", "opts", ".", "CertFile", "!=", "\"", "\"", "{", "b", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "opts", ".", "CertFile", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "c", ".", "CertPEMData", "=", "b", "\n", "}", "\n", "// Override insecure/plaintext options if specified from CLI", "if", "opts", ".", "PlainText", "{", "c", ".", "PlainText", "=", "true", "\n", "}", "\n", "if", "opts", ".", "Insecure", "{", "c", ".", "Insecure", "=", "true", "\n", "}", "\n", "if", "opts", ".", "GRPCWeb", "{", "c", ".", "GRPCWeb", "=", "true", "\n", "}", "\n", "if", "localCfg", "!=", "nil", "{", "err", "=", "c", ".", "refreshAuthToken", "(", "localCfg", ",", "ctxName", ",", "opts", ".", "ConfigPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "return", "&", "c", ",", "nil", "\n", "}" ]
// NewClient creates a new API client from a set of config options.
[ "NewClient", "creates", "a", "new", "API", "client", "from", "a", "set", "of", "config", "options", "." ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/pkg/apiclient/apiclient.go#L112-L193
161,798
argoproj/argo-cd
pkg/apiclient/apiclient.go
OIDCConfig
func (c *client) OIDCConfig(ctx context.Context, set *settings.Settings) (*oauth2.Config, *oidc.Provider, error) { var clientID string var issuerURL string if set.DexConfig != nil && len(set.DexConfig.Connectors) > 0 { clientID = common.ArgoCDCLIClientAppID issuerURL = fmt.Sprintf("%s%s", set.URL, common.DexAPIEndpoint) } else if set.OIDCConfig != nil && set.OIDCConfig.Issuer != "" { if set.OIDCConfig.CLIClientID != "" { clientID = set.OIDCConfig.CLIClientID } else { clientID = set.OIDCConfig.ClientID } issuerURL = set.OIDCConfig.Issuer } else { return nil, nil, fmt.Errorf("%s is not configured with SSO", c.ServerAddr) } provider, err := oidc.NewProvider(ctx, issuerURL) if err != nil { return nil, nil, fmt.Errorf("Failed to query provider %q: %v", issuerURL, err) } oauth2conf := oauth2.Config{ ClientID: clientID, Scopes: clientScopes, Endpoint: provider.Endpoint(), } return &oauth2conf, provider, nil }
go
func (c *client) OIDCConfig(ctx context.Context, set *settings.Settings) (*oauth2.Config, *oidc.Provider, error) { var clientID string var issuerURL string if set.DexConfig != nil && len(set.DexConfig.Connectors) > 0 { clientID = common.ArgoCDCLIClientAppID issuerURL = fmt.Sprintf("%s%s", set.URL, common.DexAPIEndpoint) } else if set.OIDCConfig != nil && set.OIDCConfig.Issuer != "" { if set.OIDCConfig.CLIClientID != "" { clientID = set.OIDCConfig.CLIClientID } else { clientID = set.OIDCConfig.ClientID } issuerURL = set.OIDCConfig.Issuer } else { return nil, nil, fmt.Errorf("%s is not configured with SSO", c.ServerAddr) } provider, err := oidc.NewProvider(ctx, issuerURL) if err != nil { return nil, nil, fmt.Errorf("Failed to query provider %q: %v", issuerURL, err) } oauth2conf := oauth2.Config{ ClientID: clientID, Scopes: clientScopes, Endpoint: provider.Endpoint(), } return &oauth2conf, provider, nil }
[ "func", "(", "c", "*", "client", ")", "OIDCConfig", "(", "ctx", "context", ".", "Context", ",", "set", "*", "settings", ".", "Settings", ")", "(", "*", "oauth2", ".", "Config", ",", "*", "oidc", ".", "Provider", ",", "error", ")", "{", "var", "clientID", "string", "\n", "var", "issuerURL", "string", "\n", "if", "set", ".", "DexConfig", "!=", "nil", "&&", "len", "(", "set", ".", "DexConfig", ".", "Connectors", ")", ">", "0", "{", "clientID", "=", "common", ".", "ArgoCDCLIClientAppID", "\n", "issuerURL", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "set", ".", "URL", ",", "common", ".", "DexAPIEndpoint", ")", "\n", "}", "else", "if", "set", ".", "OIDCConfig", "!=", "nil", "&&", "set", ".", "OIDCConfig", ".", "Issuer", "!=", "\"", "\"", "{", "if", "set", ".", "OIDCConfig", ".", "CLIClientID", "!=", "\"", "\"", "{", "clientID", "=", "set", ".", "OIDCConfig", ".", "CLIClientID", "\n", "}", "else", "{", "clientID", "=", "set", ".", "OIDCConfig", ".", "ClientID", "\n", "}", "\n", "issuerURL", "=", "set", ".", "OIDCConfig", ".", "Issuer", "\n", "}", "else", "{", "return", "nil", ",", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "c", ".", "ServerAddr", ")", "\n", "}", "\n", "provider", ",", "err", ":=", "oidc", ".", "NewProvider", "(", "ctx", ",", "issuerURL", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "issuerURL", ",", "err", ")", "\n", "}", "\n", "oauth2conf", ":=", "oauth2", ".", "Config", "{", "ClientID", ":", "clientID", ",", "Scopes", ":", "clientScopes", ",", "Endpoint", ":", "provider", ".", "Endpoint", "(", ")", ",", "}", "\n", "return", "&", "oauth2conf", ",", "provider", ",", "nil", "\n", "}" ]
// OIDCConfig returns OAuth2 client config and a OpenID Provider based on Argo CD settings // ctx can hold an appropriate http.Client to use for the exchange
[ "OIDCConfig", "returns", "OAuth2", "client", "config", "and", "a", "OpenID", "Provider", "based", "on", "Argo", "CD", "settings", "ctx", "can", "hold", "an", "appropriate", "http", ".", "Client", "to", "use", "for", "the", "exchange" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/pkg/apiclient/apiclient.go#L197-L223
161,799
argoproj/argo-cd
pkg/apiclient/apiclient.go
HTTPClient
func (c *client) HTTPClient() (*http.Client, error) { tlsConfig, err := c.tlsConfig() if err != nil { return nil, err } return &http.Client{ Transport: &http.Transport{ TLSClientConfig: tlsConfig, Proxy: http.ProxyFromEnvironment, Dial: (&net.Dialer{ Timeout: 30 * time.Second, KeepAlive: 30 * time.Second, }).Dial, TLSHandshakeTimeout: 10 * time.Second, ExpectContinueTimeout: 1 * time.Second, }, }, nil }
go
func (c *client) HTTPClient() (*http.Client, error) { tlsConfig, err := c.tlsConfig() if err != nil { return nil, err } return &http.Client{ Transport: &http.Transport{ TLSClientConfig: tlsConfig, Proxy: http.ProxyFromEnvironment, Dial: (&net.Dialer{ Timeout: 30 * time.Second, KeepAlive: 30 * time.Second, }).Dial, TLSHandshakeTimeout: 10 * time.Second, ExpectContinueTimeout: 1 * time.Second, }, }, nil }
[ "func", "(", "c", "*", "client", ")", "HTTPClient", "(", ")", "(", "*", "http", ".", "Client", ",", "error", ")", "{", "tlsConfig", ",", "err", ":=", "c", ".", "tlsConfig", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "http", ".", "Client", "{", "Transport", ":", "&", "http", ".", "Transport", "{", "TLSClientConfig", ":", "tlsConfig", ",", "Proxy", ":", "http", ".", "ProxyFromEnvironment", ",", "Dial", ":", "(", "&", "net", ".", "Dialer", "{", "Timeout", ":", "30", "*", "time", ".", "Second", ",", "KeepAlive", ":", "30", "*", "time", ".", "Second", ",", "}", ")", ".", "Dial", ",", "TLSHandshakeTimeout", ":", "10", "*", "time", ".", "Second", ",", "ExpectContinueTimeout", ":", "1", "*", "time", ".", "Second", ",", "}", ",", "}", ",", "nil", "\n", "}" ]
// HTTPClient returns a HTTPClient appropriate for performing OAuth, based on TLS settings
[ "HTTPClient", "returns", "a", "HTTPClient", "appropriate", "for", "performing", "OAuth", "based", "on", "TLS", "settings" ]
5c353a12f2c67d8ab0d5d9aa619c9059c5261640
https://github.com/argoproj/argo-cd/blob/5c353a12f2c67d8ab0d5d9aa619c9059c5261640/pkg/apiclient/apiclient.go#L226-L243