Skip to content
This repository was archived by the owner on Jul 7, 2024. It is now read-only.

Commit 75f94da

Browse files
committed
srv: cs token support
1 parent 4ad0570 commit 75f94da

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

cs/config.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,15 @@ func (t *TokensConfig) UnmarshalYAML(value *yaml.Node) error {
6969
}
7070

7171
type TokenConfig struct {
72-
Name string `yaml:"name" json:"name"`
73-
Hash *util.TokenHash `yaml:"hash" json:"hash"`
74-
Networks map[string]string `yaml:"networks" json:"networks"`
75-
CanPull bool `yaml:"canPull"`
76-
CanPush *CanPush `yaml:"canPush"`
77-
CanAdminTokens *CanAdminTokens `yaml:"canAdminTokens"`
72+
Name string `yaml:"name" json:"name"`
73+
Hash *util.TokenHash `yaml:"hash" json:"hash"`
74+
Networks map[string]string `yaml:"networks" json:"networks"`
75+
CanPull bool `yaml:"canPull"`
76+
CanPush *CanPush `yaml:"canPush"`
77+
CanAdminTokens *CanAdminTokens `yaml:"canAdminTokens"`
78+
CanSRVUpdate bool `yaml:"canSRVUpdate"`
79+
SRVAllowances []central.SRVAllowance `yaml:"srvAllowances"`
80+
SRVAllowancesAny bool `yaml:"srvAllowancesAny"`
7881
}
7982

8083
func convertTokens2(tokens []TokenConfig) ([]Token, error) {
@@ -83,11 +86,14 @@ func convertTokens2(tokens []TokenConfig) ([]Token, error) {
8386
res[i] = Token{
8487
Hash: *token.Hash,
8588
Info: TokenInfo{
86-
Name: token.Name,
87-
Networks: token.Networks,
88-
CanPull: token.CanPull,
89-
CanPush: token.CanPush,
90-
CanAdminTokens: token.CanAdminTokens,
89+
Name: token.Name,
90+
Networks: token.Networks,
91+
CanPull: token.CanPull,
92+
CanPush: token.CanPush,
93+
CanAdminTokens: token.CanAdminTokens,
94+
CanSRVUpdate: token.CanSRVUpdate,
95+
SRVAllowances: token.SRVAllowances,
96+
SRVAllowancesAny: token.SRVAllowancesAny,
9197
},
9298
}
9399
}

cs/tokencheck.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ func checkSrv(ti TokenInfo, cnn string) error {
5353
if ti.CanPush == nil {
5454
return newHttpError(403, errors.New("token: cannot push"))
5555
}
56+
if !ti.CanSRVUpdate {
57+
return newHttpError(403, errors.New("token: cannot srvUpdate"))
58+
}
5659
if !ti.CanPush.Any {
5760
_, ok := ti.CanPush.Networks[cnn]
5861
if !ok {

nixos-modules.nix

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,19 @@ args@{ self, system, nixpkgsFor, libFor, nixosLibFor, ldflags, packages, ...
374374
description =
375375
"Allow token to add more tokens, or remove any tokens.";
376376
};
377+
allowedSRVs = mkOption {
378+
type = nullOr (listOf (submodule {
379+
options = {
380+
service = mkOption { type = str; };
381+
serviceAny = mkOption { type = bool; default = false; };
382+
priorityMin = mkOption { type = port; default = 0; };
383+
priorityMax = mkOption { type = port; default = 65535; };
384+
weightMin = mkOption { type = port; default = 0; };
385+
weightMax = mkOption { type = port; default = 65535; };
386+
};
387+
}));
388+
default = null;
389+
};
377390
};
378391
});
379392
};

0 commit comments

Comments
 (0)