mirror of
https://github.com/grafana/grafana.git
synced 2025-07-29 05:12:31 +08:00
Provisioning: Add user token to git and bitbucket repository specs (#108186)
* Add token user to git and bitbucket specs * Use token user if available in git type
This commit is contained in:

committed by
GitHub

parent
0d1534e43c
commit
ae4dc181d1
@ -64,6 +64,8 @@ type GitRepositoryConfig struct {
|
|||||||
URL string `json:"url,omitempty"`
|
URL string `json:"url,omitempty"`
|
||||||
// The branch to use in the repository.
|
// The branch to use in the repository.
|
||||||
Branch string `json:"branch"`
|
Branch string `json:"branch"`
|
||||||
|
// TokenUser is the user that will be used to access the repository if it's a personal access token.
|
||||||
|
TokenUser string `json:"tokenUser,omitempty"`
|
||||||
// Token for accessing the repository. If set, it will be encrypted into encryptedToken, then set to an empty string again.
|
// Token for accessing the repository. If set, it will be encrypted into encryptedToken, then set to an empty string again.
|
||||||
Token string `json:"token,omitempty"`
|
Token string `json:"token,omitempty"`
|
||||||
// Token for accessing the repository, but encrypted. This is not possible to read back to a user decrypted.
|
// Token for accessing the repository, but encrypted. This is not possible to read back to a user decrypted.
|
||||||
@ -82,6 +84,8 @@ type BitbucketRepositoryConfig struct {
|
|||||||
URL string `json:"url,omitempty"`
|
URL string `json:"url,omitempty"`
|
||||||
// The branch to use in the repository.
|
// The branch to use in the repository.
|
||||||
Branch string `json:"branch"`
|
Branch string `json:"branch"`
|
||||||
|
// TokenUser is the user that will be used to access the repository if it's a personal access token.
|
||||||
|
TokenUser string `json:"tokenUser,omitempty"`
|
||||||
// Token for accessing the repository. If set, it will be encrypted into encryptedToken, then set to an empty string again.
|
// Token for accessing the repository. If set, it will be encrypted into encryptedToken, then set to an empty string again.
|
||||||
Token string `json:"token,omitempty"`
|
Token string `json:"token,omitempty"`
|
||||||
// Token for accessing the repository, but encrypted. This is not possible to read back to a user decrypted.
|
// Token for accessing the repository, but encrypted. This is not possible to read back to a user decrypted.
|
||||||
|
@ -115,6 +115,13 @@ func schema_pkg_apis_provisioning_v0alpha1_BitbucketRepositoryConfig(ref common.
|
|||||||
Format: "",
|
Format: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"tokenUser": {
|
||||||
|
SchemaProps: spec.SchemaProps{
|
||||||
|
Description: "TokenUser is the user that will be used to access the repository if it's a personal access token.",
|
||||||
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
"token": {
|
"token": {
|
||||||
SchemaProps: spec.SchemaProps{
|
SchemaProps: spec.SchemaProps{
|
||||||
Description: "Token for accessing the repository. If set, it will be encrypted into encryptedToken, then set to an empty string again.",
|
Description: "Token for accessing the repository. If set, it will be encrypted into encryptedToken, then set to an empty string again.",
|
||||||
@ -447,6 +454,13 @@ func schema_pkg_apis_provisioning_v0alpha1_GitRepositoryConfig(ref common.Refere
|
|||||||
Format: "",
|
Format: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"tokenUser": {
|
||||||
|
SchemaProps: spec.SchemaProps{
|
||||||
|
Description: "TokenUser is the user that will be used to access the repository if it's a personal access token.",
|
||||||
|
Type: []string{"string"},
|
||||||
|
Format: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
"token": {
|
"token": {
|
||||||
SchemaProps: spec.SchemaProps{
|
SchemaProps: spec.SchemaProps{
|
||||||
Description: "Token for accessing the repository. If set, it will be encrypted into encryptedToken, then set to an empty string again.",
|
Description: "Token for accessing the repository. If set, it will be encrypted into encryptedToken, then set to an empty string again.",
|
||||||
|
@ -9,6 +9,7 @@ package v0alpha1
|
|||||||
type BitbucketRepositoryConfigApplyConfiguration struct {
|
type BitbucketRepositoryConfigApplyConfiguration struct {
|
||||||
URL *string `json:"url,omitempty"`
|
URL *string `json:"url,omitempty"`
|
||||||
Branch *string `json:"branch,omitempty"`
|
Branch *string `json:"branch,omitempty"`
|
||||||
|
TokenUser *string `json:"tokenUser,omitempty"`
|
||||||
Token *string `json:"token,omitempty"`
|
Token *string `json:"token,omitempty"`
|
||||||
EncryptedToken []byte `json:"encryptedToken,omitempty"`
|
EncryptedToken []byte `json:"encryptedToken,omitempty"`
|
||||||
Path *string `json:"path,omitempty"`
|
Path *string `json:"path,omitempty"`
|
||||||
@ -36,6 +37,14 @@ func (b *BitbucketRepositoryConfigApplyConfiguration) WithBranch(value string) *
|
|||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithTokenUser sets the TokenUser field in the declarative configuration to the given value
|
||||||
|
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||||
|
// If called multiple times, the TokenUser field is set to the value of the last call.
|
||||||
|
func (b *BitbucketRepositoryConfigApplyConfiguration) WithTokenUser(value string) *BitbucketRepositoryConfigApplyConfiguration {
|
||||||
|
b.TokenUser = &value
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
// WithToken sets the Token field in the declarative configuration to the given value
|
// WithToken sets the Token field in the declarative configuration to the given value
|
||||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||||
// If called multiple times, the Token field is set to the value of the last call.
|
// If called multiple times, the Token field is set to the value of the last call.
|
||||||
|
@ -9,6 +9,7 @@ package v0alpha1
|
|||||||
type GitRepositoryConfigApplyConfiguration struct {
|
type GitRepositoryConfigApplyConfiguration struct {
|
||||||
URL *string `json:"url,omitempty"`
|
URL *string `json:"url,omitempty"`
|
||||||
Branch *string `json:"branch,omitempty"`
|
Branch *string `json:"branch,omitempty"`
|
||||||
|
TokenUser *string `json:"tokenUser,omitempty"`
|
||||||
Token *string `json:"token,omitempty"`
|
Token *string `json:"token,omitempty"`
|
||||||
EncryptedToken []byte `json:"encryptedToken,omitempty"`
|
EncryptedToken []byte `json:"encryptedToken,omitempty"`
|
||||||
Path *string `json:"path,omitempty"`
|
Path *string `json:"path,omitempty"`
|
||||||
@ -36,6 +37,14 @@ func (b *GitRepositoryConfigApplyConfiguration) WithBranch(value string) *GitRep
|
|||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithTokenUser sets the TokenUser field in the declarative configuration to the given value
|
||||||
|
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||||
|
// If called multiple times, the TokenUser field is set to the value of the last call.
|
||||||
|
func (b *GitRepositoryConfigApplyConfiguration) WithTokenUser(value string) *GitRepositoryConfigApplyConfiguration {
|
||||||
|
b.TokenUser = &value
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
// WithToken sets the Token field in the declarative configuration to the given value
|
// WithToken sets the Token field in the declarative configuration to the given value
|
||||||
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
// and returns the receiver, so that objects can be built by chaining "With" function invocations.
|
||||||
// If called multiple times, the Token field is set to the value of the last call.
|
// If called multiple times, the Token field is set to the value of the last call.
|
||||||
|
@ -1196,6 +1196,7 @@ func (b *APIBuilder) AsRepository(ctx context.Context, r *provisioning.Repositor
|
|||||||
URL: r.Spec.Git.URL,
|
URL: r.Spec.Git.URL,
|
||||||
Branch: r.Spec.Git.Branch,
|
Branch: r.Spec.Git.Branch,
|
||||||
Path: r.Spec.Git.Path,
|
Path: r.Spec.Git.Path,
|
||||||
|
TokenUser: r.Spec.Git.TokenUser,
|
||||||
Token: token,
|
Token: token,
|
||||||
EncryptedToken: r.Spec.Git.EncryptedToken,
|
EncryptedToken: r.Spec.Git.EncryptedToken,
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ const gitTokenSecretSuffix = "-git-token"
|
|||||||
type RepositoryConfig struct {
|
type RepositoryConfig struct {
|
||||||
URL string
|
URL string
|
||||||
Branch string
|
Branch string
|
||||||
|
TokenUser string
|
||||||
Token string
|
Token string
|
||||||
EncryptedToken []byte
|
EncryptedToken []byte
|
||||||
Path string
|
Path string
|
||||||
@ -54,7 +55,12 @@ func NewGitRepository(
|
|||||||
) (GitRepository, error) {
|
) (GitRepository, error) {
|
||||||
var opts []options.Option
|
var opts []options.Option
|
||||||
if len(gitConfig.Token) > 0 {
|
if len(gitConfig.Token) > 0 {
|
||||||
opts = append(opts, options.WithBasicAuth("git", gitConfig.Token))
|
tokenUser := gitConfig.TokenUser
|
||||||
|
if tokenUser == "" {
|
||||||
|
tokenUser = "git"
|
||||||
|
}
|
||||||
|
|
||||||
|
opts = append(opts, options.WithBasicAuth(tokenUser, gitConfig.Token))
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := nanogit.NewHTTPClient(gitConfig.URL, opts...)
|
client, err := nanogit.NewHTTPClient(gitConfig.URL, opts...)
|
||||||
|
@ -2597,6 +2597,10 @@
|
|||||||
"description": "Token for accessing the repository. If set, it will be encrypted into encryptedToken, then set to an empty string again.",
|
"description": "Token for accessing the repository. If set, it will be encrypted into encryptedToken, then set to an empty string again.",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"tokenUser": {
|
||||||
|
"description": "TokenUser is the user that will be used to access the repository if it's a personal access token.",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"url": {
|
"url": {
|
||||||
"description": "The repository URL (e.g. `https://bitbucket.org/example/test`).",
|
"description": "The repository URL (e.g. `https://bitbucket.org/example/test`).",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@ -2782,6 +2786,10 @@
|
|||||||
"description": "Token for accessing the repository. If set, it will be encrypted into encryptedToken, then set to an empty string again.",
|
"description": "Token for accessing the repository. If set, it will be encrypted into encryptedToken, then set to an empty string again.",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"tokenUser": {
|
||||||
|
"description": "TokenUser is the user that will be used to access the repository if it's a personal access token.",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"url": {
|
"url": {
|
||||||
"description": "The repository URL (e.g. `https://github.com/example/test.git`).",
|
"description": "The repository URL (e.g. `https://github.com/example/test.git`).",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
@ -862,6 +862,8 @@ export type BitbucketRepositoryConfig = {
|
|||||||
path?: string;
|
path?: string;
|
||||||
/** Token for accessing the repository. If set, it will be encrypted into encryptedToken, then set to an empty string again. */
|
/** Token for accessing the repository. If set, it will be encrypted into encryptedToken, then set to an empty string again. */
|
||||||
token?: string;
|
token?: string;
|
||||||
|
/** TokenUser is the user that will be used to access the repository if it's a personal access token. */
|
||||||
|
tokenUser?: string;
|
||||||
/** The repository URL (e.g. `https://bitbucket.org/example/test`). */
|
/** The repository URL (e.g. `https://bitbucket.org/example/test`). */
|
||||||
url?: string;
|
url?: string;
|
||||||
};
|
};
|
||||||
@ -876,6 +878,8 @@ export type GitRepositoryConfig = {
|
|||||||
path?: string;
|
path?: string;
|
||||||
/** Token for accessing the repository. If set, it will be encrypted into encryptedToken, then set to an empty string again. */
|
/** Token for accessing the repository. If set, it will be encrypted into encryptedToken, then set to an empty string again. */
|
||||||
token?: string;
|
token?: string;
|
||||||
|
/** TokenUser is the user that will be used to access the repository if it's a personal access token. */
|
||||||
|
tokenUser?: string;
|
||||||
/** The repository URL (e.g. `https://github.com/example/test.git`). */
|
/** The repository URL (e.g. `https://github.com/example/test.git`). */
|
||||||
url?: string;
|
url?: string;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user