MCPcopy Index your code
hub / github.com/devopsctl/gitlabctl / newGitlabClient

Function newGitlabClient

cmd/gitlab_client.go:40–82  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

38}
39
40func newGitlabClient() (*gitlab.Client, error) {
41 switch {
42 case getCfg("access_token") != "" && getCfg("host_url") != "":
43 gitlabClient, err :=
44 newOAuthClient(getCfg("access_token"), getCfg("host_url")+"/api/v4")
45 if err != nil {
46 return nil, err
47 }
48 return gitlabClient, nil
49
50 case getCfg("USERNAME") != "" &&
51 getCfg("PASSWORD") != "" &&
52 getCfg("HTTP_URL") != "":
53 gitlabClient, err := newBasicAuthClient(getCfg("USERNAME"),
54 getCfg("PASSWORD"),
55 getCfg("HTTP_URL"),
56 )
57 if err != nil {
58 return nil, err
59 }
60 return gitlabClient, nil
61
62 case getCfg("PRIVATE_TOKEN") != "" && getCfg("API_HTTP_URL") != "":
63 gitlabClient, err :=
64 newClient(getCfg("PRIVATE_TOKEN"), getCfg("API_HTTP_URL"))
65 if err != nil {
66 return nil, err
67 }
68 return gitlabClient, nil
69
70 case getCfg("OAUTH_TOKEN") != "" && getCfg("API_HTTP_URL") != "":
71 gitlabClient, err :=
72 newOAuthClient(getCfg("OAUTH_TOKEN"), getCfg("API_HTTP_URL"))
73 if err != nil {
74 return nil, err
75 }
76 return gitlabClient, nil
77
78 default:
79 return nil, fmt.Errorf("no client was created. "+
80 "gitlab configuration was not set properly. \n %s", authDoc)
81 }
82}
83
84// getCfg retrieves the value of a token from the config '--config' file
85// in 'key=value' format or from any environment variable that starts

Callers 15

getNamespaceIDFunction · 0.85
getBranchFunction · 0.85
deleteProjectHookFunction · 0.85
getProjectHooksFunction · 0.85
descGroupFunction · 0.85
getUsersFunction · 0.85
deleteUserFunction · 0.85
getGroupsFunction · 0.85
getSubgroupsFunction · 0.85
deleteTagFunction · 0.85
newReleaseFunction · 0.85
newProjectHookFunction · 0.85

Calls 4

getCfgFunction · 0.85
newOAuthClientFunction · 0.85
newBasicAuthClientFunction · 0.85
newClientFunction · 0.85

Tested by 1

TestGitlabNewClientFunction · 0.68