Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Plural
platform
plural-cli
Commits
cbad6f91
Commit
cbad6f91
authored
3 years ago
by
michaelguarino
Browse files
Options
Download
Email Patches
Plain Diff
Add repo attrs target
parent
d8222fa3
master
oidc-recipe-domains
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
pkg/api/repos.go
+60
-4
pkg/api/repos.go
pkg/pluralfile/artifact.go
+2
-4
pkg/pluralfile/artifact.go
pkg/pluralfile/attrs.go
+72
-0
pkg/pluralfile/attrs.go
pkg/pluralfile/lock.go
+7
-0
pkg/pluralfile/lock.go
pkg/pluralfile/parse.go
+5
-0
pkg/pluralfile/parse.go
with
146 additions
and
8 deletions
+146
-8
pkg/api/repos.go
+
60
-
4
View file @
cbad6f91
...
...
@@ -2,8 +2,11 @@ package api
import
(
"fmt"
"os"
"path/filepath"
"gopkg.in/yaml.v2"
"github.com/michaeljguarino/graphql"
)
type
ResourceDefinitionInput
struct
{
...
...
@@ -30,10 +33,12 @@ type IntegrationInput struct {
}
type
RepositoryInput
struct
{
Dashboards
[]
struct
{
Name
string
UID
string
`json:"uid"`
}
Name
string
Description
string
Tags
[]
Tag
`json:"tags,omitempty" yaml:"tags"`
Icon
string
`json:"icon,omitempty" yaml:"icon"`
DarkIcon
string
`json:"darkIcon,omitempty" yaml:"darkIcon"`
Category
string
}
const
updateRepository
=
`
...
...
@@ -44,6 +49,12 @@ const updateRepository = `
}
`
const
upsertRepository
=
`
mutation UpsertRepository($name: String!, $publisher: String!, $attributes: RepositoryAttributes!) {
upsertRepository(name: $name, publisher: $publisher, attributes: $attributes) { id }
}
`
const
createIntegration
=
`
mutation CreateIntegration($name: String!, $attrs: IntegrationAttributes!) {
createIntegration(repositoryName: $name, attributes: $attrs) {
...
...
@@ -113,6 +124,51 @@ func (client *Client) UpdateRepository(name string, input RepositoryInput) (stri
return
resp
.
Id
,
err
}
func
(
client
*
Client
)
CreateRepository
(
name
,
publisher
string
,
input
RepositoryInput
)
error
{
var
resp
struct
{
UpsertRepository
struct
{
Id
string
}
}
req
:=
client
.
Build
(
upsertRepository
)
req
.
Var
(
"name"
,
name
)
req
.
Var
(
"publisher"
,
publisher
)
ok
,
err
:=
getIconReader
(
input
.
Icon
,
"icon"
,
req
)
if
err
!=
nil
{
return
err
}
if
ok
{
input
.
Icon
=
"icon"
}
ok
,
err
=
getIconReader
(
input
.
DarkIcon
,
"darkicon"
,
req
)
if
err
!=
nil
{
return
err
}
if
ok
{
input
.
DarkIcon
=
"darkicon"
}
req
.
Var
(
"attributes"
,
input
)
return
client
.
Run
(
req
,
&
resp
)
}
func
getIconReader
(
icon
,
field
string
,
req
*
graphql
.
Request
)
(
bool
,
error
)
{
if
icon
==
""
{
return
false
,
nil
}
file
,
err
:=
filepath
.
Abs
(
icon
)
if
err
!=
nil
{
return
false
,
err
}
f
,
err
:=
os
.
Open
(
file
)
req
.
File
(
field
,
file
,
f
)
return
true
,
err
}
func
ConstructRepositoryInput
(
marshalled
[]
byte
)
(
input
RepositoryInput
,
err
error
)
{
err
=
yaml
.
Unmarshal
(
marshalled
,
&
input
)
return
...
...
This diff is collapsed.
Click to expand it.
pkg/pluralfile/artifact.go
+
2
-
4
View file @
cbad6f91
...
...
@@ -57,14 +57,12 @@ func mkSha(file string) (sha string, err error) {
return
}
readmePath
,
_
:=
filepath
.
Abs
(
input
.
Readme
)
readme
,
err
:=
utils
.
Sha256
(
readmePath
)
readme
,
err
:=
fileSha
(
input
.
Readme
)
if
err
!=
nil
{
return
}
blobPath
,
_
:=
filepath
.
Abs
(
input
.
Blob
)
blob
,
err
:=
utils
.
Sha256
(
blobPath
)
blob
,
err
:=
fileSha
(
input
.
Blob
)
if
err
!=
nil
{
return
}
...
...
This diff is collapsed.
Click to expand it.
pkg/pluralfile/attrs.go
0 → 100644
+
72
-
0
View file @
cbad6f91
package
pluralfile
import
(
"fmt"
"io/ioutil"
"path/filepath"
"github.com/pluralsh/plural/pkg/api"
"github.com/pluralsh/plural/pkg/utils"
)
type
RepoAttrs
struct
{
File
string
Publisher
string
}
func
(
a
*
RepoAttrs
)
Type
()
ComponentName
{
return
REPO_ATTRS
}
func
(
a
*
RepoAttrs
)
Key
()
string
{
return
fmt
.
Sprintf
(
"%s_%s"
,
a
.
File
,
a
.
Publisher
)
}
func
(
a
*
RepoAttrs
)
Push
(
repo
string
,
sha
string
)
(
string
,
error
)
{
fullPath
,
_
:=
filepath
.
Abs
(
a
.
File
)
contents
,
err
:=
ioutil
.
ReadFile
(
fullPath
)
if
err
!=
nil
{
return
""
,
err
}
input
,
err
:=
api
.
ConstructRepositoryInput
(
contents
)
if
err
!=
nil
{
return
""
,
err
}
newsha
,
err
:=
a
.
mkSha
(
fullPath
,
input
)
if
err
!=
nil
||
newsha
==
sha
{
utils
.
Highlight
(
"No change for %s
\n
"
,
a
.
File
)
return
sha
,
err
}
client
:=
api
.
NewClient
()
return
newsha
,
client
.
CreateRepository
(
repo
,
a
.
Publisher
,
input
)
}
func
(
a
*
RepoAttrs
)
mkSha
(
fullPath
string
,
input
api
.
RepositoryInput
)
(
sha
string
,
err
error
)
{
base
,
err
:=
utils
.
Sha256
(
fullPath
)
if
err
!=
nil
{
return
}
iconSha
,
err
:=
fileSha
(
input
.
Icon
)
if
err
!=
nil
{
return
}
darkIconSha
,
err
:=
fileSha
(
input
.
DarkIcon
)
if
err
!=
nil
{
return
}
sha
=
utils
.
Sha
([]
byte
(
fmt
.
Sprintf
(
"%s:%s:%s"
,
base
,
iconSha
,
darkIconSha
)))
return
}
func
fileSha
(
path
string
)
(
string
,
error
)
{
if
path
==
""
{
return
""
,
nil
}
fpath
,
_
:=
filepath
.
Abs
(
path
)
return
utils
.
Sha256
(
fpath
)
}
This diff is collapsed.
Click to expand it.
pkg/pluralfile/lock.go
+
7
-
0
View file @
cbad6f91
...
...
@@ -18,6 +18,7 @@ type Lockfile struct {
Crd
map
[
string
]
string
Ird
map
[
string
]
string
Tag
map
[
string
]
string
Attrs
map
[
string
]
string
}
func
lock
()
*
Lockfile
{
...
...
@@ -30,6 +31,7 @@ func lock() *Lockfile {
Crd
:
map
[
string
]
string
{},
Ird
:
map
[
string
]
string
{},
Tag
:
map
[
string
]
string
{},
Attrs
:
map
[
string
]
string
{},
}
}
...
...
@@ -89,6 +91,9 @@ func (lock *Lockfile) getSha(name ComponentName, key string) string {
case
TAG
:
sha
,
_
:=
lock
.
Tag
[
key
]
return
sha
case
REPO_ATTRS
:
sha
,
_
:=
lock
.
Tag
[
key
]
return
sha
default
:
return
""
}
...
...
@@ -113,6 +118,8 @@ func (lock *Lockfile) addSha(name ComponentName, key string, sha string) {
lock
.
Ird
[
key
]
=
sha
case
TAG
:
lock
.
Tag
[
key
]
=
sha
case
REPO_ATTRS
:
lock
.
Attrs
[
key
]
=
sha
default
:
return
}
...
...
This diff is collapsed.
Click to expand it.
pkg/pluralfile/parse.go
+
5
-
0
View file @
cbad6f91
...
...
@@ -25,6 +25,7 @@ const (
IRD
ComponentName
=
"ird"
COMMAND
ComponentName
=
"run"
TAG
ComponentName
=
"tag"
REPO_ATTRS
ComponentName
=
"attrs"
)
type
Component
interface
{
...
...
@@ -153,6 +154,10 @@ func Parse(f string) (*Pluralfile, error) {
return
plrl
,
err
}
plrl
.
Components
=
append
(
plrl
.
Components
,
tags
...
)
case
"attributes"
:
pub
,
file
:=
splitline
[
1
],
splitline
[
2
]
plrl
.
Components
=
append
(
plrl
.
Components
,
&
RepoAttrs
{
File
:
file
,
Publisher
:
pub
})
default
:
continue
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help