Add auth
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
main.log
|
main.log
|
||||||
|
.env
|
||||||
|
5
go.mod
5
go.mod
@@ -2,7 +2,10 @@ module main
|
|||||||
|
|
||||||
go 1.22.4
|
go 1.22.4
|
||||||
|
|
||||||
require code.gitea.io/sdk/gitea v0.18.0
|
require (
|
||||||
|
code.gitea.io/sdk/gitea v0.18.0
|
||||||
|
github.com/joho/godotenv v1.5.1
|
||||||
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/davidmz/go-pageant v1.0.2 // indirect
|
github.com/davidmz/go-pageant v1.0.2 // indirect
|
||||||
|
2
go.sum
2
go.sum
@@ -8,6 +8,8 @@ github.com/go-fed/httpsig v1.1.0 h1:9M+hb0jkEICD8/cAiNqEB66R87tTINszBRTjwjQzWcI=
|
|||||||
github.com/go-fed/httpsig v1.1.0/go.mod h1:RCMrTZvN1bJYtofsG4rd5NaO5obxQ5xBkdiS7xsT7bM=
|
github.com/go-fed/httpsig v1.1.0/go.mod h1:RCMrTZvN1bJYtofsG4rd5NaO5obxQ5xBkdiS7xsT7bM=
|
||||||
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
|
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
|
||||||
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
||||||
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||||
|
20
main.go
20
main.go
@@ -8,9 +8,11 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"code.gitea.io/sdk/gitea"
|
"code.gitea.io/sdk/gitea"
|
||||||
|
"github.com/joho/godotenv"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Error *log.Logger
|
var Error *log.Logger
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
log.SetFlags(log.Lmicroseconds | log.Lshortfile)
|
log.SetFlags(log.Lmicroseconds | log.Lshortfile)
|
||||||
logFile, err := os.Create("main.log")
|
logFile, err := os.Create("main.log")
|
||||||
@@ -27,6 +29,15 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
godotenv.Load()
|
||||||
|
username := os.Getenv("GITEA_USER")
|
||||||
|
password := os.Getenv("GITEA_PASSWORD")
|
||||||
|
|
||||||
|
if username == "" || password == "" {
|
||||||
|
Error.Fatalf("GITEA_USER and GITEA_PASSWORD environment variables are required")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
var name string
|
var name string
|
||||||
var private bool
|
var private bool
|
||||||
flag.StringVar(&name, "name", "", "Name of the repository")
|
flag.StringVar(&name, "name", "", "Name of the repository")
|
||||||
@@ -49,15 +60,16 @@ func main() {
|
|||||||
Error.Fatalf("Error creating client: %v", err)
|
Error.Fatalf("Error creating client: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
client.SetBasicAuth("dave", "D7u@NHh^9d33ue!xVAEu")
|
||||||
|
|
||||||
repo, _, err := client.CreateRepo(gitea.CreateRepoOption{
|
repo, _, err := client.CreateRepo(gitea.CreateRepoOption{
|
||||||
Name: name,
|
Name: name,
|
||||||
Private: private,
|
Private: private,
|
||||||
DefaultBranch: "master",
|
DefaultBranch: "master",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Error.Fatalf("Error creating repository: %v", err)
|
Error.Fatalf("Error creating repository: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
log.Printf("Repository created: %v", repo)
|
log.Printf("Repository created at:\n%s", repo.CloneURL)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user