Created
March 20, 2018 07:54
-
-
Save katzefudder/7061ecc29bb9c6e570d31eb152bd4137 to your computer and use it in GitHub Desktop.
Get storage info from Artifactory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
docker run --network="artifactory" --name artifactory -tid -p 80:8081 docker.bintray.io/jfrog/artifactory-pro | |
docker build -t json-exporter . --force-rm --no-cache | |
docker run --network="artifactory" -ti json-exporter |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM golang:1.8 | |
WORKDIR /go/src/app | |
COPY . . | |
RUN go-wrapper download && go-wrapper install | |
EXPOSE 9116 | |
CMD ["go-wrapper", "run"] # ["app"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net/http" | |
"encoding/base64" | |
"io/ioutil" | |
"encoding/json" | |
//"os" | |
) | |
func basicAuth(username, password string) string { | |
auth := username + ":" + password | |
return base64.StdEncoding.EncodeToString([]byte(auth)) | |
} | |
func redirectPolicyFunc(req *http.Request, via []*http.Request) error{ | |
req.SetBasicAuth("admin", "password") | |
return nil | |
} | |
type Repositories struct { | |
Summary | |
} | |
type Summary struct { | |
BinariesSummary | |
FilestoreSummary | |
RepositoriesSummaryList | |
} | |
type BinariesSummary struct { | |
binariesCount string `json:"binariesCount"` | |
binariesSize string `json:"binariesSize"` | |
artifactsSize string | |
optimization string | |
itemsCount string | |
artifactsCount string | |
} | |
type FilestoreSummary struct { | |
storageType string | |
storageDirectory string | |
totalSpace string | |
usedSpace string | |
freeSpace string | |
} | |
type RepositoriesSummaryList struct { | |
RepositoriesSummaryListElement | |
} | |
type RepositoriesSummaryListElement struct { | |
repoKey string | |
repoType string | |
foldersCount int | |
filesCount int | |
usedSpace string | |
itemsCount int | |
packageType string | |
percentage string | |
} | |
/* | |
type Repository struct { | |
repoKey string | |
repoType string | |
foldersCount int | |
filesCount int | |
usedSpace string | |
itemsCount int | |
packageType string | |
percentage string | |
} | |
*/ | |
func main() { | |
client := &http.Client { | |
CheckRedirect: redirectPolicyFunc, | |
} | |
// https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API#ArtifactoryRESTAPI-GetStorageSummaryInfo | |
req, err := http.NewRequest("GET", "http://artifactory:8081/artifactory/api/storageinfo", nil) | |
req.SetBasicAuth("admin", "password") | |
if err != nil { | |
panic(err) | |
} | |
resp, err := client.Do(req) | |
if err != nil { | |
panic(err) | |
} | |
defer resp.Body.Close() | |
body, err := ioutil.ReadAll(resp.Body) | |
if err != nil { | |
panic(err) | |
} | |
var data Repositories | |
if err := json.Unmarshal(body, &data); err != nil { | |
panic(err) | |
} | |
fmt.Println("Original: %v\n", string(body)) | |
fmt.Printf("Results: %v\n", data) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment